From d3f99a10068560e9f8031b0681e16df3715e2081 Mon Sep 17 00:00:00 2001 From: Jay Pipes Date: Sat, 21 May 2016 23:35:08 -0400 Subject: [PATCH] Remove tests for missing get_available_resource() There are no virt drivers that do not return a dict of resources information in the virt driver get_available_resource() call. This means the unit tests that validate that the resource tracker doesn't do anything if nothing is returned from the get_available_resource() are pointless. We remove the code in the resource tracker that tests to see if None is returned by the virt driver's get_available_resource() call because no virt driver actually does this. It's just bloat code. Change-Id: I66739c05d894a0d6234eda3bdf450acc49e99166 --- nova/compute/resource_tracker.py | 7 -- .../unit/compute/test_resource_tracker.py | 77 ------------------- 2 files changed, 84 deletions(-) diff --git a/nova/compute/resource_tracker.py b/nova/compute/resource_tracker.py index ede167e2da8e..c3aaf202068e 100644 --- a/nova/compute/resource_tracker.py +++ b/nova/compute/resource_tracker.py @@ -456,13 +456,6 @@ class ResourceTracker(object): "node %(node)s"), {'node': self.nodename}) resources = self.driver.get_available_resource(self.nodename) - - if not resources: - # The virt driver does not support this function - LOG.info(_LI("Virt driver does not support " - "'get_available_resource'. Compute tracking is disabled.")) - self.compute_node = None - return resources['host_ip'] = CONF.my_ip # We want the 'cpu_info' to be None from the POV of the diff --git a/nova/tests/unit/compute/test_resource_tracker.py b/nova/tests/unit/compute/test_resource_tracker.py index 367729950bb2..82d02c4f9a95 100644 --- a/nova/tests/unit/compute/test_resource_tracker.py +++ b/nova/tests/unit/compute/test_resource_tracker.py @@ -66,20 +66,6 @@ FAKE_VIRT_STATS_JSON = jsonutils.dumps(FAKE_VIRT_STATS) CONF = cfg.CONF -class UnsupportedVirtDriver(driver.ComputeDriver): - """Pretend version of a lame virt driver.""" - - def __init__(self): - super(UnsupportedVirtDriver, self).__init__(None) - - def get_host_ip_addr(self): - return '127.0.0.1' - - def get_available_resource(self, nodename): - # no support for getting resource usage info - return {} - - class FakeVirtDriver(driver.ComputeDriver): def __init__(self, pci_support=False, stats=None, @@ -441,69 +427,6 @@ class BaseTestCase(test.TestCase): return tracker -class UnsupportedDriverTestCase(BaseTestCase): - """Resource tracking should be disabled when the virt driver doesn't - support it. - """ - def setUp(self): - super(UnsupportedDriverTestCase, self).setUp() - self.tracker = self._tracker() - # seed tracker with data: - self.tracker.update_available_resource(self.context) - - def _driver(self): - return UnsupportedVirtDriver() - - def test_disabled(self): - # disabled = no compute node stats - self.assertTrue(self.tracker.disabled) - self.assertIsNone(self.tracker.compute_node) - - def test_disabled_claim(self): - # basic claim: - instance = self._fake_instance_obj() - with mock.patch.object(instance, 'save'): - claim = self.tracker.instance_claim(self.context, instance) - self.assertEqual(0, claim.memory_mb) - - def test_disabled_instance_claim(self): - # instance variation: - instance = self._fake_instance_obj() - with mock.patch.object(instance, 'save'): - claim = self.tracker.instance_claim(self.context, instance) - self.assertEqual(0, claim.memory_mb) - - @mock.patch('nova.objects.Instance.save') - def test_disabled_instance_context_claim(self, mock_save): - # instance context manager variation: - instance = self._fake_instance_obj() - self.tracker.instance_claim(self.context, instance) - with self.tracker.instance_claim(self.context, instance) as claim: - self.assertEqual(0, claim.memory_mb) - - def test_disabled_updated_usage(self): - instance = self._fake_instance_obj(host='fakehost', memory_mb=5, - root_gb=10) - self.tracker.update_usage(self.context, instance) - - def test_disabled_resize_claim(self): - instance = self._fake_instance_obj() - instance_type = self._fake_flavor_create() - claim = self.tracker.resize_claim(self.context, instance, - instance_type) - self.assertEqual(0, claim.memory_mb) - self.assertEqual(instance['uuid'], claim.migration['instance_uuid']) - self.assertEqual(instance_type['id'], - claim.migration['new_instance_type_id']) - - def test_disabled_resize_context_claim(self): - instance = self._fake_instance_obj() - instance_type = self._fake_flavor_create() - with self.tracker.resize_claim(self.context, instance, instance_type) \ - as claim: - self.assertEqual(0, claim.memory_mb) - - class MissingComputeNodeTestCase(BaseTestCase): def setUp(self): super(MissingComputeNodeTestCase, self).setUp()