コード例 #1
0
    def test_delete_err_rpcerr(self):
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier("t", stack_name, "1"))
        params = {"Action": "DeleteStack", "StackName": stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "identify_stack", "args": {"stack_name": stack_name}, "version": self.api_version},
            None,
        ).AndReturn(identity)

        # Insert an engine RPC error and ensure we map correctly to the
        # heat exception type
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "delete_stack", "args": {"stack_identity": identity}, "version": self.api_version},
            None,
        ).AndRaise(rpc_common.RemoteError("AttributeError"))

        self.m.ReplayAll()

        result = self.controller.delete(dummy_req)

        self.assertEqual(type(result), exception.HeatInvalidParameterValueError)
コード例 #2
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_lookup(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')

        req = self._get('/stacks/%(stack_name)s' % identity)

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'identify_stack',
                'args': {
                    'stack_name': identity.stack_name
                },
                'version': self.api_version
            }, None).AndReturn(identity)

        self.m.ReplayAll()

        try:
            result = self.controller.lookup(req,
                                            tenant_id=identity.tenant,
                                            stack_name=identity.stack_name)
        except webob.exc.HTTPFound as found:
            self.assertEqual(found.location, self._url(identity))
        else:
            self.fail('No redirect generated')
        self.m.VerifyAll()
コード例 #3
0
    def test_update_bad_name(self):
        stack_name = "wibble"
        template = {u"Foo": u"bar"}
        json_template = json.dumps(template)
        params = {
            "Action": "UpdateStack",
            "StackName": stack_name,
            "TemplateBody": "%s" % json_template,
            "Parameters.member.1.ParameterKey": "InstanceType",
            "Parameters.member.1.ParameterValue": "m1.xlarge",
        }
        dummy_req = self._dummy_GET_request(params)

        # Insert an engine RPC error and ensure we map correctly to the
        # heat exception type
        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "identify_stack", "args": {"stack_name": stack_name}, "version": self.api_version},
            None,
        ).AndRaise(rpc_common.RemoteError("AttributeError"))

        self.m.ReplayAll()

        result = self.controller.update(dummy_req)
        self.assertEqual(type(result), exception.HeatInvalidParameterValueError)
コード例 #4
0
    def test_list_metrics_filter_namespace(self):

        # Add a Namespace filter and change the engine response so
        # we should get two reponses
        params = {'Action': 'ListMetrics',
                  'Namespace': 'atestnamespace/foo'}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        # We dummy three different metrics and namespaces to test
        # filtering by parameter
        engine_resp = [
                        {u'timestamp': u'2012-08-30T15:09:02Z',
                        u'watch_name': u'HttpFailureAlarm',
                        u'namespace': u'atestnamespace/foo',
                        u'metric_name': u'ServiceFailure',
                        u'data': {u'Units': u'Counter', u'Value': 1}},

                        {u'timestamp': u'2012-08-30T15:10:03Z',
                        u'watch_name': u'HttpFailureAlarm2',
                        u'namespace': u'atestnamespace/foo',
                        u'metric_name': u'ServiceFailure2',
                        u'data': {u'Units': u'Counter', u'Value': 1}},

                        {u'timestamp': u'2012-08-30T15:16:03Z',
                        u'watch_name': u'HttpFailureAlar3m',
                        u'namespace': u'system/linux3',
                        u'metric_name': u'ServiceFailure3',
                        u'data': {u'Units': u'Counter', u'Value': 1}}]

        self.m.StubOutWithMock(rpc, 'call')
        # Current engine implementation means we filter in the API
        # and pass None/None for namespace/watch_name which returns
        # all metric data which we post-process in the API
        rpc.call(dummy_req.context, self.topic, {'args':
                 {'namespace': None,
                 'metric_name': None},
                 'method': 'show_watch_metric', 'version': self.api_version},
                 None).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.list_metrics(dummy_req)
        expected = {'ListMetricsResponse': {'ListMetricsResult': {'Metrics': [
                    {'Namespace': u'atestnamespace/foo',
                    'Dimensions': [
                    {'Name': 'AlarmName', 'Value': u'HttpFailureAlarm'},
                    {'Name': 'Timestamp', 'Value': u'2012-08-30T15:09:02Z'},
                    {'Name': u'Units', 'Value': u'Counter'},
                    {'Name': u'Value', 'Value': 1}],
                    'MetricName': u'ServiceFailure'},

                    {'Namespace': u'atestnamespace/foo',
                    'Dimensions': [
                    {'Name': 'AlarmName', 'Value': u'HttpFailureAlarm2'},
                    {'Name': 'Timestamp', 'Value': u'2012-08-30T15:10:03Z'},
                    {'Name': u'Units', 'Value': u'Counter'},
                    {'Name': u'Value', 'Value': 1}],
                    'MetricName': u'ServiceFailure2'}]}}}
        self.assert_(response == expected)
コード例 #5
0
    def test_describe_stack_resource(self):
        # Format a dummy request
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier("t", stack_name, "6"))
        params = {"Action": "DescribeStackResource", "StackName": stack_name, "LogicalResourceId": "WikiDatabase"}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = {
            u"description": u"",
            u"stack_name": u"wordpress",
            u"logical_resource_id": u"WikiDatabase",
            u"resource_status_reason": None,
            u"updated_time": u"2012-07-23T13:06:00Z",
            u"stack_identity": {u"tenant": u"t", u"stack_name": u"wordpress", u"stack_id": u"6", u"path": u""},
            u"resource_status": u"CREATE_COMPLETE",
            u"physical_resource_id": u"a3455d8c-9f88-404d-a85b-5315293e67de",
            u"resource_type": u"AWS::EC2::Instance",
            u"metadata": {u"wordpress": []},
        }

        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "identify_stack", "args": {"stack_name": stack_name}, "version": self.api_version},
            None,
        ).AndReturn(identity)
        args = {"stack_identity": identity, "resource_name": dummy_req.params.get("LogicalResourceId")}
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "describe_stack_resource", "args": args, "version": self.api_version},
            None,
        ).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.describe_stack_resource(dummy_req)

        expected = {
            "DescribeStackResourceResponse": {
                "DescribeStackResourceResult": {
                    "StackResourceDetail": {
                        "StackId": u"arn:openstack:heat::t:stacks/wordpress/6",
                        "ResourceStatus": u"CREATE_COMPLETE",
                        "Description": u"",
                        "ResourceType": u"AWS::EC2::Instance",
                        "ResourceStatusReason": None,
                        "LastUpdatedTimestamp": u"2012-07-23T13:06:00Z",
                        "StackName": u"wordpress",
                        "PhysicalResourceId": u"a3455d8c-9f88-404d-a85b-5315293e67de",
                        "Metadata": {u"wordpress": []},
                        "LogicalResourceId": u"WikiDatabase",
                    }
                }
            }
        }

        self.assertEqual(response, expected)
