Exemplo n.º 1
0
 def test_get_statistics(self):
     expected_statistics = \
         {u'elements': [{u'name': u'mon.fake_metric',
                         u'columns':
                             [u'timestamp',
                              u'avg'],
                         u'id': '0',
                         u'dimensions':
                             {u'hostname': u'devstack',
                              u'service': u'monitoring'},
                         u'statistics':
                             [[u'2019-03-12T12:35:00Z', 49.25],
                              [u'2019-03-12T12:40:00Z', 28.25],
                              [u'2019-03-12T12:45:00Z', 27.5],
                              [u'2019-03-12T12:50:00Z', 27],
                              [u'2019-03-12T12:55:00Z', 28]]}]}
     return_value = self.metrics_repo_mock.return_value
     return_value.metrics_statistics.return_value = expected_statistics['elements']
     response = self.simulate_request(path='/v2.0/metrics/statistics',
                                      headers={'X-Roles':
                                               CONF.security.default_authorized_roles[0],
                                               'X-Tenant-Id': TENANT_ID},
                                      method='GET',
                                      query_string='name=mon.fake_metric&'
                                                   'start_time=2015-03-01T00:00:01.000Z&'
                                                   'statistics=avg')
     self.assertEqual(falcon.HTTP_200, response.status)
     self.assertThat(response, base.RESTResponseEquals(expected_statistics))
Exemplo n.º 2
0
    def test_get_measurements(self):
        expected_measurements = \
            {'elements': [
                {u'name': u'mon.fake_metric',
                 u'columns': [u'timestamp',
                              u'value',
                              u'value_meta'],
                 u'id': '0',
                 u'dimensions': {
                     u'hostname': u'devstack',
                     u'service': u'monitoring'},
                 u'measurements':
                     [[u'2019-03-12T12:37:10.106Z', 98.5, {}],
                      [u'2019-03-12T12:37:23.012Z', 98.8, {}],
                      [u'2019-03-12T12:37:38.031Z', 68.7, {}],
                      [u'2019-03-12T12:37:53.046Z', 55.3, {}],
                      [u'2019-03-12T12:38:08.048Z', 52.8, {}]]}]}

        return_value = self.metrics_repo_mock.return_value
        return_value.measurement_list.return_value = expected_measurements['elements']
        response = self.simulate_request(path='/v2.0/metrics/measurements',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID},
                                         method='GET',
                                         query_string='name=mon.fake_metric&'
                                                      'start_time=2015-03-01T00:00:01.000Z')
        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_measurements))
    def test_get_notification_with_id(self):
        expected_elements = \
            {'name': u'notification',
             'id': u'1',
             'type': u'EMAIL',
             'period': 0,
             'address': u'*****@*****.**'}

        return_value = self.notifications_repo_mock.return_value
        return_value.list_notification.return_value = \
            {'name': u'notification',
             'id': u'1',
             'tenant_id': u'4199b031d5fa401abf9afaf7e58890b7',
             'type': u'EMAIL',
             'period': 0,
             'address': u'*****@*****.**',
             'created_at': datetime.datetime(2019, 3, 22, 9, 35, 25),
             'updated_at': datetime.datetime(2019, 3, 22, 9, 35, 25)}
        response = self.simulate_request(path='/v2.0/notification-methods/1',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID},
                                         method='GET')
        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_elements))
    def test_list_notifications_with_offset(self):
        expected_elements = \
            {'elements': [
                {'name': u'notification',
                 'id': u'1',
                 'type': u'EMAIL',
                 'period': 0,
                 'address': u'*****@*****.**',
                 'links': [{
                     'href': 'http://falconframework.org/v2.0/notification-methods/1',
                     'rel': 'self'}]}]}

        return_value = self.notifications_repo_mock.return_value
        return_value.list_notifications.return_value = \
            [{'name': u'notification',
              'id': u'1',
              'tenant_id': u'4199b031d5fa401abf9afaf7e58890b7',
              'type': u'EMAIL',
              'period': 0,
              'address': u'*****@*****.**',
              'created_at': datetime.datetime(2019, 3, 22, 9, 35, 25),
              'updated_at': datetime.datetime(2019, 3, 22, 9, 35, 25)}]
        response = self.simulate_request(path='/v2.0/notification-methods',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID},
                                         query_string='offset=10',
                                         method='GET')
        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_elements))
