stacks = db_api.stack_get_all_by_tenant(cnxt) or []
return list(format_stack_details(stacks))
+ def _validate_mandatory_credentials(self, cnxt):
+ if cnxt.username is None:
+ raise exception.MissingCredentialError(required='X-Auth-User')
+ if cnxt.password is None:
+ raise exception.MissingCredentialError(required='X-Auth-Key')
+
@request_context
def create_stack(self, cnxt, stack_name, template, params, files, args):
"""
"""
logger.info('template is %s' % template)
+ self._validate_mandatory_credentials(cnxt)
+
def _stack_create(stack):
# Create the stack, and create the periodic task if successful
stack.create()
"""
logger.info('template is %s' % template)
+ self._validate_mandatory_credentials(cnxt)
+
# Get the database representation of the existing stack
db_stack = self._get_stack(cnxt, stack_identity)
def create_context(mocks, user='stacks_test_user',
- tenant='test_admin', ctx=None):
- ctx = ctx or context.get_admin_context()
+ tenant='test_admin', password='stacks_test_password'):
+ ctx = context.get_admin_context()
mocks.StubOutWithMock(ctx, 'username')
mocks.StubOutWithMock(ctx, 'tenant_id')
+ mocks.StubOutWithMock(ctx, 'password')
ctx.username = user
ctx.tenant_id = tenant
+ ctx.password = password
return ctx
self.ctx, stack_name,
stack.t, {}, None, {})
+ def test_stack_create_no_credentials(self):
+ stack_name = 'service_create_test_stack'
+ params = {'foo': 'bar'}
+ template = '{ "Template": "data" }'
+
+ ctx = self.ctx = create_context(self.m, password=None)
+ self.assertRaises(exception.MissingCredentialError,
+ self.man.create_stack, ctx, stack_name, template,
+ params, None, {})
+
+ ctx = self.ctx = create_context(self.m, user=None)
+ self.assertRaises(exception.MissingCredentialError,
+ self.man.create_stack, ctx, stack_name, template,
+ params, None, {})
+
def test_stack_validate(self):
stack_name = 'service_create_test_validate'
stack = get_wordpress_stack(stack_name, self.ctx)
None, {})
self.m.VerifyAll()
+ def test_stack_update_no_credentials(self):
+ stack_name = 'service_update_nonexist_test_stack'
+ params = {'foo': 'bar'}
+ template = '{ "Template": "data" }'
+
+ stack = get_wordpress_stack(stack_name, self.ctx)
+
+ ctx = self.ctx = create_context(self.m, password=None)
+ self.assertRaises(exception.MissingCredentialError,
+ self.man.update_stack,
+ ctx, stack.identifier(), template, params,
+ None, {})
+
+ ctx = self.ctx = create_context(self.m, user=None)
+ self.assertRaises(exception.MissingCredentialError,
+ self.man.update_stack,
+ ctx, stack.identifier(), template, params,
+ None, {})
+
class stackServiceSuspendResumeTest(HeatTestCase):