Merge "Map instance to its node"
This commit is contained in:
@@ -40,8 +40,9 @@ class NovaNotification(base.NotificationEndpoint):
|
|||||||
|
|
||||||
def get_or_create_instance(self, instance_uuid, node_uuid=None):
|
def get_or_create_instance(self, instance_uuid, node_uuid=None):
|
||||||
try:
|
try:
|
||||||
|
node = None
|
||||||
if node_uuid:
|
if node_uuid:
|
||||||
self.get_or_create_node(node_uuid)
|
node = self.get_or_create_node(node_uuid)
|
||||||
except exception.ComputeNodeNotFound:
|
except exception.ComputeNodeNotFound:
|
||||||
LOG.warning("Could not find compute node %(node)s for "
|
LOG.warning("Could not find compute node %(node)s for "
|
||||||
"instance %(instance)s",
|
"instance %(instance)s",
|
||||||
@@ -55,6 +56,8 @@ class NovaNotification(base.NotificationEndpoint):
|
|||||||
instance = element.Instance(uuid=instance_uuid)
|
instance = element.Instance(uuid=instance_uuid)
|
||||||
|
|
||||||
self.cluster_data_model.add_instance(instance)
|
self.cluster_data_model.add_instance(instance)
|
||||||
|
if node:
|
||||||
|
self.cluster_data_model.map_instance(instance, node)
|
||||||
|
|
||||||
return instance
|
return instance
|
||||||
|
|
||||||
|
|||||||
@@ -332,7 +332,24 @@ class TestNovaNotifications(NotificationTestCase):
|
|||||||
exception.ComputeNodeNotFound,
|
exception.ComputeNodeNotFound,
|
||||||
compute_model.get_node_by_uuid, 'Node_2')
|
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()
|
compute_model = self.fake_cdmc.generate_scenario_3_with_2_nodes()
|
||||||
self.fake_cdmc.cluster_data_model = compute_model
|
self.fake_cdmc.cluster_data_model = compute_model
|
||||||
handler = novanotification.VersionedNotification(self.fake_cdmc)
|
handler = novanotification.VersionedNotification(self.fake_cdmc)
|
||||||
@@ -352,7 +369,14 @@ class TestNovaNotifications(NotificationTestCase):
|
|||||||
metadata=self.FAKE_METADATA,
|
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(element.InstanceState.ACTIVE.value, instance0.state)
|
||||||
self.assertEqual(1, instance0.vcpus)
|
self.assertEqual(1, instance0.vcpus)
|
||||||
|
|||||||
Reference in New Issue
Block a user