Пример #1
0
  def testModelHandlerPUTModelCreate(self, createModel,
                                     getMetricDisplayFieldsMock, _engineMock):
    cols = []
    for key in METRIC_DISPLAY_FIELDS:
      m = Mock()
      m.configure_mock(name=key)
      cols.append(m)

    getMetricDisplayFieldsMock.return_value=cols

    metric = Mock(**dict((col, getattr(self.metric, col))
                         for col in METRIC_DISPLAY_FIELDS))
    metric.keys.return_value = [col for col in METRIC_DISPLAY_FIELDS]
    metric.name = self.metric.name

    createModel.return_value = metric

    params = {"type": "metric",
              "region": "us-east-1",
              "namespace": "AWS/EC2",
              "datasource": "cloudwatch",
              "metric": "CPUUtilization",
              "dimensions": {
                "InstanceId": "i-0c149c66"
              }}
    response = self.app.put("/", json.dumps(params), headers=self.headers)
    assertions.assertResponseStatusCode(self, response, 201)
    assertions. assertResponseHeaders(self, response, "json")
    self.assertTrue(createModel.called)
Пример #2
0
    def testModelHandlerPUTModelCreate(self, createModel,
                                       getMetricDisplayFieldsMock,
                                       _engineMock):
        cols = []
        for key in METRIC_DISPLAY_FIELDS:
            m = Mock()
            m.configure_mock(name=key)
            cols.append(m)

        getMetricDisplayFieldsMock.return_value = cols

        metric = Mock(**dict(
            (col, getattr(self.metric, col)) for col in METRIC_DISPLAY_FIELDS))
        metric.keys.return_value = [col for col in METRIC_DISPLAY_FIELDS]
        metric.name = self.metric.name

        createModel.return_value = metric

        params = {
            "type": "metric",
            "region": "us-east-1",
            "namespace": "AWS/EC2",
            "datasource": "cloudwatch",
            "metric": "CPUUtilization",
            "dimensions": {
                "InstanceId": "i-0c149c66"
            }
        }
        response = self.app.put("/", json.dumps(params), headers=self.headers)
        assertions.assertResponseStatusCode(self, response, 201)
        assertions.assertResponseHeaders(self, response, "json")
        self.assertTrue(createModel.called)
Пример #3
0
 def testMetricDataHandlerGetMetricDataWithToFromAnomaly(self,
     getMetricDataMock, _engineMock):
   getMetricDataMock.return_value = self.decodeRowTuples(
     self.metric_data['withanomaly'])
   response = self.app.get(
     "/be9fab-f416-4845-8dab-02d292244112/data?from=2013-08-15 21:34:00&" \
     "to=2013-08-15 21:24:00&anomaly=0.025", headers=self.headers)
   assertions.assertResponseStatusCode(self, response, 200)
   result = json.loads(response.body)
   self.assertEqual([row[1:] for row in self.metric_data['withanomaly']],
    result["data"])
Пример #4
0
  def testGETInvalidSection(self):
    """
    Test for GET for '/_settings/section, List Some invalid Settings
    resoponse is validated for appropriate headers and body
    """
    response = self.app.get("/dddd", headers=self.headers)

    assertions.assertResponseHeaders(self, response)
    assertions.assertResponseBody(self, response)
    assertions.assertResponseStatusCode(self, response, 200)
    self.assertEqual(app_utils.jsonDecode(response.body), {})
Пример #5
0
 def testMetricDataHandlerGetMetricDataWithToFromAnomaly(
         self, getMetricDataMock, _engineMock):
     getMetricDataMock.return_value = self.decodeRowTuples(
         self.metric_data['withanomaly'])
     response = self.app.get(
       "/be9fab-f416-4845-8dab-02d292244112/data?from=2013-08-15 21:34:00&" \
       "to=2013-08-15 21:24:00&anomaly=0.025", headers=self.headers)
     assertions.assertResponseStatusCode(self, response, 200)
     result = json.loads(response.body)
     self.assertEqual([row[1:] for row in self.metric_data['withanomaly']],
                      result["data"])
