Browse Source

Fix InfluxDB storage's "_point_to_dataframe_entry" method

This fixes the "_point_to_dataframe_entry" method by checking if the
"metadata" and "groupby" attributes of points returned by the influxdb
client are not None.

Change-Id: Ic7e482fad3ad05026fa14412acb577fe7a02045c
(cherry picked from commit 0259fe458c)
changes/72/705772/1
Luka Peschke 10 months ago
parent
commit
7d6b82b8a8
2 changed files with 59 additions and 2 deletions
  1. +4
    -2
      cloudkitty/storage/v2/influx.py
  2. +55
    -0
      cloudkitty/tests/storage/v2/test_influxdb.py

+ 4
- 2
cloudkitty/storage/v2/influx.py View File

@@ -270,8 +270,10 @@ class InfluxStorage(v2_storage.BaseStorage):

@staticmethod
def _point_to_dataframe_entry(point):
groupby = point.pop('groupby').split('|')
metadata = point.pop('metadata').split('|')
groupby = (point.pop('groupby', None) or '').split('|')
groupby = [g for g in groupby if g]
metadata = (point.pop('metadata', None) or '').split('|')
metadata = [m for m in metadata if m]
return {
'vol': {
'unit': point['unit'],

+ 55
- 0
cloudkitty/tests/storage/v2/test_influxdb.py View File

@@ -0,0 +1,55 @@
# Copyright 2019 Objectif Libre
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
from cloudkitty.storage.v2.influx import InfluxStorage
from cloudkitty.tests import TestCase


class TestInfluxDBStorage(TestCase):

def setUp(self):
super(TestInfluxDBStorage, self).setUp()
self.point = {
'unit': 'banana',
'qty': 42,
'price': 1.0,
'groupby': 'one|two',
'metadata': '1|2',
'one': '1',
'two': '2',
'1': 'one',
'2': 'two',
}

def test_point_to_dataframe_entry_valid_point(self):
self.assertEqual(
InfluxStorage._point_to_dataframe_entry(self.point), {
'vol': {'unit': 'banana', 'qty': 42},
'rating': {'price': 1.0},
'groupby': {'one': '1', 'two': '2'},
'metadata': {'1': 'one', '2': 'two'},
}
)

def test_point_to_dataframe_entry_invalid_groupby_metadata(self):
self.point['groupby'] = 'a'
self.point['metadata'] = None
self.assertEqual(
InfluxStorage._point_to_dataframe_entry(self.point), {
'vol': {'unit': 'banana', 'qty': 42},
'rating': {'price': 1.0},
'groupby': {'a': ''},
'metadata': {}
}
)

Loading…
Cancel
Save