Exemplo n.º 5
0
    def test_get_dimension_values(self):
        expected_dimension_names = \
            {u'elements': [
                {u'dimension_value': u'dummy_dimension_value'}]}

        return_value = self.metrics_repo_mock.return_value
        return_value.list_dimension_values.return_value = expected_dimension_names['elements']
        response = self.simulate_request(path='/v2.0/metrics/dimensions/values',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID},
                                         method='GET',
                                         query_string='dimension_name=dummy_dimension_name')
        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_dimension_names))
    def test_patch_notification_period_fields(self):
        expected_elements = \
            {"id": "1",
             "name": "notification",
             "type": "WEBHOOK",
             "address": "http://jamesbond.com",
             "period": 60}

        return_value = self.notifications_type_repo_mock.return_value
        return_value.list_notification_method_types.return_value = \
            [u'EMAIL',
             u'PAGERDUTY',
             u'WEBHOOK']

        return_value = self.notifications_repo_mock.return_value
        return_value.find_notification_by_name.return_value = \
            {'name': u'notification',
             'id': u'1',
             'tenant_id': u'444',
             'type': u'WEBHOOK',
             'period': 0,
             'address': u'http://jamesbond.com',
             'created_at': datetime.datetime(2019, 3, 22, 9, 35, 25),
             'updated_at': datetime.datetime(2019, 3, 22, 9, 35, 25)}

        return_value = self.notifications_repo_mock.return_value
        return_value.list_notification.return_value = \
            {'name': u'notification',
             'id': u'1',
             'tenant_id': u'444',
             'type': u'WEBHOOK',
             'period': 0,
             'address': u'http://jamesbond.com'}

        request_body = {"period": 60}

        response = self.simulate_request(path='/v2.0/notification-methods/1',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID,
                                                  'Content-Type': 'application/json'},
                                         method='PATCH',
                                         body=json.dumps(request_body))

        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_elements))
Exemplo n.º 7
0
    def test_get_metrics_names(self):
        expected_metrics_names = \
            {u'elements': [
                {u'name': u'cpu.frequency_mhz'},
                {u'name': u'cpu.idle_perc'},
                {u'name': u'cpu.idle_time'},
                {u'name': u'cpu.percent'},
                {u'name': u'cpu.stolen_perc'},
                {u'name': u'cpu.system_perc'},
                {u'name': u'cpu.system_time'}]}

        return_value = self.metrics_repo_mock.return_value
        return_value.list_metric_names.return_value = expected_metrics_names['elements']
        response = self.simulate_request(path='/v2.0/metrics/names',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID},
                                         method='GET')
        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_metrics_names))
    def test_get_notification_types(self):
        expected_notification_types = \
            {'elements': [
                {'type': 'EMAIL'},
                {'type': 'PAGERDUTY'},
                {'type': 'WEBHOOK'}]}
        return_value = self.notifications_type_repo_mock.return_value
        return_value.list_notification_method_types.return_value = \
            [u'EMAIL',
             u'PAGERDUTY',
             u'WEBHOOK']

        response = self.simulate_request(path='/v2.0/notification-methods/types',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID,
                                                  'Content-Type': 'application/json'},
                                         method='GET')
        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_notification_types))
Exemplo n.º 9
0
    def test_list_metrics(self):
        expected_elements = \
            {'elements': [{'id': '0',
                           'name': 'mon.fake_metric',
                           'dimensions':
                               {'hostname': 'host0',
                                'db': 'vegeta'}},
                          {'id': '1',
                           'name': 'cpu.idle_perc',
                           'dimensions':
                               {'hostname': 'host0',
                                'db': 'vegeta'}}
                          ]}

        return_value = self.metrics_repo_mock.return_value
        return_value.list_metrics.return_value = expected_elements['elements']

        response = self.simulate_request(path='/v2.0/metrics',
                                         headers={'X-Roles':
                                                  CONF.security.default_authorized_roles[0],
                                                  'X-Tenant-Id': TENANT_ID},
                                         method='GET')
        self.assertEqual(falcon.HTTP_200, response.status)
        self.assertThat(response, base.RESTResponseEquals(expected_elements))