示例#1
0
class TestTypeList(TestResourceType):

    expected_columns = ['Resource Type']
    list_response = [
        resource_types.ResourceType(None, 'BBB'),
        resource_types.ResourceType(None, 'AAA'),
        resource_types.ResourceType(None, 'CCC')
    ]
    expected_rows = [['AAA'], ['BBB'], ['CCC']]

    def setUp(self):
        super(TestTypeList, self).setUp()
        self.cmd = resource_type.ResourceTypeList(self.app, None)
        self.mock_client.resource_types.list = mock.Mock(
            return_value=self.list_response)

    def test_resourcetype_list(self):
        arglist = []
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)

        self.mock_client.resource_types.list.assert_called_with(filters={})
        self.assertEqual(self.expected_columns, columns)
        self.assertEqual(self.expected_rows, rows)

    def test_resourcetype_list_filter(self):
        arglist = ['--filter', 'name=B']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)

        self.mock_client.resource_types.list.assert_called_once_with(
            filters={'name': 'B'})
        self.assertEqual(self.expected_columns, columns)
        self.assertEqual(self.expected_rows, rows)

    def test_resourcetype_list_filters(self):
        arglist = ['--filter', 'name=B', '--filter', 'version=123']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)

        self.mock_client.resource_types.list.assert_called_once_with(
            filters={
                'name': 'B',
                'version': '123'
            })
        self.assertEqual(self.expected_columns, columns)
        self.assertEqual(self.expected_rows, rows)
