Allow register-node to accept int for input
register-node used to pipe the nodes definition file through jq, which explicitly converts all int values to strings, but the new implementation doesn't do so, which is backward incompatible. Change-Id: Id5c5b56ccd73bdabe02eb24575e5b8c4dbcdb04b Closes-Bug: #1382275
This commit is contained in:
parent
742a0fb738
commit
b3e1d87b13
|
@ -19,6 +19,7 @@ import time
|
|||
from ironicclient.openstack.common.apiclient import exceptions as ironicexp
|
||||
from novaclient.openstack.common.apiclient import exceptions as novaexc
|
||||
from os_cloud_config.cmd.utils import _clients as clients
|
||||
import six
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
@ -40,8 +41,10 @@ def register_nova_bm_node(service_host, node, client=None, blocking=True):
|
|||
LOG.debug('Registering %s node with nova-baremetal, try #%d.' %
|
||||
(node["pm_addr"], count))
|
||||
try:
|
||||
bm_node = client.baremetal.create(service_host, node["cpu"],
|
||||
node["memory"], node["disk"],
|
||||
bm_node = client.baremetal.create(service_host,
|
||||
six.text_type(node["cpu"]),
|
||||
six.text_type(node["memory"]),
|
||||
six.text_type(node["disk"]),
|
||||
node["mac"][0], **kwargs)
|
||||
break
|
||||
except (novaexc.ConnectionRefused, novaexc.ServiceUnavailable):
|
||||
|
@ -62,9 +65,9 @@ def register_nova_bm_node(service_host, node, client=None, blocking=True):
|
|||
|
||||
|
||||
def register_ironic_node(service_host, node, client=None, blocking=True):
|
||||
properties = {"cpus": node["cpu"],
|
||||
"memory_mb": node["memory"],
|
||||
"local_gb": node["disk"],
|
||||
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"]}
|
||||
if "ipmi" in node["pm_type"]:
|
||||
driver_info = {"ipmi_address": node["pm_addr"],
|
||||
|
@ -196,7 +199,8 @@ def _update_or_register_ironic_node(service_host, node, node_map, client=None,
|
|||
ironic_node.uuid))
|
||||
node_patch = []
|
||||
for key, value in massage_map.items():
|
||||
node_patch.append({'path': value, 'value': node[key],
|
||||
node_patch.append({'path': value,
|
||||
'value': six.text_type(node[key]),
|
||||
'op': 'replace'})
|
||||
for count in range(2):
|
||||
try:
|
||||
|
|
|
@ -108,6 +108,20 @@ class NodesTest(base.TestCase):
|
|||
node["pm_password"] = ""
|
||||
self.assert_nova_bm_call_with_no_pm_password(node)
|
||||
|
||||
def test_register_nova_bm_node_int_values(self):
|
||||
node = self._get_node()
|
||||
node['cpu'] = 1
|
||||
node['memory'] = 2048
|
||||
node['disk'] = 30
|
||||
client = mock.MagicMock()
|
||||
nodes.register_nova_bm_node('service_host', node, client=client)
|
||||
client.baremetal.create.assert_called_once_with('service_host', '1',
|
||||
'2048', '30',
|
||||
node["mac"][0],
|
||||
pm_password='random',
|
||||
pm_address='foo.bar',
|
||||
pm_user='test')
|
||||
|
||||
@mock.patch('os_cloud_config.nodes.using_ironic', return_value=True)
|
||||
def test_register_all_nodes_ironic(self, using_ironic):
|
||||
node_list = [self._get_node(), self._get_node(),
|
||||
|
@ -220,6 +234,47 @@ class NodesTest(base.TestCase):
|
|||
nodes._update_or_register_ironic_node, None, node,
|
||||
node_map, client=ironic)
|
||||
|
||||
def test_register_ironic_node_int_values(self):
|
||||
node_properties = {"cpus": "1",
|
||||
"memory_mb": "2048",
|
||||
"local_gb": "30",
|
||||
"cpu_arch": "amd64"}
|
||||
node = self._get_node()
|
||||
node['cpu'] = 1
|
||||
node['memory'] = 2048
|
||||
node['disk'] = 30
|
||||
client = mock.MagicMock()
|
||||
nodes.register_ironic_node('service_host', node, client=client)
|
||||
client.node.create.assert_called_once_with(driver=mock.ANY,
|
||||
properties=node_properties,
|
||||
driver_info=mock.ANY)
|
||||
|
||||
def test_register_ironic_node_update_int_values(self):
|
||||
node = self._get_node()
|
||||
ironic = mock.MagicMock()
|
||||
node['cpu'] = 1
|
||||
node['memory'] = 2048
|
||||
node['disk'] = 30
|
||||
node_map = {'mac': {'aaa': 1}}
|
||||
|
||||
def side_effect(*args, **kwargs):
|
||||
update_patch = [
|
||||
{'path': '/driver_info/ssh_key_contents', 'value': 'random'},
|
||||
{'path': '/driver_info/ssh_address', 'value': 'foo.bar'},
|
||||
{'path': '/properties/memory_mb', 'value': '2048'},
|
||||
{'path': '/properties/local_gb', 'value': '30'},
|
||||
{'path': '/properties/cpu_arch', 'value': 'amd64'},
|
||||
{'path': '/properties/cpus', 'value': '1'},
|
||||
{'path': '/driver_info/ssh_username', 'value': 'test'}]
|
||||
for key in update_patch:
|
||||
key['op'] = 'replace'
|
||||
self.assertThat(update_patch,
|
||||
matchers.MatchesSetwise(*(map(matchers.Equals,
|
||||
args[1]))))
|
||||
ironic.node.update.side_effect = side_effect
|
||||
nodes._update_or_register_ironic_node(None, node, node_map,
|
||||
client=ironic)
|
||||
|
||||
def test_populate_node_mapping_nova_bm(self):
|
||||
client = mock.MagicMock()
|
||||
node1 = mock.MagicMock()
|
||||
|
|
Loading…
Reference in New Issue