"Fossies" - the Fresh Open Source Software Archive

Member "cloudkitty-9.0.0/cloudkitty/tests/collectors/test_gnocchi.py" (10 Apr 2019, 4897 Bytes) of package /linux/misc/openstack/cloudkitty-9.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test_gnocchi.py": 8.0.0_vs_9.0.0.

    1 # -*- coding: utf-8 -*-
    2 # Copyright 2015 Objectif Libre
    3 #
    4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    5 #    not use this file except in compliance with the License. You may obtain
    6 #    a copy of the License at
    7 #
    8 #         http://www.apache.org/licenses/LICENSE-2.0
    9 #
   10 #    Unless required by applicable law or agreed to in writing, software
   11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   13 #    License for the specific language governing permissions and limitations
   14 #    under the License.
   15 #
   16 #
   17 from cloudkitty.collector import gnocchi
   18 from cloudkitty import tests
   19 from cloudkitty.tests import samples
   20 from cloudkitty import transformer
   21 
   22 
   23 class GnocchiCollectorTest(tests.TestCase):
   24     def setUp(self):
   25         super(GnocchiCollectorTest, self).setUp()
   26         self._tenant_id = samples.TENANT
   27         self.conf.set_override('collector', 'gnocchi', 'collect')
   28         self.conf.set_override(
   29             'gnocchi_auth_type', 'basic', 'collector_gnocchi')
   30 
   31         self.collector = gnocchi.GnocchiCollector(
   32             transformer.get_transformers(),
   33             period=3600,
   34             conf=samples.DEFAULT_METRICS_CONF,
   35         )
   36 
   37     def test_format_data_raises_exception(self):
   38         metconf = {'extra_args': {'resource_key': 'id'}}
   39         data = {'group': {'id': '281b9dc6-5d02-4610-af2d-10d0d6887f48'}}
   40         self.assertRaises(
   41             gnocchi.AssociatedResourceNotFound,
   42             self.collector._format_data,
   43             metconf,
   44             data,
   45             resources_info={},
   46         )
   47 
   48     # Filter generation
   49     def test_generate_one_field_filter(self):
   50         actual = self.collector.gen_filter(value1=2)
   51         expected = {
   52             '=': {
   53                 'value1': 2
   54             }}
   55         self.assertEqual(expected, actual)
   56 
   57     def test_generate_two_fields_filter(self):
   58         actual = self.collector.gen_filter(value1=2, value2=3)
   59         expected = {'and': [{
   60             '=': {
   61                 'value1': 2
   62             }}, {
   63             '=': {
   64                 'value2': 3
   65             }}]}
   66         self.assertEqual(expected, actual)
   67 
   68     def test_generate_two_fields_filter_different_operations(self):
   69         actual = self.collector.gen_filter(
   70             cop='>=',
   71             lop='or',
   72             value1=2,
   73             value2=3)
   74         expected = {'or': [{
   75             '>=': {
   76                 'value1': 2
   77             }}, {
   78             '>=': {
   79                 'value2': 3
   80             }}]}
   81         self.assertEqual(expected, actual)
   82 
   83     def test_generate_two_filters_and_add_logical(self):
   84         filter1 = self.collector.gen_filter(value1=2)
   85         filter2 = self.collector.gen_filter(cop='>', value2=3)
   86         actual = self.collector.extend_filter(filter1, filter2, lop='or')
   87         expected = {'or': [{
   88             '=': {
   89                 'value1': 2
   90             }}, {
   91             '>': {
   92                 'value2': 3
   93             }}]}
   94         self.assertEqual(expected, actual)
   95 
   96     def test_noop_on_single_filter(self):
   97         filter1 = self.collector.gen_filter(value1=2)
   98         actual = self.collector.extend_filter(filter1, lop='or')
   99         self.assertEqual(filter1, actual)
  100 
  101     def test_try_extend_empty_filter(self):
  102         actual = self.collector.extend_filter()
  103         self.assertEqual({}, actual)
  104         actual = self.collector.extend_filter(actual, actual)
  105         self.assertEqual({}, actual)
  106 
  107     def test_try_extend_filter_with_none(self):
  108         filter1 = self.collector.gen_filter(value1=2)
  109         actual = self.collector.extend_filter(filter1, None)
  110         self.assertEqual(filter1, actual)
  111 
  112     def test_generate_two_logical_ops(self):
  113         filter1 = self.collector.gen_filter(value1=2, value2=3)
  114         filter2 = self.collector.gen_filter(cop='<=', value3=1)
  115         actual = self.collector.extend_filter(filter1, filter2, lop='or')
  116         expected = {'or': [{
  117             'and': [{
  118                 '=': {
  119                     'value1': 2
  120                 }}, {
  121                 '=': {
  122                     'value2': 3
  123                 }}]}, {
  124             '<=': {
  125                 'value3': 1
  126             }}]}
  127         self.assertEqual(expected, actual)
  128 
  129     def test_gen_filter_parameters(self):
  130         actual = self.collector.gen_filter(
  131             cop='>',
  132             lop='or',
  133             value1=2,
  134             value2=3)
  135         expected = {'or': [{
  136             '>': {
  137                 'value1': 2
  138             }}, {
  139             '>': {
  140                 'value2': 3
  141             }}]}
  142         self.assertEqual(expected, actual)
  143 
  144     def test_extend_filter_parameters(self):
  145         actual = self.collector.extend_filter(
  146             ['dummy1'],
  147             ['dummy2'],
  148             lop='or')
  149         expected = {'or': ['dummy1', 'dummy2']}
  150         self.assertEqual(expected, actual)