Esempio n. 1
0
 def _create_req(self):
     args = fake_build_request.fake_db_req()
     args.pop('id', None)
     args['instance_uuid'] = self.instance_uuid
     args['project_id'] = self.project_id
     return build_request.BuildRequest._from_db_object(
         self.context, self.build_req_obj,
         self.build_req_obj._create_in_db(self.context, args))
Esempio n. 2
0
    def test_get_by_instance_uuid_instance_none(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        fake_req['instance'] = None
        get_by_uuid.return_value = fake_req

        self.assertRaises(exception.BuildRequestNotFound,
                build_request.BuildRequest.get_by_instance_uuid, self.context,
                fake_req['instance_uuid'])
Esempio n. 3
0
 def _create_req(self):
     args = fake_build_request.fake_db_req()
     args.pop('id', None)
     args['instance_uuid'] = self.instance_uuid
     args['project_id'] = self.project_id
     return build_request.BuildRequest._from_db_object(self.context,
             self.build_req_obj,
             self.build_req_obj._create_in_db(self.context, args))
Esempio n. 4
0
    def test_get_by_instance_uuid_instance_none(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        fake_req['instance'] = None
        get_by_uuid.return_value = fake_req

        self.assertRaises(exception.BuildRequestNotFound,
                          build_request.BuildRequest.get_by_instance_uuid,
                          self.context, fake_req['instance_uuid'])
Esempio n. 5
0
 def test_from_db_object_set_deleted(self):
     # Assert that if we persisted an instance not yet having the deleted
     # field being set, we still return a value for that field.
     fake_req = fake_build_request.fake_db_req()
     with mock.patch.object(o_vo_base.VersionedObject,
                            'obj_set_defaults') as mock_obj_set_defaults:
         build_request = objects.BuildRequest._from_db_object(
             self.context, objects.BuildRequest(), fake_req)
     mock_obj_set_defaults.assert_called_once_with('deleted')
     self.assertFalse(build_request.instance.deleted)
Esempio n. 6
0
 def test_from_db_object_set_deleted(self):
     # Assert that if we persisted an instance not yet having the deleted
     # field being set, we still return a value for that field.
     fake_req = fake_build_request.fake_db_req()
     with mock.patch.object(o_vo_base.VersionedObject,
                            'obj_set_defaults') as mock_obj_set_defaults:
         build_request = objects.BuildRequest._from_db_object(
             self.context, objects.BuildRequest(), fake_req)
     mock_obj_set_defaults.assert_called_once_with('deleted')
     self.assertFalse(build_request.instance.deleted)
Esempio n. 7
0
    def test_get_by_instance_uuid_instance_version_too_new(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        instance = fake_instance.fake_instance_obj(self.context,
                objects.Instance, uuid=fake_req['instance_uuid'])
        instance.VERSION = '99'
        fake_req['instance'] = jsonutils.dumps(instance.obj_to_primitive)
        get_by_uuid.return_value = fake_req

        self.assertRaises(exception.BuildRequestNotFound,
                build_request.BuildRequest.get_by_instance_uuid, self.context,
                fake_req['instance_uuid'])
Esempio n. 8
0
    def test_get_by_instance_uuid_instance_version_too_new(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        instance = fake_instance.fake_instance_obj(
            self.context, objects.Instance, uuid=fake_req['instance_uuid'])
        instance.VERSION = '99'
        fake_req['instance'] = jsonutils.dumps(instance.obj_to_primitive)
        get_by_uuid.return_value = fake_req

        self.assertRaises(exception.BuildRequestNotFound,
                          build_request.BuildRequest.get_by_instance_uuid,
                          self.context, fake_req['instance_uuid'])
Esempio n. 9
0
 def _create_req(self, project_id=None, instance=None):
     kwargs = {}
     if instance:
         kwargs['instance'] = jsonutils.dumps(instance.obj_to_primitive())
     args = fake_build_request.fake_db_req(**kwargs)
     args.pop('id', None)
     args['instance_uuid'] = uuidutils.generate_uuid()
     args['project_id'] = self.project_id if not project_id else project_id
     return build_request.BuildRequest._from_db_object(self.context,
             build_request.BuildRequest(),
             build_request.BuildRequest._create_in_db(self.context, args))
Esempio n. 10
0
 def _create_req(self, project_id=None, instance=None):
     kwargs = {}
     if instance:
         kwargs['instance'] = jsonutils.dumps(instance.obj_to_primitive())
     args = fake_build_request.fake_db_req(**kwargs)
     args.pop('id', None)
     args['instance_uuid'] = uuidutils.generate_uuid()
     args['project_id'] = self.project_id if not project_id else project_id
     return build_request.BuildRequest._from_db_object(
         self.context, build_request.BuildRequest(),
         build_request.BuildRequest._create_in_db(self.context, args))
Esempio n. 11
0
 def _create_req(self):
     req_spec = fake_request_spec.fake_spec_obj(remove_id=True)
     req_spec.instance_uuid = self.instance_uuid
     req_spec.create()
     args = fake_build_request.fake_db_req(request_spec_id=req_spec.id)
     args.pop('id', None)
     args.pop('request_spec', None)
     args['project_id'] = self.project_id
     return build_request.BuildRequest._from_db_object(
         self.context, self.build_req_obj,
         self.build_req_obj._create_in_db(self.context, args))
Esempio n. 12
0
    def test_get_by_instance_uuid(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        get_by_uuid.return_value = fake_req

        req_obj = build_request.BuildRequest.get_by_instance_uuid(self.context,
                fake_req['instance_uuid'])

        self.assertEqual(fake_req['instance_uuid'], req_obj.instance_uuid)
        self.assertEqual(fake_req['project_id'], req_obj.project_id)
        self.assertIsInstance(req_obj.instance, objects.Instance)
        get_by_uuid.assert_called_once_with(self.context,
                fake_req['instance_uuid'])
Esempio n. 13
0
 def _create_req(self):
     req_spec = fake_request_spec.fake_spec_obj(remove_id=True)
     req_spec.instance_uuid = self.instance_uuid
     req_spec.create()
     args = fake_build_request.fake_db_req(
             request_spec_id=req_spec.id)
     args.pop('id', None)
     args.pop('request_spec', None)
     args['project_id'] = self.project_id
     return build_request.BuildRequest._from_db_object(self.context,
             self.build_req_obj,
             self.build_req_obj._create_in_db(self.context, args))
Esempio n. 14
0
    def test_get_by_instance_uuid(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        get_by_uuid.return_value = fake_req

        req_obj = build_request.BuildRequest.get_by_instance_uuid(
            self.context, fake_req['instance_uuid'])

        self.assertEqual(fake_req['instance_uuid'], req_obj.instance_uuid)
        self.assertEqual(fake_req['project_id'], req_obj.project_id)
        self.assertIsInstance(req_obj.instance, objects.Instance)
        get_by_uuid.assert_called_once_with(self.context,
                                            fake_req['instance_uuid'])
Esempio n. 15
0
    def test_get_by_instance_uuid_do_not_override_locked_by(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        instance = fake_instance.fake_instance_obj(
            self.context, objects.Instance, uuid=fake_req['instance_uuid'])
        instance.locked_by = 'admin'
        fake_req['instance'] = jsonutils.dumps(instance.obj_to_primitive())
        get_by_uuid.return_value = fake_req

        req_obj = build_request.BuildRequest.get_by_instance_uuid(
            self.context, fake_req['instance_uuid'])

        self.assertIsInstance(req_obj.instance, objects.Instance)
        self.assertEqual('admin', req_obj.instance.locked_by)
Esempio n. 16
0
    def test_get_all(self, get_all):
        fake_reqs = [fake_build_request.fake_db_req() for x in range(2)]
        get_all.return_value = fake_reqs

        req_objs = build_request.BuildRequestList.get_all(self.context)

        self.assertEqual(2, len(req_objs))
        for i in range(2):
            self.assertEqual(fake_reqs[i]['instance_uuid'],
                             req_objs[i].instance_uuid)
            self.assertEqual(fake_reqs[i]['project_id'],
                             req_objs[i].project_id)
            self.assertIsInstance(req_objs[i].instance, objects.Instance)
Esempio n. 17
0
    def test_get_all(self, get_all):
        fake_reqs = [fake_build_request.fake_db_req() for x in range(2)]
        get_all.return_value = fake_reqs

        req_objs = build_request.BuildRequestList.get_all(self.context)

        self.assertEqual(2, len(req_objs))
        for i in range(2):
            self.assertEqual(fake_reqs[i]['instance_uuid'],
                             req_objs[i].instance_uuid)
            self.assertEqual(fake_reqs[i]['project_id'],
                             req_objs[i].project_id)
            self.assertIsInstance(req_objs[i].instance, objects.Instance)
Esempio n. 18
0
    def test_get_by_instance_uuid_do_not_override_locked_by(self, get_by_uuid):
        fake_req = fake_build_request.fake_db_req()
        instance = fake_instance.fake_instance_obj(self.context,
                objects.Instance, uuid=fake_req['instance_uuid'])
        instance.locked_by = 'admin'
        fake_req['instance'] = jsonutils.dumps(instance.obj_to_primitive())
        get_by_uuid.return_value = fake_req

        req_obj = build_request.BuildRequest.get_by_instance_uuid(self.context,
                fake_req['instance_uuid'])

        self.assertIsInstance(req_obj.instance, objects.Instance)
        self.assertEqual('admin', req_obj.instance.locked_by)
Esempio n. 19
0
 def test_get_new_instance_show_changed_fields(self):
     # Assert that we create a very dirty object from the cleaned one
     # on build_request
     fake_req = fake_build_request.fake_db_req()
     fields = jsonutils.loads(fake_req['instance'])['nova_object.data']
     build_request = objects.BuildRequest._from_db_object(
         self.context, objects.BuildRequest(), fake_req)
     self.assertEqual(0, len(build_request.instance.obj_what_changed()))
     instance = build_request.get_new_instance(self.context)
     for field in fields:
         self.assertIn(field, instance.obj_what_changed())
         self.assertEqual(getattr(build_request.instance, field),
                          getattr(instance, field))
Esempio n. 20
0
 def test_get_new_instance_show_changed_fields(self):
     # Assert that we create a very dirty object from the cleaned one
     # on build_request
     fake_req = fake_build_request.fake_db_req()
     fields = jsonutils.loads(fake_req['instance'])['nova_object.data']
     build_request = objects.BuildRequest._from_db_object(
         self.context, objects.BuildRequest(), fake_req)
     self.assertEqual(0, len(build_request.instance.obj_what_changed()))
     instance = build_request.get_new_instance(self.context)
     for field in fields:
         self.assertIn(field, instance.obj_what_changed())
         self.assertEqual(getattr(build_request.instance, field),
                          getattr(instance, field))
Esempio n. 21
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'})
Esempio n. 22
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'})
Esempio n. 23
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()
Esempio n. 24
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()
    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()