]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
[scheduler][tests]: Fix incorrect aggr mock values
authorPavel Kholkin <pkholkin@mirantis.com>
Fri, 25 Nov 2016 15:58:23 +0000 (18:58 +0300)
committerPavel Kholkin <pkholkin@mirantis.com>
Fri, 25 Nov 2016 16:54:15 +0000 (19:54 +0300)
Currently the value return from 'utils.aggregate_metadata_get_by_host'
is a type of collections.defaultdict(set). That said all the values
are 'set' not 'String'. Unfortunately, most of test cases related to
aggregate filters are using it with in incorrect way. This patch fixes
it and adds an extra test case to verify it.

Co-Authored-By: Fei Long Wang <flwang@catalyst.net.nz>
Change-Id: I12f033a66ed31cd624bda47be944bab6c841dbf5

nova/tests/unit/scheduler/filters/test_aggregate_image_properties_isolation_filters.py
nova/tests/unit/scheduler/filters/test_aggregate_instance_extra_specs_filters.py
nova/tests/unit/scheduler/filters/test_availability_zone_filters.py

index 89b739b0404681310bba4336a0dd0de418bb7801..f17a7168f19e074629449ff8a262ebd020a2b4ff 100644 (file)
@@ -26,7 +26,7 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
         self.filt_cls = aipi.AggregateImagePropertiesIsolation()
 
     def test_aggregate_image_properties_isolation_passes(self, agg_mock):