Пример #6
0
    def testGETInvalidSection(self):
        """
    Test for GET for '/_settings/section, List Some invalid Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("/dddd", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)
        self.assertEqual(app_utils.jsonDecode(response.body), {})
Пример #7
0
 def testMetricDataHandlerGetMultiMetricDataWithAnomaly(self,
     getMetricDataMock, _engineMock):
   getMetricDataMock.return_value = []
   response = self.app.get("/data?anomaly=0.01", headers=self.headers)
   assertions.assertResponseStatusCode(self, response, 200)
   getMetricDataMock.assert_called_once_with(
     _engineMock.return_value.connect.return_value.__enter__.return_value,
     metricId=None,
     fields=ANY,
     fromTimestamp=ANY,
     toTimestamp=ANY,
     score=0.01,
     sort=ANY)
Пример #8
0
 def testMetricDataHandlerGetMultiMetricDataWithAnomaly(
         self, getMetricDataMock, _engineMock):
     getMetricDataMock.return_value = []
     response = self.app.get("/data?anomaly=0.01", headers=self.headers)
     assertions.assertResponseStatusCode(self, response, 200)
     getMetricDataMock.assert_called_once_with(
         _engineMock.return_value.connect.return_value.__enter__.
         return_value,
         metricId=None,
         fields=ANY,
         fromTimestamp=ANY,
         toTimestamp=ANY,
         score=0.01,
         sort=ANY)
Пример #9
0
  def testModelExportHandlerGETMetric(self, getMetricMock,
                                      createDatasourceAdapterMock,
                                      _engineMock):

    metric = Mock(
      uid=u'5f76ba824fe147c8a4bc1c59565d8499',
      description=(
        u'CPUUtilization on EC2 instance i-ab15a19d in us-west-2 region'),
      server=u'i-ab15a19d',
      location=u'us-west-2',
      parameters=jsonEncode({
        "datasource": "cloudwatch",

        "metricSpec": {
          "region": "us-west-2",
          "namespace": "AWS/EC2",
          "metric": "CPUUtilization",
          "dimensions": {
            "InstanceId": "i-12d67826"
          }
        },

        "modelParams": {
          "min": 0,
          "max": 100
        }
      }),
      last_timestamp=datetime.datetime(2013, 11, 23, 18, 36),
      poll_interval=300L,
      status=MetricStatus.ACTIVE,
      message=None,
      collector_error=None,
      tag_name=u'jenkins-master',
      last_rowid=1440L,
      datasource="cloudwatch")
    metric.name = u'AWS/EC2/CPUUtilization'


    getMetricMock.return_value = metric
    createDatasourceAdapterMock.return_value.exportModel.return_value = (
      metric.parameters)

    response = self.app.get("/5f76ba824fe147c8a4bc1c59565d8499/export",
      headers=self.headers)

    assertions.assertResponseStatusCode(self, response, 200)

    # Assert response matches expected behavior
    self.assertEqual(json.loads(response.body), [metric.parameters])
Пример #10
0
 def testMetricDataHandlerGetMultiMetricDataWithToFromAnomaly(self,
     getMetricDataMock, _engineMock):
   getMetricDataMock.return_value = []
   response = self.app.get("/data?from=2013-08-15 21:34:00&"
                           "to=2013-08-15 21:24:00&anomaly=0.025",
                           headers=self.headers)
   assertions.assertResponseStatusCode(self, response, 200)
   getMetricDataMock.assert_called_once_with(
     _engineMock.return_value.connect.return_value.__enter__.return_value,
     metricId=None,
     fields=ANY,
     fromTimestamp="2013-08-15 21:34:00",
     toTimestamp="2013-08-15 21:24:00",
     score=0.025,
     sort=ANY)
Пример #11
0
 def testMetricDataHandlerGetMultiMetricDataWithToTimestamp(self,
     getMetricDataMock, _engineMock):
   getMetricDataMock.return_value = self.decodeRowTuples(
     self.metric_data["withto"])
   response = self.app.get("/data?to=2013-08-15 21:28:00",
    headers=self.headers)
   assertions.assertResponseStatusCode(self, response, 200)
   getMetricDataMock.assert_called_once_with(
     _engineMock.return_value.connect.return_value.__enter__.return_value,
     metricId=None,
     fields=ANY,
     fromTimestamp=ANY,
     toTimestamp="2013-08-15 21:28:00",
     score=ANY,
     sort=ANY)
Пример #12
0
 def testMetricDataHandlerGetMultiMetricDataWithToTimestamp(
         self, getMetricDataMock, _engineMock):
     getMetricDataMock.return_value = self.decodeRowTuples(
         self.metric_data["withto"])
     response = self.app.get("/data?to=2013-08-15 21:28:00",
                             headers=self.headers)
     assertions.assertResponseStatusCode(self, response, 200)
     getMetricDataMock.assert_called_once_with(
         _engineMock.return_value.connect.return_value.__enter__.
         return_value,
         metricId=None,
         fields=ANY,
         fromTimestamp=ANY,
         toTimestamp="2013-08-15 21:28:00",
         score=ANY,
         sort=ANY)
Пример #13
0
    def testModelExportHandlerGETMetric(self, getMetricMock,
                                        createDatasourceAdapterMock,
                                        _engineMock):

        metric = Mock(
            uid=u'5f76ba824fe147c8a4bc1c59565d8499',
            description=(
                u'CPUUtilization on EC2 instance i-ab15a19d in us-west-2 region'
            ),
            server=u'i-ab15a19d',
            location=u'us-west-2',
            parameters=jsonEncode({
                "datasource": "cloudwatch",
                "metricSpec": {
                    "region": "us-west-2",
                    "namespace": "AWS/EC2",
                    "metric": "CPUUtilization",
                    "dimensions": {
                        "InstanceId": "i-12d67826"
                    }
                },
                "modelParams": {
                    "min": 0,
                    "max": 100
                }
            }),
            last_timestamp=datetime.datetime(2013, 11, 23, 18, 36),
            poll_interval=300L,
            status=MetricStatus.ACTIVE,
            message=None,
            collector_error=None,
            tag_name=u'jenkins-master',
            last_rowid=1440L,
            datasource="cloudwatch")
        metric.name = u'AWS/EC2/CPUUtilization'

        getMetricMock.return_value = metric
        createDatasourceAdapterMock.return_value.exportModel.return_value = (
            metric.parameters)

        response = self.app.get("/5f76ba824fe147c8a4bc1c59565d8499/export",
                                headers=self.headers)

        assertions.assertResponseStatusCode(self, response, 200)

        # Assert response matches expected behavior
        self.assertEqual(json.loads(response.body), [metric.parameters])
Пример #14
0
 def testMetricDataHandlerGetMultiMetricDataWithToFromAnomaly(
         self, getMetricDataMock, _engineMock):
     getMetricDataMock.return_value = []
     response = self.app.get(
         "/data?from=2013-08-15 21:34:00&"
         "to=2013-08-15 21:24:00&anomaly=0.025",
         headers=self.headers)
     assertions.assertResponseStatusCode(self, response, 200)
     getMetricDataMock.assert_called_once_with(
         _engineMock.return_value.connect.return_value.__enter__.
         return_value,
         metricId=None,
         fields=ANY,
         fromTimestamp="2013-08-15 21:34:00",
         toTimestamp="2013-08-15 21:24:00",
         score=0.025,
         sort=ANY)
Пример #15
0
  def testGETValidSection(self):
    """
    Test for GET for '/_settings/section, List Some Settings
    resoponse is validated for appropriate headers and body
    """
    response = self.app.get("/aws", headers=self.headers)

    assertions.assertResponseHeaders(self, response)
    assertions.assertResponseBody(self, response)
    assertions.assertResponseStatusCode(self, response, 200)

    result = app_utils.jsonDecode(response.body)
    self.assertIsInstance(result, dict)
    for key in set(self.configurable_options["aws"]):
      if key in settings_api.HIDDEN_SETTINGS["aws"]:
        self.assertNotIn(key, result)
      else:
        self.assertIn(key, result)
Пример #16
0
    def testGETValidSection(self):
        """
    Test for GET for '/_settings/section, List Some Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("/aws", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)

        result = app_utils.jsonDecode(response.body)
        self.assertIsInstance(result, dict)
        for key in set(self.configurable_options["aws"]):
            if key in settings_api.HIDDEN_SETTINGS["aws"]:
                self.assertNotIn(key, result)
            else:
                self.assertIn(key, result)
