Пример #1
0
    def test_event_log_formatter(self):
        event1 = {
            'event_time': '2015-09-28T12:12:12',
            'id': '123456789',
            'resource_name': 'res_name',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'CREATE started'
        }
        event2 = {
            'event_time': '2015-09-28T12:12:22',
            'id': '123456789',
            'resource_name': 'res_name',
            'resource_status': 'CREATE_COMPLETE',
            'resource_status_reason': 'CREATE completed'
        }
        events_list = [
            hc_res.Resource(manager=None, info=event1),
            hc_res.Resource(manager=None, info=event2)
        ]

        expected = ('2015-09-28 12:12:12 [res_name]: '
                    'CREATE_IN_PROGRESS  CREATE started\n'
                    '2015-09-28 12:12:22 [res_name]: '
                    'CREATE_COMPLETE  CREATE completed')
        self.assertEqual(expected, utils.event_log_formatter(events_list))
        self.assertEqual('', utils.event_log_formatter([]))
Пример #2
0
 def _mock_resource(resource_id, nested_id=None):
     res_info = {
         "links": [{
             "href": "http://heat/foo",
             "rel": "self"
         }, {
             "href": "http://heat/foo2",
             "rel": "resource"
         }],
         "logical_resource_id":
         resource_id,
         "physical_resource_id":
         resource_id,
         "resource_status":
         "CREATE_COMPLETE",
         "resource_status_reason":
         "state changed",
         "resource_type":
         "OS::Nested::Server",
         "updated_time":
         "2014-01-06T16:14:26Z"
     }
     if nested_id:
         nested_link = {
             "href": "http://heat/%s" % nested_id,
             "rel": "nested"
         }
         res_info["links"].append(nested_link)
     return hc_res.Resource(manager=None, info=res_info)
Пример #3
0
 def test_resource_nested_identifier_none(self):
     rsrc_info = {'resource_name': 'aresource',
                  'links': [{'href': u'http://foo/name/id/resources/0',
                             'rel': u'self'},
                            {'href': u'http://foo/name/id',
                             'rel': u'stack'}]}
     rsrc = hc_res.Resource(manager=None, info=rsrc_info)
     self.assertIsNone(utils.resource_nested_identifier(rsrc))
 def test_stack_name(self):
     resource = resources.Resource(None, {"links": [{
         "href": "http://heat.example.com:8004/foo/12/resources/foobar",
         "rel": "self"
     }, {
         "href": "http://heat.example.com:8004/foo/12",
         "rel": "stack"
     }]})
     self.assertEqual('foo', resource.stack_name)
Пример #5
0
 def setUp(self):
     super(TestStackResourceListDotFormat, self).setUp()
     self.resource_client = self.app.client_manager.orchestration.resources
     self.cmd = resource.ResourceList(self.app, None)
     with open(self.response_path) as f:
         response = json.load(f)
     self.resources = []
     for r in response['resources']:
         self.resources.append(v1_resources.Resource(None, r))
Пример #6
0
class TestStackHookClear(TestStack):

    stack = stacks.Stack(
        None, {
            "id": '1234',
            "stack_name": 'my_stack',
            "creation_time": "2013-08-04T20:57:55Z",
            "updated_time": "2013-08-04T20:57:55Z",
            "stack_status": "CREATE_IN_PROGRESS"
        })
    resource = resources.Resource(None, {
        'stack_id': 'my_stack',
        'resource_name': 'resource'
    })

    def setUp(self):
        super(TestStackHookClear, self).setUp()
        self.cmd = stack.StackHookClear(self.app, None)
        self.mock_client.stacks.get = mock.Mock(return_value=self.stack)
        self.mock_client.resources.signal = mock.Mock()
        self.mock_client.resources.list = mock.Mock(
            return_value=[self.resource])

    def test_hook_clear(self):
        arglist = ['my_stack', 'resource']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        self.cmd.take_action(parsed_args)
        self.mock_client.resources.signal.assert_called_once_with(
            data={'unset_hook': 'pre-create'},
            resource_name='resource',
            stack_id='my_stack')

    def test_hook_clear_pre_create(self):
        arglist = ['my_stack', 'resource', '--pre-create']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        self.cmd.take_action(parsed_args)
        self.mock_client.resources.signal.assert_called_once_with(
            data={'unset_hook': 'pre-create'},
            resource_name='resource',
            stack_id='my_stack')

    def test_hook_clear_pre_update(self):
        arglist = ['my_stack', 'resource', '--pre-update']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        self.cmd.take_action(parsed_args)
        self.mock_client.resources.signal.assert_called_once_with(
            data={'unset_hook': 'pre-update'},
            resource_name='resource',
            stack_id='my_stack')
