Map instance to its node

When receiving Nova notification instance.create.end,
map instance to its node after adding instance to datamodel.
Related-Bug: #1832156

Change-Id: I6f39e8d935195c611f668f71590e1d9ff52ced0d
This commit is contained in:
licanwei 2019-06-06 16:39:42 +08:00
parent 7f37f7b92a
commit 79a57f67e6
2 changed files with 30 additions and 3 deletions

View File

@ -40,8 +40,9 @@ class NovaNotification(base.NotificationEndpoint):
def get_or_create_instance(self, instance_uuid, node_uuid=None):
try:
node = None
if node_uuid:
self.get_or_create_node(node_uuid)
node = self.get_or_create_node(node_uuid)
except exception.ComputeNodeNotFound:
LOG.warning("Could not find compute node %(node)s for "
"instance %(instance)s",
@ -55,6 +56,8 @@ class NovaNotification(base.NotificationEndpoint):
instance = element.Instance(uuid=instance_uuid)
self.cluster_data_model.add_instance(instance)
if node:
self.cluster_data_model.map_instance(instance, node)
return instance

View File

@ -332,7 +332,24 @@ class TestNovaNotifications(NotificationTestCase):
exception.ComputeNodeNotFound,
compute_model.get_node_by_uuid, 'Node_2')
def test_nova_instance_create(self):
@mock.patch.object(nova_helper, 'NovaHelper')
def test_nova_instance_create(self, m_nova_helper_cls):
m_get_compute_node_by_hostname = mock.Mock(
side_effect=lambda uuid: mock.Mock(
name='m_get_compute_node_by_hostname',
id=3,
hypervisor_hostname="compute",
state='up',
status='enabled',
uuid=uuid,
memory_mb=7777,
vcpus=42,
free_disk_gb=974,
local_gb=1337))
m_nova_helper_cls.return_value = mock.Mock(
get_compute_node_by_hostname=m_get_compute_node_by_hostname,
name='m_nova_helper')
compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes()
self.fake_cdmc.cluster_data_model = compute_model
handler = novanotification.VersionedNotification(self.fake_cdmc)
@ -352,7 +369,14 @@ class TestNovaNotifications(NotificationTestCase):
metadata=self.FAKE_METADATA,
)
instance0 = compute_model.get_instance_by_uuid(instance0_uuid)
hostname = message['payload']['nova_object.data']['host']
node = self.fake_cdmc.cluster_data_model.get_node_by_instance_uuid(
instance0_uuid)
self.assertEqual(hostname, node.hostname)
m_get_compute_node_by_hostname.assert_called_once_with(hostname)
instance0 = self.fake_cdmc.cluster_data_model.get_instance_by_uuid(
instance0_uuid)
self.assertEqual(element.InstanceState.ACTIVE.value, instance0.state)
self.assertEqual(1, instance0.vcpus)