コード例 #6
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_validate_template(self):
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        body = {'template': template}

        req = self._post('/validate', json.dumps(body))

        engine_response = {
            u'Description':
            u'blah',
            u'Parameters': [{
                u'NoEcho': u'false',
                u'ParameterKey': u'InstanceType',
                u'Description': u'Instance type'
            }]
        }

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'validate_template',
                'args': {
                    'template': template
                },
                'version': self.api_version
            }, None).AndReturn(engine_response)
        self.m.ReplayAll()

        response = self.controller.validate_template(req,
                                                     tenant_id=self.tenant,
                                                     body=body)
        self.assertEqual(response, engine_response)
        self.m.VerifyAll()
コード例 #7
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_delete_bad_name(self):
        identity = identifier.HeatIdentifier(self.tenant, "wibble", "6")
        template = {u"Foo": u"bar"}
        json_template = json.dumps(template)
        parameters = {u"InstanceType": u"m1.xlarge"}
        body = {"template": template, "parameters": parameters, "timeout_mins": 30}

        req = self._delete("/stacks/%(stack_name)s/%(stack_id)s" % identity)

        self.m.StubOutWithMock(rpc, "call")
        # Engine returns None when delete successful
        rpc.call(
            req.context,
            self.topic,
            {"method": "delete_stack", "args": {"stack_identity": dict(identity)}, "version": self.api_version},
            None,
        ).AndRaise(rpc_common.RemoteError("AttributeError"))
        self.m.ReplayAll()

        self.assertRaises(
            webob.exc.HTTPNotFound,
            self.controller.delete,
            req,
            tenant_id=identity.tenant,
            stack_name=identity.stack_name,
            stack_id=identity.stack_id,
        )
        self.m.VerifyAll()
コード例 #8
0
    def test_create_err_engine(self):
        stack_name = "wordpress"
        template = {u'Foo': u'bar'}
        parameters = {u'InstanceType': u'm1.xlarge'}
        json_template = json.dumps(template)
        body = {'template': template,
                'stack_name': stack_name,
                'parameters': parameters,
                'timeout_mins': 30}

        req = self._post('/stacks', json.dumps(body))

        self.m.StubOutWithMock(rpc, 'call')
        engine_err = {'Description': 'Something went wrong'}
        rpc.call(req.context, self.topic,
                 {'method': 'create_stack',
                  'args': {'stack_name': stack_name,
                           'template': template,
                           'params': parameters,
                           'args': {'timeout_mins': 30}},
                  'version': self.api_version},
                 None).AndReturn(engine_err)
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create,
                          req, tenant_id=self.tenant, body=body)
        self.m.VerifyAll()
コード例 #9
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_create(self):
        identity = identifier.HeatIdentifier(self.tenant, "wordpress", "1")
        template = {u"Foo": u"bar"}
        json_template = json.dumps(template)
        parameters = {u"InstanceType": u"m1.xlarge"}
        body = {"template": template, "stack_name": identity.stack_name, "parameters": parameters, "timeout_mins": 30}

        req = self._post("/stacks", json.dumps(body))

        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            req.context,
            self.topic,
            {
                "method": "create_stack",
                "args": {
                    "stack_name": identity.stack_name,
                    "template": template,
                    "params": parameters,
                    "args": {"timeout_mins": 30},
                },
                "version": self.api_version,
            },
            None,
        ).AndReturn(dict(identity))
        self.m.ReplayAll()

        try:
            response = self.controller.create(req, tenant_id=identity.tenant, body=body)
        except webob.exc.HTTPCreated as created:
            self.assertEqual(created.location, self._url(identity))
        else:
            self.fail("HTTPCreated not raised")
        self.m.VerifyAll()
コード例 #10
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_create_err_engine(self):
        stack_name = "wordpress"
        template = {u"Foo": u"bar"}
        parameters = {u"InstanceType": u"m1.xlarge"}
        json_template = json.dumps(template)
        body = {"template": template, "stack_name": stack_name, "parameters": parameters, "timeout_mins": 30}

        req = self._post("/stacks", json.dumps(body))

        self.m.StubOutWithMock(rpc, "call")
        engine_err = {"Description": "Something went wrong"}
        rpc.call(
            req.context,
            self.topic,
            {
                "method": "create_stack",
                "args": {
                    "stack_name": stack_name,
                    "template": template,
                    "params": parameters,
                    "args": {"timeout_mins": 30},
                },
                "version": self.api_version,
            },
            None,
        ).AndReturn(engine_err)
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPBadRequest, self.controller.create, req, tenant_id=self.tenant, body=body)
        self.m.VerifyAll()