Пример #7
0
    def test_resource_list_no_resource_name(self):
        arglist = ['my_stack']
        resp = copy.deepcopy(self.response)
        del resp['resource_name']
        cols = copy.deepcopy(self.columns)
        cols[0] = 'logical_resource_id'
        out = copy.deepcopy(self.data)
        out[1] = '1234'
        self.resource_client.list.return_value = [
            v1_resources.Resource(None, resp)
        ]
        parsed_args = self.check_parser(self.cmd, arglist, [])

        columns, data = self.cmd.take_action(parsed_args)

        self.resource_client.list.assert_called_with('my_stack',
                                                     filters={},
                                                     with_detail=False,
                                                     nested_depth=None)
        self.assertEqual(cols, columns)
Пример #8
0
 def test_stack_name_no_links(self):
     resource = resources.Resource(None, {})
     self.assertIsNone(resource.stack_name)
Пример #9
0
 def setUp(self):
     super(TestStackResourceShow, self).setUp()
     self.cmd = resource.ResourceShow(self.app, None)
     self.resource_client.get = mock.MagicMock(
         return_value=v1_resources.Resource(None, self.response))
Пример #10
0
 def setUp(self):
     super(TestStackResourceList, self).setUp()
     self.cmd = resource.ResourceList(self.app, None)
     self.resource_client.list = mock.MagicMock(
         return_value=[v1_resources.Resource(None, self.response)])
Пример #11
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)
Пример #12
0
def data(TEST):

    # Stack
    TEST.heatclient_stacks = test_data_utils.TestDataContainer()
    stack_1 = stacks.Stack(
        stacks.StackManager(None), {
            'id':
            'stack-id-1',
            'stack_name':
            'overcloud',
            'stack_status':
            'RUNNING',
            'outputs': [{
                'output_key': 'KeystoneURL',
                'output_value': 'http://192.0.2.23:5000/v2',
            }],
            'parameters': {
                'plan_id': 'plan-1',
                'one': 'one',
                'two': 'two',
            }
        })
    TEST.heatclient_stacks.add(stack_1)

    # Events
    TEST.heatclient_events = test_data_utils.TestDataContainer()
    event_1 = events.Event(
        events.EventManager(None), {
            'id': 1,
            'stack_id': 'stack-id-1',
            'resource_name': 'Controller',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:26:15Z'
        })
    event_2 = events.Event(
        events.EventManager(None), {
            'id': 2,
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute0',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:26:27Z'
        })
    event_3 = events.Event(
        events.EventManager(None), {
            'id': 3,
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute1',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:26:44Z'
        })
    event_4 = events.Event(
        events.EventManager(None), {
            'id': 4,
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute0',
            'resource_status': 'CREATE_COMPLETE',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:27:14Z'
        })
    event_5 = events.Event(
        events.EventManager(None), {
            'id': 5,
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute2',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:27:31Z'
        })
    event_6 = events.Event(
        events.EventManager(None), {
            'id': 6,
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute1',
            'resource_status': 'CREATE_COMPLETE',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:28:01Z'
        })
    event_7 = events.Event(
        events.EventManager(None), {
            'id': 7,
            'stack_id': 'stack-id-1',
            'resource_name': 'Controller',
            'resource_status': 'CREATE_COMPLETE',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:28:59Z'
        })
    event_8 = events.Event(
        events.EventManager(None), {
            'id': 8,
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute2',
            'resource_status': 'CREATE_COMPLETE',
            'resource_status_reason': 'state changed',
            'event_time': '2014-01-01T07:29:11Z'
        })
    TEST.heatclient_events.add(event_1, event_2, event_3, event_4, event_5,
                               event_6, event_7, event_8)

    # Resource
    TEST.heatclient_resources = test_data_utils.TestDataContainer()
    resource_1 = resources.Resource(
        resources.ResourceManager(None), {
            'id': '1-resource-id',
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute0',
            'logical_resource_id': 'Compute0',
            'physical_resource_id': 'aa',
            'resource_status': 'CREATE_COMPLETE',
            'resource_type': 'Compute'
        })
    resource_2 = resources.Resource(
        resources.ResourceManager(None), {
            'id': '2-resource-id',
            'stack_id': 'stack-id-1',
            'resource_name': 'Controller',
            'logical_resource_id': 'Controller',
            'physical_resource_id': 'bb',
            'resource_status': 'CREATE_COMPLETE',
            'resource_type': 'Controller'
        })
    resource_3 = resources.Resource(
        resources.ResourceManager(None), {
            'id': '3-resource-id',
            'stack_id': 'stack-id-1',
            'resource_name': 'Compute1',
            'logical_resource_id': 'Compute1',
            'physical_resource_id': 'cc',
            'resource_status': 'CREATE_COMPLETE',
            'resource_type': 'Compute'
        })
    resource_4 = resources.Resource(
        resources.ResourceManager(None), {
            'id': '4-resource-id',
            'stack_id': 'stack-id-4',
            'resource_name': 'Compute2',
            'logical_resource_id': 'Compute2',
            'physical_resource_id': 'dd',
            'resource_status': 'CREATE_COMPLETE',
            'resource_type': 'Compute'
        })
    TEST.heatclient_resources.add(resource_1, resource_2, resource_3,
                                  resource_4)

    # Server
    TEST.novaclient_servers = test_data_utils.TestDataContainer()
    s_1 = servers.Server(
        servers.ServerManager(None), {
            'id': 'aa',
            'name': 'Compute',
            'created': '2014-06-26T20:38:06Z',
            'image': {
                'id': '1'
            },
            'flavor': {
                'id': '1',
            },
            'status': 'ACTIVE',
            'public_ip': '192.168.1.1'
        })
    s_2 = servers.Server(
        servers.ServerManager(None), {
            'id': 'bb',
            'name': 'Controller',
            'created': '2014-06-27T20:38:06Z',
            'image': {
                'id': '2'
            },
            'flavor': {
                'id': '2',
            },
            'status': 'ACTIVE',
            'public_ip': '192.168.1.2'
        })
    s_3 = servers.Server(
        servers.ServerManager(None), {
            'id': 'cc',
            'name': 'Compute',
            'created': '2014-06-28T20:38:06Z',
            'image': {
                'id': '1'
            },
            'flavor': {
                'id': '1',
            },
            'status': 'BUILD',
            'public_ip': '192.168.1.3'
        })
    s_4 = servers.Server(
        servers.ServerManager(None), {
            'id': 'dd',
            'name': 'Compute',
            'created': '2014-06-29T20:38:06Z',
            'image': {
                'id': '1'
            },
            'flavor': {
                'id': '1',
            },
            'status': 'ERROR',
            'public_ip': '192.168.1.4'
        })
    TEST.novaclient_servers.add(s_1, s_2, s_3, s_4)

    # Image
    TEST.glanceclient_images = test_data_utils.TestDataContainer()
    image_1 = images.Image(images.ImageManager(None), {
        'id': '2',
        'name': 'overcloud-control'
    })
    image_2 = images.Image(images.ImageManager(None), {
        'id': '1',
        'name': 'overcloud-compute'
    })
    image_3 = images.Image(images.ImageManager(None), {
        'id': '3',
        'name': 'Object Storage Image'
    })
    image_4 = images.Image(images.ImageManager(None), {
        'id': '4',
        'name': 'Block Storage Image'
    })
    TEST.glanceclient_images.add(image_1, image_2, image_3, image_4)
