def create(self, data, lp_metadata, lp_params):
        """Create a new languagepack."""

        self._check_if_limit_of_lps_reached(self.context)

        common.check_url(data['source_uri'])

        try:
            # Check if an LP with the same name exists.
            objects.registry.Image.get_lp_by_name_or_uuid(
                self.context, data['name'], include_operators_lp=True)
        except exc.ResourceNotFound:
            db_obj = objects.registry.Image()
            db_obj.update(data)
            db_obj.uuid = uuidutils.generate_uuid()
            db_obj.user_id = self.context.user
            db_obj.project_id = self.context.tenant
            db_obj.status = image.States.QUEUED
            db_obj.artifact_type = 'language_pack'
            if lp_metadata:
                db_obj.tags = []
                db_obj.tags.append(lp_metadata)

            db_obj.create(self.context)
            self._start_build(db_obj, lp_params)
            return db_obj
        else:
            raise exc.ResourceExists(name=data['name'])
    def create(self, data, lp_metadata):
        """Create a new languagepack."""
        try:
            # Check if an LP with the same name exists.
            objects.registry.Image.get_lp_by_name_or_uuid(
                self.context, data['name'], include_operators_lp=True)
        except exc.ResourceNotFound:
            db_obj = objects.registry.Image()
            db_obj.update(data)
            db_obj.uuid = str(uuid.uuid4())
            db_obj.user_id = self.context.user
            db_obj.project_id = self.context.tenant
            db_obj.status = image.States.QUEUED
            db_obj.artifact_type = 'language_pack'
            if lp_metadata:
                db_obj.tags = []
                db_obj.tags.append(lp_metadata)

            db_obj.create(self.context)
            self._start_build(db_obj)
            return db_obj
        else:
            raise exc.ResourceExists(name=data['name'])
Example #3
0
 def _raise_duplicate_object(cls):
     if hasattr(cls, '__resource__'):
         raise exception.ResourceExists(name=cls.__resource__)
     else:
         raise exception.ObjectNotUnique(name=cls.__tablename__)
 def test_application_exists(self):
     exc = exception.ResourceExists(name='test')
     self.assertIn("The test resource already exists.",
                   six.text_type(exc))
     self.assertEqual(409, exc.code)
Example #5
0
 def test_resource_exists(self):
     exc = exception.ResourceExists()
     self.assertIn("The requested resource already exists.",
                   six.text_type(exc))
     self.assertEqual(exc.code, 409)