コード例 #11
0
ファイル: test_api_cfn_v1.py プロジェクト: ishantTyagi/heat
    def test_get_template(self):
        # Format a dummy request
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
        template = {u'Foo': u'bar'}
        params = {'Action': 'GetTemplate', 'StackName': stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = template

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(dummy_req.context, self.topic, {'method': 'identify_stack',
            'args': {'stack_name': stack_name},
            'version': self.api_version}, None).AndReturn(identity)
        rpc.call(dummy_req.context, self.topic, {'method': 'get_template',
            'args':
            {'stack_identity': identity},
            'version': self.api_version}, None).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.get_template(dummy_req)

        expected = {'GetTemplateResponse': {'GetTemplateResult':
                        {'TemplateBody': template}}}

        self.assertEqual(response, expected)
コード例 #12
0
ファイル: test_api_cfn_v1.py プロジェクト: ishantTyagi/heat
    def test_get_template_err_none(self):
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
        template = {u'Foo': u'bar'}
        params = {'Action': 'GetTemplate', 'StackName': stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine to return None
        # this test the "no such stack" error path
        engine_resp = None

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(dummy_req.context, self.topic, {'method': 'identify_stack',
            'args': {'stack_name': stack_name},
            'version': self.api_version}, None).AndReturn(identity)
        rpc.call(dummy_req.context, self.topic, {'method': 'get_template',
            'args':
            {'stack_identity': identity},
            'version': self.api_version}, None).AndReturn(engine_resp)

        self.m.ReplayAll()

        result = self.controller.get_template(dummy_req)

        self.assertEqual(type(result),
                         exception.HeatInvalidParameterValueError)
コード例 #13
0
ファイル: test_api_cfn_v1.py プロジェクト: ishantTyagi/heat
    def test_delete_err_rpcerr(self):
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier('t', stack_name, '1'))
        params = {'Action': 'DeleteStack', 'StackName': stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(dummy_req.context, self.topic, {'method': 'identify_stack',
            'args': {'stack_name': stack_name},
            'version': self.api_version}, None).AndReturn(identity)

        # Insert an engine RPC error and ensure we map correctly to the
        # heat exception type
        rpc.call(dummy_req.context, self.topic, {'method': 'delete_stack',
            'args': {'stack_identity': identity},
            'version': self.api_version}, None
            ).AndRaise(rpc_common.RemoteError("AttributeError"))

        self.m.ReplayAll()

        result = self.controller.delete(dummy_req)

        self.assertEqual(type(result),
                         exception.HeatInvalidParameterValueError)
コード例 #14
0
    def test_delete_bad_name(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wibble', '6')
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        parameters = {u'InstanceType': u'm1.xlarge'}
        body = {'template': template,
                'parameters': parameters,
                'timeout_mins': 30}

        req = self._delete('/stacks/%(stack_name)s/%(stack_id)s' % identity)

        self.m.StubOutWithMock(rpc, 'call')
        # Engine returns None when delete successful
        rpc.call(req.context, self.topic,
                 {'method': 'delete_stack',
                  'args': {'stack_identity': dict(identity)},
                  'version': self.api_version},
                 None).AndRaise(rpc_common.RemoteError("AttributeError"))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPNotFound,
                          self.controller.delete,
                          req, tenant_id=identity.tenant,
                          stack_name=identity.stack_name,
                          stack_id=identity.stack_id)
        self.m.VerifyAll()
コード例 #15
0
ファイル: test_api_cfn_v1.py プロジェクト: ishantTyagi/heat
    def test_create_err_engine(self):
        # Format a dummy request
        stack_name = "wordpress"
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        params = {'Action': 'CreateStack', 'StackName': stack_name,
                  'TemplateBody': '%s' % json_template,
                  'TimeoutInMinutes': 30,
                  'Parameters.member.1.ParameterKey': 'InstanceType',
                  'Parameters.member.1.ParameterValue': 'm1.xlarge'}
        engine_parms = {u'InstanceType': u'm1.xlarge'}
        engine_args = {'timeout_mins': u'30'}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        self.m.StubOutWithMock(rpc, 'call')
        engine_err = {'Description': 'Something went wrong'}

        rpc.call(dummy_req.context, self.topic, {'method': 'create_stack',
            'args':
            {'stack_name': stack_name,
            'template': template,
            'params': engine_parms,
            'args': engine_args},
            'version': self.api_version}, None
            ).AndReturn(engine_err)

        self.m.ReplayAll()

        result = self.controller.create(dummy_req)

        expected = {'CreateStackResponse': {'CreateStackResult': engine_err}}

        self.assertEqual(result, expected)
コード例 #16
0
    def test_update(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')
        stack_name = u'wordpress'
        stack_id = u'6'
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        parameters = {u'InstanceType': u'm1.xlarge'}
        body = {'template': template,
                'parameters': parameters,
                'timeout_mins': 30}

        req = self._put('/stacks/%(stack_name)s/%(stack_id)s' % identity,
                        json.dumps(body))

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(req.context, self.topic,
                 {'method': 'update_stack',
                  'args': {'stack_identity': dict(identity),
                           'template': template,
                           'params': parameters,
                           'args': {'timeout_mins': 30}},
                  'version': self.api_version},
                 None).AndReturn(dict(identity))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPAccepted,
                          self.controller.update,
                          req, tenant_id=identity.tenant,
                          stack_name=identity.stack_name,
                          stack_id=identity.stack_id,
                          body=body)
        self.m.VerifyAll()
コード例 #17
0
ファイル: test_api_cfn_v1.py プロジェクト: ishantTyagi/heat
    def test_create_err_rpcerr(self):
        # Format a dummy request
        stack_name = "wordpress"
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        params = {'Action': 'CreateStack', 'StackName': stack_name,
                  'TemplateBody': '%s' % json_template,
                  'TimeoutInMinutes': 30,
                  'Parameters.member.1.ParameterKey': 'InstanceType',
                  'Parameters.member.1.ParameterValue': 'm1.xlarge'}
        engine_parms = {u'InstanceType': u'm1.xlarge'}
        engine_args = {'timeout_mins': u'30'}
        dummy_req = self._dummy_GET_request(params)

        # Insert an engine RPC error and ensure we map correctly to the
        # heat exception type
        self.m.StubOutWithMock(rpc, 'call')

        rpc.call(dummy_req.context, self.topic, {'method': 'create_stack',
            'args':
            {'stack_name': stack_name,
            'template': template,
            'params': engine_parms,
            'args': engine_args},
            'version': self.api_version}, None
            ).AndRaise(rpc_common.RemoteError("AttributeError"))

        self.m.ReplayAll()

        result = self.controller.create(dummy_req)

        self.assertEqual(type(result),
                         exception.HeatInvalidParameterValueError)
コード例 #18
0
    def test_create(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        parameters = {u'InstanceType': u'm1.xlarge'}
        body = {'template': template,
                'stack_name': identity.stack_name,
                'parameters': parameters,
                'timeout_mins': 30}

        req = self._post('/stacks', json.dumps(body))

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(req.context, self.topic,
                 {'method': 'create_stack',
                  'args': {'stack_name': identity.stack_name,
                           'template': template,
                           'params': parameters,
                           'args': {'timeout_mins': 30}},
                  'version': self.api_version},
                 None).AndReturn(dict(identity))
        self.m.ReplayAll()

        try:
            response = self.controller.create(req,
                                              tenant_id=identity.tenant,
                                              body=body)
        except webob.exc.HTTPCreated as created:
            self.assertEqual(created.location, self._url(identity))
        else:
            self.fail('HTTPCreated not raised')
        self.m.VerifyAll()
コード例 #19
0
    def test_set_alarm_state(self):
        state_map = {'OK': engine_api.WATCH_STATE_OK,
                      'ALARM': engine_api.WATCH_STATE_ALARM,
                      'INSUFFICIENT_DATA': engine_api.WATCH_STATE_NODATA}

        for state in state_map.keys():
            params = {u'StateValue': state,
                      u'StateReason': u'',
                      u'AlarmName': u'HttpFailureAlarm',
                      u'Action': u'SetAlarmState'}

            dummy_req = self._dummy_GET_request(params)

            # Stub out the RPC call to verify the engine call parameters
            # The real engine response is the same as show_watch but with
            # the state overridden, but since the API doesn't make use
            # of the response at present we pass nothing back from the stub
            engine_resp = {}

            self.m.StubOutWithMock(rpc, 'call')
            rpc.call(dummy_req.context, self.topic, {'args':
                 {'state': state_map[state],
                 'watch_name': u'HttpFailureAlarm'},
                 'method': 'set_watch_state',
                 'version': self.api_version},
                 None).AndReturn(engine_resp)

            self.m.ReplayAll()

            response = self.controller.set_alarm_state(dummy_req)
            expected = {'SetAlarmStateResponse': {'SetAlarmStateResult': ''}}
            self.assert_(response == expected)

            self.m.UnsetStubs()
            self.m.VerifyAll()
コード例 #20
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_delete_bad_name(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wibble', '6')
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        parameters = {u'InstanceType': u'm1.xlarge'}
        body = {
            'template': template,
            'parameters': parameters,
            'timeout_mins': 30
        }

        req = self._delete('/stacks/%(stack_name)s/%(stack_id)s' % identity)

        self.m.StubOutWithMock(rpc, 'call')
        # Engine returns None when delete successful
        rpc.call(
            req.context, self.topic, {
                'method': 'delete_stack',
                'args': {
                    'stack_identity': dict(identity)
                },
                'version': self.api_version
            }, None).AndRaise(rpc_common.RemoteError("AttributeError"))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPNotFound,
                          self.controller.delete,
                          req,
                          tenant_id=identity.tenant,
                          stack_name=identity.stack_name,
                          stack_id=identity.stack_id)
        self.m.VerifyAll()
コード例 #21
0
    def test_put_metric_data(self):

        params = {u'Namespace': u'system/linux',
                  u'MetricData.member.1.Unit': u'Count',
                  u'MetricData.member.1.Value': u'1',
                  u'MetricData.member.1.MetricName': u'ServiceFailure',
                  u'MetricData.member.1.Dimensions.member.1.Name':
                    u'AlarmName',
                  u'MetricData.member.1.Dimensions.member.1.Value':
                    u'HttpFailureAlarm',
                  u'Action': u'PutMetricData'}

        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to verify the engine call parameters
        engine_resp = {}

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(dummy_req.context, self.topic, {'args': {'stats_data':
                 {'Namespace': u'system/linux',
                 u'ServiceFailure':
                    {'Value': u'1',
                    'Unit': u'Count',
                    'Dimensions': []}},
                    'watch_name': u'HttpFailureAlarm'},
                 'method': 'create_watch_data',
                 'version': self.api_version},
                 None).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.put_metric_data(dummy_req)
        expected = {'PutMetricDataResponse': {'PutMetricDataResult':
                    {'ResponseMetadata': None}}}
        self.assert_(response == expected)
コード例 #22
0
    def test_events_list_err_rpcerr(self):
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier("t", stack_name, "6"))
        params = {"Action": "DescribeStackEvents", "StackName": stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Insert an engine RPC error and ensure we map correctly to the
        # heat exception type
        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "identify_stack", "args": {"stack_name": stack_name}, "version": self.api_version},
            None,
        ).AndReturn(identity)
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "list_events", "args": {"stack_identity": identity}, "version": self.api_version},
            None,
        ).AndRaise(rpc_common.RemoteError("Exception"))

        self.m.ReplayAll()

        result = self.controller.events_list(dummy_req)

        self.assertEqual(type(result), exception.HeatInternalFailureError)
