Merge "Allow platform in instackenv.json"

This commit is contained in:
Zuul 2018-07-03 12:37:49 +00:00 committed by Gerrit Code Review
commit 648aa43675
2 changed files with 63 additions and 1 deletions

View File

@ -317,6 +317,34 @@ class NodesTest(base.TestCase):
ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
ironic.port.create.assert_has_calls([port_call])
def test_register_all_nodes_with_platform(self):
node_list = [self._get_node()]
node_list[0]['root_device'] = {"serial": "abcdef"}
node_properties = {"cpus": "1",
"memory_mb": "2048",
"local_gb": "30",
"cpu_arch": "amd64",
"capabilities": "num_nics:6",
"root_device": {"serial": "abcdef"}}
node_list[0].update({'platform': 'SNB'})
node_extra = {"tripleo_platform": "SNB"}
ironic = mock.MagicMock()
nodes.register_all_nodes(node_list, client=ironic)
pxe_node_driver_info = {"ipmi_address": "foo.bar",
"ipmi_username": "test",
"ipmi_password": "random"}
pxe_node = mock.call(driver="ipmi",
name='node1',
driver_info=pxe_node_driver_info,
resource_class='baremetal',
properties=node_properties,
extra=node_extra)
port_call = mock.call(node_uuid=ironic.node.create.return_value.uuid,
address='aaa', physical_network='ctlplane',
local_link_connection=None)
ironic.node.create.assert_has_calls([pxe_node, mock.ANY])
ironic.port.create.assert_has_calls([port_call])
def test_register_all_nodes_kernel_ramdisk(self):
node_list = [self._get_node()]
node_properties = {"cpus": "1",
@ -1000,6 +1028,12 @@ VALID_NODE_JSON = [
'pm_user': 'root',
'pm_password': 'foobar',
'pm_system_id': '/redfish/v1/Systems/1'},
{'pm_type': 'ipmi',
'pm_addr': '1.1.1.1',
'pm_user': 'root',
'pm_password': 'p@$$w0rd',
'arch': 'x86_64',
'platform': 'SNB'},
]
@ -1125,6 +1159,20 @@ class TestValidateNodes(base.TestCase):
'fields are missing: %s' % field,
nodes.validate_nodes, nodes_json)
def test_missing_arch_with_platform_fail(self):
nodes_json = [
{'pm_type': 'ipmi',
'pm_addr': '1.1.1.1',
'pm_user': 'root',
'pm_password': 'p@$$w0rd',
'platform': 'SNB'},
]
msg = 'You have specified a platform without an architecture'
self.assertRaisesRegex(exception.InvalidNode,
msg,
nodes.validate_nodes, nodes_json)
def test_ipmi_missing_user_ok(self):
nodes_json = [
{'pm_type': 'ipmi',

View File

@ -353,6 +353,11 @@ def register_ironic_node(node, client):
for k, v in mapping.items()
if node.get(v) is not None}
extra = {}
platform = node.get('platform')
if platform:
extra = dict(tripleo_platform=platform)
if 'capabilities' in node:
caps = node['capabilities']
if isinstance(caps, dict):
@ -371,6 +376,8 @@ def register_ironic_node(node, client):
"driver_info": driver_info,
"resource_class": resource_class}
create_map.update(interface_fields)
if extra:
create_map["extra"] = extra
for field in ('name', 'uuid'):
if field in node:
@ -453,7 +460,9 @@ _NON_DRIVER_FIELDS = {'cpu': '/properties/cpus',
'/driver_info/rescue_kernel'],
'ramdisk_id': ['/driver_info/deploy_ramdisk',
'/driver_info/rescue_ramdisk'],
'capabilities': '/properties/capabilities'}
'capabilities': '/properties/capabilities',
'platform': '/extra/tripleo_platform',
}
_NON_DRIVER_FIELDS.update({field: '/%s' % field
for field in _KNOWN_INTERFACE_FIELDS})
@ -590,6 +599,11 @@ def validate_nodes(nodes_list):
else:
names.add(node['name'])
if node.get('platform') and not node.get('arch'):
failures.append(
(index,
'You have specified a platform without an architecture'))
try:
capabilities_to_dict(node.get('capabilities'))
except (ValueError, TypeError):