示例#1
0
    def test_display_active_members_only(self):
        ctx = context.RequestContext('fake_user', 'fake')

        fake_build_req = fake_build_request.fake_req_obj(ctx)

        @staticmethod
        def _fake_get_by_instance_uuid(context, instance_uuid):
            return fake_build_req

        self.stub_out('nova.objects.BuildRequest.get_by_instance_uuid',
                      _fake_get_by_instance_uuid)

        (ig_uuid, instances, members) = self._create_groups_and_instances(ctx)

        # delete an instance
        im = objects.InstanceMapping.get_by_instance_uuid(ctx,
                                                          instances[1].uuid)
        with context.target_cell(ctx, im.cell_mapping) as cctxt:
            instances[1]._context = cctxt
            instances[1].destroy()

        # check that the instance does not exist
        self.assertRaises(exception.InstanceNotFound,
                          objects.Instance.get_by_uuid,
                          ctx, instances[1].uuid)
        res_dict = self.controller.show(self.req, ig_uuid)
        result_members = res_dict['server_group']['members']
        # check that only the active instance is displayed
        self.assertEqual(2, len(result_members))
        self.assertIn(instances[0].uuid, result_members)
示例#2
0
 def test_obj_make_compatible_pre_1_3(self):
     obj = fake_build_request.fake_req_obj(self.context)
     build_request_obj = objects.BuildRequest(self.context)
     data = lambda x: x['nova_object.data']
     obj_primitive = data(obj.obj_to_primitive())
     self.assertIn('tags', obj_primitive)
     build_request_obj.obj_make_compatible(obj_primitive, '1.2')
     self.assertIn('instance_uuid', obj_primitive)
     self.assertNotIn('tags', obj_primitive)
示例#3
0
 def test_create_with_tags_set(self):
     # Test that when we set tags on the build request,
     # create it and reload it from the database that the
     # build_request.instance.tags is the same thing.
     build_request_obj = fake_build_request.fake_req_obj(self.context)
     self.assertEqual(1, len(build_request_obj.tags))
     build_request_obj.create()
     self.assertEqual(1, len(build_request_obj.tags))
     self.assertEqual(len(build_request_obj.tags),
                      len(build_request_obj.instance.tags))
     # Can't compare list objects directly, just compare the single
     # item they contain.
     base.obj_equal_prims(build_request_obj.tags[0],
                          build_request_obj.instance.tags[0])
示例#4
0
    def test_save(self, save_in_db):
        fake_req = fake_build_request.fake_db_req()
        save_in_db.return_value = fake_req
        req_obj = fake_build_request.fake_req_obj(self.context, fake_req)
        # We need to simulate the BuildRequest object being persisted before
        # that call.
        req_obj.id = 1
        req_obj.obj_reset_changes(recursive=True)

        req_obj.project_id = 'foo'
        req_obj.save()

        save_in_db.assert_called_once_with(self.context, req_obj.id,
                                           {'project_id': 'foo'})
示例#5
0
    def test_save(self, save_in_db):
        fake_req = fake_build_request.fake_db_req()
        save_in_db.return_value = fake_req
        req_obj = fake_build_request.fake_req_obj(self.context, fake_req)
        # We need to simulate the BuildRequest object being persisted before
        # that call.
        req_obj.id = 1
        req_obj.obj_reset_changes(recursive=True)

        req_obj.project_id = 'foo'
        req_obj.save()

        save_in_db.assert_called_once_with(self.context, req_obj.id,
                                           {'project_id': 'foo'})
示例#6
0
 def test_create_with_tags_set(self):
     # Test that when we set tags on the build request,
     # create it and reload it from the database that the
     # build_request.instance.tags is the same thing.
     build_request_obj = fake_build_request.fake_req_obj(self.context)
     self.assertEqual(1, len(build_request_obj.tags))
     build_request_obj.create()
     self.assertEqual(1, len(build_request_obj.tags))
     self.assertEqual(len(build_request_obj.tags),
                      len(build_request_obj.instance.tags))
     # Can't compare list objects directly, just compare the single
     # item they contain.
     base.obj_equal_prims(build_request_obj.tags[0],
                          build_request_obj.instance.tags[0])
示例#7
0
    def test_create(self):
        fake_req = fake_build_request.fake_db_req()
        req_obj = fake_build_request.fake_req_obj(self.context, fake_req)

        def _test_create_args(self2, context, changes):
            for field in ['instance_uuid', 'project_id']:
                self.assertEqual(fake_req[field], changes[field])
            self.assertEqual(
                    jsonutils.dumps(req_obj.instance.obj_to_primitive()),
                    changes['instance'])
            return fake_req

        with mock.patch.object(build_request.BuildRequest, '_create_in_db',
                _test_create_args):
            req_obj.create()
示例#8
0
    def test_create(self, create_in_db):
        fake_req = fake_build_request.fake_db_req()
        req_obj = fake_build_request.fake_req_obj(self.context, fake_req)

        def _test_create_args(self2, context, changes):
            for field in [fields for fields in
                    build_request.BuildRequest.fields if fields not in
                    ['created_at', 'updated_at', 'request_spec', 'id']]:
                self.assertEqual(fake_req[field], changes[field])
            self.assertEqual(fake_req['request_spec']['id'],
                    changes['request_spec_id'])
            return fake_req

        with mock.patch.object(build_request.BuildRequest, '_create_in_db',
                _test_create_args):
            req_obj.create()
示例#9
0
    def test_display_members(self):
        ctx = context.RequestContext('fake_user', 'fake')
        fake_build_req = fake_build_request.fake_req_obj(ctx)

        @staticmethod
        def _fake_get_by_instance_uuid(context, instance_uuid):
            return fake_build_req

        self.stub_out('nova.objects.BuildRequest.get_by_instance_uuid',
                      _fake_get_by_instance_uuid)

        (ig_uuid, instances, members) = self._create_groups_and_instances(ctx)
        res_dict = self.controller.show(self.req, ig_uuid)
        result_members = res_dict['server_group']['members']
        self.assertEqual(3, len(result_members))
        for member in members:
            self.assertIn(member, result_members)
    def test_create(self, create_in_db):
        fake_req = fake_build_request.fake_db_req()
        req_obj = fake_build_request.fake_req_obj(self.context, fake_req)

        def _test_create_args(self2, context, changes):
            for field in [
                    fields for fields in build_request.BuildRequest.fields
                    if fields not in
                ['created_at', 'updated_at', 'request_spec', 'id']
            ]:
                self.assertEqual(fake_req[field], changes[field])
            self.assertEqual(fake_req['request_spec']['id'],
                             changes['request_spec_id'])
            return fake_req

        with mock.patch.object(build_request.BuildRequest, '_create_in_db',
                               _test_create_args):
            req_obj.create()
示例#11
0
 def test_obj_make_compatible_pre_1_3(self):
     obj = fake_build_request.fake_req_obj(self.context)
     build_request_obj = objects.BuildRequest(self.context)
     obj_primitive = obj.obj_to_primitive()
     build_request_obj.obj_make_compatible(obj_primitive, '1.2')
     self.assertNotIn('tags', obj_primitive)
示例#12
0
 def test_obj_make_compatible_pre_1_3(self):
     obj = fake_build_request.fake_req_obj(self.context)
     build_request_obj = objects.BuildRequest(self.context)
     obj_primitive = obj.obj_to_primitive()
     build_request_obj.obj_make_compatible(obj_primitive, '1.2')
     self.assertNotIn('tags', obj_primitive)