コード例 #23
0
    def test_validate_template(self):
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        body = {'template': template}

        req = self._post('/validate', json.dumps(body))

        engine_response = {
            u'Description': u'blah',
            u'Parameters': [
                {
                    u'NoEcho': u'false',
                    u'ParameterKey': u'InstanceType',
                    u'Description': u'Instance type'
                }
            ]
        }

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(req.context, self.topic,
                 {'method': 'validate_template',
                  'args': {'template': template},
                  'version': self.api_version},
                 None).AndReturn(engine_response)
        self.m.ReplayAll()

        response = self.controller.validate_template(req,
                                                     tenant_id=self.tenant,
                                                     body=body)
        self.assertEqual(response, engine_response)
        self.m.VerifyAll()
コード例 #24
0
    def test_delete(self):
        # Format a dummy request
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier("t", stack_name, "1"))
        params = {"Action": "DeleteStack", "StackName": stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "identify_stack", "args": {"stack_name": stack_name}, "version": self.api_version},
            None,
        ).AndReturn(identity)
        # Engine returns None when delete successful
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "delete_stack", "args": {"stack_identity": identity}, "version": self.api_version},
            None,
        ).AndReturn(None)

        self.m.ReplayAll()

        response = self.controller.delete(dummy_req)

        expected = {"DeleteStackResponse": {"DeleteStackResult": ""}}

        self.assertEqual(response, expected)
コード例 #25
0
    def test_get_template_err_none(self):
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier("t", stack_name, "6"))
        template = {u"Foo": u"bar"}
        params = {"Action": "GetTemplate", "StackName": stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine to return None
        # this test the "no such stack" error path
        engine_resp = None

        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "identify_stack", "args": {"stack_name": stack_name}, "version": self.api_version},
            None,
        ).AndReturn(identity)
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "get_template", "args": {"stack_identity": identity}, "version": self.api_version},
            None,
        ).AndReturn(engine_resp)

        self.m.ReplayAll()

        result = self.controller.get_template(dummy_req)

        self.assertEqual(type(result), exception.HeatInvalidParameterValueError)
コード例 #26
0
    def test_get_template(self):
        # Format a dummy request
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier("t", stack_name, "6"))
        template = {u"Foo": u"bar"}
        params = {"Action": "GetTemplate", "StackName": stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = template

        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "identify_stack", "args": {"stack_name": stack_name}, "version": self.api_version},
            None,
        ).AndReturn(identity)
        rpc.call(
            dummy_req.context,
            self.topic,
            {"method": "get_template", "args": {"stack_identity": identity}, "version": self.api_version},
            None,
        ).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.get_template(dummy_req)

        expected = {"GetTemplateResponse": {"GetTemplateResult": {"TemplateBody": template}}}

        self.assertEqual(response, expected)
コード例 #27
0
ファイル: test_api_cloudwatch.py プロジェクト: vandita31/heat
    def test_list_metrics_filter_name(self):

        # Add a MetricName filter, so we should only get one of the three
        params = {'Action': 'ListMetrics',
                  'MetricName': 'ServiceFailure'}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        # We dummy three different metrics and namespaces to test
        # filtering by parameter
        engine_resp = [{u'timestamp': u'2012-08-30T15:09:02Z',
                        u'watch_name': u'HttpFailureAlarm',
                        u'namespace': u'system/linux',
                        u'metric_name': u'ServiceFailure',
                        u'data': {u'Units': u'Counter', u'Value': 1}},

                       {u'timestamp': u'2012-08-30T15:10:03Z',
                        u'watch_name': u'HttpFailureAlarm2',
                        u'namespace': u'system/linux2',
                        u'metric_name': u'ServiceFailure2',
                        u'data': {u'Units': u'Counter', u'Value': 1}},

                       {u'timestamp': u'2012-08-30T15:16:03Z',
                        u'watch_name': u'HttpFailureAlar3m',
                        u'namespace': u'system/linux3',
                        u'metric_name': u'ServiceFailure3',
                        u'data': {u'Units': u'Counter', u'Value': 1}}]

        self.m.StubOutWithMock(rpc, 'call')
        # Current engine implementation means we filter in the API
        # and pass None/None for namespace/watch_name which returns
        # all metric data which we post-process in the API
        rpc.call(dummy_req.context, self.topic, {'args':
                 {'metric_namespace': None,
                  'metric_name': None},
                 'namespace': None,
                 'method': 'show_watch_metric',
                 'version': self.api_version},
                 None).AndReturn(engine_resp)

        self.m.ReplayAll()

        # First pass no query paramters filtering, should get all three
        response = self.controller.list_metrics(dummy_req)
        expected = {'ListMetricsResponse':
                    {'ListMetricsResult':
                     {'Metrics':
                      [{'Namespace': u'system/linux',
                        'Dimensions':
                        [{'Name': 'AlarmName',
                          'Value': u'HttpFailureAlarm'},
                         {'Name': 'Timestamp',
                          'Value': u'2012-08-30T15:09:02Z'},
                         {'Name': u'Units',
                          'Value': u'Counter'},
                         {'Name': u'Value',
                          'Value': 1}],
                        'MetricName': u'ServiceFailure'}]}}}
        self.assert_(response == expected)
