Exemple #1
0
    def _get_stack(self, cnxt, stack_identity):
        identity = identifier.HeatIdentifier(**stack_identity)

        if identity.tenant != cnxt.tenant_id:
            raise exception.InvalidTenant(target=identity.tenant,
                                          actual=cnxt.tenant_id)

        s = db_api.stack_get(cnxt, identity.stack_id)

        if s is None:
            raise exception.StackNotFound(stack_name=identity.stack_name)

        if identity.path or s.name != identity.stack_name:
            raise exception.StackNotFound(stack_name=identity.stack_name)

        return s
Exemple #2
0
    def test_metadata_show_nonexist(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'metadata', True)
        res_name = 'WikiDatabase'
        stack_identity = identifier.HeatIdentifier(self.tenant, 'rubbish', '1')
        res_identity = identifier.ResourceIdentifier(resource_name=res_name,
                                                     **stack_identity)

        req = self._get(res_identity._tenant_path() + '/metadata')

        error = heat_exc.StackNotFound(stack_name='a')
        self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
        rpc_client.EngineClient.call(req.context, ('describe_stack_resource', {
            'stack_identity': stack_identity,
            'resource_name': res_name,
            'with_attr': None
        }),
                                     version='1.2').AndRaise(
                                         tools.to_remote_error(error))
        self.m.ReplayAll()

        resp = tools.request_with_middleware(
            fault.FaultWrapper,
            self.controller.metadata,
            req,
            tenant_id=self.tenant,
            stack_name=stack_identity.stack_name,
            stack_id=stack_identity.stack_id,
            resource_name=res_name)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('StackNotFound', resp.json['error']['type'])
        self.m.VerifyAll()
Exemple #3
0
    def test_show_stack_nonexist(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'show', True)
        event_id = '42'
        res_name = 'WikiDatabase'
        stack_identity = identifier.HeatIdentifier(self.tenant,
                                                   'wibble', '6')

        req = self._get(stack_identity._tenant_path() +
                        '/resources/' + res_name + '/events/' + event_id)

        kwargs = {'stack_identity': stack_identity,
                  'limit': None, 'sort_keys': None, 'marker': None,
                  'sort_dir': None, 'filters': {'resource_name': res_name}}

        error = heat_exc.StackNotFound(stack_name='a')
        self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
        rpc_client.EngineClient.call(
            req.context, ('list_events', kwargs)
        ).AndRaise(tools.to_remote_error(error))
        self.m.ReplayAll()

        resp = tools.request_with_middleware(
            fault.FaultWrapper,
            self.controller.show,
            req, tenant_id=self.tenant,
            stack_name=stack_identity.stack_name,
            stack_id=stack_identity.stack_id,
            resource_name=res_name,
            event_id=event_id)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('StackNotFound', resp.json['error']['type'])
        self.m.VerifyAll()
Exemple #4
0
    def test_index_nonexist(self, mock_enforce):
        self._mock_enforce_setup(mock_enforce, 'index', True)
        stack_identity = identifier.HeatIdentifier(self.tenant, 'rubbish', '1')

        req = self._get(stack_identity._tenant_path() + '/resources')

        error = heat_exc.StackNotFound(stack_name='a')
        self.m.StubOutWithMock(rpc_client.EngineClient, 'call')
        rpc_client.EngineClient.call(req.context, ('list_stack_resources', {
            'stack_identity': stack_identity,
            'nested_depth': 0,
            'with_detail': False
        }),
                                     version='1.12').AndRaise(
                                         tools.to_remote_error(error))
        self.m.ReplayAll()

        resp = tools.request_with_middleware(
            fault.FaultWrapper,
            self.controller.index,
            req,
            tenant_id=self.tenant,
            stack_name=stack_identity.stack_name,
            stack_id=stack_identity.stack_id)

        self.assertEqual(404, resp.json['code'])
        self.assertEqual('StackNotFound', resp.json['error']['type'])
        self.m.VerifyAll()
Exemple #5
0
    def _get_stack(self, cnxt, stack_identity, show_deleted=False):
        identity = identifier.HeatIdentifier(**stack_identity)

        s = db_api.stack_get(cnxt, identity.stack_id,
                             show_deleted=show_deleted)

        if s is None:
            raise exception.StackNotFound(stack_name=identity.stack_name)

        if cnxt.tenant_id not in (identity.tenant, s.stack_user_project_id):
            # The DB API should not allow this, but sanity-check anyway..
            raise exception.InvalidTenant(target=identity.tenant,
                                          actual=cnxt.tenant_id)

        if identity.path or s.name != identity.stack_name:
            raise exception.StackNotFound(stack_name=identity.stack_name)

        return s
