Beispiel #1
0
    def test_read_usage_records_given_no_records_found(self):
        acs_mock = self.mock_cloudstack({'project': [{'name': 'name'}]}, {'usagerecord': []})
        measure_mock = self.mock_measure()
        reader = UsageRecordReader('region')

        reader.index_usage()

        self.assertEquals(1, measure_mock.delete.call_count)
        self.assertEquals(0, measure_mock.create.call_count)
        self.assertEquals(1, acs_mock.listUsageRecords.called)
    def test_read_usage_records_given_no_records_found(self):
        acs_mock = self.mock_cloudstack({'project': [{'name': 'name'}]}, {'usagerecord': []}, {'serviceoffering': [self.service_offerings]})
        measure_mock = self.mock_elk()
        reader = UsageRecordReader('region')

        reader.index_usage()

        self.assertEquals(1, measure_mock.delete_usage_records.call_count)
        self.assertEquals(0, measure_mock.create_usage_record.call_count)
        self.assertEquals(1, acs_mock.listUsageRecords.called)
Beispiel #3
0
    def test_read_usage_records(self):
        acs_mock = self.mock_cloudstack({'project': [{'name': 'name'}]}, {'usagerecord': [{
            "enddate": "2016-03-14'T'23:59:59-03:00",
            "offeringid": "8d67bc56-d1dd-4f19-83bd-b3b546a2a4f7",
            "project": "Admin",
            "projectid": "8ea2cf55-2b12-4821-bac7-3c96a4cf1ac2",
            "rawusage": "24",
            "startdate": "2016-03-14'T'00:00:00-03:00",
            "usagetype": 2

        }]})
        measure_mock = self.mock_measure()
        reader = UsageRecordReader('region')

        reader.index_usage()

        self.assertEquals(1, measure_mock.delete.call_count)
        self.assertEquals(4, measure_mock.create.call_count)
        self.assertEquals(8, acs_mock.listUsageRecords.call_count)
    def test_read_usage_records(self):
        acs_mock = self.mock_cloudstack({'project': [{'name': 'name'}]}, {'usagerecord': [{
            "enddate": "2016-03-14'T'23:59:59-03:00",
            "offeringid": "8d67bc56-d1dd-4f19-83bd-b3b546a2a4f7",
            "project": "Admin",
            "projectid": "8ea2cf55-2b12-4821-bac7-3c96a4cf1ac2",
            "rawusage": "24",
            "startdate": "2016-03-14'T'00:00:00-03:00",
            "usagetype": 2

        }]}, {'serviceoffering': [self.service_offerings]})
        measure_mock = self.mock_elk()
        reader = UsageRecordReader('region')

        reader.index_usage()

        self.assertEquals(1, measure_mock.delete_usage_records.call_count)
        self.assertEquals(2, measure_mock.create_usage_record.call_count)
        self.assertEquals(4, acs_mock.listUsageRecords.call_count)
def index_usage():
    try:
        date_str = request.args.get('date', None)
        if date_str:
            datetime.datetime.strptime(date_str, '%Y-%m-%d')
        region = request.args.get('region')
        if region is None:
            return "Parameter 'region' should be informed"

        UsageRecordReader(region).index_usage(date_str)
        return "Execution ended for region %s" % region
    except ValueError:
        return "Incorrect date format, should be YYYY-MM-DD"