Пример #13
0
class TestStackHookPoll(TestStack):

    stack = stacks.Stack(
        None, {
            "id": '1234',
            "stack_name": 'my_stack',
            "creation_time": "2013-08-04T20:57:55Z",
            "updated_time": "2013-08-04T20:57:55Z",
            "stack_status": "CREATE_IN_PROGRESS"
        })
    resource = resources.Resource(
        None, {
            'resource_name':
            'resource1',
            'links': [{
                'href': 'http://heat.example.com:8004/resource1',
                'rel': 'self'
            }, {
                'href': 'http://192.168.27.100:8004/my_stack',
                'rel': 'stack'
            }],
            'logical_resource_id':
            'random_group',
            'creation_time':
            '2015-12-03T16:50:56',
            'resource_status':
            'INIT_COMPLETE',
            'updated_time':
            '2015-12-03T16:50:56',
            'required_by': [],
            'resource_status_reason':
            '',
            'physical_resource_id':
            '',
            'resource_type':
            'OS::Heat::ResourceGroup',
            'id':
            '1111'
        })
    columns = ['ID', 'Resource Status Reason', 'Resource Status', 'Event Time']
    event0 = events.Event(manager=None,
                          info={
                              'resource_name': 'my_stack',
                              'event_time': '2015-12-02T16:50:56',
                              'logical_resource_id': 'my_stack',
                              'resource_status': 'CREATE_IN_PROGRESS',
                              'resource_status_reason': 'Stack CREATE started',
                              'id': '1234'
                          })
    event1 = events.Event(manager=None,
                          info={
                              'resource_name': 'resource1',
                              'event_time': '2015-12-03T19:59:58',
                              'logical_resource_id': 'resource1',
                              'resource_status': 'INIT_COMPLETE',
                              'resource_status_reason':
                              'CREATE paused until Hook pre-create is cleared',
                              'id': '1111'
                          })
    row1 = ('resource1', '1111',
            'CREATE paused until Hook pre-create is cleared', 'INIT_COMPLETE',
            '2015-12-03T19:59:58')

    def setUp(self):
        super(TestStackHookPoll, self).setUp()
        self.cmd = stack.StackHookPoll(self.app, None)
        self.mock_client.stacks.get = mock.Mock(return_value=self.stack)
        self.mock_client.events.list = mock.Mock(
            return_value=[self.event0, self.event1])
        self.mock_client.resources.list = mock.Mock(
            return_value=[self.resource])

    def test_hook_poll(self):
        expected_columns = ['Resource Name'] + self.columns
        expected_rows = [self.row1]
        arglist = ['my_stack']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)
        self.assertEqual(expected_rows, list(rows))
        self.assertEqual(expected_columns, columns)

    def test_hook_poll_nested(self):
        expected_columns = ['Resource Name'] + self.columns + ['Stack Name']
        expected_rows = [self.row1 + ('my_stack', )]
        arglist = ['my_stack', '--nested-depth=10']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)
        self.assertEqual(expected_rows, list(rows))
        self.assertEqual(expected_columns, columns)

    def test_hook_poll_nested_invalid(self):
        arglist = ['my_stack', '--nested-depth=ugly']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
