def test_format_stack_updated_time(self): self.stack.updated_time = None info = api.format_stack(self.stack) self.assertIsNone(info['updated_time']) self.stack.updated_time = datetime(1970, 1, 1) info = api.format_stack(self.stack) self.assertEqual('1970-01-01T00:00:00Z', info['updated_time'])
def test_format_stack(self): self.stack.created_time = datetime(1970, 1, 1) info = api.format_stack(self.stack) aws_id = ('arn:openstack:heat::test_tenant_id:' 'stacks/test_stack/' + self.stack.id) expected_stack_info = { 'capabilities': [], 'creation_time': '1970-01-01T00:00:00Z', 'description': 'No description', 'disable_rollback': True, 'notification_topics': [], 'stack_action': '', 'stack_name': 'test_stack', 'stack_status': '', 'stack_status_reason': '', 'template_description': 'No description', 'timeout_mins': None, 'parameters': { 'AWS::Region': 'ap-southeast-1', 'AWS::StackId': aws_id, 'AWS::StackName': 'test_stack'}, 'stack_identity': { 'path': '', 'stack_id': self.stack.id, 'stack_name': 'test_stack', 'tenant': 'test_tenant_id'}, 'updated_time': None} self.assertEqual(expected_stack_info, info)
def test_format_stack(self): self.stack.created_time = datetime(1970, 1, 1) info = api.format_stack(self.stack) aws_id = "arn:openstack:heat::test_tenant_id:" "stacks/test_stack/" + self.stack.id expected_stack_info = { "capabilities": [], "creation_time": "1970-01-01T00:00:00Z", "description": "No description", "disable_rollback": True, "notification_topics": [], "stack_action": "", "stack_name": "test_stack", "stack_status": "", "stack_status_reason": "", "template_description": "No description", "timeout_mins": None, "parameters": {"AWS::Region": "ap-southeast-1", "AWS::StackId": aws_id, "AWS::StackName": "test_stack"}, "stack_identity": { "path": "", "stack_id": self.stack.id, "stack_name": "test_stack", "tenant": "test_tenant_id", }, "updated_time": None, } self.assertEqual(expected_stack_info, info)
def test_format_stack(self): self.stack.created_time = datetime(1970, 1, 1) info = api.format_stack(self.stack) aws_id = ('arn:openstack:heat::test_tenant_id:' 'stacks/test_stack/' + self.stack.id) expected_stack_info = { 'capabilities': [], 'creation_time': '1970-01-01T00:00:00Z', 'description': 'No description', 'disable_rollback': True, 'notification_topics': [], 'stack_action': 'CREATE', 'stack_name': 'test_stack', 'stack_owner': 'test_username', 'stack_status': 'IN_PROGRESS', 'stack_status_reason': '', 'template_description': 'No description', 'timeout_mins': None, 'parameters': { 'AWS::Region': 'ap-southeast-1', 'AWS::StackId': aws_id, 'AWS::StackName': 'test_stack' }, 'stack_identity': { 'path': '', 'stack_id': self.stack.id, 'stack_name': 'test_stack', 'tenant': 'test_tenant_id' }, 'updated_time': None, 'parent': None } self.assertEqual(expected_stack_info, info)
def list_stacks(self, cnxt, limit=None, marker=None, sort_keys=None, sort_dir=None, filters=None, tenant_safe=True, show_deleted=False): """ The list_stacks method returns attributes of all stacks. It supports pagination (``limit`` and ``marker``), sorting (``sort_keys`` and ``sort_dir``) and filtering (``filters``) of the results. :param cnxt: RPC context :param limit: the number of stacks to list (integer or string) :param marker: the ID of the last item in the previous page :param sort_keys: an array of fields used to sort the list :param sort_dir: the direction of the sort ('asc' or 'desc') :param filters: a dict with attribute:value to filter the list :param tenant_safe: if true, scope the request by the current tenant :param show_deleted: if true, show soft-deleted stacks :returns: a list of formatted stacks """ stacks = parser.Stack.load_all(cnxt, limit, marker, sort_keys, sort_dir, filters, tenant_safe, show_deleted, resolve_data=False) return [api.format_stack(stack) for stack in stacks]
def format_stack_details(stacks): for s in stacks: try: stack = parser.Stack.load(context, stack=s, resolve_data=False) except exception.NotFound: # The stack may have been deleted between listing # and formatting pass else: yield api.format_stack(stack)
def format_stack_details(stacks): for s in stacks: try: stack = parser.Stack.load(cnxt, stack=s, resolve_data=False) except exception.NotFound: # The stack may have been deleted between listing # and formatting pass else: yield api.format_stack(stack)
def show_stack(self, cnxt, stack_identity): """ Return detailed information about one or all stacks. :param cnxt: RPC context. :param stack_identity: Name of the stack you want to show, or None to show all """ if stack_identity is not None: db_stack = self._get_stack(cnxt, stack_identity, show_deleted=True) stacks = [parser.Stack.load(cnxt, stack=db_stack)] else: stacks = parser.Stack.load_all(cnxt) return [api.format_stack(stack) for stack in stacks]
def list_stacks(self, cnxt, limit=None, marker=None, sort_keys=None, sort_dir=None, filters=None, tenant_safe=True, show_deleted=False): """ The list_stacks method returns attributes of all stacks. It supports pagination (``limit`` and ``marker``), sorting (``sort_keys`` and ``sort_dir``) and filtering (``filters``) of the results. :param cnxt: RPC context :param limit: the number of stacks to list (integer or string) :param marker: the ID of the last item in the previous page :param sort_keys: an array of fields used to sort the list :param sort_dir: the direction of the sort ('asc' or 'desc') :param filters: a dict with attribute:value to filter the list :param tenant_safe: if true, scope the request by the current tenant :param show_deleted: if true, show soft-deleted stacks :returns: a list of formatted stacks """ stacks = parser.Stack.load_all(cnxt, limit, sort_keys, marker, sort_dir, filters, tenant_safe, show_deleted, resolve_data=False) return [api.format_stack(stack) for stack in stacks]
def test_get_attribute(self): tmpl = template_format.parse(self.test_template) ctx = utils.dummy_context('test_username', 'aaaa', 'password') stack = parser.Stack(ctx, 'test', template.Template(tmpl)) stack.store() stack_res = stack['the_nested'] stack_res.store() nested_t = template_format.parse(self.nested_template) nested_t['Parameters']['KeyName']['Default'] = 'Key' nested_stack = parser.Stack(ctx, 'test', template.Template(nested_t)) nested_stack.store() stack_res._rpc_client = mock.MagicMock() stack_res._rpc_client.show_stack.return_value = [ api.format_stack(nested_stack) ] stack_res.nested_identifier = mock.Mock() stack_res.nested_identifier.return_value = {'foo': 'bar'} self.assertEqual('bar', stack_res.FnGetAtt('Outputs.Foo'))
def test_get_attribute(self): tmpl = template_format.parse(self.test_template) ctx = utils.dummy_context('test_username', 'aaaa', 'password') stack = parser.Stack(ctx, 'test', template.Template(tmpl)) stack.store() stack_res = stack['the_nested'] stack_res.store() nested_t = template_format.parse(self.nested_template) nested_t['Parameters']['KeyName']['Default'] = 'Key' nested_stack = parser.Stack(ctx, 'test', template.Template(nested_t)) nested_stack.store() stack_res._rpc_client = mock.MagicMock() stack_res._rpc_client.show_stack.return_value = [ api.format_stack(nested_stack)] stack_res.nested_identifier = mock.Mock() stack_res.nested_identifier.return_value = {'foo': 'bar'} self.assertEqual('bar', stack_res.FnGetAtt('Outputs.Foo'))
def test_format_stack_adds_outputs(self, mock_fmt_outputs): mock_fmt_outputs.return_value = 'foobar' self.stack.action = 'CREATE' self.stack.status = 'COMPLETE' info = api.format_stack(self.stack) self.assertEqual('foobar', info[rpc_api.STACK_OUTPUTS])
def format_stack_detail(s): stack = parser.Stack.load(context, stack=s, resolve_data=False) return api.format_stack(stack)
def test_format_stack_created_time(self): self.stack.created_time = None info = api.format_stack(self.stack) self.assertIsNotNone(info['creation_time'])
def format_stack_detail(s): stack = parser.Stack.load(cnxt, stack=s) return api.format_stack(stack)
def format_stack_detail(s): stack = parser.Stack.load(context, s.id) return api.format_stack(stack)
def test_format_stack_without_resolving_outputs(self, mock_fmt_outputs): mock_fmt_outputs.return_value = 'foobar' self.stack.action = 'CREATE' self.stack.status = 'COMPLETE' info = api.format_stack(self.stack, resolve_outputs=False) self.assertIsNone(info.get(rpc_api.STACK_OUTPUTS))
def test_format_stack_adds_outputs(self, mock_fmt_outputs): mock_fmt_outputs.return_value = "foobar" self.stack.action = "CREATE" self.stack.status = "COMPLETE" info = api.format_stack(self.stack) self.assertEqual("foobar", info[rpc_api.STACK_OUTPUTS])