示例#2
0
def data(TEST):
    TEST.stacks = utils.TestDataContainer()
    TEST.stack_templates = utils.TestDataContainer()
    TEST.stack_environments = utils.TestDataContainer()
    TEST.stack_snapshot_create = utils.TestDataContainer()
    TEST.stack_snapshot = utils.TestDataContainer()
    TEST.resource_types = utils.TestDataContainer()
    TEST.heat_resources = utils.TestDataContainer()
    TEST.heat_services = utils.TestDataContainer()
    TEST.template_versions = utils.TestDataContainer()
    TEST.template_functions = utils.TestDataContainer()

    # Services
    service_1 = services.Service(
        services.ServiceManager(None), {
            "status": "up",
            "binary": "heat-engine",
            "report_interval": 60,
            "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d1",
            "created_at": "2015-02-06T03:23:32.000000",
            "hostname": "mrkanag",
            "updated_at": "2015-02-20T09:49:52.000000",
            "topic": "engine",
            "host": "engine-1",
            "deleted_at": None,
            "id": "1efd7015-5016-4caa-b5c8-12438af7b100"
        })

    service_2 = services.Service(
        services.ServiceManager(None), {
            "status": "up",
            "binary": "heat-engine",
            "report_interval": 60,
            "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d2",
            "created_at": "2015-02-06T03:23:32.000000",
            "hostname": "mrkanag",
            "updated_at": "2015-02-20T09:49:52.000000",
            "topic": "engine",
            "host": "engine-2",
            "deleted_at": None,
            "id": "1efd7015-5016-4caa-b5c8-12438af7b100"
        })

    TEST.heat_services.add(service_1)
    TEST.heat_services.add(service_2)

    # Data return by heatclient.
    TEST.api_resource_types = utils.TestDataContainer()

    for i in range(10):
        stack_data = {
            "description":
            "No description",
            "links": [{
                "href":
                "http://192.168.1.70:8004/v1/"
                "051c727ee67040d6a7b7812708485a97/"
                "stacks/stack-test{0}/"
                "05b4f39f-ea96-4d91-910c-e758c078a089{0}".format(i),
                "rel":
                "self"
            }],
            "parameters": {
                'DBUsername':
                '******',
                'InstanceType':
                'm1.small',
                'AWS::StackId':
                ('arn:openstack:heat::2ce287:stacks/teststack/88553ec'),
                'DBRootPassword':
                '******',
                'AWS::StackName':
                "teststack{0}".format(i),
                'DBPassword':
                '******',
                'AWS::Region':
                'ap-southeast-1',
                'DBName':
                u'wordpress'
            },
            "stack_status_reason":
            "Stack successfully created",
            "stack_name":
            "stack-test{0}".format(i),
            "creation_time":
            "2013-04-22T00:11:39Z",
            "updated_time":
            "2013-04-22T00:11:39Z",
            "stack_status":
            "CREATE_COMPLETE",
            "id":
            "05b4f39f-ea96-4d91-910c-e758c078a089{0}".format(i)
        }
        stack = stacks.Stack(stacks.StackManager(None), stack_data)
        TEST.stacks.add(stack)

    for i in range(10):
        snapshot_data = {
            "status": "COMPLETE",
            "name": 'null',
            "data": {
                "files": {},
                "status": "COMPLETE",
                "name": "zhao3",
                "tags": ["a", " 123", " b", " 456"],
                "stack_user_project_id": "3cba4460875444049a2a7cc5420ccddb",
                "environment": {
                    "encrypted_param_names": [],
                    "parameter_defaults": {},
                    "event_sinks": [],
                    "parameters": {},
                    "resource_registry": {
                        "resources": {}
                    }
                },
                "template": {
                    "heat_template_version": "2013-05-23",
                    "description": "HOT template for Test.",
                    "resources": {
                        "private_subnet": {
                            "type": "OS::Neutron::Subnet",
                            "properties": {
                                "network_id": {
                                    "get_resource": "private_net"
                                },
                                "cidr": "172.16.2.0/24",
                                "gateway_ip": "172.16.2.1"
                            }
                        },
                        "private_net": {
                            "type": "OS::Neutron::Net",
                            "properties": {
                                "name": "private-net"
                            }
                        }
                    }
                },
                "action": "SNAPSHOT",
                "project_id": "1acd0026829f4d28bb2eff912d7aad0d",
                "id": "70650725-bdbd-419f-b53f-5707767bfe0e",
                "resources": {
                    "private_subnet": {
                        "status": "COMPLETE",
                        "name": "private_subnet",
                        "resource_data": {},
                        "resource_id": "9c7211b3-31c7-41f6-b92a-442ad3f71ef0",
                        "action": "SNAPSHOT",
                        "type": "OS::Neutron::Subnet",
                        "metadata": {}
                    },
                    "private_net": {
                        "status": "COMPLETE",
                        "name": "private_net",
                        "resource_data": {},
                        "resource_id": "ff4fd287-31b2-4d00-bc96-c409bc1db027",
                        "action": "SNAPSHOT",
                        "type": "OS::Neutron::Net",
                        "metadata": {}
                    }
                }
            },
            "creation_time": "2016-02-21T04:02:54",
            "status_reason": "Stack SNAPSHOT completed successfully",
            "id": "01558a3b-ba05-4427-bbb4-1e4ab71cfca{0}".format(i)
        }
        TEST.stack_snapshot.add(snapshot_data)

    TEST.stack_templates.add(Template(TEMPLATE, VALIDATE))
    TEST.stack_environments.add(Environment(ENVIRONMENT))
    TEST.stack_snapshot_create.add(Snapshot(SNAPSHOT_CREATE))

    # Resource types list
    r_type_1 = {
        "resource_type": "AWS::CloudFormation::Stack",
        "attributes": {},
        "properties": {
            "Parameters": {
                "description":
                "The set of parameters passed to this nested stack.",
                "immutable": False,
                "required": False,
                "type": "map",
                "update_allowed": True
            },
            "TemplateURL": {
                "description": "The URL of a template that specifies"
                " the stack to be created as a resource.",
                "immutable": False,
                "required": True,
                "type": "string",
                "update_allowed": True
            },
            "TimeoutInMinutes": {
                "description": "The length of time, in minutes,"
                " to wait for the nested stack creation.",
                "immutable": False,
                "required": False,
                "type": "number",
                "update_allowed": True
            }
        }
    }

    r_type_2 = {
        "resource_type": "OS::Heat::CloudConfig",
        "attributes": {
            "config": {
                "description": "The config value of the software config."
            }
        },
        "properties": {
            "cloud_config": {
                "description": "Map representing the cloud-config data"
                " structure which will be formatted as YAML.",
                "immutable": False,
                "required": False,
                "type": "map",
                "update_allowed": False
            }
        }
    }

    r_types_list = [r_type_1, r_type_2]

    for rt in r_types_list:
        r_type = resource_types.ResourceType(
            resource_types.ResourceTypeManager(None), rt['resource_type'])
        TEST.resource_types.add(r_type)
        TEST.api_resource_types.add(rt)

    # Resources
    resource_1 = resources.Resource(
        resources.ResourceManager(None), {
            "logical_resource_id":
            "my_resource",
            "physical_resource_id":
            "7b5e29b1-c94d-402d-b69c-df9ac6dfc0ce",
            "resource_name":
            "my_resource",
            "links": [{
                "href":
                "http://192.168.1.70:8004/v1/"
                "051c727ee67040d6a7b7812708485a97/"
                "stacks/%s/%s/resources/my_resource" %
                (TEST.stacks.first().stack_name, TEST.stacks.first().id),
                "rel":
                "self"
            }, {
                "href":
                "http://192.168.1.70:8004/v1/"
                "051c727ee67040d6a7b7812708485a97/"
                "stacks/%s/%s" %
                (TEST.stacks.first().stack_name, TEST.stacks.first().id),
                "rel":
                "stack"
            }],
            "attributes": {
                "metadata": {}
            }
        })

    TEST.heat_resources.add(resource_1)

    # Template versions
    template_version_1 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "version": "HeatTemplateFormatVersion.2012-12-12",
            "type": "cfn"
        })

    template_version_2 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "version": "heat_template_version.2013-05-23",
            "type": "hot"
        })

    TEST.template_versions.add(template_version_1)
    TEST.template_versions.add(template_version_2)

    # Template functions
    template_function_1 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "functions": "Fn::GetAZs",
            "description": "A function for retrieving the availability zones."
        })

    template_function_2 = template_versions.TemplateVersion(
        template_versions.TemplateVersionManager(None), {
            "functions": "Fn::Join",
            "description": "A function for joining strings."
        })

    TEST.template_functions.add(template_function_1)
    TEST.template_functions.add(template_function_2)
