Exemple #1
0
    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_client.EngineClient, '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_client.EngineClient.call(
            dummy_req.context,
            ('show_watch_metric',
             {'metric_namespace': None, 'metric_name': None})
        ).AndReturn(engine_resp)

        self.m.ReplayAll()

        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'}]}}}
        # First pass no query paramters filtering, should get all three
        self.assertEqual(
            utils.recursive_sort(expected),
            utils.recursive_sort(self.controller.list_metrics(dummy_req)))
Exemple #2
0
    def test_reformat_dimensions(self):

        dims = [{'StackId': u'21617058-781e-4262-97ab-5f9df371ee52',
                 'Foo': 'bar'}]
        self.assertEqual(
            utils.recursive_sort(
                [{'Name': 'StackId',
                  'Value': u'21617058-781e-4262-97ab-5f9df371ee52'},
                 {'Name': 'Foo',
                  'Value': 'bar'}]),
            utils.recursive_sort(self.controller._reformat_dimensions(dims)))