summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Radez <dradez@redhat.com>2017-10-12 14:02:14 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-10-12 14:02:15 +0000
commitf5ff4ff13a1ab3b45454268f1871a2ba5c4cd944 (patch)
treee56b265fb1232800c43f4f917eb99d68a4ce0ac5
parent6ddb7d379156ba03c9c4bdcb01679d6727cb4dd6 (diff)
parentdbfb8214328d08c0f8bd967b422476b1a503a001 (diff)
Merge "Updates to Inventory object" into stable/euphrates
-rw-r--r--apex/inventory/inventory.py64
-rw-r--r--apex/overcloud/overcloud_deploy.py32
-rw-r--r--apex/tests/test_apex_inventory.py17
3 files changed, 52 insertions, 61 deletions
diff --git a/apex/inventory/inventory.py b/apex/inventory/inventory.py
index 3483e57..b5ffd2f 100644
--- a/apex/inventory/inventory.py
+++ b/apex/inventory/inventory.py
@@ -41,34 +41,35 @@ class Inventory(dict):
# 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'
@@ -81,10 +82,25 @@ class Inventory(dict):
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
diff --git a/apex/overcloud/overcloud_deploy.py b/apex/overcloud/overcloud_deploy.py
index e324853..ef916a4 100644
--- a/apex/overcloud/overcloud_deploy.py
+++ b/apex/overcloud/overcloud_deploy.py
@@ -93,34 +93,6 @@ def build_sdn_env_list(ds, sdn_map, env_list=None):
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'):
@@ -146,7 +118,7 @@ def create_deploy_cmd(ds, ns, inv, tmp_dir,
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))
@@ -410,7 +382,7 @@ def prep_env(ds, ns, inv, opnfv_env, net_env, tmp_dir):
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:
diff --git a/apex/tests/test_apex_inventory.py b/apex/tests/test_apex_inventory.py
index 87e7d50..7197946 100644
--- a/apex/tests/test_apex_inventory.py
+++ b/apex/tests/test_apex_inventory.py
@@ -15,7 +15,7 @@ from nose.tools import (
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
@@ -47,14 +47,17 @@ class TestInventory:
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)
@@ -64,7 +67,7 @@ class TestInventory:
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))