Пример #17
0
  def testSettingsHandlerDefault(self):
    """
    Test for GET for '/_settings', List All Settings
    resoponse is validated for appropriate headers and body
    """
    response = self.app.get("", headers=self.headers)

    assertions.assertResponseHeaders(self, response)
    assertions.assertResponseBody(self, response)
    assertions.assertResponseStatusCode(self, response, 200)

    result = app_utils.jsonDecode(response.body)
    self.assertIsInstance(result, dict)
    for config in self.configurable_options:
      self.assertTrue(result.has_key(config))
      for key in self.configurable_options[config]:
        if key in settings_api.HIDDEN_SETTINGS[config]:
          self.assertNotIn(key, result[config])
        else:
          self.assertIn(key, result[config])
Пример #18
0
    def testSettingsHandlerDefault(self):
        """
    Test for GET for '/_settings', List All Settings
    resoponse is validated for appropriate headers and body
    """
        response = self.app.get("", headers=self.headers)

        assertions.assertResponseHeaders(self, response)
        assertions.assertResponseBody(self, response)
        assertions.assertResponseStatusCode(self, response, 200)

        result = app_utils.jsonDecode(response.body)
        self.assertIsInstance(result, dict)
        for config in self.configurable_options:
            self.assertTrue(result.has_key(config))
            for key in self.configurable_options[config]:
                if key in settings_api.HIDDEN_SETTINGS[config]:
                    self.assertNotIn(key, result[config])
                else:
                    self.assertIn(key, result[config])