Пример #14
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)
Пример #15
0
    def test_event_log_formatter_resource_path(self):

        events = [{
            'resource_name': 'nested',
            'event_time': '2016-09-05T04:10:24Z',
            'links': [{
                'href': 'http://192.0.2.1:8004/v1/t/stacks/'
                'nested/1bed5d4d-41d6-4451-b274-c073ebee375d',
                'rel': 'stack'
            }],
            'logical_resource_id': 'nested',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'Stack CREATE started',
            'physical_resource_id': '1bed5d4d-41d6-4451-b274-c073ebee375d',
        }, {
            'resource_name': 'rg1',
            'event_time': '2016-09-05T04:10:24Z',
            'links': [{
                'href': 'http://192.0.2.1:8004/v1/t/stacks/'
                'nested/1bed5d4d-41d6-4451-b274-c073ebee375d',
                'rel': 'stack'
            }],
            'logical_resource_id': 'rg1',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'state changed',
            'physical_resource_id': 'nested-rg1-m4zxcs4pra6t',
            'id': '375c49ae-cefb-4fb3-8f4d-1d5f1b9e3e5d'
        }, {
            'resource_name': 'nested-rg1-m4zxcs4pra6t',
            'event_time': '2016-09-05T04:10:24Z',
            'links': [{
                'href': 'http://192.0.2.1:8004/v1/t/stacks/'
                'nested-rg1-m4zxcs4pra6t/'
                '3400bbad-a825-4226-ac23-c607846420db',
                'rel': 'stack'
            }],
            'logical_resource_id': 'nested-rg1-m4zxcs4pra6t',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'Stack CREATE started',
            'physical_resource_id': '3400bbad-a825-4226-ac23-c607846420db',
            'id': '7e521c84-cd35-4f4c-b0de-962bd3cc40a8'
        }, {
            'resource_name': '1',
            'event_time': '2016-09-05T04:10:24Z',
            'links': [{
                'href': 'http://192.0.2.1:8004/v1/t/stacks/'
                'nested-rg1-m4zxcs4pra6t/'
                '3400bbad-a825-4226-ac23-c607846420db',
                'rel': 'stack'
            }],
            'logical_resource_id': '1',
            'resource_status': 'CREATE_IN_PROGRESS',
            'resource_status_reason': 'state changed',
            'physical_resource_id': 'nested-rg1-m4zxcs4pra6t-1-z6sgpq54n6e7',
            'id': 'c6186c16-94ef-4214-a11a-7e3cc8a17f82'
        }]

        events_list = [hc_res.Resource(manager=None, info=event)
                       for event in events]

        expected = '''\
2016-09-05 04:10:24Z [nested]: \
CREATE_IN_PROGRESS  Stack CREATE started
2016-09-05 04:10:24Z [nested.rg1]: \
CREATE_IN_PROGRESS  state changed
2016-09-05 04:10:24Z [nested.rg1]: \
CREATE_IN_PROGRESS  Stack CREATE started
2016-09-05 04:10:24Z [nested.rg1.1]: \
CREATE_IN_PROGRESS  state changed'''
        self.assertEqual(expected, utils.event_log_formatter(events_list))