示例#3
0
def data(TEST):
    TEST.stacks = utils.TestDataContainer()
    TEST.stack_templates = utils.TestDataContainer()
    TEST.stack_environments = utils.TestDataContainer()
    TEST.resource_types = utils.TestDataContainer()
    TEST.heat_resources = utils.TestDataContainer()
    TEST.heat_services = utils.TestDataContainer()

    # Services
    service_1 = services.Service(services.ServiceManager(None), {
        "status": "up",
        "binary": "heat-engine",
        "report_interval": 60,
        "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d1",
        "created_at": "2015-02-06T03:23:32.000000",
        "hostname": "mrkanag",
        "updated_at": "2015-02-20T09:49:52.000000",
        "topic": "engine",
        "host": "engine-1",
        "deleted_at": None,
        "id": "1efd7015-5016-4caa-b5c8-12438af7b100"
    })

    service_2 = services.Service(services.ServiceManager(None), {
        "status": "up",
        "binary": "heat-engine",
        "report_interval": 60,
        "engine_id": "2f7b5a9b-c50b-4b01-8248-f89f5fb338d2",
        "created_at": "2015-02-06T03:23:32.000000",
        "hostname": "mrkanag",
        "updated_at": "2015-02-20T09:49:52.000000",
        "topic": "engine",
        "host": "engine-2",
        "deleted_at": None,
        "id": "1efd7015-5016-4caa-b5c8-12438af7b100"
    })

    TEST.heat_services.add(service_1)
    TEST.heat_services.add(service_2)

    # Data return by heatclient.
    TEST.api_resource_types = utils.TestDataContainer()

    for i in range(10):
        stack_data = {
            "description": "No description",
            "links": [{
                "href": "http://192.168.1.70:8004/v1/"
                        "051c727ee67040d6a7b7812708485a97/"
                        "stacks/stack-test{0}/"
                        "05b4f39f-ea96-4d91-910c-e758c078a089{0}".format(i),
                "rel": "self"
            }],
            "parameters": {
                'DBUsername': '******',
                'InstanceType': 'm1.small',
                'AWS::StackId': (
                    'arn:openstack:heat::2ce287:stacks/teststack/88553ec'),
                'DBRootPassword': '******',
                'AWS::StackName': "teststack{0}".format(i),
                'DBPassword': '******',
                'AWS::Region': 'ap-southeast-1',
                'DBName': u'wordpress'
            },
            "stack_status_reason": "Stack successfully created",
            "stack_name": "stack-test{0}".format(i),
            "creation_time": "2013-04-22T00:11:39Z",
            "updated_time": "2013-04-22T00:11:39Z",
            "stack_status": "CREATE_COMPLETE",
            "id": "05b4f39f-ea96-4d91-910c-e758c078a089{0}".format(i)
        }
        stack = stacks.Stack(stacks.StackManager(None), stack_data)
        TEST.stacks.add(stack)

    TEST.stack_templates.add(Template(TEMPLATE, VALIDATE))
    TEST.stack_environments.add(Environment(ENVIRONMENT))

    # Resource types list
    r_type_1 = {
        "resource_type": "AWS::CloudFormation::Stack",
        "attributes": {},
        "properties": {
            "Parameters": {
                "description":
                    "The set of parameters passed to this nested stack.",
                "immutable": False,
                "required": False,
                "type": "map",
                "update_allowed": True},
            "TemplateURL": {
                "description": "The URL of a template that specifies"
                               " the stack to be created as a resource.",
                "immutable": False,
                "required": True,
                "type": "string",
                "update_allowed": True},
            "TimeoutInMinutes": {
                "description": "The length of time, in minutes,"
                               " to wait for the nested stack creation.",
                "immutable": False,
                "required": False,
                "type": "number",
                "update_allowed": True}
        }
    }

    r_type_2 = {
        "resource_type": "OS::Heat::CloudConfig",
        "attributes": {
            "config": {
                "description": "The config value of the software config."}
        },
        "properties": {
            "cloud_config": {
                "description": "Map representing the cloud-config data"
                               " structure which will be formatted as YAML.",
                "immutable": False,
                "required": False,
                "type": "map",
                "update_allowed": False}
        }
    }

    r_types_list = [r_type_1, r_type_2]

    for rt in r_types_list:
        r_type = resource_types.ResourceType(
            resource_types.ResourceTypeManager(None), rt['resource_type'])
        TEST.resource_types.add(r_type)
        TEST.api_resource_types.add(rt)

    # Resources
    resource_1 = resources.Resource(resources.ResourceManager(None), {
        "logical_resource_id": "my_resource",
        "physical_resource_id": "7b5e29b1-c94d-402d-b69c-df9ac6dfc0ce",
        "resource_name": "my_resource",
        "links": [
            {
                "href": "http://192.168.1.70:8004/v1/"
                        "051c727ee67040d6a7b7812708485a97/"
                        "stacks/%s/%s/resources/my_resource" %
                        (TEST.stacks.first().stack_name,
                         TEST.stacks.first().id),
                "rel": "self"
            },
            {
                "href": "http://192.168.1.70:8004/v1/"
                        "051c727ee67040d6a7b7812708485a97/"
                        "stacks/%s/%s" %
                        (TEST.stacks.first().stack_name,
                         TEST.stacks.first().id),
                "rel": "stack"
            }
        ],
        "attributes": {
            "metadata": {}
        }
    })

    TEST.heat_resources.add(resource_1)
