Remove requirement of specifying hardware stats

With introspection in place, there is no longer a hard requirement of
knowing the hardware statistics (cpu, memory, disk, arch) of nodes when
initially registering them with Ironic.

The requirement was never on the Ironic side, it was only enforced here
in os-cloud-config. Previously, to get around the requirement, one could
just specify an empty string value for these statistics in the nodes
json file.

This change makes it such that these keys do not even have to exist in
the json anymore.

Add a unit test as well that verifies this change.

Change-Id: Idcc5a9a4ac043c88fe0102626eefb327476819fd
This commit is contained in:
James Slagle 2015-10-06 13:25:03 -04:00
parent 73b02563c7
commit cea8502527
3 changed files with 41 additions and 4 deletions

View File

@ -79,6 +79,10 @@ Where ``/tmp/one-node`` contains::
}
]
.. note::
The memory, disk, arch, and cpu fields are optional and can be omitted.
----------------------------------------------------------
Generating keys and certificates for use with Keystone PKI
----------------------------------------------------------

View File

@ -80,10 +80,13 @@ def _extract_driver_info(node):
def register_ironic_node(service_host, node, client=None, blocking=True):
properties = {"cpus": six.text_type(node["cpu"]),
"memory_mb": six.text_type(node["memory"]),
"local_gb": six.text_type(node["disk"]),
"cpu_arch": node["arch"]}
mapping = {'cpus': 'cpu',
'memory_mb': 'memory',
'local_gb': 'disk',
'cpu_arch': 'arch'}
properties = {k: six.text_type(node.get(v))
for k, v in mapping.items()
if node.get(v) is not None}
driver_info = _extract_driver_info(node)
if 'capabilities' in node:

View File

@ -152,6 +152,36 @@ class NodesTest(base.TestCase):
node["pm_type"] = "unknown_type"
self.assertRaises(ValueError, nodes._extract_driver_info, node)
def test_register_all_nodes_ironic_no_hw_stats(self):
node_list = [self._get_node()]
# Remove the hardware stats from the node dictionary
node_list[0].pop("cpu")
node_list[0].pop("memory")
node_list[0].pop("disk")
node_list[0].pop("arch")
# Node properties should be created with empty string values for the
# hardware statistics
node_properties = {"capabilities": "num_nics:6"}
ironic = mock.MagicMock()
nodes.register_all_nodes('servicehost', node_list, client=ironic)
pxe_node_driver_info = {"ssh_address": "foo.bar",
"ssh_username": "test",
"ssh_key_contents": "random",
"ssh_virt_type": "virsh"}
pxe_node = mock.call(driver="pxe_ssh",
name='node1',
driver_info=pxe_node_driver_info,
properties=node_properties)
port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
address='aaa')
power_off_call = mock.call(ironic.node.create.return_value.uuid, 'off')
ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
ironic.port.create.assert_has_calls([port_call])
ironic.node.set_power_state.assert_has_calls([power_off_call])
def test_register_all_nodes_ironic(self):
node_list = [self._get_node()]
node_properties = {"cpus": "1",