Example #1
0
 def test_get_not_deleted_by_cell_and_project_None(self):
     cm = cell_mapping.CellMapping(context=self.context,
                                   uuid=uuidsentinel.cell,
                                   database_connection='fake:///',
                                   transport_url='fake://')
     cm.create()
     im1 = instance_mapping.InstanceMapping(context=self.context,
                                            project_id='fake-project-1',
                                            cell_mapping=cm,
                                            instance_uuid=uuidsentinel.uid1,
                                            queued_for_delete=False)
     im1.create()
     im2 = instance_mapping.InstanceMapping(context=self.context,
                                            project_id='fake-project-2',
                                            cell_mapping=cm,
                                            instance_uuid=uuidsentinel.uid2,
                                            queued_for_delete=None)
     im2.create()
     # testing if it accepts None project_id in the query and
     # catches None queued for delete records.
     ims = (instance_mapping.InstanceMappingList.
            get_not_deleted_by_cell_and_project(self.context,
                                                cm.uuid,
                                                None))
     self.assertEqual(2, len(ims))
Example #2
0
    def test_get_not_deleted_by_cell_and_project(self):
        cells = []
        # Create two cells
        for uuid in (uuidsentinel.cell1, uuidsentinel.cell2):
            cm = cell_mapping.CellMapping(context=self.context, uuid=uuid,
                                          database_connection="fake:///",
                                          transport_url='fake://')
            cm.create()
            cells.append(cm)

        uuids = {cells[0]: [uuidsentinel.c1i1, uuidsentinel.c1i2],
                 cells[1]: [uuidsentinel.c2i1, uuidsentinel.c2i2]}
        project_ids = ['fake-project-1', 'fake-project-2']
        # Create five instance_mappings such that:
        for cell, uuid in uuids.items():
            # Both the cells contain a mapping belonging to fake-project-1
            im1 = instance_mapping.InstanceMapping(context=self.context,
                project_id=project_ids[0], cell_mapping=cell,
                instance_uuid=uuid[0], queued_for_delete=False)
            im1.create()
            # Both the cells contain a mapping belonging to fake-project-2
            im2 = instance_mapping.InstanceMapping(context=self.context,
                project_id=project_ids[1], cell_mapping=cell,
                instance_uuid=uuid[1], queued_for_delete=False)
            im2.create()
            # The second cell has a third mapping that is queued for deletion
            # which belongs to fake-project-1.
            if cell.uuid == uuidsentinel.cell2:
                im3 = instance_mapping.InstanceMapping(context=self.context,
                    project_id=project_ids[0], cell_mapping=cell,
                    instance_uuid=uuidsentinel.qfd, queued_for_delete=True)
                im3.create()

        # Get not queued for deletion mappings from cell1 belonging to
        # fake-project-2.
        ims = (instance_mapping.InstanceMappingList.
               get_not_deleted_by_cell_and_project(
               self.context, cells[0].uuid, 'fake-project-2'))
        # This will give us one mapping from cell1
        self.assertEqual([uuidsentinel.c1i2],
                         sorted([m.instance_uuid for m in ims]))
        self.assertIn('cell_mapping', ims[0])
        # Get not queued for deletion mappings from cell2 belonging to
        # fake-project-1.
        ims = (instance_mapping.InstanceMappingList.
               get_not_deleted_by_cell_and_project(
               self.context, cells[1].uuid, 'fake-project-1'))
        # This will give us one mapping from cell2. Note that even if
        # there are two mappings belonging to fake-project-1 inside cell2,
        # only the one not queued for deletion is returned.
        self.assertEqual([uuidsentinel.c2i1],
                         sorted([m.instance_uuid for m in ims]))
        # Try getting a mapping belonging to a non-existing project_id.
        ims = (instance_mapping.InstanceMappingList.
               get_not_deleted_by_cell_and_project(
               self.context, cells[0].uuid, 'fake-project-3'))
        # Since no mappings belong to fake-project-3, nothing is returned.
        self.assertEqual([], sorted([m.instance_uuid for m in ims]))
Example #3
0
 def test_obj_make_compatible(self):
     uuid = uuidutils.generate_uuid()
     im_obj = instance_mapping.InstanceMapping(context=self.context)
     fake_im_obj = instance_mapping.InstanceMapping(context=self.context,
                                                    instance_uuid=uuid,
                                                    queued_for_delete=False)
     obj_primitive = fake_im_obj.obj_to_primitive('1.0')
     obj = im_obj.obj_from_primitive(obj_primitive)
     self.assertIn('instance_uuid', obj)
     self.assertEqual(uuid, obj.instance_uuid)
     self.assertNotIn('queued_for_delete', obj)
Example #4
0
    def test_get_not_deleted_by_cell_and_project_limit(self):
        cm = cell_mapping.CellMapping(context=self.context,
                                      uuid=uuidsentinel.cell,
                                      database_connection='fake:///',
                                      transport_url='fake://')
        cm.create()
        pid = self.context.project_id
        for uuid in (uuidsentinel.uuid2, uuidsentinel.inst2):
            im = instance_mapping.InstanceMapping(context=self.context,
                                                  project_id=pid,
                                                  cell_mapping=cm,
                                                  instance_uuid=uuid,
                                                  queued_for_delete=False)
            im.create()

        ims = (instance_mapping.InstanceMappingList.
               get_not_deleted_by_cell_and_project(self.context, cm.uuid, pid))
        self.assertEqual(2, len(ims))

        ims = (instance_mapping.InstanceMappingList.
               get_not_deleted_by_cell_and_project(self.context,
                                                   cm.uuid,
                                                   pid,
                                                   limit=10))
        self.assertEqual(2, len(ims))

        ims = (instance_mapping.InstanceMappingList.
               get_not_deleted_by_cell_and_project(self.context,
                                                   cm.uuid,
                                                   pid,
                                                   limit=1))
        self.assertEqual(1, len(ims))
 def test_obj_load_attr(self, mock_log):
     im_obj = instance_mapping.InstanceMapping()
     # Access of unset user_id should have special handling
     self.assertRaises(exception.ObjectActionError, im_obj.obj_load_attr,
                       'user_id')
     msg = ('The unset user_id attribute of an unmigrated instance mapping '
            'should not be accessed.')
     mock_log.assert_called_once_with(msg)
     # Access of any other unset attribute should fall back to base class
     self.assertRaises(NotImplementedError, im_obj.obj_load_attr,
                       'project_id')
Example #6
0
    def test_modify_cell_mapping(self):
        inst_mapping = instance_mapping.InstanceMapping(context=self.context)
        inst_mapping.instance_uuid = uuidutils.generate_uuid()
        inst_mapping.project_id = self.context.project_id
        inst_mapping.cell_mapping = None
        inst_mapping.create()

        c_mapping = cell_mapping.CellMapping(self.context,
                                             uuid=uuidutils.generate_uuid(),
                                             name="cell0",
                                             transport_url="none:///",
                                             database_connection="fake:///")
        c_mapping.create()

        inst_mapping.cell_mapping = c_mapping
        inst_mapping.save()

        result_mapping = instance_mapping.InstanceMapping.get_by_instance_uuid(
            self.context, inst_mapping.instance_uuid)

        self.assertEqual(result_mapping.cell_mapping.id, c_mapping.id)
Example #7
0
 def setUp(self):
     super(InstanceMappingTestCase, self).setUp()
     self.useFixture(fixtures.Database(database='api'))
     self.context = context.RequestContext('fake-user', 'fake-project')
     self.mapping_obj = instance_mapping.InstanceMapping()