示例#4
0
class TestTypeList(TestResourceType):

    expected_columns = ['Resource Type']
    list_response = [
        resource_types.ResourceType(None, {'resource_type': 'BBB',
                                           'description': 'This is BBB'}),
        resource_types.ResourceType(None, {'resource_type': 'AAA',
                                           'description': 'Well done'}),
        resource_types.ResourceType(None,
                                    {'resource_type': 'CCC',
                                     'description': 'No description given'})
    ]
    expected_rows = [
        ['AAA'],
        ['BBB'],
        ['CCC']
    ]

    def setUp(self):
        super(TestTypeList, self).setUp()
        self.cmd = resource_type.ResourceTypeList(self.app, None)
        self.mock_client.resource_types.list.return_value = self.list_response

    def test_resourcetype_list(self):
        arglist = []
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)

        self.mock_client.resource_types.list.assert_called_with(
            filters={}, with_description=False)
        self.assertEqual(self.expected_columns, columns)
        self.assertEqual(self.expected_rows, rows)

    def test_resourcetype_list_filter(self):
        arglist = ['--filter', 'name=B']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)

        self.mock_client.resource_types.list.assert_called_once_with(
            filters={'name': 'B'}, with_description=False)
        self.assertEqual(self.expected_columns, columns)
        self.assertEqual(self.expected_rows, rows)

    def test_resourcetype_list_filters(self):
        arglist = ['--filter', 'name=B', '--filter', 'version=123']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)

        self.mock_client.resource_types.list.assert_called_once_with(
            filters={'name': 'B', 'version': '123'}, with_description=False)
        self.assertEqual(self.expected_columns, columns)
        self.assertEqual(self.expected_rows, rows)

    def test_resourcetype_list_with_description(self):
        arglist = ['--long']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)

        self.mock_client.resource_types.list.assert_called_once_with(
            filters={}, with_description=True)
        self.assertEqual(['Resource Type', 'Description'], columns)
        self.assertEqual([['AAA', 'Well done'],
                          ['BBB', 'This is BBB'],
                          ['CCC', 'No description given']],
                         rows)