Пример #1
0
    def _validate(self, app_data):
        # check max apps created for given tenant
        handler = app_handler.AppHandler(pecan.request.security_context)
        if len(handler.get_all()) >= cfg.CONF.api.max_apps_per_tenant:
            msg = "Cannot create application as maximum allowed limit reached."
            raise exception.ResourceLimitExceeded(reason=msg)

        if not app_data.languagepack:
            raise exception.BadRequest(reason="Languagepack not specified.")

        if not app_data.name:
            raise exception.BadRequest(reason='App name cannot be empty.')

        msg = ("Application name must be 1-100 characters long, only contain "
               "a-z,0-9,-,_ and start with an alphabet character.")
        # check if app name contains any invalid characters
        if not app_data.name or not app_data.name[0].isalpha():
            raise exception.BadRequest(reason=msg)

        try:
            re.match(r'^([a-z0-9-_]{1,100})$', app_data.name).group(0)
        except AttributeError:
            raise exception.BadRequest(reason=msg)

        # check if languagepack exists or not
        if str(app_data.languagepack).lower() != "false":
            try:
                objects.registry.Image.get_lp_by_name_or_uuid(
                    pecan.request.security_context,
                    app_data.languagepack,
                    include_operators_lp=True)
            except exception.ResourceNotFound:
                raise exception.ObjectNotFound(name="Languagepack",
                                               id=app_data.languagepack)
Пример #2
0
    def test_get_template_vm_swift_error(self, mock_catalog_get, mock_ua):
        handler = heat_handler.Handler()
        fake_assembly = fakes.FakeAssembly()

        exc_obj = exception.ObjectNotFound()
        mock_catalog_get.side_effect = exc_obj

        template_getter = mock.MagicMock()
        template_getter.return_value = self._get_fake_template()
        handler._get_template_for_swift = template_getter

        image_format = 'vm'
        image_storage = 'swift'
        image_loc = 'abc'
        image_name = 'def'
        ports = [80]
        mock_logger = mock.MagicMock()
        template = handler._get_template(self.ctx, image_format, image_storage,
                                         image_loc, image_name, fake_assembly,
                                         ports, mock_logger)
        self.assertIsNone(template)
        mock_ua.assert_called_once_with(self.ctx, fake_assembly.id,
                                        {'status': STATES.ERROR})

        assert not handler._get_template_for_swift.called
Пример #3
0
 def test_ensure_workbook_unknown(self, mock_get, mock_clients,
                                  mock_registry):
     fpipe = fakes.FakePipeline()
     fpipe.workbook_name = 'we-dont-have-this'
     mock_mistral = mock_clients.return_value.mistral.return_value
     mock_mistral.workbooks.get.side_effect = ValueError(
         'Workbook not found')
     mock_get.side_effect = exception.ObjectNotFound(name='workbook',
                                                     id='we-dont-have-this')
     handler = pipeline_handler.PipelineHandler(self.ctx)
     self.assertRaises(exception.ObjectNotFound, handler._ensure_workbook,
                       fpipe)
Пример #4
0
def get(entity, name, content_type='yaml'):
    """This reads a file's contents from local storage.

    /etc/solum/<entity>/name.<content_type>
    """
    proj_dir = os.path.join(os.path.dirname(__file__), '..', '..')
    file_path = os.path.join(proj_dir, 'etc', 'solum', entity,
                             '%s.%s' % (name, content_type))
    file_path = os.path.realpath(file_path)
    try:
        with open(file_path) as fd:
            return fd.read()
    except Exception:
        raise exception.ObjectNotFound(
            name=entity, id=name)
Пример #5
0
def get_from_contrib(name):
    """This reads a file's contents from local storage.

    /contrib/common/name.<content_type>
    """
    proj_dir = CONF.get('source_path')
    if not proj_dir:
        proj_dir = os.path.join(os.path.dirname(__file__), '..', '..')
    file_path = os.path.join(proj_dir, 'contrib', 'common', '%s' % name)
    file_path = os.path.realpath(file_path)
    try:
        with open(file_path) as fd:
            return fd.read()
    except Exception:
        raise exception.ObjectNotFound(id=name)
Пример #6
0
    def _validate(self, app_data):
        # check max apps created for given tenant
        handler = app_handler.AppHandler(pecan.request.security_context)
        if len(handler.get_all()) >= cfg.CONF.api.max_apps_per_tenant:
            msg = "Cannot create application as maximum allowed limit reached."
            raise exception.ResourceLimitExceeded(reason=msg)

        if not app_data.languagepack:
            raise exception.BadRequest(reason="Languagepack not specified.")

        if not app_data.name:
            raise exception.BadRequest(reason='App name cannot be empty.')

        # check if languagepack exists or not
        try:
            objects.registry.Image.get_lp_by_name_or_uuid(
                pecan.request.security_context,
                app_data.languagepack,
                include_operators_lp=True)
        except exception.ResourceNotFound:
            raise exception.ObjectNotFound(name="Languagepack",
                                           id=app_data.languagepack)
Пример #7
0
 def _raise_not_found(cls, item_id):
     """Raise a not found exception."""
     if hasattr(cls, '__resource__'):
         raise exception.ResourceNotFound(name=cls.__resource__, id=item_id)
     else:
         raise exception.ObjectNotFound(name=cls.__tablename__, id=item_id)