Ejemplo n.º 1
0
    def test_stack_adopt_wait_fail(self, mock_poll):
        arglist = ['my_stack', '--adopt-file', self.adopt_file, '--wait']
        self.stack_client.get = mock.MagicMock(return_value=(
            stacks.Stack(None, {'stack_status': 'ADOPT_FAILED'})))
        parsed_args = self.check_parser(self.cmd, arglist, [])

        self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
Ejemplo n.º 2
0
def mock_stack(manager, stack_name, stack_id):
    return stacks.Stack(
        manager, {
            "id":
            stack_id,
            "stack_name":
            stack_name,
            "links": [{
                "href":
                "http://192.0.2.1:8004/v1/1234/stacks/%s/%s" %
                (stack_name, stack_id),
                "rel":
                "self"
            }],
            "description":
            "No description",
            "stack_status_reason":
            "Stack create completed successfully",
            "creation_time":
            "2013-08-04T20:57:55Z",
            "updated_time":
            "2013-08-04T20:57:55Z",
            "stack_status":
            "CREATE_COMPLETE"
        })
Ejemplo n.º 3
0
def data(TEST):
    TEST.stacks = utils.TestDataContainer()
    TEST.stack_templates = utils.TestDataContainer()

    # Stacks
    stack1 = {
        "description":
        "No description",
        "links": [{
            "href":
            "http://192.168.1.70:8004/v1/"
            "051c727ee67040d6a7b7812708485a97/"
            "stacks/stack-1211-38/"
            "05b4f39f-ea96-4d91-910c-e758c078a089",
            "rel":
            "self"
        }],
        "stack_status_reason":
        "Stack successfully created",
        "stack_name":
        "stack-test",
        "creation_time":
        "2013-04-22T00:11:39Z",
        "updated_time":
        "2013-04-22T00:11:39Z",
        "stack_status":
        "CREATE_COMPLETE",
        "id":
        "05b4f39f-ea96-4d91-910c-e758c078a089"
    }
    stack = stacks.Stack(stacks.StackManager(None), stack1)
    TEST.stacks.add(stack)

    TEST.stack_templates.add(Template(TEMPLATE, VALIDATE))
Ejemplo n.º 4
0
 def setUp(self):
     super(TestStackCreate, self).setUp()
     self.cmd = stack.CreateStack(self.app, None)
     self.stack_client.create = mock.MagicMock(
         return_value={'stack': {'id': '1234'}})
     self.stack_client.get = mock.MagicMock(
         return_value={'stack_status': 'create_complete'})
     self.stack_client.preview = mock.MagicMock(
         return_value=stacks.Stack(None, {'stack': {'id', '1234'}}))
     stack._authenticated_fetcher = mock.MagicMock()
Ejemplo n.º 5
0
    def test_stack_adopt_wait(self, mock_poll):
        arglist = ['my_stack', '--adopt-file', self.adopt_file, '--wait']
        self.stack_client.get = mock.MagicMock(return_value=(
            stacks.Stack(None, {'stack_status': 'ADOPT_COMPLETE'})))
        parsed_args = self.check_parser(self.cmd, arglist, [])

        self.cmd.take_action(parsed_args)

        self.stack_client.create.assert_called_with(**self.defaults)
        self.stack_client.get.assert_called_with(**{'stack_id': '1234'})