コード例 #28
0
ファイル: test_api_cfn_v1.py プロジェクト: ishantTyagi/heat
    def test_describe_stack_resources(self):
        # Format a dummy request
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
        params = {'Action': 'DescribeStackResources',
                  'StackName': stack_name,
                  'LogicalResourceId': "WikiDatabase"}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = [{u'description': u'',
                        u'stack_name': u'wordpress',
                        u'logical_resource_id': u'WikiDatabase',
                        u'resource_status_reason': None,
                        u'updated_time': u'2012-07-23T13:06:00Z',
                        u'stack_identity': {u'tenant': u't',
                                            u'stack_name': u'wordpress',
                                            u'stack_id': u'6',
                                            u'path': u''},
                        u'resource_status': u'CREATE_COMPLETE',
                        u'physical_resource_id':
                            u'a3455d8c-9f88-404d-a85b-5315293e67de',
                        u'resource_type': u'AWS::EC2::Instance',
                        u'metadata': {u'ensureRunning': u'true''true'}}]

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(dummy_req.context, self.topic, {'method': 'identify_stack',
            'args': {'stack_name': stack_name},
            'version': self.api_version}, None).AndReturn(identity)
        args = {
            'stack_identity': identity,
            'physical_resource_id': None,
            'logical_resource_id': dummy_req.params.get('LogicalResourceId'),
        }
        rpc.call(dummy_req.context, self.topic,
            {'method': 'describe_stack_resources',
            'args': args,
            'version': self.api_version}, None).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.describe_stack_resources(dummy_req)

        expected = {'DescribeStackResourcesResponse':
                    {'DescribeStackResourcesResult':
                    {'StackResources':
                      [{'StackId': u'arn:openstack:heat::t:stacks/wordpress/6',
                        'ResourceStatus': u'CREATE_COMPLETE',
                        'Description': u'',
                        'ResourceType': u'AWS::EC2::Instance',
                        'Timestamp': u'2012-07-23T13:06:00Z',
                        'ResourceStatusReason': None,
                        'StackName': u'wordpress',
                        'PhysicalResourceId':
                            u'a3455d8c-9f88-404d-a85b-5315293e67de',
                        'LogicalResourceId': u'WikiDatabase'}]}}}

        self.assertEqual(response, expected)
コード例 #29
0
ファイル: test_api_cfn_v1.py プロジェクト: anotherjesse/heat
    def test_events_list(self):
        # Format a dummy request
        stack_name = "wordpress"
        identity = dict(identifier.HeatIdentifier('t', stack_name, '6'))
        params = {'Action': 'DescribeStackEvents', 'StackName': stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = {u'events': [{u'stack_name': u'wordpress',
                        u'event_time': u'2012-07-23T13:05:39Z',
                        u'stack_identity': {u'tenant': u't',
                                            u'stack_name': u'wordpress',
                                            u'stack_id': u'6',
                                            u'path': u''},
                        u'logical_resource_id': u'WikiDatabase',
                        u'resource_status_reason': u'state changed',
                        u'event_identity': {
                            u'tenant': u't',
                            u'stack_name': u'wordpress',
                            u'stack_id': u'6',
                            u'path': u'/resources/WikiDatabase/events/42'
                        },
                        u'resource_status': u'IN_PROGRESS',
                        u'physical_resource_id': None,
                        u'resource_properties':
                            {u'UserData': u'blah'},
                        u'resource_type': u'AWS::EC2::Instance'}]}

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(dummy_req.context, self.topic, {'method': 'identify_stack',
            'args': {'stack_name': stack_name},
            'version': self.api_version}, None).AndReturn(identity)
        rpc.call(dummy_req.context, self.topic, {'method': 'list_events',
            'args':
            {'stack_identity': identity},
            'version': self.api_version}, None).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.events_list(dummy_req)

        expected = {'DescribeStackEventsResponse':
            {'DescribeStackEventsResult':
            {'StackEvents':
                [{'EventId': u'42',
                'StackId': u'arn:openstack:heat::t:stacks/wordpress/6',
                'ResourceStatus': u'IN_PROGRESS',
                'ResourceType': u'AWS::EC2::Instance',
                'Timestamp': u'2012-07-23T13:05:39Z',
                'StackName': u'wordpress',
                'ResourceProperties': json.dumps({u'UserData': u'blah'}),
                'PhysicalResourceId': None,
                'ResourceStatusReason': u'state changed',
                'LogicalResourceId': u'WikiDatabase'}]}}}

        self.assertEqual(response, expected)
コード例 #30
0
    def test_describe_stack_resources(self):
        # Format a dummy request
        stack_name = "wordpress"
        params = {'Action': 'DescribeStackResources',
                  'StackName': stack_name,
                  'LogicalResourceId': "WikiDatabase"}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = [{u'description': u'',
                        u'stack_name': u'wordpress',
                        u'logical_resource_id': u'WikiDatabase',
                        u'resource_status_reason': None,
                        u'updated_time': u'2012-07-23T13:06:00Z',
                        u'stack_id': 6,
                        u'resource_status': u'CREATE_COMPLETE',
                        u'physical_resource_id':
                            u'a3455d8c-9f88-404d-a85b-5315293e67de',
                        u'resource_type': u'AWS::EC2::Instance',
                        u'metadata': {u'ensureRunning': u'true''true'}}]

        self.m.StubOutWithMock(rpc, 'call')
        args = {
            'stack_name': dummy_req.params.get('StackName'),
            'physical_resource_id': None,
            'logical_resource_id': dummy_req.params.get('LogicalResourceId'),
        }
        rpc.call(dummy_req.context, self.topic,
            {'method': 'describe_stack_resources',
            'args': args,
            'version': self.api_version}, None).AndReturn(engine_resp)

        # Stub socket.gethostname so it returns "ahostname"
        self.m.StubOutWithMock(socket, 'gethostname')
        socket.gethostname().AndReturn("ahostname")

        self.m.ReplayAll()

        response = self.controller.describe_stack_resources(dummy_req)

        expected = {'DescribeStackResourcesResponse':
                    {'DescribeStackResourcesResult':
                    {'StackResources':
                        [{'StackId': u'ahostname:8000:stack/wordpress/6',
                        'ResourceStatus': u'CREATE_COMPLETE',
                        'Description': u'',
                        'ResourceType': u'AWS::EC2::Instance',
                        'Timestamp': u'2012-07-23T13:06:00Z',
                        'ResourceStatusReason': None,
                        'StackName': u'wordpress',
                        'PhysicalResourceId':
                            u'a3455d8c-9f88-404d-a85b-5315293e67de',
                        'LogicalResourceId': u'WikiDatabase'}]}}}

        self.assert_(response == expected)
コード例 #31
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_index(self):
        req = self._get('/stacks')

        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')

        engine_resp = {
            u'stacks': [{
                u'stack_identity': dict(identity),
                u'updated_time': u'2012-07-09T09:13:11Z',
                u'template_description': u'blah',
                u'description': u'blah',
                u'stack_status_reason': u'Stack successfully created',
                u'creation_time': u'2012-07-09T09:12:45Z',
                u'stack_name': identity.stack_name,
                u'stack_status': u'CREATE_COMPLETE',
                u'parameters': {},
                u'outputs': [],
                u'notification_topics': [],
                u'capabilities': [],
                u'disable_rollback': True,
                u'timeout_mins': 60,
            }]
        }
        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'show_stack',
                'args': {
                    'stack_identity': None
                },
                'version': self.api_version
            }, None).AndReturn(engine_resp)
        self.m.ReplayAll()

        result = self.controller.index(req, tenant_id=identity.tenant)

        expected = {
            'stacks': [{
                'links': [{
                    "href": self._url(identity),
                    "rel": "self"
                }],
                'id': '1',
                u'updated_time': u'2012-07-09T09:13:11Z',
                u'description': u'blah',
                u'stack_status_reason': u'Stack successfully created',
                u'creation_time': u'2012-07-09T09:12:45Z',
                u'stack_name': u'wordpress',
                u'stack_status': u'CREATE_COMPLETE'
            }]
        }
        self.assertEqual(result, expected)
        self.m.VerifyAll()