Exemple #6
0
 def test_openstack_exception_with_kwargs(self):
     wrapper = fault.FaultWrapper(None)
     msg = wrapper._error(heat_exc.StackNotFound(stack_name='a'))
     expected = {'code': 404,
                 'error': {'message': 'The Stack (a) could not be found.',
                           'traceback': None,
                           'type': 'StackNotFound'},
                 'explanation': 'The resource could not be found.',
                 'title': 'Not Found'}
     self.assertEqual(expected, msg)
    def test_stack_resource_describe_nonexist_stack(self, mock_get):
        non_exist_identifier = identifier.HeatIdentifier(
            self.ctx.tenant_id, 'wibble',
            '18d06e2e-44d3-4bef-9fbf-52480d604b02')
        mock_get.side_effect = exception.StackNotFound(stack_name='test')

        ex = self.assertRaises(dispatcher.ExpectedException,
                               self.eng.describe_stack_resource, self.ctx,
                               non_exist_identifier, 'WebServer')
        self.assertEqual(exception.StackNotFound, ex.exc_info[0])
        mock_get.assert_called_once_with(self.ctx, non_exist_identifier)
Exemple #8
0
 def identify_stack(self, cnxt, stack_name):
     """
     The identify_stack method returns the full stack identifier for a
     single, live stack given the stack name.
     arg1 -> RPC context.
     arg2 -> Name or UUID of the stack to look up.
     """
     if uuidutils.is_uuid_like(stack_name):
         s = db_api.stack_get(cnxt, stack_name, show_deleted=True)
     else:
         s = db_api.stack_get_by_name(cnxt, stack_name)
     if s:
         stack = parser.Stack.load(cnxt, stack=s)
         return dict(stack.identifier())
     else:
         raise exception.StackNotFound(stack_name=stack_name)
 def test_remote_exception(self):
     error = heat_exc.StackNotFound(stack_name='a')
     exc_info = (type(error), error, None)
     serialized = rpc_common.serialize_remote_exception(exc_info)
     remote_error = rpc_common.deserialize_remote_exception(cfg.CONF,
                                                            serialized)
     wrapper = fault.FaultWrapper(None)
     msg = wrapper._error(remote_error)
     expected_message, expected_traceback = str(remote_error).split('\n', 1)
     expected = {'code': 404,
                 'error': {'message': expected_message,
                           'traceback': expected_traceback,
                           'type': 'StackNotFound'},
                 'explanation': 'The resource could not be found.',
                 'title': 'Not Found'}
     self.assertEqual(msg, expected)
Exemple #10
0
    def identify_stack(self, cnxt, stack_name):
        """
        The identify_stack method returns the full stack identifier for a
        single, live stack given the stack name.

        :param cnxt: RPC context.
        :param stack_name: Name or UUID of the stack to look up.
        """
        if uuidutils.is_uuid_like(stack_name):
            s = db_api.stack_get(cnxt, stack_name, show_deleted=True)
            # may be the name is in uuid format, so if get by id returns None,
            # we should get the info by name again
            if not s:
                s = db_api.stack_get_by_name(cnxt, stack_name)
        else:
            s = db_api.stack_get_by_name(cnxt, stack_name)
        if s:
            stack = parser.Stack.load(cnxt, stack=s)
            return dict(stack.identifier())
        else:
            raise exception.StackNotFound(stack_name=stack_name)
Exemple #11
0
 def test_remote_exception(self):
     # We want tracebacks
     cfg.CONF.set_override('debug', True)
     error = heat_exc.StackNotFound(stack_name='a')
     exc_info = (type(error), error, None)
     serialized = rpc_common.serialize_remote_exception(exc_info)
     remote_error = rpc_common.deserialize_remote_exception(
         serialized, ["heat.common.exception"])
     wrapper = fault.FaultWrapper(None)
     msg = wrapper._error(remote_error)
     expected_message, expected_traceback = six.text_type(
         remote_error).split('\n', 1)
     expected = {
         'code': 404,
         'error': {
             'message': expected_message,
             'traceback': expected_traceback,
             'type': 'StackNotFound'
         },
         'explanation': 'The resource could not be found.',
         'title': 'Not Found'
     }
     self.assertEqual(expected, msg)