From 9d28a15c7f1ab6e7e422e3769a891d2903f416a5 Mon Sep 17 00:00:00 2001 From: Anton Studenov Date: Tue, 20 Dec 2016 18:14:36 +0300 Subject: [PATCH] [API] Add API class Current implementation requires additional steps before api usage: - setting(initialization) config; - logging configuration; - etc. All required steps already implemented on CLI level. This patch just moves it on API layer, so users will be able to use rally api right away. Change-Id: I806a6b5a915c751095f03ab128b41cb79ec5d3c5 --- rally/plugins/openstack/hook/fault_injection.py | 4 ++-- tests/unit/fakes.py | 16 ++++++++++++++++ .../openstack/hook/test_fault_injection.py | 6 +++--- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/rally/plugins/openstack/hook/fault_injection.py b/rally/plugins/openstack/hook/fault_injection.py index f0d6e9fd..526650d8 100644 --- a/rally/plugins/openstack/hook/fault_injection.py +++ b/rally/plugins/openstack/hook/fault_injection.py @@ -15,8 +15,8 @@ import os_faults -from rally import api from rally.common import logging +from rally.common import objects from rally import consts from rally.task import hook @@ -56,7 +56,7 @@ class FaultInjectionHook(hook.Hook): } def get_cloud_config(self): - deployment = api.Deployment.get(self.task["deployment_uuid"]) + deployment = objects.Deployment.get(self.task["deployment_uuid"]) deployment_config = deployment["config"] if deployment_config["type"] != "ExistingCloud": return None diff --git a/tests/unit/fakes.py b/tests/unit/fakes.py index fe09dc02..2440cdc4 100644 --- a/tests/unit/fakes.py +++ b/tests/unit/fakes.py @@ -27,6 +27,7 @@ from novaclient import exceptions as nova_exceptions import six from swiftclient import exceptions as swift_exceptions +from rally import api from rally.common import objects from rally.common import utils as rally_utils from rally import consts @@ -1847,3 +1848,18 @@ class FakeTask(dict): def to_dict(self): return self + + +class FakeAPI(object): + + def __init__(self): + self._deployment = mock.Mock(spec=api._Deployment) + self._task = mock.Mock(spec=api._Task) + + @property + def deployment(self): + return self._deployment + + @property + def task(self): + return self._task diff --git a/tests/unit/plugins/openstack/hook/test_fault_injection.py b/tests/unit/plugins/openstack/hook/test_fault_injection.py index 26cbd5a3..1befad1f 100644 --- a/tests/unit/plugins/openstack/hook/test_fault_injection.py +++ b/tests/unit/plugins/openstack/hook/test_fault_injection.py @@ -60,7 +60,7 @@ class FaultInjectionHookTestCase(test.TestCase): fault_injection.FaultInjectionHook.validate, config) - @mock.patch("rally.cli.commands.deployment.api.Deployment.get") + @mock.patch("rally.common.objects.Deployment.get") @mock.patch("os_faults.human_api") @mock.patch("os_faults.connect") @mock.patch("rally.common.utils.Timer", side_effect=fakes.FakeTimer) @@ -84,7 +84,7 @@ class FaultInjectionHookTestCase(test.TestCase): injector_inst.verify.assert_called_once_with() mock_human_api.assert_called_once_with(injector_inst, "foo") - @mock.patch("rally.cli.commands.deployment.api.Deployment.get") + @mock.patch("rally.common.objects.Deployment.get") @mock.patch("os_faults.human_api") @mock.patch("os_faults.connect") @mock.patch("rally.common.utils.Timer", side_effect=fakes.FakeTimer) @@ -109,7 +109,7 @@ class FaultInjectionHookTestCase(test.TestCase): mock_connect.assert_called_once_with({"conf": "foo_config"}) mock_human_api.assert_called_once_with(injector_inst, "foo") - @mock.patch("rally.cli.commands.deployment.api.Deployment.get") + @mock.patch("rally.common.objects.Deployment.get") @mock.patch("os_faults.human_api") @mock.patch("os_faults.connect") @mock.patch("rally.common.utils.Timer", side_effect=fakes.FakeTimer)