コード例 #32
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_index(self):
        req = self._get("/stacks")

        identity = identifier.HeatIdentifier(self.tenant, "wordpress", "1")

        engine_resp = {
            u"stacks": [
                {
                    u"stack_identity": dict(identity),
                    u"updated_time": u"2012-07-09T09:13:11Z",
                    u"template_description": u"blah",
                    u"description": u"blah",
                    u"stack_status_reason": u"Stack successfully created",
                    u"creation_time": u"2012-07-09T09:12:45Z",
                    u"stack_name": identity.stack_name,
                    u"stack_status": u"CREATE_COMPLETE",
                    u"parameters": {},
                    u"outputs": [],
                    u"notification_topics": [],
                    u"capabilities": [],
                    u"disable_rollback": True,
                    u"timeout_mins": 60,
                }
            ]
        }
        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            req.context,
            self.topic,
            {"method": "show_stack", "args": {"stack_identity": None}, "version": self.api_version},
            None,
        ).AndReturn(engine_resp)
        self.m.ReplayAll()

        result = self.controller.index(req, tenant_id=identity.tenant)

        expected = {
            "stacks": [
                {
                    "links": [{"href": self._url(identity), "rel": "self"}],
                    "id": "1",
                    u"updated_time": u"2012-07-09T09:13:11Z",
                    u"description": u"blah",
                    u"stack_status_reason": u"Stack successfully created",
                    u"creation_time": u"2012-07-09T09:12:45Z",
                    u"stack_name": u"wordpress",
                    u"stack_status": u"CREATE_COMPLETE",
                }
            ]
        }
        self.assertEqual(result, expected)
        self.m.VerifyAll()
コード例 #33
0
    def test_index(self):
        req = self._get('/stacks')

        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')

        engine_resp = {
            u'stacks': [
                {
                    u'stack_identity': dict(identity),
                    u'updated_time': u'2012-07-09T09:13:11Z',
                    u'template_description': u'blah',
                    u'description': u'blah',
                    u'stack_status_reason': u'Stack successfully created',
                    u'creation_time': u'2012-07-09T09:12:45Z',
                    u'stack_name': identity.stack_name,
                    u'stack_status': u'CREATE_COMPLETE',
                    u'parameters': {},
                    u'outputs': [],
                    u'notification_topics': [],
                    u'capabilities': [],
                    u'disable_rollback': True,
                    u'timeout_mins': 60,
                }
            ]
        }
        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(req.context, self.topic,
                 {'method': 'list_stacks',
                  'args': {},
                           'version': self.api_version},
                 None).AndReturn(engine_resp)
        self.m.ReplayAll()

        result = self.controller.index(req, tenant_id=identity.tenant)

        expected = {
            'stacks': [
                {
                    'links': [{"href": self._url(identity),
                               "rel": "self"}],
                    'id': '1',
                    u'updated_time': u'2012-07-09T09:13:11Z',
                    u'description': u'blah',
                    u'stack_status_reason': u'Stack successfully created',
                    u'creation_time': u'2012-07-09T09:12:45Z',
                    u'stack_name': u'wordpress',
                    u'stack_status': u'CREATE_COMPLETE'
                }
            ]
        }
        self.assertEqual(result, expected)
        self.m.VerifyAll()
コード例 #34
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_index_rmt_interr(self):
        req = self._get("/stacks")

        self.m.StubOutWithMock(rpc, "call")
        rpc.call(
            req.context,
            self.topic,
            {"method": "show_stack", "args": {"stack_identity": None}, "version": self.api_version},
            None,
        ).AndRaise(rpc_common.RemoteError("Exception"))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPInternalServerError, self.controller.index, req, tenant_id=self.tenant)
        self.m.VerifyAll()
コード例 #35
0
    def test_events_list(self):
        # Format a dummy request
        stack_name = "wordpress"
        params = {'Action': 'DescribeStackEvents', 'StackName': stack_name}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = {u'events': [{u'stack_name': u'wordpress',
                        u'event_time': u'2012-07-23T13:05:39Z',
                        u'stack_id': 6,
                        u'logical_resource_id': u'WikiDatabase',
                        u'resource_status_reason': u'state changed',
                        u'event_id': 42,
                        u'resource_status': u'IN_PROGRESS',
                        u'physical_resource_id': None,
                        u'resource_properties':
                            {u'UserData': u'blah'},
                        u'resource_type': u'AWS::EC2::Instance'}]}

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(dummy_req.context, self.topic, {'method': 'list_events',
            'args':
            {'stack_name': stack_name,
            'params': dict(dummy_req.params)},
            'version': self.api_version}, None).AndReturn(engine_resp)

        # Stub socket.gethostname so it returns "ahostname"
        self.m.StubOutWithMock(socket, 'gethostname')
        socket.gethostname().AndReturn("ahostname")

        self.m.ReplayAll()

        response = self.controller.events_list(dummy_req)

        expected = {'DescribeStackEventsResponse':
            {'DescribeStackEventsResult':
            {'StackEvents':
                [{'EventId': 42,
                'StackId': u'ahostname:8000:stack/wordpress/6',
                'ResourceStatus': u'IN_PROGRESS',
                'ResourceType': u'AWS::EC2::Instance',
                'Timestamp': u'2012-07-23T13:05:39Z',
                'StackName': u'wordpress',
                'ResourceProperties': {u'UserData': u'blah'},
                'PhysicalResourceId': None,
                'ResourceStatusData': u'state changed',
                'LogicalResourceId': u'WikiDatabase'}]}}}

        self.assert_(response == expected)
コード例 #36
0
ファイル: test_api_cloudwatch.py プロジェクト: vikomall/heat
    def test_put_metric_data(self):

        params = {
            u'Namespace': u'system/linux',
            u'MetricData.member.1.Unit': u'Count',
            u'MetricData.member.1.Value': u'1',
            u'MetricData.member.1.MetricName': u'ServiceFailure',
            u'MetricData.member.1.Dimensions.member.1.Name': u'AlarmName',
            u'MetricData.member.1.Dimensions.member.1.Value':
            u'HttpFailureAlarm',
            u'Action': u'PutMetricData'
        }

        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to verify the engine call parameters
        engine_resp = {}

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            dummy_req.context, self.topic, {
                'args': {
                    'stats_data': {
                        'Namespace': u'system/linux',
                        u'ServiceFailure': {
                            'Value': u'1',
                            'Unit': u'Count',
                            'Dimensions': []
                        }
                    },
                    'watch_name': u'HttpFailureAlarm'
                },
                'namespace': None,
                'method': 'create_watch_data',
                'version': self.api_version
            }, None).AndReturn(engine_resp)

        self.m.ReplayAll()

        response = self.controller.put_metric_data(dummy_req)
        expected = {
            'PutMetricDataResponse': {
                'PutMetricDataResult': {
                    'ResponseMetadata': None
                }
            }
        }
        self.assert_(response == expected)
