def test_nova_cdmc_execute(self, m_nova_helper_cls): m_nova_helper = mock.Mock(name="nova_helper") m_nova_helper_cls.return_value = m_nova_helper m_nova_helper.get_service.return_value = mock.Mock( id=1355, host='test_hostname', binary='nova-compute', status='enabled', state='up', disabled_reason='', ) fake_compute_node = mock.Mock( id=1337, service={'id': 123}, hypervisor_hostname='test_hostname', memory_mb=333, free_disk_gb=222, local_gb=111, vcpus=4, state='TEST_STATE', status='TEST_STATUS', ) fake_instance = mock.Mock( id='ef500f7e-dac8-470f-960c-169486fce71b', human_id='fake_instance', flavor={ 'ram': 333, 'disk': 222, 'vcpus': 4, 'id': 1 }, metadata={'hi': 'hello'}, tenant_id='ff560f7e-dbc8-771f-960c-164482fce21b', ) setattr(fake_instance, 'OS-EXT-STS:vm_state', 'VM_STATE') setattr(fake_instance, 'OS-EXT-SRV-ATTR:host', 'test_hostname') m_nova_helper.get_compute_node_list.return_value = [fake_compute_node] # m_nova_helper.get_instances_by_node.return_value = [fake_instance] m_nova_helper.get_instance_list.return_value = [fake_instance] m_config = mock.Mock() m_osc = mock.Mock() nova_cdmc = nova.NovaClusterDataModelCollector(config=m_config, osc=m_osc) model = nova_cdmc.execute() compute_nodes = model.get_all_compute_nodes() instances = model.get_all_instances() self.assertEqual(1, len(compute_nodes)) self.assertEqual(1, len(instances)) node = list(compute_nodes.values())[0] instance = list(instances.values())[0] self.assertEqual(node.uuid, 'test_hostname') self.assertEqual(instance.uuid, 'ef500f7e-dac8-470f-960c-169486fce71b')
def test_nova_cdmc_execute(self, m_nova_helper_cls): m_nova_helper = mock.Mock(name="nova_helper") m_nova_helper_cls.return_value = m_nova_helper m_nova_helper.get_service.return_value = mock.Mock( host="test_hostname") fake_compute_node = mock.Mock( id=1337, service={'id': 123}, hypervisor_hostname='test_hostname', memory_mb=333, free_disk_gb=222, local_gb=111, vcpus=4, state='TEST_STATE', status='TEST_STATUS', ) fake_instance = mock.Mock( id='ef500f7e-dac8-470f-960c-169486fce71b', human_id='fake_instance', flavor={ 'ram': 333, 'disk': 222, 'vcpus': 4, 'id': 1 }, ) setattr(fake_instance, 'OS-EXT-STS:vm_state', 'VM_STATE') m_nova_helper.get_compute_node_list.return_value = [fake_compute_node] # m_nova_helper.get_instances_by_node.return_value = [fake_instance] m_nova_helper.get_instance_list.return_value = [fake_instance] m_nova_helper.get_flavor.return_value = utils.Struct(**{ 'ram': 333, 'disk': 222, 'vcpus': 4 }) m_config = mock.Mock() m_osc = mock.Mock() nova_cdmc = nova.NovaClusterDataModelCollector(config=m_config, osc=m_osc) model = nova_cdmc.execute() compute_nodes = model.get_all_compute_nodes() instances = model.get_all_instances() self.assertEqual(1, len(compute_nodes)) self.assertEqual(1, len(instances)) node = list(compute_nodes.values())[0] instance = list(instances.values())[0] self.assertEqual(node.uuid, 'test_hostname') self.assertEqual(instance.uuid, 'ef500f7e-dac8-470f-960c-169486fce71b')
def test_nova_cdmc_execute(self, m_nova_helper_cls): m_nova_helper = mock.Mock() m_nova_helper_cls.return_value = m_nova_helper fake_compute_node = mock.Mock( service={'id': 123}, hypervisor_hostname='test_hostname', memory_mb=333, free_disk_gb=222, local_gb=111, vcpus=4, state='TEST_STATE', status='TEST_STATUS', ) fake_instance = mock.Mock( id='ef500f7e-dac8-470f-960c-169486fce71b', state=mock.Mock(**{'OS-EXT-STS:vm_state': 'VM_STATE'}), flavor={ 'ram': 333, 'disk': 222, 'vcpus': 4 }, ) m_nova_helper.get_compute_node_list.return_value = [fake_compute_node] m_nova_helper.get_instances_by_node.return_value = [fake_instance] m_nova_helper.nova.services.find.return_value = mock.Mock( host='test_hostname') def m_get_flavor_instance(instance, cache): instance.flavor = {'ram': 333, 'disk': 222, 'vcpus': 4} return instance m_nova_helper.get_flavor_instance.side_effect = m_get_flavor_instance m_config = mock.Mock() m_osc = mock.Mock() nova_cdmc = nova.NovaClusterDataModelCollector(config=m_config, osc=m_osc) model = nova_cdmc.execute() compute_nodes = model.get_all_compute_nodes() instances = model.get_all_instances() self.assertEqual(1, len(compute_nodes)) self.assertEqual(1, len(instances)) node = list(compute_nodes.values())[0] instance = list(instances.values())[0] self.assertEqual(node.uuid, 'test_hostname') self.assertEqual(instance.uuid, 'ef500f7e-dac8-470f-960c-169486fce71b')
def test_nova_cdmc_execute(self, m_nova_helper_cls, m_placement_helper_cls): m_placement_helper = mock.Mock(name="placement_helper") m_placement_helper.get_inventories.return_value = { orc.VCPU: { "allocation_ratio": 16.0, "total": 8, "reserved": 0, "step_size": 1, "min_unit": 1, "max_unit": 8}, orc.MEMORY_MB: { "allocation_ratio": 1.5, "total": 16039, "reserved": 512, "step_size": 1, "min_unit": 1, "max_unit": 16039}, orc.DISK_GB: { "allocation_ratio": 1.0, "total": 142, "reserved": 0, "step_size": 1, "min_unit": 1, "max_unit": 142} } m_placement_helper.get_usages_for_resource_provider.return_value = { orc.DISK_GB: 10, orc.MEMORY_MB: 100, orc.VCPU: 0 } m_placement_helper_cls.return_value = m_placement_helper m_nova_helper = mock.Mock(name="nova_helper") m_nova_helper_cls.return_value = m_nova_helper m_nova_helper.get_service.return_value = mock.Mock( id=1355, host='test_hostname', binary='nova-compute', status='enabled', state='up', disabled_reason='', ) minimal_node = dict( id='160a0e7b-8b0b-4854-8257-9c71dff4efcc', hypervisor_hostname='test_hostname', state='TEST_STATE', status='TEST_STATUS', ) minimal_node_with_servers = dict( servers=[ {'name': 'fake_instance', 'uuid': 'ef500f7e-dac8-470f-960c-169486fce71b'} ], **minimal_node ) fake_compute_node = mock.Mock( service={'id': 123, 'host': 'test_hostname', 'disabled_reason': ''}, memory_mb=333, memory_mb_used=100, free_disk_gb=222, local_gb=111, local_gb_used=10, vcpus=4, vcpus_used=0, servers=None, # Don't let the mock return a value for servers. **minimal_node ) fake_detailed_node = mock.Mock( service={'id': 123, 'host': 'test_hostname', 'disabled_reason': ''}, memory_mb=333, memory_mb_used=100, free_disk_gb=222, local_gb=111, local_gb_used=10, vcpus=4, vcpus_used=0, **minimal_node_with_servers) fake_instance = mock.Mock( id='ef500f7e-dac8-470f-960c-169486fce71b', name='fake_instance', flavor={'ram': 333, 'disk': 222, 'vcpus': 4, 'id': 1}, metadata={'hi': 'hello'}, tenant_id='ff560f7e-dbc8-771f-960c-164482fce21b', ) setattr(fake_instance, 'OS-EXT-STS:vm_state', 'VM_STATE') setattr(fake_instance, 'name', 'fake_instance') # Returns the hypervisors with details (service) but no servers. m_nova_helper.get_compute_node_list.return_value = [fake_compute_node] # Returns the hypervisor with servers and details (service). m_nova_helper.get_compute_node_by_name.return_value = [ fake_detailed_node] # Returns the hypervisor with details (service) but no servers. m_nova_helper.get_instance_list.return_value = [fake_instance] m_config = mock.Mock() m_osc = mock.Mock() nova_cdmc = nova.NovaClusterDataModelCollector( config=m_config, osc=m_osc) nova_cdmc.get_audit_scope_handler([]) model = nova_cdmc.execute() compute_nodes = model.get_all_compute_nodes() instances = model.get_all_instances() self.assertEqual(1, len(compute_nodes)) self.assertEqual(1, len(instances)) node = list(compute_nodes.values())[0] instance = list(instances.values())[0] self.assertEqual(node.uuid, '160a0e7b-8b0b-4854-8257-9c71dff4efcc') self.assertEqual(instance.uuid, 'ef500f7e-dac8-470f-960c-169486fce71b') memory_total = (node.memory-node.memory_mb_reserved)*node.memory_ratio self.assertEqual(node.memory_mb_capacity, memory_total) disk_total = (node.disk-node.disk_gb_reserved)*node.disk_ratio self.assertEqual(node.disk_gb_capacity, disk_total) vcpus_total = (node.vcpus-node.vcpu_reserved)*node.vcpu_ratio self.assertEqual(node.vcpu_capacity, vcpus_total) m_nova_helper.get_compute_node_by_name.assert_called_once_with( minimal_node['hypervisor_hostname'], servers=True, detailed=True) m_nova_helper.get_instance_list.assert_called_once_with( filters={'host': fake_compute_node.service['host']}, limit=1)