Browse Source

Merge "Improve handling of memory retrieval from introspection data"

changes/14/787914/2
Zuul 1 week ago
committed by Gerrit Code Review
parent
commit
ab51504b44
2 changed files with 28 additions and 6 deletions
  1. +13
    -6
      tripleo_ansible/ansible_plugins/modules/tripleo_derive_hci_parameters.py
  2. +15
    -0
      tripleo_ansible/tests/modules/test_derive_hci_parameters.py

+ 13
- 6
tripleo_ansible/ansible_plugins/modules/tripleo_derive_hci_parameters.py View File

@ -259,13 +259,20 @@ def count_osds(tripleo_environment_parameters):
def count_memory(ironic):
"""
Counts the memory found in the ironic introspection data as
represented by memory_mb. Returns integer of memory in GB.
Counts the memory found in the ironic introspection data. If
memory_mb is 0, uses ['inventory']['memory']['total'] in bytes.
Returns integer of memory in GB.
"""
try:
memory = ironic['data']['memory_mb'] / float(MB_PER_GB)
except KeyError:
memory = 0
memory = 0
if 'data' in ironic:
if 'memory_mb' in ironic['data']:
if int(ironic['data']['memory_mb']) > 0:
memory = int(ironic['data']['memory_mb']) / float(MB_PER_GB)
elif 'inventory' in ironic['data']:
if 'memory' in ironic['data']['inventory']:
if 'total' in ironic['data']['inventory']['memory']:
memory = int(ironic['data']['inventory']['memory']['total']) \
/ float(MB_PER_GB) / float(MB_PER_GB) / float(MB_PER_GB)
return memory


+ 15
- 0
tripleo_ansible/tests/modules/test_derive_hci_parameters.py View File

@ -161,3 +161,18 @@ class TestTripleoDeriveHciParameters(tests_base.TestCase):
der = derive_params.derive(mem_gb=256, vcpus=56, osds=16)
self.assertFalse(der['failed'])
self.assertEqual(der['nova_reserved_mem_mb'], 81920)
def test_count_memory(self):
"""Test that the count_memory method can the right number
regardless of which value ironic might provide.
"""
mock_ironic_memory_mb = {'data':
{'memory_mb': 262144}}
mock_ironic_memory_bytes = {'data':
{'memory_mb': 0,
'inventory':
{'memory':
{'total': 274877906944}}}}
gb_from_mb = derive_params.count_memory(mock_ironic_memory_mb)
gb_from_bytes = derive_params.count_memory(mock_ironic_memory_bytes)
self.assertEqual(gb_from_mb, gb_from_bytes)

Loading…
Cancel
Save