コード例 #37
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_index_rmt_interr(self):
        req = self._get('/stacks')

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'show_stack',
                'args': {
                    'stack_identity': None
                },
                'version': self.api_version
            }, None).AndRaise(rpc_common.RemoteError("Exception"))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPInternalServerError,
                          self.controller.index,
                          req,
                          tenant_id=self.tenant)
        self.m.VerifyAll()
コード例 #38
0
ファイル: test_api_cloudwatch.py プロジェクト: vikomall/heat
    def test_set_alarm_state(self):
        state_map = {
            'OK': engine_api.WATCH_STATE_OK,
            'ALARM': engine_api.WATCH_STATE_ALARM,
            'INSUFFICIENT_DATA': engine_api.WATCH_STATE_NODATA
        }

        for state in state_map.keys():
            params = {
                u'StateValue': state,
                u'StateReason': u'',
                u'AlarmName': u'HttpFailureAlarm',
                u'Action': u'SetAlarmState'
            }

            dummy_req = self._dummy_GET_request(params)

            # Stub out the RPC call to verify the engine call parameters
            # The real engine response is the same as show_watch but with
            # the state overridden, but since the API doesn't make use
            # of the response at present we pass nothing back from the stub
            engine_resp = {}

            self.m.StubOutWithMock(rpc, 'call')
            rpc.call(
                dummy_req.context, self.topic, {
                    'args': {
                        'state': state_map[state],
                        'watch_name': u'HttpFailureAlarm'
                    },
                    'namespace': None,
                    'method': 'set_watch_state',
                    'version': self.api_version
                }, None).AndReturn(engine_resp)

            self.m.ReplayAll()

            response = self.controller.set_alarm_state(dummy_req)
            expected = {'SetAlarmStateResponse': {'SetAlarmStateResult': ''}}
            self.assert_(response == expected)

            self.m.UnsetStubs()
            self.m.VerifyAll()
コード例 #39
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_update(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')
        stack_name = u'wordpress'
        stack_id = u'6'
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        parameters = {u'InstanceType': u'm1.xlarge'}
        body = {
            'template': template,
            'parameters': parameters,
            'timeout_mins': 30
        }

        req = self._put('/stacks/%(stack_name)s/%(stack_id)s' % identity,
                        json.dumps(body))

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'update_stack',
                'args': {
                    'stack_identity': dict(identity),
                    'template': template,
                    'params': parameters,
                    'args': {
                        'timeout_mins': 30
                    }
                },
                'version': self.api_version
            }, None).AndReturn(dict(identity))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPAccepted,
                          self.controller.update,
                          req,
                          tenant_id=identity.tenant,
                          stack_name=identity.stack_name,
                          stack_id=identity.stack_id,
                          body=body)
        self.m.VerifyAll()
コード例 #40
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_create(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '1')
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        parameters = {u'InstanceType': u'm1.xlarge'}
        body = {
            'template': template,
            'stack_name': identity.stack_name,
            'parameters': parameters,
            'timeout_mins': 30
        }

        req = self._post('/stacks', json.dumps(body))

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'create_stack',
                'args': {
                    'stack_name': identity.stack_name,
                    'template': template,
                    'params': parameters,
                    'args': {
                        'timeout_mins': 30
                    }
                },
                'version': self.api_version
            }, None).AndReturn(dict(identity))
        self.m.ReplayAll()

        try:
            response = self.controller.create(req,
                                              tenant_id=identity.tenant,
                                              body=body)
        except webob.exc.HTTPCreated as created:
            self.assertEqual(created.location, self._url(identity))
        else:
            self.fail('HTTPCreated not raised')
        self.m.VerifyAll()
コード例 #41
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_lookup_nonexistant(self):
        stack_name = 'wibble'

        req = self._get('/stacks/%(stack_name)s' % locals())

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'identify_stack',
                'args': {
                    'stack_name': stack_name
                },
                'version': self.api_version
            }, None).AndRaise(rpc_common.RemoteError("AttributeError"))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPNotFound,
                          self.controller.lookup,
                          req,
                          tenant_id=self.tenant,
                          stack_name=stack_name)
        self.m.VerifyAll()
コード例 #42
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_show_aterr(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')

        req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity)

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'show_stack',
                'args': {
                    'stack_identity': dict(identity)
                },
                'version': self.api_version
            }, None).AndRaise(rpc_common.RemoteError("AttributeError"))
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPNotFound,
                          self.controller.show,
                          req,
                          tenant_id=identity.tenant,
                          stack_name=identity.stack_name,
                          stack_id=identity.stack_id)
        self.m.VerifyAll()
コード例 #43
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_get_template(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')
        req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity)
        template = {u'Foo': u'bar'}

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'get_template',
                'args': {
                    'stack_identity': dict(identity)
                },
                'version': self.api_version
            }, None).AndReturn(template)
        self.m.ReplayAll()

        response = self.controller.template(req,
                                            tenant_id=identity.tenant,
                                            stack_name=identity.stack_name,
                                            stack_id=identity.stack_id)

        self.assertEqual(response, template)
        self.m.VerifyAll()
コード例 #44
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_create_err_engine(self):
        stack_name = "wordpress"
        template = {u'Foo': u'bar'}
        parameters = {u'InstanceType': u'm1.xlarge'}
        json_template = json.dumps(template)
        body = {
            'template': template,
            'stack_name': stack_name,
            'parameters': parameters,
            'timeout_mins': 30
        }

        req = self._post('/stacks', json.dumps(body))

        self.m.StubOutWithMock(rpc, 'call')
        engine_err = {'Description': 'Something went wrong'}
        rpc.call(
            req.context, self.topic, {
                'method': 'create_stack',
                'args': {
                    'stack_name': stack_name,
                    'template': template,
                    'params': parameters,
                    'args': {
                        'timeout_mins': 30
                    }
                },
                'version': self.api_version
            }, None).AndReturn(engine_err)
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.create,
                          req,
                          tenant_id=self.tenant,
                          body=body)
        self.m.VerifyAll()
コード例 #45
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_validate_template_error(self):
        template = {u'Foo': u'bar'}
        json_template = json.dumps(template)
        body = {'template': template}

        req = self._post('/validate', json.dumps(body))

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'validate_template',
                'args': {
                    'template': template
                },
                'version': self.api_version
            }, None).AndReturn({'Error': 'fubar'})
        self.m.ReplayAll()

        self.assertRaises(webob.exc.HTTPBadRequest,
                          self.controller.validate_template,
                          req,
                          tenant_id=self.tenant,
                          body=body)
        self.m.VerifyAll()
