Move Destination object tests to their own test class

The TestDestinationObject class has been added
since Ic2bcee40b41c97170a8603b27b935113f0633de7.
The following test methods in the _TestRequestSpecObject class are for
the Destination object.

- test_destination_aggregates_default
- test_destination_require_aggregates
- test_destination_obj_make_compatible
- test_destination_forbidden_aggregates_default
- test_destination_append_forbidden_aggregates
- test_destination_delete_forbidden_aggregates

They should be moved to their own test class,
so move them to the test class.
In addition, some methods are merged into one test method.

Change-Id: I0bd9d44a61f16a703cd9c850d13d1f8f35e81ad7
This commit is contained in:
Takashi NATSUME 2019-09-19 11:13:46 +09:00
parent 1a226aaa9e
commit 6725da92bd
1 changed files with 50 additions and 55 deletions

View File

@ -888,29 +888,6 @@ class _TestRequestSpecObject(object):
objects.NetworkMetadata)
self.assertIn('network_metadata', req_obj)
def test_destination_aggregates_default(self):
destination = objects.Destination()
self.assertIsNone(destination.aggregates)
def test_destination_require_aggregates(self):
destination = objects.Destination()
destination.require_aggregates(['foo', 'bar'])
destination.require_aggregates(['baz'])
self.assertEqual(['foo,bar', 'baz'], destination.aggregates)
def test_destination_obj_make_compatible(self):
destination = objects.Destination(
aggregates=['foo'], host='fake-host', allow_cross_cell_move=False)
primitive = destination.obj_to_primitive(
target_version='1.2')['nova_object.data']
self.assertIn('aggregates', primitive)
self.assertNotIn('allow_cross_cell_move', primitive)
primitive = destination.obj_to_primitive(
target_version='1.0')['nova_object.data']
self.assertNotIn('aggregates', primitive)
self.assertEqual('fake-host', primitive['host'])
def test_create_raises_on_unchanged_object(self):
ctxt = context.RequestContext(uuids.user_id, uuids.project_id)
req_obj = request_spec.RequestSpec(context=ctxt)
@ -921,25 +898,6 @@ class _TestRequestSpecObject(object):
req_obj.create()
req_obj.save()
def test_destination_forbidden_aggregates_default(self):
destination = objects.Destination()
self.assertIsNone(destination.forbidden_aggregates)
def test_destination_append_forbidden_aggregates(self):
destination = objects.Destination()
destination.append_forbidden_aggregates(set(['foo', 'bar']))
self.assertEqual(
set(['foo', 'bar']), destination.forbidden_aggregates)
destination.append_forbidden_aggregates(set(['bar', 'baz']))
self.assertEqual(
set(['foo', 'bar', 'baz']), destination.forbidden_aggregates)
def test_destination_delete_forbidden_aggregates(self):
destination = objects.Destination()
destination.append_forbidden_aggregates(set(['foo']))
primitive = destination.obj_to_primitive(target_version='1.0')
self.assertNotIn('forbidden_aggregates', primitive['nova_object.data'])
class TestRequestSpecObject(test_objects._LocalTest,
_TestRequestSpecObject):
@ -1062,32 +1020,69 @@ class TestDestinationObject(test.NoDBTestCase):
self.project_id = uuids.project_id
self.context = context.RequestContext(uuids.user_id, uuids.project_id)
def test_obj_make_compatible_destination(self):
values = {
'host': 'fake_host',
'node': 'fake_node',
'aggregates': ['agg1', 'agg2'],
'forbidden_aggregates': set(['agg3', 'agg4'])}
obj = objects.Destination(self.context, **values)
data = lambda x: x['nova_object.data']
obj_primitive = data(obj.obj_to_primitive(target_version='1.3'))
self.assertNotIn('forbidden_aggregates', obj_primitive)
self.assertIn('aggregates', obj_primitive)
def test_destination_aggregates_default(self):
destination = objects.Destination()
self.assertIsNone(destination.aggregates)
def test_obj_make_compatible_destination_with_forbidden_aggregates(self):
def test_destination_require_aggregates(self):
destination = objects.Destination()
destination.require_aggregates(['foo', 'bar'])
destination.require_aggregates(['baz'])
self.assertEqual(['foo,bar', 'baz'], destination.aggregates)
def test_destination_forbidden_aggregates_default(self):
destination = objects.Destination()
self.assertIsNone(destination.forbidden_aggregates)
def test_destination_append_forbidden_aggregates(self):
destination = objects.Destination()
destination.append_forbidden_aggregates(set(['foo', 'bar']))
self.assertEqual(
set(['foo', 'bar']), destination.forbidden_aggregates)
destination.append_forbidden_aggregates(set(['bar', 'baz']))
self.assertEqual(
set(['foo', 'bar', 'baz']), destination.forbidden_aggregates)
def test_obj_make_compatible(self):
values = {
'host': 'fake_host',
'node': 'fake_node',
'cell': objects.CellMapping(uuid=uuids.cell1),
'aggregates': ['agg1', 'agg2'],
'allow_cross_cell_move': False,
'forbidden_aggregates': set(['agg3', 'agg4'])}
obj = objects.Destination(self.context, **values)
data = lambda x: x['nova_object.data']
obj_primitive = data(obj.obj_to_primitive(target_version='1.4'))
manifest = ovo_base.obj_tree_get_versions(obj.obj_name())
obj_primitive = data(obj.obj_to_primitive(target_version='1.4',
version_manifest=manifest))
self.assertIn('forbidden_aggregates', obj_primitive)
self.assertItemsEqual(obj_primitive['forbidden_aggregates'],
set(['agg3', 'agg4']))
self.assertIn('aggregates', obj_primitive)
obj_primitive = data(obj.obj_to_primitive(target_version='1.3',
version_manifest=manifest))
self.assertNotIn('forbidden_aggregates', obj_primitive)
self.assertIn('allow_cross_cell_move', obj_primitive)
obj_primitive = data(obj.obj_to_primitive(target_version='1.2',
version_manifest=manifest))
self.assertIn('aggregates', obj_primitive)
self.assertNotIn('allow_cross_cell_move', obj_primitive)
obj_primitive = data(obj.obj_to_primitive(target_version='1.1',
version_manifest=manifest))
self.assertIn('cell', obj_primitive)
self.assertNotIn('aggregates', obj_primitive)
obj_primitive = data(obj.obj_to_primitive(target_version='1.0',
version_manifest=manifest))
self.assertNotIn('forbidden_aggregates', obj_primitive)
self.assertNotIn('cell', obj_primitive)
self.assertEqual('fake_host', obj_primitive['host'])
class TestMappingRequestGroupsToProviders(test.NoDBTestCase):
def setUp(self):