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
This commit is contained in:
Oliver Walsh 2017-01-25 15:28:40 +00:00
parent 5d977af0ac
commit 185546cfa5
4 changed files with 32 additions and 5 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
Run ``nova-manage cell_v2 discover_hosts`` when any baremetal nodes are
registered with the undercloud.

View File

@ -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

View File

@ -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()

View File

@ -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'
)