Ejemplo n.º 6
0
def data(TEST):
    TEST.stacks = utils.TestDataContainer()
    TEST.stack_templates = utils.TestDataContainer()
    TEST.stack_environments = utils.TestDataContainer()

    for i in range(10):
        stack_data = {
            "description":
            "No description",
            "links": [{
                "href":
                "http://192.168.1.70:8004/v1/"
                "051c727ee67040d6a7b7812708485a97/"
                "stacks/stack-1211-38/"
                "05b4f39f-ea96-4d91-910c-e758c078a089",
                "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))
Ejemplo n.º 7
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')
Ejemplo n.º 8
0
class TestStackCancel(_TestStackCheckBase, TestStack):

    stack_update_in_progress = 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": "UPDATE_IN_PROGRESS"
    })

    def setUp(self):
        super(TestStackCancel, self).setUp()
        self.mock_client.actions.cancel_update = mock.Mock()
        self._setUp(
            stack.CancelStack(self.app, None),
            self.mock_client.actions.cancel_update,
            'ROLLBACK'
        )
        self.mock_client.stacks.get = mock.Mock(
            return_value=self.stack_update_in_progress)

    def test_stack_cancel(self):
        self._test_stack_action(2)

    def test_stack_cancel_multi(self):
        self._test_stack_action_multi(4)

    def test_stack_cancel_wait(self):
        self._test_stack_action_wait()

    def test_stack_cancel_wait_error(self):
        self._test_stack_action_wait_error()

    def test_stack_cancel_exception(self):
        self._test_stack_action_exception()

    def test_stack_cancel_unsupported_state(self):
        self.mock_client.stacks.get = mock.Mock(
            return_value=self.stack)
        error = self.assertRaises(exc.CommandError,
                                  self._test_stack_action,
                                  2)
        self.assertEqual('Stack my_stack with status \'create_complete\' '
                         'not in cancelable state',
                         str(error))
Ejemplo n.º 9
0
def get_stack(stack_id='c8a19429-7fde-47ea-a42f-40045488226c',
              stack_name='teststack', description='No description',
              creation_time='2013-08-04T20:57:55Z',
              updated_time='2013-08-04T20:57:55Z',
              stack_status='CREATE_COMPLETE',
              stack_status_reason='',
              outputs=None):
    action = stack_status[:stack_status.index('_')]
    status = stack_status[stack_status.index('_') + 1:]
    data = {
        'id': stack_id,
        'stack_name': stack_name,
        'description': description,
        'creation_time': creation_time,
        'updated_time': updated_time,
        'stack_status': stack_status,
        'stack_status_reason': stack_status_reason,
        'action': action,
        'status': status,
        'outputs': outputs or None,
    }
    return stacks.Stack(mock.MagicMock(), data)
Ejemplo n.º 10
0
 def setUp(self):
     super(TestStackShow, self).setUp()
     self.cmd = stack.ShowStack(self.app, None)
     self.stack_client.get = mock.Mock(
         return_value=stacks.Stack(None, self.get_response))
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
 def setUp(self):
     super(TestStackOutputList, self).setUp()
     self.cmd = stack.OutputListStack(self.app, None)
     self.stack_client.get = mock.MagicMock(
         return_value=stacks.Stack(None, self.response))
Ejemplo n.º 15
0
 def test_is_diff_object_with_diff_type(self):
     # Two resources with different types: is different object
     r1 = events.Event(None, {'id': 1})
     r2 = stacks.Stack(None, {'id': 1})
     self.assertFalse(r1.is_same_obj(r2))
     self.assertFalse(r2.is_same_obj(r1))
Ejemplo n.º 16
0
 def setUp(self):
     super(TestStackList, self).setUp()
     self.cmd = stack.ListStack(self.app, None)
     self.stack_client.list = mock.MagicMock(
         return_value=[stacks.Stack(None, self.data)])
     utils.get_dict_properties = mock.MagicMock(return_value='')
Ejemplo n.º 17
0
class _TestStackCheckBase(object):

    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_COMPLETE"
        })

    columns = [
        'ID', 'Stack Name', 'Stack Status', 'Creation Time', 'Updated Time'
    ]

    def _setUp(self, cmd, action, action_name=None):
        self.cmd = cmd
        self.action = action
        self.mock_client.stacks.get = mock.Mock(return_value=self.stack)
        self.action_name = action_name

    def _test_stack_action(self, get_call_count=1):
        arglist = ['my_stack']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)
        self.action.assert_called_once_with('my_stack')
        self.mock_client.stacks.get.assert_called_with('my_stack')
        self.assertEqual(get_call_count,
                         self.mock_client.stacks.get.call_count)
        self.assertEqual(self.columns, columns)
        self.assertEqual(1, len(rows))

    def _test_stack_action_multi(self, get_call_count=2):
        arglist = ['my_stack1', 'my_stack2']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)
        self.assertEqual(2, self.action.call_count)
        self.assertEqual(get_call_count,
                         self.mock_client.stacks.get.call_count)
        self.action.assert_called_with('my_stack2')
        self.mock_client.stacks.get.assert_called_with('my_stack2')
        self.assertEqual(self.columns, columns)
        self.assertEqual(2, len(rows))

    @mock.patch('heatclient.common.event_utils.poll_for_events')
    @mock.patch('heatclient.common.event_utils.get_events', return_value=[])
    def _test_stack_action_wait(self, ge, mock_poll):
        arglist = ['my_stack', '--wait']
        mock_poll.return_value = ('%s_COMPLETE' % self.action_name,
                                  'Stack my_stack %s_COMPLETE' %
                                  self.action_name)
        parsed_args = self.check_parser(self.cmd, arglist, [])
        columns, rows = self.cmd.take_action(parsed_args)
        self.action.assert_called_with('my_stack')
        self.mock_client.stacks.get.assert_called_with('my_stack')
        self.assertEqual(self.columns, columns)
        self.assertEqual(1, len(rows))

    @mock.patch('heatclient.common.event_utils.poll_for_events')
    @mock.patch('heatclient.common.event_utils.get_events', return_value=[])
    def _test_stack_action_wait_error(self, ge, mock_poll):
        arglist = ['my_stack', '--wait']
        mock_poll.return_value = (
            '%s_FAILED' % self.action_name,
            'Error waiting for status from stack my_stack')
        parsed_args = self.check_parser(self.cmd, arglist, [])
        error = self.assertRaises(exc.CommandError, self.cmd.take_action,
                                  parsed_args)
        self.assertEqual('Error waiting for status from stack my_stack',
                         str(error))

    def _test_stack_action_exception(self):
        self.action.side_effect = heat_exc.HTTPNotFound
        arglist = ['my_stack']
        parsed_args = self.check_parser(self.cmd, arglist, [])
        error = self.assertRaises(exc.CommandError, self.cmd.take_action,
                                  parsed_args)
        self.assertEqual('Stack not found: my_stack', str(error))
Ejemplo n.º 18
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)