コード例 #46
0
    def call(self, context, msg, topic=None, version=None, timeout=None):
        """rpc.call() a remote method.

        :param context: The request context
        :param msg: The message to send, including the method and args.
        :param topic: Override the topic for this message.
        :param timeout: (Optional) A timeout to use when waiting for the
               response.  If no timeout is specified, a default timeout will be
               used that is usually sufficient.
        :param version: (Optional) Override the requested API version in this
               message.

        :returns: The return value from the remote method.
        """
        self._set_version(msg, version)
        return rpc.call(context, self._get_topic(topic), msg, timeout)
コード例 #47
0
ファイル: proxy.py プロジェクト: zzz6519003/heat
    def call(self, context, msg, topic=None, version=None, timeout=None):
        """rpc.call() a remote method.

        :param context: The request context
        :param msg: The message to send, including the method and args.
        :param topic: Override the topic for this message.
        :param version: (Optional) Override the requested API version in this
               message.
        :param timeout: (Optional) A timeout to use when waiting for the
               response.  If no timeout is specified, a default timeout will be
               used that is usually sufficient.

        :returns: The return value from the remote method.
        """
        self._set_version(msg, version)
        msg['args'] = self._serialize_msg_args(context, msg['args'])
        real_topic = self._get_topic(topic)
        try:
            result = rpc.call(context, real_topic, msg, timeout)
            return self.serializer.deserialize_entity(context, result)
        except rpc.common.Timeout as exc:
            raise rpc.common.Timeout(exc.info, real_topic, msg.get('method'))
コード例 #48
0
ファイル: test_api_openstack_v1.py プロジェクト: vladikr/heat
    def test_show(self):
        identity = identifier.HeatIdentifier(self.tenant, 'wordpress', '6')

        req = self._get('/stacks/%(stack_name)s/%(stack_id)s' % identity)

        parameters = {
            u'DBUsername': u'admin',
            u'LinuxDistribution': u'F17',
            u'InstanceType': u'm1.large',
            u'DBRootPassword': u'admin',
            u'DBPassword': u'admin',
            u'DBName': u'wordpress'
        }
        outputs = [{
            u'output_key': u'WebsiteURL',
            u'description': u'URL for Wordpress wiki',
            u'output_value': u'http://10.0.0.8/wordpress'
        }]

        engine_resp = {
            u'stacks': [{
                u'stack_identity': dict(identity),
                u'updated_time': u'2012-07-09T09:13:11Z',
                u'parameters': parameters,
                u'outputs': outputs,
                u'stack_status_reason': u'Stack successfully created',
                u'creation_time': u'2012-07-09T09:12:45Z',
                u'stack_name': identity.stack_name,
                u'notification_topics': [],
                u'stack_status': u'CREATE_COMPLETE',
                u'description': u'blah',
                u'disable_rollback': True,
                u'timeout_mins': 60,
                u'capabilities': [],
            }]
        }
        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            req.context, self.topic, {
                'method': 'show_stack',
                'args': {
                    'stack_identity': dict(identity)
                },
                'version': self.api_version
            }, None).AndReturn(engine_resp)
        self.m.ReplayAll()

        response = self.controller.show(req,
                                        tenant_id=identity.tenant,
                                        stack_name=identity.stack_name,
                                        stack_id=identity.stack_id)

        expected = {
            'stack': {
                'links': [{
                    "href": self._url(identity),
                    "rel": "self"
                }],
                'id': '6',
                u'updated_time': u'2012-07-09T09:13:11Z',
                u'parameters': parameters,
                u'outputs': outputs,
                u'description': u'blah',
                u'stack_status_reason': u'Stack successfully created',
                u'creation_time': u'2012-07-09T09:12:45Z',
                u'stack_name': identity.stack_name,
                u'stack_status': u'CREATE_COMPLETE',
                u'capabilities': [],
                u'notification_topics': [],
                u'disable_rollback': True,
                u'timeout_mins': 60,
            }
        }
        self.assertEqual(response, expected)
        self.m.VerifyAll()
コード例 #49
0
ファイル: test_api_cloudwatch.py プロジェクト: randres/heat
    def test_describe_all(self):
        watch_name = None  # Get all watches

        # Format a dummy GET request to pass into the WSGI handler
        params = {'Action': 'DescribeAlarms'}
        dummy_req = self._dummy_GET_request(params)

        # Stub out the RPC call to the engine with a pre-canned response
        engine_resp = [{
            u'state_updated_time': u'2012-08-30T14:13:21Z',
            u'stack_id': u'21617058-781e-4262-97ab-5f9df371ee52',
            u'period': u'300',
            u'actions': [u'WebServerRestartPolicy'],
            u'topic': None,
            u'periods': u'1',
            u'statistic': u'SampleCount',
            u'threshold': u'2',
            u'unit': None,
            u'state_reason': None,
            u'dimensions': [],
            u'namespace': u'system/linux',
            u'state_value': u'NORMAL',
            u'ok_actions': None,
            u'description': u'Restart the WikiDatabase',
            u'actions_enabled': None,
            u'state_reason_data': None,
            u'insufficient_actions': None,
            u'metric_name': u'ServiceFailure',
            u'comparison': u'GreaterThanThreshold',
            u'name': u'HttpFailureAlarm',
            u'updated_time': u'2012-08-30T14:10:46Z'
        }]

        self.m.StubOutWithMock(rpc, 'call')
        rpc.call(
            dummy_req.context, self.topic, {
                'args': {
                    'watch_name': watch_name
                },
                'method': 'show_watch',
                'version': self.api_version
            }, None).AndReturn(engine_resp)

        self.m.ReplayAll()

        # Call the list controller function and compare the response
        response = self.controller.describe_alarms(dummy_req)

        expected = {
            'DescribeAlarmsResponse': {
                'DescribeAlarmsResult': {
                    'MetricAlarms': [{
                        'EvaluationPeriods':
                        u'1',
                        'StateReasonData':
                        None,
                        'AlarmArn':
                        None,
                        'StateUpdatedTimestamp':
                        u'2012-08-30T14:13:21Z',
                        'AlarmConfigurationUpdatedTimestamp':
                        u'2012-08-30T14:10:46Z',
                        'AlarmActions': [u'WebServerRestartPolicy'],
                        'Threshold':
                        u'2',
                        'AlarmDescription':
                        u'Restart the WikiDatabase',
                        'Namespace':
                        u'system/linux',
                        'Period':
                        u'300',
                        'StateValue':
                        u'NORMAL',
                        'ComparisonOperator':
                        u'GreaterThanThreshold',
                        'AlarmName':
                        u'HttpFailureAlarm',
                        'Unit':
                        None,
                        'Statistic':
                        u'SampleCount',
                        'StateReason':
                        None,
                        'InsufficientDataActions':
                        None,
                        'OKActions':
                        None,
                        'MetricName':
                        u'ServiceFailure',
                        'ActionsEnabled':
                        None,
                        'Dimensions': [{
                            'Name':
                            'StackId',
                            'Value':
                            u'21617058-781e-4262-97ab-5f9df371ee52'
                        }]
                    }]
                }
            }
        }

        self.assert_(response == expected)