-        agg_mock.return_value = {'hw_vm_mode': 'hvm'}
+        agg_mock.return_value = {'hw_vm_mode': set(['hvm'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -35,7 +35,7 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
         self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
 
     def test_aggregate_image_properties_isolation_passes_comma(self, agg_mock):
-        agg_mock.return_value = {'hw_vm_mode': 'hvm,xen'}
+        agg_mock.return_value = {'hw_vm_mode': set(['hvm', 'xen'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -43,9 +43,20 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
         host = fakes.FakeHostState('host1', 'compute', {})
         self.assertTrue(self.filt_cls.host_passes(host, spec_obj))
 
+    def test_aggregate_image_properties_isolation_props_bad_comma(self,
+            agg_mock):
+        agg_mock.return_value = {'os_distro': set(['windows', 'linux'])}
+        spec_obj = objects.RequestSpec(
+            context=mock.sentinel.ctx,
+            image=objects.ImageMeta(properties=objects.ImageMetaProps(
+                os_distro='windows,')))
+        host = fakes.FakeHostState('host1', 'compute', {})
+        self.assertFalse(self.filt_cls.host_passes(host, spec_obj))
+
     def test_aggregate_image_properties_isolation_multi_props_passes(self,
             agg_mock):
-        agg_mock.return_value = {'hw_vm_mode': 'hvm', 'hw_cpu_cores': '2'}
+        agg_mock.return_value = {'hw_vm_mode': set(['hvm']),
+                                 'hw_cpu_cores': set(['2'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -55,7 +66,7 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
 
     def test_aggregate_image_properties_isolation_props_with_meta_passes(self,
             agg_mock):
-        agg_mock.return_value = {'hw_vm_mode': 'hvm'}
+        agg_mock.return_value = {'hw_vm_mode': set(['hvm'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps()))
@@ -74,7 +85,7 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
 
     def test_aggregate_image_properties_isolation_props_not_match_fails(self,
             agg_mock):
-        agg_mock.return_value = {'hw_vm_mode': 'hvm'}
+        agg_mock.return_value = {'hw_vm_mode': set(['hvm'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -84,7 +95,8 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
 
     def test_aggregate_image_properties_isolation_props_not_match2_fails(self,
             agg_mock):
-        agg_mock.return_value = {'hw_vm_mode': 'hvm', 'hw_cpu_cores': '1'}
+        agg_mock.return_value = {'hw_vm_mode': set(['hvm']),
+                                 'hw_cpu_cores': set(['1'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -98,7 +110,8 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
                    group='filter_scheduler')
         self.flags(aggregate_image_properties_isolation_separator='_',
                    group='filter_scheduler')
-        agg_mock.return_value = {'hw_vm_mode': 'hvm', 'img_owner_id': 'foo'}
+        agg_mock.return_value = {'hw_vm_mode': set(['hvm']),
+                                 'img_owner_id': set(['foo'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -108,7 +121,7 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
 
     def test_aggregate_image_properties_iso_props_with_custom_meta(self,
             agg_mock):
-        agg_mock.return_value = {'os': 'linux'}
+        agg_mock.return_value = {'os': set(['linux'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -118,7 +131,7 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
 
     def test_aggregate_image_properties_iso_props_with_matching_meta_pass(self,
             agg_mock):
-        agg_mock.return_value = {'os_type': 'linux'}
+        agg_mock.return_value = {'os_type': set(['linux'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
@@ -128,7 +141,7 @@ class TestAggImagePropsIsolationFilter(test.NoDBTestCase):
 
     def test_aggregate_image_properties_iso_props_with_matching_meta_fail(
             self, agg_mock):
-        agg_mock.return_value = {'os_type': 'windows'}
+        agg_mock.return_value = {'os_type': set(['windows'])}
         spec_obj = objects.RequestSpec(
             context=mock.sentinel.ctx,
             image=objects.ImageMeta(properties=objects.ImageMetaProps(
index 51d1cab12f485b492a11aa7e37393b969f4f8b2f..22884bbaa9f4a21ba26394740b8eb93b5288e130 100644 (file)
@@ -55,7 +55,7 @@ class TestAggregateInstanceExtraSpecsFilter(test.NoDBTestCase):
         assertion(self.filt_cls.host_passes(host, spec_obj))
 
     def test_aggregate_filter_passes_extra_specs_simple(self, agg_mock):
-        agg_mock.return_value = {'opt1': '1', 'opt2': '2'}
+        agg_mock.return_value = {'opt1': set(['1']), 'opt2': set(['2'])}
         especs = {
             # Un-scoped extra spec
             'opt1': '1',
@@ -67,7 +67,7 @@ class TestAggregateInstanceExtraSpecsFilter(test.NoDBTestCase):
         self._do_test_aggregate_filter_extra_specs(especs, passes=True)
 
     def test_aggregate_filter_passes_extra_specs_simple_comma(self, agg_mock):
-        agg_mock.return_value = {'opt1': '1,3', 'opt2': '2'}
+        agg_mock.return_value = {'opt1': set(['1', '3']), 'opt2': set(['2'])}
         especs = {
             # Un-scoped extra spec
             'opt1': '1',
@@ -79,7 +79,7 @@ class TestAggregateInstanceExtraSpecsFilter(test.NoDBTestCase):
         self._do_test_aggregate_filter_extra_specs(especs, passes=True)
 
     def test_aggregate_filter_passes_with_key_same_as_scope(self, agg_mock):
-        agg_mock.return_value = {'aggregate_instance_extra_specs': '1'}
+        agg_mock.return_value = {'aggregate_instance_extra_specs': set(['1'])}
         especs = {
             # Un-scoped extra spec, make sure we don't blow up if it
             # happens to match our scope.
@@ -88,7 +88,7 @@ class TestAggregateInstanceExtraSpecsFilter(test.NoDBTestCase):
         self._do_test_aggregate_filter_extra_specs(especs, passes=True)
 
     def test_aggregate_filter_fails_extra_specs_simple(self, agg_mock):
-        agg_mock.return_value = {'opt1': '1', 'opt2': '2'}
+        agg_mock.return_value = {'opt1': set(['1']), 'opt2': set(['2'])}
         especs = {
             'opt1': '1',
             'opt2': '222',
index ae26674616b67eca2aeb578bd1d5244f7bf71a60..2c1a43225e985e6d435225adb9fe29e010a22e83 100644 (file)
@@ -32,19 +32,19 @@ class TestAvailabilityZoneFilter(test.NoDBTestCase):
             availability_zone=zone)
 
     def test_availability_zone_filter_same(self, agg_mock):
-        agg_mock.return_value = {'availability_zone': 'nova'}
+        agg_mock.return_value = {'availability_zone': set(['nova'])}
         request = self._make_zone_request('nova')
         host = fakes.FakeHostState('host1', 'node1', {})
         self.assertTrue(self.filt_cls.host_passes(host, request))
 
     def test_availability_zone_filter_same_comma(self, agg_mock):
-        agg_mock.return_value = {'availability_zone': 'nova,nova2'}
+        agg_mock.return_value = {'availability_zone': set(['nova', 'nova2'])}
         request = self._make_zone_request('nova')
         host = fakes.FakeHostState('host1', 'node1', {})
         self.assertTrue(self.filt_cls.host_passes(host, request))
 
     def test_availability_zone_filter_different(self, agg_mock):
-        agg_mock.return_value = {'availability_zone': 'nova'}
+        agg_mock.return_value = {'availability_zone': set(['nova'])}
         request = self._make_zone_request('bad')
         host = fakes.FakeHostState('host1', 'node1', {})
         self.assertFalse(self.filt_cls.host_passes(host, request))