# move ipmi_* to pm_*
# make mac a list
def munge_node(node):
- node['pm_addr'] = node['ipmi_ip']
- node['pm_password'] = node['ipmi_pass']
- node['pm_user'] = node['ipmi_user']
- node['mac'] = [node['mac_address']]
- if 'cpus' in node:
- node['cpu'] = node['cpus']
+ pairs = (('pm_addr', 'ipmi_ip'), ('pm_password', 'ipmi_pass'),
+ ('pm_user', 'ipmi_user'), ('mac', 'mac_address'),
+ ('cpu', 'cpus'), (None, 'disk_device'))
+
+ for x, y in pairs:
+ if y in node:
+ if y == 'disk_device':
+ self.root_device = node[y]
+ elif x == 'mac':
+ node[x] = [node[y]]
+ elif x is not None and y in node:
+ node[x] = node[y]
+ del node[y]
# aarch64 is always uefi
if 'arch' in node and node['arch'] == 'aarch64':
node['capabilities'] += ',boot_mode:uefi'
- for i in ('ipmi_ip', 'ipmi_pass', 'ipmi_user', 'mac_address',
- 'disk_device'):
- if i in node.keys():
- if i == 'disk_device':
- self.root_device = node[i]
- del node[i]
-
return node
+
super().__init__({'nodes': list(map(munge_node, init_dict['nodes']))})
# verify number of nodes
if ha and len(self['nodes']) < 5:
- raise InventoryException('You must provide at least 5 '
- 'nodes for HA deployment')
+ raise ApexInventoryException('You must provide at least 5 '
+ 'nodes for HA deployment')
elif len(self['nodes']) < 2:
- raise InventoryException('You must provide at least 2 nodes '
- 'for non-HA deployment')
+ raise ApexInventoryException('You must provide at least 2 nodes '
+ 'for non-HA deployment')
if virtual:
self['host-ip'] = '192.168.122.1'
def dump_instackenv_json(self):
print(json.dumps(dict(self), sort_keys=True, indent=4))
-
-class InventoryException(Exception):
- def __init__(self, value):
- self.value = value
-
- def __str__(self):
- return self.value
+ def get_node_counts(self):
+ """
+ Return numbers of controller and compute nodes in inventory
+ :param inventory: node inventory data structure
+ :return: number of controller and compute nodes in inventory
+ """
+ nodes = self['nodes']
+ num_control = 0
+ num_compute = 0
+ for node in nodes:
+ if 'profile:control' in node['capabilities']:
+ num_control += 1
+ elif 'profile:compute' in node['capabilities']:
+ num_compute += 1
+ else:
+ raise ApexInventoryException("Node missing capabilities "
+ "key: {}".format(node))
+ return num_control, num_compute
+
+
+class ApexInventoryException(Exception):
+ pass
return env_list
-def _get_node_counts(inventory):
- """
- Return numbers of controller and compute nodes in inventory
-
- :param inventory: node inventory data structure
- :return: number of controller and compute nodes in inventory
- """
- if not inventory:
- raise ApexDeployException("Empty inventory")
-
- nodes = inventory['nodes']
- num_control = 0
- num_compute = 0
- for node in nodes:
- if node['capabilities'] == 'profile:control':
- num_control += 1
- elif node['capabilities'] == 'profile:compute':
- num_compute += 1
- else:
- # TODO(trozet) do we want to allow capabilities to not exist?
- logging.error("Every node must include a 'capabilities' key "
- "tagged with either 'profile:control' or "
- "'profile:compute'")
- raise ApexDeployException("Node missing capabilities "
- "key: {}".format(node))
- return num_control, num_compute
-
-
def create_deploy_cmd(ds, ns, inv, tmp_dir,
virtual, env_file='opnfv-environment.yaml'):
else:
deploy_options.append('baremetal-environment.yaml')
- num_control, num_compute = _get_node_counts(inv)
+ num_control, num_compute = inv.get_node_counts()
if num_control == 0 or num_compute == 0:
logging.error("Detected 0 control or compute nodes. Control nodes: "
"{}, compute nodes{}".format(num_control, num_compute))
if 'OS::TripleO::Services::NeutronDhcpAgent' in line:
output_line = ''
elif 'NeutronDhcpAgentsPerNetwork' in line:
- num_control, num_compute = _get_node_counts(inv)
+ num_control, num_compute = inv.get_node_counts()
output_line = (" NeutronDhcpAgentsPerNetwork: {}"
.format(num_compute))
elif 'ComputeServices' in line:
assert_raises)
from apex import Inventory
-from apex.inventory.inventory import InventoryException
+from apex.inventory.inventory import ApexInventoryException
from apex.tests.constants import (
TEST_CONFIG_DIR,
TEST_DUMMY_CONFIG
for f in inventory_files:
i = Inventory(os.path.join(files_dir, f))
assert_equal(i.dump_instackenv_json(), None)
+ i['nodes'][0]['arch'] = 'aarch64'
+ i = Inventory(i)
+ assert_equal(i['nodes'][0]['arch'], 'aarch64')
def test_inventory_invalid_ha_count(self):
- assert_raises(InventoryException, Inventory,
+ assert_raises(ApexInventoryException, Inventory,
os.path.join(TEST_DUMMY_CONFIG, 'inventory-virt.yaml'),
virtual=True, ha=True)
def test_inventory_invalid_noha_count(self):
- assert_raises(InventoryException, Inventory,
+ assert_raises(ApexInventoryException, Inventory,
os.path.join(TEST_DUMMY_CONFIG,
'inventory-virt-1-node.yaml'),
virtual=True, ha=False)
virtual=True, ha=False)
assert_equal(i.dump_instackenv_json(), None)
- def test_exception(self):
- e = InventoryException("test")
- print(e)
- assert_is_instance(e, InventoryException)
+ def test_get_node_counts(self):
+ i = Inventory(os.path.join(TEST_DUMMY_CONFIG, 'inventory-virt.yaml'),
+ virtual=True, ha=False)
+ assert_equal(i.get_node_counts(), (1, 1))