Merge "Add Gnocchi datasource"
This commit is contained in:
@@ -15,6 +15,8 @@ import ceilometerclient.v2.client as ceclient_v2
|
||||
from cinderclient import client as ciclient
|
||||
from cinderclient.v1 import client as ciclient_v1
|
||||
from glanceclient import client as glclient
|
||||
from gnocchiclient import client as gnclient
|
||||
from gnocchiclient.v1 import client as gnclient_v1
|
||||
from keystoneauth1 import loading as ka_loading
|
||||
import mock
|
||||
from monascaclient import client as monclient
|
||||
@@ -157,6 +159,32 @@ class TestClients(base.TestCase):
|
||||
glance_cached = osc.glance()
|
||||
self.assertEqual(glance, glance_cached)
|
||||
|
||||
@mock.patch.object(gnclient, 'Client')
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_gnocchi(self, mock_session, mock_call):
|
||||
osc = clients.OpenStackClients()
|
||||
osc._gnocchi = None
|
||||
osc.gnocchi()
|
||||
mock_call.assert_called_once_with(CONF.gnocchi_client.api_version,
|
||||
session=mock_session)
|
||||
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_gnocchi_diff_vers(self, mock_session):
|
||||
# gnocchiclient currently only has one version (v1)
|
||||
CONF.set_override('api_version', '1', group='gnocchi_client')
|
||||
osc = clients.OpenStackClients()
|
||||
osc._gnocchi = None
|
||||
osc.gnocchi()
|
||||
self.assertEqual(gnclient_v1.Client, type(osc.gnocchi()))
|
||||
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_gnocchi_cached(self, mock_session):
|
||||
osc = clients.OpenStackClients()
|
||||
osc._gnocchi = None
|
||||
gnocchi = osc.gnocchi()
|
||||
gnocchi_cached = osc.gnocchi()
|
||||
self.assertEqual(gnocchi, gnocchi_cached)
|
||||
|
||||
@mock.patch.object(ciclient, 'Client')
|
||||
@mock.patch.object(clients.OpenStackClients, 'session')
|
||||
def test_clients_cinder(self, mock_session, mock_call):
|
||||
|
||||
@@ -30,8 +30,9 @@ class TestListOpts(base.TestCase):
|
||||
self.base_sections = [
|
||||
'DEFAULT', 'api', 'database', 'watcher_decision_engine',
|
||||
'watcher_applier', 'watcher_planner', 'nova_client',
|
||||
'glance_client', 'cinder_client', 'ceilometer_client',
|
||||
'monasca_client', 'neutron_client', 'watcher_clients_auth']
|
||||
'glance_client', 'gnocchi_client', 'cinder_client',
|
||||
'ceilometer_client', 'monasca_client',
|
||||
'neutron_client', 'watcher_clients_auth']
|
||||
self.opt_sections = list(dict(opts.list_opts()).keys())
|
||||
|
||||
def test_run_list_opts(self):
|
||||
|
||||
68
watcher/tests/datasource/test_gnocchi_helper.py
Normal file
68
watcher/tests/datasource/test_gnocchi_helper.py
Normal file
@@ -0,0 +1,68 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2017 Servionica
|
||||
#
|
||||
# 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.
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from oslo_utils import timeutils
|
||||
|
||||
from watcher.common import clients
|
||||
from watcher.common import exception
|
||||
from watcher.datasource import gnocchi as gnocchi_helper
|
||||
from watcher.tests import base
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
@mock.patch.object(clients.OpenStackClients, 'gnocchi')
|
||||
class TestGnocchiHelper(base.BaseTestCase):
|
||||
|
||||
def test_gnocchi_statistic_aggregation(self, mock_gnocchi):
|
||||
gnocchi = mock.MagicMock()
|
||||
expected_result = 5.5
|
||||
|
||||
expected_measures = [["2017-02-02T09:00:00.000000", 360, 5.5]]
|
||||
|
||||
gnocchi.metric.get_measures.return_value = expected_measures
|
||||
mock_gnocchi.return_value = gnocchi
|
||||
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
result = helper.statistic_aggregation(
|
||||
resource_id='16a86790-327a-45f9-bc82-45839f062fdc',
|
||||
metric='cpu_util',
|
||||
granularity=360,
|
||||
start_time=timeutils.parse_isotime("2017-02-02T09:00:00.000000"),
|
||||
stop_time=timeutils.parse_isotime("2017-02-02T10:00:00.000000"),
|
||||
aggregation='mean'
|
||||
)
|
||||
self.assertEqual(expected_result, result)
|
||||
|
||||
def test_gnocchi_wrong_datetime(self, mock_gnocchi):
|
||||
gnocchi = mock.MagicMock()
|
||||
|
||||
expected_measures = [["2017-02-02T09:00:00.000000", 360, 5.5]]
|
||||
|
||||
gnocchi.metric.get_measures.return_value = expected_measures
|
||||
mock_gnocchi.return_value = gnocchi
|
||||
|
||||
helper = gnocchi_helper.GnocchiHelper()
|
||||
self.assertRaises(
|
||||
exception.InvalidParameter, helper.statistic_aggregation,
|
||||
resource_id='16a86790-327a-45f9-bc82-45839f062fdc',
|
||||
metric='cpu_util',
|
||||
granularity=360,
|
||||
start_time="2017-02-02T09:00:00.000000",
|
||||
stop_time=timeutils.parse_isotime("2017-02-02T10:00:00.000000"),
|
||||
aggregation='mean')
|
||||
Reference in New Issue
Block a user