Move os_faults import from the root of module
os-faults dependency is not lightweight. It depends on ansible which is quite huge library. os-faults is not used regurarly, so there is no need to load all its module and dependencies at run-time for all cases(even when fault_injection hook plugin is not used). Change-Id: Iba35853f96ab7d46de12c2fe32da4fd268c90946
This commit is contained in:
parent
23f72e6bf1
commit
53a77e76c7
@ -13,8 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os_faults
|
||||
|
||||
from rally.common import logging
|
||||
from rally.common import objects
|
||||
from rally import consts
|
||||
@ -23,7 +21,7 @@ from rally.task import hook
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@hook.configure(name="fault_injection")
|
||||
@hook.configure(name="fault_injection", platform="openstack")
|
||||
class FaultInjectionHook(hook.Hook):
|
||||
"""Performs fault injection using os-faults library.
|
||||
|
||||
@ -65,6 +63,8 @@ class FaultInjectionHook(hook.Hook):
|
||||
return extra_config.get("cloud_config")
|
||||
|
||||
def run(self):
|
||||
import os_faults
|
||||
|
||||
# get cloud configuration
|
||||
cloud_config = self.get_cloud_config()
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
import os_faults
|
||||
from os_faults.api import error
|
||||
|
||||
from rally import consts
|
||||
@ -46,44 +47,47 @@ class FaultInjectionHookTestCase(test.TestCase):
|
||||
self.assertEqual(1, len(results))
|
||||
|
||||
@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)
|
||||
def test_run(self, mock_timer, mock_connect, mock_human_api,
|
||||
mock_deployment_get):
|
||||
injector_inst = mock_connect.return_value
|
||||
def test_run(self, mock_timer, mock_deployment_get):
|
||||
hook = fault_injection.FaultInjectionHook(
|
||||
self.task, {"action": "foo", "verify": True},
|
||||
{"iteration": 1})
|
||||
|
||||
with mock.patch.object(os_faults, "human_api") as mock_human_api:
|
||||
with mock.patch.object(os_faults, "connect") as mock_connect:
|
||||
hook.run_sync()
|
||||
|
||||
injector_inst = mock_connect.return_value
|
||||
|
||||
mock_connect.assert_called_once_with(None)
|
||||
mock_human_api.assert_called_once_with(injector_inst, "foo")
|
||||
|
||||
self.assertEqual(
|
||||
{"finished_at": fakes.FakeTimer().finish_timestamp(),
|
||||
"started_at": fakes.FakeTimer().timestamp(),
|
||||
"status": consts.HookStatus.SUCCESS,
|
||||
"triggered_by": {"iteration": 1}},
|
||||
hook.result())
|
||||
|
||||
mock_connect.assert_called_once_with(None)
|
||||
injector_inst.verify.assert_called_once_with()
|
||||
mock_human_api.assert_called_once_with(injector_inst, "foo")
|
||||
|
||||
@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)
|
||||
def test_run_extra_config(self, mock_timer, mock_connect, mock_human_api,
|
||||
mock_deployment_get):
|
||||
def test_run_extra_config(self, mock_timer, mock_deployment_get):
|
||||
mock_deployment_get.return_value = {
|
||||
"config": {"type": "ExistingCloud",
|
||||
"extra": {"cloud_config": {"conf": "foo_config"}}}}
|
||||
injector_inst = mock_connect.return_value
|
||||
hook = fault_injection.FaultInjectionHook(
|
||||
self.task, {"action": "foo"}, {"iteration": 1})
|
||||
|
||||
with mock.patch.object(os_faults, "human_api") as mock_human_api:
|
||||
with mock.patch.object(os_faults, "connect") as mock_connect:
|
||||
hook.run_sync()
|
||||
|
||||
injector_inst = mock_connect.return_value
|
||||
|
||||
mock_connect.assert_called_once_with({"conf": "foo_config"})
|
||||
mock_human_api.assert_called_once_with(injector_inst, "foo")
|
||||
|
||||
self.assertEqual(
|
||||
{"finished_at": fakes.FakeTimer().finish_timestamp(),
|
||||
"started_at": fakes.FakeTimer().timestamp(),
|
||||
@ -91,9 +95,6 @@ class FaultInjectionHookTestCase(test.TestCase):
|
||||
"triggered_by": {"iteration": 1}},
|
||||
hook.result())
|
||||
|
||||
mock_connect.assert_called_once_with({"conf": "foo_config"})
|
||||
mock_human_api.assert_called_once_with(injector_inst, "foo")
|
||||
|
||||
@mock.patch("rally.common.objects.Deployment.get")
|
||||
@mock.patch("os_faults.human_api")
|
||||
@mock.patch("os_faults.connect")
|
||||
|
Loading…
x
Reference in New Issue
Block a user