From 9be3801e5bd3a73208485354d8370104792ef35c Mon Sep 17 00:00:00 2001 From: John Griffith Date: Mon, 21 Jan 2013 21:50:20 -0700 Subject: [PATCH] Check for installed cinder in filter tests. Some of the filter tests require that the cinder pkg is installed on the system, specifically cinder.egg-info/entry_points. This change check that the egg-info directory exists in the root cinder directory and determines whether to skip or not. Change-Id: I36145f170e802aed5dfae8eec4684e60ad3d6f2c --- cinder/tests/scheduler/test_capacity_weigher.py | 7 +++++++ cinder/tests/scheduler/test_filter_scheduler.py | 13 +++++++++---- cinder/tests/scheduler/test_host_filters.py | 5 +++++ cinder/tests/utils.py | 11 +++++++++-- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/cinder/tests/scheduler/test_capacity_weigher.py b/cinder/tests/scheduler/test_capacity_weigher.py index 471364f9c..a569ff255 100644 --- a/cinder/tests/scheduler/test_capacity_weigher.py +++ b/cinder/tests/scheduler/test_capacity_weigher.py @@ -20,6 +20,7 @@ from cinder import context from cinder.openstack.common.scheduler.weights import HostWeightHandler from cinder import test from cinder.tests.scheduler import fakes +from cinder.tests import utils as test_utils class CapacityWeigherTestCase(test.TestCase): @@ -45,6 +46,8 @@ class CapacityWeigherTestCase(test.TestCase): self.mox.ResetAll() return host_states + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed') def test_default_of_spreading_first(self): hostinfo_list = self._get_all_hosts() @@ -58,6 +61,8 @@ class CapacityWeigherTestCase(test.TestCase): self.assertEqual(weighed_host.weight, 921.0) self.assertEqual(weighed_host.obj.host, 'host1') + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed') def test_capacity_weight_multiplier1(self): self.flags(capacity_weight_multiplier=-1.0) hostinfo_list = self._get_all_hosts() @@ -72,6 +77,8 @@ class CapacityWeigherTestCase(test.TestCase): self.assertEqual(weighed_host.weight, -190.0) self.assertEqual(weighed_host.obj.host, 'host4') + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed') def test_capacity_weight_multiplier2(self): self.flags(capacity_weight_multiplier=2.0) hostinfo_list = self._get_all_hosts() diff --git a/cinder/tests/scheduler/test_filter_scheduler.py b/cinder/tests/scheduler/test_filter_scheduler.py index 6f56575f7..064c27461 100644 --- a/cinder/tests/scheduler/test_filter_scheduler.py +++ b/cinder/tests/scheduler/test_filter_scheduler.py @@ -16,16 +16,15 @@ Tests For Filter Scheduler. """ -import mox - from cinder import context from cinder import exception +from cinder import test + from cinder.openstack.common.scheduler import weights -from cinder.scheduler import driver from cinder.scheduler import filter_scheduler -from cinder.scheduler import host_manager from cinder.tests.scheduler import fakes from cinder.tests.scheduler import test_scheduler +from cinder.tests import utils as test_utils def fake_get_filtered_hosts(hosts, filter_properties): @@ -37,6 +36,8 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): driver_cls = filter_scheduler.FilterScheduler + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed (try setup.py develop') def test_create_volume_no_hosts(self): """ Ensure empty hosts & child_zones result in NoValidHosts exception. @@ -54,6 +55,8 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): self.assertRaises(exception.NoValidHost, sched.schedule_create_volume, fake_context, request_spec, None) + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed (try setup.py develop') def test_create_volume_non_admin(self): """Test creating an instance locally using run_instance, passing a non-admin context. DB actions should work.""" @@ -78,6 +81,8 @@ class FilterSchedulerTestCase(test_scheduler.SchedulerTestCase): fake_context, request_spec, None) self.assertTrue(self.was_admin) + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed (try setup.py develop') def test_schedule_happy_day(self): """Make sure there's nothing glaringly wrong with _schedule() by doing a happy day pass through.""" diff --git a/cinder/tests/scheduler/test_host_filters.py b/cinder/tests/scheduler/test_host_filters.py index 5bcffd63c..76b808b6a 100644 --- a/cinder/tests/scheduler/test_host_filters.py +++ b/cinder/tests/scheduler/test_host_filters.py @@ -25,6 +25,7 @@ from cinder.openstack.common import jsonutils from cinder.openstack.common.scheduler import filters from cinder import test from cinder.tests.scheduler import fakes +from cinder.tests import utils as test_utils from cinder import utils @@ -75,6 +76,8 @@ class HostFiltersTestCase(test.TestCase): return ret_value self.stubs.Set(utils, 'service_is_up', fake_service_is_up) + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed') def test_capacity_filter_passes(self): self._stub_service_is_up(True) filt_cls = self.class_map['CapacityFilter']() @@ -86,6 +89,8 @@ class HostFiltersTestCase(test.TestCase): 'service': service}) self.assertTrue(filt_cls.host_passes(host, filter_properties)) + @test.skip_if(not test_utils.is_cinder_installed(), + 'Test requires Cinder installed') def test_capacity_filter_fails(self): self._stub_service_is_up(True) filt_cls = self.class_map['CapacityFilter']() diff --git a/cinder/tests/utils.py b/cinder/tests/utils.py index 5b9086b75..221e6b097 100644 --- a/cinder/tests/utils.py +++ b/cinder/tests/utils.py @@ -14,12 +14,19 @@ # License for the specific language governing permissions and limitations # +import os + import cinder.context -import cinder.db -import cinder.flags FLAGS = cinder.flags.FLAGS def get_test_admin_context(): return cinder.context.get_admin_context() + + +def is_cinder_installed(): + if os.path.exists('../../cinder.cinder.egg-info'): + return True + else: + return False -- 2.45.2