From 185546cfa5cd7da03733091dc3621e28ecc3ad4f Mon Sep 17 00:00:00 2001 From: Oliver Walsh Date: Wed, 25 Jan 2017 15:28:40 +0000 Subject: [PATCH] Run nova manage cell_v2 discover_host after ironic nodes are registered Once cell_v2 is enabled by default in Ocata we will need to run this command to update the host mappings whenever a new host is added. Change-Id: I0bb98bfcf0c271ae3b577ca126dd3dfdaece179e Depends-On: I591b451197dc3bd0783978f5e3d2b1c830afe54e Related-Bug: #1649341 --- .../discover_hosts-f1733234ba32a909.yaml | 5 +++++ sudoers | 1 + tripleo_common/tests/utils/test_nodes.py | 20 ++++++++++++++----- tripleo_common/utils/nodes.py | 11 ++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 releasenotes/notes/discover_hosts-f1733234ba32a909.yaml diff --git a/releasenotes/notes/discover_hosts-f1733234ba32a909.yaml b/releasenotes/notes/discover_hosts-f1733234ba32a909.yaml new file mode 100644 index 000000000..1d545eba2 --- /dev/null +++ b/releasenotes/notes/discover_hosts-f1733234ba32a909.yaml @@ -0,0 +1,5 @@ +--- +features: + - | + Run ``nova-manage cell_v2 discover_hosts`` when any baremetal nodes are + registered with the undercloud. diff --git a/sudoers b/sudoers index 9677b13f7..a7cb35eb8 100644 --- a/sudoers +++ b/sudoers @@ -4,4 +4,5 @@ Defaults:mistral !requiretty mistral ALL = (validations) NOPASSWD:SETENV: /usr/bin/run-validation mistral ALL = NOPASSWD: /usr/bin/chown validations\: /tmp/validations_identity_* mistral ALL = NOPASSWD: /usr/bin/rm -f /tmp/validations_identity_* +mistral ALL = NOPASSWD: /bin/nova-manage cell_v2 discover_hosts validations ALL = NOPASSWD: ALL diff --git a/tripleo_common/tests/utils/test_nodes.py b/tripleo_common/tests/utils/test_nodes.py index 63e4f8a52..45c4f850a 100644 --- a/tripleo_common/tests/utils/test_nodes.py +++ b/tripleo_common/tests/utils/test_nodes.py @@ -190,7 +190,8 @@ class NodesTest(base.TestCase): 'pm_password': 'random', 'pm_type': 'pxe_ssh', 'name': 'node1', 'capabilities': 'num_nics:6'} - def test_register_all_nodes_ironic_no_hw_stats(self): + @mock.patch('tripleo_common.utils.nodes.run_nova_cell_v2_discovery') + def test_register_all_nodes_ironic_no_hw_stats(self, mock_discovery): node_list = [self._get_node()] # Remove the hardware stats from the node dictionary @@ -218,8 +219,10 @@ class NodesTest(base.TestCase): address='aaa') ironic.node.create.assert_has_calls([pxe_node, mock.ANY]) ironic.port.create.assert_has_calls([port_call]) + mock_discovery.assert_called_once() - def test_register_all_nodes(self): + @mock.patch('tripleo_common.utils.nodes.run_nova_cell_v2_discovery') + def test_register_all_nodes(self, mock_discovery): node_list = [self._get_node()] node_properties = {"cpus": "1", "memory_mb": "2048", @@ -240,8 +243,10 @@ class NodesTest(base.TestCase): address='aaa') ironic.node.create.assert_has_calls([pxe_node, mock.ANY]) ironic.port.create.assert_has_calls([port_call]) + mock_discovery.assert_called_once() - def test_register_all_nodes_kernel_ramdisk(self): + @mock.patch('tripleo_common.utils.nodes.run_nova_cell_v2_discovery') + def test_register_all_nodes_kernel_ramdisk(self, mock_discovery): node_list = [self._get_node()] node_properties = {"cpus": "1", "memory_mb": "2048", @@ -270,8 +275,10 @@ class NodesTest(base.TestCase): address='aaa') ironic.node.create.assert_has_calls([pxe_node, mock.ANY]) ironic.port.create.assert_has_calls([port_call]) + mock_discovery.assert_called_once() - def test_register_all_nodes_uuid(self): + @mock.patch('tripleo_common.utils.nodes.run_nova_cell_v2_discovery') + def test_register_all_nodes_uuid(self, mock_discovery): node_list = [self._get_node()] node_list[0]['uuid'] = 'abcdef' node_properties = {"cpus": "1", @@ -294,8 +301,10 @@ class NodesTest(base.TestCase): address='aaa') ironic.node.create.assert_has_calls([pxe_node, mock.ANY]) ironic.port.create.assert_has_calls([port_call]) + mock_discovery.assert_called_once() - def test_register_all_nodes_caps_dict(self): + @mock.patch('tripleo_common.utils.nodes.run_nova_cell_v2_discovery') + def test_register_all_nodes_caps_dict(self, mock_discovery): node_list = [self._get_node()] node_list[0]['capabilities'] = { 'num_nics': 7 @@ -319,6 +328,7 @@ class NodesTest(base.TestCase): address='aaa') ironic.node.create.assert_has_calls([pxe_node, mock.ANY]) ironic.port.create.assert_has_calls([port_call]) + mock_discovery.assert_called_once() def test_register_update(self): node = self._get_node() diff --git a/tripleo_common/utils/nodes.py b/tripleo_common/utils/nodes.py index 50fd28423..503e5805d 100644 --- a/tripleo_common/utils/nodes.py +++ b/tripleo_common/utils/nodes.py @@ -18,6 +18,7 @@ import re import six +from oslo_concurrency import processutils from tripleo_common import exception from tripleo_common.utils import glance @@ -381,6 +382,7 @@ def register_all_nodes(nodes_list, client, remove=False, glance_client=None, seen.append(node) _clean_up_extra_nodes(seen, client, remove=remove) + run_nova_cell_v2_discovery() return seen @@ -443,3 +445,12 @@ def generate_hostmap(baremetal_client, compute_client): hostmap[port.address] = {"compute_name": node.name, "baremetal_name": bm_node.name} return hostmap + + +def run_nova_cell_v2_discovery(): + return processutils.execute( + '/usr/bin/sudo', + '/bin/nova-manage', + 'cell_v2', + 'discover_hosts' + )