예제 #1
0
 def test_query_invalid_statistics(self, boto3, config, query_dict,
                                   response):
     query_dict.update({'statistics': 'foo'})
     query = CWDataSource.METRIC_QUERY_CLS(**query_dict)
     cw = CWDataSource(config)
     with pytest.raises(InvalidMetricQuery):
         datapoints = cw.datapoints(query)
예제 #2
0
 def test_boto3_raises_exceptions_fail(self, boto3, config):
     boto3.session.Session.side_effect = PartialCredentialsError(
         provider=Mock(), cred_var=Mock())
     assert CWDataSource(config).test() == False
     boto3.session.Session.side_effect = ClientError(MagicMock(), Mock())
     assert CWDataSource(config).test() == False
     boto3.session.Session.side_effect = NoRegionError()
     assert CWDataSource(config).test() == False
예제 #3
0
 def test_raises_boto3clienterror(self, boto3, config):
     boto3.session.Session.side_effect = PartialCredentialsError(
         provider=Mock(), cred_var=Mock())
     with pytest.raises(Boto3ClientError):
         CWDataSource(config)._cw_client()
     boto3.session.Session.side_effect = ClientError(MagicMock(), Mock())
     with pytest.raises(Boto3ClientError):
         CWDataSource(config)._cw_client()
     boto3.session.Session.side_effect = NoRegionError()
     with pytest.raises(Boto3ClientError):
         CWDataSource(config)._cw_client()
예제 #4
0
    def test_query_maxdatapoints(self, boto3, config, query_dict):
        query = CWDataSource.METRIC_QUERY_CLS(**query_dict)
        cw = CWDataSource(config)
        datapoints = cw.datapoints(query, maxdatapoints=100)

        boto3.session.Session.return_value.client.return_value.\
            get_metric_statistics.assert_called_with(
                Namespace='AWS/EC2', MetricName='CPUUtillization',
                StartTime=datetime.strptime(query.since, '%Y-%m-%dT%H:%M:%S'),
                EndTime=datetime.strptime(query.until, '%Y-%m-%dT%H:%M:%S'), Period=480,
                Dimensions=[{'Name': 'AutoScalingGroupName', 'Value': 'foo'}],
                Statistics=['Average']
            )
예제 #5
0
    def test_query_maxdatapoints(self, boto3, config, query_dict):
        query = CWDataSource.METRIC_QUERY_CLS(**query_dict)
        cw = CWDataSource(config)
        datapoints = cw.datapoints(query, maxdatapoints=100)

        boto3.session.Session.return_value.client.return_value.get_metric_statistics.assert_called_with(
            Namespace="AWS/EC2",
            MetricName="CPUUtillization",
            StartTime=datetime.strptime(query.since, "%Y-%m-%dT%H:%M:%S"),
            EndTime=datetime.strptime(query.until, "%Y-%m-%dT%H:%M:%S"),
            Period=480,
            Dimensions=[{"Name": "AutoScalingGroupName", "Value": "foo"}],
            Statistics=["Average"],
        )
예제 #6
0
def config_options():
    return CWDataSource.DATA_SOURCE_CONFIGURATION_CLS(**{
        'type': 'cw',
        'name': 'cw',
        'region': 'eu-west-1',
        'profile': 'sandbox',
    })
예제 #7
0
    def test_query(self, boto3, config, query_dict, response):
        query = CWDataSource.METRIC_QUERY_CLS(**query_dict)
        boto3.session.Session.return_value.client.return_value.\
            get_metric_statistics.return_value = response
        cw = CWDataSource(config)
        datapoints = cw.datapoints(query)
        assert len(datapoints) == len(response['Datapoints'])
        for idx, i in enumerate(datapoints):
            assert i[0] == response['Datapoints'][idx]['Average']
            assert i[0] == response['Datapoints'][idx]['Average']

        boto3.session.Session.return_value.client.return_value.\
            get_metric_statistics.assert_called_with(
                Namespace='AWS/EC2', MetricName='CPUUtillization',
                StartTime=datetime.strptime(query.since, '%Y-%m-%dT%H:%M:%S'),
                EndTime=datetime.strptime(query.until, '%Y-%m-%dT%H:%M:%S'), Period=60,
                Dimensions=[{'Name': 'AutoScalingGroupName', 'Value': 'foo'}],
                Statistics=['Average']
            )
예제 #8
0
    def test_query(self, boto3, config, query_dict, response):
        query = CWDataSource.METRIC_QUERY_CLS(**query_dict)
        boto3.session.Session.return_value.client.return_value.get_metric_statistics.return_value = response
        cw = CWDataSource(config)
        datapoints = cw.datapoints(query)
        assert len(datapoints) == len(response["Datapoints"])
        for idx, i in enumerate(datapoints):
            assert i[0] == response["Datapoints"][idx]["Average"]
            assert i[0] == response["Datapoints"][idx]["Average"]

        boto3.session.Session.return_value.client.return_value.get_metric_statistics.assert_called_with(
            Namespace="AWS/EC2",
            MetricName="CPUUtillization",
            StartTime=datetime.strptime(query.since, "%Y-%m-%dT%H:%M:%S"),
            EndTime=datetime.strptime(query.until, "%Y-%m-%dT%H:%M:%S"),
            Period=60,
            Dimensions=[{"Name": "AutoScalingGroupName", "Value": "foo"}],
            Statistics=["Average"],
        )
예제 #9
0
 def test_ok(self, boto3, config):
     cw = CWDataSource(config)
     assert cw.test() == True
예제 #10
0
 def test_cw_client_opitons(self, boto3, config_options):
     cw = CWDataSource(config_options)
     cw._cw_client()
     boto3.session.Session.called_with(region_name='eu-west-1',
                                       profile_name='sandbox')
예제 #11
0
 def test_cw_client(self, boto3, config):
     cw = CWDataSource(config)
     cw._cw_client()
     boto3.session.Session.called_with(None, None)
예제 #12
0
def config():
    return CWDataSource.DATA_SOURCE_CONFIGURATION_CLS(**{
        'type': 'cw',
        'name': 'cw',
    })
예제 #13
0
 def test_ok(self, boto3, config):
     cw = CWDataSource(config)
     assert cw.test() == True
예제 #14
0
 def test_cw_client_opitons(self, boto3, config_options):
     cw = CWDataSource(config_options)
     cw._cw_client()
     boto3.session.Session.called_with(region_name="eu-west-1", profile_name="sandbox")
예제 #15
0
 def test_cw_client(self, boto3, config):
     cw = CWDataSource(config)
     cw._cw_client()
     boto3.session.Session.called_with(None, None)
예제 #16
0
 def test_query_invalid_statistics(self, boto3, config, query_dict, response):
     query_dict.update({"statistics": "foo"})
     query = CWDataSource.METRIC_QUERY_CLS(**query_dict)
     cw = CWDataSource(config)
     with pytest.raises(InvalidMetricQuery):
         datapoints = cw.datapoints(query)