Пример #19
0
  def testModelHandlerPUTMonitorMetric(self,
                                       repositoryMock,
                                       createDatasourceAdapterMock,
                                       getMetricDisplayFieldsMock,
                                       quotaRepositoryMock,
                                       engineMock):

    cols = []
    for key in METRIC_DISPLAY_FIELDS:
      m = Mock()
      m.configure_mock(name=key)
      cols.append(m)

    getMetricDisplayFieldsMock.return_value=cols

    metric = Mock(**dict((col, getattr(self.metric, col))
                         for col in METRIC_DISPLAY_FIELDS))
    metric.keys.return_value = [col for col in METRIC_DISPLAY_FIELDS]
    metric.name = self.metric.name

    quotaRepositoryMock.getInstanceCount.return_value = 0
    repositoryMock.getMetric.return_value = metric

    params = {
        "region": "us-east-1",
        "namespace": "AWS/EC2",
        "datasource": "cloudwatch",
        "metric": "CPUUtilization",
        "dimensions": {
            "InstanceId": "i-0c149c66"
        }
    }

    response = self.app.put("/", json.dumps(params), headers=self.headers)
    assertions.assertResponseStatusCode(self, response, 201)
    assertions.assertResponseHeaders(self, response, "json")
    repositoryMock.getMetric.assert_called_once_with(
      engineMock.return_value.connect.return_value.__enter__.return_value,
      createDatasourceAdapterMock.return_value.monitorMetric.return_value)
Пример #20
0
    def testModelHandlerPUTMonitorMetric(self, repositoryMock,
                                         createDatasourceAdapterMock,
                                         getMetricDisplayFieldsMock,
                                         quotaRepositoryMock, engineMock):

        cols = []
        for key in METRIC_DISPLAY_FIELDS:
            m = Mock()
            m.configure_mock(name=key)
            cols.append(m)

        getMetricDisplayFieldsMock.return_value = cols

        metric = Mock(**dict(
            (col, getattr(self.metric, col)) for col in METRIC_DISPLAY_FIELDS))
        metric.keys.return_value = [col for col in METRIC_DISPLAY_FIELDS]
        metric.name = self.metric.name

        quotaRepositoryMock.getInstanceCount.return_value = 0
        repositoryMock.getMetric.return_value = metric

        params = {
            "region": "us-east-1",
            "namespace": "AWS/EC2",
            "datasource": "cloudwatch",
            "metric": "CPUUtilization",
            "dimensions": {
                "InstanceId": "i-0c149c66"
            }
        }

        response = self.app.put("/", json.dumps(params), headers=self.headers)
        assertions.assertResponseStatusCode(self, response, 201)
        assertions.assertResponseHeaders(self, response, "json")
        repositoryMock.getMetric.assert_called_once_with(
            engineMock.return_value.connect.return_value.__enter__.
            return_value, createDatasourceAdapterMock.return_value.
            monitorMetric.return_value)
Пример #21
0
 def testhtmItHandlerGET(self, render, _instanceDataMock):
   response = self.app.get("/htmit", headers=self.headers)
   self.assertTrue(render.called)
   assertions.assertResponseStatusCode(self, response, code=200)
   headers = dict(response.headers)
   self.assertEqual(headers["Content-Type"], "text/html; charset=UTF-8")
Пример #22
0
 def testModelHandlerDELETEModel(self, deleteModel, _engineMock):
     response = self.app.delete("/12232-jn939", headers=self.headers)
     self.assertTrue(deleteModel.called)
     assertions.assertResponseStatusCode(self, response, 200)
     assertions.assertResponseHeaders(self, response, "json")
Пример #23
0
 def testhtmItHandlerGET(self, render, _instanceDataMock):
     response = self.app.get("/htmit", headers=self.headers)
     self.assertTrue(render.called)
     assertions.assertResponseStatusCode(self, response, code=200)
     headers = dict(response.headers)
     self.assertEqual(headers["Content-Type"], "text/html; charset=UTF-8")
Пример #24
0
 def testModelHandlerDELETEModel(self, deleteModel, _engineMock):
   response = self.app.delete("/12232-jn939", headers=self.headers)
   self.assertTrue(deleteModel.called)
   assertions.assertResponseStatusCode(self, response, 200)
   assertions. assertResponseHeaders(self, response, "json")