def _parse_service_catalog_info(config, context): try: service_type, service_name, endpoint_type = config.split(':') except ValueError: msg = _("Failed to parse the catalog info option %s, " "must be in the form: " "<service_type>:<service_name>:<endpoint_type>") % config raise exception.KarborException(msg) for entry in context.service_catalog: if entry.get('type') == service_type: return entry.get('endpoints')[0].get(endpoint_type) raise exception.KarborException( _("Couldn't find the endpoint of service type %s " "from service catalog") % service_type)
def delete(self, context, provider_id, checkpoint_id): LOG.info("Starting protection service:delete action") LOG.debug('provider_id :%s checkpoint_id:%s', provider_id, checkpoint_id) provider = self.provider_registry.show_provider(provider_id) try: checkpoint_collection = provider.get_checkpoint_collection() checkpoint = checkpoint_collection.get(checkpoint_id) except Exception: LOG.error("get checkpoint failed, checkpoint_id:%s", checkpoint_id) raise exception.InvalidInput( reason=_("Invalid checkpoint_id or provider_id")) if checkpoint.status not in [ constants.CHECKPOINT_STATUS_AVAILABLE, constants.CHECKPOINT_STATUS_ERROR, ]: raise exception.CheckpointNotBeDeleted(checkpoint_id=checkpoint_id) checkpoint.status = constants.CHECKPOINT_STATUS_DELETING checkpoint.commit() try: flow = self.worker.get_flow( context=context, operation_type=constants.OPERATION_DELETE, checkpoint=checkpoint, provider=provider) except Exception: LOG.exception( "Failed to create delete checkpoint flow," "checkpoint:%s.", checkpoint_id) raise exception.KarborException( _("Failed to create delete checkpoint flow.")) self._spawn(self.worker.run_flow, flow)
def __call__(self, *args, **kwargs): if self._raise_except: raise exception.KarborException() res = mock.Mock() res.volume_id = self._volume_id return res
def create_client(cls, service, context, conf=cfg.CONF, privileged_user=False, **kwargs): module = cls.get_client_module(service) if module is None: raise exception.KarborException(_('Unknown service(%s)') % service) kwargs['privileged_user'] = privileged_user kwargs['keystone_plugin'] = cls.get_keystone_plugin() if context or privileged_user: kwargs['session'] = cls._generate_session(context, service, privileged_user) return module.create(context, conf, **kwargs)
def get_url(service, context, client_config, append_project_fmt=None, **kwargs): '''Return the url of given service endpoint.''' url = "" privileged_user = kwargs.get('privileged_user') # get url by endpoint if privileged_user is not True: try: url = _parse_service_endpoint( getattr(client_config, '%s_endpoint' % service), context, append_project_fmt) if url: return url except Exception: pass # get url by catalog try: url = _parse_service_catalog_info( getattr(client_config, '%s_catalog_info' % service), context) if url: return url except Exception: pass # get url by accessing keystone try: keystone_plugin = kwargs.get('keystone_plugin') url = keystone_plugin.get_service_endpoint( client_config.service_name, client_config.service_type, client_config.region_id, client_config.interface) url = url.replace("$", "%") except Exception: pass if url: return url raise exception.KarborException( _("Couldn't find the endpoint of service(%s)") % service)
def test_error_msg_is_exception_to_string(self): msg = 'test message' exc1 = Exception(msg) exc2 = exception.KarborException(exc1) self.assertEqual(msg, exc2.msg)
def test_error_msg(self): self.assertEqual('test', six.text_type(exception.KarborException('test')))