unit-tests: fix mocks' naming
Fix mocks' argument/decorator naming. Partial-Bug: #1462956 Change-Id: I8366736f3bc7088f867eec1fc72630dbe1bcf19e
This commit is contained in:
@@ -28,13 +28,13 @@ PLOT = "rally.benchmark.processing.plot."
|
||||
class PlotTestCase(test.TestCase):
|
||||
@mock.patch(PLOT + "ui_utils")
|
||||
@mock.patch(PLOT + "_process_results")
|
||||
def test_plot(self, mock_proc_results, mock_utils):
|
||||
def test_plot(self, mock__process_results, mock_ui_utils):
|
||||
mock_render = mock.Mock(return_value="plot_html")
|
||||
mock_utils.get_template = mock.Mock(
|
||||
mock_ui_utils.get_template = mock.Mock(
|
||||
return_value=mock.Mock(render=mock_render))
|
||||
task_data = [{"name": "a"}, {"name": "b"}]
|
||||
task_source = "JSON"
|
||||
mock_proc_results.return_value = (task_source, task_data)
|
||||
mock__process_results.return_value = (task_source, task_data)
|
||||
|
||||
result = plot.plot(["abc"])
|
||||
|
||||
@@ -43,15 +43,17 @@ class PlotTestCase(test.TestCase):
|
||||
data=json.dumps(task_data),
|
||||
source=json.dumps(task_source)
|
||||
)
|
||||
mock_utils.get_template.assert_called_once_with("task/report.mako")
|
||||
mock_ui_utils.get_template.assert_called_once_with("task/report.mako")
|
||||
|
||||
@mock.patch(PLOT + "json.dumps")
|
||||
@mock.patch(PLOT + "_prepare_data")
|
||||
@mock.patch(PLOT + "_process_atomic")
|
||||
@mock.patch(PLOT + "_get_atomic_action_durations")
|
||||
@mock.patch(PLOT + "_process_main_duration")
|
||||
def test__process_results(self, mock_main_duration, mock_get_atomic,
|
||||
mock_atomic, mock_prepare, mock_dumps):
|
||||
def test__process_results(
|
||||
self, mock__process_main_duration,
|
||||
mock__get_atomic_action_durations, mock__process_atomic,
|
||||
mock__prepare_data, mock_dumps):
|
||||
sla = [{"success": True}]
|
||||
result = ["iter_1", "iter_2"]
|
||||
iterations = len(result)
|
||||
@@ -73,15 +75,15 @@ class PlotTestCase(test.TestCase):
|
||||
"Success",
|
||||
"Count"]
|
||||
atomic_durations = [["atomic_1"], ["atomic_2"]]
|
||||
mock_prepare.side_effect = lambda i: {"errors": "errors_list",
|
||||
"output": [],
|
||||
"output_errors": [],
|
||||
"sla": i["sla"],
|
||||
"load_duration": 1234.5,
|
||||
"full_duration": 6789.1}
|
||||
mock_main_duration.return_value = "main_duration"
|
||||
mock_get_atomic.return_value = atomic_durations
|
||||
mock_atomic.return_value = "main_atomic"
|
||||
mock__prepare_data.side_effect = lambda i: {"errors": "errors_list",
|
||||
"output": [],
|
||||
"output_errors": [],
|
||||
"sla": i["sla"],
|
||||
"load_duration": 1234.5,
|
||||
"full_duration": 6789.1}
|
||||
mock__process_main_duration.return_value = "main_duration"
|
||||
mock__get_atomic_action_durations.return_value = atomic_durations
|
||||
mock__process_atomic.return_value = "main_atomic"
|
||||
mock_dumps.return_value = "JSON"
|
||||
|
||||
source, scenarios = plot._process_results(results)
|
||||
@@ -105,8 +107,8 @@ class PlotTestCase(test.TestCase):
|
||||
"met": met,
|
||||
"name": name,
|
||||
"config": config,
|
||||
"iterations": mock_main_duration.return_value,
|
||||
"atomic": mock_atomic.return_value,
|
||||
"iterations": mock__process_main_duration.return_value,
|
||||
"atomic": mock__process_atomic.return_value,
|
||||
"table_cols": table_cols,
|
||||
"table_rows": atomic_durations,
|
||||
"errors": "errors_list",
|
||||
|
@@ -98,29 +98,29 @@ class ScenarioTestCase(test.TestCase):
|
||||
validators, clients, args, "fake_uuid")
|
||||
|
||||
@mock.patch("rally.benchmark.scenarios.base.Scenario.get_by_name")
|
||||
def test_validate__no_validators(self, mock_base_get_by_name):
|
||||
def test_validate__no_validators(self, mock_scenario_get_by_name):
|
||||
|
||||
class FakeScenario(fakes.FakeScenario):
|
||||
pass
|
||||
|
||||
FakeScenario.do_it = mock.MagicMock()
|
||||
FakeScenario.do_it.validators = []
|
||||
mock_base_get_by_name.return_value = FakeScenario
|
||||
mock_scenario_get_by_name.return_value = FakeScenario
|
||||
|
||||
base.Scenario.validate("FakeScenario.do_it", {"a": 1, "b": 2})
|
||||
|
||||
mock_base_get_by_name.assert_called_once_with("FakeScenario")
|
||||
mock_scenario_get_by_name.assert_called_once_with("FakeScenario")
|
||||
|
||||
@mock.patch("rally.benchmark.scenarios.base.Scenario._validate_helper")
|
||||
@mock.patch("rally.benchmark.scenarios.base.Scenario.get_by_name")
|
||||
def test_validate__admin_validators(self, mock_base_get_by_name,
|
||||
mock_validate_helper):
|
||||
def test_validate__admin_validators(self, mock_scenario_get_by_name,
|
||||
mock_scenario__validate_helper):
|
||||
|
||||
class FakeScenario(fakes.FakeScenario):
|
||||
pass
|
||||
|
||||
FakeScenario.do_it = mock.MagicMock()
|
||||
mock_base_get_by_name.return_value = FakeScenario
|
||||
mock_scenario_get_by_name.return_value = FakeScenario
|
||||
|
||||
validators = [mock.MagicMock(), mock.MagicMock()]
|
||||
for validator in validators:
|
||||
@@ -131,19 +131,19 @@ class ScenarioTestCase(test.TestCase):
|
||||
args = {"a": 1, "b": 2}
|
||||
base.Scenario.validate(
|
||||
"FakeScenario.do_it", args, admin="admin", deployment=deployment)
|
||||
mock_validate_helper.assert_called_once_with(validators, "admin", args,
|
||||
deployment)
|
||||
mock_scenario__validate_helper.assert_called_once_with(
|
||||
validators, "admin", args, deployment)
|
||||
|
||||
@mock.patch("rally.benchmark.scenarios.base.Scenario._validate_helper")
|
||||
@mock.patch("rally.benchmark.scenarios.base.Scenario.get_by_name")
|
||||
def test_validate_user_validators(self, mock_base_get_by_name,
|
||||
mock_validate_helper):
|
||||
def test_validate_user_validators(self, mock_scenario_get_by_name,
|
||||
mock_scenario__validate_helper):
|
||||
|
||||
class FakeScenario(fakes.FakeScenario):
|
||||
pass
|
||||
|
||||
FakeScenario.do_it = mock.MagicMock()
|
||||
mock_base_get_by_name.return_value = FakeScenario
|
||||
mock_scenario_get_by_name.return_value = FakeScenario
|
||||
|
||||
validators = [mock.MagicMock(), mock.MagicMock()]
|
||||
for validator in validators:
|
||||
@@ -154,7 +154,7 @@ class ScenarioTestCase(test.TestCase):
|
||||
base.Scenario.validate(
|
||||
"FakeScenario.do_it", args, users=["u1", "u2"])
|
||||
|
||||
mock_validate_helper.assert_has_calls([
|
||||
mock_scenario__validate_helper.assert_has_calls([
|
||||
mock.call(validators, "u1", args, None),
|
||||
mock.call(validators, "u2", args, None)
|
||||
])
|
||||
@@ -288,9 +288,6 @@ class ScenarioTestCase(test.TestCase):
|
||||
self.assertIsInstance(base.Scenario.RESOURCE_NAME_LENGTH, int)
|
||||
self.assertTrue(base.Scenario.RESOURCE_NAME_LENGTH > 4)
|
||||
|
||||
@mock.patch(
|
||||
"rally.benchmark.scenarios.base."
|
||||
"Scenario.RESOURCE_NAME_PREFIX", "prefix_")
|
||||
def test_generate_random_name(self):
|
||||
set_by_length = lambda lst: set(map(len, lst))
|
||||
len_by_prefix = (lambda lst, prefix:
|
||||
@@ -345,10 +342,11 @@ class AtomicActionTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("tests.unit.fakes.FakeScenario._add_atomic_actions")
|
||||
@mock.patch("rally.common.utils.time")
|
||||
def test__exit__(self, mock_time, mock__add_atomic_actions):
|
||||
def test__exit__(self, mock_time, mock_fake_scenario__add_atomic_actions):
|
||||
fake_scenario_instance = fakes.FakeScenario()
|
||||
self.start = mock_time.time()
|
||||
with base.AtomicAction(fake_scenario_instance, "asdf"):
|
||||
pass
|
||||
duration = mock_time.time() - self.start
|
||||
mock__add_atomic_actions.assert_called_once_with("asdf", duration)
|
||||
mock_fake_scenario__add_atomic_actions.assert_called_once_with(
|
||||
"asdf", duration)
|
||||
|
@@ -124,7 +124,7 @@ class BaseContextTestCase(test.TestCase):
|
||||
class ContextManagerTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.context.Context.get")
|
||||
def test_validate(self, mock_get):
|
||||
def test_validate(self, mock_context_get):
|
||||
config = {
|
||||
"ctx1": mock.MagicMock(),
|
||||
"ctx2": mock.MagicMock()
|
||||
@@ -132,13 +132,13 @@ class ContextManagerTestCase(test.TestCase):
|
||||
|
||||
context.ContextManager.validate(config)
|
||||
for ctx in ("ctx1", "ctx2"):
|
||||
mock_get.assert_has_calls([
|
||||
mock_context_get.assert_has_calls([
|
||||
mock.call(ctx),
|
||||
mock.call().validate(config[ctx], non_hidden=False),
|
||||
])
|
||||
|
||||
@mock.patch("rally.benchmark.context.Context.get")
|
||||
def test_validate_non_hidden(self, mock_get):
|
||||
def test_validate_non_hidden(self, mock_context_get):
|
||||
config = {
|
||||
"ctx1": mock.MagicMock(),
|
||||
"ctx2": mock.MagicMock()
|
||||
@@ -146,7 +146,7 @@ class ContextManagerTestCase(test.TestCase):
|
||||
|
||||
context.ContextManager.validate(config, non_hidden=True)
|
||||
for ctx in ("ctx1", "ctx2"):
|
||||
mock_get.assert_has_calls([
|
||||
mock_context_get.assert_has_calls([
|
||||
mock.call(ctx),
|
||||
mock.call().validate(config[ctx], non_hidden=True),
|
||||
])
|
||||
@@ -159,75 +159,73 @@ class ContextManagerTestCase(test.TestCase):
|
||||
context.ContextManager.validate, config)
|
||||
|
||||
@mock.patch("rally.benchmark.context.Context.get")
|
||||
def test_setup(self, mock_get):
|
||||
def test_setup(self, mock_context_get):
|
||||
mock_context = mock.MagicMock()
|
||||
mock_context.return_value = mock.MagicMock(__lt__=lambda x, y: True)
|
||||
mock_get.return_value = mock_context
|
||||
mock_context_get.return_value = mock_context
|
||||
ctx_object = {"config": {"a": [], "b": []}}
|
||||
|
||||
manager = context.ContextManager(ctx_object)
|
||||
result = manager.setup()
|
||||
|
||||
self.assertEqual(result, ctx_object)
|
||||
mock_get.assert_has_calls([mock.call("a"), mock.call("b")],
|
||||
any_order=True)
|
||||
mock_context.assert_has_calls([mock.call(ctx_object),
|
||||
mock.call(ctx_object)], any_order=True)
|
||||
mock_context_get.assert_has_calls(
|
||||
[mock.call("a"), mock.call("b")], any_order=True)
|
||||
mock_context.assert_has_calls(
|
||||
[mock.call(ctx_object), mock.call(ctx_object)], any_order=True)
|
||||
self.assertEqual([mock_context(), mock_context()], manager._visited)
|
||||
mock_context.return_value.assert_has_calls([mock.call.setup(),
|
||||
mock.call.setup()],
|
||||
any_order=True)
|
||||
mock_context.return_value.assert_has_calls(
|
||||
[mock.call.setup(), mock.call.setup()], any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.context.Context.get")
|
||||
def test_cleanup(self, mock_get):
|
||||
def test_cleanup(self, mock_context_get):
|
||||
mock_context = mock.MagicMock()
|
||||
mock_context.return_value = mock.MagicMock(__lt__=lambda x, y: True)
|
||||
mock_get.return_value = mock_context
|
||||
mock_context_get.return_value = mock_context
|
||||
ctx_object = {"config": {"a": [], "b": []}}
|
||||
|
||||
manager = context.ContextManager(ctx_object)
|
||||
manager.cleanup()
|
||||
mock_get.assert_has_calls([mock.call("a"), mock.call("b")],
|
||||
any_order=True)
|
||||
mock_context.assert_has_calls([mock.call(ctx_object),
|
||||
mock.call(ctx_object)], any_order=True)
|
||||
mock_context.return_value.assert_has_calls([mock.call.cleanup(),
|
||||
mock.call.cleanup()],
|
||||
any_order=True)
|
||||
mock_context_get.assert_has_calls(
|
||||
[mock.call("a"), mock.call("b")], any_order=True)
|
||||
mock_context.assert_has_calls(
|
||||
[mock.call(ctx_object), mock.call(ctx_object)], any_order=True)
|
||||
mock_context.return_value.assert_has_calls(
|
||||
[mock.call.cleanup(), mock.call.cleanup()], any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.context.Context.get")
|
||||
def test_cleanup_exception(self, mock_get):
|
||||
def test_cleanup_exception(self, mock_context_get):
|
||||
mock_context = mock.MagicMock()
|
||||
mock_context.return_value = mock.MagicMock(__lt__=lambda x, y: True)
|
||||
mock_context.cleanup.side_effect = Exception()
|
||||
mock_get.return_value = mock_context
|
||||
mock_context_get.return_value = mock_context
|
||||
ctx_object = {"config": {"a": [], "b": []}}
|
||||
manager = context.ContextManager(ctx_object)
|
||||
manager.cleanup()
|
||||
|
||||
mock_get.assert_has_calls([mock.call("a"), mock.call("b")],
|
||||
any_order=True)
|
||||
mock_context.assert_has_calls([mock.call(ctx_object),
|
||||
mock.call(ctx_object)], any_order=True)
|
||||
mock_context.return_value.assert_has_calls([mock.call.cleanup(),
|
||||
mock.call.cleanup()],
|
||||
any_order=True)
|
||||
mock_context_get.assert_has_calls(
|
||||
[mock.call("a"), mock.call("b")], any_order=True)
|
||||
mock_context.assert_has_calls(
|
||||
[mock.call(ctx_object), mock.call(ctx_object)], any_order=True)
|
||||
mock_context.return_value.assert_has_calls(
|
||||
[mock.call.cleanup(), mock.call.cleanup()], any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.context.ContextManager.setup")
|
||||
def test_with_statement(self, mock_setup, mock_cleanup):
|
||||
def test_with_statement(
|
||||
self, mock_context_manager_setup, mock_context_manager_cleanup):
|
||||
with context.ContextManager(mock.MagicMock()):
|
||||
mock_setup.assert_called_once_with()
|
||||
mock_setup.reset_mock()
|
||||
self.assertFalse(mock_cleanup.called)
|
||||
self.assertFalse(mock_setup.called)
|
||||
mock_cleanup.assert_called_once_with()
|
||||
mock_context_manager_setup.assert_called_once_with()
|
||||
mock_context_manager_setup.reset_mock()
|
||||
self.assertFalse(mock_context_manager_cleanup.called)
|
||||
self.assertFalse(mock_context_manager_setup.called)
|
||||
mock_context_manager_cleanup.assert_called_once_with()
|
||||
|
||||
@mock.patch("rally.benchmark.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.context.ContextManager.setup")
|
||||
def test_with_statement_excpetion_during_setup(self, mock_setup,
|
||||
mock_cleanup):
|
||||
mock_setup.side_effect = Exception("abcdef")
|
||||
def test_with_statement_excpetion_during_setup(
|
||||
self, mock_context_manager_setup, mock_context_manager_cleanup):
|
||||
mock_context_manager_setup.side_effect = Exception("abcdef")
|
||||
|
||||
try:
|
||||
with context.ContextManager(mock.MagicMock()):
|
||||
@@ -235,5 +233,5 @@ class ContextManagerTestCase(test.TestCase):
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
mock_setup.assert_called_once_with()
|
||||
mock_cleanup.assert_called_once_with()
|
||||
mock_context_manager_setup.assert_called_once_with()
|
||||
mock_context_manager_cleanup.assert_called_once_with()
|
||||
|
@@ -38,7 +38,7 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
self.assertEqual(eng.task, task)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.jsonschema.validate")
|
||||
def test_validate(self, mock_json_validate):
|
||||
def test_validate(self, mock_validate):
|
||||
config = mock.MagicMock()
|
||||
eng = engine.BenchmarkEngine(config, mock.MagicMock())
|
||||
mock_validate = mock.MagicMock()
|
||||
@@ -67,7 +67,7 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
self.assertTrue(task.set_failed.called)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.jsonschema.validate")
|
||||
def test_validate__wrong_scenarios_name(self, mova_validate):
|
||||
def test_validate__wrong_scenarios_name(self, mock_validate):
|
||||
task = mock.MagicMock()
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), task)
|
||||
eng._validate_config_scenarios_name = mock.MagicMock(
|
||||
@@ -77,7 +77,7 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
self.assertTrue(task.set_failed.called)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.jsonschema.validate")
|
||||
def test_validate__wrong_syntax(self, mova_validate):
|
||||
def test_validate__wrong_syntax(self, mock_validate):
|
||||
task = mock.MagicMock()
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), task)
|
||||
eng._validate_config_scenarios_name = mock.MagicMock()
|
||||
@@ -88,7 +88,7 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
self.assertTrue(task.set_failed.called)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.jsonschema.validate")
|
||||
def test_validate__wrong_semantic(self, mova_validate):
|
||||
def test_validate__wrong_semantic(self, mock_validate):
|
||||
task = mock.MagicMock()
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), task)
|
||||
eng._validate_config_scenarios_name = mock.MagicMock()
|
||||
@@ -125,53 +125,56 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner.validate")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.validate")
|
||||
def test__validate_config_syntax(self, mock_context, mock_runner):
|
||||
def test__validate_config_syntax(
|
||||
self, mock_context_manager_validate,
|
||||
mock_scenario_runner_validate):
|
||||
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
|
||||
eng._validate_config_syntax(config)
|
||||
mock_runner.assert_has_calls([mock.call({}), mock.call("b")],
|
||||
any_order=True)
|
||||
mock_context.assert_has_calls([mock.call("a", non_hidden=True),
|
||||
mock.call({}, non_hidden=True)],
|
||||
any_order=True)
|
||||
mock_scenario_runner_validate.assert_has_calls(
|
||||
[mock.call({}), mock.call("b")], any_order=True)
|
||||
mock_context_manager_validate.assert_has_calls(
|
||||
[mock.call("a", non_hidden=True), mock.call({}, non_hidden=True)],
|
||||
any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.validate")
|
||||
def test__validate_config_syntax__wrong_runner(self, mock_context,
|
||||
mock_runner):
|
||||
def test__validate_config_syntax__wrong_runner(
|
||||
self, mock_context_manager_validate, mock_scenario_runner):
|
||||
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
|
||||
|
||||
mock_runner.validate = mock.MagicMock(
|
||||
mock_scenario_runner.validate = mock.MagicMock(
|
||||
side_effect=jsonschema.ValidationError("a"))
|
||||
self.assertRaises(exceptions.InvalidBenchmarkConfig,
|
||||
eng._validate_config_syntax, config)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner.validate")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager")
|
||||
def test__validate_config_syntax__wrong_context(self, mock_context,
|
||||
mock_runner):
|
||||
def test__validate_config_syntax__wrong_context(
|
||||
self, mock_context_manager, mock_scenario_runner_validate):
|
||||
config = {"sca": [{"context": "a"}], "scb": [{"runner": "b"}]}
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
|
||||
|
||||
mock_context.validate = mock.MagicMock(
|
||||
mock_context_manager.validate = mock.MagicMock(
|
||||
side_effect=jsonschema.ValidationError("a"))
|
||||
self.assertRaises(exceptions.InvalidBenchmarkConfig,
|
||||
eng._validate_config_syntax, config)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario.validate")
|
||||
def test__validate_config_semantic_helper(self, mock_validate):
|
||||
def test__validate_config_semantic_helper(self, mock_scenario_validate):
|
||||
deployment = mock.MagicMock()
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
|
||||
eng._validate_config_semantic_helper("admin", "user", "name", "pos",
|
||||
deployment, {"args": "args"})
|
||||
mock_validate.assert_called_once_with("name", {"args": "args"},
|
||||
admin="admin", users=["user"],
|
||||
deployment=deployment)
|
||||
mock_scenario_validate.assert_called_once_with(
|
||||
"name", {"args": "args"}, admin="admin", users=["user"],
|
||||
deployment=deployment)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario.validate")
|
||||
def test__validate_config_semanitc_helper_invalid_arg(self, mock_validate):
|
||||
mock_validate.side_effect = exceptions.InvalidScenarioArgument()
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario.validate",
|
||||
side_effect=exceptions.InvalidScenarioArgument)
|
||||
def test__validate_config_semanitc_helper_invalid_arg(
|
||||
self, mock_scenario_validate):
|
||||
eng = engine.BenchmarkEngine(mock.MagicMock(), mock.MagicMock())
|
||||
|
||||
self.assertRaises(exceptions.InvalidBenchmarkConfig,
|
||||
@@ -179,7 +182,8 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
"p", mock.MagicMock(), {})
|
||||
|
||||
@mock.patch("rally.benchmark.engine.existingusers_ctx.ExistingUsers")
|
||||
def test_get_user_ctx_for_validation_existing_users(self, mock_users_ctx):
|
||||
def test_get_user_ctx_for_validation_existing_users(
|
||||
self, mock_existing_users):
|
||||
|
||||
context = {"a": 10}
|
||||
users = [mock.MagicMock(), mock.MagicMock()]
|
||||
@@ -190,9 +194,9 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
result = eng._get_user_ctx_for_validation(context)
|
||||
|
||||
self.assertEqual(context["config"]["existing_users"], users)
|
||||
mock_users_ctx.assert_called_once_with(context)
|
||||
mock_existing_users.assert_called_once_with(context)
|
||||
|
||||
self.assertEqual(mock_users_ctx.return_value, result)
|
||||
self.assertEqual(mock_existing_users.return_value, result)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.osclients.Clients")
|
||||
@mock.patch("rally.benchmark.engine.users_ctx")
|
||||
@@ -200,11 +204,12 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
"._validate_config_semantic_helper")
|
||||
@mock.patch("rally.benchmark.engine.objects.Deployment.get",
|
||||
return_value="FakeDeployment")
|
||||
def test__validate_config_semantic(self, mock_deployment_get,
|
||||
mock_helper, mock_userctx,
|
||||
mock_osclients):
|
||||
mock_userctx.UserGenerator = fakes.FakeUserContext
|
||||
mock_osclients.return_value = mock.MagicMock()
|
||||
def test__validate_config_semantic(
|
||||
self, mock_deployment_get,
|
||||
mock__validate_config_semantic_helper,
|
||||
mock_users_ctx, mock_clients):
|
||||
mock_users_ctx.UserGenerator = fakes.FakeUserContext
|
||||
mock_clients.return_value = mock.MagicMock()
|
||||
config = {
|
||||
"a": [mock.MagicMock(), mock.MagicMock()],
|
||||
"b": [mock.MagicMock()]
|
||||
@@ -221,26 +226,29 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
mock.call("admin"),
|
||||
mock.call(fakes.FakeUserContext.user["endpoint"])
|
||||
]
|
||||
mock_osclients.assert_has_calls(expected_calls)
|
||||
mock_clients.assert_has_calls(expected_calls)
|
||||
|
||||
mock_deployment_get.assert_called_once_with(fake_task["uuid"])
|
||||
|
||||
admin = user = mock_osclients.return_value
|
||||
admin = user = mock_clients.return_value
|
||||
fake_deployment = mock_deployment_get.return_value
|
||||
expected_calls = [
|
||||
mock.call(admin, user, "a", 0, fake_deployment, config["a"][0]),
|
||||
mock.call(admin, user, "a", 1, fake_deployment, config["a"][1]),
|
||||
mock.call(admin, user, "b", 0, fake_deployment, config["b"][0])
|
||||
]
|
||||
mock_helper.assert_has_calls(expected_calls, any_order=True)
|
||||
mock__validate_config_semantic_helper.assert_has_calls(
|
||||
expected_calls, any_order=True)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine.consume_results")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario")
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
def test_run__update_status(self, mock_runner, mock_scenario,
|
||||
mock_setup, mock_cleanup, mock_consume):
|
||||
def test_run__update_status(
|
||||
self, mock_scenario_runner, mock_scenario,
|
||||
mock_context_manager_setup, mock_context_manager_cleanup,
|
||||
mock_consume_results):
|
||||
task = mock.MagicMock()
|
||||
eng = engine.BenchmarkEngine([], task)
|
||||
eng.run()
|
||||
@@ -254,8 +262,10 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run__config_has_args(self, mock_setup, mock_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume):
|
||||
def test_run__config_has_args(
|
||||
self, mock_context_manager_setup, mock_context_manager_cleanup,
|
||||
mock_scenario_runner, mock_scenario,
|
||||
mock_consume_results):
|
||||
config = {
|
||||
"a.benchmark": [{"args": {"a": "a", "b": 1}}],
|
||||
"b.benchmark": [{"args": {"a": 1}}]
|
||||
@@ -269,8 +279,9 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run__config_has_runner(self, mock_setup, mock_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume):
|
||||
def test_run__config_has_runner(
|
||||
self, mock_context_manager_setup, mock_context_manager_cleanup,
|
||||
mock_scenario_runner, mock_scenario, mock_consume_results):
|
||||
config = {
|
||||
"a.benchmark": [{"runner": {"type": "a", "b": 1}}],
|
||||
"b.benchmark": [{"runner": {"type": "c", "a": 1}}]
|
||||
@@ -284,8 +295,9 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run__config_has_context(self, mock_ctx_setup, mock_ctx_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume):
|
||||
def test_run__config_has_context(
|
||||
self, mock_context_manager_setup, mock_context_manager_cleanup,
|
||||
mock_scenario_runner, mock_scenario, mock_consume_results):
|
||||
config = {
|
||||
"a.benchmark": [{"context": {"context_a": {"a": 1}}}],
|
||||
"b.benchmark": [{"context": {"context_b": {"b": 2}}}]
|
||||
@@ -300,11 +312,12 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
@mock.patch("rally.benchmark.engine.runner.ScenarioRunner")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.cleanup")
|
||||
@mock.patch("rally.benchmark.engine.context.ContextManager.setup")
|
||||
def test_run_exception_is_logged(self, mock_ctx_setup, mock_ctx_cleanup,
|
||||
mock_runner, mock_scenario, mock_consume,
|
||||
mock_log):
|
||||
def test_run_exception_is_logged(
|
||||
self, mock_context_manager_setup, mock_context_manager_cleanup,
|
||||
mock_scenario_runner, mock_scenario, mock_consume_results,
|
||||
mock_log):
|
||||
|
||||
mock_ctx_setup.side_effect = Exception
|
||||
mock_context_manager_setup.side_effect = Exception
|
||||
|
||||
config = {
|
||||
"a.benchmark": [{"context": {"context_a": {"a": 1}}}],
|
||||
@@ -317,9 +330,9 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
self.assertEqual(2, mock_log.exception.call_count)
|
||||
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario.meta")
|
||||
def test__prepare_context(self, mock_meta):
|
||||
def test__prepare_context(self, mock_scenario_meta):
|
||||
default_context = {"a": 1, "b": 2}
|
||||
mock_meta.return_value = default_context
|
||||
mock_scenario_meta.return_value = default_context
|
||||
task = mock.MagicMock()
|
||||
name = "a.benchmark"
|
||||
context = {"b": 3, "c": 4}
|
||||
@@ -339,11 +352,11 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
"config": expected_context
|
||||
}
|
||||
self.assertEqual(result, expected_result)
|
||||
mock_meta.assert_called_once_with(name, "context")
|
||||
mock_scenario_meta.assert_called_once_with(name, "context")
|
||||
|
||||
@mock.patch("rally.benchmark.engine.base_scenario.Scenario.meta")
|
||||
def test__prepare_context_with_existing_users(self, mock_meta):
|
||||
mock_meta.return_value = {}
|
||||
def test__prepare_context_with_existing_users(self, mock_scenario_meta):
|
||||
mock_scenario_meta.return_value = {}
|
||||
task = mock.MagicMock()
|
||||
name = "a.benchmark"
|
||||
context = {"b": 3, "c": 4}
|
||||
@@ -363,12 +376,12 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
"config": expected_context
|
||||
}
|
||||
self.assertEqual(result, expected_result)
|
||||
mock_meta.assert_called_once_with(name, "context")
|
||||
mock_scenario_meta.assert_called_once_with(name, "context")
|
||||
|
||||
@mock.patch("rally.benchmark.sla.SLAChecker")
|
||||
def test_consume_results(self, mock_sla):
|
||||
def test_consume_results(self, mock_sla_checker):
|
||||
mock_sla_instance = mock.MagicMock()
|
||||
mock_sla.return_value = mock_sla_instance
|
||||
mock_sla_checker.return_value = mock_sla_instance
|
||||
key = {"kw": {"fake": 2}, "name": "fake", "pos": 0}
|
||||
task = mock.MagicMock()
|
||||
config = {
|
||||
@@ -382,15 +395,15 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
eng.duration = 123
|
||||
eng.full_duration = 456
|
||||
eng.consume_results(key, task, is_done, {}, runner)
|
||||
mock_sla.assert_called_once_with({"fake": 2})
|
||||
mock_sla_checker.assert_called_once_with({"fake": 2})
|
||||
expected_iteration_calls = [mock.call(1), mock.call(2)]
|
||||
self.assertEqual(expected_iteration_calls,
|
||||
mock_sla_instance.add_iteration.mock_calls)
|
||||
|
||||
@mock.patch("rally.benchmark.sla.SLAChecker")
|
||||
def test_consume_results_sla_failure_abort(self, mock_sla):
|
||||
def test_consume_results_sla_failure_abort(self, mock_sla_checker):
|
||||
mock_sla_instance = mock.MagicMock()
|
||||
mock_sla.return_value = mock_sla_instance
|
||||
mock_sla_checker.return_value = mock_sla_instance
|
||||
mock_sla_instance.add_iteration.side_effect = [True, True, False,
|
||||
False]
|
||||
key = {"kw": {"fake": 2}, "name": "fake", "pos": 0}
|
||||
@@ -406,13 +419,13 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
eng.duration = 123
|
||||
eng.full_duration = 456
|
||||
eng.consume_results(key, task, is_done, {}, runner)
|
||||
mock_sla.assert_called_once_with({"fake": 2})
|
||||
mock_sla_checker.assert_called_once_with({"fake": 2})
|
||||
self.assertTrue(runner.abort.called)
|
||||
|
||||
@mock.patch("rally.benchmark.sla.SLAChecker")
|
||||
def test_consume_results_sla_failure_continue(self, mock_sla):
|
||||
def test_consume_results_sla_failure_continue(self, mock_sla_checker):
|
||||
mock_sla_instance = mock.MagicMock()
|
||||
mock_sla.return_value = mock_sla_instance
|
||||
mock_sla_checker.return_value = mock_sla_instance
|
||||
mock_sla_instance.add_iteration.side_effect = [True, True, False,
|
||||
False]
|
||||
key = {"kw": {"fake": 2}, "name": "fake", "pos": 0}
|
||||
@@ -428,5 +441,5 @@ class BenchmarkEngineTestCase(test.TestCase):
|
||||
eng.duration = 123
|
||||
eng.full_duration = 456
|
||||
eng.consume_results(key, task, is_done, {}, runner)
|
||||
mock_sla.assert_called_once_with({"fake": 2})
|
||||
mock_sla_checker.assert_called_once_with({"fake": 2})
|
||||
self.assertEqual(0, runner.abort.call_count)
|
||||
|
@@ -48,7 +48,7 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
mock_format_exc.assert_called_once_with(mock_exc)
|
||||
|
||||
@mock.patch(BASE + "random.choice", side_effect=lambda x: x[1])
|
||||
def test_get_scenario_context(self, mock_random):
|
||||
def test_get_scenario_context(self, mock_choice):
|
||||
|
||||
users = []
|
||||
tenants = {}
|
||||
@@ -80,8 +80,8 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
runner._get_scenario_context(context))
|
||||
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_internal_logic(self, mock_clients):
|
||||
mock_clients.Clients.return_value = "cl"
|
||||
def test_run_scenario_once_internal_logic(self, mock_osclients):
|
||||
mock_osclients.Clients.return_value = "cl"
|
||||
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
@@ -100,8 +100,8 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_without_scenario_output(self, mock_clients,
|
||||
mock_rtimer):
|
||||
def test_run_scenario_once_without_scenario_output(self, mock_osclients,
|
||||
mock_timer):
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
args = (1, fakes.FakeScenario, "do_it", context, {})
|
||||
@@ -119,8 +119,8 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_with_scenario_output(self, mock_clients,
|
||||
mock_rtimer):
|
||||
def test_run_scenario_once_with_scenario_output(self, mock_osclients,
|
||||
mock_timer):
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
args = (1, fakes.FakeScenario, "with_output", context, {})
|
||||
@@ -138,7 +138,7 @@ class ScenarioHelpersTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(BASE + "rutils.Timer", side_effect=fakes.FakeTimer)
|
||||
@mock.patch(BASE + "osclients")
|
||||
def test_run_scenario_once_exception(self, mock_clients, mock_rtimer):
|
||||
def test_run_scenario_once_exception(self, mock_osclients, mock_timer):
|
||||
context = runner._get_scenario_context(
|
||||
fakes.FakeUserContext({}).context)
|
||||
args = (1, fakes.FakeScenario, "something_went_wrong", context, {})
|
||||
@@ -194,7 +194,7 @@ class ScenarioRunnerResultTestCase(test.TestCase):
|
||||
class ScenarioRunnerTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(BASE + "rutils.Timer.duration", return_value=10)
|
||||
def test_run(self, mock_duration):
|
||||
def test_run(self, mock_timer_duration):
|
||||
runner_obj = serial.SerialScenarioRunner(
|
||||
mock.MagicMock(),
|
||||
mock.MagicMock())
|
||||
@@ -215,7 +215,7 @@ class ScenarioRunnerTestCase(test.TestCase):
|
||||
|
||||
result = runner_obj.run(scenario_name, context_obj, config_kwargs)
|
||||
|
||||
self.assertEqual(result, mock_duration.return_value)
|
||||
self.assertEqual(result, mock_timer_duration.return_value)
|
||||
self.assertEqual(list(runner_obj.result_queue), [])
|
||||
|
||||
cls_name, method_name = scenario_name.split(".", 1)
|
||||
@@ -260,7 +260,7 @@ class ScenarioRunnerTestCase(test.TestCase):
|
||||
self.assertIsInstance(process, multiprocessing.Process)
|
||||
|
||||
@mock.patch(BASE + "ScenarioRunner._send_result")
|
||||
def test__join_processes(self, mock_send_result):
|
||||
def test__join_processes(self, mock_scenario_runner__send_result):
|
||||
process = mock.MagicMock(is_alive=mock.MagicMock(return_value=False))
|
||||
processes = 10
|
||||
process_pool = collections.deque([process] * processes)
|
||||
|
@@ -336,7 +336,7 @@ class PreprocessTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.types.base.Scenario.meta")
|
||||
@mock.patch("rally.benchmark.types.osclients")
|
||||
def test_preprocess(self, mock_osclients, mock_meta):
|
||||
def test_preprocess(self, mock_osclients, mock_scenario_meta):
|
||||
cls = "some_class"
|
||||
method_name = "method_name"
|
||||
context = {
|
||||
@@ -352,11 +352,11 @@ class PreprocessTestCase(test.TestCase):
|
||||
def transform(cls, clients, resource_config):
|
||||
return resource_config * 2
|
||||
|
||||
mock_meta.return_value = {"a": Preprocessor}
|
||||
mock_scenario_meta.return_value = {"a": Preprocessor}
|
||||
result = types.preprocess(cls, method_name, context, args)
|
||||
mock_meta.assert_called_once_with(cls, default={},
|
||||
method_name=method_name,
|
||||
attr_name="preprocessors")
|
||||
mock_scenario_meta.assert_called_once_with(
|
||||
cls, default={}, method_name=method_name,
|
||||
attr_name="preprocessors")
|
||||
mock_osclients.Clients.assert_called_once_with(
|
||||
context["admin"]["endpoint"])
|
||||
self.assertEqual({"a": 20, "b": 20}, result)
|
||||
|
@@ -232,9 +232,9 @@ class ValidatorsTestCase(test.TestCase):
|
||||
self.assertTrue(result[0].is_valid, result[0].msg)
|
||||
self.assertEqual(result[1], image)
|
||||
|
||||
@mock.patch(MODULE + "types.ImageResourceType.transform")
|
||||
def test__get_validated_image(self, mock_transform):
|
||||
mock_transform.return_value = "image_id"
|
||||
@mock.patch(MODULE + "types.ImageResourceType.transform",
|
||||
return_value="image_id")
|
||||
def test__get_validated_image(self, mock_image_resource_type_transform):
|
||||
clients = mock.MagicMock()
|
||||
clients.glance().images.get().to_dict.return_value = {
|
||||
"image": "image_id"}
|
||||
@@ -245,19 +245,21 @@ class ValidatorsTestCase(test.TestCase):
|
||||
clients, "a")
|
||||
self.assertTrue(result[0].is_valid, result[0].msg)
|
||||
self.assertEqual(result[1], {"image": "image_id"})
|
||||
mock_transform.assert_called_once_with(clients=clients,
|
||||
resource_config="test")
|
||||
mock_image_resource_type_transform.assert_called_once_with(
|
||||
clients=clients, resource_config="test")
|
||||
clients.glance().images.get.assert_called_with(image="image_id")
|
||||
|
||||
@mock.patch(MODULE + "types.ImageResourceType.transform")
|
||||
def test__get_validated_image_transform_error(self, mock_transform):
|
||||
mock_transform.side_effect = exceptions.InvalidScenarioArgument
|
||||
@mock.patch(MODULE + "types.ImageResourceType.transform",
|
||||
side_effect=exceptions.InvalidScenarioArgument)
|
||||
def test__get_validated_image_transform_error(
|
||||
self, mock_image_resource_type_transform):
|
||||
result = validation._get_validated_image({"args": {"a": "test"}},
|
||||
None, "a")
|
||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||
|
||||
@mock.patch(MODULE + "types.ImageResourceType.transform")
|
||||
def test__get_validated_image_not_found(self, mock_transform):
|
||||
def test__get_validated_image_not_found(
|
||||
self, mock_image_resource_type_transform):
|
||||
clients = mock.MagicMock()
|
||||
clients.glance().images.get().to_dict.side_effect = (
|
||||
glance_exc.HTTPNotFound(""))
|
||||
@@ -269,9 +271,10 @@ class ValidatorsTestCase(test.TestCase):
|
||||
result = validation._get_validated_flavor({}, None, "non_existing")
|
||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
||||
def test__get_validated_flavor(self, mock_transform):
|
||||
mock_transform.return_value = "flavor_id"
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform",
|
||||
return_value="flavor_id")
|
||||
def test__get_validated_flavor(
|
||||
self, mock_flavor_resource_type_transform):
|
||||
clients = mock.MagicMock()
|
||||
clients.nova().flavors.get.return_value = "flavor"
|
||||
|
||||
@@ -279,19 +282,21 @@ class ValidatorsTestCase(test.TestCase):
|
||||
clients, "a")
|
||||
self.assertTrue(result[0].is_valid, result[0].msg)
|
||||
self.assertEqual(result[1], "flavor")
|
||||
mock_transform.assert_called_once_with(clients=clients,
|
||||
resource_config="test")
|
||||
mock_flavor_resource_type_transform.assert_called_once_with(
|
||||
clients=clients, resource_config="test")
|
||||
clients.nova().flavors.get.assert_called_once_with(flavor="flavor_id")
|
||||
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
||||
def test__get_validated_flavor_transform_error(self, mock_transform):
|
||||
mock_transform.side_effect = exceptions.InvalidScenarioArgument
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform",
|
||||
side_effect=exceptions.InvalidScenarioArgument)
|
||||
def test__get_validated_flavor_transform_error(
|
||||
self, mock_flavor_resource_type_transform):
|
||||
result = validation._get_validated_flavor({"args": {"a": "test"}},
|
||||
None, "a")
|
||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
||||
def test__get_validated_flavor_not_found(self, mock_transform):
|
||||
def test__get_validated_flavor_not_found(
|
||||
self, mock_flavor_resource_type_transform):
|
||||
clients = mock.MagicMock()
|
||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||
result = validation._get_validated_flavor({"args": {"a": "test"}},
|
||||
@@ -299,7 +304,8 @@ class ValidatorsTestCase(test.TestCase):
|
||||
self.assertFalse(result[0].is_valid, result[0].msg)
|
||||
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
||||
def test__get_validated_flavor_from_context(self, mock_transform):
|
||||
def test__get_validated_flavor_from_context(
|
||||
self, mock_flavor_resource_type_transform):
|
||||
clients = mock.MagicMock()
|
||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||
config = {
|
||||
@@ -315,7 +321,8 @@ class ValidatorsTestCase(test.TestCase):
|
||||
self.assertTrue(result[0].is_valid, result[0].msg)
|
||||
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
||||
def test__get_validated_flavor_from_context_failed(self, mock_transform):
|
||||
def test__get_validated_flavor_from_context_failed(
|
||||
self, mock_flavor_resource_type_transform):
|
||||
clients = mock.MagicMock()
|
||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||
config = {
|
||||
@@ -364,7 +371,8 @@ class ValidatorsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MODULE + "_get_validated_image")
|
||||
@mock.patch(MODULE + "_get_validated_flavor")
|
||||
def test_image_valid_on_flavor(self, mock_get_flavor, mock_get_image):
|
||||
def test_image_valid_on_flavor(self, mock__get_validated_flavor,
|
||||
mock__get_validated_image):
|
||||
image = {
|
||||
"id": "fake_id",
|
||||
"min_ram": None,
|
||||
@@ -373,8 +381,8 @@ class ValidatorsTestCase(test.TestCase):
|
||||
}
|
||||
flavor = mock.MagicMock()
|
||||
success = validation.ValidationResult(True)
|
||||
mock_get_flavor.return_value = (success, flavor)
|
||||
mock_get_image.return_value = (success, image)
|
||||
mock__get_validated_flavor.return_value = (success, flavor)
|
||||
mock__get_validated_image.return_value = (success, image)
|
||||
|
||||
validator = self._unwrap_validator(validation.image_valid_on_flavor,
|
||||
"flavor", "image")
|
||||
@@ -407,14 +415,15 @@ class ValidatorsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MODULE + "types.FlavorResourceType.transform")
|
||||
@mock.patch(MODULE + "_get_validated_image")
|
||||
def test_image_valid_on_flavor_context(self, mock_get_image,
|
||||
mock_transform):
|
||||
def test_image_valid_on_flavor_context(
|
||||
self, mock__get_validated_image,
|
||||
mock_flavor_resource_type_transform):
|
||||
clients = mock.MagicMock()
|
||||
clients.nova().flavors.get.side_effect = nova_exc.NotFound("")
|
||||
|
||||
image = {"min_ram": 24, "id": "fake_id"}
|
||||
success = validation.ValidationResult(True)
|
||||
mock_get_image.return_value = (success, image)
|
||||
mock__get_validated_image.return_value = (success, image)
|
||||
|
||||
validator = self._unwrap_validator(validation.image_valid_on_flavor,
|
||||
"flavor", "image")
|
||||
@@ -683,7 +692,7 @@ class ValidatorsTestCase(test.TestCase):
|
||||
self.assertFalse(result.is_valid, result.msg)
|
||||
|
||||
@mock.patch(MODULE + "osclients")
|
||||
def test_required_clients(self, mock_clients):
|
||||
def test_required_clients(self, mock_osclients):
|
||||
validator = self._unwrap_validator(validation.required_clients,
|
||||
"keystone", "nova")
|
||||
clients = mock.MagicMock()
|
||||
@@ -691,7 +700,7 @@ class ValidatorsTestCase(test.TestCase):
|
||||
clients.nova.return_value = "nova"
|
||||
result = validator({}, clients, {})
|
||||
self.assertTrue(result.is_valid, result.msg)
|
||||
self.assertFalse(mock_clients.Clients.called)
|
||||
self.assertFalse(mock_osclients.Clients.called)
|
||||
|
||||
clients.nova.side_effect = ImportError
|
||||
result = validator({}, clients, {})
|
||||
@@ -699,18 +708,18 @@ class ValidatorsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MODULE + "objects")
|
||||
@mock.patch(MODULE + "osclients")
|
||||
def test_required_clients_with_admin(self, mock_clients, mock_objects):
|
||||
def test_required_clients_with_admin(self, mock_osclients, mock_objects):
|
||||
validator = self._unwrap_validator(validation.required_clients,
|
||||
"keystone", "nova", admin=True)
|
||||
clients = mock.Mock()
|
||||
clients.keystone.return_value = "keystone"
|
||||
clients.nova.return_value = "nova"
|
||||
mock_clients.Clients.return_value = clients
|
||||
mock_osclients.Clients.return_value = clients
|
||||
mock_objects.Endpoint.return_value = "foo_endpoint"
|
||||
result = validator({}, clients, {"admin": {"foo": "bar"}})
|
||||
self.assertTrue(result.is_valid, result.msg)
|
||||
mock_objects.Endpoint.assert_called_once_with(foo="bar")
|
||||
mock_clients.Clients.assert_called_once_with("foo_endpoint")
|
||||
mock_osclients.Clients.assert_called_once_with("foo_endpoint")
|
||||
clients.nova.side_effect = ImportError
|
||||
result = validator({}, clients, {"admin": {"foo": "bar"}})
|
||||
self.assertFalse(result.is_valid, result.msg)
|
||||
|
@@ -35,11 +35,13 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.deployment.DeploymentCommands.list")
|
||||
@mock.patch("rally.cli.commands.deployment.api.Deployment.create")
|
||||
@mock.patch("rally.cli.commands.deployment.open",
|
||||
mock.mock_open(read_data="{\"some\": \"json\"}"),
|
||||
side_effect=mock.mock_open(read_data="{\"some\": \"json\"}"),
|
||||
create=True)
|
||||
def test_create(self, mock_create, mock_list):
|
||||
def test_create(self, mock_open, mock_deployment_create,
|
||||
mock_deployment_commands_list):
|
||||
self.deployment.create("fake_deploy", False, "path_to_config.json")
|
||||
mock_create.assert_called_once_with({"some": "json"}, "fake_deploy")
|
||||
mock_deployment_create.assert_called_once_with(
|
||||
{"some": "json"}, "fake_deploy")
|
||||
|
||||
@mock.patch.dict(os.environ, {"OS_AUTH_URL": "fake_auth_url",
|
||||
"OS_USERNAME": "fake_username",
|
||||
@@ -50,9 +52,9 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
"RALLY_DEPLOYMENT": "fake_deployment_id"})
|
||||
@mock.patch("rally.cli.commands.deployment.api.Deployment.create")
|
||||
@mock.patch("rally.cli.commands.deployment.DeploymentCommands.list")
|
||||
def test_createfromenv(self, mock_list, mock_create):
|
||||
def test_createfromenv(self, mock_list, mock_deployment_create):
|
||||
self.deployment.create("from_env", True)
|
||||
mock_create.assert_called_once_with(
|
||||
mock_deployment_create.assert_called_once_with(
|
||||
{
|
||||
"type": "ExistingCloud",
|
||||
"auth_url": "fake_auth_url",
|
||||
@@ -72,36 +74,38 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.deployment.api.Deployment.create",
|
||||
return_value=dict(uuid="uuid"))
|
||||
@mock.patch("rally.cli.commands.deployment.open",
|
||||
mock.mock_open(read_data="{\"uuid\": \"uuid\"}"),
|
||||
side_effect=mock.mock_open(read_data="{\"uuid\": \"uuid\"}"),
|
||||
create=True)
|
||||
def test_create_and_use(self, mock_create, mock_use_deployment,
|
||||
mock_list):
|
||||
def test_create_and_use(self, mock_open, mock_deployment_create,
|
||||
mock_deployment_commands_use,
|
||||
mock_deployment_commands_list):
|
||||
self.deployment.create("fake_deploy", False, "path_to_config.json",
|
||||
True)
|
||||
mock_create.assert_called_once_with({"uuid": "uuid"}, "fake_deploy")
|
||||
mock_use_deployment.assert_called_once_with("uuid")
|
||||
mock_deployment_create.assert_called_once_with(
|
||||
{"uuid": "uuid"}, "fake_deploy")
|
||||
mock_deployment_commands_use.assert_called_once_with("uuid")
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.api.Deployment.recreate")
|
||||
def test_recreate(self, mock_recreate):
|
||||
def test_recreate(self, mock_deployment_recreate):
|
||||
deployment_id = "43924f8b-9371-4152-af9f-4cf02b4eced4"
|
||||
self.deployment.recreate(deployment_id)
|
||||
mock_recreate.assert_called_once_with(deployment_id)
|
||||
mock_deployment_recreate.assert_called_once_with(deployment_id)
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.envutils.get_global")
|
||||
def test_recreate_no_deployment_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_recreate_no_deployment_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.deployment.recreate, None)
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.api.Deployment.destroy")
|
||||
def test_destroy(self, mock_destroy):
|
||||
def test_destroy(self, mock_deployment_destroy):
|
||||
deployment_id = "53fd0273-60ce-42e5-a759-36f1a683103e"
|
||||
self.deployment.destroy(deployment_id)
|
||||
mock_destroy.assert_called_once_with(deployment_id)
|
||||
mock_deployment_destroy.assert_called_once_with(deployment_id)
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.envutils.get_global")
|
||||
def test_destroy_no_deployment_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_destroy_no_deployment_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.deployment.destroy, None)
|
||||
|
||||
@@ -109,11 +113,11 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.deployment.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.deployment.envutils.get_global")
|
||||
@mock.patch("rally.cli.commands.deployment.db.deployment_list")
|
||||
def test_list_different_deployment_id(self, mock_deployments,
|
||||
mock_default, mock_struct,
|
||||
def test_list_different_deployment_id(self, mock_deployment_list,
|
||||
mock_get_global, mock_struct,
|
||||
mock_print_list):
|
||||
current_deployment_id = "26a3ce76-0efa-40e4-86e5-514574bd1ff6"
|
||||
mock_default.return_value = current_deployment_id
|
||||
mock_get_global.return_value = current_deployment_id
|
||||
fake_deployment_list = [
|
||||
{"uuid": "fa34aea2-ae2e-4cf7-a072-b08d67466e3e",
|
||||
"created_at": "03-12-2014",
|
||||
@@ -121,7 +125,7 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
"status": "deploy->started",
|
||||
"active": "False"}]
|
||||
|
||||
mock_deployments.return_value = fake_deployment_list
|
||||
mock_deployment_list.return_value = fake_deployment_list
|
||||
self.deployment.list()
|
||||
|
||||
fake_deployment = fake_deployment_list[0]
|
||||
@@ -137,17 +141,17 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.deployment.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.deployment.envutils.get_global")
|
||||
@mock.patch("rally.cli.commands.deployment.db.deployment_list")
|
||||
def test_list_current_deployment_id(self, mock_deployments,
|
||||
mock_default, mock_struct,
|
||||
def test_list_current_deployment_id(self, mock_deployment_list,
|
||||
mock_get_global, mock_struct,
|
||||
mock_print_list):
|
||||
current_deployment_id = "64258e84-ffa1-4011-9e4c-aba07bdbcc6b"
|
||||
mock_default.return_value = current_deployment_id
|
||||
mock_get_global.return_value = current_deployment_id
|
||||
fake_deployment_list = [{"uuid": current_deployment_id,
|
||||
"created_at": "13-12-2014",
|
||||
"name": "dep2",
|
||||
"status": "deploy->finished",
|
||||
"active": "True"}]
|
||||
mock_deployments.return_value = fake_deployment_list
|
||||
mock_deployment_list.return_value = fake_deployment_list
|
||||
self.deployment.list()
|
||||
|
||||
fake_deployment = fake_deployment_list[0]
|
||||
@@ -161,25 +165,25 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.db.deployment_get")
|
||||
@mock.patch("json.dumps")
|
||||
def test_config(self, mock_json_dumps, mock_deployment):
|
||||
def test_config(self, mock_json_dumps, mock_deployment_get):
|
||||
deployment_id = "fa4a423e-f15d-4d83-971a-89574f892999"
|
||||
value = {"config": "config"}
|
||||
mock_deployment.return_value = value
|
||||
mock_deployment_get.return_value = value
|
||||
self.deployment.config(deployment_id)
|
||||
mock_json_dumps.assert_called_once_with(value["config"],
|
||||
sort_keys=True, indent=4)
|
||||
mock_deployment.assert_called_once_with(deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(deployment_id)
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.envutils.get_global")
|
||||
def test_config_no_deployment_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_config_no_deployment_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.deployment.config, None)
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.cliutils.print_list")
|
||||
@mock.patch("rally.cli.commands.deployment.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.deployment.db.deployment_get")
|
||||
def test_show(self, mock_deployment, mock_struct, mock_print_list):
|
||||
def test_show(self, mock_deployment_get, mock_struct, mock_print_list):
|
||||
deployment_id = "b1a6153e-a314-4cb3-b63b-cf08c1a416c3"
|
||||
value = {
|
||||
"admin": {
|
||||
@@ -192,9 +196,9 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
},
|
||||
"users": []
|
||||
}
|
||||
mock_deployment.return_value = value
|
||||
mock_deployment_get.return_value = value
|
||||
self.deployment.show(deployment_id)
|
||||
mock_deployment.assert_called_once_with(deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(deployment_id)
|
||||
|
||||
headers = ["auth_url", "username", "password", "tenant_name",
|
||||
"region_name", "endpoint_type"]
|
||||
@@ -203,8 +207,8 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
mock_print_list.assert_called_once_with([mock_struct()], headers)
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.envutils.get_global")
|
||||
def test_deploy_no_deployment_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_deploy_no_deployment_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.deployment.show, None)
|
||||
|
||||
@@ -215,11 +219,11 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
uuid="593b683c-4b16-4b2b-a56b-e162bd60f10b"))
|
||||
@mock.patch("os.path.exists", return_value=True)
|
||||
@mock.patch("rally.common.fileutils.update_env_file")
|
||||
def test_use(self, mock_env, mock_path, mock_deployment,
|
||||
mock_symlink, mock_remove):
|
||||
deployment_id = mock_deployment.return_value["uuid"]
|
||||
def test_use(self, mock_update_env_file, mock_path_exists,
|
||||
mock_deployment_get, mock_symlink, mock_remove):
|
||||
deployment_id = mock_deployment_get.return_value["uuid"]
|
||||
|
||||
mock_deployment.return_value["admin"] = {
|
||||
mock_deployment_get.return_value["admin"] = {
|
||||
"auth_url": "fake_auth_url",
|
||||
"username": "fake_username",
|
||||
"password": "fake_password",
|
||||
@@ -230,8 +234,8 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
with mock.patch("rally.cli.commands.deployment.open", mock.mock_open(),
|
||||
create=True) as mock_file:
|
||||
self.deployment.use(deployment_id)
|
||||
self.assertEqual(2, mock_path.call_count)
|
||||
mock_env.assert_called_once_with(os.path.expanduser(
|
||||
self.assertEqual(2, mock_path_exists.call_count)
|
||||
mock_update_env_file.assert_called_once_with(os.path.expanduser(
|
||||
"~/.rally/globals"),
|
||||
"RALLY_DEPLOYMENT", "%s\n" % deployment_id)
|
||||
mock_file.return_value.write.assert_any_call(
|
||||
@@ -251,8 +255,8 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
"_update_openrc_deployment_file")
|
||||
@mock.patch("rally.common.fileutils.update_globals_file")
|
||||
@mock.patch("rally.cli.commands.deployment.db")
|
||||
def test_use_by_name(self, mock_db, mock_update_openrc,
|
||||
mock_update_globals):
|
||||
def test_use_by_name(self, mock_db, mock_update_globals_file,
|
||||
mock__update_openrc_deployment_file):
|
||||
fake_deployment = fakes.FakeDeployment(
|
||||
uuid="fake_uuid",
|
||||
admin="fake_endpoints")
|
||||
@@ -261,9 +265,9 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
status = self.deployment.use(deployment="fake_name")
|
||||
self.assertIsNone(status)
|
||||
mock_db.deployment_get.assert_called_once_with("fake_name")
|
||||
mock_update_openrc.assert_called_once_with(
|
||||
mock_update_globals_file.assert_called_once_with(
|
||||
envutils.ENV_DEPLOYMENT, "fake_uuid")
|
||||
mock_update_globals.assert_called_once_with(
|
||||
mock__update_openrc_deployment_file.assert_called_once_with(
|
||||
"fake_uuid", "fake_endpoints")
|
||||
|
||||
@mock.patch("rally.cli.commands.deployment.db.deployment_get")
|
||||
@@ -276,8 +280,8 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.osclients.Clients.verified_keystone")
|
||||
@mock.patch("rally.osclients.Clients.keystone")
|
||||
@mock.patch("rally.cli.commands.deployment.db.deployment_get")
|
||||
def test_deployment_check(self, mock_deployment_get, mock_keystone,
|
||||
mock_verified_keystone):
|
||||
def test_deployment_check(self, mock_deployment_get, mock_clients_keystone,
|
||||
mock_clients_verified_keystone):
|
||||
deployment_id = "e87e4dca-b515-4477-888d-5f6103f13b42"
|
||||
sample_endpoint = objects.Endpoint("http://192.168.1.1:5000/v2.0/",
|
||||
"admin",
|
||||
@@ -286,17 +290,18 @@ class DeploymentCommandsTestCase(test.TestCase):
|
||||
"users": [sample_endpoint]}
|
||||
self.deployment.check(deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(deployment_id)
|
||||
mock_keystone.assert_called_once_with()
|
||||
mock_verified_keystone.assert_called_once_with()
|
||||
mock_clients_keystone.assert_called_once_with()
|
||||
mock_clients_verified_keystone.assert_called_once_with()
|
||||
|
||||
@mock.patch("rally.osclients.Clients.verified_keystone")
|
||||
@mock.patch("rally.cli.commands.deployment.db.deployment_get")
|
||||
def test_deployment_check_raise(self, mock_deployment_get, mock_client):
|
||||
def test_deployment_check_raise(self, mock_deployment_get,
|
||||
mock_clients_verified_keystone):
|
||||
deployment_id = "e87e4dca-b515-4477-888d-5f6103f13b42"
|
||||
sample_endpoint = objects.Endpoint("http://192.168.1.1:5000/v2.0/",
|
||||
"admin",
|
||||
"adminpass").to_dict()
|
||||
sample_endpoint["not-exist-key"] = "error"
|
||||
mock_deployment_get.return_value = {"admin": sample_endpoint}
|
||||
mock_client.services.list.return_value = []
|
||||
mock_clients_verified_keystone.services.list.return_value = []
|
||||
self.assertRaises(TypeError, self.deployment.check, deployment_id)
|
||||
|
@@ -44,62 +44,62 @@ class InfoCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SCENARIO + ".get_by_name",
|
||||
return_value=dummy.Dummy)
|
||||
def test_find_dummy_scenario_group(self, mock_get):
|
||||
def test_find_dummy_scenario_group(self, mock_scenario_get_by_name):
|
||||
query = "Dummy"
|
||||
status = self.info.find(query)
|
||||
mock_get.assert_called_once_with(query)
|
||||
mock_scenario_get_by_name.assert_called_once_with(query)
|
||||
self.assertIsNone(status)
|
||||
|
||||
@mock.patch(SCENARIO + ".get_scenario_by_name",
|
||||
return_value=dummy.Dummy.dummy)
|
||||
def test_find_dummy_scenario(self, mock_get_scenario_by_name):
|
||||
def test_find_dummy_scenario(self, mock_scenario_get_scenario_by_name):
|
||||
query = "Dummy.dummy"
|
||||
status = self.info.find(query)
|
||||
mock_get_scenario_by_name.assert_called_once_with(query)
|
||||
mock_scenario_get_scenario_by_name.assert_called_once_with(query)
|
||||
self.assertIsNone(status)
|
||||
|
||||
@mock.patch(SCENARIO + ".get_scenario_by_name",
|
||||
side_effect=exceptions.NoSuchScenario)
|
||||
def test_find_failure_status(self, mock_get_scenario_by_name):
|
||||
def test_find_failure_status(self, mock_scenario_get_scenario_by_name):
|
||||
query = "Dummy.non_existing"
|
||||
status = self.info.find(query)
|
||||
mock_get_scenario_by_name.assert_called_once_with(query)
|
||||
mock_scenario_get_scenario_by_name.assert_called_once_with(query)
|
||||
self.assertEqual(1, status)
|
||||
|
||||
@mock.patch(SLA + ".get", return_value=failure_rate.FailureRate)
|
||||
def test_find_failure_rate_sla(self, mock_get):
|
||||
def test_find_failure_rate_sla(self, mock_sla_get):
|
||||
query = "failure_rate"
|
||||
status = self.info.find(query)
|
||||
mock_get.assert_called_once_with(query)
|
||||
mock_sla_get.assert_called_once_with(query)
|
||||
self.assertIsNone(status)
|
||||
|
||||
@mock.patch(ENGINE + ".get",
|
||||
return_value=existing_cloud.ExistingCloud)
|
||||
def test_find_existing_cloud(self, mock_get):
|
||||
def test_find_existing_cloud(self, mock_engine_factory_get):
|
||||
query = "ExistingCloud"
|
||||
status = self.info.find(query)
|
||||
mock_get.assert_called_once_with(query)
|
||||
mock_engine_factory_get.assert_called_once_with(query)
|
||||
self.assertIsNone(status)
|
||||
|
||||
@mock.patch(PROVIDER + ".get",
|
||||
return_value=existing_servers.ExistingServers)
|
||||
def test_find_existing_servers(self, mock_get):
|
||||
def test_find_existing_servers(self, mock_provider_factory_get):
|
||||
query = "ExistingServers"
|
||||
status = self.info.find(query)
|
||||
mock_get.assert_called_once_with(query)
|
||||
mock_provider_factory_get.assert_called_once_with(query)
|
||||
self.assertIsNone(status)
|
||||
|
||||
@mock.patch(COMMANDS + ".ServerProviders")
|
||||
@mock.patch(COMMANDS + ".DeploymentEngines")
|
||||
@mock.patch(COMMANDS + ".SLA")
|
||||
@mock.patch(COMMANDS + ".BenchmarkScenarios")
|
||||
def test_list(self, mock_BenchmarkScenarios, mock_SLA,
|
||||
mock_DeploymentEngines, mock_ServerProviders):
|
||||
def test_list(self, mock_benchmark_scenarios, mock_sla,
|
||||
mock_deployment_engines, mock_server_providers):
|
||||
status = self.info.list()
|
||||
mock_BenchmarkScenarios.assert_called_once_with()
|
||||
mock_SLA.assert_called_once_with()
|
||||
mock_DeploymentEngines.assert_called_once_with()
|
||||
mock_ServerProviders.assert_called_once_with()
|
||||
mock_benchmark_scenarios.assert_called_once_with()
|
||||
mock_sla.assert_called_once_with()
|
||||
mock_deployment_engines.assert_called_once_with()
|
||||
mock_server_providers.assert_called_once_with()
|
||||
self.assertIsNone(status)
|
||||
|
||||
@mock.patch(DISCOVER + ".itersubclasses", return_value=[dummy.Dummy])
|
||||
|
@@ -49,12 +49,13 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.show.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.show.osclients.Clients.glance")
|
||||
@mock.patch("rally.cli.commands.show.db.deployment_get")
|
||||
def test_images(self, mock_deployment_get, mock_get_glance,
|
||||
mock_struct, mock_formatter, mock_print_list, mock_print):
|
||||
def test_images(self, mock_deployment_get, mock_clients_glance,
|
||||
mock_struct, mock_pretty_float_formatter,
|
||||
mock_print_list, mock_print):
|
||||
self.fake_glance_client.images.create("image", None, None, None)
|
||||
fake_image = list(self.fake_glance_client.images.cache.values())[0]
|
||||
fake_image.size = 1
|
||||
mock_get_glance.return_value = self.fake_glance_client
|
||||
mock_clients_glance.return_value = self.fake_glance_client
|
||||
mock_deployment_get.return_value = {
|
||||
"admin": self.admin_endpoint,
|
||||
"users": [self.user_endpoints, self.user_endpoints]
|
||||
@@ -63,8 +64,8 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
self.show.images(self.fake_deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(self.fake_deployment_id)
|
||||
|
||||
mock_get_glance.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_get_glance.call_count)
|
||||
mock_clients_glance.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_clients_glance.call_count)
|
||||
|
||||
headers = ["UUID", "Name", "Size (B)"]
|
||||
fake_data = dict(
|
||||
@@ -72,7 +73,7 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
)
|
||||
mock_struct.assert_has_calls([mock.call(**fake_data)] * 3)
|
||||
|
||||
fake_formatters = {"Size (B)": mock_formatter()}
|
||||
fake_formatters = {"Size (B)": mock_pretty_float_formatter()}
|
||||
mixed_case_fields = ["UUID", "Name"]
|
||||
mock_print_list.assert_has_calls([mock.call(
|
||||
[mock_struct()],
|
||||
@@ -87,21 +88,22 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.show.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.show.osclients.Clients.nova")
|
||||
@mock.patch("rally.cli.commands.show.db.deployment_get")
|
||||
def test_flavors(self, mock_deployment_get, mock_get_nova,
|
||||
mock_struct, mock_formatter, mock_print_list):
|
||||
def test_flavors(self, mock_deployment_get, mock_clients_nova,
|
||||
mock_struct, mock_pretty_float_formatter,
|
||||
mock_print_list):
|
||||
self.fake_nova_client.flavors.create()
|
||||
fake_flavor = list(self.fake_nova_client.flavors.cache.values())[0]
|
||||
fake_flavor.id, fake_flavor.name, fake_flavor.vcpus = 1, "m1.fake", 1
|
||||
fake_flavor.ram, fake_flavor.swap, fake_flavor.disk = 1024, 128, 10
|
||||
mock_get_nova.return_value = self.fake_nova_client
|
||||
mock_clients_nova.return_value = self.fake_nova_client
|
||||
mock_deployment_get.return_value = {
|
||||
"admin": self.admin_endpoint,
|
||||
"users": [self.user_endpoints, self.user_endpoints]
|
||||
}
|
||||
self.show.flavors(self.fake_deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(self.fake_deployment_id)
|
||||
mock_get_nova.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_get_nova.call_count)
|
||||
mock_clients_nova.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_clients_nova.call_count)
|
||||
|
||||
headers = ["ID", "Name", "vCPUs", "RAM (MB)", "Swap (MB)", "Disk (GB)"]
|
||||
fake_data = dict(
|
||||
@@ -112,9 +114,9 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
|
||||
mock_struct.assert_has_calls([mock.call(**fake_data)] * 3)
|
||||
|
||||
fake_formatters = {"RAM (MB)": mock_formatter(),
|
||||
"Swap (MB)": mock_formatter(),
|
||||
"Disk (GB)": mock_formatter()}
|
||||
fake_formatters = {"RAM (MB)": mock_pretty_float_formatter(),
|
||||
"Swap (MB)": mock_pretty_float_formatter(),
|
||||
"Disk (GB)": mock_pretty_float_formatter()}
|
||||
mixed_case_fields = ["ID", "Name", "vCPUs"]
|
||||
mock_print_list.assert_has_calls([mock.call(
|
||||
[mock_struct()],
|
||||
@@ -127,21 +129,21 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.show.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.show.osclients.Clients.nova")
|
||||
@mock.patch("rally.cli.commands.show.db.deployment_get")
|
||||
def test_networks(self, mock_deployment_get, mock_get_nova,
|
||||
def test_networks(self, mock_deployment_get, mock_clients_nova,
|
||||
mock_struct, mock_print_list):
|
||||
self.fake_nova_client.networks.create(1234)
|
||||
fake_network = list(self.fake_nova_client.networks.cache.values())[0]
|
||||
fake_network.label = "fakenet"
|
||||
fake_network.cidr = "10.0.0.0/24"
|
||||
mock_get_nova.return_value = self.fake_nova_client
|
||||
mock_clients_nova.return_value = self.fake_nova_client
|
||||
mock_deployment_get.return_value = {
|
||||
"admin": self.admin_endpoint,
|
||||
"users": [self.user_endpoints, self.user_endpoints]
|
||||
}
|
||||
self.show.networks(self.fake_deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(self.fake_deployment_id)
|
||||
mock_get_nova.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_get_nova.call_count)
|
||||
mock_clients_nova.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_clients_nova.call_count)
|
||||
|
||||
headers = ["ID", "Label", "CIDR"]
|
||||
fake_data = dict(
|
||||
@@ -161,7 +163,7 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.show.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.show.osclients.Clients.nova")
|
||||
@mock.patch("rally.cli.commands.show.db.deployment_get")
|
||||
def test_secgroups(self, mock_deployment_get, mock_get_nova,
|
||||
def test_secgroups(self, mock_deployment_get, mock_clients_nova,
|
||||
mock_struct, mock_print_list):
|
||||
self.fake_nova_client.security_groups.create("othersg")
|
||||
fake_secgroup = list(
|
||||
@@ -170,15 +172,15 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
fake_secgroup2 = list(
|
||||
self.fake_nova_client.security_groups.cache.values())[1]
|
||||
fake_secgroup2.id = 1
|
||||
mock_get_nova.return_value = self.fake_nova_client
|
||||
mock_clients_nova.return_value = self.fake_nova_client
|
||||
mock_deployment_get.return_value = {
|
||||
"admin": self.admin_endpoint,
|
||||
"users": [self.user_endpoints]
|
||||
}
|
||||
self.show.secgroups(self.fake_deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(self.fake_deployment_id)
|
||||
mock_get_nova.assert_has_calls([mock.call()] * 2)
|
||||
self.assertEqual(2, mock_get_nova.call_count)
|
||||
mock_clients_nova.assert_has_calls([mock.call()] * 2)
|
||||
self.assertEqual(2, mock_clients_nova.call_count)
|
||||
|
||||
headers = ["ID", "Name", "Description"]
|
||||
fake_data = [fake_secgroup.id, fake_secgroup.name, ""]
|
||||
@@ -198,20 +200,20 @@ class ShowCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.show.utils.Struct")
|
||||
@mock.patch("rally.cli.commands.show.osclients.Clients.nova")
|
||||
@mock.patch("rally.cli.commands.show.db.deployment_get")
|
||||
def test_keypairs(self, mock_deployment_get, mock_get_nova,
|
||||
def test_keypairs(self, mock_deployment_get, mock_clients_nova,
|
||||
mock_struct, mock_print_list):
|
||||
self.fake_nova_client.keypairs.create("keypair")
|
||||
fake_keypair = list(self.fake_nova_client.keypairs.cache.values())[0]
|
||||
fake_keypair.fingerprint = "84:87:58"
|
||||
mock_get_nova.return_value = self.fake_nova_client
|
||||
mock_clients_nova.return_value = self.fake_nova_client
|
||||
mock_deployment_get.return_value = {
|
||||
"admin": self.admin_endpoint,
|
||||
"users": [self.user_endpoints, self.user_endpoints]
|
||||
}
|
||||
self.show.keypairs(self.fake_deployment_id)
|
||||
mock_deployment_get.assert_called_once_with(self.fake_deployment_id)
|
||||
mock_get_nova.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_get_nova.call_count)
|
||||
mock_clients_nova.assert_has_calls([mock.call()] * 3)
|
||||
self.assertEqual(3, mock_clients_nova.call_count)
|
||||
|
||||
headers = ["Name", "Fingerprint"]
|
||||
fake_data = dict(
|
||||
|
@@ -103,39 +103,40 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
return_value={"some": "json"})
|
||||
@mock.patch("rally.api.Task.create")
|
||||
@mock.patch("rally.cli.commands.task.api.Task.start")
|
||||
def test_start(self, mock_api, mock_create_task, mock_load,
|
||||
mock_task_detailed):
|
||||
mock_create_task.return_value = (
|
||||
def test_start(self, mock_task_start, mock_task_create, mock__load_task,
|
||||
mock_task_commands_detailed):
|
||||
mock_task_create.return_value = (
|
||||
dict(uuid="c1a9bbe-1ead-4740-92b5-0feecf421634",
|
||||
created_at="2014-01-14 09:14:45.395822",
|
||||
status="init", tag=None))
|
||||
deployment_id = "e0617de9-77d1-4875-9b49-9d5789e29f20"
|
||||
task_path = "path_to_config.json"
|
||||
self.task.start(task_path, deployment_id)
|
||||
mock_api.assert_called_once_with(deployment_id, {"some": "json"},
|
||||
task=mock_create_task.return_value,
|
||||
abort_on_sla_failure=False)
|
||||
mock_load.assert_called_once_with(task_path, None, None)
|
||||
mock_task_start.assert_called_once_with(
|
||||
deployment_id, {"some": "json"},
|
||||
task=mock_task_create.return_value, abort_on_sla_failure=False)
|
||||
mock__load_task.assert_called_once_with(task_path, None, None)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.TaskCommands._load_task",
|
||||
side_effect=task.FailedToLoadTask)
|
||||
def test_start_with_task_args(self, mock_load):
|
||||
def test_start_with_task_args(self, mock__load_task):
|
||||
task_path = mock.MagicMock()
|
||||
task_args = mock.MagicMock()
|
||||
task_args_file = mock.MagicMock()
|
||||
self.task.start(task_path, deployment="any", task_args=task_args,
|
||||
task_args_file=task_args_file)
|
||||
mock_load.assert_called_once_with(task_path, task_args, task_args_file)
|
||||
mock__load_task.assert_called_once_with(
|
||||
task_path, task_args, task_args_file)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.envutils.get_global")
|
||||
def test_start_no_deployment_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_start_no_deployment_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.task.start, "path_to_config.json", None)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.TaskCommands._load_task")
|
||||
@mock.patch("rally.cli.commands.task.api")
|
||||
def test_start_invalid_task(self, mock_api, mock_load):
|
||||
def test_start_invalid_task(self, mock_api, mock__load_task):
|
||||
mock_api.Task.start.side_effect = exceptions.InvalidConfigException
|
||||
|
||||
result = self.task.start("task_path", "deployment", tag="tag")
|
||||
@@ -143,7 +144,7 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
|
||||
mock_api.Task.create.assert_called_once_with("deployment", "tag")
|
||||
mock_api.Task.start.assert_called_once_with(
|
||||
"deployment", mock_load.return_value,
|
||||
"deployment", mock__load_task.return_value,
|
||||
task=mock_api.Task.create.return_value, abort_on_sla_failure=False)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.api")
|
||||
@@ -154,8 +155,8 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
task.api.Task.abort.assert_called_once_with(test_uuid)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.envutils.get_global")
|
||||
def test_abort_no_task_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_abort_no_task_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.task.abort, None)
|
||||
|
||||
@@ -168,8 +169,8 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
mock_db.task_get.assert_called_once_with(test_uuid)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.envutils.get_global")
|
||||
def test_status_no_task_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_status_no_task_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.task.status, None)
|
||||
|
||||
@@ -266,8 +267,8 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
self.task.detailed("task_uuid")
|
||||
|
||||
@mock.patch("rally.cli.commands.task.envutils.get_global")
|
||||
def test_detailed_no_task_id(self, mock_default):
|
||||
mock_default.side_effect = exceptions.InvalidArgumentsException
|
||||
def test_detailed_no_task_id(self, mock_get_global):
|
||||
mock_get_global.side_effect = exceptions.InvalidArgumentsException
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
self.task.detailed, None)
|
||||
|
||||
@@ -280,7 +281,7 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("json.dumps")
|
||||
@mock.patch("rally.cli.commands.task.objects.Task.get")
|
||||
def test_results(self, mock_get, mock_json):
|
||||
def test_results(self, mock_task_get, mock_json_dumps):
|
||||
task_id = "foo_task_id"
|
||||
data = [
|
||||
{"key": "foo_key", "data": {"raw": "foo_raw", "sla": [],
|
||||
@@ -293,25 +294,25 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
"full_duration": x["data"]["full_duration"],
|
||||
"sla": x["data"]["sla"]}, data)
|
||||
mock_results = mock.Mock(return_value=data)
|
||||
mock_get.return_value = mock.Mock(get_results=mock_results)
|
||||
mock_task_get.return_value = mock.Mock(get_results=mock_results)
|
||||
|
||||
self.task.results(task_id)
|
||||
self.assertEqual(1, mock_json.call_count)
|
||||
self.assertEqual(1, len(mock_json.call_args[0]))
|
||||
self.assertSequenceEqual(result, mock_json.call_args[0][0])
|
||||
self.assertEqual(1, mock_json_dumps.call_count)
|
||||
self.assertEqual(1, len(mock_json_dumps.call_args[0]))
|
||||
self.assertSequenceEqual(result, mock_json_dumps.call_args[0][0])
|
||||
self.assertEqual({"sort_keys": True, "indent": 4},
|
||||
mock_json.call_args[1])
|
||||
mock_get.assert_called_once_with(task_id)
|
||||
mock_json_dumps.call_args[1])
|
||||
mock_task_get.assert_called_once_with(task_id)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.sys.stdout")
|
||||
@mock.patch("rally.cli.commands.task.objects.Task.get")
|
||||
def test_results_no_data(self, mock_get, mock_stdout):
|
||||
def test_results_no_data(self, mock_task_get, mock_stdout):
|
||||
task_id = "foo_task_id"
|
||||
mock_results = mock.Mock(return_value=[])
|
||||
mock_get.return_value = mock.Mock(get_results=mock_results)
|
||||
mock_task_get.return_value = mock.Mock(get_results=mock_results)
|
||||
|
||||
result = self.task.results(task_id)
|
||||
mock_get.assert_called_once_with(task_id)
|
||||
mock_task_get.assert_called_once_with(task_id)
|
||||
self.assertEqual(1, result)
|
||||
expected_out = ("The task %s is still running, results will become"
|
||||
" available when it is finished." % task_id)
|
||||
@@ -326,8 +327,9 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.task.plot")
|
||||
@mock.patch("rally.cli.commands.task.webbrowser")
|
||||
@mock.patch("rally.cli.commands.task.objects.Task.get")
|
||||
def test_report_one_uuid(self, mock_get, mock_web, mock_plot, mock_open,
|
||||
mock_os, mock_validate):
|
||||
def test_report_one_uuid(self, mock_task_get, mock_webbrowser,
|
||||
mock_plot, mock_open, mock_realpath,
|
||||
mock_validate):
|
||||
task_id = "eb290c30-38d8-4c8f-bbcc-fc8f74b004ae"
|
||||
data = [
|
||||
{"key": {"name": "class.test", "pos": 0},
|
||||
@@ -346,18 +348,18 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
"full_duration": x["data"]["full_duration"]}
|
||||
for x in data]
|
||||
mock_results = mock.Mock(return_value=data)
|
||||
mock_get.return_value = mock.Mock(get_results=mock_results)
|
||||
mock_task_get.return_value = mock.Mock(get_results=mock_results)
|
||||
mock_plot.plot.return_value = "html_report"
|
||||
|
||||
def reset_mocks():
|
||||
for m in mock_get, mock_web, mock_plot, mock_open:
|
||||
for m in mock_task_get, mock_webbrowser, mock_plot, mock_open:
|
||||
m.reset_mock()
|
||||
self.task.report(tasks=task_id, out="/tmp/%s.html" % task_id)
|
||||
mock_open.assert_called_once_with("/tmp/%s.html" % task_id, "w+")
|
||||
mock_plot.plot.assert_called_once_with(results)
|
||||
|
||||
mock_open.side_effect().write.assert_called_once_with("html_report")
|
||||
mock_get.assert_called_once_with(task_id)
|
||||
mock_task_get.assert_called_once_with(task_id)
|
||||
|
||||
reset_mocks()
|
||||
self.task.report(tasks=task_id, out="/tmp/%s.html" % task_id,
|
||||
@@ -366,7 +368,7 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
|
||||
reset_mocks()
|
||||
self.task.report(task_id, out="spam.html", open_it=True)
|
||||
mock_web.open_new_tab.assert_called_once_with(
|
||||
mock_webbrowser.open_new_tab.assert_called_once_with(
|
||||
"file://realpath_spam.html")
|
||||
|
||||
@mock.patch("rally.cli.commands.task.jsonschema.validate",
|
||||
@@ -378,8 +380,9 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.cli.commands.task.plot")
|
||||
@mock.patch("rally.cli.commands.task.webbrowser")
|
||||
@mock.patch("rally.cli.commands.task.objects.Task.get")
|
||||
def test_report_bunch_uuids(self, mock_get, mock_web, mock_plot, mock_open,
|
||||
mock_os, mock_validate):
|
||||
def test_report_bunch_uuids(self, mock_task_get, mock_webbrowser,
|
||||
mock_plot, mock_open, mock_realpath,
|
||||
mock_validate):
|
||||
tasks = ["eb290c30-38d8-4c8f-bbcc-fc8f74b004ae",
|
||||
"eb290c30-38d8-4c8f-bbcc-fc8f74b004af"]
|
||||
data = [
|
||||
@@ -403,11 +406,11 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
data))
|
||||
|
||||
mock_results = mock.Mock(return_value=data)
|
||||
mock_get.return_value = mock.Mock(get_results=mock_results)
|
||||
mock_task_get.return_value = mock.Mock(get_results=mock_results)
|
||||
mock_plot.plot.return_value = "html_report"
|
||||
|
||||
def reset_mocks():
|
||||
for m in mock_get, mock_web, mock_plot, mock_open:
|
||||
for m in mock_task_get, mock_webbrowser, mock_plot, mock_open:
|
||||
m.reset_mock()
|
||||
self.task.report(tasks=tasks, out="/tmp/1_test.html")
|
||||
mock_open.assert_called_once_with("/tmp/1_test.html", "w+")
|
||||
@@ -415,7 +418,7 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
|
||||
mock_open.side_effect().write.assert_called_once_with("html_report")
|
||||
expected_get_calls = [mock.call(task) for task in tasks]
|
||||
mock_get.assert_has_calls(expected_get_calls, any_order=True)
|
||||
mock_task_get.assert_has_calls(expected_get_calls, any_order=True)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.json.load")
|
||||
@mock.patch("rally.cli.commands.task.os.path.exists", return_value=True)
|
||||
@@ -425,7 +428,7 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
side_effect=lambda p: "realpath_%s" % p)
|
||||
@mock.patch("rally.cli.commands.task.open", create=True)
|
||||
@mock.patch("rally.cli.commands.task.plot")
|
||||
def test_report_one_file(self, mock_plot, mock_open, mock_os,
|
||||
def test_report_one_file(self, mock_plot, mock_open, mock_realpath,
|
||||
mock_validate, mock_path_exists, mock_json_load):
|
||||
|
||||
task_file = "/tmp/some_file.json"
|
||||
@@ -510,18 +513,18 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
status="c",
|
||||
tag="d",
|
||||
deployment_name="some_name")])
|
||||
def test_list(self, mock_objects_list, mock_default, mock_print_list):
|
||||
def test_list(self, mock_task_list, mock_get_global, mock_print_list):
|
||||
|
||||
self.task.list(status="running")
|
||||
mock_objects_list.assert_called_once_with(
|
||||
deployment=mock_default.return_value,
|
||||
mock_task_list.assert_called_once_with(
|
||||
deployment=mock_get_global.return_value,
|
||||
status=consts.TaskStatus.RUNNING)
|
||||
|
||||
headers = ["uuid", "deployment_name", "created_at", "duration",
|
||||
"status", "tag"]
|
||||
|
||||
mock_print_list.assert_called_once_with(
|
||||
mock_objects_list.return_value, headers,
|
||||
mock_task_list.return_value, headers,
|
||||
sortby_index=headers.index("created_at"))
|
||||
|
||||
@mock.patch("rally.cli.commands.task.cliutils.print_list")
|
||||
@@ -534,14 +537,14 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
status="c",
|
||||
tag="d",
|
||||
deployment_name="some_name")])
|
||||
def test_list_uuids_only(self, mock_objects_list, mock_default,
|
||||
def test_list_uuids_only(self, mock_task_list, mock_get_global,
|
||||
mock_print_list):
|
||||
self.task.list(status="running", uuids_only=True)
|
||||
mock_objects_list.assert_called_once_with(
|
||||
deployment=mock_default.return_value,
|
||||
mock_task_list.assert_called_once_with(
|
||||
deployment=mock_get_global.return_value,
|
||||
status=consts.TaskStatus.RUNNING)
|
||||
mock_print_list.assert_called_once_with(
|
||||
mock_objects_list.return_value, ["uuid"],
|
||||
mock_task_list.return_value, ["uuid"],
|
||||
print_header=False, print_border=False)
|
||||
|
||||
def test_list_wrong_status(self):
|
||||
@@ -549,17 +552,17 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
status="wrong non existing status"))
|
||||
|
||||
@mock.patch("rally.cli.commands.task.objects.Task.list", return_value=[])
|
||||
def test_list_no_results(self, mock_list):
|
||||
def test_list_no_results(self, mock_task_list):
|
||||
self.assertIsNone(
|
||||
self.task.list(deployment="fake", all_deployments=True))
|
||||
mock_list.assert_called_once_with()
|
||||
mock_list.reset_mock()
|
||||
mock_task_list.assert_called_once_with()
|
||||
mock_task_list.reset_mock()
|
||||
|
||||
self.assertIsNone(
|
||||
self.task.list(deployment="d", status=consts.TaskStatus.RUNNING)
|
||||
)
|
||||
mock_list.assert_called_once_with(deployment="d",
|
||||
status=consts.TaskStatus.RUNNING)
|
||||
mock_task_list.assert_called_once_with(
|
||||
deployment="d", status=consts.TaskStatus.RUNNING)
|
||||
|
||||
def test_delete(self):
|
||||
task_uuid = "8dcb9c5e-d60b-4022-8975-b5987c7833f7"
|
||||
@@ -608,46 +611,47 @@ class TaskCommandsTestCase(test.TestCase):
|
||||
result = self.task.sla_check(task_id="fake_task_id", tojson=True)
|
||||
self.assertEqual(0, result)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.open",
|
||||
mock.mock_open(read_data="{\"some\": \"json\"}"),
|
||||
create=True)
|
||||
@mock.patch("rally.api.Task.validate")
|
||||
def test_validate(self, mock_validate):
|
||||
@mock.patch("rally.cli.commands.task.open",
|
||||
side_effect=mock.mock_open(read_data="{\"some\": \"json\"}"),
|
||||
create=True)
|
||||
def test_validate(self, mock_open, mock_task_validate):
|
||||
self.task.validate("path_to_config.json", "fake_id")
|
||||
mock_validate.assert_called_once_with("fake_id", {"some": "json"})
|
||||
mock_task_validate.assert_called_once_with("fake_id", {"some": "json"})
|
||||
|
||||
@mock.patch("rally.cli.commands.task.TaskCommands._load_task",
|
||||
side_effect=task.FailedToLoadTask)
|
||||
def test_validate_failed_to_load_task(self, mock_load):
|
||||
def test_validate_failed_to_load_task(self, mock__load_task):
|
||||
args = mock.MagicMock()
|
||||
args_file = mock.MagicMock()
|
||||
|
||||
result = self.task.validate("path_to_task", "fake_id",
|
||||
task_args=args, task_args_file=args_file)
|
||||
self.assertEqual(1, result)
|
||||
mock_load.assert_called_once_with("path_to_task", args, args_file)
|
||||
mock__load_task.assert_called_once_with(
|
||||
"path_to_task", args, args_file)
|
||||
|
||||
@mock.patch("rally.cli.commands.task.TaskCommands._load_task")
|
||||
@mock.patch("rally.api.Task.validate")
|
||||
def test_validate_invalid(self, mock_task_validate, mock_load):
|
||||
def test_validate_invalid(self, mock_task_validate, mock__load_task):
|
||||
|
||||
mock_task_validate.side_effect = exceptions.InvalidTaskException
|
||||
result = self.task.validate("path_to_task", "deployment")
|
||||
self.assertEqual(1, result)
|
||||
mock_task_validate.assert_called_once_with("deployment",
|
||||
mock_load.return_value)
|
||||
mock_task_validate.assert_called_once_with(
|
||||
"deployment", mock__load_task.return_value)
|
||||
|
||||
@mock.patch("rally.common.fileutils._rewrite_env_file")
|
||||
@mock.patch("rally.cli.commands.task.db.task_get", return_value=True)
|
||||
def test_use(self, mock_task, mock_file):
|
||||
def test_use(self, mock_task_get, mock__rewrite_env_file):
|
||||
task_id = "80422553-5774-44bd-98ac-38bd8c7a0feb"
|
||||
self.task.use(task_id)
|
||||
mock_file.assert_called_once_with(
|
||||
mock__rewrite_env_file.assert_called_once_with(
|
||||
os.path.expanduser("~/.rally/globals"),
|
||||
["RALLY_TASK=%s\n" % task_id])
|
||||
|
||||
@mock.patch("rally.cli.commands.task.db.task_get")
|
||||
def test_use_not_found(self, mock_task):
|
||||
def test_use_not_found(self, mock_task_get):
|
||||
task_id = "ddc3f8ba-082a-496d-b18f-72cdf5c10a14"
|
||||
mock_task.side_effect = exceptions.TaskNotFound(uuid=task_id)
|
||||
mock_task_get.side_effect = exceptions.TaskNotFound(uuid=task_id)
|
||||
self.assertRaises(exceptions.TaskNotFound, self.task.use, task_id)
|
||||
|
@@ -48,7 +48,7 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.osclients.Clients")
|
||||
@mock.patch("rally.api.Verification.verify")
|
||||
def test_start(self, mock_verify, mock_clients):
|
||||
def test_start(self, mock_verification_verify, mock_clients):
|
||||
deployment_id = "0fba91c6-82d5-4ce1-bd00-5d7c989552d9"
|
||||
mock_clients().glance().images.list.return_value = [
|
||||
self.image1, self.image2]
|
||||
@@ -59,14 +59,13 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
default_set_name = "full"
|
||||
default_regex = None
|
||||
|
||||
mock_verify.assert_called_once_with(deployment_id,
|
||||
default_set_name, default_regex,
|
||||
None)
|
||||
mock_verification_verify.assert_called_once_with(
|
||||
deployment_id, default_set_name, default_regex, None)
|
||||
|
||||
@mock.patch("rally.osclients.Clients")
|
||||
@mock.patch("rally.api.Verification.verify")
|
||||
def test_start_with_user_specified_tempest_config(self, mock_verify,
|
||||
mock_clients):
|
||||
def test_start_with_user_specified_tempest_config(
|
||||
self, mock_verification_verify, mock_clients):
|
||||
deployment_id = "0fba91c6-82d5-4ce1-bd00-5d7c989552d9"
|
||||
mock_clients().glance().images.list.return_value = [
|
||||
self.image1, self.image2]
|
||||
@@ -78,13 +77,13 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
default_set_name = "full"
|
||||
default_regex = None
|
||||
|
||||
mock_verify.assert_called_once_with(deployment_id,
|
||||
default_set_name, default_regex,
|
||||
tempest_config.name)
|
||||
mock_verification_verify.assert_called_once_with(
|
||||
deployment_id, default_set_name, default_regex,
|
||||
tempest_config.name)
|
||||
tempest_config.close()
|
||||
|
||||
@mock.patch("rally.api.Verification.verify")
|
||||
def test_start_with_wrong_set_name(self, mock_verify):
|
||||
def test_start_with_wrong_set_name(self, mock_verification_verify):
|
||||
deployment_id = "f2009aae-6ef3-468e-96b2-3c987d584010"
|
||||
|
||||
wrong_set_name = "unexpected_value"
|
||||
@@ -93,7 +92,7 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
|
||||
self.assertNotIn(wrong_set_name, consts.TempestTestsSets,
|
||||
consts.TempestTestsAPI)
|
||||
self.assertFalse(mock_verify.called)
|
||||
self.assertFalse(mock_verification_verify.called)
|
||||
|
||||
@mock.patch("rally.cli.cliutils.print_list")
|
||||
@mock.patch("rally.db.verification_list")
|
||||
@@ -118,7 +117,7 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.db.verification_get")
|
||||
@mock.patch("rally.db.verification_result_get")
|
||||
@mock.patch("rally.objects.Verification")
|
||||
def test_show(self, mock_obj_verification,
|
||||
def test_show(self, mock_objects_verification,
|
||||
mock_verification_result_get, mock_verification_get,
|
||||
mock_print_list):
|
||||
|
||||
@@ -138,7 +137,7 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
tests = Test_dummy()
|
||||
mock_verification_result_get.return_value = tests
|
||||
mock_verification_get.return_value = verification
|
||||
mock_obj_verification.return_value = 1
|
||||
mock_objects_verification.return_value = 1
|
||||
values = [objects.Verification(t)
|
||||
for t in six.itervalues(tests.data["test_cases"])]
|
||||
self.verify.show(verification_id)
|
||||
@@ -150,36 +149,38 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.db.verification_result_get", return_value={"data": {}})
|
||||
@mock.patch("json.dumps")
|
||||
def test_results(self, mock_json_dumps, mock_db_result_get):
|
||||
def test_results(self, mock_json_dumps, mock_verification_result_get):
|
||||
verification_uuid = "a0231bdf-6a4e-4daf-8ab1-ae076f75f070"
|
||||
self.verify.results(verification_uuid, output_html=False,
|
||||
output_json=True)
|
||||
|
||||
mock_db_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_verification_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_json_dumps.assert_called_once_with({}, sort_keys=True, indent=4)
|
||||
|
||||
@mock.patch("rally.db.verification_result_get")
|
||||
def test_results_verification_not_found(self, mock_db_result_get):
|
||||
def test_results_verification_not_found(
|
||||
self, mock_verification_result_get):
|
||||
verification_uuid = "9044ced5-9c84-4666-8a8f-4b73a2b62acb"
|
||||
mock_db_result_get.side_effect = exceptions.NotFoundException()
|
||||
mock_verification_result_get.side_effect = (
|
||||
exceptions.NotFoundException()
|
||||
)
|
||||
self.assertEqual(self.verify.results(verification_uuid,
|
||||
output_html=False,
|
||||
output_json=True), 1)
|
||||
|
||||
mock_db_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_verification_result_get.assert_called_once_with(verification_uuid)
|
||||
|
||||
@mock.patch("rally.cli.commands.verify.open",
|
||||
side_effect=mock.mock_open(), create=True)
|
||||
@mock.patch("rally.db.verification_result_get", return_value={"data": {}})
|
||||
def test_results_with_output_json_and_output_file(self,
|
||||
mock_db_result_get,
|
||||
mock_open):
|
||||
def test_results_with_output_json_and_output_file(
|
||||
self, mock_verification_result_get, mock_open):
|
||||
mock_open.side_effect = mock.mock_open()
|
||||
verification_uuid = "94615cd4-ff45-4123-86bd-4b0741541d09"
|
||||
self.verify.results(verification_uuid, output_file="results",
|
||||
output_html=False, output_json=True)
|
||||
|
||||
mock_db_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_verification_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_open.assert_called_once_with("results", "wb")
|
||||
mock_open.side_effect().write.assert_called_once_with("{}")
|
||||
|
||||
@@ -187,29 +188,27 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
side_effect=mock.mock_open(), create=True)
|
||||
@mock.patch("rally.db.verification_result_get")
|
||||
@mock.patch("rally.verification.tempest.json2html.HtmlOutput")
|
||||
def test_results_with_output_html_and_output_file(self,
|
||||
mock_html,
|
||||
mock_db_result_get,
|
||||
mock_open):
|
||||
def test_results_with_output_html_and_output_file(
|
||||
self, mock_html_output, mock_verification_result_get, mock_open):
|
||||
|
||||
verification_uuid = "7140dd59-3a7b-41fd-a3ef-5e3e615d7dfa"
|
||||
fake_data = {}
|
||||
results = {"data": fake_data}
|
||||
mock_db_result_get.return_value = results
|
||||
mock_verification_result_get.return_value = results
|
||||
mock_create = mock.Mock(return_value="html_report")
|
||||
mock_html.return_value = mock.Mock(create_report=mock_create)
|
||||
mock_html_output.return_value = mock.Mock(create_report=mock_create)
|
||||
self.verify.results(verification_uuid, output_html=True,
|
||||
output_json=False, output_file="results")
|
||||
|
||||
mock_db_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_html.assert_called_once_with(fake_data)
|
||||
mock_verification_result_get.assert_called_once_with(verification_uuid)
|
||||
mock_html_output.assert_called_once_with(fake_data)
|
||||
mock_open.assert_called_once_with("results", "wb")
|
||||
mock_open.side_effect().write.assert_called_once_with("html_report")
|
||||
|
||||
@mock.patch("rally.db.verification_result_get",
|
||||
return_value={"data": {"test_cases": {}}})
|
||||
@mock.patch("json.dumps")
|
||||
def test_compare(self, mock_json_dumps, mock_db_result_get):
|
||||
def test_compare(self, mock_json_dumps, mock_verification_result_get):
|
||||
uuid1 = "8eda1b10-c8a4-4316-9603-8468ff1d1560"
|
||||
uuid2 = "f6ef0a98-1b18-452f-a6a7-922555c2e326"
|
||||
self.verify.compare(uuid1, uuid2, output_csv=False, output_html=False,
|
||||
@@ -218,13 +217,14 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
fake_data = []
|
||||
calls = [mock.call(uuid1),
|
||||
mock.call(uuid2)]
|
||||
mock_db_result_get.assert_has_calls(calls, True)
|
||||
mock_verification_result_get.assert_has_calls(calls, True)
|
||||
mock_json_dumps.assert_called_once_with(fake_data, sort_keys=True,
|
||||
indent=4)
|
||||
|
||||
@mock.patch("rally.db.verification_result_get",
|
||||
side_effect=exceptions.NotFoundException())
|
||||
def test_compare_verification_not_found(self, mock_db_result_get):
|
||||
def test_compare_verification_not_found(self,
|
||||
mock_verification_result_get):
|
||||
uuid1 = "f7dc82da-31a6-4d40-bbf8-6d366d58960f"
|
||||
uuid2 = "2f8a05f3-d310-4f02-aabf-e1165aaa5f9c"
|
||||
|
||||
@@ -232,15 +232,14 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
output_html=False,
|
||||
output_json=True), 1)
|
||||
|
||||
mock_db_result_get.assert_called_once_with(uuid1)
|
||||
mock_verification_result_get.assert_called_once_with(uuid1)
|
||||
|
||||
@mock.patch("rally.cli.commands.verify.open",
|
||||
side_effect=mock.mock_open(), create=True)
|
||||
@mock.patch("rally.db.verification_result_get",
|
||||
return_value={"data": {"test_cases": {}}})
|
||||
def test_compare_with_output_csv_and_output_file(self,
|
||||
mock_db_result_get,
|
||||
mock_open):
|
||||
def test_compare_with_output_csv_and_output_file(
|
||||
self, mock_verification_result_get, mock_open):
|
||||
|
||||
fake_string = "Type,Field,Value 1,Value 2,Test Name\r\n"
|
||||
uuid1 = "5e744557-4c3a-414f-9afb-7d3d8708028f"
|
||||
@@ -251,7 +250,7 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
|
||||
calls = [mock.call(uuid1),
|
||||
mock.call(uuid2)]
|
||||
mock_db_result_get.assert_has_calls(calls, True)
|
||||
mock_verification_result_get.assert_has_calls(calls, True)
|
||||
mock_open.assert_called_once_with("results", "wb")
|
||||
mock_open.side_effect().write.assert_called_once_with(fake_string)
|
||||
|
||||
@@ -259,9 +258,8 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
side_effect=mock.mock_open(), create=True)
|
||||
@mock.patch("rally.db.verification_result_get",
|
||||
return_value={"data": {"test_cases": {}}})
|
||||
def test_compare_with_output_json_and_output_file(self,
|
||||
mock_db_result_get,
|
||||
mock_open):
|
||||
def test_compare_with_output_json_and_output_file(
|
||||
self, mock_verification_result_get, mock_open):
|
||||
fake_json_string = "[]"
|
||||
uuid1 = "0505e33a-738d-4474-a611-9db21547d863"
|
||||
uuid2 = "b1908417-934e-481c-8d23-bc0badad39ed"
|
||||
@@ -271,7 +269,7 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
|
||||
calls = [mock.call(uuid1),
|
||||
mock.call(uuid2)]
|
||||
mock_db_result_get.assert_has_calls(calls, True)
|
||||
mock_verification_result_get.assert_has_calls(calls, True)
|
||||
mock_open.assert_called_once_with("results", "wb")
|
||||
mock_open.side_effect().write.assert_called_once_with(fake_json_string)
|
||||
|
||||
@@ -280,10 +278,9 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.db.verification_result_get")
|
||||
@mock.patch(("rally.verification.tempest."
|
||||
"compare2html.create_report"), return_value="")
|
||||
def test_compare_with_output_html_and_output_file(self,
|
||||
mock_compare2html_create,
|
||||
mock_db_result_get,
|
||||
mock_open):
|
||||
def test_compare_with_output_html_and_output_file(
|
||||
self, mock_compare2html_create_report,
|
||||
mock_verification_result_get, mock_open):
|
||||
|
||||
uuid1 = "cdf64228-77e9-414d-9d4b-f65e9d62c61f"
|
||||
uuid2 = "39393eec-1b45-4103-8ec1-631edac4b8f0"
|
||||
@@ -293,11 +290,11 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
output_file="results",
|
||||
output_csv=False, output_html=True,
|
||||
output_json=False)
|
||||
mock_db_result_get.return_value = results
|
||||
mock_verification_result_get.return_value = results
|
||||
calls = [mock.call(uuid1),
|
||||
mock.call(uuid2)]
|
||||
mock_db_result_get.assert_has_calls(calls, True)
|
||||
mock_compare2html_create.assert_called_once_with(fake_data)
|
||||
mock_verification_result_get.assert_has_calls(calls, True)
|
||||
mock_compare2html_create_report.assert_called_once_with(fake_data)
|
||||
|
||||
mock_open.assert_called_once_with("results", "wb")
|
||||
mock_open.side_effect().write.assert_called_once_with("")
|
||||
@@ -305,10 +302,10 @@ class VerifyCommandsTestCase(test.TestCase):
|
||||
@mock.patch("rally.common.fileutils._rewrite_env_file")
|
||||
@mock.patch("rally.cli.commands.verify.db.verification_get",
|
||||
return_value=True)
|
||||
def test_use(self, mock_task, mock_file):
|
||||
def test_use(self, mock_verification_get, mock__rewrite_env_file):
|
||||
verification_id = "80422553-5774-44bd-98ac-38bd8c7a0feb"
|
||||
self.verify.use(verification_id)
|
||||
mock_file.assert_called_once_with(
|
||||
mock__rewrite_env_file.assert_called_once_with(
|
||||
os.path.expanduser("~/.rally/globals"),
|
||||
["RALLY_VERIFICATION=%s\n" % verification_id])
|
||||
|
||||
|
@@ -158,7 +158,7 @@ class CliUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.cli.cliutils.CONF", config_file=None,
|
||||
side_effect=cfg.ConfigFilesNotFoundError("config_file"))
|
||||
def test_run_fails(self, mock_cmd_cliutils_conf):
|
||||
def test_run_fails(self, mock_cliutils_conf):
|
||||
ret = cliutils.run(["rally", "show", "flavors"], self.categories)
|
||||
self.assertEqual(ret, 2)
|
||||
|
||||
|
@@ -48,17 +48,17 @@ class EnvUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.dict(os.environ, values={}, clear=True)
|
||||
@mock.patch("rally.cli.envutils.fileutils.load_env_file")
|
||||
def test_get_deployment_id_with_exception(self, mock_file):
|
||||
def test_get_deployment_id_with_exception(self, mock_load_env_file):
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
envutils.get_global, envutils.ENV_DEPLOYMENT, True)
|
||||
mock_file.assert_called_once_with(os.path.expanduser(
|
||||
mock_load_env_file.assert_called_once_with(os.path.expanduser(
|
||||
"~/.rally/globals"))
|
||||
|
||||
@mock.patch.dict(os.environ, values={}, clear=True)
|
||||
@mock.patch("rally.cli.envutils.fileutils.load_env_file")
|
||||
def test_get_deployment_id_with_none(self, mock_file):
|
||||
def test_get_deployment_id_with_none(self, mock_load_env_file):
|
||||
self.assertIsNone(envutils.get_global(envutils.ENV_DEPLOYMENT))
|
||||
mock_file.assert_called_once_with(os.path.expanduser(
|
||||
mock_load_env_file.assert_called_once_with(os.path.expanduser(
|
||||
"~/.rally/globals"))
|
||||
|
||||
@mock.patch.dict(os.environ, values={envutils.ENV_TASK: "my_task_id"},
|
||||
@@ -68,17 +68,17 @@ class EnvUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.dict(os.environ, values={}, clear=True)
|
||||
@mock.patch("rally.cli.envutils.fileutils.load_env_file")
|
||||
def test_get_task_id_with_exception(self, mock_file):
|
||||
def test_get_task_id_with_exception(self, mock_load_env_file):
|
||||
self.assertRaises(exceptions.InvalidArgumentsException,
|
||||
envutils.get_global, envutils.ENV_TASK, True)
|
||||
mock_file.assert_called_once_with(os.path.expanduser(
|
||||
mock_load_env_file.assert_called_once_with(os.path.expanduser(
|
||||
"~/.rally/globals"))
|
||||
|
||||
@mock.patch.dict(os.environ, values={}, clear=True)
|
||||
@mock.patch("rally.cli.envutils.fileutils.load_env_file")
|
||||
def test_get_task_id_with_none(self, mock_file):
|
||||
def test_get_task_id_with_none(self, mock_load_env_file):
|
||||
self.assertIsNone(envutils.get_global("RALLY_TASK"))
|
||||
mock_file.assert_called_once_with(os.path.expanduser(
|
||||
mock_load_env_file.assert_called_once_with(os.path.expanduser(
|
||||
"~/.rally/globals"))
|
||||
|
||||
@mock.patch.dict(os.environ,
|
||||
@@ -87,9 +87,9 @@ class EnvUtilsTestCase(test.TestCase):
|
||||
@mock.patch("os.path.exists")
|
||||
@mock.patch("rally.cli.envutils.fileutils.update_env_file",
|
||||
return_value=True)
|
||||
def test_clear_global(self, mock_file, mock_file_status):
|
||||
def test_clear_global(self, mock_update_env_file, mock_path_exists):
|
||||
envutils.clear_global(envutils.ENV_DEPLOYMENT)
|
||||
mock_file.assert_called_once_with(os.path.expanduser(
|
||||
mock_update_env_file.assert_called_once_with(os.path.expanduser(
|
||||
"~/.rally/globals"), envutils.ENV_DEPLOYMENT, "\n")
|
||||
self.assertEqual(os.environ, {})
|
||||
|
||||
@@ -100,6 +100,6 @@ class EnvUtilsTestCase(test.TestCase):
|
||||
@mock.patch("os.path.exists")
|
||||
@mock.patch("rally.cli.envutils.fileutils.update_env_file",
|
||||
return_value=True)
|
||||
def test_clear_env(self, mock_file, mock_file_status):
|
||||
def test_clear_env(self, mock_update_env_file, mock_path_exists):
|
||||
envutils.clear_env()
|
||||
self.assertEqual(os.environ, {})
|
||||
|
@@ -24,11 +24,11 @@ from tests.unit import test
|
||||
class CmdManageTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.cli.manage.cliutils")
|
||||
def test_main(self, cli_mock):
|
||||
def test_main(self, mock_cliutils):
|
||||
manage.main()
|
||||
categories = {"db": manage.DBCommands,
|
||||
"tempest": manage.TempestCommands}
|
||||
cli_mock.run.assert_called_once_with(sys.argv, categories)
|
||||
mock_cliutils.run.assert_called_once_with(sys.argv, categories)
|
||||
|
||||
|
||||
class DBCommandsTestCase(test.TestCase):
|
||||
|
@@ -51,7 +51,7 @@ class LoadExtraModulesTestCase(test.TestCase):
|
||||
("/somewhere/subdir", ("/subsubdir", ), ("plugin2.py",
|
||||
"withoutextension")),
|
||||
("/somewhere/subdir/subsubdir", [], ("plugin3.py", ))])
|
||||
def test_load_plugins_from_dir_successful(self, mock_oswalk,
|
||||
def test_load_plugins_from_dir_successful(self, mock_os_walk,
|
||||
mock_find_module,
|
||||
mock_load_module, mock_isdir):
|
||||
test_path = "/somewhere"
|
||||
@@ -96,8 +96,8 @@ class LoadExtraModulesTestCase(test.TestCase):
|
||||
@mock.patch("%s.os.path" % DISCOVER, return_value=True)
|
||||
@mock.patch("%s.os.walk" % DISCOVER,
|
||||
return_value=[("/etc/.rally/plugins", [], ("load_it.py", ))])
|
||||
def test_load_plugins_fails(self, mock_oswalk, mock_ospath,
|
||||
mock_load_module, mock_find_module):
|
||||
def test_load_plugins_fails(self, mock_os_walk, mock_os_path,
|
||||
mock_find_module, mock_load_module):
|
||||
# test no fails if module is broken
|
||||
# TODO(olkonami): check exception is handled correct
|
||||
discover.load_plugins("/somwhere")
|
||||
|
@@ -69,14 +69,14 @@ class BrokerTestCase(test.TestCase):
|
||||
self.assertEqual(0, len(queue))
|
||||
|
||||
@mock.patch("rally.common.broker.LOG")
|
||||
def test__consumer_indexerror(self, m_log):
|
||||
def test__consumer_indexerror(self, mock_log):
|
||||
consume = mock.Mock()
|
||||
consume.side_effect = IndexError()
|
||||
queue = collections.deque([1, 2, 3])
|
||||
is_published = mock.Mock()
|
||||
is_published.isSet.side_effect = [False, False, True]
|
||||
broker._consumer(consume, queue, is_published)
|
||||
self.assertTrue(m_log.warning.called)
|
||||
self.assertTrue(mock_log.warning.called)
|
||||
self.assertFalse(queue)
|
||||
expected = [mock.call({}, 1), mock.call({}, 2), mock.call({}, 3)]
|
||||
self.assertEqual(expected, consume.mock_calls)
|
||||
|
@@ -28,28 +28,29 @@ class SPCheckCallTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.subprocess" % PATH)
|
||||
@mock.patch("%s.is_py26" % PATH, return_value=True)
|
||||
def test_simulation_of_py26_env(self, mock_is_py26, mock_sp):
|
||||
def test_simulation_of_py26_env(self, mock_is_py26, mock_subprocess):
|
||||
output = "output"
|
||||
process = mock.MagicMock()
|
||||
process.communicate.return_value = (output, "unused_err")
|
||||
process.poll.return_value = None
|
||||
|
||||
mock_sp.Popen.return_value = process
|
||||
mock_subprocess.Popen.return_value = process
|
||||
some_args = (1, 2)
|
||||
some_kwargs = {"a": 2}
|
||||
|
||||
self.assertEqual(output, costilius.sp_check_output(*some_args,
|
||||
**some_kwargs))
|
||||
|
||||
mock_sp.Popen.assert_called_once_with(
|
||||
stdout=mock_sp.PIPE, *some_args, **some_kwargs)
|
||||
self.assertFalse(mock_sp.check_output.called)
|
||||
mock_subprocess.Popen.assert_called_once_with(
|
||||
stdout=mock_subprocess.PIPE, *some_args, **some_kwargs)
|
||||
self.assertFalse(mock_subprocess.check_output.called)
|
||||
|
||||
@mock.patch("%s.subprocess" % PATH)
|
||||
@mock.patch("%s.is_py26" % PATH, return_value=False)
|
||||
def test_simulation_of_any_not_py26_env(self, mock_is_py26, mock_sp):
|
||||
def test_simulation_of_any_not_py26_env(self, mock_is_py26,
|
||||
mock_subprocess):
|
||||
output = "output"
|
||||
mock_sp.check_output.return_value = output
|
||||
mock_subprocess.check_output.return_value = output
|
||||
|
||||
some_args = (1, 2)
|
||||
some_kwargs = {"a": 2}
|
||||
@@ -57,8 +58,9 @@ class SPCheckCallTestCase(test.TestCase):
|
||||
self.assertEqual(output, costilius.sp_check_output(*some_args,
|
||||
**some_kwargs))
|
||||
|
||||
mock_sp.check_output.assert_called_once_with(*some_args, **some_kwargs)
|
||||
self.assertFalse(mock_sp.Popen.called)
|
||||
mock_subprocess.check_output.assert_called_once_with(
|
||||
*some_args, **some_kwargs)
|
||||
self.assertFalse(mock_subprocess.Popen.called)
|
||||
|
||||
|
||||
class GetInterpreterTestCase(test.TestCase):
|
||||
@@ -71,30 +73,30 @@ class GetInterpreterTestCase(test.TestCase):
|
||||
@mock.patch("%s.os.path.isfile" % PATH)
|
||||
@mock.patch("%s.os.environ" % PATH)
|
||||
def test_found_correct_python_interpreter_with_distutils(
|
||||
self, mock_env, mock_isfile, mock_check_output, mock_spawn):
|
||||
self, mock_environ, mock_isfile, mock_sp_check_output, mock_spawn):
|
||||
vers = (2, 7)
|
||||
interpreter = "something"
|
||||
mock_spawn.find_executable.return_value = interpreter
|
||||
|
||||
self.assertEqual(interpreter, costilius.get_interpreter(vers))
|
||||
self.assertFalse(mock_env.called)
|
||||
self.assertFalse(mock_environ.called)
|
||||
self.assertFalse(mock_isfile.called)
|
||||
self.assertFalse(mock_check_output.called)
|
||||
self.assertFalse(mock_sp_check_output.called)
|
||||
|
||||
@mock.patch("%s.spawn" % PATH)
|
||||
@mock.patch("%s.sp_check_output" % PATH)
|
||||
@mock.patch("%s.os.path.isfile" % PATH, return_value=True)
|
||||
@mock.patch("%s.os.environ" % PATH)
|
||||
def test_found_correct_python_interpreter_without_distutils(
|
||||
self, mock_env, mock_isfile, mock_check_output, mock_spawn):
|
||||
self, mock_environ, mock_isfile, mock_sp_check_output, mock_spawn):
|
||||
vers = (2, 7)
|
||||
paths = ["one_path", "second_path"]
|
||||
mock_env.get.return_value = ":".join(paths)
|
||||
mock_check_output.return_value = "%s\n" % str(vers)
|
||||
mock_environ.get.return_value = ":".join(paths)
|
||||
mock_sp_check_output.return_value = "%s\n" % str(vers)
|
||||
mock_spawn.find_executable.return_value = None
|
||||
|
||||
found_interpreter = costilius.get_interpreter(vers)
|
||||
|
||||
self.assertEqual(1, mock_check_output.call_count)
|
||||
self.assertEqual(1, mock_sp_check_output.call_count)
|
||||
self.assertIn(
|
||||
found_interpreter, ["%s/%s" % (f, "python2.7") for f in paths])
|
||||
|
@@ -25,7 +25,7 @@ class FileUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("os.path.exists", return_value=True)
|
||||
@mock.patch.dict("os.environ", values={}, clear=True)
|
||||
def test_load_env_vile(self, mock_path):
|
||||
def test_load_env_vile(self, mock_exists):
|
||||
file_data = ["FAKE_ENV=fake_env\n"]
|
||||
with mock.patch("rally.common.fileutils.open", mock.mock_open(
|
||||
read_data=file_data), create=True) as mock_file:
|
||||
@@ -35,7 +35,7 @@ class FileUtilsTestCase(test.TestCase):
|
||||
mock_file.return_value.readlines.assert_called_once_with()
|
||||
|
||||
@mock.patch("os.path.exists", return_value=True)
|
||||
def test_update_env_file(self, mock_path):
|
||||
def test_update_env_file(self, mock_exists):
|
||||
file_data = ["FAKE_ENV=old_value\n", "FAKE_ENV2=any\n"]
|
||||
with mock.patch("rally.common.fileutils.open", mock.mock_open(
|
||||
read_data=file_data), create=True) as mock_file:
|
||||
|
@@ -33,11 +33,11 @@ class SSHTestCase(test.TestCase):
|
||||
self.ssh = sshutils.SSH("root", "example.net")
|
||||
|
||||
@mock.patch("rally.common.sshutils.SSH._get_pkey")
|
||||
def test_construct(self, m_pkey):
|
||||
m_pkey.return_value = "pkey"
|
||||
def test_construct(self, mock_ssh__get_pkey):
|
||||
mock_ssh__get_pkey.return_value = "pkey"
|
||||
ssh = sshutils.SSH("root", "example.net", port=33, pkey="key",
|
||||
key_filename="kf", password="secret")
|
||||
m_pkey.assert_called_once_with("key")
|
||||
mock_ssh__get_pkey.assert_called_once_with("key")
|
||||
self.assertEqual("root", ssh.user)
|
||||
self.assertEqual("example.net", ssh.host)
|
||||
self.assertEqual(33, ssh.port)
|
||||
@@ -54,49 +54,49 @@ class SSHTestCase(test.TestCase):
|
||||
self.assertIsNone(self.ssh.password)
|
||||
|
||||
@mock.patch("rally.common.sshutils.paramiko")
|
||||
def test__get_pkey_invalid(self, m_paramiko):
|
||||
m_paramiko.SSHException = FakeParamikoException
|
||||
rsa = m_paramiko.rsakey.RSAKey
|
||||
dss = m_paramiko.dsskey.DSSKey
|
||||
rsa.from_private_key.side_effect = m_paramiko.SSHException
|
||||
dss.from_private_key.side_effect = m_paramiko.SSHException
|
||||
def test__get_pkey_invalid(self, mock_paramiko):
|
||||
mock_paramiko.SSHException = FakeParamikoException
|
||||
rsa = mock_paramiko.rsakey.RSAKey
|
||||
dss = mock_paramiko.dsskey.DSSKey
|
||||
rsa.from_private_key.side_effect = mock_paramiko.SSHException
|
||||
dss.from_private_key.side_effect = mock_paramiko.SSHException
|
||||
self.assertRaises(sshutils.SSHError, self.ssh._get_pkey, "key")
|
||||
|
||||
@mock.patch("rally.common.sshutils.six.moves")
|
||||
@mock.patch("rally.common.sshutils.six.moves.StringIO")
|
||||
@mock.patch("rally.common.sshutils.paramiko")
|
||||
def test__get_pkey_dss(self, m_paramiko, m_stringio):
|
||||
m_paramiko.SSHException = FakeParamikoException
|
||||
m_stringio.StringIO.return_value = "string_key"
|
||||
m_paramiko.dsskey.DSSKey.from_private_key.return_value = "dss_key"
|
||||
rsa = m_paramiko.rsakey.RSAKey
|
||||
rsa.from_private_key.side_effect = m_paramiko.SSHException
|
||||
def test__get_pkey_dss(self, mock_paramiko, mock_string_io):
|
||||
mock_paramiko.SSHException = FakeParamikoException
|
||||
mock_string_io.return_value = "string_key"
|
||||
mock_paramiko.dsskey.DSSKey.from_private_key.return_value = "dss_key"
|
||||
rsa = mock_paramiko.rsakey.RSAKey
|
||||
rsa.from_private_key.side_effect = mock_paramiko.SSHException
|
||||
key = self.ssh._get_pkey("key")
|
||||
dss_calls = m_paramiko.dsskey.DSSKey.from_private_key.mock_calls
|
||||
dss_calls = mock_paramiko.dsskey.DSSKey.from_private_key.mock_calls
|
||||
self.assertEqual([mock.call("string_key")], dss_calls)
|
||||
self.assertEqual(key, "dss_key")
|
||||
m_stringio.StringIO.assert_called_once_with("key")
|
||||
mock_string_io.assert_called_once_with("key")
|
||||
|
||||
@mock.patch("rally.common.sshutils.six.moves")
|
||||
@mock.patch("rally.common.sshutils.six.moves.StringIO")
|
||||
@mock.patch("rally.common.sshutils.paramiko")
|
||||
def test__get_pkey_rsa(self, m_paramiko, m_stringio):
|
||||
m_paramiko.SSHException = FakeParamikoException
|
||||
m_stringio.StringIO.return_value = "string_key"
|
||||
m_paramiko.rsakey.RSAKey.from_private_key.return_value = "rsa_key"
|
||||
dss = m_paramiko.dsskey.DSSKey
|
||||
dss.from_private_key.side_effect = m_paramiko.SSHException
|
||||
def test__get_pkey_rsa(self, mock_paramiko, mock_string_io):
|
||||
mock_paramiko.SSHException = FakeParamikoException
|
||||
mock_string_io.return_value = "string_key"
|
||||
mock_paramiko.rsakey.RSAKey.from_private_key.return_value = "rsa_key"
|
||||
dss = mock_paramiko.dsskey.DSSKey
|
||||
dss.from_private_key.side_effect = mock_paramiko.SSHException
|
||||
key = self.ssh._get_pkey("key")
|
||||
rsa_calls = m_paramiko.rsakey.RSAKey.from_private_key.mock_calls
|
||||
rsa_calls = mock_paramiko.rsakey.RSAKey.from_private_key.mock_calls
|
||||
self.assertEqual([mock.call("string_key")], rsa_calls)
|
||||
self.assertEqual(key, "rsa_key")
|
||||
m_stringio.StringIO.assert_called_once_with("key")
|
||||
mock_string_io.assert_called_once_with("key")
|
||||
|
||||
@mock.patch("rally.common.sshutils.SSH._get_pkey")
|
||||
@mock.patch("rally.common.sshutils.paramiko")
|
||||
def test__get_client(self, m_paramiko, m_pkey):
|
||||
m_pkey.return_value = "key"
|
||||
def test__get_client(self, mock_paramiko, mock_ssh__get_pkey):
|
||||
mock_ssh__get_pkey.return_value = "key"
|
||||
fake_client = mock.Mock()
|
||||
m_paramiko.SSHClient.return_value = fake_client
|
||||
m_paramiko.AutoAddPolicy.return_value = "autoadd"
|
||||
mock_paramiko.SSHClient.return_value = fake_client
|
||||
mock_paramiko.AutoAddPolicy.return_value = "autoadd"
|
||||
|
||||
ssh = sshutils.SSH("admin", "example.net", pkey="key")
|
||||
client = ssh._get_client()
|
||||
@@ -116,26 +116,25 @@ class SSHTestCase(test.TestCase):
|
||||
m_client.close.assert_called_once_with()
|
||||
self.assertFalse(self.ssh._client)
|
||||
|
||||
@mock.patch("rally.common.sshutils.six.moves")
|
||||
def test_execute(self, m_stringio):
|
||||
m_stringio.StringIO.side_effect = stdio = [mock.Mock(), mock.Mock()]
|
||||
@mock.patch("rally.common.sshutils.six.moves.StringIO")
|
||||
def test_execute(self, mock_string_io):
|
||||
mock_string_io.side_effect = stdio = [mock.Mock(), mock.Mock()]
|
||||
stdio[0].read.return_value = "stdout fake data"
|
||||
stdio[1].read.return_value = "stderr fake data"
|
||||
with mock.patch.object(self.ssh, "run", return_value=0) as m_run:
|
||||
with mock.patch.object(self.ssh, "run", return_value=0) as mock_run:
|
||||
status, stdout, stderr = self.ssh.execute("cmd",
|
||||
stdin="fake_stdin",
|
||||
timeout=43)
|
||||
m_run.assert_called_once_with("cmd", stdin="fake_stdin",
|
||||
stdout=stdio[0],
|
||||
stderr=stdio[1], timeout=43,
|
||||
raise_on_error=False)
|
||||
mock_run.assert_called_once_with(
|
||||
"cmd", stdin="fake_stdin", stdout=stdio[0],
|
||||
stderr=stdio[1], timeout=43, raise_on_error=False)
|
||||
self.assertEqual(0, status)
|
||||
self.assertEqual("stdout fake data", stdout)
|
||||
self.assertEqual("stderr fake data", stderr)
|
||||
|
||||
@mock.patch("rally.common.sshutils.time")
|
||||
def test_wait_timeout(self, m_time):
|
||||
m_time.time.side_effect = [1, 50, 150]
|
||||
def test_wait_timeout(self, mock_time):
|
||||
mock_time.time.side_effect = [1, 50, 150]
|
||||
self.ssh.execute = mock.Mock(side_effect=[sshutils.SSHError,
|
||||
sshutils.SSHError,
|
||||
0])
|
||||
@@ -143,8 +142,8 @@ class SSHTestCase(test.TestCase):
|
||||
self.assertEqual([mock.call("uname")] * 2, self.ssh.execute.mock_calls)
|
||||
|
||||
@mock.patch("rally.common.sshutils.time")
|
||||
def test_wait(self, m_time):
|
||||
m_time.time.side_effect = [1, 50, 100]
|
||||
def test_wait(self, mock_time):
|
||||
mock_time.time.side_effect = [1, 50, 100]
|
||||
self.ssh.execute = mock.Mock(side_effect=[sshutils.SSHError,
|
||||
sshutils.SSHError,
|
||||
0])
|
||||
@@ -178,8 +177,8 @@ class SSHRunTestCase(test.TestCase):
|
||||
self.ssh._get_client = mock.Mock(return_value=self.fake_client)
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_execute(self, m_select):
|
||||
m_select.select.return_value = ([], [], [])
|
||||
def test_execute(self, mock_select):
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.fake_session.recv_ready.side_effect = [1, 0, 0]
|
||||
self.fake_session.recv_stderr_ready.side_effect = [1, 0]
|
||||
self.fake_session.recv.return_value = "ok"
|
||||
@@ -190,8 +189,8 @@ class SSHRunTestCase(test.TestCase):
|
||||
self.fake_session.exec_command.assert_called_once_with("cmd")
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_execute_args(self, m_select):
|
||||
m_select.select.return_value = ([], [], [])
|
||||
def test_execute_args(self, mock_select):
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.fake_session.recv_ready.side_effect = [1, 0, 0]
|
||||
self.fake_session.recv_stderr_ready.side_effect = [1, 0]
|
||||
self.fake_session.recv.return_value = "ok"
|
||||
@@ -205,20 +204,20 @@ class SSHRunTestCase(test.TestCase):
|
||||
"cmd arg1 'arg2 with space'")
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_run(self, m_select):
|
||||
m_select.select.return_value = ([], [], [])
|
||||
def test_run(self, mock_select):
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.assertEqual(0, self.ssh.run("cmd"))
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_run_nonzero_status(self, m_select):
|
||||
m_select.select.return_value = ([], [], [])
|
||||
def test_run_nonzero_status(self, mock_select):
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.fake_session.recv_exit_status.return_value = 1
|
||||
self.assertRaises(sshutils.SSHError, self.ssh.run, "cmd")
|
||||
self.assertEqual(1, self.ssh.run("cmd", raise_on_error=False))
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_run_stdout(self, m_select):
|
||||
m_select.select.return_value = ([], [], [])
|
||||
def test_run_stdout(self, mock_select):
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.fake_session.recv_ready.side_effect = [True, True, False]
|
||||
self.fake_session.recv.side_effect = ["ok1", "ok2"]
|
||||
stdout = mock.Mock()
|
||||
@@ -227,8 +226,8 @@ class SSHRunTestCase(test.TestCase):
|
||||
stdout.write.mock_calls)
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_run_stderr(self, m_select):
|
||||
m_select.select.return_value = ([], [], [])
|
||||
def test_run_stderr(self, mock_select):
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.fake_session.recv_stderr_ready.side_effect = [True, False]
|
||||
self.fake_session.recv_stderr.return_value = "error"
|
||||
stderr = mock.Mock()
|
||||
@@ -236,13 +235,13 @@ class SSHRunTestCase(test.TestCase):
|
||||
stderr.write.assert_called_once_with("error")
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_run_stdin(self, m_select):
|
||||
def test_run_stdin(self, mock_select):
|
||||
"""Test run method with stdin.
|
||||
|
||||
Third send call was called with "e2" because only 3 bytes was sent
|
||||
by second call. So remainig 2 bytes of "line2" was sent by third call.
|
||||
"""
|
||||
m_select.select.return_value = ([], [], [])
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.fake_session.exit_status_ready.side_effect = [0, 0, 0, True]
|
||||
self.fake_session.send_ready.return_value = True
|
||||
self.fake_session.send.side_effect = [5, 3, 2]
|
||||
@@ -259,16 +258,16 @@ class SSHRunTestCase(test.TestCase):
|
||||
self.assertEqual(send_calls, self.fake_session.send.mock_calls)
|
||||
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_run_select_error(self, m_select):
|
||||
def test_run_select_error(self, mock_select):
|
||||
self.fake_session.exit_status_ready.return_value = False
|
||||
m_select.select.return_value = ([], [], [True])
|
||||
mock_select.select.return_value = ([], [], [True])
|
||||
self.assertRaises(sshutils.SSHError, self.ssh.run, "cmd")
|
||||
|
||||
@mock.patch("rally.common.sshutils.time")
|
||||
@mock.patch("rally.common.sshutils.select")
|
||||
def test_run_timemout(self, m_select, m_time):
|
||||
m_time.time.side_effect = [1, 3700]
|
||||
m_select.select.return_value = ([], [], [])
|
||||
def test_run_timemout(self, mock_select, mock_time):
|
||||
mock_time.time.side_effect = [1, 3700]
|
||||
mock_select.select.return_value = ([], [], [])
|
||||
self.fake_session.exit_status_ready.return_value = False
|
||||
self.assertRaises(sshutils.SSHTimeout, self.ssh.run, "cmd")
|
||||
|
||||
|
@@ -314,28 +314,28 @@ class TenantIteratorTestCase(test.TestCase):
|
||||
class RAMIntTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.common.utils.multiprocessing")
|
||||
def test__init__(self, mock_multi):
|
||||
def test__init__(self, mock_multiprocessing):
|
||||
utils.RAMInt()
|
||||
mock_multi.Lock.assert_called_once_with()
|
||||
mock_multi.Value.assert_called_once_with("I", 0)
|
||||
mock_multiprocessing.Lock.assert_called_once_with()
|
||||
mock_multiprocessing.Value.assert_called_once_with("I", 0)
|
||||
|
||||
@mock.patch("rally.common.utils.multiprocessing")
|
||||
def test__int__(self, mock_multi):
|
||||
mock_multi.Value.return_value = mock.Mock(value=42)
|
||||
def test__int__(self, mock_multiprocessing):
|
||||
mock_multiprocessing.Value.return_value = mock.Mock(value=42)
|
||||
self.assertEqual(int(utils.RAMInt()), 42)
|
||||
|
||||
@mock.patch("rally.common.utils.multiprocessing")
|
||||
def test__str__(self, mock_multi):
|
||||
mock_multi.Value.return_value = mock.Mock(value=42)
|
||||
def test__str__(self, mock_multiprocessing):
|
||||
mock_multiprocessing.Value.return_value = mock.Mock(value=42)
|
||||
self.assertEqual(str(utils.RAMInt()), "42")
|
||||
|
||||
@mock.patch("rally.common.utils.multiprocessing")
|
||||
def test__iter__(self, mock_multi):
|
||||
def test__iter__(self, mock_multiprocessing):
|
||||
ram_int = utils.RAMInt()
|
||||
self.assertEqual(iter(ram_int), ram_int)
|
||||
|
||||
@mock.patch("rally.common.utils.multiprocessing")
|
||||
def test__next__(self, mock_multi):
|
||||
def test__next__(self, mock_multiprocessing):
|
||||
class MemInt(int):
|
||||
THRESHOLD = 5
|
||||
|
||||
@@ -343,8 +343,8 @@ class RAMIntTestCase(test.TestCase):
|
||||
return MemInt((int(self) + i) % self.THRESHOLD)
|
||||
|
||||
mock_lock = mock.MagicMock()
|
||||
mock_multi.Lock.return_value = mock_lock
|
||||
mock_multi.Value.return_value = mock.Mock(value=MemInt(0))
|
||||
mock_multiprocessing.Lock.return_value = mock_lock
|
||||
mock_multiprocessing.Value.return_value = mock.Mock(value=MemInt(0))
|
||||
|
||||
ram_int = utils.RAMInt()
|
||||
self.assertEqual(int(ram_int), 0)
|
||||
@@ -358,12 +358,12 @@ class RAMIntTestCase(test.TestCase):
|
||||
@mock.patch("rally.common.utils.RAMInt.__next__",
|
||||
return_value="next_value")
|
||||
@mock.patch("rally.common.utils.multiprocessing")
|
||||
def test_next(self, mock_multi, mock_next):
|
||||
def test_next(self, mock_multiprocessing, mock_ram_int___next__):
|
||||
self.assertEqual(next(utils.RAMInt()), "next_value")
|
||||
mock_next.assert_called_once_with()
|
||||
mock_ram_int___next__.assert_called_once_with()
|
||||
|
||||
@mock.patch("rally.common.utils.multiprocessing")
|
||||
def test_reset(self, mock_multi):
|
||||
def test_reset(self, mock_multiprocessing):
|
||||
ram_int = utils.RAMInt()
|
||||
self.assertRaises(TypeError, int, ram_int)
|
||||
ram_int.reset()
|
||||
|
@@ -55,8 +55,8 @@ class DevstackEngineTestCase(test.TestCase):
|
||||
self.assertEqual(self.engine.localrc["ADMIN_PASSWORD"], "secret")
|
||||
|
||||
@mock.patch("rally.deploy.engines.devstack.open", create=True)
|
||||
def test_prepare_server(self, m_open):
|
||||
m_open.return_value = "fake_file"
|
||||
def test_prepare_server(self, mock_open):
|
||||
mock_open.return_value = "fake_file"
|
||||
server = mock.Mock()
|
||||
server.password = "secret"
|
||||
self.engine.prepare_server(server)
|
||||
@@ -65,31 +65,33 @@ class DevstackEngineTestCase(test.TestCase):
|
||||
mock.call("chpasswd", stdin="rally:secret"),
|
||||
]
|
||||
self.assertEqual(calls, server.ssh.run.mock_calls)
|
||||
filename = m_open.mock_calls[0][1][0]
|
||||
filename = mock_open.mock_calls[0][1][0]
|
||||
self.assertTrue(filename.endswith("rally/deploy/engines/"
|
||||
"devstack/install.sh"))
|
||||
self.assertEqual([mock.call(filename, "rb")], m_open.mock_calls)
|
||||
self.assertEqual([mock.call(filename, "rb")], mock_open.mock_calls)
|
||||
|
||||
@mock.patch("rally.deploy.engine.EngineFactory.get_provider")
|
||||
@mock.patch("rally.deploy.engines.devstack.get_updated_server")
|
||||
@mock.patch("rally.deploy.engines.devstack.get_script")
|
||||
@mock.patch("rally.deploy.serverprovider.provider.Server")
|
||||
@mock.patch("rally.deploy.engines.devstack.objects.Endpoint")
|
||||
def test_deploy(self, m_endpoint, m_server, m_gs, m_gus, m_gp):
|
||||
m_gp.return_value = fake_provider = mock.Mock()
|
||||
server = mock.Mock()
|
||||
server.host = "host"
|
||||
m_endpoint.return_value = "fake_endpoint"
|
||||
m_gus.return_value = ds_server = mock.Mock()
|
||||
m_gs.return_value = "fake_script"
|
||||
def test_deploy(self, mock_endpoint, mock_server, mock_get_script,
|
||||
mock_get_updated_server, mock_engine_factory_get_provider):
|
||||
mock_engine_factory_get_provider.return_value = fake_provider = (
|
||||
mock.Mock()
|
||||
)
|
||||
server = mock.Mock(host="host")
|
||||
mock_endpoint.return_value = "fake_endpoint"
|
||||
mock_get_updated_server.return_value = ds_server = mock.Mock()
|
||||
mock_get_script.return_value = "fake_script"
|
||||
server.get_credentials.return_value = "fake_credentials"
|
||||
fake_provider.create_servers.return_value = [server]
|
||||
with mock.patch.object(self.engine, "deployment") as m_d:
|
||||
with mock.patch.object(self.engine, "deployment") as mock_deployment:
|
||||
endpoints = self.engine.deploy()
|
||||
self.assertEqual({"admin": "fake_endpoint"}, endpoints)
|
||||
m_endpoint.assert_called_once_with("http://host:5000/v2.0/", "admin",
|
||||
"secret", "admin", "admin")
|
||||
m_d.add_resource.assert_called_once_with(
|
||||
mock_endpoint.assert_called_once_with(
|
||||
"http://host:5000/v2.0/", "admin", "secret", "admin", "admin")
|
||||
mock_deployment.add_resource.assert_called_once_with(
|
||||
info="fake_credentials",
|
||||
provider_name="DevstackEngine",
|
||||
type="credentials")
|
||||
|
@@ -85,17 +85,20 @@ class FuelEngineTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.FuelClient")
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.FuelCluster")
|
||||
def test_deploy(self, m_cluster, m_client):
|
||||
def test_deploy(self, mock_fuel_cluster, mock_fuel_client):
|
||||
attributes = {"editable": {"access": {"user": {"value": "user"},
|
||||
"password": {"value": "pw"},
|
||||
"tenant": {"value": "tn"}}}}
|
||||
client = mock.Mock()
|
||||
cluster = mock.Mock()
|
||||
cluster.cluster = {"id": 42}
|
||||
cluster.get_endpoint_ip = mock.Mock(return_value="2.3.4.5")
|
||||
cluster.get_attributes = mock.Mock(return_value=attributes)
|
||||
m_client.return_value = client
|
||||
m_cluster.return_value = cluster
|
||||
cluster = mock.Mock(
|
||||
cluster={"id": 42},
|
||||
**{
|
||||
"get_endpoint_ip.return_value": "2.3.4.5",
|
||||
"get_attributes.return_value": attributes
|
||||
}
|
||||
)
|
||||
mock_fuel_client.return_value = client
|
||||
mock_fuel_cluster.return_value = cluster
|
||||
self.deployment.add_resource = mock.Mock()
|
||||
|
||||
engine = fuel.FuelEngine(self.deployment)
|
||||
@@ -128,7 +131,7 @@ class FuelEngineTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.FuelClient")
|
||||
@mock.patch("rally.deploy.engines.fuel.objects.Deployment")
|
||||
def test_cleanup(self, m_deployment, m_client):
|
||||
def test_cleanup(self, mock_deployment, mock_fuel_client):
|
||||
fake_resources = [{"id": 41, "info": {"id": 42}}]
|
||||
self.deployment.get_resources = mock.Mock(return_value=fake_resources)
|
||||
|
||||
@@ -137,4 +140,4 @@ class FuelEngineTestCase(test.TestCase):
|
||||
engine.cleanup()
|
||||
|
||||
engine.client.delete_cluster.assert_called_once_with(42)
|
||||
m_deployment.delete_resource.assert_called_once_with(41)
|
||||
mock_deployment.delete_resource.assert_called_once_with(41)
|
||||
|
@@ -28,24 +28,24 @@ MOD_NAME = "rally.deploy.serverprovider.providers.lxc."
|
||||
class HelperFunctionsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MOD_NAME + "open", create=True, return_value="fake_script")
|
||||
def test__get_script(self, m_open):
|
||||
def test__get_script(self, mock_open):
|
||||
script = lxc._get_script("script.sh")
|
||||
self.assertEqual("fake_script", script)
|
||||
path = m_open.mock_calls[0][1][0]
|
||||
mode = m_open.mock_calls[0][1][1]
|
||||
path = mock_open.mock_calls[0][1][0]
|
||||
mode = mock_open.mock_calls[0][1][1]
|
||||
self.assertTrue(path.endswith("rally/deploy/serverprovider/providers"
|
||||
"/lxc/script.sh"))
|
||||
self.assertEqual("rb", mode)
|
||||
|
||||
@mock.patch(MOD_NAME + "_get_script", return_value="fake_script")
|
||||
@mock.patch(MOD_NAME + "moves.StringIO")
|
||||
def test__get_script_from_template(self, m_sio, m_gs):
|
||||
m_gs.return_value = fake_script = mock.Mock()
|
||||
def test__get_script_from_template(self, mock_string_io, mock__get_script):
|
||||
mock__get_script.return_value = fake_script = mock.Mock()
|
||||
fake_script.read.return_value = "fake_data {k1} {k2}"
|
||||
m_sio.return_value = "fake_formatted_script"
|
||||
mock_string_io.return_value = "fake_formatted_script"
|
||||
script = lxc._get_script_from_template("fake_tpl", k1="v1", k2="v2")
|
||||
self.assertEqual("fake_formatted_script", script)
|
||||
m_sio.assert_called_once_with("fake_data v1 v2")
|
||||
mock_string_io.assert_called_once_with("fake_data v1 v2")
|
||||
|
||||
|
||||
class LxcHostTestCase(test.TestCase):
|
||||
@@ -62,9 +62,9 @@ class LxcHostTestCase(test.TestCase):
|
||||
self.host = lxc.LxcHost(self.server, sample_config)
|
||||
|
||||
@mock.patch(MOD_NAME + "provider.Server")
|
||||
def test__get_updated_server(self, m_Server):
|
||||
def test__get_updated_server(self, mock_server):
|
||||
server = self.host._get_updated_server(host="4.4.4.4")
|
||||
new_server = m_Server.from_credentials({"host": "4.4.4.4"})
|
||||
new_server = mock_server.from_credentials({"host": "4.4.4.4"})
|
||||
self.assertEqual(new_server, server)
|
||||
|
||||
def test_backingstore_btrfs(self):
|
||||
@@ -81,8 +81,8 @@ class LxcHostTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MOD_NAME + "moves.StringIO")
|
||||
@mock.patch(MOD_NAME + "_get_script", return_value="fake_script")
|
||||
def test_prepare(self, m_gs, m_sio):
|
||||
m_sio.return_value = fake_conf = mock.Mock()
|
||||
def test_prepare(self, mock__get_script, mock_string_io):
|
||||
mock_string_io.return_value = fake_conf = mock.Mock()
|
||||
self.host.create_local_tunnels = mock.Mock()
|
||||
self.host.create_remote_tunnels = mock.Mock()
|
||||
|
||||
@@ -107,23 +107,25 @@ class LxcHostTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MOD_NAME + "os.unlink")
|
||||
@mock.patch(MOD_NAME + "_get_script_from_template")
|
||||
def test_create_local_tunnels(self, m_gs, m_unlink):
|
||||
m_gs.side_effect = ["s1", "s2"]
|
||||
def test_create_local_tunnels(self, mock__get_script_from_template,
|
||||
mock_unlink):
|
||||
mock__get_script_from_template.side_effect = ["s1", "s2"]
|
||||
self.host.create_local_tunnels()
|
||||
gs_calls = [
|
||||
getscript_calls = [
|
||||
mock.call("tunnel-local.sh", local="fake_server_ip",
|
||||
net=netaddr.IPNetwork("10.1.1.0/24"), remote="1.1.1.1"),
|
||||
mock.call("tunnel-local.sh", local="fake_server_ip",
|
||||
net=netaddr.IPNetwork("10.1.1.0/24"), remote="2.2.2.2"),
|
||||
]
|
||||
self.assertEqual(gs_calls, m_gs.mock_calls)
|
||||
self.assertEqual(
|
||||
getscript_calls, mock__get_script_from_template.mock_calls)
|
||||
self.assertEqual([mock.call("/bin/sh", stdin="s1"),
|
||||
mock.call("/bin/sh", stdin="s2")],
|
||||
self.server.ssh.run.mock_calls)
|
||||
|
||||
@mock.patch(MOD_NAME + "_get_script_from_template")
|
||||
def test_create_remote_tunnels(self, m_get_script):
|
||||
m_get_script.side_effect = ["s1", "s2"]
|
||||
def test_create_remote_tunnels(self, mock__get_script_from_template):
|
||||
mock__get_script_from_template.side_effect = ["s1", "s2"]
|
||||
fake_server = mock.Mock()
|
||||
self.host._get_updated_server = mock.Mock(return_value=fake_server)
|
||||
self.host.create_remote_tunnels()
|
||||
@@ -144,7 +146,7 @@ class LxcHostTestCase(test.TestCase):
|
||||
self.server.ssh.execute.mock_calls)
|
||||
|
||||
@mock.patch(MOD_NAME + "time.sleep")
|
||||
def test_get_ip(self, m_sleep):
|
||||
def test_get_ip(self, mock_sleep):
|
||||
s1 = "link/ether fe:54:00:d3:f5:98 brd ff:ff:ff:ff:ff:ff"
|
||||
s2 = s1 + "\n inet 10.20.0.1/24 scope global br1"
|
||||
self.host.server.ssh.execute.side_effect = [(0, s1, ""), (0, s2, "")]
|
||||
@@ -192,9 +194,9 @@ class LxcHostTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MOD_NAME + "os.path.join")
|
||||
@mock.patch(MOD_NAME + "_get_script")
|
||||
def test_configure_container(self, m_gs, m_join):
|
||||
m_gs.return_value = "fake_script"
|
||||
m_join.return_value = "fake_path"
|
||||
def test_configure_container(self, mock__get_script, mock_join):
|
||||
mock__get_script.return_value = "fake_script"
|
||||
mock_join.return_value = "fake_path"
|
||||
self.server.ssh.execute.return_value = 0, "", ""
|
||||
self.host.configure_container("name")
|
||||
self.server.ssh.run.assert_called_once_with(
|
||||
@@ -241,13 +243,13 @@ class LxcHostTestCase(test.TestCase):
|
||||
fake_server.ssh.wait.assert_called_once_with(timeout=300)
|
||||
|
||||
@mock.patch(MOD_NAME + "LxcHost.get_server_object")
|
||||
def test_get_server_objects(self, m_gso):
|
||||
m_gso.side_effect = ["s1", "s2"]
|
||||
def test_get_server_objects(self, mock_get_server_object):
|
||||
mock_get_server_object.side_effect = ["s1", "s2"]
|
||||
self.host.containers = ["c1", "c2"]
|
||||
retval = list(self.host.get_server_objects(wait="wait"))
|
||||
self.assertEqual(["s1", "s2"], retval)
|
||||
self.assertEqual([mock.call("c1", "wait"), mock.call("c2", "wait")],
|
||||
m_gso.mock_calls)
|
||||
mock_get_server_object.mock_calls)
|
||||
|
||||
|
||||
class LxcProviderTestCase(test.TestCase):
|
||||
@@ -292,7 +294,8 @@ class LxcProviderTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MOD_NAME + "LxcHost")
|
||||
@mock.patch(MOD_NAME + "provider.ProviderFactory.get_provider")
|
||||
def test_create_servers(self, m_get_provider, m_lxchost):
|
||||
def test_create_servers(self, mock_provider_factory_get_provider,
|
||||
mock_lxc_host):
|
||||
fake_provider = mock.Mock()
|
||||
fake_provider.create_servers.return_value = ["server1", "server2"]
|
||||
fake_hosts = []
|
||||
@@ -307,8 +310,8 @@ class LxcProviderTestCase(test.TestCase):
|
||||
fake_host.server.get_credentials.return_value = {"ip": "f%d" % i}
|
||||
fake_host.get_server_objects.return_value = fake_host_sos
|
||||
fake_hosts.append(fake_host)
|
||||
m_lxchost.side_effect = fake_hosts
|
||||
m_get_provider.return_value = fake_provider
|
||||
mock_lxc_host.side_effect = fake_hosts
|
||||
mock_provider_factory_get_provider.return_value = fake_provider
|
||||
|
||||
fake_info = [
|
||||
{"host": {"ip": "f1"},
|
||||
@@ -363,15 +366,16 @@ class LxcProviderTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MOD_NAME + "LxcHost")
|
||||
@mock.patch(MOD_NAME + "provider.Server.from_credentials")
|
||||
def test_destroy_servers(self, m_fc, m_lxchost):
|
||||
def test_destroy_servers(self, mock_server_from_credentials,
|
||||
mock_lxc_host):
|
||||
fake_resource = {"info": {"config": "fake_config",
|
||||
"host": "fake_credentials",
|
||||
"forwarded_ports": [1, 2],
|
||||
"container_names": ["n1", "n2"]}}
|
||||
fake_resource["id"] = "fake_res_id"
|
||||
fake_host = mock.Mock()
|
||||
m_fc.return_value = "fake_server"
|
||||
m_lxchost.return_value = fake_host
|
||||
mock_server_from_credentials.return_value = "fake_server"
|
||||
mock_lxc_host.return_value = fake_host
|
||||
self.provider.resources = mock.Mock()
|
||||
self.provider.resources.get_all.return_value = [fake_resource]
|
||||
|
||||
@@ -379,7 +383,7 @@ class LxcProviderTestCase(test.TestCase):
|
||||
ghp.return_value = fake_host_provider = mock.Mock()
|
||||
self.provider.destroy_servers()
|
||||
|
||||
m_lxchost.assert_called_once_with("fake_server", "fake_config")
|
||||
mock_lxc_host.assert_called_once_with("fake_server", "fake_config")
|
||||
host_calls = [mock.call.destroy_containers(),
|
||||
mock.call.destroy_ports([1, 2]),
|
||||
mock.call.delete_tunnels()]
|
||||
|
@@ -81,9 +81,9 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
self.clients.nova = mock.MagicMock(return_value=self.nova_client)
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_init(self, os_cli):
|
||||
def test_openstack_provider_init(self, mock_osclients):
|
||||
cfg = self._get_valid_config()
|
||||
os_cli.Clients = mock.MagicMock(return_value=FakeOSClients())
|
||||
mock_osclients.Clients = mock.MagicMock(return_value=FakeOSClients())
|
||||
os_provider = OSProvider(mock.MagicMock(), cfg)
|
||||
self.assertEqual("nova", os_provider.nova)
|
||||
self.assertEqual("glance", os_provider.glance)
|
||||
@@ -97,7 +97,7 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_init_with_invalid_conf_no_user(self,
|
||||
mock_osclient):
|
||||
mock_osclients):
|
||||
cfg = self._get_valid_config()
|
||||
cfg.pop("user")
|
||||
self.assertRaises(jsonschema.ValidationError, OSProvider,
|
||||
@@ -105,7 +105,7 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_init_with_invalid_conf_no_url(self,
|
||||
mock_osclient):
|
||||
mock_osclients):
|
||||
cfg = self._get_valid_config()
|
||||
del cfg["image"]["url"]
|
||||
del cfg["image"]["checksum"]
|
||||
@@ -113,8 +113,8 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
mock.MagicMock(), cfg)
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_init_with_invalid_conf_extra_key(self,
|
||||
mock_osclnt):
|
||||
def test_openstack_provider_init_with_invalid_conf_extra_key(
|
||||
self, mock_osclients):
|
||||
cfg = self._get_valid_config()
|
||||
cfg["aaaaa"] = "bbbbb"
|
||||
self.assertRaises(jsonschema.ValidationError, OSProvider,
|
||||
@@ -122,26 +122,26 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_init_with_invalid_conf_flavor_(self,
|
||||
mock_osclient):
|
||||
mock_osclients):
|
||||
cfg = self._get_valid_config()["user"] = 1111
|
||||
self.assertRaises(jsonschema.ValidationError, OSProvider,
|
||||
mock.MagicMock(), cfg)
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_with_valid_config(self,
|
||||
mock_osclient):
|
||||
mock_osclients):
|
||||
cfg = self._get_valid_config()
|
||||
OSProvider(mock.MagicMock(), cfg)
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_with_valid_config_uuid(self, mock_osclient):
|
||||
def test_openstack_provider_with_valid_config_uuid(self, mock_osclients):
|
||||
cfg = self._get_valid_config()
|
||||
cfg["image"] = dict(uuid="289D7A51-1A0C-43C4-800D-706EA8A3CDF3")
|
||||
OSProvider(mock.MagicMock(), cfg)
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.openstack.osclients")
|
||||
def test_openstack_provider_with_valid_config_checksum(self,
|
||||
mock_osclient):
|
||||
mock_osclients):
|
||||
cfg = self._get_valid_config()
|
||||
cfg["image"] = dict(checksum="checksum")
|
||||
OSProvider(mock.MagicMock(), cfg)
|
||||
@@ -150,7 +150,8 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
@mock.patch(MOD_NAME + ".provider.Server")
|
||||
@mock.patch(MOD_NAME + ".osclients")
|
||||
@mock.patch(MOD_NAME + ".benchmark_utils")
|
||||
def test_create_servers(self, bmutils, oscl, m_Server, m_sleep):
|
||||
def test_create_servers(self, mock_benchmark_utils, mock_osclients,
|
||||
mock_server, mock_sleep):
|
||||
fake_keypair = mock.Mock()
|
||||
fake_keypair.name = "fake_key_name"
|
||||
provider = OSProvider(mock.Mock(), self._get_valid_config())
|
||||
@@ -160,15 +161,15 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
provider.get_nics = mock.Mock(return_value="fake_nics")
|
||||
provider.create_keypair = mock.Mock(return_value=(fake_keypair,
|
||||
"fake_path"))
|
||||
m_Server.return_value = fake_server = mock.Mock()
|
||||
mock_server.return_value = fake_server = mock.Mock()
|
||||
provider.nova.servers.create.return_value = fake_instance = mock.Mock()
|
||||
fake_instance.addresses.values = mock.Mock(
|
||||
return_value=[[{"addr": "1.2.3.4"}]])
|
||||
|
||||
servers = provider.create_servers()
|
||||
|
||||
m_Server.assert_called_once_with(host="1.2.3.4", user="root",
|
||||
key="fake_path")
|
||||
mock_server.assert_called_once_with(host="1.2.3.4", user="root",
|
||||
key="fake_path")
|
||||
self.assertEqual([fake_server], servers)
|
||||
fake_server.ssh.wait.assert_called_once_with(interval=5, timeout=120)
|
||||
provider.nova.servers.create.assert_called_once_with(
|
||||
@@ -176,18 +177,18 @@ class OpenStackProviderTestCase(test.TestCase):
|
||||
nics="fake_nics", key_name="fake_key_name")
|
||||
|
||||
@mock.patch(MOD_NAME + ".osclients")
|
||||
def test_get_image_found_by_checksum(self, oscl):
|
||||
def test_get_image_found_by_checksum(self, mock_osclients):
|
||||
self._init_mock_clients()
|
||||
oscl.Clients = mock.MagicMock(return_value=self.clients)
|
||||
mock_osclients.Clients = mock.MagicMock(return_value=self.clients)
|
||||
prov = OSProvider(mock.MagicMock(), self._get_valid_config())
|
||||
image_uuid = prov.get_image_uuid()
|
||||
self.assertEqual(image_uuid, "fake-uuid")
|
||||
|
||||
@mock.patch(MOD_NAME + ".osclients")
|
||||
def test_get_image_download(self, oscl):
|
||||
def test_get_image_download(self, mock_osclients):
|
||||
self._init_mock_clients()
|
||||
self.glance_client.images.list = mock.Mock(return_value=[])
|
||||
oscl.Clients = mock.MagicMock(return_value=self.clients)
|
||||
mock_osclients.Clients = mock.MagicMock(return_value=self.clients)
|
||||
prov = OSProvider(mock.MagicMock(), self._get_valid_config())
|
||||
image_uuid = prov.get_image_uuid()
|
||||
self.assertEqual(image_uuid, "fake-uuid")
|
||||
|
@@ -42,13 +42,13 @@ class VirshProviderTestCase(test.TestCase):
|
||||
"rally.deploy.serverprovider.providers.virsh.netaddr.IPAddress")
|
||||
@mock.patch("rally.deploy.serverprovider.providers.virsh.subprocess")
|
||||
@mock.patch("time.sleep")
|
||||
def test_create_vm(self, mock_sleep, mock_subp, mock_ipaddress):
|
||||
mock_subp.check_output.return_value = "10.0.0.1"
|
||||
mock_ipaddress.return_value = "10.0.0.2"
|
||||
def test_create_vm(self, mock_sleep, mock_subprocess, mock_ip_address):
|
||||
mock_subprocess.check_output.return_value = "10.0.0.1"
|
||||
mock_ip_address.return_value = "10.0.0.2"
|
||||
server = self.provider.create_vm("name")
|
||||
script_path = ("%s/virsh/get_domain_ip.sh" %
|
||||
os.path.split(virsh.__file__)[0])
|
||||
mock_subp.assert_has_calls([
|
||||
mock_subprocess.assert_has_calls([
|
||||
mock.call.check_call("virt-clone --connect=qemu+ssh://user@host/"
|
||||
"system -o prefix -n name --auto-clone",
|
||||
shell=True),
|
||||
@@ -60,7 +60,7 @@ class VirshProviderTestCase(test.TestCase):
|
||||
mock.call.check_output("ssh -o StrictHostKeyChecking=no user@host "
|
||||
"./get_domain_ip.sh name", shell=True),
|
||||
])
|
||||
mock_ipaddress.assert_called_once_with("10.0.0.1")
|
||||
mock_ip_address.assert_called_once_with("10.0.0.1")
|
||||
self.assertEqual(server.host, "10.0.0.2")
|
||||
self.assertEqual(server.user, "user")
|
||||
self.assertIsNone(server.key)
|
||||
@@ -73,19 +73,20 @@ class VirshProviderTestCase(test.TestCase):
|
||||
"rally.deploy.serverprovider.providers.virsh.netaddr.IPAddress")
|
||||
@mock.patch("rally.deploy.serverprovider.providers.virsh.subprocess")
|
||||
@mock.patch("time.sleep")
|
||||
def test_create_vm_ip_failed(self, mock_sleep, mock_subp, mock_ipaddress):
|
||||
mock_ipaddress.side_effect = netaddr.core.AddrFormatError
|
||||
def test_create_vm_ip_failed(self, mock_sleep, mock_subprocess,
|
||||
mock_ip_address):
|
||||
mock_ip_address.side_effect = netaddr.core.AddrFormatError
|
||||
server = self.provider.create_vm("name")
|
||||
mock_subp.assert_has_calls(3 * [
|
||||
mock_subprocess.assert_has_calls(3 * [
|
||||
mock.call.check_output("ssh -o StrictHostKeyChecking=no user@host "
|
||||
"./get_domain_ip.sh name", shell=True),
|
||||
])
|
||||
self.assertEqual(server.host, "None")
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.virsh.subprocess")
|
||||
def test_destroy_vm(self, mock_subp):
|
||||
def test_destroy_vm(self, mock_subprocess):
|
||||
self.provider.destroy_vm("uuid")
|
||||
mock_subp.assert_has_calls([
|
||||
mock_subprocess.assert_has_calls([
|
||||
mock.call.check_call("virsh --connect=qemu+ssh://user@host/system "
|
||||
"destroy uuid", shell=True),
|
||||
mock.call.check_call("virsh --connect=qemu+ssh://user@host/system "
|
||||
@@ -95,26 +96,26 @@ class VirshProviderTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.deploy.serverprovider.providers.virsh.uuid")
|
||||
@mock.patch.object(virsh.VirshProvider, "create_vm")
|
||||
def test_create_servers(self, mock_create, mock_uuid):
|
||||
def test_create_servers(self, mock_create_vm, mock_uuid):
|
||||
mock_uuid.uuid4.side_effect = ["1", "2", "3"]
|
||||
mock_create.side_effect = ["s1", "s2", "s3"]
|
||||
mock_create_vm.side_effect = ["s1", "s2", "s3"]
|
||||
servers = self.provider.create_servers(amount=3)
|
||||
self.assertEqual(servers, ["s1", "s2", "s3"])
|
||||
mock_create.assert_has_calls([
|
||||
mock_create_vm.assert_has_calls([
|
||||
mock.call("1"),
|
||||
mock.call("2"),
|
||||
mock.call("3"),
|
||||
])
|
||||
|
||||
@mock.patch.object(virsh.VirshProvider, "destroy_vm")
|
||||
def test_destroy_servers(self, mock_destroy):
|
||||
def test_destroy_servers(self, mock_destroy_vm):
|
||||
self.provider.resources.get_all.return_value = [
|
||||
{"info": {"name": "1"}},
|
||||
{"info": {"name": "2"}},
|
||||
{"info": {"name": "3"}},
|
||||
]
|
||||
self.provider.destroy_servers()
|
||||
mock_destroy.assert_has_calls([
|
||||
mock_destroy_vm.assert_has_calls([
|
||||
mock.call("1"),
|
||||
mock.call("2"),
|
||||
mock.call("3"),
|
||||
|
@@ -58,12 +58,12 @@ class ProviderC(ProviderB):
|
||||
FAKE_PROVIDERS = [ProviderA, ProviderB, ProviderC]
|
||||
|
||||
|
||||
class ProviderTestCase(test.TestCase):
|
||||
class ProviderFactoryTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.object(provider.ProviderFactory, "validate")
|
||||
def test_init(self, fake_validate):
|
||||
def test_init(self, mock_validate):
|
||||
ProviderA(None, None)
|
||||
fake_validate.assert_called_once_with()
|
||||
mock_validate.assert_called_once_with()
|
||||
|
||||
def test_get_provider_not_found(self):
|
||||
self.assertRaises(exceptions.PluginNotFound,
|
||||
|
@@ -96,36 +96,38 @@ class EngineFactoryTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.object(FakeDeployment, "set_completed")
|
||||
@mock.patch.object(FakeDeployment, "set_started")
|
||||
def test_make_deploy(self, mock_set_started, mock_set_completed):
|
||||
def test_make_deploy(self, mock_fake_deployment_set_started,
|
||||
mock_fake_deployment_set_completed):
|
||||
deployment = make_fake_deployment()
|
||||
engine = FakeEngine(deployment)
|
||||
endpoint = engine.make_deploy()
|
||||
self.assertEqual(engine, endpoint)
|
||||
self.assertTrue(endpoint.deployed)
|
||||
self.assertFalse(endpoint.cleanuped)
|
||||
mock_set_started.assert_called_once_with()
|
||||
mock_set_completed.assert_called_once_with()
|
||||
mock_fake_deployment_set_completed.assert_called_once_with()
|
||||
mock_fake_deployment_set_started.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(FakeDeployment, "set_started")
|
||||
@mock.patch.object(FakeEngine, "deploy")
|
||||
def test_make_deploy_failed(self, mock_deploy, mock_set_started):
|
||||
def test_make_deploy_failed(self, mock_fake_engine_deploy,
|
||||
mock_fake_deployment_set_started):
|
||||
class DeployFailed(Exception):
|
||||
pass
|
||||
|
||||
deployment = make_fake_deployment()
|
||||
engine = FakeEngine(deployment)
|
||||
mock_deploy.side_effect = DeployFailed()
|
||||
mock_fake_engine_deploy.side_effect = DeployFailed()
|
||||
self.assertRaises(DeployFailed, engine.make_deploy)
|
||||
mock_set_started.assert_called_once_with()
|
||||
mock_fake_deployment_set_started.assert_called_once_with()
|
||||
|
||||
@mock.patch.object(FakeDeployment, "update_status")
|
||||
def test_make_cleanup(self, mock_update_status):
|
||||
def test_make_cleanup(self, mock_fake_deployment_update_status):
|
||||
deployment = make_fake_deployment()
|
||||
engine = FakeEngine(deployment)
|
||||
engine.make_cleanup()
|
||||
self.assertTrue(engine.cleanuped)
|
||||
self.assertFalse(engine.deployed)
|
||||
mock_update_status.assert_has_calls([
|
||||
mock_fake_deployment_update_status.assert_has_calls([
|
||||
mock.call(consts.DeployStatus.CLEANUP_STARTED),
|
||||
mock.call(consts.DeployStatus.CLEANUP_FINISHED),
|
||||
])
|
||||
@@ -133,26 +135,27 @@ class EngineFactoryTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.object(FakeDeployment, "update_status")
|
||||
@mock.patch.object(FakeEngine, "cleanup")
|
||||
def test_make_cleanup_failed(self, mock_cleanup, mock_update_status):
|
||||
def test_make_cleanup_failed(self, mock_fake_engine_cleanup,
|
||||
mock_fake_deployment_update_status):
|
||||
class CleanUpFailed(Exception):
|
||||
pass
|
||||
|
||||
deployment = make_fake_deployment()
|
||||
engine = FakeEngine(deployment)
|
||||
mock_cleanup.side_effect = CleanUpFailed()
|
||||
mock_fake_engine_cleanup.side_effect = CleanUpFailed()
|
||||
self.assertRaises(CleanUpFailed, engine.make_cleanup)
|
||||
mock_update_status.assert_has_calls([
|
||||
mock_fake_deployment_update_status.assert_has_calls([
|
||||
mock.call(consts.DeployStatus.CLEANUP_STARTED),
|
||||
])
|
||||
self.assertFalse(engine.cleanuped)
|
||||
|
||||
@mock.patch.object(FakeDeployment, "update_status")
|
||||
def test_with_statement(self, mock_update_status):
|
||||
def test_with_statement(self, mock_fake_deployment_update_status):
|
||||
deployment = make_fake_deployment()
|
||||
engine = FakeEngine(deployment)
|
||||
with engine as deployer:
|
||||
self.assertEqual(engine, deployer)
|
||||
self.assertFalse(mock_update_status.called)
|
||||
self.assertFalse(mock_fake_deployment_update_status.called)
|
||||
self.assertFalse(engine.cleanuped)
|
||||
self.assertFalse(engine.deployed)
|
||||
|
||||
@@ -178,7 +181,7 @@ class EngineFactoryTestCase(test.TestCase):
|
||||
|
||||
@mock.patch.object(FakeDeployment, "update_status")
|
||||
def _assert_changed_status_on_error(self, initial, final,
|
||||
mock_update_status):
|
||||
mock_fake_deployment_update_status):
|
||||
# NOTE(akscram): The assertRaises of testtools can't be used as
|
||||
# a context manager in python26:
|
||||
# with self.assertRaises(SomeError):
|
||||
@@ -198,7 +201,7 @@ class EngineFactoryTestCase(test.TestCase):
|
||||
deployment = make_fake_deployment(status=initial)
|
||||
engine = FakeEngine(deployment)
|
||||
self.assertRaises(SomeError, context_with_error, SomeError(), engine)
|
||||
mock_update_status.assert_called_once_with(final)
|
||||
mock_fake_deployment_update_status.assert_called_once_with(final)
|
||||
self.assertFalse(engine.cleanuped)
|
||||
self.assertFalse(engine.deployed)
|
||||
|
||||
|
@@ -54,12 +54,13 @@ class LxcEngineTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MOD + "objects")
|
||||
@mock.patch(MOD + "engine")
|
||||
def test__deploy_first(self, m_engine, m_objects):
|
||||
def test__deploy_first(self, mock_engine, mock_objects):
|
||||
fake_credentials = {"user": "admin", "host": "host.net"}
|
||||
fake_deployment = mock.Mock()
|
||||
fake_engine = mock.Mock()
|
||||
m_objects.Deployment = mock.Mock(return_value=fake_deployment)
|
||||
m_engine.EngineFactory.get_engine = mock.Mock(return_value=fake_engine)
|
||||
mock_objects.Deployment = mock.Mock(return_value=fake_deployment)
|
||||
mock_engine.EngineFactory.get_engine = mock.Mock(
|
||||
return_value=fake_engine)
|
||||
|
||||
fake_host = mock.Mock()
|
||||
fake_so = mock.Mock()
|
||||
@@ -74,38 +75,38 @@ class LxcEngineTestCase(test.TestCase):
|
||||
mock.call.stop_containers()]
|
||||
self.assertEqual(host_calls, fake_host.mock_calls)
|
||||
fake_engine.deploy.assert_called_once_with()
|
||||
m_engine.EngineFactory.get_engine.assert_called_once_with(
|
||||
mock_engine.EngineFactory.get_engine.assert_called_once_with(
|
||||
"FakeEngine", fake_deployment)
|
||||
engine_config = self.config["engine"].copy()
|
||||
engine_config["provider"] = {"credentials": [fake_credentials],
|
||||
"type": "DummyProvider"}
|
||||
m_objects.Deployment.assert_called_once_with(
|
||||
mock_objects.Deployment.assert_called_once_with(
|
||||
config=engine_config, parent_uuid="test-deployment-uuid")
|
||||
|
||||
@mock.patch(MOD + "provider.ProviderFactory.get_provider")
|
||||
def test__get_provider(self, m_get_provider):
|
||||
m_get_provider.return_value = "fake_provider"
|
||||
def test__get_provider(self, mock_provider_factory_get_provider):
|
||||
mock_provider_factory_get_provider.return_value = "fake_provider"
|
||||
provider = self.engine._get_provider()
|
||||
self.assertEqual("fake_provider", provider)
|
||||
m_get_provider.assert_called_once_with(self.config["provider"],
|
||||
self.deployment)
|
||||
mock_provider_factory_get_provider.assert_called_once_with(
|
||||
self.config["provider"], self.deployment)
|
||||
|
||||
@mock.patch(MOD + "open", create=True)
|
||||
@mock.patch(MOD + "get_script_path", return_value="fake_sp")
|
||||
@mock.patch(MOD + "lxc.LxcHost")
|
||||
@mock.patch(MOD + "LxcEngine._deploy_first")
|
||||
@mock.patch(MOD + "LxcEngine._get_provider")
|
||||
def test_deploy(self, m_get_provider, m_deploy_first, m_LxcHost,
|
||||
m_gsp, m_open):
|
||||
m_open.return_value = "fs"
|
||||
def test_deploy(self, mock__get_provider, mock__deploy_first,
|
||||
mock_lxc_host, mock_get_script_path, mock_open):
|
||||
mock_open.return_value = "fs"
|
||||
fake_containers = ((mock.Mock(), mock.Mock()),
|
||||
(mock.Mock(), mock.Mock()))
|
||||
fake_hosts = m_LxcHost.side_effect = [mock.Mock(), mock.Mock()]
|
||||
fake_hosts = mock_lxc_host.side_effect = [mock.Mock(), mock.Mock()]
|
||||
fake_hosts[0].get_server_objects.return_value = fake_containers[0]
|
||||
fake_hosts[1].get_server_objects.return_value = fake_containers[1]
|
||||
fake_hosts[0]._port_cache = {1: 2, 3: 4}
|
||||
fake_hosts[1]._port_cache = {5: 6, 7: 8}
|
||||
fake_provider = m_get_provider.return_value = mock.Mock()
|
||||
fake_provider = mock__get_provider.return_value
|
||||
fake_servers = [mock.Mock(), mock.Mock()]
|
||||
fake_servers[0].get_credentials.return_value = "fc1"
|
||||
fake_servers[1].get_credentials.return_value = "fc2"
|
||||
@@ -147,17 +148,17 @@ class LxcEngineTestCase(test.TestCase):
|
||||
endpoint = self.engine.deploy()
|
||||
|
||||
self.assertIsInstance(endpoint["admin"], objects.Endpoint)
|
||||
LxcHost_calls = [
|
||||
lxc_host_calls = [
|
||||
mock.call(fake_servers[0], {"network": "10.128.128.0/28",
|
||||
"tunnel_to": ["1.1.1.1", "2.2.2.2"]}),
|
||||
mock.call(fake_servers[1], {"network": "10.128.128.16/28",
|
||||
"tunnel_to": ["1.1.1.1", "2.2.2.2"]})]
|
||||
self.assertEqual(LxcHost_calls, m_LxcHost.mock_calls)
|
||||
self.assertEqual(lxc_host_calls, mock_lxc_host.mock_calls)
|
||||
deploy_first_calls = [
|
||||
mock.call(fake_hosts[0], "rally-10-128-128-0-000", "ubuntu", None),
|
||||
mock.call(fake_hosts[1], "rally-10-128-128-16-000", "ubuntu",
|
||||
None)]
|
||||
self.assertEqual(deploy_first_calls, m_deploy_first.mock_calls)
|
||||
self.assertEqual(deploy_first_calls, mock__deploy_first.mock_calls)
|
||||
|
||||
host1_calls = [
|
||||
mock.call.create_clone("rally-10-128-128-0-001",
|
||||
@@ -174,7 +175,8 @@ class LxcEngineTestCase(test.TestCase):
|
||||
self.assertEqual(host1_calls, fake_hosts[0].mock_calls)
|
||||
self.assertEqual(host2_calls, fake_hosts[1].mock_calls)
|
||||
|
||||
self.assertEqual([mock.call("fake_sp", "rb")] * 4, m_open.mock_calls)
|
||||
self.assertEqual([mock.call("fake_sp", "rb")] * 4,
|
||||
mock_open.mock_calls)
|
||||
|
||||
for host in fake_containers:
|
||||
for container in host:
|
||||
@@ -184,10 +186,11 @@ class LxcEngineTestCase(test.TestCase):
|
||||
@mock.patch(MOD + "LxcEngine._get_provider")
|
||||
@mock.patch(MOD + "lxc.LxcHost")
|
||||
@mock.patch(MOD + "provider.Server.from_credentials")
|
||||
def test_cleanup(self, m_from_c, m_lxc_host, m_get_provider):
|
||||
m_get_provider.return_value = fake_provider = mock.Mock()
|
||||
m_lxc_host.side_effect = fake_hosts = [mock.Mock(), mock.Mock()]
|
||||
m_from_c.side_effect = ["s1", "s2"]
|
||||
def test_cleanup(self, mock_server_from_credentials, mock_lxc_host,
|
||||
mock__get_provider):
|
||||
mock__get_provider.return_value = fake_provider = mock.Mock()
|
||||
mock_lxc_host.side_effect = fake_hosts = [mock.Mock(), mock.Mock()]
|
||||
mock_server_from_credentials.side_effect = ["s1", "s2"]
|
||||
fake_resources = []
|
||||
for i in range(2):
|
||||
res = mock.Mock()
|
||||
@@ -196,8 +199,8 @@ class LxcEngineTestCase(test.TestCase):
|
||||
"forwarded_ports": [(1, 2), (3, 4)],
|
||||
"containers": "fake_containers"}
|
||||
fake_resources.append(res)
|
||||
with mock.patch.object(self.engine, "deployment") as m_deployment:
|
||||
m_deployment.get_resources.return_value = fake_resources
|
||||
with mock.patch.object(self.engine, "deployment") as mock_deployment:
|
||||
mock_deployment.get_resources.return_value = fake_resources
|
||||
self.engine.cleanup()
|
||||
|
||||
for host in fake_hosts:
|
||||
@@ -207,6 +210,6 @@ class LxcEngineTestCase(test.TestCase):
|
||||
mock.call.delete_tunnels()], host.mock_calls)
|
||||
|
||||
for res in fake_resources:
|
||||
m_deployment.assert_has_calls(mock.call.delete_resource(res.id))
|
||||
mock_deployment.assert_has_calls(mock.call.delete_resource(res.id))
|
||||
|
||||
fake_provider.destroy_servers.assert_called_once_with()
|
||||
|
@@ -24,9 +24,9 @@ from tests.unit import test
|
||||
MOD = "rally.deploy.engines.multihost."
|
||||
|
||||
|
||||
class TestMultihostEngine(test.TestCase):
|
||||
class MultihostEngineTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
super(TestMultihostEngine, self).setUp()
|
||||
super(MultihostEngineTestCase, self).setUp()
|
||||
self.config = {
|
||||
"type": "MultihostEngine",
|
||||
"controller": {
|
||||
@@ -54,7 +54,7 @@ class TestMultihostEngine(test.TestCase):
|
||||
|
||||
@mock.patch(MOD + "objects.Deployment")
|
||||
@mock.patch(MOD + "engine.EngineFactory")
|
||||
def test__deploy_node(self, fakeEngineFactory, fakeDeployment):
|
||||
def test__deploy_node(self, mock_engine_factory, mock_deployment):
|
||||
fake_endpoint = mock.Mock()
|
||||
fake_deployment = mock.Mock()
|
||||
fake_engine = mock.Mock()
|
||||
@@ -62,15 +62,15 @@ class TestMultihostEngine(test.TestCase):
|
||||
fake_engine.__exit__ = mock.Mock()
|
||||
fake_engine.make_deploy = mock.Mock(return_value=fake_endpoint)
|
||||
|
||||
fakeDeployment.return_value = fake_deployment
|
||||
fakeEngineFactory.get_engine = mock.Mock(return_value=fake_engine)
|
||||
mock_deployment.return_value = fake_deployment
|
||||
mock_engine_factory.get_engine = mock.Mock(return_value=fake_engine)
|
||||
|
||||
engine, endpoint = self.engine._deploy_node(self.config["nodes"][0])
|
||||
|
||||
self.assertEqual(fake_engine, engine)
|
||||
self.assertEqual(fake_endpoint, endpoint)
|
||||
|
||||
fakeDeployment.assert_called_once_with(
|
||||
mock_deployment.assert_called_once_with(
|
||||
config=self.config["nodes"][0],
|
||||
parent_uuid=self.deployment["uuid"])
|
||||
fake_engine.__enter__.assert_called_once_with()
|
||||
@@ -84,10 +84,10 @@ class TestMultihostEngine(test.TestCase):
|
||||
|
||||
@mock.patch(MOD + "MultihostEngine._deploy_node")
|
||||
@mock.patch(MOD + "MultihostEngine._update_controller_ip")
|
||||
def test_deploy(self, update_ip, deploy_node):
|
||||
def test_deploy(self, mock__update_controller_ip, mock__deploy_node):
|
||||
fake_endpoints = [mock.Mock()]
|
||||
fake_endpoints[0].auth_url = "http://h1.net"
|
||||
deploy_node.return_value = [mock.Mock(), fake_endpoints]
|
||||
mock__deploy_node.return_value = [mock.Mock(), fake_endpoints]
|
||||
|
||||
endpoints = self.engine.deploy()
|
||||
|
||||
@@ -97,18 +97,18 @@ class TestMultihostEngine(test.TestCase):
|
||||
mock.call(self.config["nodes"][0]),
|
||||
mock.call(self.config["nodes"][1]),
|
||||
]
|
||||
self.assertEqual(expected, update_ip.mock_calls)
|
||||
self.assertEqual(expected, mock__update_controller_ip.mock_calls)
|
||||
self.deployment.update_status.assert_called_once_with(
|
||||
consts._DeployStatus.DEPLOY_SUBDEPLOY)
|
||||
|
||||
@mock.patch("rally.api")
|
||||
@mock.patch(MOD + "db")
|
||||
def test_cleanup(self, m_db, m_api):
|
||||
m_db.deployment_list.return_value = [{"uuid": "uuid1"},
|
||||
{"uuid": "uuid2"}]
|
||||
def test_cleanup(self, mock_db, mock_api):
|
||||
mock_db.deployment_list.return_value = [{"uuid": "uuid1"},
|
||||
{"uuid": "uuid2"}]
|
||||
self.engine.cleanup()
|
||||
api_calls = [
|
||||
mock.call.Deployment.destroy("uuid1"),
|
||||
mock.call.Deployment.destroy("uuid2"),
|
||||
]
|
||||
self.assertEqual(api_calls, m_api.mock_calls)
|
||||
self.assertEqual(api_calls, mock_api.mock_calls)
|
||||
|
@@ -34,7 +34,8 @@ class TaskSampleTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine"
|
||||
"._validate_config_semantic")
|
||||
def test_schema_is_valid(self, mock_semantic):
|
||||
def test_schema_is_valid(self,
|
||||
mock_benchmark_engine__validate_config_semantic):
|
||||
scenarios = set()
|
||||
|
||||
for dirname, dirnames, filenames in os.walk(self.samples_path):
|
||||
|
@@ -42,82 +42,83 @@ class DeploymentTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_create")
|
||||
def test_init_with_create(self, mock_create):
|
||||
mock_create.return_value = self.deployment
|
||||
def test_init_with_create(self, mock_deployment_create):
|
||||
mock_deployment_create.return_value = self.deployment
|
||||
deploy = objects.Deployment()
|
||||
mock_create.assert_called_once_with({})
|
||||
mock_deployment_create.assert_called_once_with({})
|
||||
self.assertEqual(deploy["uuid"], self.deployment["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_create")
|
||||
def test_init_without_create(self, mock_create):
|
||||
def test_init_without_create(self, mock_deployment_create):
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
self.assertFalse(mock_create.called)
|
||||
self.assertFalse(mock_deployment_create.called)
|
||||
self.assertEqual(deploy["uuid"], self.deployment["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_get")
|
||||
def test_get(self, mock_get):
|
||||
mock_get.return_value = self.deployment
|
||||
def test_get(self, mock_deployment_get):
|
||||
mock_deployment_get.return_value = self.deployment
|
||||
deploy = objects.Deployment.get(self.deployment["uuid"])
|
||||
mock_get.assert_called_once_with(self.deployment["uuid"])
|
||||
mock_deployment_get.assert_called_once_with(self.deployment["uuid"])
|
||||
self.assertEqual(deploy["uuid"], self.deployment["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_delete")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_create")
|
||||
def test_create_and_delete(self, mock_create, mock_delete):
|
||||
mock_create.return_value = self.deployment
|
||||
def test_create_and_delete(self, mock_deployment_create,
|
||||
mock_deployment_delete):
|
||||
mock_deployment_create.return_value = self.deployment
|
||||
deploy = objects.Deployment()
|
||||
deploy.delete()
|
||||
mock_delete.assert_called_once_with(self.deployment["uuid"])
|
||||
mock_deployment_delete.assert_called_once_with(self.deployment["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_delete")
|
||||
def test_delete_by_uuid(self, mock_delete):
|
||||
def test_delete_by_uuid(self, mock_deployment_delete):
|
||||
objects.Deployment.delete_by_uuid(self.deployment["uuid"])
|
||||
mock_delete.assert_called_once_with(self.deployment["uuid"])
|
||||
mock_deployment_delete.assert_called_once_with(self.deployment["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_create")
|
||||
def test_update(self, mock_create, mock_update):
|
||||
mock_create.return_value = self.deployment
|
||||
mock_update.return_value = {"opt": "val2"}
|
||||
def test_update(self, mock_deployment_create, mock_deployment_update):
|
||||
mock_deployment_create.return_value = self.deployment
|
||||
mock_deployment_update.return_value = {"opt": "val2"}
|
||||
deploy = objects.Deployment(opt="val1")
|
||||
deploy._update({"opt": "val2"})
|
||||
mock_update.assert_called_once_with(self.deployment["uuid"],
|
||||
{"opt": "val2"})
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"], {"opt": "val2"})
|
||||
self.assertEqual(deploy["opt"], "val2")
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
def test_update_status(self, mock_update):
|
||||
mock_update.return_value = self.deployment
|
||||
def test_update_status(self, mock_deployment_update):
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
deploy.update_status(consts.DeployStatus.DEPLOY_FAILED)
|
||||
mock_update.assert_called_once_with(
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"],
|
||||
{"status": consts.DeployStatus.DEPLOY_FAILED},
|
||||
)
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
def test_update_name(self, mock_update):
|
||||
mock_update.return_value = self.deployment
|
||||
def test_update_name(self, mock_deployment_update):
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
deploy.update_name("new_name")
|
||||
mock_update.assert_called_once_with(
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"],
|
||||
{"name": "new_name"},
|
||||
)
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
def test_update_config(self, mock_update):
|
||||
mock_update.return_value = self.deployment
|
||||
def test_update_config(self, mock_deployment_update):
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
deploy.update_config({"opt": "val"})
|
||||
mock_update.assert_called_once_with(
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"],
|
||||
{"config": {"opt": "val"}},
|
||||
)
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
def test_update_endpoints(self, mock_update):
|
||||
mock_update.return_value = self.deployment
|
||||
def test_update_endpoints(self, mock_deployment_update):
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
endpoints = {
|
||||
"admin": objects.Endpoint("url", "user", "pwd", "tenant",
|
||||
@@ -134,7 +135,7 @@ class DeploymentTestCase(test.TestCase):
|
||||
for u in endpoints["users"]]
|
||||
|
||||
deploy.update_endpoints(endpoints)
|
||||
mock_update.assert_called_once_with(
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"],
|
||||
{
|
||||
"admin": endpoints["admin"].to_dict(include_permission=True),
|
||||
@@ -142,21 +143,21 @@ class DeploymentTestCase(test.TestCase):
|
||||
})
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
def test_update_empty_endpoints(self, mock_update):
|
||||
mock_update.return_value = self.deployment
|
||||
def test_update_empty_endpoints(self, mock_deployment_update):
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
deploy.update_endpoints({})
|
||||
mock_update.assert_called_once_with(self.deployment["uuid"],
|
||||
{"admin": {}, "users": []})
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"], {"admin": {}, "users": []})
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.resource_create")
|
||||
def test_add_resource(self, mock_create):
|
||||
mock_create.return_value = self.resource
|
||||
def test_add_resource(self, mock_resource_create):
|
||||
mock_resource_create.return_value = self.resource
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
resource = deploy.add_resource("provider", type="some",
|
||||
info={"key": "value"})
|
||||
self.assertEqual(resource["id"], self.resource["id"])
|
||||
mock_create.assert_called_once_with({
|
||||
mock_resource_create.assert_called_once_with({
|
||||
"deployment_uuid": self.deployment["uuid"],
|
||||
"provider_name": "provider",
|
||||
"type": "some",
|
||||
@@ -164,13 +165,13 @@ class DeploymentTestCase(test.TestCase):
|
||||
})
|
||||
|
||||
@mock.patch("rally.objects.task.db.resource_delete")
|
||||
def test_delete(self, mock_delete):
|
||||
def test_delete(self, mock_resource_delete):
|
||||
objects.Deployment.delete_resource(42)
|
||||
mock_delete.assert_called_once_with(42)
|
||||
mock_resource_delete.assert_called_once_with(42)
|
||||
|
||||
@mock.patch("rally.objects.task.db.resource_get_all")
|
||||
def test_get_resources(self, mock_get_all):
|
||||
mock_get_all.return_value = [self.resource]
|
||||
def test_get_resources(self, mock_resource_get_all):
|
||||
mock_resource_get_all.return_value = [self.resource]
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
resources = deploy.get_resources(provider_name="provider", type="some")
|
||||
self.assertEqual(len(resources), 1)
|
||||
@@ -178,12 +179,12 @@ class DeploymentTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.objects.deploy.datetime.datetime")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
def test_update_set_started(self, mock_update, mock_datetime):
|
||||
def test_update_set_started(self, mock_deployment_update, mock_datetime):
|
||||
mock_datetime.now = mock.Mock(return_value="fake_time")
|
||||
mock_update.return_value = self.deployment
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
deploy.set_started()
|
||||
mock_update.assert_called_once_with(
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"],
|
||||
{"started_at": "fake_time",
|
||||
"status": consts.DeployStatus.DEPLOY_STARTED}
|
||||
@@ -191,12 +192,12 @@ class DeploymentTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.objects.deploy.datetime.datetime")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
def test_update_set_completed(self, mock_update, mock_datetime):
|
||||
def test_update_set_completed(self, mock_deployment_update, mock_datetime):
|
||||
mock_datetime.now = mock.Mock(return_value="fake_time")
|
||||
mock_update.return_value = self.deployment
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
deploy = objects.Deployment(deployment=self.deployment)
|
||||
deploy.set_completed()
|
||||
mock_update.assert_called_once_with(
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment["uuid"],
|
||||
{"completed_at": "fake_time",
|
||||
"status": consts.DeployStatus.DEPLOY_FINISHED}
|
||||
|
@@ -34,62 +34,65 @@ class TaskTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_create")
|
||||
def test_init_with_create(self, mock_create):
|
||||
mock_create.return_value = self.task
|
||||
def test_init_with_create(self, mock_task_create):
|
||||
mock_task_create.return_value = self.task
|
||||
task = objects.Task(status=consts.TaskStatus.FAILED)
|
||||
mock_create.assert_called_once_with({
|
||||
mock_task_create.assert_called_once_with({
|
||||
"status": consts.TaskStatus.FAILED})
|
||||
self.assertEqual(task["uuid"], self.task["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_create")
|
||||
def test_init_without_create(self, mock_create):
|
||||
def test_init_without_create(self, mock_task_create):
|
||||
task = objects.Task(task=self.task)
|
||||
self.assertFalse(mock_create.called)
|
||||
self.assertFalse(mock_task_create.called)
|
||||
self.assertEqual(task["uuid"], self.task["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.task.uuid.uuid4", return_value="some_uuid")
|
||||
@mock.patch("rally.objects.task.db.task_create")
|
||||
def test_init_with_fake_true(self, mock_create, mock_uuid):
|
||||
def test_init_with_fake_true(self, mock_task_create, mock_uuid4):
|
||||
task = objects.Task(fake=True)
|
||||
self.assertFalse(mock_create.called)
|
||||
self.assertTrue(mock_uuid.called)
|
||||
self.assertEqual(task["uuid"], mock_uuid.return_value)
|
||||
self.assertFalse(mock_task_create.called)
|
||||
self.assertTrue(mock_uuid4.called)
|
||||
self.assertEqual(task["uuid"], mock_uuid4.return_value)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_get")
|
||||
def test_get(self, mock_get):
|
||||
mock_get.return_value = self.task
|
||||
def test_get(self, mock_task_get):
|
||||
mock_task_get.return_value = self.task
|
||||
task = objects.Task.get(self.task["uuid"])
|
||||
mock_get.assert_called_once_with(self.task["uuid"])
|
||||
mock_task_get.assert_called_once_with(self.task["uuid"])
|
||||
self.assertEqual(task["uuid"], self.task["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_delete")
|
||||
@mock.patch("rally.objects.task.db.task_create")
|
||||
def test_create_and_delete(self, mock_create, mock_delete):
|
||||
mock_create.return_value = self.task
|
||||
def test_create_and_delete(self, mock_task_create, mock_task_delete):
|
||||
mock_task_create.return_value = self.task
|
||||
task = objects.Task()
|
||||
task.delete()
|
||||
mock_delete.assert_called_once_with(self.task["uuid"], status=None)
|
||||
mock_task_delete.assert_called_once_with(
|
||||
self.task["uuid"], status=None)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_delete")
|
||||
@mock.patch("rally.objects.task.db.task_create")
|
||||
def test_create_and_delete_status(self, mock_create, mock_delete):
|
||||
mock_create.return_value = self.task
|
||||
def test_create_and_delete_status(self, mock_task_create,
|
||||
mock_task_delete):
|
||||
mock_task_create.return_value = self.task
|
||||
task = objects.Task()
|
||||
task.delete(status=consts.TaskStatus.FINISHED)
|
||||
mock_delete.assert_called_once_with(self.task["uuid"],
|
||||
status=consts.TaskStatus.FINISHED)
|
||||
mock_task_delete.assert_called_once_with(
|
||||
self.task["uuid"], status=consts.TaskStatus.FINISHED)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_delete")
|
||||
def test_delete_by_uuid(self, mock_delete):
|
||||
def test_delete_by_uuid(self, mock_task_delete):
|
||||
objects.Task.delete_by_uuid(self.task["uuid"])
|
||||
mock_delete.assert_called_once_with(self.task["uuid"], status=None)
|
||||
mock_task_delete.assert_called_once_with(
|
||||
self.task["uuid"], status=None)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_delete")
|
||||
def test_delete_by_uuid_status(self, mock_delete):
|
||||
def test_delete_by_uuid_status(self, mock_task_delete):
|
||||
objects.Task.delete_by_uuid(self.task["uuid"],
|
||||
consts.TaskStatus.FINISHED)
|
||||
mock_delete.assert_called_once_with(self.task["uuid"],
|
||||
status=consts.TaskStatus.FINISHED)
|
||||
mock_task_delete.assert_called_once_with(
|
||||
self.task["uuid"], status=consts.TaskStatus.FINISHED)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_list",
|
||||
return_value=[{"uuid": "a",
|
||||
@@ -107,56 +110,57 @@ class TaskTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.task_update")
|
||||
@mock.patch("rally.objects.task.db.task_create")
|
||||
def test_update(self, mock_create, mock_update):
|
||||
mock_create.return_value = self.task
|
||||
mock_update.return_value = {"opt": "val2"}
|
||||
def test_update(self, mock_task_create, mock_task_update):
|
||||
mock_task_create.return_value = self.task
|
||||
mock_task_update.return_value = {"opt": "val2"}
|
||||
deploy = objects.Task(opt="val1")
|
||||
deploy._update({"opt": "val2"})
|
||||
mock_update.assert_called_once_with(self.task["uuid"],
|
||||
{"opt": "val2"})
|
||||
mock_task_update.assert_called_once_with(
|
||||
self.task["uuid"], {"opt": "val2"})
|
||||
self.assertEqual(deploy["opt"], "val2")
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_update")
|
||||
def test_update_status(self, mock_update):
|
||||
mock_update.return_value = self.task
|
||||
def test_update_status(self, mock_task_update):
|
||||
mock_task_update.return_value = self.task
|
||||
task = objects.Task(task=self.task)
|
||||
task.update_status(consts.TaskStatus.FINISHED)
|
||||
mock_update.assert_called_once_with(
|
||||
mock_task_update.assert_called_once_with(
|
||||
self.task["uuid"],
|
||||
{"status": consts.TaskStatus.FINISHED},
|
||||
)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_update")
|
||||
def test_update_verification_log(self, mock_update):
|
||||
mock_update.return_value = self.task
|
||||
def test_update_verification_log(self, mock_task_update):
|
||||
mock_task_update.return_value = self.task
|
||||
task = objects.Task(task=self.task)
|
||||
task.update_verification_log({"a": "fake"})
|
||||
mock_update.assert_called_once_with(
|
||||
mock_task_update.assert_called_once_with(
|
||||
self.task["uuid"],
|
||||
{"verification_log": json.dumps({"a": "fake"})}
|
||||
)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_result_get_all_by_uuid",
|
||||
return_value="foo_results")
|
||||
def test_get_results(self, mock_get):
|
||||
def test_get_results(self, mock_task_result_get_all_by_uuid):
|
||||
task = objects.Task(task=self.task)
|
||||
results = task.get_results()
|
||||
mock_get.assert_called_once_with(self.task["uuid"])
|
||||
mock_task_result_get_all_by_uuid.assert_called_once_with(
|
||||
self.task["uuid"])
|
||||
self.assertEqual(results, "foo_results")
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_result_create")
|
||||
def test_append_results(self, mock_append_results):
|
||||
def test_append_results(self, mock_task_result_create):
|
||||
task = objects.Task(task=self.task)
|
||||
task.append_results("opt", "val")
|
||||
mock_append_results.assert_called_once_with(self.task["uuid"],
|
||||
"opt", "val")
|
||||
mock_task_result_create.assert_called_once_with(
|
||||
self.task["uuid"], "opt", "val")
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_update")
|
||||
def test_set_failed(self, mock_update):
|
||||
mock_update.return_value = self.task
|
||||
def test_set_failed(self, mock_task_update):
|
||||
mock_task_update.return_value = self.task
|
||||
task = objects.Task(task=self.task)
|
||||
task.set_failed()
|
||||
mock_update.assert_called_once_with(
|
||||
mock_task_update.assert_called_once_with(
|
||||
self.task["uuid"],
|
||||
{"status": consts.TaskStatus.FAILED, "verification_log": "\"\""},
|
||||
)
|
||||
|
@@ -38,43 +38,46 @@ class VerificationTestCase(test.TestCase):
|
||||
"time": "0.29"}]}}
|
||||
|
||||
@mock.patch("rally.objects.verification.db.verification_create")
|
||||
def test_init_with_create(self, mock_create):
|
||||
def test_init_with_create(self, mock_verification_create):
|
||||
objects.Verification(deployment_uuid="some_deployment_uuid")
|
||||
mock_create.assert_called_once_with("some_deployment_uuid")
|
||||
mock_verification_create.assert_called_once_with(
|
||||
"some_deployment_uuid")
|
||||
|
||||
@mock.patch("rally.objects.verification.db.verification_create")
|
||||
def test_init_without_create(self, mock_create):
|
||||
def test_init_without_create(self, mock_verification_create):
|
||||
verification = objects.Verification(db_object=self.db_obj)
|
||||
|
||||
self.assertEqual(0, mock_create.call_count)
|
||||
self.assertEqual(0, mock_verification_create.call_count)
|
||||
self.assertEqual(self.db_obj["failures"], verification.failures)
|
||||
self.assertEqual(self.db_obj["tests"], verification.tests)
|
||||
self.assertEqual(self.db_obj["errors"], verification.errors)
|
||||
self.assertEqual(self.db_obj["time"], verification.time)
|
||||
|
||||
@mock.patch("rally.objects.verification.db.verification_get")
|
||||
def test_get(self, mock_get):
|
||||
def test_get(self, mock_verification_get):
|
||||
objects.Verification.get(self.db_obj["id"])
|
||||
mock_get.assert_called_once_with(self.db_obj["id"])
|
||||
mock_verification_get.assert_called_once_with(self.db_obj["id"])
|
||||
|
||||
@mock.patch("rally.objects.verification.db.verification_delete")
|
||||
@mock.patch("rally.objects.verification.db.verification_create")
|
||||
def test_create_and_delete(self, mock_create, mock_delete):
|
||||
def test_create_and_delete(self, mock_verification_create,
|
||||
mock_verification_delete):
|
||||
verification = objects.Verification(db_object=self.db_obj)
|
||||
verification.delete()
|
||||
mock_delete.assert_called_once_with(self.db_obj["uuid"])
|
||||
mock_verification_delete.assert_called_once_with(self.db_obj["uuid"])
|
||||
|
||||
@mock.patch("rally.objects.verification.db.verification_update")
|
||||
def test_set_failed(self, mock_update):
|
||||
mock_update.return_value = self.db_obj
|
||||
def test_set_failed(self, mock_verification_update):
|
||||
mock_verification_update.return_value = self.db_obj
|
||||
verification = objects.Verification(db_object=self.db_obj)
|
||||
verification.set_failed()
|
||||
mock_update.assert_called_once_with(self.db_obj["uuid"],
|
||||
{"status": "failed"})
|
||||
mock_verification_update.assert_called_once_with(
|
||||
self.db_obj["uuid"], {"status": "failed"})
|
||||
|
||||
@mock.patch("rally.objects.verification.db.verification_result_create")
|
||||
@mock.patch("rally.objects.verification.db.verification_update")
|
||||
def test_finish_verification(self, mock_update, mock_create):
|
||||
def test_finish_verification(self, mock_verification_update,
|
||||
mock_verification_result_create):
|
||||
verification = objects.Verification(db_object=self.db_obj)
|
||||
fake_results = fakes.get_fake_test_case()
|
||||
verification.finish_verification(
|
||||
@@ -83,8 +86,10 @@ class VerificationTestCase(test.TestCase):
|
||||
|
||||
expected_values = {"status": "finished"}
|
||||
expected_values.update(fake_results["total"])
|
||||
mock_update.assert_called_with(self.db_obj["uuid"], expected_values)
|
||||
mock_verification_update.assert_called_with(
|
||||
self.db_obj["uuid"], expected_values)
|
||||
|
||||
expected_data = fake_results["total"].copy()
|
||||
expected_data["test_cases"] = fake_results["test_cases"]
|
||||
mock_create.assert_called_once_with(verification.uuid, expected_data)
|
||||
mock_verification_result_create.assert_called_once_with(
|
||||
verification.uuid, expected_data)
|
||||
|
@@ -51,7 +51,7 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
|
||||
@mock.patch(RUNNERS + "constant.threading.Thread")
|
||||
@mock.patch(RUNNERS + "constant.multiprocessing.Queue")
|
||||
@mock.patch(RUNNERS + "constant.runner")
|
||||
def test__worker_process(self, mock_base, mock_queue, mock_thread,
|
||||
def test__worker_process(self, mock_runner, mock_queue, mock_thread,
|
||||
mock_time):
|
||||
|
||||
mock_thread_instance = mock.MagicMock(
|
||||
@@ -76,18 +76,18 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
|
||||
self.assertEqual(times, mock_thread.call_count)
|
||||
self.assertEqual(times, mock_thread_instance.start.call_count)
|
||||
self.assertEqual(times, mock_thread_instance.join.call_count)
|
||||
self.assertEqual(times, mock_base._get_scenario_context.call_count)
|
||||
self.assertEqual(times, mock_runner._get_scenario_context.call_count)
|
||||
|
||||
for i in range(times):
|
||||
scenario_context = mock_base._get_scenario_context(context)
|
||||
scenario_context = mock_runner._get_scenario_context(context)
|
||||
call = mock.call(args=(mock_queue,
|
||||
(i, "Dummy", "dummy",
|
||||
scenario_context, ())),
|
||||
target=mock_base._worker_thread)
|
||||
target=mock_runner._worker_thread)
|
||||
self.assertIn(call, mock_thread.mock_calls)
|
||||
|
||||
@mock.patch(RUNNERS_BASE + "_run_scenario_once")
|
||||
def test__worker_thread(self, mock_run_scenario_once):
|
||||
def test__worker_thread(self, mock__run_scenario_once):
|
||||
mock_queue = mock.MagicMock()
|
||||
|
||||
args = ("some_args",)
|
||||
@@ -97,7 +97,7 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
|
||||
self.assertEqual(1, mock_queue.put.call_count)
|
||||
|
||||
expected_calls = [mock.call(("some_args",))]
|
||||
self.assertEqual(expected_calls, mock_run_scenario_once.mock_calls)
|
||||
self.assertEqual(expected_calls, mock__run_scenario_once.mock_calls)
|
||||
|
||||
def test__run_scenario(self):
|
||||
runner_obj = constant.ConstantScenarioRunner(self.task, self.config)
|
||||
@@ -132,9 +132,12 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
|
||||
@mock.patch(RUNNERS +
|
||||
"constant.ConstantScenarioRunner._create_process_pool")
|
||||
@mock.patch(RUNNERS + "constant.ConstantScenarioRunner._join_processes")
|
||||
def test_that_cpu_count_is_adjusted_properly(self, mock_join_processes,
|
||||
mock_create_pool, mock_log,
|
||||
mock_cpu_count, mock_queue):
|
||||
def test_that_cpu_count_is_adjusted_properly(
|
||||
self,
|
||||
mock__join_processes,
|
||||
mock__create_process_pool,
|
||||
mock__log_debug_info,
|
||||
mock_cpu_count, mock_queue):
|
||||
|
||||
samples = [
|
||||
{
|
||||
@@ -187,10 +190,10 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
|
||||
]
|
||||
|
||||
for sample in samples:
|
||||
mock_log.reset_mock()
|
||||
mock__log_debug_info.reset_mock()
|
||||
mock_cpu_count.reset_mock()
|
||||
mock_create_pool.reset_mock()
|
||||
mock_join_processes.reset_mock()
|
||||
mock__create_process_pool.reset_mock()
|
||||
mock__join_processes.reset_mock()
|
||||
mock_queue.reset_mock()
|
||||
|
||||
mock_cpu_count.return_value = sample["real_cpu"]
|
||||
@@ -202,7 +205,7 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
|
||||
self.args)
|
||||
|
||||
mock_cpu_count.assert_called_once_with()
|
||||
mock_log.assert_called_once_with(
|
||||
mock__log_debug_info.assert_called_once_with(
|
||||
times=sample["input"]["times"],
|
||||
concurrency=sample["input"]["concurrency"],
|
||||
timeout=0,
|
||||
@@ -212,12 +215,12 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
|
||||
sample["expected"]["concurrency_per_worker"]),
|
||||
concurrency_overhead=(
|
||||
sample["expected"]["concurrency_overhead"]))
|
||||
args, kwargs = mock_create_pool.call_args
|
||||
args, kwargs = mock__create_process_pool.call_args
|
||||
self.assertIn(sample["expected"]["processes_to_start"], args)
|
||||
self.assertIn(constant._worker_process, args)
|
||||
mock_join_processes.assert_called_once_with(
|
||||
mock_create_pool(),
|
||||
mock_queue())
|
||||
mock__join_processes.assert_called_once_with(
|
||||
mock__create_process_pool.return_value,
|
||||
mock_queue.return_value)
|
||||
|
||||
def test_abort(self):
|
||||
runner_obj = constant.ConstantScenarioRunner(self.task, self.config)
|
||||
|
@@ -68,7 +68,7 @@ class RPSScenarioRunnerTestCase(test.TestCase):
|
||||
@mock.patch(RUNNERS + "rps.threading.Thread")
|
||||
@mock.patch(RUNNERS + "rps.multiprocessing.Queue")
|
||||
@mock.patch(RUNNERS + "rps.runner")
|
||||
def test__worker_process(self, mock_base, mock_queue, mock_thread,
|
||||
def test__worker_process(self, mock_runner, mock_queue, mock_thread,
|
||||
mock_time, mock_log):
|
||||
|
||||
def time_side():
|
||||
@@ -107,18 +107,18 @@ class RPSScenarioRunnerTestCase(test.TestCase):
|
||||
self.assertEqual(times - 1, mock_time.sleep.call_count)
|
||||
self.assertEqual(times, mock_thread_instance.isAlive.call_count)
|
||||
self.assertEqual(times * 4 - 1, mock_time.time.count)
|
||||
self.assertEqual(times, mock_base._get_scenario_context.call_count)
|
||||
self.assertEqual(times, mock_runner._get_scenario_context.call_count)
|
||||
|
||||
for i in range(times):
|
||||
scenario_context = mock_base._get_scenario_context(context)
|
||||
scenario_context = mock_runner._get_scenario_context(context)
|
||||
call = mock.call(args=(mock_queue,
|
||||
(i, "Dummy", "dummy",
|
||||
scenario_context, ())),
|
||||
target=mock_base._worker_thread)
|
||||
target=mock_runner._worker_thread)
|
||||
self.assertIn(call, mock_thread.mock_calls)
|
||||
|
||||
@mock.patch(RUNNERS + "rps.runner._run_scenario_once")
|
||||
def test__worker_thread(self, mock_run_scenario_once):
|
||||
def test__worker_thread(self, mock__run_scenario_once):
|
||||
mock_queue = mock.MagicMock()
|
||||
|
||||
args = ("some_args",)
|
||||
@@ -128,7 +128,7 @@ class RPSScenarioRunnerTestCase(test.TestCase):
|
||||
self.assertEqual(1, mock_queue.put.call_count)
|
||||
|
||||
expected_calls = [mock.call(("some_args",))]
|
||||
self.assertEqual(expected_calls, mock_run_scenario_once.mock_calls)
|
||||
self.assertEqual(expected_calls, mock__run_scenario_once.mock_calls)
|
||||
|
||||
@mock.patch(RUNNERS + "rps.time.sleep")
|
||||
def test__run_scenario(self, mock_sleep):
|
||||
@@ -181,9 +181,9 @@ class RPSScenarioRunnerTestCase(test.TestCase):
|
||||
@mock.patch(RUNNERS +
|
||||
"rps.RPSScenarioRunner._create_process_pool")
|
||||
@mock.patch(RUNNERS + "rps.RPSScenarioRunner._join_processes")
|
||||
def test_that_cpu_count_is_adjusted_properly(self, mock_join_processes,
|
||||
mock_create_pool, mock_log,
|
||||
mock_cpu_count, mock_queue):
|
||||
def test_that_cpu_count_is_adjusted_properly(
|
||||
self, mock__join_processes, mock__create_process_pool,
|
||||
mock__log_debug_info, mock_cpu_count, mock_queue):
|
||||
context = fakes.FakeUserContext({}).context
|
||||
context["task"] = {"uuid": "fake_uuid"}
|
||||
|
||||
@@ -250,10 +250,10 @@ class RPSScenarioRunnerTestCase(test.TestCase):
|
||||
]
|
||||
|
||||
for sample in samples:
|
||||
mock_log.reset_mock()
|
||||
mock__log_debug_info.reset_mock()
|
||||
mock_cpu_count.reset_mock()
|
||||
mock_create_pool.reset_mock()
|
||||
mock_join_processes.reset_mock()
|
||||
mock__create_process_pool.reset_mock()
|
||||
mock__join_processes.reset_mock()
|
||||
mock_queue.reset_mock()
|
||||
|
||||
mock_cpu_count.return_value = sample["real_cpu"]
|
||||
@@ -263,7 +263,7 @@ class RPSScenarioRunnerTestCase(test.TestCase):
|
||||
runner_obj._run_scenario(fakes.FakeScenario, "do_it", context, {})
|
||||
|
||||
mock_cpu_count.assert_called_once_with()
|
||||
mock_log.assert_called_once_with(
|
||||
mock__log_debug_info.assert_called_once_with(
|
||||
times=sample["input"]["times"],
|
||||
timeout=0,
|
||||
max_cpu_used=sample["expected"]["max_cpu_used"],
|
||||
@@ -275,12 +275,12 @@ class RPSScenarioRunnerTestCase(test.TestCase):
|
||||
sample["expected"]["concurrency_per_worker"]),
|
||||
concurrency_overhead=(
|
||||
sample["expected"]["concurrency_overhead"]))
|
||||
args, kwargs = mock_create_pool.call_args
|
||||
args, kwargs = mock__create_process_pool.call_args
|
||||
self.assertIn(sample["expected"]["processes_to_start"], args)
|
||||
self.assertIn(rps._worker_process, args)
|
||||
mock_join_processes.assert_called_once_with(
|
||||
mock_create_pool(),
|
||||
mock_queue())
|
||||
mock__join_processes.assert_called_once_with(
|
||||
mock__create_process_pool.return_value,
|
||||
mock_queue.return_value)
|
||||
|
||||
def test_abort(self):
|
||||
context = fakes.FakeUserContext({}).context
|
||||
|
@@ -26,11 +26,11 @@ class SerialScenarioRunnerTestCase(test.TestCase):
|
||||
super(SerialScenarioRunnerTestCase, self).setUp()
|
||||
|
||||
@mock.patch("rally.benchmark.runner._run_scenario_once")
|
||||
def test__run_scenario(self, mock_run_once):
|
||||
def test__run_scenario(self, mock__run_scenario_once):
|
||||
times = 5
|
||||
result = {"duration": 10, "idle_duration": 0, "error": [],
|
||||
"scenario_output": {}, "atomic_actions": {}}
|
||||
mock_run_once.return_value = result
|
||||
mock__run_scenario_once.return_value = result
|
||||
expected_results = [result for i in range(times)]
|
||||
|
||||
runner = serial.SerialScenarioRunner(mock.MagicMock(),
|
||||
|
@@ -19,7 +19,7 @@ from tests.unit import test
|
||||
|
||||
class DummyTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.common.scenarios.dummy.dummy.time")
|
||||
@mock.patch("rally.plugins.common.scenarios.dummy.dummy.time.sleep")
|
||||
def test_dummy(self, mock_sleep):
|
||||
scenario = dummy.Dummy()
|
||||
scenario.sleep_between = mock.MagicMock()
|
||||
@@ -27,16 +27,16 @@ class DummyTestCase(test.TestCase):
|
||||
self.assertFalse(mock_sleep.sleep.called)
|
||||
|
||||
scenario.dummy(sleep=10)
|
||||
mock_sleep.sleep.assert_called_once_with(10)
|
||||
mock_sleep.assert_called_once_with(10)
|
||||
|
||||
@mock.patch("rally.plugins.common.scenarios.dummy.dummy.time")
|
||||
@mock.patch("rally.plugins.common.scenarios.dummy.dummy.time.sleep")
|
||||
def test_dummy_exception(self, mock_sleep):
|
||||
scenario = dummy.Dummy()
|
||||
|
||||
size_of_message = 5
|
||||
self.assertRaises(dummy.DummyScenarioException,
|
||||
scenario.dummy_exception, size_of_message, sleep=10)
|
||||
mock_sleep.sleep.assert_called_once_with(10)
|
||||
mock_sleep.assert_called_once_with(10)
|
||||
|
||||
def test_dummy_exception_probability(self):
|
||||
scenario = dummy.Dummy()
|
||||
|
@@ -19,20 +19,21 @@ from tests.unit import test
|
||||
SCN = "rally.plugins.common.scenarios"
|
||||
|
||||
|
||||
class RequestsTestCase(test.TestCase):
|
||||
class RequestScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.requests.utils.RequestScenario._check_request" % SCN)
|
||||
def test_check_request(self, mock_check):
|
||||
def test_check_request(self, mock__check_request):
|
||||
Requests = http_requests.HttpRequests()
|
||||
Requests.check_request("sample_url", "GET", 200)
|
||||
mock_check.assert_called_once_with("sample_url", "GET", 200)
|
||||
mock__check_request.assert_called_once_with("sample_url", "GET", 200)
|
||||
|
||||
@mock.patch("%s.requests.utils.RequestScenario._check_request" % SCN)
|
||||
@mock.patch("%s.requests.http_requests.random.choice" % SCN)
|
||||
def test_check_random_request(self, mock_random_choice, mock_check):
|
||||
mock_random_choice.return_value = {"url": "sample_url"}
|
||||
def test_check_random_request(self, mock_choice, mock__check_request):
|
||||
mock_choice.return_value = {"url": "sample_url"}
|
||||
Requests = http_requests.HttpRequests()
|
||||
Requests.check_random_request(status_code=200,
|
||||
requests=[{"url": "sample_url"}])
|
||||
mock_random_choice.assert_called_once_with([{"url": "sample_url"}])
|
||||
mock_check.assert_called_once_with(status_code=200, url="sample_url")
|
||||
mock_choice.assert_called_once_with([{"url": "sample_url"}])
|
||||
mock__check_request.assert_called_once_with(
|
||||
status_code=200, url="sample_url")
|
||||
|
@@ -20,18 +20,18 @@ from tests.unit import test
|
||||
class RequestsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("requests.request")
|
||||
def test__check_request(self, mock_requests):
|
||||
mock_requests.return_value = mock.MagicMock(status_code=200)
|
||||
def test__check_request(self, mock_request):
|
||||
mock_request.return_value = mock.MagicMock(status_code=200)
|
||||
scenario = utils.RequestScenario()
|
||||
scenario._check_request(status_code=200, url="sample", method="GET")
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"requests.check_request")
|
||||
mock_requests.assert_called_once_with("GET", "sample")
|
||||
mock_request.assert_called_once_with("GET", "sample")
|
||||
|
||||
@mock.patch("requests.request")
|
||||
def test_check_wrong_request(self, mock_requests):
|
||||
mock_requests.return_value = mock.MagicMock(status_code=200)
|
||||
def test_check_wrong_request(self, mock_request):
|
||||
mock_request.return_value = mock.MagicMock(status_code=200)
|
||||
scenario = utils.RequestScenario()
|
||||
|
||||
self.assertRaises(ValueError, scenario._check_request,
|
||||
|
@@ -64,10 +64,10 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
self.assertEqual(resource.id, manager.id())
|
||||
|
||||
@mock.patch("%s.ResourceManager._manager" % BASE)
|
||||
def test_is_deleted(self, mock_manager):
|
||||
def test_is_deleted(self, mock_resource_manager__manager):
|
||||
raw_res = mock.MagicMock(status="deleted")
|
||||
mock_manager().get.return_value = raw_res
|
||||
mock_manager.reset_mock()
|
||||
mock_resource_manager__manager().get.return_value = raw_res
|
||||
mock_resource_manager__manager.reset_mock()
|
||||
|
||||
resource = mock.MagicMock(id="test_id")
|
||||
|
||||
@@ -78,12 +78,12 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
raw_res.status = "ACTIVE"
|
||||
self.assertFalse(manager.is_deleted())
|
||||
|
||||
mock_manager.assert_has_calls(
|
||||
mock_resource_manager__manager.assert_has_calls(
|
||||
[mock.call(), mock.call().get(resource.id)] * 3)
|
||||
self.assertEqual(mock_manager.call_count, 3)
|
||||
self.assertEqual(mock_resource_manager__manager.call_count, 3)
|
||||
|
||||
@mock.patch("%s.ResourceManager._manager" % BASE)
|
||||
def test_is_deleted_exceptions(self, mock_manager):
|
||||
def test_is_deleted_exceptions(self, mock_resource_manager__manager):
|
||||
|
||||
class Fake500Exc(Exception):
|
||||
code = 500
|
||||
@@ -91,7 +91,8 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
class Fake404Exc(Exception):
|
||||
code = 404
|
||||
|
||||
mock_manager.side_effect = [Exception, Fake500Exc, Fake404Exc]
|
||||
mock_resource_manager__manager.side_effect = [
|
||||
Exception, Fake500Exc, Fake404Exc]
|
||||
|
||||
manager = base.ResourceManager(resource=mock.MagicMock())
|
||||
self.assertFalse(manager.is_deleted())
|
||||
@@ -99,16 +100,17 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
@mock.patch("%s.ResourceManager._manager" % BASE)
|
||||
def test_delete(self, mock_manager):
|
||||
def test_delete(self, mock_resource_manager__manager):
|
||||
res = mock.MagicMock(id="test_id")
|
||||
|
||||
manager = base.ResourceManager(resource=res)
|
||||
manager.delete()
|
||||
|
||||
mock_manager.assert_has_calls(
|
||||
mock_resource_manager__manager.assert_has_calls(
|
||||
[mock.call(), mock.call().delete(res.id)])
|
||||
|
||||
@mock.patch("%s.ResourceManager._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_resource_manager__manager):
|
||||
base.ResourceManager().list()
|
||||
mock_manager.assert_has_calls([mock.call(), mock.call().list()])
|
||||
mock_resource_manager__manager.assert_has_calls(
|
||||
[mock.call(), mock.call().list()])
|
||||
|
@@ -47,7 +47,7 @@ class AdminCleanupTestCase(test.TestCase):
|
||||
@mock.patch("%s.manager.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
@mock.patch("%s.manager.SeekAndDestroy" % BASE)
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_res_mgr):
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_resource_managers):
|
||||
|
||||
ctx = {
|
||||
"config": {"admin_cleanup": ["a", "b"]},
|
||||
@@ -60,13 +60,17 @@ class AdminCleanupTestCase(test.TestCase):
|
||||
admin_cleanup.setup()
|
||||
admin_cleanup.cleanup()
|
||||
|
||||
mock_find_res_mgr.assert_called_once_with(["a", "b"], True)
|
||||
mock_find_resource_managers.assert_called_once_with(["a", "b"], True)
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(mock_find_res_mgr.return_value[0], ctx["admin"],
|
||||
ctx["users"]),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0],
|
||||
ctx["admin"],
|
||||
ctx["users"]),
|
||||
mock.call().exterminate(),
|
||||
mock.call(mock_find_res_mgr.return_value[1], ctx["admin"],
|
||||
ctx["users"]),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1],
|
||||
ctx["admin"],
|
||||
ctx["users"]),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
||||
@@ -95,7 +99,7 @@ class UserCleanupTestCase(test.TestCase):
|
||||
@mock.patch("%s.manager.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
@mock.patch("%s.manager.SeekAndDestroy" % BASE)
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_res_mgr):
|
||||
def test_cleanup(self, mock_seek_and_destroy, mock_find_resource_managers):
|
||||
|
||||
ctx = {
|
||||
"config": {"cleanup": ["a", "b"]},
|
||||
@@ -107,11 +111,15 @@ class UserCleanupTestCase(test.TestCase):
|
||||
admin_cleanup.setup()
|
||||
admin_cleanup.cleanup()
|
||||
|
||||
mock_find_res_mgr.assert_called_once_with(["a", "b"], False)
|
||||
mock_find_resource_managers.assert_called_once_with(["a", "b"], False)
|
||||
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(mock_find_res_mgr.return_value[0], None, ctx["users"]),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0],
|
||||
None, ctx["users"]),
|
||||
mock.call().exterminate(),
|
||||
mock.call(mock_find_res_mgr.return_value[1], None, ctx["users"]),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1],
|
||||
None, ctx["users"]),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
@@ -107,7 +107,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
return mock_mgr
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
def test__gen_publisher_admin(self, mock_get_client):
|
||||
def test__gen_publisher_admin(self, mock__get_cached_client):
|
||||
mock_mgr = self._manager([Exception, Exception, [1, 2, 3]],
|
||||
_perform_for_admin_only=False)
|
||||
admin = mock.MagicMock()
|
||||
@@ -116,12 +116,13 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
|
||||
queue = []
|
||||
publish(queue)
|
||||
mock_get_client.assert_called_once_with(admin)
|
||||
mock_mgr.assert_called_once_with(admin=mock_get_client.return_value)
|
||||
mock__get_cached_client.assert_called_once_with(admin)
|
||||
mock_mgr.assert_called_once_with(
|
||||
admin=mock__get_cached_client.return_value)
|
||||
self.assertEqual(queue, [(admin, None, x) for x in range(1, 4)])
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
def test__gen_publisher_admin_only(self, mock_get_client):
|
||||
def test__gen_publisher_admin_only(self, mock__get_cached_client):
|
||||
mock_mgr = self._manager([Exception, Exception, [1, 2, 3]],
|
||||
_perform_for_admin_only=True)
|
||||
admin = mock.MagicMock()
|
||||
@@ -130,12 +131,13 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
|
||||
queue = []
|
||||
publish(queue)
|
||||
mock_get_client.assert_called_once_with(admin)
|
||||
mock_mgr.assert_called_once_with(admin=mock_get_client.return_value)
|
||||
mock__get_cached_client.assert_called_once_with(admin)
|
||||
mock_mgr.assert_called_once_with(
|
||||
admin=mock__get_cached_client.return_value)
|
||||
self.assertEqual(queue, [(admin, None, x) for x in range(1, 4)])
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
def test__gen_publisher_user_resource(self, mock_get_client):
|
||||
def test__gen_publisher_user_resource(self, mock__get_cached_client):
|
||||
mock_mgr = self._manager([Exception, Exception, [1, 2, 3],
|
||||
Exception, Exception, [4, 5]],
|
||||
_perform_for_admin_only=False,
|
||||
@@ -149,7 +151,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
queue = []
|
||||
publish(queue)
|
||||
|
||||
mock_client = mock_get_client.return_value
|
||||
mock_client = mock__get_cached_client.return_value
|
||||
mock_mgr.assert_has_calls([
|
||||
mock.call(admin=mock_client, user=mock_client,
|
||||
tenant_uuid=users[0]["tenant_id"]),
|
||||
@@ -161,7 +163,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
mock.call().list(),
|
||||
mock.call().list()
|
||||
])
|
||||
mock_get_client.assert_has_calls([
|
||||
mock__get_cached_client.assert_has_calls([
|
||||
mock.call(admin),
|
||||
mock.call(users[0]),
|
||||
mock.call(users[1])
|
||||
@@ -171,7 +173,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
self.assertEqual(queue, expected_queue)
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
def test__gen_publisher_tenant_resource(self, mock_get_client):
|
||||
def test__gen_publisher_tenant_resource(self, mock__get_cached_client):
|
||||
mock_mgr = self._manager([Exception, [1, 2, 3],
|
||||
Exception, Exception, Exception,
|
||||
["this shouldn't be in results"]],
|
||||
@@ -187,7 +189,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
queue = []
|
||||
publish(queue)
|
||||
|
||||
mock_client = mock_get_client.return_value
|
||||
mock_client = mock__get_cached_client.return_value
|
||||
mock_mgr.assert_has_calls([
|
||||
mock.call(admin=mock_client, user=mock_client,
|
||||
tenant_uuid=users[0]["tenant_id"]),
|
||||
@@ -199,7 +201,7 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
mock.call().list(),
|
||||
mock.call().list()
|
||||
])
|
||||
mock_get_client.assert_has_calls([
|
||||
mock__get_cached_client.assert_has_calls([
|
||||
mock.call(None),
|
||||
mock.call(users[0]),
|
||||
mock.call(users[2])
|
||||
@@ -208,7 +210,8 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._get_cached_client" % BASE)
|
||||
@mock.patch("%s.SeekAndDestroy._delete_single_resource" % BASE)
|
||||
def test__gen_consumer(self, mock_del_single_resource, mock_get_client):
|
||||
def test__gen_consumer(self, mock__delete_single_resource,
|
||||
mock__get_cached_client):
|
||||
mock_mgr = mock.MagicMock(__name__="Test")
|
||||
|
||||
consumer = manager.SeekAndDestroy(mock_mgr, None, None)._gen_consumer()
|
||||
@@ -220,45 +223,49 @@ class SeekAndDestroyTestCase(test.TestCase):
|
||||
consumer(cache, (admin, user1, "res"))
|
||||
mock_mgr.assert_called_once_with(
|
||||
resource="res",
|
||||
admin=mock_get_client.return_value,
|
||||
user=mock_get_client.return_value,
|
||||
admin=mock__get_cached_client.return_value,
|
||||
user=mock__get_cached_client.return_value,
|
||||
tenant_uuid=user1["tenant_id"])
|
||||
mock_get_client.assert_has_calls([
|
||||
mock__get_cached_client.assert_has_calls([
|
||||
mock.call(admin, cache=cache),
|
||||
mock.call(user1, cache=cache)
|
||||
])
|
||||
mock_del_single_resource.assert_called_once_with(mock_mgr.return_value)
|
||||
mock__delete_single_resource.assert_called_once_with(
|
||||
mock_mgr.return_value)
|
||||
|
||||
mock_mgr.reset_mock()
|
||||
mock_get_client.reset_mock()
|
||||
mock_del_single_resource.reset_mock()
|
||||
mock__get_cached_client.reset_mock()
|
||||
mock__delete_single_resource.reset_mock()
|
||||
|
||||
consumer(cache, (admin, None, "res2"))
|
||||
mock_mgr.assert_called_once_with(
|
||||
resource="res2",
|
||||
admin=mock_get_client.return_value,
|
||||
user=mock_get_client.return_value,
|
||||
admin=mock__get_cached_client.return_value,
|
||||
user=mock__get_cached_client.return_value,
|
||||
tenant_uuid=None)
|
||||
|
||||
mock_get_client.assert_has_calls([
|
||||
mock__get_cached_client.assert_has_calls([
|
||||
mock.call(admin, cache=cache),
|
||||
mock.call(None, cache=cache)
|
||||
])
|
||||
mock_del_single_resource.assert_called_once_with(mock_mgr.return_value)
|
||||
mock__delete_single_resource.assert_called_once_with(
|
||||
mock_mgr.return_value)
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy._gen_consumer" % BASE)
|
||||
@mock.patch("%s.SeekAndDestroy._gen_publisher" % BASE)
|
||||
@mock.patch("%s.broker.run" % BASE)
|
||||
def test_exterminate(self, mock_broker_run, mock_publisher, mock_consumer):
|
||||
def test_exterminate(self, mock_broker_run, mock__gen_publisher,
|
||||
mock__gen_consumer):
|
||||
|
||||
manager_cls = mock.MagicMock(_threads=5)
|
||||
manager.SeekAndDestroy(manager_cls, None, None).exterminate()
|
||||
|
||||
mock_publisher.assert_called_once_with()
|
||||
mock_consumer.assert_called_once_with()
|
||||
mock_broker_run.assert_called_once_with(mock_publisher.return_value,
|
||||
mock_consumer.return_value,
|
||||
consumers_count=5)
|
||||
mock__gen_publisher.assert_called_once_with()
|
||||
mock__gen_consumer.assert_called_once_with()
|
||||
mock_broker_run.assert_called_once_with(
|
||||
mock__gen_publisher.return_value,
|
||||
mock__gen_consumer.return_value,
|
||||
consumers_count=5)
|
||||
|
||||
|
||||
class ResourceManagerTestCase(test.TestCase):
|
||||
@@ -276,8 +283,8 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
mock_iter.reset_mock()
|
||||
|
||||
@mock.patch("%s.discover.itersubclasses" % BASE)
|
||||
def test_list_resource_names(self, mock_iter):
|
||||
mock_iter.return_value = [
|
||||
def test_list_resource_names(self, mock_itersubclasses):
|
||||
mock_itersubclasses.return_value = [
|
||||
self._get_res_mock(_service="fake", _resource="1",
|
||||
_admin_required=True),
|
||||
self._get_res_mock(_service="fake", _resource="2",
|
||||
@@ -287,14 +294,18 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
]
|
||||
|
||||
self._list_res_names_helper(
|
||||
["fake", "other", "fake.1", "fake.2", "other.2"], None, mock_iter)
|
||||
self._list_res_names_helper(["fake", "fake.1"], True, mock_iter)
|
||||
self._list_res_names_helper(["fake", "other", "fake.2", "other.2"],
|
||||
False, mock_iter)
|
||||
["fake", "other", "fake.1", "fake.2", "other.2"],
|
||||
None, mock_itersubclasses)
|
||||
self._list_res_names_helper(
|
||||
["fake", "fake.1"],
|
||||
True, mock_itersubclasses)
|
||||
self._list_res_names_helper(
|
||||
["fake", "other", "fake.2", "other.2"],
|
||||
False, mock_itersubclasses)
|
||||
|
||||
@mock.patch("%s.discover.itersubclasses" % BASE)
|
||||
def test_find_resource_managers(self, mock_iter):
|
||||
mock_iter.return_value = [
|
||||
def test_find_resource_managers(self, mock_itersubclasses):
|
||||
mock_itersubclasses.return_value = [
|
||||
self._get_res_mock(_service="fake", _resource="1", _order=1,
|
||||
_admin_required=True),
|
||||
self._get_res_mock(_service="fake", _resource="2", _order=3,
|
||||
@@ -303,36 +314,41 @@ class ResourceManagerTestCase(test.TestCase):
|
||||
_admin_required=False)
|
||||
]
|
||||
|
||||
self.assertEqual(mock_iter.return_value[0:2],
|
||||
self.assertEqual(mock_itersubclasses.return_value[0:2],
|
||||
manager.find_resource_managers(names=["fake"]))
|
||||
|
||||
self.assertEqual(mock_iter.return_value[0:1],
|
||||
self.assertEqual(mock_itersubclasses.return_value[0:1],
|
||||
manager.find_resource_managers(names=["fake.1"]))
|
||||
|
||||
self.assertEqual(
|
||||
[mock_iter.return_value[0], mock_iter.return_value[2],
|
||||
mock_iter.return_value[1]],
|
||||
[mock_itersubclasses.return_value[0],
|
||||
mock_itersubclasses.return_value[2],
|
||||
mock_itersubclasses.return_value[1]],
|
||||
manager.find_resource_managers(names=["fake", "other"]))
|
||||
|
||||
self.assertEqual(mock_iter.return_value[0:1],
|
||||
self.assertEqual(mock_itersubclasses.return_value[0:1],
|
||||
manager.find_resource_managers(names=["fake"],
|
||||
admin_required=True))
|
||||
self.assertEqual(mock_iter.return_value[1:2],
|
||||
self.assertEqual(mock_itersubclasses.return_value[1:2],
|
||||
manager.find_resource_managers(names=["fake"],
|
||||
admin_required=False))
|
||||
|
||||
@mock.patch("%s.SeekAndDestroy" % BASE)
|
||||
@mock.patch("%s.find_resource_managers" % BASE,
|
||||
return_value=[mock.MagicMock(), mock.MagicMock()])
|
||||
def test_cleanup(self, mock_find, mock_seek_and_destroy):
|
||||
def test_cleanup(self, mock_find_resource_managers, mock_seek_and_destroy):
|
||||
manager.cleanup(names=["a", "b"], admin_required=True,
|
||||
admin="admin", users=["user"])
|
||||
|
||||
mock_find.assert_called_once_with(["a", "b"], True)
|
||||
mock_find_resource_managers.assert_called_once_with(["a", "b"], True)
|
||||
|
||||
mock_seek_and_destroy.assert_has_calls([
|
||||
mock.call(mock_find.return_value[0], "admin", ["user"]),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[0], "admin", ["user"]
|
||||
),
|
||||
mock.call().exterminate(),
|
||||
mock.call(mock_find.return_value[1], "admin", ["user"]),
|
||||
mock.call(
|
||||
mock_find_resource_managers.return_value[1], "admin", ["user"]
|
||||
),
|
||||
mock.call().exterminate()
|
||||
])
|
||||
|
@@ -108,13 +108,13 @@ class NovaServerTestCase(test.TestCase):
|
||||
class NovaSecurityGroupTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_resource_manager__manager):
|
||||
secgroups = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
|
||||
secgroups[0].name = "a"
|
||||
secgroups[1].name = "b"
|
||||
secgroups[2].name = "default"
|
||||
|
||||
mock_manager().list.return_value = secgroups
|
||||
mock_resource_manager__manager().list.return_value = secgroups
|
||||
self.assertSequenceEqual(secgroups[:2],
|
||||
resources.NovaSecurityGroup().list())
|
||||
|
||||
@@ -127,13 +127,13 @@ class NovaFloatingIpsBulkTestCase(test.TestCase):
|
||||
self.assertEqual(ip_range.raw_resource.address, ip_range.id())
|
||||
|
||||
@mock.patch("%s.base.ResourceManager._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_resource_manager__manager):
|
||||
ip_range = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
|
||||
ip_range[0].pool = "a"
|
||||
ip_range[1].pool = "rally_fip_pool_a"
|
||||
ip_range[2].pool = "rally_fip_pool_b"
|
||||
|
||||
mock_manager().list.return_value = ip_range
|
||||
mock_resource_manager__manager().list.return_value = ip_range
|
||||
self.assertEqual(ip_range[1:], resources.NovaFloatingIpsBulk().list())
|
||||
|
||||
|
||||
@@ -153,30 +153,31 @@ class EC2MixinTestCase(test.TestCase):
|
||||
class EC2ServerTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_is_deleted(self, mock_manager):
|
||||
def test_is_deleted(self, mock_ec2_server__manager):
|
||||
raw_res1 = mock.MagicMock(state="terminated")
|
||||
raw_res2 = mock.MagicMock(state="terminated")
|
||||
resource = mock.MagicMock(id="test_id")
|
||||
manager = resources.EC2Server(resource=resource)
|
||||
|
||||
mock_manager().get_only_instances.return_value = [raw_res1]
|
||||
mock_ec2_server__manager().get_only_instances.return_value = [raw_res1]
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
raw_res1.state = "running"
|
||||
self.assertFalse(manager.is_deleted())
|
||||
|
||||
mock_manager().get_only_instances.return_value = [raw_res1, raw_res2]
|
||||
mock_ec2_server__manager().get_only_instances.return_value = [
|
||||
raw_res1, raw_res2]
|
||||
self.assertFalse(manager.is_deleted())
|
||||
|
||||
raw_res1.state = "terminated"
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
mock_manager().get_only_instances.return_value = []
|
||||
mock_ec2_server__manager().get_only_instances.return_value = []
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_is_deleted_exceptions(self, mock_manager):
|
||||
mock_manager.side_effect = [
|
||||
def test_is_deleted_exceptions(self, mock_ec2_server__manager):
|
||||
mock_ec2_server__manager.side_effect = [
|
||||
boto_exception.EC2ResponseError(
|
||||
status="fake", reason="fake",
|
||||
body={"Error": {"Code": "fake_code"}}),
|
||||
@@ -189,17 +190,18 @@ class EC2ServerTestCase(test.TestCase):
|
||||
self.assertTrue(manager.is_deleted())
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_delete(self, mock_manager):
|
||||
def test_delete(self, mock_ec2_server__manager):
|
||||
resource = mock.MagicMock(id="test_id")
|
||||
manager = resources.EC2Server(resource=resource)
|
||||
manager.delete()
|
||||
mock_manager().terminate_instances.assert_called_once_with(
|
||||
mock_ec2_server__manager().terminate_instances.assert_called_once_with(
|
||||
instance_ids=["test_id"])
|
||||
|
||||
@mock.patch("%s.EC2Server._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_ec2_server__manager):
|
||||
manager = resources.EC2Server()
|
||||
mock_manager().get_only_instances.return_value = ["a", "b", "c"]
|
||||
mock_ec2_server__manager().get_only_instances.return_value = [
|
||||
"a", "b", "c"]
|
||||
self.assertEqual(["a", "b", "c"], manager.list())
|
||||
|
||||
|
||||
@@ -283,10 +285,11 @@ class NeutronPortTestCase(test.TestCase):
|
||||
class NeutronQuotaTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.NeutronQuota._manager" % BASE)
|
||||
def test_delete(self, mock_manager):
|
||||
def test_delete(self, mock_neutron_quota__manager):
|
||||
user = mock.MagicMock()
|
||||
resources.NeutronQuota(user=user, tenant_uuid="fake").delete()
|
||||
mock_manager().delete_quota.assert_called_once_with("fake")
|
||||
mock_neutron_quota__manager().delete_quota.assert_called_once_with(
|
||||
"fake")
|
||||
|
||||
def test__manager(self):
|
||||
admin = mock.MagicMock(neutron=mock.Mock(return_value="foo"))
|
||||
@@ -298,14 +301,15 @@ class NeutronQuotaTestCase(test.TestCase):
|
||||
class GlanceImageTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.GlanceImage._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_glance_image__manager):
|
||||
glance = resources.GlanceImage()
|
||||
glance.tenant_uuid = mock.MagicMock()
|
||||
|
||||
mock_manager().list.return_value = ["a", "b", "c"]
|
||||
mock_glance_image__manager().list.return_value = ["a", "b", "c"]
|
||||
|
||||
self.assertEqual(["a", "b", "c"], glance.list())
|
||||
mock_manager().list.assert_called_once_with(owner=glance.tenant_uuid)
|
||||
mock_glance_image__manager().list.assert_called_once_with(
|
||||
owner=glance.tenant_uuid)
|
||||
|
||||
|
||||
class CeilometerTestCase(test.TestCase):
|
||||
@@ -316,15 +320,15 @@ class CeilometerTestCase(test.TestCase):
|
||||
self.assertEqual(ceil.raw_resource.alarm_id, ceil.id())
|
||||
|
||||
@mock.patch("%s.CeilometerAlarms._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_ceilometer_alarms__manager):
|
||||
|
||||
ceil = resources.CeilometerAlarms()
|
||||
ceil.tenant_uuid = mock.MagicMock()
|
||||
mock_manager().list.return_value = ["a", "b", "c"]
|
||||
mock_manager.reset_mock()
|
||||
mock_ceilometer_alarms__manager().list.return_value = ["a", "b", "c"]
|
||||
mock_ceilometer_alarms__manager.reset_mock()
|
||||
|
||||
self.assertEqual(["a", "b", "c"], ceil.list())
|
||||
mock_manager().list.assert_called_once_with(
|
||||
mock_ceilometer_alarms__manager().list.assert_called_once_with(
|
||||
q=[{"field": "project_id", "op": "eq", "value": ceil.tenant_uuid}])
|
||||
|
||||
|
||||
@@ -416,11 +420,13 @@ class SwiftMixinTestCase(test.TestCase):
|
||||
class SwiftObjectTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.SwiftMixin._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_swift_mixin__manager):
|
||||
containers = [mock.MagicMock(), mock.MagicMock()]
|
||||
objects = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
|
||||
mock_manager().get_account.return_value = ("header", containers)
|
||||
mock_manager().get_container.return_value = ("header", objects)
|
||||
mock_swift_mixin__manager().get_account.return_value = (
|
||||
"header", containers)
|
||||
mock_swift_mixin__manager().get_container.return_value = (
|
||||
"header", objects)
|
||||
self.assertEqual(len(containers),
|
||||
len(resources.SwiftContainer().list()))
|
||||
self.assertEqual(len(containers) * len(objects),
|
||||
@@ -430,8 +436,9 @@ class SwiftObjectTestCase(test.TestCase):
|
||||
class SwiftContainerTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.SwiftMixin._manager" % BASE)
|
||||
def test_list(self, mock_manager):
|
||||
def test_list(self, mock_swift_mixin__manager):
|
||||
containers = [mock.MagicMock(), mock.MagicMock(), mock.MagicMock()]
|
||||
mock_manager().get_account.return_value = ("header", containers)
|
||||
mock_swift_mixin__manager().get_account.return_value = (
|
||||
"header", containers)
|
||||
self.assertEqual(len(containers),
|
||||
len(resources.SwiftContainer().list()))
|
||||
|
@@ -22,8 +22,8 @@ class CinderQuotasTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_update(self, client_mock):
|
||||
cinder_quo = cinder_quotas.CinderQuotas(client_mock)
|
||||
def test_update(self, mock_clients):
|
||||
cinder_quo = cinder_quotas.CinderQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
quotas_values = {
|
||||
"volumes": 10,
|
||||
@@ -31,13 +31,13 @@ class CinderQuotasTestCase(test.TestCase):
|
||||
"gigabytes": 1000
|
||||
}
|
||||
cinder_quo.update(tenant_id, **quotas_values)
|
||||
client_mock.cinder().quotas.update.assert_called_once_with(
|
||||
mock_clients.cinder().quotas.update.assert_called_once_with(
|
||||
tenant_id, **quotas_values)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_delete(self, client_mock):
|
||||
cinder_quo = cinder_quotas.CinderQuotas(client_mock)
|
||||
def test_delete(self, mock_clients):
|
||||
cinder_quo = cinder_quotas.CinderQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
cinder_quo.delete(tenant_id)
|
||||
client_mock.cinder().quotas.delete.assert_called_once_with(tenant_id)
|
||||
mock_clients.cinder().quotas.delete.assert_called_once_with(tenant_id)
|
||||
|
@@ -22,8 +22,8 @@ class DesignateQuotasTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_update(self, client_mock):
|
||||
quotas = designate_quotas.DesignateQuotas(client_mock)
|
||||
def test_update(self, mock_clients):
|
||||
quotas = designate_quotas.DesignateQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
quotas_values = {
|
||||
"domains": 5,
|
||||
@@ -32,14 +32,14 @@ class DesignateQuotasTestCase(test.TestCase):
|
||||
"recordset_records": 20,
|
||||
}
|
||||
quotas.update(tenant_id, **quotas_values)
|
||||
client_mock.designate().quotas.update.assert_called_once_with(
|
||||
mock_clients.designate().quotas.update.assert_called_once_with(
|
||||
tenant_id, quotas_values)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_delete(self, client_mock):
|
||||
quotas = designate_quotas.DesignateQuotas(client_mock)
|
||||
def test_delete(self, mock_clients):
|
||||
quotas = designate_quotas.DesignateQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
quotas.delete(tenant_id)
|
||||
client_mock.designate().quotas.reset.assert_called_once_with(
|
||||
mock_clients.designate().quotas.reset.assert_called_once_with(
|
||||
tenant_id)
|
||||
|
@@ -22,8 +22,8 @@ class NeutronQuotasTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_update(self, client_mock):
|
||||
neutron_quotas = quotas.NeutronQuotas(client_mock)
|
||||
def test_update(self, mock_clients):
|
||||
neutron_quotas = quotas.NeutronQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
quotas_values = {
|
||||
"network": 20,
|
||||
@@ -36,13 +36,13 @@ class NeutronQuotasTestCase(test.TestCase):
|
||||
}
|
||||
neutron_quotas.update(tenant_id, **quotas_values)
|
||||
body = {"quota": quotas_values}
|
||||
client_mock.neutron().update_quota.assert_called_once_with(tenant_id,
|
||||
body=body)
|
||||
mock_clients.neutron().update_quota.assert_called_once_with(tenant_id,
|
||||
body=body)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_delete(self, client_mock):
|
||||
neutron_quotas = quotas.NeutronQuotas(client_mock)
|
||||
def test_delete(self, mock_clients):
|
||||
neutron_quotas = quotas.NeutronQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
neutron_quotas.delete(tenant_id)
|
||||
client_mock.neutron().delete_quota.assert_called_once_with(tenant_id)
|
||||
mock_clients.neutron().delete_quota.assert_called_once_with(tenant_id)
|
||||
|
@@ -22,8 +22,8 @@ class NovaQuotasTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_update(self, client_mock):
|
||||
nova_quotas = quotas.NovaQuotas(client_mock)
|
||||
def test_update(self, mock_clients):
|
||||
nova_quotas = quotas.NovaQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
quotas_values = {
|
||||
"instances": 10,
|
||||
@@ -40,13 +40,13 @@ class NovaQuotasTestCase(test.TestCase):
|
||||
"security_group_rules": 50
|
||||
}
|
||||
nova_quotas.update(tenant_id, **quotas_values)
|
||||
client_mock.nova().quotas.update.assert_called_once_with(
|
||||
mock_clients.nova().quotas.update.assert_called_once_with(
|
||||
tenant_id, **quotas_values)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
def test_delete(self, client_mock):
|
||||
nova_quotas = quotas.NovaQuotas(client_mock)
|
||||
def test_delete(self, mock_clients):
|
||||
nova_quotas = quotas.NovaQuotas(mock_clients)
|
||||
tenant_id = mock.MagicMock()
|
||||
nova_quotas.delete(tenant_id)
|
||||
client_mock.nova().quotas.delete.assert_called_once_with(tenant_id)
|
||||
mock_clients.nova().quotas.delete.assert_called_once_with(tenant_id)
|
||||
|
@@ -139,7 +139,7 @@ class QuotasTestCase(test.TestCase):
|
||||
"quotas.quotas.osclients.Clients")
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.cinder_quotas.CinderQuotas")
|
||||
def test_cinder_quotas(self, mock_quotas, mock_osclients):
|
||||
def test_cinder_quotas(self, mock_cinder_quotas, mock_clients):
|
||||
ctx = copy.deepcopy(self.context)
|
||||
ctx["config"]["quotas"] = {
|
||||
"cinder": {
|
||||
@@ -158,19 +158,21 @@ class QuotasTestCase(test.TestCase):
|
||||
expected_setup_calls.append(mock.call()
|
||||
.update(tenant,
|
||||
**cinder_quotas))
|
||||
mock_quotas.assert_has_calls(expected_setup_calls, any_order=True)
|
||||
mock_quotas.reset_mock()
|
||||
mock_cinder_quotas.assert_has_calls(
|
||||
expected_setup_calls, any_order=True)
|
||||
mock_cinder_quotas.reset_mock()
|
||||
|
||||
expected_cleanup_calls = []
|
||||
for tenant in tenants:
|
||||
expected_cleanup_calls.append(mock.call().delete(tenant))
|
||||
mock_quotas.assert_has_calls(expected_cleanup_calls, any_order=True)
|
||||
mock_cinder_quotas.assert_has_calls(
|
||||
expected_cleanup_calls, any_order=True)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.nova_quotas.NovaQuotas")
|
||||
def test_nova_quotas(self, mock_quotas, mock_osclients):
|
||||
def test_nova_quotas(self, mock_nova_quotas, mock_clients):
|
||||
ctx = copy.deepcopy(self.context)
|
||||
|
||||
ctx["config"]["quotas"] = {
|
||||
@@ -198,19 +200,21 @@ class QuotasTestCase(test.TestCase):
|
||||
expected_setup_calls.append(mock.call()
|
||||
.update(tenant,
|
||||
**nova_quotas))
|
||||
mock_quotas.assert_has_calls(expected_setup_calls, any_order=True)
|
||||
mock_quotas.reset_mock()
|
||||
mock_nova_quotas.assert_has_calls(
|
||||
expected_setup_calls, any_order=True)
|
||||
mock_nova_quotas.reset_mock()
|
||||
|
||||
expected_cleanup_calls = []
|
||||
for tenant in ctx["tenants"]:
|
||||
expected_cleanup_calls.append(mock.call().delete(tenant))
|
||||
mock_quotas.assert_has_calls(expected_cleanup_calls, any_order=True)
|
||||
mock_nova_quotas.assert_has_calls(
|
||||
expected_cleanup_calls, any_order=True)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.neutron_quotas.NeutronQuotas")
|
||||
def test_neutron_quotas(self, mock_quotas, mock_osclients):
|
||||
def test_neutron_quotas(self, mock_neutron_quotas, mock_clients):
|
||||
ctx = copy.deepcopy(self.context)
|
||||
|
||||
ctx["config"]["quotas"] = {
|
||||
@@ -233,13 +237,15 @@ class QuotasTestCase(test.TestCase):
|
||||
expected_setup_calls.append(mock.call()
|
||||
.update(tenant,
|
||||
**neutron_quotas))
|
||||
mock_quotas.assert_has_calls(expected_setup_calls, any_order=True)
|
||||
mock_quotas.reset_mock()
|
||||
mock_neutron_quotas.assert_has_calls(
|
||||
expected_setup_calls, any_order=True)
|
||||
mock_neutron_quotas.reset_mock()
|
||||
|
||||
expected_cleanup_calls = []
|
||||
for tenant in ctx["tenants"]:
|
||||
expected_cleanup_calls.append(mock.call().delete(tenant))
|
||||
mock_quotas.assert_has_calls(expected_cleanup_calls, any_order=True)
|
||||
mock_neutron_quotas.assert_has_calls(
|
||||
expected_cleanup_calls, any_order=True)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.quotas.osclients.Clients")
|
||||
@@ -249,8 +255,8 @@ class QuotasTestCase(test.TestCase):
|
||||
"quotas.cinder_quotas.CinderQuotas")
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"quotas.neutron_quotas.NeutronQuotas")
|
||||
def test_no_quotas(self, mock_neutron_quota, mock_cinder_quotas,
|
||||
mock_nova_quotas, mock_osclients):
|
||||
def test_no_quotas(self, mock_neutron_quotas, mock_cinder_quotas,
|
||||
mock_nova_quotas, mock_clients):
|
||||
ctx = copy.deepcopy(self.context)
|
||||
if "quotas" in ctx["config"]:
|
||||
del ctx["config"]["quotas"]
|
||||
@@ -259,11 +265,11 @@ class QuotasTestCase(test.TestCase):
|
||||
quotas_ctx.setup()
|
||||
self.assertFalse(mock_cinder_quotas.update.called)
|
||||
self.assertFalse(mock_nova_quotas.update.called)
|
||||
self.assertFalse(mock_neutron_quota.update.called)
|
||||
self.assertFalse(mock_neutron_quotas.update.called)
|
||||
|
||||
self.assertFalse(mock_cinder_quotas.delete.called)
|
||||
self.assertFalse(mock_nova_quotas.delete.called)
|
||||
self.assertFalse(mock_neutron_quota.delete.called)
|
||||
self.assertFalse(mock_neutron_quotas.delete.called)
|
||||
|
||||
@ddt.data(
|
||||
{"quotas_ctxt": {"nova": {"cpu": 1}},
|
||||
|
@@ -71,8 +71,9 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
@mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch("%s.sahara_cluster.osclients" % CTX)
|
||||
def test_setup_and_cleanup(self, mock_osclients,
|
||||
mock_launch, mock_cleanup):
|
||||
def test_setup_and_cleanup(
|
||||
self, mock_osclients, mock_sahara_scenario__launch_cluster,
|
||||
mock_cleanup):
|
||||
|
||||
mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()
|
||||
|
||||
@@ -104,7 +105,8 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
mock.MagicMock(status="active")]
|
||||
sahara_ctx.setup()
|
||||
|
||||
mock_launch.assert_has_calls(launch_cluster_calls)
|
||||
mock_sahara_scenario__launch_cluster.assert_has_calls(
|
||||
launch_cluster_calls)
|
||||
sahara_ctx.cleanup()
|
||||
mock_cleanup.assert_called_once_with(names=["sahara.clusters"],
|
||||
users=ctx["users"])
|
||||
@@ -112,7 +114,8 @@ class SaharaClusterTestCase(test.TestCase):
|
||||
@mock.patch("%s.sahara_cluster.utils.SaharaScenario._launch_cluster" % CTX,
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch("%s.sahara_cluster.osclients" % CTX)
|
||||
def test_setup_and_cleanup_error(self, mock_osclients, mock_launch):
|
||||
def test_setup_and_cleanup_error(
|
||||
self, mock_osclients, mock_sahara_scenario__launch_cluster):
|
||||
|
||||
mock_sahara = mock_osclients.Clients(mock.MagicMock()).sahara()
|
||||
|
||||
|
@@ -89,8 +89,9 @@ class SaharaImageTestCase(test.TestCase):
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch("%s.osclients" % CTX)
|
||||
@mock.patch("%s.resource_manager.cleanup" % CTX)
|
||||
def test_setup_and_cleanup_url_image(self, mock_cleanup, mock_osclients,
|
||||
mock_image_generator, mock_uuid):
|
||||
def test_setup_and_cleanup_url_image(
|
||||
self, mock_cleanup, mock_osclients,
|
||||
mock_glance_scenario__create_image, mock_generate_random_name):
|
||||
|
||||
ctx = self.url_image_context
|
||||
sahara_ctx = sahara_image.SaharaImage(ctx)
|
||||
@@ -115,7 +116,7 @@ class SaharaImageTestCase(test.TestCase):
|
||||
new_tags=["test_plugin", "test_version"]))
|
||||
|
||||
sahara_ctx.setup()
|
||||
mock_image_generator.assert_has_calls(glance_calls)
|
||||
mock_glance_scenario__create_image.assert_has_calls(glance_calls)
|
||||
mock_osclients.Clients(
|
||||
mock.MagicMock()).sahara().images.update_image.assert_has_calls(
|
||||
sahara_update_image_calls)
|
||||
@@ -131,11 +132,11 @@ class SaharaImageTestCase(test.TestCase):
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch("%s.resource_manager.cleanup" % CTX)
|
||||
@mock.patch("%s.osclients" % CTX)
|
||||
def test_setup_and_cleanup_existing_image(self, mock_os_clients,
|
||||
mock_cleanup,
|
||||
mock_image_generator):
|
||||
def test_setup_and_cleanup_existing_image(
|
||||
self, mock_osclients, mock_cleanup,
|
||||
mock_glance_scenario__create_image):
|
||||
|
||||
clients = mock_os_clients.Clients(mock.MagicMock())
|
||||
clients = mock_osclients.Clients(mock.MagicMock())
|
||||
clients.glance().images.get.return_value = mock.MagicMock(
|
||||
is_public=True)
|
||||
|
||||
@@ -147,24 +148,24 @@ class SaharaImageTestCase(test.TestCase):
|
||||
image_id = sahara_ctx.context["tenants"][tenant_id]["sahara_image"]
|
||||
self.assertEqual("some_id", image_id)
|
||||
|
||||
self.assertEqual(False, mock_image_generator.called)
|
||||
self.assertEqual(False, mock_glance_scenario__create_image.called)
|
||||
|
||||
sahara_ctx.cleanup()
|
||||
self.assertEqual(False, mock_cleanup.called)
|
||||
|
||||
@mock.patch("%s.osclients" % CTX)
|
||||
def test_check_existing_image(self, mock_os_clients):
|
||||
def test_check_existing_image(self, mock_osclients):
|
||||
|
||||
ctx = self.existing_image_context
|
||||
sahara_ctx = sahara_image.SaharaImage(ctx)
|
||||
sahara_ctx.setup()
|
||||
|
||||
mock_os_clients.glance().images.get.asser_called_once_with("some_id")
|
||||
mock_osclients.glance().images.get.asser_called_once_with("some_id")
|
||||
|
||||
@mock.patch("%s.osclients" % CTX)
|
||||
def test_check_existing_image_fail(self, mock_os_clients):
|
||||
def test_check_existing_image_fail(self, mock_osclients):
|
||||
|
||||
clients = mock_os_clients.Clients(mock.MagicMock())
|
||||
clients = mock_osclients.Clients(mock.MagicMock())
|
||||
clients.glance().images.get.return_value = mock.MagicMock(
|
||||
is_public=False)
|
||||
|
||||
|
@@ -24,12 +24,12 @@ class ExistingUserTestCase(test.TestCase):
|
||||
"existing_users.osclients.Clients")
|
||||
@mock.patch("rally.plugins.openstack.context."
|
||||
"existing_users.objects.Endpoint")
|
||||
def test_setup(self, mock_endpoint, mock_osclients):
|
||||
def test_setup(self, mock_endpoint, mock_clients):
|
||||
user1 = mock.MagicMock(tenant_id="1")
|
||||
user2 = mock.MagicMock(tenant_id="1")
|
||||
user3 = mock.MagicMock(tenant_id="2")
|
||||
|
||||
mock_osclients.return_value.keystone.side_effect = [
|
||||
mock_clients.return_value.keystone.side_effect = [
|
||||
user1, user2, user3
|
||||
]
|
||||
|
||||
|
@@ -49,9 +49,9 @@ class FlavorsGeneratorTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
@mock.patch("%s.flavors.osclients.Clients" % CTX)
|
||||
def test_setup(self, mock_osclients):
|
||||
def test_setup(self, mock_clients):
|
||||
# Setup and mock
|
||||
mock_create = mock_osclients().nova().flavors.create
|
||||
mock_create = mock_clients().nova().flavors.create
|
||||
mock_create().to_dict.return_value = {"flavor_key": "flavor_value"}
|
||||
|
||||
# Run
|
||||
@@ -62,7 +62,7 @@ class FlavorsGeneratorTestCase(test.TestCase):
|
||||
self.assertEqual(flavors_ctx.context["flavors"],
|
||||
{"flavor_name": {"flavor_key": "flavor_value"}})
|
||||
|
||||
mock_osclients.assert_called_with(self.context["admin"]["endpoint"])
|
||||
mock_clients.assert_called_with(self.context["admin"]["endpoint"])
|
||||
|
||||
mock_create.assert_called_with(
|
||||
name="flavor_name", ram=2048, vcpus=3,
|
||||
@@ -71,12 +71,12 @@ class FlavorsGeneratorTestCase(test.TestCase):
|
||||
mock_create().to_dict.assert_called_with()
|
||||
|
||||
@mock.patch("%s.flavors.osclients.Clients" % CTX)
|
||||
def test_setup_failexists(self, mock_osclients):
|
||||
def test_setup_failexists(self, mock_clients):
|
||||
# Setup and mock
|
||||
new_context = copy.deepcopy(self.context)
|
||||
new_context["flavors"] = {}
|
||||
|
||||
mock_flavor_create = mock_osclients().nova().flavors.create
|
||||
mock_flavor_create = mock_clients().nova().flavors.create
|
||||
|
||||
exception = nova_exceptions.Conflict("conflict")
|
||||
mock_flavor_create.side_effect = exception
|
||||
@@ -88,14 +88,14 @@ class FlavorsGeneratorTestCase(test.TestCase):
|
||||
# Assertions
|
||||
self.assertEqual(new_context, flavors_ctx.context)
|
||||
|
||||
mock_osclients.assert_called_with(self.context["admin"]["endpoint"])
|
||||
mock_clients.assert_called_with(self.context["admin"]["endpoint"])
|
||||
|
||||
mock_flavor_create.assert_called_once_with(
|
||||
name="flavor_name", ram=2048, vcpus=3,
|
||||
disk=10, ephemeral=3, swap=5)
|
||||
|
||||
@mock.patch("%s.flavors.osclients.Clients" % CTX)
|
||||
def test_cleanup(self, mock_osclients):
|
||||
def test_cleanup(self, mock_clients):
|
||||
# Setup and mock
|
||||
real_context = {
|
||||
"flavors": {
|
||||
@@ -115,7 +115,7 @@ class FlavorsGeneratorTestCase(test.TestCase):
|
||||
flavors_ctx.cleanup()
|
||||
|
||||
# Assertions
|
||||
mock_osclients.assert_called_with(real_context["admin"]["endpoint"])
|
||||
mock_clients.assert_called_with(real_context["admin"]["endpoint"])
|
||||
|
||||
mock_flavors_delete = mock_osclients().nova().flavors.delete
|
||||
mock_flavors_delete = mock_clients().nova().flavors.delete
|
||||
mock_flavors_delete.assert_called_with("flavor_name")
|
||||
|
@@ -35,10 +35,10 @@ class ImageGeneratorTestCase(test.TestCase):
|
||||
return tenants
|
||||
|
||||
@mock.patch("%s.images.context.Context.__init__" % CTX)
|
||||
def test_init(self, mock_base_context_init):
|
||||
ctx = {}
|
||||
ctx["task"] = mock.MagicMock()
|
||||
ctx["config"] = {
|
||||
def test_init(self, mock_context___init__):
|
||||
context = {}
|
||||
context["task"] = mock.MagicMock()
|
||||
context["config"] = {
|
||||
"images": {
|
||||
"image_url": "mock_url",
|
||||
"image_type": "qcow2",
|
||||
@@ -50,8 +50,8 @@ class ImageGeneratorTestCase(test.TestCase):
|
||||
}
|
||||
}
|
||||
|
||||
images.ImageGenerator(ctx)
|
||||
mock_base_context_init.assert_called_once_with(ctx)
|
||||
images.ImageGenerator(context)
|
||||
mock_context___init__.assert_called_once_with(context)
|
||||
|
||||
def test_init_validation(self):
|
||||
context = {}
|
||||
@@ -68,7 +68,7 @@ class ImageGeneratorTestCase(test.TestCase):
|
||||
@mock.patch("%s.glance.utils.GlanceScenario._create_image" % SCN,
|
||||
return_value=fakes.FakeImage(id="uuid"))
|
||||
@mock.patch("%s.images.osclients" % CTX)
|
||||
def test_setup(self, mock_osclients, mock_image_create):
|
||||
def test_setup(self, mock_osclients, mock_glance_scenario__create_image):
|
||||
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
|
@@ -48,8 +48,8 @@ class KeyPairContextTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
@mock.patch("%s.keypair.Keypair._generate_keypair" % CTX)
|
||||
def test_keypair_setup(self, mock_generate):
|
||||
mock_generate.side_effect = [
|
||||
def test_keypair_setup(self, mock_keypair__generate_keypair):
|
||||
mock_keypair__generate_keypair.side_effect = [
|
||||
{"id": "key_id", "key": "key", "name": self.keypair_name},
|
||||
{"id": "key_id", "key": "key", "name": self.keypair_name},
|
||||
]
|
||||
@@ -60,7 +60,7 @@ class KeyPairContextTestCase(test.TestCase):
|
||||
|
||||
self.assertEqual(
|
||||
[mock.call("endpoint")] * 2,
|
||||
mock_generate.mock_calls)
|
||||
mock_keypair__generate_keypair.mock_calls)
|
||||
|
||||
@mock.patch("%s.keypair.resource_manager.cleanup" % CTX)
|
||||
def test_keypair_cleanup(self, mock_cleanup):
|
||||
@@ -70,8 +70,8 @@ class KeyPairContextTestCase(test.TestCase):
|
||||
users=self.ctx_with_keys["users"])
|
||||
|
||||
@mock.patch("rally.osclients.Clients")
|
||||
def test_keypair_generate(self, mock_osclients):
|
||||
mock_keypairs = mock_osclients.return_value.nova.return_value.keypairs
|
||||
def test_keypair_generate(self, mock_clients):
|
||||
mock_keypairs = mock_clients.return_value.nova.return_value.keypairs
|
||||
mock_keypair = mock_keypairs.create.return_value
|
||||
mock_keypair.public_key = "public_key"
|
||||
mock_keypair.private_key = "private_key"
|
||||
@@ -86,7 +86,7 @@ class KeyPairContextTestCase(test.TestCase):
|
||||
"public": "public_key"
|
||||
}, key)
|
||||
|
||||
mock_osclients.assert_has_calls([
|
||||
mock_clients.assert_has_calls([
|
||||
mock.call().nova().keypairs.delete("rally_ssh_key_foo_task_id"),
|
||||
mock.call().nova().keypairs.create("rally_ssh_key_foo_task_id"),
|
||||
])
|
||||
|
@@ -65,9 +65,9 @@ class MuranoGeneratorTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context.murano_packages.osclients")
|
||||
def test_setup(self, mock_clients):
|
||||
def test_setup(self, mock_osclients):
|
||||
mock_app = mock.MagicMock(id="fake_app_id")
|
||||
(mock_clients.Clients().murano().
|
||||
(mock_osclients.Clients().murano().
|
||||
packages.create.return_value) = mock_app
|
||||
|
||||
murano_ctx = murano_packages.PackageGenerator(self._get_context())
|
||||
@@ -80,9 +80,9 @@ class MuranoGeneratorTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context.murano_packages.osclients")
|
||||
@mock.patch("%s.images.resource_manager.cleanup" % CTX)
|
||||
def test_cleanup(self, mock_cleanup, mock_clients):
|
||||
def test_cleanup(self, mock_cleanup, mock_osclients):
|
||||
mock_app = mock.Mock(id="fake_app_id")
|
||||
(mock_clients.Clients().murano().
|
||||
(mock_osclients.Clients().murano().
|
||||
packages.create.return_value) = mock_app
|
||||
|
||||
murano_ctx = murano_packages.PackageGenerator(self._get_context())
|
||||
|
@@ -71,7 +71,7 @@ class NetworkTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.osclients.Clients")
|
||||
@mock.patch(NET + "wrap")
|
||||
def test_cleanup(self, mock_wrap, mock_osclients):
|
||||
def test_cleanup(self, mock_wrap, mock_clients):
|
||||
net_context = network_context.Network(self.get_context())
|
||||
net_context.cleanup()
|
||||
mock_wrap().delete_network.assert_has_calls(
|
||||
|
@@ -50,12 +50,12 @@ class SecGroupContextTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context.secgroup.osclients.Clients")
|
||||
def test__prepare_open_secgroup(self, mock_osclients):
|
||||
def test__prepare_open_secgroup(self, mock_clients):
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
self.assertEqual(len(fake_nova.security_groups.list()), 1)
|
||||
mock_cl = mock.MagicMock()
|
||||
mock_cl.nova.return_value = fake_nova
|
||||
mock_osclients.return_value = mock_cl
|
||||
mock_clients.return_value = mock_cl
|
||||
|
||||
ret = secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
|
||||
self.assertEqual(self.secgroup_name, ret["name"])
|
||||
@@ -70,14 +70,14 @@ class SecGroupContextTestCase(test.TestCase):
|
||||
self.assertEqual(2, len(fake_nova.security_groups.list()))
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context.secgroup.osclients.Clients")
|
||||
def test__prepare_open_secgroup_rules(self, mock_osclients):
|
||||
def test__prepare_open_secgroup_rules(self, mock_clients):
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
|
||||
# NOTE(hughsaunders) Default security group is precreated
|
||||
self.assertEqual(1, len(fake_nova.security_groups.list()))
|
||||
mock_cl = mock.MagicMock()
|
||||
mock_cl.nova.return_value = fake_nova
|
||||
mock_osclients.return_value = mock_cl
|
||||
mock_clients.return_value = mock_cl
|
||||
|
||||
secgroup._prepare_open_secgroup("endpoint", self.secgroup_name)
|
||||
|
||||
@@ -95,16 +95,16 @@ class SecGroupContextTestCase(test.TestCase):
|
||||
"secgroup._prepare_open_secgroup")
|
||||
@mock.patch("rally.plugins.openstack.wrappers.network.wrap")
|
||||
def test_secgroup_setup_cleanup_with_secgroup_supported(
|
||||
self, mock_network_wrap, mock_prepare_open_secgroup,
|
||||
mock_osclients):
|
||||
self, mock_network_wrap, mock__prepare_open_secgroup,
|
||||
mock_clients):
|
||||
mock_network_wrapper = mock.MagicMock()
|
||||
mock_network_wrapper.supports_security_group.return_value = (
|
||||
True, "")
|
||||
mock_network_wrap.return_value = mock_network_wrapper
|
||||
mock_prepare_open_secgroup.return_value = {
|
||||
mock__prepare_open_secgroup.return_value = {
|
||||
"name": "secgroup",
|
||||
"id": "secgroup_id"}
|
||||
mock_osclients.return_value = mock.MagicMock()
|
||||
mock_clients.return_value = mock.MagicMock()
|
||||
|
||||
secgrp_ctx = secgroup.AllowSSH(self.ctx_without_secgroup)
|
||||
secgrp_ctx.setup()
|
||||
@@ -119,27 +119,26 @@ class SecGroupContextTestCase(test.TestCase):
|
||||
mock.call().nova().security_groups.get("secgroup_id"),
|
||||
mock.call().nova().security_groups.get().delete()
|
||||
],
|
||||
mock_osclients.mock_calls)
|
||||
mock_clients.mock_calls)
|
||||
|
||||
mock_network_wrap.assert_called_once_with(
|
||||
mock_osclients.return_value, {})
|
||||
mock_clients.return_value, {})
|
||||
|
||||
@mock.patch("rally.plugins.openstack.context.secgroup.osclients.Clients")
|
||||
@mock.patch("rally.plugins.openstack.wrappers.network.wrap")
|
||||
def test_secgroup_setup_with_secgroup_unsupported(self,
|
||||
mock_network_wrap,
|
||||
mock_osclients):
|
||||
def test_secgroup_setup_with_secgroup_unsupported(
|
||||
self, mock_network_wrap, mock_clients):
|
||||
mock_network_wrapper = mock.MagicMock()
|
||||
mock_network_wrapper.supports_security_group.return_value = (
|
||||
False, "Not supported")
|
||||
mock_network_wrap.return_value = mock_network_wrapper
|
||||
mock_osclients.return_value = mock.MagicMock()
|
||||
mock_clients.return_value = mock.MagicMock()
|
||||
|
||||
secgrp_ctx = secgroup.AllowSSH(dict(self.ctx_without_secgroup))
|
||||
secgrp_ctx.setup()
|
||||
self.assertEqual(self.ctx_without_secgroup, secgrp_ctx.context)
|
||||
|
||||
mock_osclients.assert_called_once_with("admin_endpoint")
|
||||
mock_clients.assert_called_once_with("admin_endpoint")
|
||||
|
||||
mock_network_wrap.assert_called_once_with(
|
||||
mock_osclients.return_value, {})
|
||||
mock_clients.return_value, {})
|
||||
|
@@ -62,8 +62,9 @@ class ServerGeneratorTestCase(test.TestCase):
|
||||
@mock.patch("%s.FlavorResourceType.transform" % TYP,
|
||||
return_value=mock.MagicMock())
|
||||
@mock.patch("%s.servers.osclients" % CTX, return_value=fakes.FakeClients())
|
||||
def test_setup(self, mock_osclients, mock_flavor_transform,
|
||||
mock_image_transform, mock_boot_servers):
|
||||
def test_setup(self, mock_osclients, mock_flavor_resource_type_transform,
|
||||
mock_image_resource_type_transform,
|
||||
mock_nova_scenario__boot_servers):
|
||||
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
|
@@ -48,7 +48,7 @@ class TestStackGenerator(test.TestCase):
|
||||
@mock.patch("%s.heat.utils.HeatScenario._create_stack" % SCN,
|
||||
return_value=fakes.FakeStack(id="uuid"))
|
||||
@mock.patch("%s.stacks.osclients" % CTX)
|
||||
def test_setup(self, mock_osclients, mock_stack_create):
|
||||
def test_setup(self, mock_osclients, mock_heat_scenario__create_stack):
|
||||
tenants_count = 2
|
||||
users_per_tenant = 5
|
||||
stacks_per_tenant = 1
|
||||
@@ -83,7 +83,7 @@ class TestStackGenerator(test.TestCase):
|
||||
stack_ctx = stacks.StackGenerator(context)
|
||||
stack_ctx.setup()
|
||||
self.assertEqual(tenants_count * stacks_per_tenant,
|
||||
mock_stack_create.call_count)
|
||||
mock_heat_scenario__create_stack.call_count)
|
||||
# check that stack ids have been saved in context
|
||||
for ten_id in context["tenants"].keys():
|
||||
self.assertEqual(stacks_per_tenant,
|
||||
|
@@ -39,14 +39,16 @@ class TempestContextTestCase(test.TestCase):
|
||||
@mock.patch(TEMPEST + ".Tempest.is_configured", return_value=True)
|
||||
@mock.patch(TEMPEST + ".Tempest.install")
|
||||
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=True)
|
||||
def test_setup(self, mock_is_install, mock_install, mock_is_cfg, mock_cfg,
|
||||
mock_mkdir):
|
||||
def test_setup(
|
||||
self, mock_tempest_is_installed, mock_tempest_install,
|
||||
mock_tempest_is_configured, mock_tempest_generate_config_file,
|
||||
mock_mkdir):
|
||||
benchmark = tempest.Tempest(self.context)
|
||||
|
||||
benchmark.setup()
|
||||
|
||||
self.assertEqual(0, mock_install.call_count)
|
||||
self.assertEqual(0, mock_cfg.call_count)
|
||||
self.assertEqual(0, mock_tempest_install.call_count)
|
||||
self.assertEqual(0, mock_tempest_generate_config_file.call_count)
|
||||
self.assertEqual("/dev/null", benchmark.verifier.log_file_raw)
|
||||
|
||||
@mock.patch(CONTEXT + ".os.mkdir")
|
||||
@@ -54,43 +56,50 @@ class TempestContextTestCase(test.TestCase):
|
||||
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=False)
|
||||
@mock.patch(TEMPEST + ".Tempest.install")
|
||||
def test_setup_failure_on_tempest_installation(
|
||||
self, mock_install, mock_is_installed, mock_is_cfg, mock_mkdir):
|
||||
mock_install.side_effect = tempest_verifier.TempestSetupFailure()
|
||||
self, mock_tempest_install, mock_tempest_is_installed,
|
||||
mock_tempest_is_configured, mock_mkdir):
|
||||
mock_tempest_install.side_effect = (
|
||||
tempest_verifier.TempestSetupFailure()
|
||||
)
|
||||
|
||||
benchmark = tempest.Tempest(self.context)
|
||||
|
||||
self.assertRaises(exceptions.BenchmarkSetupFailure, benchmark.setup)
|
||||
self.assertEqual(0, mock_is_cfg.call_count)
|
||||
self.assertEqual(0, mock_tempest_is_configured.call_count)
|
||||
|
||||
@mock.patch(CONTEXT + ".os.mkdir")
|
||||
@mock.patch(TEMPEST + ".Tempest.is_configured", return_value=False)
|
||||
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=True)
|
||||
@mock.patch(TEMPEST + ".Tempest.generate_config_file")
|
||||
def test_setup_failure_on_tempest_configuration(
|
||||
self, mock_gen, mock_is_installed, mock_is_cfg, mock_mkdir):
|
||||
mock_gen.side_effect = config.TempestConfigCreationFailure()
|
||||
self, mock_tempest_generate_config_file, mock_tempest_is_installed,
|
||||
mock_tempest_is_configured, mock_mkdir):
|
||||
mock_tempest_generate_config_file.side_effect = (
|
||||
config.TempestConfigCreationFailure()
|
||||
)
|
||||
|
||||
benchmark = tempest.Tempest(self.context)
|
||||
|
||||
self.assertRaises(exceptions.BenchmarkSetupFailure, benchmark.setup)
|
||||
self.assertEqual(1, mock_is_cfg.call_count)
|
||||
self.assertEqual(1, mock_tempest_is_configured.call_count)
|
||||
|
||||
@mock.patch(CONTEXT + ".os.mkdir")
|
||||
@mock.patch(TEMPEST + ".Tempest.is_configured", return_value=False)
|
||||
@mock.patch(TEMPEST + ".Tempest.is_installed", return_value=True)
|
||||
@mock.patch(TEMPEST + ".Tempest.generate_config_file")
|
||||
def test_setup_with_no_configuration(
|
||||
self, mock_gen, mock_is_installed, mock_is_cfg, mock_mkdir):
|
||||
self, mock_tempest_generate_config_file, mock_tempest_is_installed,
|
||||
mock_tempest_is_configured, mock_mkdir):
|
||||
|
||||
benchmark = tempest.Tempest(self.context)
|
||||
benchmark.setup()
|
||||
self.assertEqual(1, mock_is_installed.call_count)
|
||||
self.assertEqual(1, mock_tempest_is_installed.call_count)
|
||||
self.assertEqual("/dev/null", benchmark.verifier.log_file_raw)
|
||||
self.assertEqual(1, mock_gen.call_count)
|
||||
self.assertEqual(1, mock_tempest_generate_config_file.call_count)
|
||||
|
||||
@mock.patch(CONTEXT + ".os.path.exists", return_value=True)
|
||||
@mock.patch(CONTEXT + ".shutil")
|
||||
def test_cleanup(self, mock_shutil, mock_os_path_exists):
|
||||
def test_cleanup(self, mock_shutil, mock_exists):
|
||||
benchmark = tempest.Tempest(self.context)
|
||||
benchmark.verifier = mock.MagicMock()
|
||||
benchmark.results_dir = "/tmp/path"
|
||||
|
@@ -85,12 +85,12 @@ class UserGeneratorTestCase(test.TestCase):
|
||||
@mock.patch("rally.plugins.openstack.context.users.network")
|
||||
@mock.patch("rally.benchmark.utils.check_service_status",
|
||||
return_value=False)
|
||||
def test__remove_default_security_group(self, mock_check_service_status,
|
||||
mock_netwrap,
|
||||
mock_iterate_per_tenants):
|
||||
def test__remove_default_security_group(
|
||||
self, mock_check_service_status, mock_network,
|
||||
mock_iterate_per_tenants):
|
||||
net_wrapper = mock.Mock(SERVICE_IMPL=consts.Service.NEUTRON)
|
||||
net_wrapper.supports_security_group.return_value = (True, None)
|
||||
mock_netwrap.wrap.return_value = net_wrapper
|
||||
mock_network.wrap.return_value = net_wrapper
|
||||
|
||||
user_generator = users.UserGenerator(self.context)
|
||||
|
||||
@@ -107,7 +107,7 @@ class UserGeneratorTestCase(test.TestCase):
|
||||
|
||||
user_generator._remove_default_security_group()
|
||||
|
||||
mock_netwrap.wrap.assert_called_once_with(admin_clients)
|
||||
mock_network.wrap.assert_called_once_with(admin_clients)
|
||||
|
||||
mock_iterate_per_tenants.assert_called_once_with(
|
||||
user_generator.context["users"])
|
||||
|
@@ -49,7 +49,7 @@ class VolumeGeneratorTestCase(test.TestCase):
|
||||
@mock.patch("%s.cinder.utils.CinderScenario._create_volume" % SCN,
|
||||
return_value=fakes.FakeVolume(id="uuid"))
|
||||
@mock.patch("%s.volumes.osclients" % CTX)
|
||||
def test_setup(self, mock_osclients, mock_volume_create):
|
||||
def test_setup(self, mock_osclients, mock_cinder_scenario__create_volume):
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
|
||||
|
@@ -68,16 +68,16 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
||||
return_value="image")
|
||||
@mock.patch("%s.types.FlavorResourceType.transform" % BASE,
|
||||
return_value="flavor")
|
||||
def test_create_one_image(self, mock_flavor_transform,
|
||||
mock_image_transform, mock_osclients,
|
||||
mock_vmtasks):
|
||||
def test_create_one_image(
|
||||
self, mock_flavor_resource_type_transform,
|
||||
mock_image_resource_type_transform, mock_clients, mock_vm_tasks):
|
||||
ip = {"ip": "foo_ip", "id": "foo_id", "is_floating": True}
|
||||
fake_server = mock.Mock()
|
||||
|
||||
fake_image = mock.MagicMock(
|
||||
to_dict=mock.MagicMock(return_value={"id": "image"}))
|
||||
|
||||
mock_vm_scenario = mock_vmtasks.return_value = mock.MagicMock(
|
||||
mock_vm_scenario = mock_vm_tasks.return_value = mock.MagicMock(
|
||||
_create_image=mock.MagicMock(return_value=fake_image),
|
||||
_boot_server_with_fip=mock.MagicMock(
|
||||
return_value=(fake_server, ip)),
|
||||
@@ -96,14 +96,14 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
||||
custom_image = generator_ctx.create_one_image(user,
|
||||
foo_arg="foo_value")
|
||||
|
||||
mock_flavor_transform.assert_called_once_with(
|
||||
clients=mock_osclients.return_value,
|
||||
mock_flavor_resource_type_transform.assert_called_once_with(
|
||||
clients=mock_clients.return_value,
|
||||
resource_config={"name": "flavor"})
|
||||
mock_image_transform.assert_called_once_with(
|
||||
clients=mock_osclients.return_value,
|
||||
mock_image_resource_type_transform.assert_called_once_with(
|
||||
clients=mock_clients.return_value,
|
||||
resource_config={"name": "image"})
|
||||
mock_vmtasks.assert_called_once_with(
|
||||
self.context, clients=mock_osclients.return_value)
|
||||
mock_vm_tasks.assert_called_once_with(
|
||||
self.context, clients=mock_clients.return_value)
|
||||
|
||||
mock_vm_scenario._boot_server_with_fip.assert_called_once_with(
|
||||
image="image", flavor="flavor",
|
||||
@@ -124,16 +124,16 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
||||
self.assertEqual({"id": "image"}, custom_image)
|
||||
|
||||
@mock.patch("%s.osclients.Clients" % BASE)
|
||||
def test_make_image_public(self, mock_osclients):
|
||||
def test_make_image_public(self, mock_clients):
|
||||
fc = mock.MagicMock()
|
||||
mock_osclients.return_value = fc
|
||||
mock_clients.return_value = fc
|
||||
|
||||
generator_ctx = TestImageGenerator(self.context)
|
||||
custom_image = {"id": "image"}
|
||||
|
||||
generator_ctx.make_image_public(custom_image=custom_image)
|
||||
|
||||
mock_osclients.assert_called_once_with(
|
||||
mock_clients.assert_called_once_with(
|
||||
self.context["admin"]["endpoint"])
|
||||
|
||||
fc.glance.assert_called_once_with()
|
||||
@@ -143,7 +143,7 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("%s.nova_utils.NovaScenario" % BASE)
|
||||
@mock.patch("%s.osclients.Clients" % BASE)
|
||||
def test_delete_one_image(self, mock_osclients, mock_nova_scenario):
|
||||
def test_delete_one_image(self, mock_clients, mock_nova_scenario):
|
||||
nova_scenario = mock_nova_scenario.return_value = mock.MagicMock()
|
||||
nova_client = nova_scenario.clients.return_value
|
||||
nova_client.images.get.return_value = "image_obj"
|
||||
@@ -156,7 +156,7 @@ class BaseCustomImageContextVMTestCase(test.TestCase):
|
||||
generator_ctx.delete_one_image(user, custom_image)
|
||||
|
||||
mock_nova_scenario.assert_called_once_with(
|
||||
context=self.context, clients=mock_osclients.return_value)
|
||||
context=self.context, clients=mock_clients.return_value)
|
||||
|
||||
nova_scenario.clients.assert_called_once_with("nova")
|
||||
nova_client.images.get.assert_called_once_with("image")
|
||||
|
@@ -27,119 +27,131 @@ class DesignateBasicTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._list_domains")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_domain")
|
||||
def test_create_and_list_domains(self, mock_create, mock_list):
|
||||
def test_create_and_list_domains(self, mock_designate_basic__create_domain,
|
||||
mock_designate_basic__list_domains):
|
||||
scenario = basic.DesignateBasic()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_list_domains()
|
||||
mock_create.assert_called_once_with()
|
||||
mock_list.assert_called_once_with()
|
||||
mock_designate_basic__create_domain.assert_called_once_with()
|
||||
mock_designate_basic__list_domains.assert_called_once_with()
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._delete_domain")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_domain")
|
||||
def test_create_and_delete_domain(self, mock_create, mock_delete):
|
||||
def test_create_and_delete_domain(
|
||||
self, mock_designate_basic__create_domain,
|
||||
mock_designate_basic__delete_domain):
|
||||
|
||||
scenario = basic.DesignateBasic()
|
||||
|
||||
mock_create.return_value = {"id": "123"}
|
||||
mock_designate_basic__create_domain.return_value = {"id": "123"}
|
||||
|
||||
# Default options
|
||||
scenario.create_and_delete_domain()
|
||||
|
||||
mock_create.assert_called_once_with()
|
||||
mock_delete.assert_called_once_with("123")
|
||||
mock_designate_basic__create_domain.assert_called_once_with()
|
||||
mock_designate_basic__delete_domain.assert_called_once_with("123")
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._list_domains")
|
||||
def test_list_domains(self, mock_list):
|
||||
def test_list_domains(self, mock_designate_basic__list_domains):
|
||||
scenario = basic.DesignateBasic()
|
||||
|
||||
# Default options
|
||||
scenario.list_domains()
|
||||
mock_list.assert_called_once_with()
|
||||
mock_designate_basic__list_domains.assert_called_once_with()
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._list_records")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_record")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_domain")
|
||||
def test_create_and_list_records(self,
|
||||
mock_create_domain,
|
||||
mock_create_record,
|
||||
mock_list):
|
||||
def test_create_and_list_records(
|
||||
self, mock_designate_basic__create_domain,
|
||||
mock_designate_basic__create_record,
|
||||
mock_designate_basic__list_records):
|
||||
scenario = basic.DesignateBasic()
|
||||
domain = {
|
||||
"name": "zone.name",
|
||||
"email": "email@zone.name",
|
||||
"id": "123"}
|
||||
mock_create_domain.return_value = domain
|
||||
mock_designate_basic__create_domain.return_value = domain
|
||||
records_per_domain = 5
|
||||
|
||||
scenario.create_and_list_records(
|
||||
records_per_domain=records_per_domain)
|
||||
mock_create_domain.assert_called_once_with()
|
||||
self.assertEqual(mock_create_record.mock_calls,
|
||||
[mock.call(domain, atomic_action=False)]
|
||||
* records_per_domain)
|
||||
mock_list.assert_called_once_with(domain["id"])
|
||||
mock_designate_basic__create_domain.assert_called_once_with()
|
||||
self.assertEqual(
|
||||
mock_designate_basic__create_record.mock_calls,
|
||||
[mock.call(domain, atomic_action=False)]
|
||||
* records_per_domain)
|
||||
mock_designate_basic__list_records.assert_called_once_with(
|
||||
domain["id"])
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._delete_record")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_record")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_domain")
|
||||
def test_create_and_delete_records(self,
|
||||
mock_create_domain,
|
||||
mock_create_record,
|
||||
mock_delete):
|
||||
def test_create_and_delete_records(
|
||||
self, mock_designate_basic__create_domain,
|
||||
mock_designate_basic__create_record,
|
||||
mock_designate_basic__delete_record):
|
||||
scenario = basic.DesignateBasic()
|
||||
domain = {
|
||||
"name": "zone.name",
|
||||
"email": "email@zone.name",
|
||||
"id": "123"}
|
||||
mock_create_domain.return_value = domain
|
||||
mock_create_record.return_value = {"id": "321"}
|
||||
mock_designate_basic__create_domain.return_value = domain
|
||||
mock_designate_basic__create_record.return_value = {"id": "321"}
|
||||
records_per_domain = 5
|
||||
|
||||
scenario.create_and_delete_records(
|
||||
records_per_domain=records_per_domain)
|
||||
mock_create_domain.assert_called_once_with()
|
||||
self.assertEqual(mock_create_record.mock_calls,
|
||||
[mock.call(domain, atomic_action=False)]
|
||||
* records_per_domain)
|
||||
self.assertEqual(mock_delete.mock_calls,
|
||||
[mock.call(domain["id"], "321", atomic_action=False)]
|
||||
* records_per_domain)
|
||||
mock_designate_basic__create_domain.assert_called_once_with()
|
||||
self.assertEqual(
|
||||
mock_designate_basic__create_record.mock_calls,
|
||||
[mock.call(domain, atomic_action=False)]
|
||||
* records_per_domain)
|
||||
self.assertEqual(
|
||||
mock_designate_basic__delete_record.mock_calls,
|
||||
[mock.call(domain["id"], "321", atomic_action=False)]
|
||||
* records_per_domain)
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._list_records")
|
||||
def test_list_records(self, mock_list):
|
||||
def test_list_records(self, mock_designate_basic__list_records):
|
||||
scenario = basic.DesignateBasic()
|
||||
|
||||
# Default options
|
||||
scenario.list_records("123")
|
||||
mock_list.assert_called_once_with("123")
|
||||
mock_designate_basic__list_records.assert_called_once_with("123")
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._list_servers")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_server")
|
||||
def test_create_and_list_servers(self, mock_create, mock_list):
|
||||
def test_create_and_list_servers(
|
||||
self, mock_designate_basic__create_server,
|
||||
mock_designate_basic__list_servers):
|
||||
scenario = basic.DesignateBasic()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_list_servers()
|
||||
mock_create.assert_called_once_with()
|
||||
mock_list.assert_called_once_with()
|
||||
mock_designate_basic__create_server.assert_called_once_with()
|
||||
mock_designate_basic__list_servers.assert_called_once_with()
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._delete_server")
|
||||
@mock.patch(DESIGNATE_BASIC + "._create_server")
|
||||
def test_create_and_delete_server(self, mock_create, mock_delete):
|
||||
def test_create_and_delete_server(
|
||||
self, mock_designate_basic__create_server,
|
||||
mock_designate_basic__delete_server):
|
||||
scenario = basic.DesignateBasic()
|
||||
|
||||
mock_create.return_value = {"id": "123"}
|
||||
mock_designate_basic__create_server.return_value = {"id": "123"}
|
||||
|
||||
# Default options
|
||||
scenario.create_and_delete_server()
|
||||
|
||||
mock_create.assert_called_once_with()
|
||||
mock_delete.assert_called_once_with("123")
|
||||
mock_designate_basic__create_server.assert_called_once_with()
|
||||
mock_designate_basic__delete_server.assert_called_once_with("123")
|
||||
|
||||
@mock.patch(DESIGNATE_BASIC + "._list_servers")
|
||||
def test_list_servers(self, mock_list):
|
||||
def test_list_servers(self, mock_designate_basic__list_servers):
|
||||
scenario = basic.DesignateBasic()
|
||||
|
||||
# Default options
|
||||
scenario.list_servers()
|
||||
mock_list.assert_called_once_with()
|
||||
mock_designate_basic__list_servers.assert_called_once_with()
|
||||
|
@@ -29,15 +29,15 @@ class DesignateScenarioTestCase(test.ClientsTestCase):
|
||||
self.domain = mock.Mock()
|
||||
self.server = mock.Mock()
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
|
||||
def test_create_domain(self, mock_random_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_domain(self, mock_generate_random_name):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
random_name = "foo"
|
||||
explicit_name = "bar.io."
|
||||
email = "root@zone.name"
|
||||
|
||||
mock_random_name.return_value = random_name
|
||||
mock_generate_random_name.return_value = random_name
|
||||
self.clients("designate").domains.create.return_value = self.domain
|
||||
|
||||
# Check that the defaults / randoms are used if nothing is specified
|
||||
@@ -72,15 +72,15 @@ class DesignateScenarioTestCase(test.ClientsTestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"designate.delete_domain")
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
|
||||
def test_create_record(self, mock_random_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_record(self, mock_generate_random_name):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
random_name = "foo"
|
||||
domain_name = "zone.name."
|
||||
random_record_name = "%s.%s" % (random_name, domain_name)
|
||||
|
||||
mock_random_name.return_value = random_name
|
||||
mock_generate_random_name.return_value = random_name
|
||||
|
||||
domain = {"name": domain_name, "id": "123"}
|
||||
|
||||
@@ -125,14 +125,14 @@ class DesignateScenarioTestCase(test.ClientsTestCase):
|
||||
self.clients("designate").records.delete.assert_called_once_with(
|
||||
domain_id, record_id)
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
|
||||
def test_create_server(self, mock_random_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_server(self, mock_generate_random_name):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
random_name = "foo"
|
||||
explicit_name = "bar.io."
|
||||
|
||||
mock_random_name.return_value = random_name
|
||||
mock_generate_random_name.return_value = random_name
|
||||
self.admin_clients(
|
||||
"designate").servers.create.return_value = self.server
|
||||
|
||||
|
@@ -28,7 +28,8 @@ class EC2ServersTestCase(test.ClientsTestCase):
|
||||
@mock.patch(UTILS + "ec2_resource_is", return_value="foo_state")
|
||||
@mock.patch(UTILS + "time")
|
||||
@mock.patch(UTILS + "CONF")
|
||||
def test_boot_server(self, mock_conf, mock_time, mock_is, mock_wait):
|
||||
def test_boot_server(self, mock_conf, mock_time, mock_ec2_resource_is,
|
||||
mock_wait_for):
|
||||
mock_conf.benchmark.ec2_server_boot_prepoll_delay = "foo_delay"
|
||||
mock_conf.benchmark.ec2_server_boot_timeout = "foo_timeout"
|
||||
mock_conf.benchmark.ec2_server_boot_poll_interval = "foo_interval"
|
||||
@@ -39,9 +40,9 @@ class EC2ServersTestCase(test.ClientsTestCase):
|
||||
self.clients("ec2").run_instances.return_value = mock_instances
|
||||
server = scenario._boot_server("foo_image", "foo_flavor", foo="bar")
|
||||
|
||||
mock_wait.assert_called_once_with("foo_inst", is_ready="foo_state",
|
||||
update_resource="foo_update",
|
||||
timeout="foo_timeout",
|
||||
check_interval="foo_interval")
|
||||
mock_wait_for.assert_called_once_with("foo_inst", is_ready="foo_state",
|
||||
update_resource="foo_update",
|
||||
timeout="foo_timeout",
|
||||
check_interval="foo_interval")
|
||||
mock_time.sleep.assert_called_once_with("foo_delay")
|
||||
self.assertEqual(server, "running_server")
|
||||
|
@@ -27,17 +27,15 @@ class ModuleTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(UTILS + "six")
|
||||
@mock.patch(UTILS + "FuelClient", return_value="fuel_client")
|
||||
def test_fuel(self, mock_fuelclient, mock_six):
|
||||
def test_fuel(self, mock_fuel_client, mock_six):
|
||||
mock_six.moves.urllib.parse.urlparse().hostname = "foo_host"
|
||||
clients_ins = mock.Mock(endpoint=mock.Mock(username="foo_user",
|
||||
password="foo_pass"))
|
||||
|
||||
client = utils.fuel(clients_ins)
|
||||
mock_fuelclient.assert_called_once_with(version="v1",
|
||||
server_address="foo_host",
|
||||
server_port=8000,
|
||||
username="foo_user",
|
||||
password="foo_pass")
|
||||
mock_fuel_client.assert_called_once_with(
|
||||
version="v1", server_address="foo_host", server_port=8000,
|
||||
username="foo_user", password="foo_pass")
|
||||
self.assertEqual("fuel_client", client)
|
||||
|
||||
def test_fuel_is_registered(self):
|
||||
|
@@ -27,55 +27,56 @@ class GlanceImagesTestCase(test.TestCase):
|
||||
@mock.patch(GLANCE_IMAGES + "._generate_random_name")
|
||||
@mock.patch(GLANCE_IMAGES + "._list_images")
|
||||
@mock.patch(GLANCE_IMAGES + "._create_image")
|
||||
def test_create_and_list_image(self, mock_create, mock_list,
|
||||
mock_random_name):
|
||||
def test_create_and_list_image(self, mock__create_image,
|
||||
mock__list_images,
|
||||
mock__generate_random_name):
|
||||
glance_scenario = images.GlanceImages()
|
||||
mock_random_name.return_value = "test-rally-image"
|
||||
mock__generate_random_name.return_value = "test-rally-image"
|
||||
glance_scenario.create_and_list_image("cf", "url", "df",
|
||||
fakearg="f")
|
||||
mock_create.assert_called_once_with("cf", "url", "df",
|
||||
fakearg="f")
|
||||
mock_list.assert_called_once_with()
|
||||
mock__create_image.assert_called_once_with(
|
||||
"cf", "url", "df", fakearg="f")
|
||||
mock__list_images.assert_called_once_with()
|
||||
|
||||
@mock.patch(GLANCE_IMAGES + "._list_images")
|
||||
def test_list_images(self, mock_list):
|
||||
def test_list_images(self, mock__list_images):
|
||||
glance_scenario = images.GlanceImages()
|
||||
glance_scenario.list_images()
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_images.assert_called_once_with()
|
||||
|
||||
@mock.patch(GLANCE_IMAGES + "._generate_random_name")
|
||||
@mock.patch(GLANCE_IMAGES + "._delete_image")
|
||||
@mock.patch(GLANCE_IMAGES + "._create_image")
|
||||
def test_create_and_delete_image(self, mock_create, mock_delete,
|
||||
mock_random_name):
|
||||
def test_create_and_delete_image(
|
||||
self, mock__create_image, mock__delete_image,
|
||||
mock__generate_random_name):
|
||||
glance_scenario = images.GlanceImages()
|
||||
fake_image = object()
|
||||
mock_create.return_value = fake_image
|
||||
mock_random_name.return_value = "test-rally-image"
|
||||
mock__create_image.return_value = fake_image
|
||||
mock__generate_random_name.return_value = "test-rally-image"
|
||||
glance_scenario.create_and_delete_image("cf", "url", "df",
|
||||
fakearg="f")
|
||||
|
||||
mock_create.assert_called_once_with("cf",
|
||||
"url", "df", fakearg="f")
|
||||
mock_delete.assert_called_once_with(fake_image)
|
||||
mock__create_image.assert_called_once_with(
|
||||
"cf", "url", "df", fakearg="f")
|
||||
mock__delete_image.assert_called_once_with(fake_image)
|
||||
|
||||
@mock.patch(GLANCE_IMAGES + "._boot_servers")
|
||||
@mock.patch(GLANCE_IMAGES + "._create_image")
|
||||
def test_create_image_and_boot_instances(self,
|
||||
mock_create_image,
|
||||
mock_boot_servers):
|
||||
def test_create_image_and_boot_instances(
|
||||
self, mock__create_image, mock__boot_servers):
|
||||
glance_scenario = images.GlanceImages()
|
||||
fake_image = fakes.FakeImage()
|
||||
fake_servers = [mock.Mock() for i in range(5)]
|
||||
mock_create_image.return_value = fake_image
|
||||
mock_boot_servers.return_value = fake_servers
|
||||
mock__create_image.return_value = fake_image
|
||||
mock__boot_servers.return_value = fake_servers
|
||||
kwargs = {"fakearg": "f"}
|
||||
with mock.patch("rally.plugins.openstack.scenarios."
|
||||
"glance.utils.time.sleep"):
|
||||
glance_scenario.create_image_and_boot_instances("cf", "url",
|
||||
"df", "fid",
|
||||
5, **kwargs)
|
||||
mock_create_image.assert_called_once_with("cf",
|
||||
"url", "df")
|
||||
mock_boot_servers.assert_called_once_with("image-id-0",
|
||||
"fid", 5, **kwargs)
|
||||
mock__create_image.assert_called_once_with(
|
||||
"cf", "url", "df")
|
||||
mock__boot_servers.assert_called_once_with(
|
||||
"image-id-0", "fid", 5, **kwargs)
|
||||
|
@@ -33,26 +33,25 @@ class HeatStacksTestCase(test.ClientsTestCase):
|
||||
@mock.patch(HEAT_STACKS + "._generate_random_name")
|
||||
@mock.patch(HEAT_STACKS + "._list_stacks")
|
||||
@mock.patch(HEAT_STACKS + "._create_stack")
|
||||
def test_create_and_list_stack(self, mock_create, mock_list,
|
||||
mock_random_name):
|
||||
def test_create_and_list_stack(self, mock__create_stack, mock__list_stacks,
|
||||
mock__generate_random_name):
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
mock_random_name.return_value = "test-rally-stack"
|
||||
mock__generate_random_name.return_value = "test-rally-stack"
|
||||
heat_scenario.create_and_list_stack(
|
||||
template_path=self.default_template,
|
||||
parameters=self.default_parameters,
|
||||
files=self.default_files,
|
||||
environment=self.default_environment
|
||||
)
|
||||
mock_create.assert_called_once_with(self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock_list.assert_called_once_with()
|
||||
mock__create_stack.assert_called_once_with(
|
||||
self.default_template, self.default_parameters, self.default_files,
|
||||
self.default_environment)
|
||||
mock__list_stacks.assert_called_once_with()
|
||||
|
||||
@mock.patch(HEAT_STACKS + "._list_stacks")
|
||||
def test_list_stack_and_resources(self, mock_list_stack):
|
||||
def test_list_stack_and_resources(self, mock__list_stacks):
|
||||
stack = mock.Mock()
|
||||
mock_list_stack.return_value = [stack]
|
||||
mock__list_stacks.return_value = [stack]
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
heat_scenario.list_stacks_and_resources()
|
||||
self.clients("heat").resources.list.assert_called_once_with(stack.id)
|
||||
@@ -60,9 +59,9 @@ class HeatStacksTestCase(test.ClientsTestCase):
|
||||
heat_scenario.atomic_actions(), "heat.list_resources_of_1_stacks")
|
||||
|
||||
@mock.patch(HEAT_STACKS + "._list_stacks")
|
||||
def test_list_stack_and_events(self, mock_list_stack):
|
||||
def test_list_stack_and_events(self, mock__list_stacks):
|
||||
stack = mock.Mock()
|
||||
mock_list_stack.return_value = [stack]
|
||||
mock__list_stacks.return_value = [stack]
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
heat_scenario.list_stacks_and_events()
|
||||
self.clients("heat").events.list.assert_called_once_with(stack.id)
|
||||
@@ -72,12 +71,13 @@ class HeatStacksTestCase(test.ClientsTestCase):
|
||||
@mock.patch(HEAT_STACKS + "._generate_random_name")
|
||||
@mock.patch(HEAT_STACKS + "._delete_stack")
|
||||
@mock.patch(HEAT_STACKS + "._create_stack")
|
||||
def test_create_and_delete_stack(self, mock_create, mock_delete,
|
||||
mock_random_name):
|
||||
def test_create_and_delete_stack(
|
||||
self, mock__create_stack, mock__delete_stack,
|
||||
mock__generate_random_name):
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
fake_stack = object()
|
||||
mock_create.return_value = fake_stack
|
||||
mock_random_name.return_value = "test-rally-stack"
|
||||
mock__create_stack.return_value = fake_stack
|
||||
mock__generate_random_name.return_value = "test-rally-stack"
|
||||
heat_scenario.create_and_delete_stack(
|
||||
template_path=self.default_template,
|
||||
parameters=self.default_parameters,
|
||||
@@ -85,42 +85,44 @@ class HeatStacksTestCase(test.ClientsTestCase):
|
||||
environment=self.default_environment
|
||||
)
|
||||
|
||||
mock_create.assert_called_once_with(self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock_delete.assert_called_once_with(fake_stack)
|
||||
mock__create_stack.assert_called_once_with(
|
||||
self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock__delete_stack.assert_called_once_with(fake_stack)
|
||||
|
||||
@mock.patch(HEAT_STACKS + "._delete_stack")
|
||||
@mock.patch(HEAT_STACKS + "._check_stack")
|
||||
@mock.patch(HEAT_STACKS + "._create_stack")
|
||||
def test_create_check_delete_stack(self, mock_create, mock_check,
|
||||
mock_delete):
|
||||
def test_create_check_delete_stack(
|
||||
self, mock__create_stack, mock__check_stack, mock__delete_stack):
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
mock_create.return_value = "fake_stack_create_check_delete"
|
||||
heat_scenario.create_check_delete_stack(
|
||||
template_path=self.default_template,
|
||||
parameters=self.default_parameters,
|
||||
files=self.default_files,
|
||||
environment=self.default_environment
|
||||
)
|
||||
mock_create.assert_called_once_with(self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock_check.assert_called_once_with("fake_stack_create_check_delete")
|
||||
mock_delete.assert_called_once_with("fake_stack_create_check_delete")
|
||||
mock__create_stack.assert_called_once_with(
|
||||
self.default_template, self.default_parameters, self.default_files,
|
||||
self.default_environment)
|
||||
mock__check_stack.assert_called_once_with(
|
||||
mock__create_stack.return_value)
|
||||
mock__delete_stack.assert_called_once_with(
|
||||
mock__create_stack.return_value)
|
||||
|
||||
@mock.patch(HEAT_STACKS + "._generate_random_name")
|
||||
@mock.patch(HEAT_STACKS + "._delete_stack")
|
||||
@mock.patch(HEAT_STACKS + "._update_stack")
|
||||
@mock.patch(HEAT_STACKS + "._create_stack")
|
||||
def test_create_update_delete_stack(self, mock_create, mock_update,
|
||||
mock_delete, mock_random_name):
|
||||
def test_create_update_delete_stack(
|
||||
self, mock__create_stack, mock__update_stack, mock__delete_stack,
|
||||
mock__generate_random_name):
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
fake_stack = object()
|
||||
mock_create.return_value = fake_stack
|
||||
mock_random_name.return_value = "test-rally-stack"
|
||||
mock__create_stack.return_value = fake_stack
|
||||
mock__generate_random_name.return_value = "test-rally-stack"
|
||||
heat_scenario.create_update_delete_stack(
|
||||
template_path=self.default_template,
|
||||
parameters=self.default_parameters,
|
||||
@@ -129,27 +131,26 @@ class HeatStacksTestCase(test.ClientsTestCase):
|
||||
environment=self.default_environment
|
||||
)
|
||||
|
||||
mock_create.assert_called_once_with(self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock_update.assert_called_once_with(fake_stack, self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock_delete.assert_called_once_with(fake_stack)
|
||||
mock__create_stack.assert_called_once_with(
|
||||
self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock__update_stack.assert_called_once_with(
|
||||
fake_stack, self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock__delete_stack.assert_called_once_with(fake_stack)
|
||||
|
||||
@mock.patch(HEAT_STACKS + "._delete_stack")
|
||||
@mock.patch(HEAT_STACKS + "._resume_stack")
|
||||
@mock.patch(HEAT_STACKS + "._suspend_stack")
|
||||
@mock.patch(HEAT_STACKS + "._create_stack")
|
||||
def test_create_suspend_resume_delete_stack(self,
|
||||
mock_create,
|
||||
mock_suspend,
|
||||
mock_resume,
|
||||
mock_delete):
|
||||
def test_create_suspend_resume_delete_stack(
|
||||
self, mock__create_stack, mock__suspend_stack, mock__resume_stack,
|
||||
mock__delete_stack):
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
mock_create.return_value = "fake_stack_create_suspend_resume_delete"
|
||||
heat_scenario.create_suspend_resume_delete_stack(
|
||||
template_path=self.default_template,
|
||||
parameters=self.default_parameters,
|
||||
@@ -157,13 +158,16 @@ class HeatStacksTestCase(test.ClientsTestCase):
|
||||
environment=self.default_environment
|
||||
)
|
||||
|
||||
mock_create.assert_called_once_with(self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment)
|
||||
mock_suspend.assert_called_once_with(
|
||||
"fake_stack_create_suspend_resume_delete")
|
||||
mock_resume.assert_called_once_with(
|
||||
"fake_stack_create_suspend_resume_delete")
|
||||
mock_delete.assert_called_once_with(
|
||||
"fake_stack_create_suspend_resume_delete")
|
||||
mock__create_stack.assert_called_once_with(
|
||||
self.default_template,
|
||||
self.default_parameters,
|
||||
self.default_files,
|
||||
self.default_environment
|
||||
)
|
||||
mock__suspend_stack.assert_called_once_with(
|
||||
mock__create_stack.return_value)
|
||||
mock__resume_stack.assert_called_once_with(
|
||||
mock__create_stack.return_value)
|
||||
mock__delete_stack.assert_called_once_with(
|
||||
mock__create_stack.return_value
|
||||
)
|
||||
|
@@ -31,24 +31,22 @@ class KeystoneBasicTestCase(test.TestCase):
|
||||
"tenant": {"id": "fake"}
|
||||
}
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_user(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_user(self, mock_generate_random_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._user_create = mock.MagicMock()
|
||||
scenario.create_user(name_length=20, password="tttt", tenant_id="id")
|
||||
scenario._user_create.assert_called_once_with(name_length=20,
|
||||
password="tttt",
|
||||
tenant_id="id")
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_delete_user(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_delete_user(self, mock_generate_random_name):
|
||||
create_result = mock.MagicMock()
|
||||
|
||||
scenario = basic.KeystoneBasic()
|
||||
scenario._user_create = mock.MagicMock(return_value=create_result)
|
||||
scenario._resource_delete = mock.MagicMock()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
|
||||
scenario.create_delete_user(name_length=30, email="abcd", enabled=True)
|
||||
|
||||
@@ -57,19 +55,17 @@ class KeystoneBasicTestCase(test.TestCase):
|
||||
enabled=True)
|
||||
scenario._resource_delete.assert_called_once_with(create_result)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_tenant(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_tenant(self, mock_generate_random_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._tenant_create = mock.MagicMock()
|
||||
scenario.create_tenant(name_length=20, enabled=True)
|
||||
scenario._tenant_create.assert_called_once_with(name_length=20,
|
||||
enabled=True)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_tenant_with_users(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_tenant_with_users(self, mock_generate_random_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
fake_tenant = mock.MagicMock()
|
||||
scenario._tenant_create = mock.MagicMock(return_value=fake_tenant)
|
||||
scenario._users_create = mock.MagicMock()
|
||||
@@ -81,10 +77,9 @@ class KeystoneBasicTestCase(test.TestCase):
|
||||
users_per_tenant=1,
|
||||
name_length=20)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_and_list_users(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_and_list_users(self, mock_generate_random_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._user_create = mock.MagicMock()
|
||||
scenario._list_users = mock.MagicMock()
|
||||
scenario.create_and_list_users(name_length=20, password="tttt",
|
||||
@@ -94,10 +89,9 @@ class KeystoneBasicTestCase(test.TestCase):
|
||||
tenant_id="id")
|
||||
scenario._list_users.assert_called_once_with()
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_create_and_list_tenants(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_and_list_tenants(self, mock_generate_random_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeest"
|
||||
scenario._tenant_create = mock.MagicMock()
|
||||
scenario._list_tenants = mock.MagicMock()
|
||||
scenario.create_and_list_tenants(name_length=20, enabled=True)
|
||||
@@ -152,10 +146,9 @@ class KeystoneBasicTestCase(test.TestCase):
|
||||
scenario._list_roles_for_user.assert_called_once_with(fake_user,
|
||||
fake_tenant)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name")
|
||||
def test_get_entities(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_get_entities(self, mock_generate_random_name):
|
||||
scenario = basic.KeystoneBasic()
|
||||
mock_gen_name.return_value = "teeeeest"
|
||||
fake_tenant = mock.MagicMock()
|
||||
fake_user = mock.MagicMock()
|
||||
fake_role = mock.MagicMock()
|
||||
|
@@ -48,31 +48,31 @@ class KeystoneUtilsTestCase(test.TestCase):
|
||||
class KeystoneScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(UTILS + "uuid.uuid4", return_value="pwd")
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name",
|
||||
return_value="abc")
|
||||
def test_user_create(self, mock_gen_name, mock_uuid4):
|
||||
@mock.patch("rally.common.utils.generate_random_name",
|
||||
return_value="foobarov")
|
||||
def test_user_create(self, mock_generate_random_name, mock_uuid4):
|
||||
scenario = utils.KeystoneScenario()
|
||||
result = scenario._user_create()
|
||||
|
||||
self.assertEqual(
|
||||
self.admin_clients("keystone").users.create.return_value, result)
|
||||
self.admin_clients("keystone").users.create.assert_called_once_with(
|
||||
mock_gen_name.return_value,
|
||||
"foobarov",
|
||||
password=mock_uuid4.return_value,
|
||||
email=mock_gen_name.return_value + "@rally.me")
|
||||
email="foobarov@rally.me")
|
||||
mock_uuid4.assert_called_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_user")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_role_create(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_role_create(self, mock_generate_random_name):
|
||||
scenario = utils.KeystoneScenario()
|
||||
result = scenario._role_create()
|
||||
|
||||
self.assertEqual(
|
||||
self.admin_clients("keystone").roles.create.return_value, result)
|
||||
self.admin_clients("keystone").roles.create.assert_called_once_with(
|
||||
mock_gen_name.return_value)
|
||||
mock_generate_random_name.return_value)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_role")
|
||||
|
||||
@@ -129,21 +129,21 @@ class KeystoneScenarioTestCase(test.ClientsTestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.remove_role")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_tenant_create(self, mock_gen_name):
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_tenant_create(self, mock_generate_random_name):
|
||||
scenario = utils.KeystoneScenario()
|
||||
result = scenario._tenant_create()
|
||||
|
||||
self.assertEqual(
|
||||
self.admin_clients("keystone").tenants.create.return_value, result)
|
||||
self.admin_clients("keystone").tenants.create.assert_called_once_with(
|
||||
mock_gen_name.return_value)
|
||||
mock_generate_random_name.return_value)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_tenant")
|
||||
|
||||
def test_service_create(self):
|
||||
name = "abc"
|
||||
service_type = name + "service_type"
|
||||
service_type = name + "_service_type"
|
||||
description = name + "_description"
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
@@ -160,18 +160,16 @@ class KeystoneScenarioTestCase(test.ClientsTestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_service")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_tenant_create_with_users(self, mock_gen_name):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
|
||||
@mock.patch("rally.common.utils.generate_random_name",
|
||||
return_value="foobarov")
|
||||
def test_tenant_create_with_users(self, mock_generate_random_name):
|
||||
tenant = mock.MagicMock()
|
||||
scenario = utils.KeystoneScenario()
|
||||
|
||||
scenario._users_create(tenant, users_per_tenant=1, name_length=10)
|
||||
|
||||
self.admin_clients("keystone").users.create.assert_called_once_with(
|
||||
name, password=name, email=name + "@rally.me",
|
||||
"foobarov", password="foobarov", email="foobarov@rally.me",
|
||||
tenant_id=tenant.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_users")
|
||||
|
@@ -25,31 +25,33 @@ MISTRAL_WBS = ("rally.plugins.openstack.scenarios."
|
||||
class MistralWorkbooksTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(MISTRAL_WBS + "._list_workbooks")
|
||||
def test_list_workbooks(self, mock_list):
|
||||
def test_list_workbooks(self, mock__list_workbooks):
|
||||
mistral_scenario = workbooks.MistralWorkbooks()
|
||||
mistral_scenario.list_workbooks()
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_workbooks.assert_called_once_with()
|
||||
|
||||
@mock.patch(MISTRAL_WBS + "._create_workbook")
|
||||
def test_create_workbook(self, mock_create):
|
||||
def test_create_workbook(self, mock__create_workbook):
|
||||
mistral_scenario = workbooks.MistralWorkbooks()
|
||||
definition = "---\nversion: \"2.0\"\nname: wb"
|
||||
fake_wb = mock.MagicMock()
|
||||
fake_wb.name = "wb"
|
||||
mock_create.return_value = fake_wb
|
||||
mock__create_workbook.return_value = fake_wb
|
||||
mistral_scenario.create_workbook(definition)
|
||||
|
||||
self.assertEqual(1, mock_create.called)
|
||||
self.assertEqual(1, mock__create_workbook.called)
|
||||
|
||||
@mock.patch(MISTRAL_WBS + "._delete_workbook")
|
||||
@mock.patch(MISTRAL_WBS + "._create_workbook")
|
||||
def test_create_delete_workbook(self, mock_create, mock_delete):
|
||||
def test_create_delete_workbook(self,
|
||||
mock__create_workbook,
|
||||
mock__delete_workbook):
|
||||
mistral_scenario = workbooks.MistralWorkbooks()
|
||||
definition = "---\nversion: \"2.0\"\nname: wb"
|
||||
fake_wb = mock.MagicMock()
|
||||
fake_wb.name = "wb"
|
||||
mock_create.return_value = fake_wb
|
||||
mock__create_workbook.return_value = fake_wb
|
||||
mistral_scenario.create_workbook(definition, do_delete=True)
|
||||
|
||||
self.assertEqual(1, mock_create.called)
|
||||
mock_delete.assert_called_once_with(fake_wb.name)
|
||||
self.assertEqual(1, mock__create_workbook.called)
|
||||
mock__delete_workbook.assert_called_once_with(fake_wb.name)
|
||||
|
@@ -44,40 +44,40 @@ class MuranoEnvironmentsTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
@mock.patch(MURANO_SCENARIO + "._list_environments")
|
||||
def test_list_environments(self, mock_list):
|
||||
def test_list_environments(self, mock__list_environments):
|
||||
scenario = environments.MuranoEnvironments()
|
||||
scenario._list_environments()
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_environments.assert_called_once_with()
|
||||
|
||||
@mock.patch(MURANO_SCENARIO + "._create_session")
|
||||
@mock.patch(MURANO_SCENARIO + "._delete_environment")
|
||||
@mock.patch(MURANO_SCENARIO + "._create_environment")
|
||||
@mock.patch(MURANO_SCENARIO + "._generate_random_name")
|
||||
def test_create_and_delete_environment(self, mock_random_name,
|
||||
mock_create, mock_delete,
|
||||
mock_session):
|
||||
def test_create_and_delete_environment(
|
||||
self, mock__generate_random_name, mock__create_environment,
|
||||
mock__delete_environment, mock__create_session):
|
||||
scenario = environments.MuranoEnvironments()
|
||||
fake_environment = mock.Mock(id="fake_id")
|
||||
mock_create.return_value = fake_environment
|
||||
mock_random_name.return_value = "foo"
|
||||
mock__create_environment.return_value = fake_environment
|
||||
mock__generate_random_name.return_value = "foo"
|
||||
scenario.create_and_delete_environment()
|
||||
mock_create.assert_called_once_with()
|
||||
mock_session.assert_called_once_with(fake_environment.id)
|
||||
mock_delete.assert_called_once_with(fake_environment)
|
||||
mock__create_environment.assert_called_once_with()
|
||||
mock__create_session.assert_called_once_with(fake_environment.id)
|
||||
mock__delete_environment.assert_called_once_with(fake_environment)
|
||||
|
||||
@mock.patch(MURANO_SCENARIO + "._create_environment")
|
||||
@mock.patch(MURANO_SCENARIO + "._create_session")
|
||||
@mock.patch(MURANO_SCENARIO + "._create_service")
|
||||
@mock.patch(MURANO_SCENARIO + "._deploy_environment")
|
||||
def test_create_and_deploy_environment(self, mock_deploy_env,
|
||||
mock_create_service, mock_session,
|
||||
mock_environment):
|
||||
def test_create_and_deploy_environment(
|
||||
self, mock__deploy_environment, mock__create_service,
|
||||
mock__create_session, mock__create_environment):
|
||||
|
||||
fake_environment = mock.MagicMock(id="fake_env_id")
|
||||
mock_environment.return_value = fake_environment
|
||||
mock__create_environment.return_value = fake_environment
|
||||
|
||||
fake_session = mock.Mock(id="fake_session_id")
|
||||
mock_session.return_value = fake_session
|
||||
mock__create_session.return_value = fake_session
|
||||
|
||||
scenario = environments.MuranoEnvironments()
|
||||
scenario.context = self._get_context()
|
||||
@@ -89,9 +89,9 @@ class MuranoEnvironmentsTestCase(test.TestCase):
|
||||
|
||||
scenario.create_and_deploy_environment(1)
|
||||
|
||||
mock_environment.assert_called_once_with()
|
||||
mock_session.assert_called_once_with(fake_environment.id)
|
||||
mock_create_service.assert_called_once_with(
|
||||
mock__create_environment.assert_called_once_with()
|
||||
mock__create_session.assert_called_once_with(fake_environment.id)
|
||||
mock__create_service.assert_called_once_with(
|
||||
fake_environment, fake_session, "fake", atomic_action=False)
|
||||
mock_deploy_env.assert_called_once_with(fake_environment,
|
||||
fake_session)
|
||||
mock__deploy_environment.assert_called_once_with(
|
||||
fake_environment, fake_session)
|
||||
|
@@ -26,25 +26,26 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._list_networks")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network")
|
||||
def test_create_and_list_networks(self, mock_create, mock_list):
|
||||
def test_create_and_list_networks(self, mock__create_network,
|
||||
mock__list_networks):
|
||||
neutron_scenario = network.NeutronNetworks()
|
||||
|
||||
# Default options
|
||||
network_create_args = {}
|
||||
neutron_scenario.create_and_list_networks(
|
||||
network_create_args=network_create_args)
|
||||
mock_create.assert_called_once_with(network_create_args)
|
||||
mock_list.assert_called_once_with()
|
||||
mock__create_network.assert_called_once_with(network_create_args)
|
||||
mock__list_networks.assert_called_once_with()
|
||||
|
||||
mock_create.reset_mock()
|
||||
mock_list.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
mock__list_networks.reset_mock()
|
||||
|
||||
# Explicit network name is specified
|
||||
network_create_args = {"name": "given-name"}
|
||||
neutron_scenario.create_and_list_networks(
|
||||
network_create_args=network_create_args)
|
||||
mock_create.assert_called_once_with(network_create_args)
|
||||
mock_list.assert_called_once_with()
|
||||
mock__create_network.assert_called_once_with(network_create_args)
|
||||
mock__list_networks.assert_called_once_with()
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._update_network")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network", return_value={
|
||||
@@ -55,8 +56,8 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
}
|
||||
})
|
||||
def test_create_and_update_networks(self,
|
||||
mock_create_network,
|
||||
mock_update_network):
|
||||
mock__create_network,
|
||||
mock__update_network):
|
||||
scenario = network.NeutronNetworks()
|
||||
|
||||
network_update_args = {"name": "_updated", "admin_state_up": True}
|
||||
@@ -65,13 +66,15 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
scenario.create_and_update_networks(
|
||||
network_update_args=network_update_args)
|
||||
|
||||
mock_create_network.assert_called_once_with({})
|
||||
mock__create_network.assert_called_once_with({})
|
||||
|
||||
mock_update_network.assert_has_calls(
|
||||
[mock.call(mock_create_network.return_value, network_update_args)])
|
||||
mock__update_network.assert_has_calls(
|
||||
[mock.call(
|
||||
mock__create_network.return_value, network_update_args
|
||||
)])
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock_update_network.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
mock__update_network.reset_mock()
|
||||
|
||||
# Explicit network name is specified
|
||||
network_create_args = {"name": "network-name", "admin_state_up": False}
|
||||
@@ -79,55 +82,54 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
scenario.create_and_update_networks(
|
||||
network_create_args=network_create_args,
|
||||
network_update_args=network_update_args)
|
||||
mock_create_network.assert_called_once_with(network_create_args)
|
||||
mock_update_network.assert_has_calls(
|
||||
[mock.call(mock_create_network.return_value, network_update_args)])
|
||||
mock__create_network.assert_called_once_with(network_create_args)
|
||||
mock__update_network.assert_has_calls(
|
||||
[mock.call(mock__create_network.return_value,
|
||||
network_update_args)])
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._delete_network")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network")
|
||||
def test_create_and_delete_networks(self, mock_create, mock_delete):
|
||||
def test_create_and_delete_networks(self, mock__create_network,
|
||||
mock__delete_network):
|
||||
neutron_scenario = network.NeutronNetworks()
|
||||
|
||||
# Default options
|
||||
network_create_args = {}
|
||||
neutron_scenario.create_and_delete_networks()
|
||||
mock_create.assert_called_once_with(network_create_args)
|
||||
self.assertEqual(1, mock_delete.call_count)
|
||||
mock__create_network.assert_called_once_with(network_create_args)
|
||||
self.assertEqual(1, mock__delete_network.call_count)
|
||||
|
||||
mock_create.reset_mock()
|
||||
mock_delete.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
mock__delete_network.reset_mock()
|
||||
|
||||
# Explict network name is specified
|
||||
network_create_args = {"name": "given-name"}
|
||||
neutron_scenario.create_and_delete_networks(
|
||||
network_create_args=network_create_args)
|
||||
mock_create.assert_called_once_with(network_create_args)
|
||||
self.assertEqual(1, mock_delete.call_count)
|
||||
mock__create_network.assert_called_once_with(network_create_args)
|
||||
self.assertEqual(1, mock__delete_network.call_count)
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._list_subnets")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
def test_create_and_list_subnets(self,
|
||||
mock_create_network_and_subnets,
|
||||
mock_list):
|
||||
mock__create_network_and_subnets,
|
||||
mock__list_subnets):
|
||||
scenario = network.NeutronNetworks()
|
||||
subnets_per_network = 4
|
||||
subnet_cidr_start = "default_cidr"
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_list.reset_mock()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_list_subnets(
|
||||
subnets_per_network=subnets_per_network,
|
||||
subnet_cidr_start=subnet_cidr_start)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {}, subnets_per_network,
|
||||
subnet_cidr_start)])
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_subnets.assert_called_once_with()
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_list.reset_mock()
|
||||
mock__create_network_and_subnets.reset_mock()
|
||||
mock__list_subnets.reset_mock()
|
||||
|
||||
# Custom options
|
||||
scenario.create_and_list_subnets(
|
||||
@@ -135,16 +137,16 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnet_cidr_start="custom_cidr",
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {"allocation_pools": []},
|
||||
subnets_per_network, "custom_cidr")])
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_subnets.assert_called_once_with()
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._update_subnet")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
def test_create_and_update_subnets(self,
|
||||
mock_create_network_and_subnets,
|
||||
mock_update_subnet):
|
||||
mock__create_network_and_subnets,
|
||||
mock__update_subnet):
|
||||
scenario = network.NeutronNetworks()
|
||||
subnets_per_network = 1
|
||||
subnet_cidr_start = "default_cidr"
|
||||
@@ -160,25 +162,22 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
"enable_dhcp": False
|
||||
}
|
||||
}
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock__create_network_and_subnets.return_value = (net, [subnet])
|
||||
subnet_update_args = {"name": "_updated", "enable_dhcp": True}
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_update_subnet.reset_mock()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_update_subnets(
|
||||
subnet_update_args=subnet_update_args,
|
||||
subnet_cidr_start=subnet_cidr_start,
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {}, subnets_per_network, subnet_cidr_start)])
|
||||
mock_update_subnet.assert_has_calls(
|
||||
mock__update_subnet.assert_has_calls(
|
||||
[mock.call(subnet, subnet_update_args)])
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_update_subnet.reset_mock()
|
||||
mock__create_network_and_subnets.reset_mock()
|
||||
mock__update_subnet.reset_mock()
|
||||
|
||||
# Custom options
|
||||
subnet_cidr_start = "custom_cidr"
|
||||
@@ -188,17 +187,17 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnet_cidr_start=subnet_cidr_start,
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {"allocation_pools": []}, subnets_per_network,
|
||||
subnet_cidr_start)])
|
||||
mock_update_subnet.assert_has_calls(
|
||||
mock__update_subnet.assert_has_calls(
|
||||
[mock.call(subnet, subnet_update_args)])
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._delete_subnet")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
def test_create_and_delete_subnets(self,
|
||||
mock_create_network_and_subnets,
|
||||
mock_delete):
|
||||
mock__create_network_and_subnets,
|
||||
mock__delete_subnet):
|
||||
scenario = network.NeutronNetworks()
|
||||
net = {
|
||||
"network": {
|
||||
@@ -212,26 +211,23 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
"enable_dhcp": False
|
||||
}
|
||||
}
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock__create_network_and_subnets.return_value = (net, [subnet])
|
||||
subnets_per_network = 1
|
||||
subnet_cidr_start = "default_cidr"
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_delete.reset_mock()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_delete_subnets(
|
||||
subnets_per_network=subnets_per_network,
|
||||
subnet_cidr_start=subnet_cidr_start)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {}, subnets_per_network,
|
||||
subnet_cidr_start)])
|
||||
|
||||
mock_delete.assert_has_calls([mock.call(subnet)])
|
||||
mock__delete_subnet.assert_has_calls([mock.call(subnet)])
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_delete.reset_mock()
|
||||
mock__create_network_and_subnets.reset_mock()
|
||||
mock__delete_subnet.reset_mock()
|
||||
|
||||
# Custom options
|
||||
subnet_cidr_start = "custom_cidr"
|
||||
@@ -240,18 +236,18 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnet_cidr_start="custom_cidr",
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {"allocation_pools": []}, subnets_per_network,
|
||||
subnet_cidr_start)])
|
||||
mock_delete.assert_has_calls([mock.call(subnet)])
|
||||
mock__delete_subnet.assert_has_calls([mock.call(subnet)])
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._list_routers")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
def test_create_and_list_routers(self,
|
||||
mock_create_network_and_subnets,
|
||||
mock_create_router,
|
||||
mock_list):
|
||||
mock__create_network_and_subnets,
|
||||
mock__create_router,
|
||||
mock__list_routers):
|
||||
scenario = network.NeutronNetworks()
|
||||
subnets_per_network = 1
|
||||
subnet_cidr_start = "default_cidr"
|
||||
@@ -268,7 +264,7 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
"enable_dhcp": False
|
||||
}
|
||||
}
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock__create_network_and_subnets.return_value = (net, [subnet])
|
||||
self.clients("neutron").add_interface_router = mock.Mock()
|
||||
router = {
|
||||
"router": {
|
||||
@@ -276,16 +272,16 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
"id": "router-id"
|
||||
}
|
||||
}
|
||||
mock_create_router.return_value = router
|
||||
mock__create_router.return_value = router
|
||||
|
||||
# Default options
|
||||
scenario.create_and_list_routers(
|
||||
subnet_cidr_start=subnet_cidr_start,
|
||||
subnets_per_network=subnets_per_network)
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {}, subnets_per_network, subnet_cidr_start)])
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
mock__create_router.assert_has_calls(
|
||||
[mock.call({})] * subnets_per_network)
|
||||
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
@@ -293,11 +289,11 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_create_router.reset_mock()
|
||||
mock__create_network_and_subnets.reset_mock()
|
||||
mock__create_router.reset_mock()
|
||||
|
||||
self.clients("neutron").add_interface_router.reset_mock()
|
||||
mock_list.reset_mock()
|
||||
mock__list_routers.reset_mock()
|
||||
|
||||
# Custom options
|
||||
subnet_cidr_start = "custom_cidr"
|
||||
@@ -309,26 +305,26 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnets_per_network=subnets_per_network,
|
||||
router_create_args=router_create_args)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, subnet_create_args, subnets_per_network,
|
||||
subnet_cidr_start)])
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
mock__create_router.assert_has_calls(
|
||||
[mock.call(router_create_args)] * subnets_per_network)
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_routers.assert_called_once_with()
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._update_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
def test_create_and_update_routers(self,
|
||||
mock_create_network_and_subnets,
|
||||
mock_create_router,
|
||||
mock_update_router):
|
||||
mock__create_network_and_subnets,
|
||||
mock__create_router,
|
||||
mock__update_router):
|
||||
scenario = network.NeutronNetworks()
|
||||
subnets_per_network = 1
|
||||
subnet_cidr_start = "default_cidr"
|
||||
@@ -355,8 +351,8 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
"name": "_updated",
|
||||
"admin_state_up": False
|
||||
}
|
||||
mock_create_router.return_value = router
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock__create_router.return_value = router
|
||||
mock__create_network_and_subnets.return_value = (net, [subnet])
|
||||
self.clients("neutron").add_interface_router = mock.Mock()
|
||||
|
||||
# Default options
|
||||
@@ -365,24 +361,24 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnet_cidr_start=subnet_cidr_start,
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {}, subnets_per_network, subnet_cidr_start)])
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
mock__create_router.assert_has_calls(
|
||||
[mock.call({})] * subnets_per_network)
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
|
||||
mock_update_router.assert_has_calls(
|
||||
mock__update_router.assert_has_calls(
|
||||
[mock.call(router, router_update_args)
|
||||
] * subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_create_router.reset_mock()
|
||||
mock__create_network_and_subnets.reset_mock()
|
||||
mock__create_router.reset_mock()
|
||||
self.clients("neutron").add_interface_router.reset_mock()
|
||||
mock_update_router.reset_mock()
|
||||
mock__update_router.reset_mock()
|
||||
|
||||
# Custom options
|
||||
subnet_cidr_start = "custom_cidr"
|
||||
@@ -395,18 +391,18 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnets_per_network=subnets_per_network,
|
||||
router_create_args=router_create_args)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, subnet_create_args, subnets_per_network,
|
||||
subnet_cidr_start)])
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
mock__create_router.assert_has_calls(
|
||||
[mock.call(router_create_args)] * subnets_per_network)
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
|
||||
mock_update_router.assert_has_calls(
|
||||
mock__update_router.assert_has_calls(
|
||||
[mock.call(router, router_update_args)
|
||||
] * subnets_per_network)
|
||||
|
||||
@@ -414,9 +410,9 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
def test_create_and_delete_routers(self,
|
||||
mock_create_network_and_subnets,
|
||||
mock_create_router,
|
||||
mock_delete_router):
|
||||
mock__create_network_and_subnets,
|
||||
mock__create_router,
|
||||
mock__delete_router):
|
||||
scenario = network.NeutronNetworks()
|
||||
subnets_per_network = 1
|
||||
subnet_cidr_start = "default_cidr"
|
||||
@@ -440,8 +436,8 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
}
|
||||
}
|
||||
|
||||
mock_create_router.return_value = router
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock__create_router.return_value = router
|
||||
mock__create_network_and_subnets.return_value = (net, [subnet])
|
||||
self.clients("neutron").add_interface_router = mock.Mock()
|
||||
|
||||
# Default options
|
||||
@@ -449,23 +445,23 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnet_cidr_start=subnet_cidr_start,
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, {}, subnets_per_network, subnet_cidr_start)])
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
mock__create_router.assert_has_calls(
|
||||
[mock.call({})] * subnets_per_network)
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
|
||||
mock_delete_router.assert_has_calls(
|
||||
mock__delete_router.assert_has_calls(
|
||||
[mock.call(router)] * subnets_per_network)
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_create_router.reset_mock()
|
||||
mock__create_network_and_subnets.reset_mock()
|
||||
mock__create_router.reset_mock()
|
||||
self.clients("neutron").add_interface_router.reset_mock()
|
||||
mock_delete_router.reset_mock()
|
||||
mock__delete_router.reset_mock()
|
||||
|
||||
# Custom options
|
||||
subnet_cidr_start = "custom_cidr"
|
||||
@@ -477,18 +473,18 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
subnets_per_network=subnets_per_network,
|
||||
router_create_args=router_create_args)
|
||||
|
||||
mock_create_network_and_subnets.assert_has_calls(
|
||||
mock__create_network_and_subnets.assert_has_calls(
|
||||
[mock.call({}, subnet_create_args, subnets_per_network,
|
||||
subnet_cidr_start)])
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
mock__create_router.assert_has_calls(
|
||||
[mock.call(router_create_args)] * subnets_per_network)
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
|
||||
mock_delete_router.assert_has_calls(
|
||||
mock__delete_router.assert_has_calls(
|
||||
[mock.call(router)] * subnets_per_network)
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._generate_random_name")
|
||||
@@ -496,41 +492,41 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_port")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network")
|
||||
def test_create_and_list_ports(self,
|
||||
mock_create_network,
|
||||
mock_create_port,
|
||||
mock_list,
|
||||
mock_random_name):
|
||||
mock__create_network,
|
||||
mock__create_port,
|
||||
mock__list_ports,
|
||||
mock__generate_random_name):
|
||||
scenario = network.NeutronNetworks()
|
||||
mock_random_name.return_value = "random-name"
|
||||
mock__generate_random_name.return_value = "random-name"
|
||||
net = {"network": {"id": "fake-id"}}
|
||||
mock_create_network.return_value = net
|
||||
mock__create_network.return_value = net
|
||||
ports_per_network = 10
|
||||
|
||||
self.assertRaises(TypeError, scenario.create_and_list_ports)
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
|
||||
# Defaults
|
||||
scenario.create_and_list_ports(ports_per_network=ports_per_network)
|
||||
mock_create_network.assert_called_once_with({})
|
||||
self.assertEqual(mock_create_port.mock_calls,
|
||||
mock__create_network.assert_called_once_with({})
|
||||
self.assertEqual(mock__create_port.mock_calls,
|
||||
[mock.call(net, {})] * ports_per_network)
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_ports.assert_called_once_with()
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock_create_port.reset_mock()
|
||||
mock_list.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
mock__create_port.reset_mock()
|
||||
mock__list_ports.reset_mock()
|
||||
|
||||
# Custom options
|
||||
scenario.create_and_list_ports(
|
||||
network_create_args={"name": "given-name"},
|
||||
port_create_args={"allocation_pools": []},
|
||||
ports_per_network=ports_per_network)
|
||||
mock_create_network.assert_called_once_with({"name": "given-name"})
|
||||
mock__create_network.assert_called_once_with({"name": "given-name"})
|
||||
self.assertEqual(
|
||||
mock_create_port.mock_calls,
|
||||
mock__create_port.mock_calls,
|
||||
[mock.call(net, {"allocation_pools": []})] * ports_per_network)
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_ports.assert_called_once_with()
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._generate_random_name")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._update_port")
|
||||
@@ -544,12 +540,12 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network", return_value={
|
||||
"network": {"id": "fake-id"}})
|
||||
def test_create_and_update_ports(self,
|
||||
mock_create_network,
|
||||
mock_create_port,
|
||||
mock_update_port,
|
||||
mock_random_name):
|
||||
mock__create_network,
|
||||
mock__create_port,
|
||||
mock__update_port,
|
||||
mock__generate_random_name):
|
||||
scenario = network.NeutronNetworks()
|
||||
mock_random_name.return_value = "random-name"
|
||||
mock__generate_random_name.return_value = "random-name"
|
||||
ports_per_network = 10
|
||||
|
||||
port_update_args = {
|
||||
@@ -561,18 +557,18 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
scenario.create_and_update_ports(
|
||||
port_update_args=port_update_args,
|
||||
ports_per_network=ports_per_network)
|
||||
mock_create_network.assert_called_once_with({})
|
||||
mock__create_network.assert_called_once_with({})
|
||||
|
||||
mock_create_port.assert_has_calls(
|
||||
mock__create_port.assert_has_calls(
|
||||
[mock.call({"network": {"id": "fake-id"}},
|
||||
{})] * ports_per_network)
|
||||
mock_update_port.assert_has_calls(
|
||||
[mock.call(mock_create_port.return_value, port_update_args)
|
||||
mock__update_port.assert_has_calls(
|
||||
[mock.call(mock__create_port.return_value, port_update_args)
|
||||
] * ports_per_network)
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock_create_port.reset_mock()
|
||||
mock_update_port.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
mock__create_port.reset_mock()
|
||||
mock__update_port.reset_mock()
|
||||
|
||||
# Custom options
|
||||
scenario.create_and_update_ports(
|
||||
@@ -580,12 +576,12 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
network_create_args={"name": "given-name"},
|
||||
port_create_args={"allocation_pools": []},
|
||||
ports_per_network=ports_per_network)
|
||||
mock_create_network.assert_called_once_with({"name": "given-name"})
|
||||
mock_create_port.assert_has_calls(
|
||||
mock__create_network.assert_called_once_with({"name": "given-name"})
|
||||
mock__create_port.assert_has_calls(
|
||||
[mock.call({"network": {"id": "fake-id"}},
|
||||
{"allocation_pools": []})] * ports_per_network)
|
||||
mock_update_port.assert_has_calls(
|
||||
[mock.call(mock_create_port.return_value, port_update_args)
|
||||
mock__update_port.assert_has_calls(
|
||||
[mock.call(mock__create_port.return_value, port_update_args)
|
||||
] * ports_per_network)
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._generate_random_name")
|
||||
@@ -593,40 +589,41 @@ class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_port")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network")
|
||||
def test_create_and_delete_ports(self,
|
||||
mock_create_network,
|
||||
mock_create_port,
|
||||
mock_delete,
|
||||
mock_random_name):
|
||||
mock__create_network,
|
||||
mock__create_port,
|
||||
mock__delete_port,
|
||||
mock__generate_random_name):
|
||||
scenario = network.NeutronNetworks()
|
||||
mock_random_name.return_value = "random-name"
|
||||
mock__generate_random_name.return_value = "random-name"
|
||||
net = {"network": {"id": "fake-id"}}
|
||||
mock_create_network.return_value = net
|
||||
mock__create_network.return_value = net
|
||||
ports_per_network = 10
|
||||
|
||||
self.assertRaises(TypeError, scenario.create_and_delete_ports)
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_delete_ports(ports_per_network=ports_per_network)
|
||||
mock_create_network.assert_called_once_with({})
|
||||
self.assertEqual(mock_create_port.mock_calls,
|
||||
mock__create_network.assert_called_once_with({})
|
||||
self.assertEqual(mock__create_port.mock_calls,
|
||||
[mock.call(net, {})] * ports_per_network)
|
||||
self.assertEqual(mock_delete.mock_calls,
|
||||
[mock.call(mock_create_port())] * ports_per_network)
|
||||
self.assertEqual(mock__delete_port.mock_calls,
|
||||
[mock.call(mock__create_port())] * ports_per_network)
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock_create_port.reset_mock()
|
||||
mock_delete.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
mock__create_port.reset_mock()
|
||||
mock__delete_port.reset_mock()
|
||||
|
||||
# Custom options
|
||||
scenario.create_and_delete_ports(
|
||||
network_create_args={"name": "given-name"},
|
||||
port_create_args={"allocation_pools": []},
|
||||
ports_per_network=ports_per_network)
|
||||
mock_create_network.assert_called_once_with({"name": "given-name"})
|
||||
mock__create_network.assert_called_once_with({"name": "given-name"})
|
||||
self.assertEqual(
|
||||
mock_create_port.mock_calls,
|
||||
mock__create_port.mock_calls,
|
||||
[mock.call(net, {"allocation_pools": []})] * ports_per_network)
|
||||
self.assertEqual(mock_delete.mock_calls,
|
||||
[mock.call(mock_create_port())] * ports_per_network)
|
||||
self.assertEqual(
|
||||
mock__delete_port.mock_calls,
|
||||
[mock.call(mock__create_port.return_value)] * ports_per_network)
|
||||
|
@@ -29,11 +29,11 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
self.network = mock.Mock()
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
|
||||
def test_create_network(self, mock_random_name):
|
||||
def test_create_network(self, mock__generate_random_name):
|
||||
neutron_scenario = utils.NeutronScenario()
|
||||
explicit_name = "explicit_name"
|
||||
random_name = "random_name"
|
||||
mock_random_name.return_value = random_name
|
||||
mock__generate_random_name.return_value = random_name
|
||||
self.clients("neutron").create_network.return_value = self.network
|
||||
|
||||
# Network name is specified
|
||||
@@ -96,7 +96,7 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name",
|
||||
return_value="test_subnet")
|
||||
def test_create_subnet(self, mock_random_name):
|
||||
def test_create_subnet(self, mock__generate_random_name):
|
||||
scenario = utils.NeutronScenario()
|
||||
network_id = "fake-id"
|
||||
start_cidr = "192.168.0.0/24"
|
||||
@@ -107,7 +107,7 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
"network_id": network_id,
|
||||
"cidr": start_cidr,
|
||||
"ip_version": scenario.SUBNET_IP_VERSION,
|
||||
"name": mock_random_name.return_value
|
||||
"name": mock__generate_random_name.return_value
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,12 +171,12 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
"neutron.delete_subnet")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
|
||||
def test_create_router(self, mock_random_name):
|
||||
def test_create_router(self, mock__generate_random_name):
|
||||
scenario = utils.NeutronScenario()
|
||||
router = mock.Mock()
|
||||
explicit_name = "explicit_name"
|
||||
random_name = "random_name"
|
||||
mock_random_name.return_value = random_name
|
||||
mock__generate_random_name.return_value = random_name
|
||||
self.clients("neutron").create_router.return_value = router
|
||||
|
||||
# Default options
|
||||
@@ -257,13 +257,13 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
self.assertEqual(utils.NeutronScenario.SUBNET_IP_VERSION, 4)
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
|
||||
def test_create_port(self, mock_rand_name):
|
||||
def test_create_port(self, mock__generate_random_name):
|
||||
scenario = utils.NeutronScenario()
|
||||
|
||||
net_id = "network-id"
|
||||
net = {"network": {"id": net_id}}
|
||||
rand_name = "random-name"
|
||||
mock_rand_name.return_value = rand_name
|
||||
mock__generate_random_name.return_value = rand_name
|
||||
expected_port_args = {
|
||||
"port": {
|
||||
"network_id": net_id,
|
||||
@@ -354,29 +354,26 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
}
|
||||
})
|
||||
def test_create_network_and_subnets(self,
|
||||
mock_create_network,
|
||||
mock_create_subnet):
|
||||
mock__create_network,
|
||||
mock__create_subnet):
|
||||
scenario = utils.NeutronScenario()
|
||||
network_create_args = {}
|
||||
subnet_create_args = {}
|
||||
subnets_per_network = 4
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock_create_subnet.reset_mock()
|
||||
|
||||
# Default options
|
||||
scenario._create_network_and_subnets(
|
||||
network_create_args=network_create_args,
|
||||
subnet_create_args=subnet_create_args,
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network.assert_called_once_with({})
|
||||
mock_create_subnet.assert_has_calls(
|
||||
mock__create_network.assert_called_once_with({})
|
||||
mock__create_subnet.assert_has_calls(
|
||||
[mock.call({"network": {"id": "fake-id"}},
|
||||
{}, "1.0.0.0/24")] * subnets_per_network)
|
||||
|
||||
mock_create_network.reset_mock()
|
||||
mock_create_subnet.reset_mock()
|
||||
mock__create_network.reset_mock()
|
||||
mock__create_subnet.reset_mock()
|
||||
|
||||
# Custom options
|
||||
scenario._create_network_and_subnets(
|
||||
@@ -385,8 +382,8 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
subnet_cidr_start="10.10.10.0/24",
|
||||
subnets_per_network=subnets_per_network)
|
||||
|
||||
mock_create_network.assert_called_once_with({})
|
||||
mock_create_subnet.assert_has_calls(
|
||||
mock__create_network.assert_called_once_with({})
|
||||
mock__create_subnet.assert_has_calls(
|
||||
[mock.call({"network": {"id": "fake-id"}},
|
||||
{"allocation_pools": []},
|
||||
"10.10.10.0/24")] * subnets_per_network)
|
||||
@@ -411,13 +408,13 @@ class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
neutron_scenario.atomic_actions(), "neutron.create_pool")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
|
||||
def test_create_v1_pool_default(self, mock_random_name):
|
||||
def test_create_v1_pool_default(self, mock__generate_random_name):
|
||||
neutron_scenario = utils.NeutronScenario()
|
||||
random_name = "random_name"
|
||||
subnet = "fake-id"
|
||||
pool = mock.Mock()
|
||||
self.clients("neutron").create_pool.return_value = pool
|
||||
mock_random_name.return_value = random_name
|
||||
mock__generate_random_name.return_value = random_name
|
||||
# Random pool name
|
||||
pool_data = {}
|
||||
args = {"lb_method": "ROUND_ROBIN", "protocol": "HTTP",
|
||||
|
@@ -25,7 +25,6 @@ from tests.unit import test
|
||||
|
||||
BM_UTILS = "rally.benchmark.utils"
|
||||
NOVA_UTILS = "rally.plugins.openstack.scenarios.nova.utils"
|
||||
SCN = "rally.benchmark.scenarios.base"
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
@@ -95,9 +94,9 @@ class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.list_servers")
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
def test__boot_server(self, mock_generate_random_name):
|
||||
def test__boot_server(self, mock__generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={})
|
||||
return_server = nova_scenario._boot_server("image_id",
|
||||
@@ -113,9 +112,9 @@ class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.boot_server")
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
def test__boot_server_with_network(self, mock_generate_random_name):
|
||||
def test__boot_server_with_network(self, mock__generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
networks = [{"id": "foo_id", "external": False},
|
||||
{"id": "bar_id", "external": False}]
|
||||
@@ -147,9 +146,9 @@ class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
"image_id", "flavor_id",
|
||||
auto_assign_nic=True)
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
def test__boot_server_with_ssh(self, mock_generate_random_name):
|
||||
def test__boot_server_with_ssh(self, mock__generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "test"}}}
|
||||
@@ -167,9 +166,9 @@ class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.boot_server")
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
def test__boot_server_with_sec_group(self, mock_generate_random_name):
|
||||
def test__boot_server_with_sec_group(self, mock__generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "new"}}}
|
||||
@@ -189,10 +188,10 @@ class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.boot_server")
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
def test__boot_server_with_similar_sec_group(self,
|
||||
mock_generate_random_name):
|
||||
mock__generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "test1"}}}
|
||||
@@ -714,7 +713,7 @@ class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
"nova.list_floating_ips_bulk")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".network_wrapper.generate_cidr")
|
||||
def test__create_floating_ips_bulk(self, mock_gencidr):
|
||||
def test__create_floating_ips_bulk(self, mock_generate_cidr):
|
||||
fake_cidr = "10.2.0.0/24"
|
||||
fake_pool = "test1"
|
||||
fake_floating_ips_bulk = mock.MagicMock()
|
||||
@@ -724,7 +723,7 @@ class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
fake_floating_ips_bulk)
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_iprange = nova_scenario._create_floating_ips_bulk(fake_cidr)
|
||||
mock_gencidr.assert_called_once_with(start_cidr=fake_cidr)
|
||||
mock_generate_cidr.assert_called_once_with(start_cidr=fake_cidr)
|
||||
self.assertEqual(return_iprange, fake_floating_ips_bulk)
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.create_floating_ips_bulk")
|
||||
|
@@ -28,8 +28,8 @@ class SaharaClustersTestCase(test.ClientsTestCase):
|
||||
@mock.patch(SAHARA_CLUSTERS + "._delete_cluster")
|
||||
@mock.patch(SAHARA_CLUSTERS + "._launch_cluster",
|
||||
return_value=mock.MagicMock(id=42))
|
||||
def test_create_and_delete_cluster(self, mock_launch_cluster,
|
||||
mock_delete_cluster):
|
||||
def test_create_and_delete_cluster(
|
||||
self, mock__launch_cluster, mock__delete_cluster):
|
||||
clusters_scenario = clusters.SaharaClusters()
|
||||
|
||||
clusters_scenario.context = {
|
||||
@@ -43,7 +43,7 @@ class SaharaClustersTestCase(test.ClientsTestCase):
|
||||
plugin_name="test_plugin",
|
||||
hadoop_version="test_version")
|
||||
|
||||
mock_launch_cluster.assert_called_once_with(
|
||||
mock__launch_cluster.assert_called_once_with(
|
||||
flavor_id="test_flavor",
|
||||
image_id="test_image",
|
||||
workers_count=5,
|
||||
@@ -58,16 +58,16 @@ class SaharaClustersTestCase(test.ClientsTestCase):
|
||||
cluster_configs=None,
|
||||
enable_anti_affinity=False)
|
||||
|
||||
mock_delete_cluster.assert_called_once_with(
|
||||
mock_launch_cluster.return_value)
|
||||
mock__delete_cluster.assert_called_once_with(
|
||||
mock__launch_cluster.return_value)
|
||||
|
||||
@mock.patch(SAHARA_CLUSTERS + "._delete_cluster")
|
||||
@mock.patch(SAHARA_CLUSTERS + "._scale_cluster")
|
||||
@mock.patch(SAHARA_CLUSTERS + "._launch_cluster",
|
||||
return_value=mock.MagicMock(id=42))
|
||||
def test_create_scale_delete_cluster(self, mock_launch_cluster,
|
||||
mock_scale_cluster,
|
||||
mock_delete_cluster):
|
||||
def test_create_scale_delete_cluster(
|
||||
self, mock__launch_cluster, mock__scale_cluster,
|
||||
mock__delete_cluster):
|
||||
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
id=42, status="active"
|
||||
)
|
||||
@@ -86,7 +86,7 @@ class SaharaClustersTestCase(test.ClientsTestCase):
|
||||
plugin_name="test_plugin",
|
||||
hadoop_version="test_version")
|
||||
|
||||
mock_launch_cluster.assert_called_once_with(
|
||||
mock__launch_cluster.assert_called_once_with(
|
||||
flavor_id="test_flavor",
|
||||
image_id="test_image",
|
||||
workers_count=5,
|
||||
@@ -101,10 +101,10 @@ class SaharaClustersTestCase(test.ClientsTestCase):
|
||||
cluster_configs=None,
|
||||
enable_anti_affinity=False)
|
||||
|
||||
mock_scale_cluster.assert_has_calls([
|
||||
mock__scale_cluster.assert_has_calls([
|
||||
mock.call(self.clients("sahara").clusters.get.return_value, 1),
|
||||
mock.call(self.clients("sahara").clusters.get.return_value, -1),
|
||||
])
|
||||
|
||||
mock_delete_cluster.assert_called_once_with(
|
||||
mock__delete_cluster.assert_called_once_with(
|
||||
self.clients("sahara").clusters.get.return_value)
|
||||
|
@@ -33,11 +33,12 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
CONF.set_override("cluster_check_interval", 0, "benchmark")
|
||||
CONF.set_override("job_check_interval", 0, "benchmark")
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
@mock.patch("rally.common.utils.generate_random_name",
|
||||
return_value="job_42")
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
def test_create_launch_job_java(self, mock_run_execution,
|
||||
mock_random_name):
|
||||
def test_create_launch_job_java(self, mock__run_job_execution,
|
||||
mock_generate_random_name):
|
||||
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
|
||||
@@ -58,14 +59,14 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
job_idx=0
|
||||
)
|
||||
self.clients("sahara").jobs.create.assert_called_once_with(
|
||||
name=mock_random_name.return_value,
|
||||
name=mock_generate_random_name.return_value,
|
||||
type="java",
|
||||
description="",
|
||||
mains=["main_42"],
|
||||
libs=["lib_42"]
|
||||
)
|
||||
|
||||
mock_run_execution.assert_called_once_with(
|
||||
mock__run_job_execution.assert_called_once_with(
|
||||
job_id="42",
|
||||
cluster_id="cl_42",
|
||||
input_id=None,
|
||||
@@ -74,13 +75,15 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
job_idx=0
|
||||
)
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
@mock.patch("rally.common.utils.generate_random_name",
|
||||
return_value="job_42")
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
@mock.patch(SAHARA_JOB + "._create_output_ds",
|
||||
return_value=mock.MagicMock(id="out_42"))
|
||||
def test_create_launch_job_pig(self, mock_create_ds,
|
||||
mock_run_execution, mock_random_name):
|
||||
def test_create_launch_job_pig(self, mock__create_output_ds,
|
||||
mock__run_job_execution,
|
||||
mock_generate_random_name):
|
||||
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
|
||||
@@ -101,14 +104,14 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
job_idx=0
|
||||
)
|
||||
self.clients("sahara").jobs.create.assert_called_once_with(
|
||||
name=mock_random_name.return_value,
|
||||
name=mock_generate_random_name.return_value,
|
||||
type="pig",
|
||||
description="",
|
||||
mains=["main_42"],
|
||||
libs=["lib_42"]
|
||||
)
|
||||
|
||||
mock_run_execution.assert_called_once_with(
|
||||
mock__run_job_execution.assert_called_once_with(
|
||||
job_id="42",
|
||||
cluster_id="cl_42",
|
||||
input_id="in_42",
|
||||
@@ -117,11 +120,12 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
job_idx=0
|
||||
)
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
@mock.patch("rally.common.utils.generate_random_name",
|
||||
return_value="job_42")
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
def test_create_launch_job_sequence(self, mock_run_execution,
|
||||
mock_random_name):
|
||||
def test_create_launch_job_sequence(self, mock__run_job_execution,
|
||||
mock_generate_random_name):
|
||||
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
|
||||
@@ -147,7 +151,7 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
}])
|
||||
|
||||
jobs_create_call = mock.call(
|
||||
name=mock_random_name.return_value,
|
||||
name=mock_generate_random_name.return_value,
|
||||
type="java",
|
||||
description="",
|
||||
mains=["main_42"],
|
||||
@@ -156,7 +160,7 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
self.clients("sahara").jobs.create.assert_has_calls([jobs_create_call,
|
||||
jobs_create_call])
|
||||
|
||||
mock_run_execution.assert_has_calls([
|
||||
mock__run_job_execution.assert_has_calls([
|
||||
mock.call(
|
||||
job_id="42",
|
||||
cluster_id="cl_42",
|
||||
@@ -173,18 +177,18 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
job_idx=1)]
|
||||
)
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
@mock.patch("rally.common.utils.generate_random_name",
|
||||
return_value="job_42")
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
@mock.patch(SAHARA_JOB + "._scale_cluster")
|
||||
def test_create_launch_job_sequence_with_scaling(self, mock_scale,
|
||||
mock_run_execution,
|
||||
mock_random_name):
|
||||
def test_create_launch_job_sequence_with_scaling(
|
||||
self, mock__scale_cluster, mock__run_job_execution,
|
||||
mock_generate_random_name):
|
||||
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
id="cl_42",
|
||||
status="active")
|
||||
id="cl_42", status="active")
|
||||
|
||||
jobs_scenario = jobs.SaharaJob()
|
||||
|
||||
@@ -209,7 +213,7 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
deltas=[1, -1])
|
||||
|
||||
jobs_create_call = mock.call(
|
||||
name=mock_random_name.return_value,
|
||||
name=mock_generate_random_name.return_value,
|
||||
type="java",
|
||||
description="",
|
||||
mains=["main_42"],
|
||||
@@ -224,5 +228,5 @@ class SaharaJobTestCase(test.ClientsTestCase):
|
||||
je_1 = mock.call(job_id="42", cluster_id="cl_42", input_id=None,
|
||||
output_id=None,
|
||||
configs={"conf_key2": "conf_val2"}, job_idx=1)
|
||||
mock_run_execution.assert_has_calls([je_0, je_1, je_0, je_1, je_0,
|
||||
je_1])
|
||||
mock__run_job_execution.assert_has_calls(
|
||||
[je_0, je_1, je_0, je_1, je_0, je_1])
|
||||
|
@@ -30,33 +30,37 @@ class SaharaNodeGroupTemplatesTestCase(test.TestCase):
|
||||
return_value=object())
|
||||
@mock.patch(SAHARA_NGTS + "._create_worker_node_group_template",
|
||||
return_value=object)
|
||||
def test_create_and_list_node_group_templates(self, mock_create_worker,
|
||||
mock_create_master,
|
||||
mock_list):
|
||||
def test_create_and_list_node_group_templates(
|
||||
self,
|
||||
mock__create_worker_node_group_template,
|
||||
mock__create_master_node_group_template,
|
||||
mock__list_node_group_templates):
|
||||
|
||||
ngts_scenario = ngts.SaharaNodeGroupTemplates()
|
||||
ngts_scenario.create_and_list_node_group_templates("test_flavor",
|
||||
"test_plugin",
|
||||
"test_version")
|
||||
|
||||
mock_create_master.assert_called_once_with(
|
||||
mock__create_master_node_group_template.assert_called_once_with(
|
||||
flavor_id="test_flavor",
|
||||
plugin_name="test_plugin",
|
||||
hadoop_version="test_version")
|
||||
mock_create_worker.assert_called_once_with(
|
||||
mock__create_worker_node_group_template.assert_called_once_with(
|
||||
flavor_id="test_flavor",
|
||||
plugin_name="test_plugin",
|
||||
hadoop_version="test_version")
|
||||
mock_list.assert_called_once_with()
|
||||
mock__list_node_group_templates.assert_called_once_with()
|
||||
|
||||
@mock.patch(SAHARA_NGTS + "._delete_node_group_template")
|
||||
@mock.patch(SAHARA_NGTS + "._create_master_node_group_template",
|
||||
return_value=mock.MagicMock(id=1))
|
||||
@mock.patch(SAHARA_NGTS + "._create_worker_node_group_template",
|
||||
return_value=mock.MagicMock(id=2))
|
||||
def test_create_delete_node_group_templates(self, mock_create_worker,
|
||||
mock_create_master,
|
||||
mock_delete):
|
||||
def test_create_delete_node_group_templates(
|
||||
self,
|
||||
mock__create_worker_node_group_template,
|
||||
mock__create_master_node_group_template,
|
||||
mock__delete_node_group_template):
|
||||
|
||||
ngts_scenario = ngts.SaharaNodeGroupTemplates()
|
||||
ngts_scenario.create_delete_node_group_templates(
|
||||
@@ -64,15 +68,15 @@ class SaharaNodeGroupTemplatesTestCase(test.TestCase):
|
||||
"test_plugin",
|
||||
"test_version")
|
||||
|
||||
mock_create_master.assert_called_once_with(
|
||||
mock__create_master_node_group_template.assert_called_once_with(
|
||||
flavor_id="test_flavor",
|
||||
plugin_name="test_plugin",
|
||||
hadoop_version="test_version")
|
||||
mock_create_worker.assert_called_once_with(
|
||||
mock__create_worker_node_group_template.assert_called_once_with(
|
||||
flavor_id="test_flavor",
|
||||
plugin_name="test_plugin",
|
||||
hadoop_version="test_version")
|
||||
|
||||
mock_delete.assert_has_calls(calls=[
|
||||
mock.call(mock_create_master.return_value),
|
||||
mock.call(mock_create_worker.return_value)])
|
||||
mock__delete_node_group_template.assert_has_calls(calls=[
|
||||
mock.call(mock__create_master_node_group_template.return_value),
|
||||
mock.call(mock__create_worker_node_group_template.return_value)])
|
||||
|
@@ -28,10 +28,10 @@ CONF = cfg.CONF
|
||||
SAHARA_UTILS = "rally.plugins.openstack.scenarios.sahara.utils"
|
||||
|
||||
|
||||
class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
class SaharaScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SaharaUtilsTestCase, self).setUp()
|
||||
super(SaharaScenarioTestCase, self).setUp()
|
||||
|
||||
CONF.set_override("cluster_check_interval", 0, "benchmark")
|
||||
CONF.set_override("job_check_interval", 0, "benchmark")
|
||||
@@ -50,8 +50,10 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="random_name")
|
||||
@mock.patch(SAHARA_UTILS + ".sahara_consts")
|
||||
def test_create_node_group_templates(self, mock_constants,
|
||||
mock_random_name):
|
||||
def test_create_node_group_templates(
|
||||
self, mock_sahara_consts,
|
||||
mock__generate_random_name):
|
||||
|
||||
scenario = utils.SaharaScenario()
|
||||
mock_processes = {
|
||||
"test_plugin": {
|
||||
@@ -62,7 +64,7 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
}
|
||||
}
|
||||
|
||||
mock_constants.NODE_PROCESSES = mock_processes
|
||||
mock_sahara_consts.NODE_PROCESSES = mock_processes
|
||||
|
||||
scenario._create_master_node_group_template(
|
||||
flavor_id="test_flavor",
|
||||
@@ -114,7 +116,8 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="random_name")
|
||||
@mock.patch(SAHARA_UTILS + ".sahara_consts")
|
||||
def test_launch_cluster(self, mock_constants, mock_random_name):
|
||||
def test_launch_cluster(self, mock_sahara_consts,
|
||||
mock__generate_random_name):
|
||||
|
||||
context = {
|
||||
"tenant": {
|
||||
@@ -177,8 +180,8 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
}
|
||||
]
|
||||
|
||||
mock_constants.NODE_PROCESSES = mock_processes
|
||||
mock_constants.REPLICATION_CONFIGS = mock_configs
|
||||
mock_sahara_consts.NODE_PROCESSES = mock_processes
|
||||
mock_sahara_consts.REPLICATION_CONFIGS = mock_configs
|
||||
|
||||
self.clients("sahara").clusters.create.return_value = mock.MagicMock(
|
||||
id="test_cluster_id")
|
||||
@@ -217,7 +220,9 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="random_name")
|
||||
@mock.patch(SAHARA_UTILS + ".sahara_consts")
|
||||
def test_launch_cluster_error(self, mock_constants, mock_random_name):
|
||||
def test_launch_cluster_error(self, mock_sahara_consts,
|
||||
mock__generate_random_name):
|
||||
|
||||
scenario = utils.SaharaScenario(clients=mock.MagicMock())
|
||||
mock_processes = {
|
||||
"test_plugin": {
|
||||
@@ -237,8 +242,8 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
}
|
||||
}
|
||||
|
||||
mock_constants.NODE_PROCESSES = mock_processes
|
||||
mock_constants.REPLICATION_CONFIGS = mock_configs
|
||||
mock_sahara_consts.NODE_PROCESSES = mock_processes
|
||||
mock_sahara_consts.REPLICATION_CONFIGS = mock_configs
|
||||
|
||||
self.clients("sahara").clusters.create.return_value = mock.MagicMock(
|
||||
id="test_cluster_id")
|
||||
@@ -303,7 +308,7 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="42")
|
||||
def test_create_output_ds(self, mock_random_name):
|
||||
def test_create_output_ds(self, mock__generate_random_name):
|
||||
ctxt = {
|
||||
"sahara_output_conf": {
|
||||
"output_type": "hdfs",
|
||||
@@ -323,7 +328,7 @@ class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="42")
|
||||
def test_create_output_ds_swift(self, mock_random_name):
|
||||
def test_create_output_ds_swift(self, mock__generate_random_name):
|
||||
ctxt = {
|
||||
"sahara_output_conf": {
|
||||
"output_type": "swift",
|
||||
|
@@ -50,130 +50,130 @@ class TempestScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_single_test(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_single_test(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
fake_test = "tempest.api.fake.test"
|
||||
|
||||
self.scenario.single_test(test_name=fake_test)
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd([fake_test])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_single_test_negative(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_single_test_negative(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
fake_test = "tempest.api.network"
|
||||
|
||||
self.scenario.single_test(test_name=fake_test)
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd([fake_test])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_single_test_without_prefix(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_single_test_without_prefix(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
|
||||
self.scenario.single_test("network")
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd(["tempest.api.network"])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_all(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_all(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
|
||||
self.scenario.all()
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd([])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_set_smoke(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_set_smoke(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
|
||||
self.scenario.set("smoke")
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd(["smoke"])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_set_full(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_set_full(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
|
||||
self.scenario.set("full")
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd([])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
def test_set_from_list(self, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_set_from_list(self, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
|
||||
fake_scenarios = ["network", "volume", "baremetal",
|
||||
"image", "identity", "compute", "database",
|
||||
"data_processing", "object_storage",
|
||||
"telemetry", "queuing", "orchestration"]
|
||||
for fake_scenario in fake_scenarios:
|
||||
with mock.patch(VERIFIER + ".subprocess") as mock_sp:
|
||||
with mock.patch(VERIFIER + ".subprocess") as mock_subprocess:
|
||||
self.scenario.set(fake_scenario)
|
||||
fake_test = "tempest.api." + fake_scenario
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd([fake_test])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_set_selective(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_set_selective(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
|
||||
self.scenario.set("network")
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd(["tempest.api.network"])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_list_of_tests(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_list_of_tests(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
fake_tests = ["tempest.fake.test1", "tempest.fake.test2"]
|
||||
|
||||
self.scenario.list_of_tests(fake_tests)
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd(fake_tests)
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
@mock.patch(VERIFIER + ".subprocess")
|
||||
def test_specific_regex(self, mock_sp, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "/dev/null"
|
||||
def test_specific_regex(self, mock_subprocess, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "/dev/null"
|
||||
regex = "tempest.fake.test1"
|
||||
|
||||
self.scenario.specific_regex(regex)
|
||||
|
||||
expected_call = self.get_tests_launcher_cmd([regex])
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
expected_call, cwd=self.verifier.path(),
|
||||
env=self.verifier.env, shell=True)
|
||||
|
@@ -35,8 +35,8 @@ class TempestLogWrappersTestCase(test.TestCase):
|
||||
self.scenario._add_atomic_actions = mock.MagicMock()
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
def test_launch_without_specified_log_file(self, mock_tmp):
|
||||
mock_tmp.NamedTemporaryFile().name = "tmp_file"
|
||||
def test_launch_without_specified_log_file(self, mock_tempfile):
|
||||
mock_tempfile.NamedTemporaryFile().name = "tmp_file"
|
||||
target_func = mock.MagicMock()
|
||||
target_func.__name__ = "target_func"
|
||||
func = utils.tempest_log_wrapper(target_func)
|
||||
@@ -47,7 +47,7 @@ class TempestLogWrappersTestCase(test.TestCase):
|
||||
log_file="/tmp/dir/tmp_file")
|
||||
|
||||
@mock.patch(TS + ".utils.tempfile")
|
||||
def test_launch_with_specified_log_file(self, mock_tmp):
|
||||
def test_launch_with_specified_log_file(self, mock_tempfile):
|
||||
target_func = mock.MagicMock()
|
||||
target_func.__name__ = "target_func"
|
||||
func = utils.tempest_log_wrapper(target_func)
|
||||
@@ -56,4 +56,4 @@ class TempestLogWrappersTestCase(test.TestCase):
|
||||
|
||||
target_func.assert_called_once_with(self.scenario,
|
||||
log_file="log_file")
|
||||
self.assertEqual(0, mock_tmp.NamedTemporaryFile.call_count)
|
||||
self.assertEqual(0, mock_tempfile.NamedTemporaryFile.call_count)
|
||||
|
@@ -52,7 +52,7 @@ class VMScenarioTestCase(test.TestCase):
|
||||
mock_open.assert_called_once_with("foobar", "rb")
|
||||
|
||||
@mock.patch("%s.six.moves.StringIO" % VMTASKS_UTILS)
|
||||
def test__run_command_over_ssh_script_inline(self, mock_stringio):
|
||||
def test__run_command_over_ssh_script_inline(self, mock_string_io):
|
||||
mock_ssh = mock.MagicMock()
|
||||
vm_scenario = utils.VMScenario()
|
||||
vm_scenario._run_command_over_ssh(
|
||||
@@ -64,8 +64,8 @@ class VMScenarioTestCase(test.TestCase):
|
||||
)
|
||||
mock_ssh.execute.assert_called_once_with(
|
||||
["interpreter", "interpreter_arg"],
|
||||
stdin=mock_stringio.return_value)
|
||||
mock_stringio.assert_called_once_with("foobar")
|
||||
stdin=mock_string_io.return_value)
|
||||
mock_string_io.assert_called_once_with("foobar")
|
||||
|
||||
def test__run_command_over_ssh_remote_path(self):
|
||||
mock_ssh = mock.MagicMock()
|
||||
@@ -95,102 +95,93 @@ class VMScenarioTestCase(test.TestCase):
|
||||
@mock.patch(VMTASKS_UTILS + ".bench_utils.resource_is")
|
||||
@mock.patch(VMTASKS_UTILS + ".VMScenario._ping_ip_address",
|
||||
return_value=True)
|
||||
def test__wait_for_ping(self, mock__ping, mock_resource_is):
|
||||
def test__wait_for_ping(self, mock_vm_scenario__ping_ip_address,
|
||||
mock_resource_is):
|
||||
vm_scenario = utils.VMScenario()
|
||||
vm_scenario._wait_for_ping(netaddr.IPAddress("1.2.3.4"))
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
netaddr.IPAddress("1.2.3.4"),
|
||||
is_ready=mock_resource_is.return_value,
|
||||
timeout=120)
|
||||
mock_resource_is.assert_called_once_with("ICMP UP", mock__ping)
|
||||
mock_resource_is.assert_called_once_with(
|
||||
"ICMP UP", mock_vm_scenario__ping_ip_address)
|
||||
|
||||
@mock.patch(VMTASKS_UTILS + ".VMScenario._run_command_over_ssh")
|
||||
@mock.patch("rally.common.sshutils.SSH")
|
||||
def test__run_command(self, mock_ssh_class, mock_run_command_over_ssh):
|
||||
mock_ssh_instance = mock.MagicMock()
|
||||
mock_ssh_class.return_value = mock_ssh_instance
|
||||
|
||||
def test__run_command(self, mock_sshutils_ssh,
|
||||
mock_vm_scenario__run_command_over_ssh):
|
||||
vm_scenario = utils.VMScenario()
|
||||
vm_scenario.context = {"user": {"keypair": {"private": "ssh"}}}
|
||||
vm_scenario._run_command("1.2.3.4", 22, "username", "password",
|
||||
command={"script_file": "foo",
|
||||
"interpreter": "bar"})
|
||||
|
||||
mock_ssh_class.assert_called_once_with("username", "1.2.3.4", port=22,
|
||||
pkey="ssh",
|
||||
password="password")
|
||||
mock_ssh_instance.wait.assert_called_once_with()
|
||||
mock_run_command_over_ssh.assert_called_once_with(
|
||||
mock_ssh_instance,
|
||||
mock_sshutils_ssh.assert_called_once_with(
|
||||
"username", "1.2.3.4", port=22, pkey="ssh", password="password")
|
||||
mock_sshutils_ssh.return_value.wait.assert_called_once_with()
|
||||
mock_vm_scenario__run_command_over_ssh.assert_called_once_with(
|
||||
mock_sshutils_ssh.return_value,
|
||||
{"script_file": "foo", "interpreter": "bar"})
|
||||
|
||||
@mock.patch(VMTASKS_UTILS + ".sys")
|
||||
@mock.patch("subprocess.Popen")
|
||||
def test__ping_ip_address_linux(self, mock_subprocess, mock_sys):
|
||||
ping_process = mock.MagicMock()
|
||||
ping_process.returncode = 0
|
||||
mock_subprocess.return_value = ping_process
|
||||
def test__ping_ip_address_linux(self, mock_popen, mock_sys):
|
||||
mock_popen.return_value.returncode = 0
|
||||
mock_sys.platform = "linux2"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = netaddr.IPAddress("1.2.3.4")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
mock_popen.assert_called_once_with(
|
||||
["ping", "-c1", "-w1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
mock_popen.return_value.wait.assert_called_once_with()
|
||||
|
||||
@mock.patch(VMTASKS_UTILS + ".sys")
|
||||
@mock.patch("subprocess.Popen")
|
||||
def test__ping_ip_address_linux_ipv6(self, mock_subprocess, mock_sys):
|
||||
ping_process = mock.MagicMock()
|
||||
ping_process.returncode = 0
|
||||
mock_subprocess.return_value = ping_process
|
||||
def test__ping_ip_address_linux_ipv6(self, mock_popen, mock_sys):
|
||||
mock_popen.return_value.returncode = 0
|
||||
mock_sys.platform = "linux2"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = netaddr.IPAddress("1ce:c01d:bee2:15:a5:900d:a5:11fe")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
mock_popen.assert_called_once_with(
|
||||
["ping6", "-c1", "-w1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
mock_popen.return_value.wait.assert_called_once_with()
|
||||
|
||||
@mock.patch(VMTASKS_UTILS + ".sys")
|
||||
@mock.patch("subprocess.Popen")
|
||||
def test__ping_ip_address_other_os(self, mock_subprocess, mock_sys):
|
||||
ping_process = mock.MagicMock()
|
||||
ping_process.returncode = 0
|
||||
mock_subprocess.return_value = ping_process
|
||||
def test__ping_ip_address_other_os(self, mock_popen, mock_sys):
|
||||
mock_popen.return_value.returncode = 0
|
||||
mock_sys.platform = "freebsd10"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = netaddr.IPAddress("1.2.3.4")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
mock_popen.assert_called_once_with(
|
||||
["ping", "-c1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
mock_popen.return_value.wait.assert_called_once_with()
|
||||
|
||||
@mock.patch(VMTASKS_UTILS + ".sys")
|
||||
@mock.patch("subprocess.Popen")
|
||||
def test__ping_ip_address_other_os_ipv6(self, mock_subprocess, mock_sys):
|
||||
ping_process = mock.MagicMock()
|
||||
ping_process.returncode = 0
|
||||
mock_subprocess.return_value = ping_process
|
||||
def test__ping_ip_address_other_os_ipv6(self, mock_popen, mock_sys):
|
||||
mock_popen.return_value.returncode = 0
|
||||
mock_sys.platform = "freebsd10"
|
||||
|
||||
vm_scenario = utils.VMScenario()
|
||||
host_ip = netaddr.IPAddress("1ce:c01d:bee2:15:a5:900d:a5:11fe")
|
||||
self.assertTrue(vm_scenario._ping_ip_address(host_ip))
|
||||
|
||||
mock_subprocess.assert_called_once_with(
|
||||
mock_popen.assert_called_once_with(
|
||||
["ping6", "-c1", str(host_ip)],
|
||||
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
ping_process.wait.assert_called_once_with()
|
||||
mock_popen.return_value.wait.assert_called_once_with()
|
||||
|
||||
def get_scenario(self):
|
||||
server = mock.Mock(
|
||||
|
@@ -24,14 +24,14 @@ BASIC = BASE + "basic.ZaqarBasic."
|
||||
class ZaqarBasicTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name", return_value="fizbit")
|
||||
def test_create_queue(self, mock_gen_name):
|
||||
def test_create_queue(self, mock__generate_random_name):
|
||||
scenario = basic.ZaqarBasic()
|
||||
scenario._queue_create = mock.MagicMock()
|
||||
scenario.create_queue(name_length=10)
|
||||
scenario._queue_create.assert_called_once_with(name_length=10)
|
||||
|
||||
@mock.patch(BASIC + "_generate_random_name", return_value="kitkat")
|
||||
def test_producer_consumer(self, mock_gen_name):
|
||||
def test_producer_consumer(self, mock__generate_random_name):
|
||||
scenario = basic.ZaqarBasic()
|
||||
messages = [{"body": {"id": idx}, "ttl": 360} for idx
|
||||
in range(20)]
|
||||
|
@@ -25,7 +25,7 @@ class ZaqarScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(UTILS + "ZaqarScenario._generate_random_name",
|
||||
return_value="kitkat")
|
||||
def test_queue_create(self, mock_gen_name):
|
||||
def test_queue_create(self, mock__generate_random_name):
|
||||
scenario = utils.ZaqarScenario()
|
||||
result = scenario._queue_create(name_length=10)
|
||||
|
||||
|
@@ -45,21 +45,24 @@ class NovaNetworkWrapperTestCase(test.TestCase):
|
||||
service.client.networks.list.assert_called_once_with()
|
||||
|
||||
@mock.patch("rally.plugins.openstack.wrappers.network.generate_cidr")
|
||||
def test__generate_cidr(self, mock_cidr):
|
||||
def test__generate_cidr(self, mock_generate_cidr):
|
||||
skip_cidrs = [5, 7]
|
||||
cidrs = iter(range(7))
|
||||
mock_cidr.side_effect = lambda start_cidr: start_cidr + next(cidrs)
|
||||
mock_generate_cidr.side_effect = (
|
||||
lambda start_cidr: start_cidr + next(cidrs)
|
||||
)
|
||||
service = self.get_wrapper(*skip_cidrs, start_cidr=3)
|
||||
self.assertEqual(service._generate_cidr(), 3)
|
||||
self.assertEqual(service._generate_cidr(), 4)
|
||||
self.assertEqual(service._generate_cidr(), 6) # 5 is skipped
|
||||
self.assertEqual(service._generate_cidr(), 8) # 7 is skipped
|
||||
self.assertEqual(service._generate_cidr(), 9)
|
||||
self.assertEqual(mock_cidr.mock_calls, [mock.call(start_cidr=3)] * 7)
|
||||
self.assertEqual(mock_generate_cidr.mock_calls,
|
||||
[mock.call(start_cidr=3)] * 7)
|
||||
|
||||
@mock.patch("rally.common.utils.generate_random_name",
|
||||
return_value="foo_name")
|
||||
def test_create_network(self, mock_name):
|
||||
def test_create_network(self, mock_generate_random_name):
|
||||
service = self.get_wrapper()
|
||||
service.client.networks.create.side_effect = (
|
||||
lambda **kwargs: self.Net(id="foo_id", **kwargs))
|
||||
@@ -71,7 +74,7 @@ class NovaNetworkWrapperTestCase(test.TestCase):
|
||||
"status": "ACTIVE",
|
||||
"external": False,
|
||||
"tenant_id": "foo_tenant"})
|
||||
mock_name.assert_called_once_with("rally_net_")
|
||||
mock_generate_random_name.assert_called_once_with("rally_net_")
|
||||
service._generate_cidr.assert_called_once_with()
|
||||
service.client.networks.create.assert_called_once_with(
|
||||
tenant_id="foo_tenant", cidr="foo_cidr", label="foo_name")
|
||||
@@ -152,16 +155,19 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
self.assertEqual(network.NeutronWrapper.SUBNET_IP_VERSION, 4)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.wrappers.network.generate_cidr")
|
||||
def test__generate_cidr(self, mock_cidr):
|
||||
def test__generate_cidr(self, mock_generate_cidr):
|
||||
cidrs = iter(range(5))
|
||||
mock_cidr.side_effect = lambda start_cidr: start_cidr + next(cidrs)
|
||||
mock_generate_cidr.side_effect = (
|
||||
lambda start_cidr: start_cidr + next(cidrs)
|
||||
)
|
||||
service = self.get_wrapper(start_cidr=3)
|
||||
self.assertEqual(service._generate_cidr(), 3)
|
||||
self.assertEqual(service._generate_cidr(), 4)
|
||||
self.assertEqual(service._generate_cidr(), 5)
|
||||
self.assertEqual(service._generate_cidr(), 6)
|
||||
self.assertEqual(service._generate_cidr(), 7)
|
||||
self.assertEqual(mock_cidr.mock_calls, [mock.call(start_cidr=3)] * 5)
|
||||
self.assertEqual(mock_generate_cidr.mock_calls,
|
||||
[mock.call(start_cidr=3)] * 5)
|
||||
|
||||
def test_external_networks(self):
|
||||
wrap = self.get_wrapper()
|
||||
@@ -205,15 +211,15 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
name="foo_name")
|
||||
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_network(self, mock_name):
|
||||
mock_name.return_value = "foo_name"
|
||||
def test_create_network(self, mock_generate_random_name):
|
||||
mock_generate_random_name.return_value = "foo_name"
|
||||
service = self.get_wrapper()
|
||||
service.client.create_network.return_value = {
|
||||
"network": {"id": "foo_id",
|
||||
"name": "foo_name",
|
||||
"status": "foo_status"}}
|
||||
net = service.create_network("foo_tenant")
|
||||
mock_name.assert_called_once_with("rally_net_")
|
||||
mock_generate_random_name.assert_called_once_with("rally_net_")
|
||||
service.client.create_network.assert_called_once_with({
|
||||
"network": {"tenant_id": "foo_tenant", "name": "foo_name"}})
|
||||
self.assertEqual(net, {"id": "foo_id",
|
||||
@@ -225,9 +231,9 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
"subnets": []})
|
||||
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_network_with_subnets(self, mock_name):
|
||||
def test_create_network_with_subnets(self, mock_generate_random_name):
|
||||
subnets_num = 4
|
||||
mock_name.return_value = "foo_name"
|
||||
mock_generate_random_name.return_value = "foo_name"
|
||||
service = self.get_wrapper()
|
||||
subnets_cidrs = iter(range(subnets_num))
|
||||
subnets_ids = iter(range(subnets_num))
|
||||
@@ -263,8 +269,8 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
for i in range(subnets_num)])
|
||||
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_network_with_router(self, mock_name):
|
||||
mock_name.return_value = "foo_name"
|
||||
def test_create_network_with_router(self, mock_generate_random_name):
|
||||
mock_generate_random_name.return_value = "foo_name"
|
||||
service = self.get_wrapper()
|
||||
service.create_router = mock.Mock(return_value={"id": "foo_router"})
|
||||
service.client.create_network.return_value = {
|
||||
@@ -283,9 +289,10 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
tenant_id="foo_tenant")
|
||||
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_network_with_router_and_subnets(self, mock_name):
|
||||
def test_create_network_with_router_and_subnets(self,
|
||||
mock_generate_random_name):
|
||||
subnets_num = 4
|
||||
mock_name.return_value = "foo_name"
|
||||
mock_generate_random_name.return_value = "foo_name"
|
||||
service = self.get_wrapper()
|
||||
service._generate_cidr = mock.Mock(return_value="foo_cidr")
|
||||
service.create_router = mock.Mock(return_value={"id": "foo_router"})
|
||||
@@ -375,7 +382,7 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
service.client.list_networks.assert_called_once_with()
|
||||
|
||||
@mock.patch(SVC + "NeutronWrapper.external_networks")
|
||||
def test_create_floating_ip(self, mock_ext_networks):
|
||||
def test_create_floating_ip(self, mock_neutron_wrapper_external_networks):
|
||||
wrap = self.get_wrapper()
|
||||
wrap.create_port = mock.Mock(return_value={"id": "port_id"})
|
||||
wrap.client.create_floatingip = mock.Mock(
|
||||
@@ -384,11 +391,13 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
|
||||
self.assertRaises(ValueError, wrap.create_floating_ip)
|
||||
|
||||
mock_ext_networks.__get__ = lambda *args: []
|
||||
mock_neutron_wrapper_external_networks.__get__ = lambda *args: []
|
||||
self.assertRaises(network.NetworkWrapperException,
|
||||
wrap.create_floating_ip, tenant_id="foo_tenant")
|
||||
|
||||
mock_ext_networks.__get__ = lambda *args: [{"id": "ext_id"}]
|
||||
mock_neutron_wrapper_external_networks.__get__ = (
|
||||
lambda *args: [{"id": "ext_id"}]
|
||||
)
|
||||
fip = wrap.create_floating_ip(tenant_id="foo_tenant")
|
||||
self.assertEqual(fip, {"id": "fip_id", "ip": "fip_ip"})
|
||||
|
||||
@@ -416,11 +425,14 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SVC + "NeutronWrapper.external_networks")
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_router(self, mock_random, mock_ext_networks):
|
||||
def test_create_router(self, mock_generate_random_name,
|
||||
mock_neutron_wrapper_external_networks):
|
||||
wrap = self.get_wrapper()
|
||||
mock_random.return_value = "random_name"
|
||||
mock_generate_random_name.return_value = "random_name"
|
||||
wrap.client.create_router.return_value = {"router": "foo_router"}
|
||||
mock_ext_networks.__get__ = lambda *args: [{"id": "ext_id"}]
|
||||
mock_neutron_wrapper_external_networks.__get__ = (
|
||||
lambda *args: [{"id": "ext_id"}]
|
||||
)
|
||||
|
||||
router = wrap.create_router(name="foo_name")
|
||||
wrap.client.create_router.assert_called_once_with(
|
||||
@@ -436,9 +448,9 @@ class NeutronWrapperTestCase(test.TestCase):
|
||||
"foo": "bar"}})
|
||||
|
||||
@mock.patch("rally.common.utils.generate_random_name")
|
||||
def test_create_port(self, mock_random):
|
||||
def test_create_port(self, mock_generate_random_name):
|
||||
wrap = self.get_wrapper()
|
||||
mock_random.return_value = "random_name"
|
||||
mock_generate_random_name.return_value = "random_name"
|
||||
wrap.client.create_port.return_value = {"port": "foo_port"}
|
||||
|
||||
port = wrap.create_port("foo_net", name="foo_name")
|
||||
|
@@ -30,7 +30,8 @@ class RallyJobsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.engine.BenchmarkEngine"
|
||||
"._validate_config_semantic")
|
||||
def test_schema_is_valid(self, mock_validate):
|
||||
def test_schema_is_valid(
|
||||
self, mock_benchmark_engine__validate_config_semantic):
|
||||
discover.load_plugins(os.path.join(self.rally_jobs_path, "plugins"))
|
||||
|
||||
for filename in ["rally.yaml", "rally-neutron.yaml",
|
||||
|
@@ -59,10 +59,11 @@ class TaskAPITestCase(test.TestCase):
|
||||
admin=mock.MagicMock(),
|
||||
users=[]))
|
||||
@mock.patch("rally.api.engine.BenchmarkEngine")
|
||||
def test_validate(self, mock_engine, mock_deployment_get, mock_task):
|
||||
def test_validate(
|
||||
self, mock_benchmark_engine, mock_deployment_get, mock_task):
|
||||
api.Task.validate(mock_deployment_get.return_value["uuid"], "config")
|
||||
|
||||
mock_engine.assert_has_calls([
|
||||
mock_benchmark_engine.assert_has_calls([
|
||||
mock.call("config", mock_task.return_value,
|
||||
admin=mock_deployment_get.return_value["admin"],
|
||||
users=[]),
|
||||
@@ -105,11 +106,11 @@ class TaskAPITestCase(test.TestCase):
|
||||
@mock.patch("rally.objects.Deployment.get",
|
||||
return_value={"uuid": "b0d9cd6c-2c94-4417-a238-35c7019d0257"})
|
||||
@mock.patch("rally.objects.Task")
|
||||
def test_create(self, mock_task, mock_d_get):
|
||||
def test_create(self, mock_task, mock_deployment_get):
|
||||
tag = "a"
|
||||
api.Task.create(mock_d_get.return_value["uuid"], tag)
|
||||
api.Task.create(mock_deployment_get.return_value["uuid"], tag)
|
||||
mock_task.assert_called_once_with(
|
||||
deployment_uuid=mock_d_get.return_value["uuid"], tag=tag)
|
||||
deployment_uuid=mock_deployment_get.return_value["uuid"], tag=tag)
|
||||
|
||||
@mock.patch("rally.api.objects.Task")
|
||||
@mock.patch("rally.api.objects.Deployment.get",
|
||||
@@ -117,10 +118,11 @@ class TaskAPITestCase(test.TestCase):
|
||||
admin=mock.MagicMock(),
|
||||
users=[]))
|
||||
@mock.patch("rally.api.engine.BenchmarkEngine")
|
||||
def test_start(self, mock_engine, mock_deployment_get, mock_task):
|
||||
def test_start(self, mock_benchmark_engine, mock_deployment_get,
|
||||
mock_task):
|
||||
api.Task.start(mock_deployment_get.return_value["uuid"], "config")
|
||||
|
||||
mock_engine.assert_has_calls([
|
||||
mock_benchmark_engine.assert_has_calls([
|
||||
mock.call("config", mock_task.return_value,
|
||||
admin=mock_deployment_get.return_value["admin"],
|
||||
users=[], abort_on_sla_failure=False),
|
||||
@@ -136,9 +138,9 @@ class TaskAPITestCase(test.TestCase):
|
||||
@mock.patch("rally.api.objects.Task")
|
||||
@mock.patch("rally.api.objects.Deployment.get")
|
||||
@mock.patch("rally.api.engine.BenchmarkEngine")
|
||||
def test_start_invalid_task_ignored(self, mock_engine,
|
||||
def test_start_invalid_task_ignored(self, mock_benchmark_engine,
|
||||
mock_deployment_get, mock_task):
|
||||
mock_engine().run.side_effect = (
|
||||
mock_benchmark_engine().run.side_effect = (
|
||||
exceptions.InvalidTaskException())
|
||||
|
||||
# check that it doesn't raise anything
|
||||
@@ -147,9 +149,9 @@ class TaskAPITestCase(test.TestCase):
|
||||
@mock.patch("rally.api.objects.Task")
|
||||
@mock.patch("rally.api.objects.Deployment.get")
|
||||
@mock.patch("rally.api.engine.BenchmarkEngine")
|
||||
def test_start_exception(self, mock_engine, mock_deployment_get,
|
||||
def test_start_exception(self, mock_benchmark_engine, mock_deployment_get,
|
||||
mock_task):
|
||||
mock_engine().run.side_effect = TypeError
|
||||
mock_benchmark_engine().run.side_effect = TypeError
|
||||
self.assertRaises(TypeError, api.Task.start, "deployment_uuid",
|
||||
"config")
|
||||
mock_deployment_get().update_status.assert_called_once_with(
|
||||
@@ -159,16 +161,17 @@ class TaskAPITestCase(test.TestCase):
|
||||
self.assertRaises(NotImplementedError, api.Task.abort, self.task_uuid)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_delete")
|
||||
def test_delete(self, mock_delete):
|
||||
def test_delete(self, mock_task_delete):
|
||||
api.Task.delete(self.task_uuid)
|
||||
mock_delete.assert_called_once_with(
|
||||
mock_task_delete.assert_called_once_with(
|
||||
self.task_uuid,
|
||||
status=consts.TaskStatus.FINISHED)
|
||||
|
||||
@mock.patch("rally.objects.task.db.task_delete")
|
||||
def test_delete_force(self, mock_delete):
|
||||
def test_delete_force(self, mock_task_delete):
|
||||
api.Task.delete(self.task_uuid, force=True)
|
||||
mock_delete.assert_called_once_with(self.task_uuid, status=None)
|
||||
mock_task_delete.assert_called_once_with(
|
||||
self.task_uuid, status=None)
|
||||
|
||||
|
||||
class BaseDeploymentTestCase(test.TestCase):
|
||||
@@ -197,16 +200,17 @@ class DeploymentAPITestCase(BaseDeploymentTestCase):
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_create")
|
||||
@mock.patch("rally.deploy.engine.EngineFactory.validate")
|
||||
def test_create(self, mock_validate, mock_create, mock_update):
|
||||
mock_create.return_value = self.deployment
|
||||
mock_update.return_value = self.deployment
|
||||
def test_create(self, mock_engine_factory_validate,
|
||||
mock_deployment_create, mock_deployment_update):
|
||||
mock_deployment_create.return_value = self.deployment
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
api.Deployment.create(self.deployment_config, "fake_deployment")
|
||||
mock_create.assert_called_once_with({
|
||||
mock_deployment_create.assert_called_once_with({
|
||||
"name": "fake_deployment",
|
||||
"config": self.deployment_config,
|
||||
})
|
||||
mock_validate.assert_called_with()
|
||||
mock_update.assert_has_calls([
|
||||
mock_engine_factory_validate.assert_called_with()
|
||||
mock_deployment_update.assert_has_calls([
|
||||
mock.call(self.deployment_uuid, self.endpoints)
|
||||
])
|
||||
|
||||
@@ -214,13 +218,14 @@ class DeploymentAPITestCase(BaseDeploymentTestCase):
|
||||
@mock.patch("rally.objects.deploy.db.deployment_create")
|
||||
@mock.patch("rally.deploy.engine.EngineFactory.validate",
|
||||
side_effect=jsonschema.ValidationError("ValidationError"))
|
||||
def test_create_validation_error(self, mock_validate, mock_create,
|
||||
mock_update):
|
||||
mock_create.return_value = self.deployment
|
||||
def test_create_validation_error(
|
||||
self, mock_engine_factory_validate, mock_deployment_create,
|
||||
mock_deployment_update):
|
||||
mock_deployment_create.return_value = self.deployment
|
||||
self.assertRaises(jsonschema.ValidationError,
|
||||
api.Deployment.create,
|
||||
self.deployment_config, "fake_deployment")
|
||||
mock_update.assert_called_once_with(
|
||||
mock_deployment_update.assert_called_once_with(
|
||||
self.deployment_uuid,
|
||||
{"status": consts.DeployStatus.DEPLOY_FAILED})
|
||||
|
||||
@@ -228,7 +233,7 @@ class DeploymentAPITestCase(BaseDeploymentTestCase):
|
||||
@mock.patch("rally.objects.deploy.db.deployment_create",
|
||||
side_effect=exceptions.DeploymentNameExists(
|
||||
deployment="fake_deploy"))
|
||||
def test_create_duplication_error(self, mock_d_create, mock_log):
|
||||
def test_create_duplication_error(self, mock_deployment_create, mock_log):
|
||||
self.assertRaises(exceptions.DeploymentNameExists,
|
||||
api.Deployment.create, self.deployment_config,
|
||||
"fake_deployment")
|
||||
@@ -236,21 +241,22 @@ class DeploymentAPITestCase(BaseDeploymentTestCase):
|
||||
@mock.patch("rally.objects.deploy.db.deployment_delete")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_get")
|
||||
def test_destroy(self, mock_get, mock_update, mock_delete):
|
||||
mock_get.return_value = self.deployment
|
||||
mock_update.return_value = self.deployment
|
||||
def test_destroy(self, mock_deployment_get,
|
||||
mock_deployment_update, mock_deployment_delete):
|
||||
mock_deployment_get.return_value = self.deployment
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
api.Deployment.destroy(self.deployment_uuid)
|
||||
mock_get.assert_called_once_with(self.deployment_uuid)
|
||||
mock_delete.assert_called_once_with(self.deployment_uuid)
|
||||
mock_deployment_get.assert_called_once_with(self.deployment_uuid)
|
||||
mock_deployment_delete.assert_called_once_with(self.deployment_uuid)
|
||||
|
||||
@mock.patch("rally.objects.deploy.db.deployment_update")
|
||||
@mock.patch("rally.objects.deploy.db.deployment_get")
|
||||
def test_recreate(self, mock_get, mock_update):
|
||||
mock_get.return_value = self.deployment
|
||||
mock_update.return_value = self.deployment
|
||||
def test_recreate(self, mock_deployment_get, mock_deployment_update):
|
||||
mock_deployment_get.return_value = self.deployment
|
||||
mock_deployment_update.return_value = self.deployment
|
||||
api.Deployment.recreate(self.deployment_uuid)
|
||||
mock_get.assert_called_once_with(self.deployment_uuid)
|
||||
mock_update.assert_has_calls([
|
||||
mock_deployment_get.assert_called_once_with(self.deployment_uuid)
|
||||
mock_deployment_update.assert_has_calls([
|
||||
mock.call(self.deployment_uuid, self.endpoints)
|
||||
])
|
||||
|
||||
@@ -263,8 +269,9 @@ class VerificationAPITestCase(BaseDeploymentTestCase):
|
||||
@mock.patch("rally.objects.Deployment.get")
|
||||
@mock.patch("rally.api.objects.Verification")
|
||||
@mock.patch("rally.verification.tempest.tempest.Tempest")
|
||||
def test_verify(self, mock_tempest, mock_verification, mock_d_get):
|
||||
mock_d_get.return_value = {"uuid": self.deployment_uuid}
|
||||
def test_verify(self, mock_tempest, mock_verification,
|
||||
mock_deployment_get):
|
||||
mock_deployment_get.return_value = {"uuid": self.deployment_uuid}
|
||||
|
||||
mock_tempest.return_value = self.tempest
|
||||
self.tempest.is_installed.return_value = True
|
||||
@@ -278,8 +285,9 @@ class VerificationAPITestCase(BaseDeploymentTestCase):
|
||||
@mock.patch("rally.api.objects.Verification")
|
||||
@mock.patch("rally.verification.tempest.tempest.Tempest")
|
||||
def test_verify_tempest_not_installed(self, mock_tempest,
|
||||
mock_verification, mock_d_get):
|
||||
mock_d_get.return_value = {"uuid": self.deployment_uuid}
|
||||
mock_verification,
|
||||
mock_deployment_get):
|
||||
mock_deployment_get.return_value = {"uuid": self.deployment_uuid}
|
||||
mock_tempest.return_value = self.tempest
|
||||
self.tempest.is_installed.return_value = False
|
||||
api.Verification.verify(self.deployment_uuid, "smoke", None, None)
|
||||
@@ -291,14 +299,14 @@ class VerificationAPITestCase(BaseDeploymentTestCase):
|
||||
|
||||
@mock.patch("rally.api.objects.Deployment.get")
|
||||
@mock.patch("rally.api.tempest.Tempest")
|
||||
def test_install_tempest(self, mock_tempest, mock_d_get):
|
||||
def test_install_tempest(self, mock_tempest, mock_deployment_get):
|
||||
mock_tempest.return_value = self.tempest
|
||||
api.Verification.install_tempest(self.deployment_uuid)
|
||||
self.tempest.install.assert_called_once_with()
|
||||
|
||||
@mock.patch("rally.api.objects.Deployment.get")
|
||||
@mock.patch("rally.api.tempest.Tempest")
|
||||
def test_uninstall_tempest(self, mock_tempest, mock_d_get):
|
||||
def test_uninstall_tempest(self, mock_tempest, mock_deployment_get):
|
||||
mock_tempest.return_value = self.tempest
|
||||
api.Verification.uninstall_tempest(self.deployment_uuid)
|
||||
self.tempest.uninstall.assert_called_once_with()
|
||||
@@ -308,8 +316,8 @@ class VerificationAPITestCase(BaseDeploymentTestCase):
|
||||
@mock.patch("shutil.copy2")
|
||||
@mock.patch("rally.api.objects.Deployment.get")
|
||||
@mock.patch("rally.api.tempest.Tempest")
|
||||
def test_reinstall_tempest(self, mock_tempest, mock_d_get,
|
||||
mock_copy, mock_move, mock_tmp):
|
||||
def test_reinstall_tempest(self, mock_tempest, mock_deployment_get,
|
||||
mock_copy2, mock_move, mock_gettempdir):
|
||||
|
||||
fake_source = "fake__source"
|
||||
fake_conf = "/path/to/fake_conf"
|
||||
@@ -317,11 +325,10 @@ class VerificationAPITestCase(BaseDeploymentTestCase):
|
||||
tmp_file = os.path.join(fake_tmpdir, "fake_conf")
|
||||
self.tempest.config_file = fake_conf
|
||||
mock_tempest.return_value = self.tempest
|
||||
mock_tmp.return_value = fake_tmpdir
|
||||
mock_gettempdir.return_value = fake_tmpdir
|
||||
api.Verification.reinstall_tempest(self.deployment_uuid,
|
||||
source=fake_source)
|
||||
self.tempest.uninstall.assert_called_once_with()
|
||||
mock_copy.assert_called_once_with(fake_conf,
|
||||
tmp_file)
|
||||
mock_copy2.assert_called_once_with(fake_conf, tmp_file)
|
||||
self.tempest.install.assert_called_once_with()
|
||||
mock_move.assert_called_once_with(tmp_file, fake_conf)
|
||||
|
@@ -154,7 +154,7 @@ class FuelClusterTestCase(test.TestCase):
|
||||
"key2": "val2"}]})
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.time.sleep")
|
||||
def test_deploy(self, m_sleep):
|
||||
def test_deploy(self, mock_sleep):
|
||||
call1 = {"progress": 50}
|
||||
call2 = {"progress": 100}
|
||||
self.client.get_task.side_effect = [call1, call2]
|
||||
@@ -190,7 +190,7 @@ class FuelClusterTestCase(test.TestCase):
|
||||
self.cluster.verify_network.assert_called_once_with({"key": "val"})
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.time.sleep")
|
||||
def test_verify_network(self, m_sleep):
|
||||
def test_verify_network(self, mock_sleep):
|
||||
call1 = {"progress": 50}
|
||||
call2 = {"progress": 100, "message": ""}
|
||||
|
||||
@@ -207,7 +207,7 @@ class FuelClusterTestCase(test.TestCase):
|
||||
self.client.get_task.mock_calls)
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.time.sleep")
|
||||
def test_verify_network_fail(self, m_sleep):
|
||||
def test_verify_network_fail(self, mock_sleep):
|
||||
self.client.put.return_value = {"id": 42}
|
||||
self.client.get_task.return_value = {"progress": 100,
|
||||
"message": "error"}
|
||||
@@ -245,94 +245,96 @@ class FuelClientTestCase(test.TestCase):
|
||||
self.client = fuelclient.FuelClient("http://10.20.0.2:8000/api/v1/")
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.requests")
|
||||
def test__request_non_json(self, fake_req):
|
||||
def test__request_non_json(self, mock_requests):
|
||||
reply = mock.Mock()
|
||||
reply.status_code = 200
|
||||
reply.headers = {"content-type": "application/x-httpd-php"}
|
||||
reply.text = "{\"reply\": \"ok\"}"
|
||||
fake_req.method = mock.Mock(return_value=reply)
|
||||
mock_requests.method.return_value = reply
|
||||
|
||||
retval = self.client._request("method", "url", data={"key": "value"})
|
||||
|
||||
self.assertEqual(retval, reply)
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.requests")
|
||||
def test__request_non_2xx(self, fake_req):
|
||||
def test__request_non_2xx(self, mock_requests):
|
||||
reply = mock.Mock()
|
||||
reply.status_code = 300
|
||||
reply.headers = {"content-type": "application/json"}
|
||||
reply.text = "{\"reply\": \"ok\"}"
|
||||
fake_req.method = mock.Mock(return_value=reply)
|
||||
mock_requests.method.return_value = reply
|
||||
self.assertRaises(fuelclient.FuelClientException,
|
||||
self.client._request, "method", "url",
|
||||
data={"key": "value"})
|
||||
|
||||
@mock.patch("rally.deploy.fuel.fuelclient.requests")
|
||||
def test__request(self, fake_req):
|
||||
def test__request(self, mock_requests):
|
||||
reply = mock.Mock()
|
||||
reply.status_code = 202
|
||||
reply.headers = {"content-type": "application/json"}
|
||||
reply.text = "{\"reply\": \"ok\"}"
|
||||
fake_req.method = mock.Mock(return_value=reply)
|
||||
mock_requests.method.return_value = reply
|
||||
|
||||
retval = self.client._request("method", "url", data={"key": "value"})
|
||||
fake_req.method.assert_called_once_with(
|
||||
mock_requests.method.assert_called_once_with(
|
||||
"http://10.20.0.2:8000/api/v1/url",
|
||||
headers={"content-type": "application/json"},
|
||||
data="{\"key\": \"value\"}")
|
||||
self.assertEqual(retval, {"reply": "ok"})
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "_request")
|
||||
def test_get(self, m_request):
|
||||
def test_get(self, mock_fuel_client__request):
|
||||
self.client.get("url")
|
||||
m_request.assert_called_once_with("get", "url")
|
||||
mock_fuel_client__request.assert_called_once_with("get", "url")
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "_request")
|
||||
def test_delete(self, m_request):
|
||||
def test_delete(self, mock_fuel_client__request):
|
||||
self.client.delete("url")
|
||||
m_request.assert_called_once_with("delete", "url")
|
||||
mock_fuel_client__request.assert_called_once_with("delete", "url")
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "_request")
|
||||
def test_post(self, m_request):
|
||||
def test_post(self, mock_fuel_client__request):
|
||||
self.client.post("url", {"key": "val"})
|
||||
m_request.assert_called_once_with("post", "url", {"key": "val"})
|
||||
mock_fuel_client__request.assert_called_once_with(
|
||||
"post", "url", {"key": "val"})
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "_request")
|
||||
def test_put(self, m_request):
|
||||
def test_put(self, mock_fuel_client__request):
|
||||
self.client.put("url", {"key": "val"})
|
||||
m_request.assert_called_once_with("put", "url", {"key": "val"})
|
||||
mock_fuel_client__request.assert_called_once_with(
|
||||
"put", "url", {"key": "val"})
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "get")
|
||||
def test_get_releases(self, m_get):
|
||||
def test_get_releases(self, mock_fuel_client_get):
|
||||
self.client.get_releases()
|
||||
m_get.assert_called_once_with("releases")
|
||||
mock_fuel_client_get.assert_called_once_with("releases")
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "get")
|
||||
def test_get_task(self, m_get):
|
||||
def test_get_task(self, mock_fuel_client_get):
|
||||
self.client.get_task(42)
|
||||
m_get.assert_called_once_with("tasks/42")
|
||||
mock_fuel_client_get.assert_called_once_with("tasks/42")
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "get")
|
||||
def test_get_tasks(self, m_get):
|
||||
def test_get_tasks(self, mock_fuel_client_get):
|
||||
self.client.get_tasks(42)
|
||||
m_get.assert_called_once_with("tasks?cluster_id=42")
|
||||
mock_fuel_client_get.assert_called_once_with("tasks?cluster_id=42")
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "get")
|
||||
def test_get_node(self, m_get):
|
||||
def test_get_node(self, mock_fuel_client_get):
|
||||
self.client.get_node(42)
|
||||
m_get.assert_called_once_with("nodes/42")
|
||||
mock_fuel_client_get.assert_called_once_with("nodes/42")
|
||||
|
||||
@mock.patch.object(fuelclient, "FuelNodesCollection")
|
||||
@mock.patch.object(fuelclient.FuelClient, "get")
|
||||
def test_get_nodes(self, m_get, m_collection):
|
||||
m_get.return_value = "fake_nodes"
|
||||
m_collection.return_value = "fake_collection"
|
||||
def test_get_nodes(self, mock_fuel_client_get, mock_fuel_nodes_collection):
|
||||
mock_fuel_client_get.return_value = "fake_nodes"
|
||||
mock_fuel_nodes_collection.return_value = "fake_collection"
|
||||
retval = self.client.get_nodes()
|
||||
self.assertEqual("fake_collection", retval)
|
||||
m_collection.assert_called_once_with("fake_nodes")
|
||||
m_get.assert_called_once_with("nodes")
|
||||
mock_fuel_nodes_collection.assert_called_once_with("fake_nodes")
|
||||
mock_fuel_client_get.assert_called_once_with("nodes")
|
||||
|
||||
@mock.patch.object(fuelclient.FuelClient, "delete")
|
||||
def test_delete_cluster(self, m_delete):
|
||||
def test_delete_cluster(self, mock_fuel_client_delete):
|
||||
self.client.delete_cluster(42)
|
||||
m_delete.assert_called_once_with("clusters/42")
|
||||
mock_fuel_client_delete.assert_called_once_with("clusters/42")
|
||||
|
@@ -26,7 +26,7 @@ class LogTestCase(test.TestCase):
|
||||
@mock.patch("rally.common.log.CONF")
|
||||
@mock.patch("rally.common.log.handlers")
|
||||
@mock.patch("rally.common.log.oslogging")
|
||||
def test_setup(self, mock_oslogger, mock_handlers, mock_conf):
|
||||
def test_setup(self, mock_oslogging, mock_handlers, mock_conf):
|
||||
|
||||
proj = "fakep"
|
||||
version = "fakev"
|
||||
@@ -41,33 +41,34 @@ class LogTestCase(test.TestCase):
|
||||
mock_handlers.ColorHandler.LEVEL_COLORS[logging.DEBUG],
|
||||
mock_handlers.ColorHandler.LEVEL_COLORS[logging.RDEBUG])
|
||||
|
||||
mock_oslogger.setup.assert_called_once_with(mock_conf, proj, version)
|
||||
mock_oslogger.getLogger(None).logger.setLevel.assert_called_once_with(
|
||||
mock_oslogging.setup.assert_called_once_with(mock_conf, proj, version)
|
||||
mock_oslogging.getLogger(None).logger.setLevel.assert_called_once_with(
|
||||
logging.RDEBUG)
|
||||
|
||||
@mock.patch("rally.common.log.logging")
|
||||
@mock.patch("rally.common.log.RallyContextAdapter")
|
||||
@mock.patch("rally.common.log.oslogging")
|
||||
def test_getLogger(self, mock_oslogger, mock_radapter, mock_pylogging):
|
||||
def test_getLogger(self, mock_oslogging, mock_rally_context_adapter,
|
||||
mock_logging):
|
||||
|
||||
name = "fake"
|
||||
vers = "fake"
|
||||
mock_oslogger._loggers = {}
|
||||
mock_oslogging._loggers = {}
|
||||
|
||||
returned_logger = log.getLogger(name, vers)
|
||||
|
||||
self.assertIn(name, mock_oslogger._loggers)
|
||||
mock_radapter.assert_called_once_with(
|
||||
mock_pylogging.getLogger(name),
|
||||
self.assertIn(name, mock_oslogging._loggers)
|
||||
mock_rally_context_adapter.assert_called_once_with(
|
||||
mock_logging.getLogger(name),
|
||||
{"project": "rally", "version": vers})
|
||||
self.assertEqual(mock_oslogger._loggers[name], returned_logger)
|
||||
self.assertEqual(mock_oslogging._loggers[name], returned_logger)
|
||||
|
||||
|
||||
class LogRallyContaxtAdapter(test.TestCase):
|
||||
|
||||
@mock.patch("rally.common.log.logging")
|
||||
@mock.patch("rally.common.log.oslogging.KeywordArgumentAdapter")
|
||||
def test_debug(self, mock_oslo_adapter, mock_logging):
|
||||
def test_debug(self, mock_keyword_argument_adapter, mock_logging):
|
||||
|
||||
mock_logging.RDEBUG = 123
|
||||
fake_msg = "fake message"
|
||||
@@ -125,9 +126,10 @@ class LogCatcherTestCase(test.TestCase):
|
||||
|
||||
class CatcherHandlerTestCase(test.TestCase):
|
||||
@mock.patch("logging.handlers.BufferingHandler.__init__")
|
||||
def test_init(self, mock_buffering_handler_init):
|
||||
def test_init(self, mock_buffering_handler___init__):
|
||||
catcher_handler = log.CatcherHandler()
|
||||
mock_buffering_handler_init.assert_called_once_with(catcher_handler, 0)
|
||||
mock_buffering_handler___init__.assert_called_once_with(
|
||||
catcher_handler, 0)
|
||||
|
||||
def test_shouldFlush(self):
|
||||
catcher_handler = log.CatcherHandler()
|
||||
|
@@ -147,23 +147,25 @@ class OSClientsTestCase(test.TestCase):
|
||||
self.assertEqual(self.fake_keystone, self.clients.cache["keystone"])
|
||||
|
||||
@mock.patch("rally.osclients.Clients.keystone")
|
||||
def test_verified_keystone_user_not_admin(self, mock_keystone):
|
||||
mock_keystone.return_value = fakes.FakeKeystoneClient()
|
||||
mock_keystone.return_value.auth_ref.role_names = ["notadmin"]
|
||||
def test_verified_keystone_user_not_admin(self, mock_clients_keystone):
|
||||
mock_clients_keystone.return_value = fakes.FakeKeystoneClient()
|
||||
mock_clients_keystone.return_value.auth_ref.role_names = ["notadmin"]
|
||||
self.assertRaises(exceptions.InvalidAdminException,
|
||||
self.clients.verified_keystone)
|
||||
|
||||
@mock.patch("rally.osclients.Clients.keystone")
|
||||
def test_verified_keystone_unauthorized(self, mock_keystone):
|
||||
mock_keystone.return_value = fakes.FakeKeystoneClient()
|
||||
mock_keystone.side_effect = keystone_exceptions.Unauthorized
|
||||
def test_verified_keystone_unauthorized(self, mock_clients_keystone):
|
||||
mock_clients_keystone.return_value = fakes.FakeKeystoneClient()
|
||||
mock_clients_keystone.side_effect = keystone_exceptions.Unauthorized
|
||||
self.assertRaises(exceptions.InvalidEndpointsException,
|
||||
self.clients.verified_keystone)
|
||||
|
||||
@mock.patch("rally.osclients.Clients.keystone")
|
||||
def test_verified_keystone_unreachable(self, mock_keystone):
|
||||
mock_keystone.return_value = fakes.FakeKeystoneClient()
|
||||
mock_keystone.side_effect = keystone_exceptions.AuthorizationFailure
|
||||
def test_verified_keystone_unreachable(self, mock_clients_keystone):
|
||||
mock_clients_keystone.return_value = fakes.FakeKeystoneClient()
|
||||
mock_clients_keystone.side_effect = (
|
||||
keystone_exceptions.AuthorizationFailure
|
||||
)
|
||||
self.assertRaises(exceptions.HostUnreachableException,
|
||||
self.clients.verified_keystone)
|
||||
|
||||
@@ -487,12 +489,13 @@ class OSClientsTestCase(test.TestCase):
|
||||
self.assertEqual(fake_ec2, self.clients.cache["ec2"])
|
||||
|
||||
@mock.patch("rally.osclients.Clients.keystone")
|
||||
def test_services(self, mock_keystone):
|
||||
def test_services(self, mock_clients_keystone):
|
||||
available_services = {consts.ServiceType.IDENTITY: {},
|
||||
consts.ServiceType.COMPUTE: {},
|
||||
"unknown_service": {}}
|
||||
mock_keystone.return_value = mock.Mock(service_catalog=mock.Mock(
|
||||
get_endpoints=lambda: available_services))
|
||||
mock_clients_keystone.return_value = mock.Mock(
|
||||
service_catalog=mock.Mock(
|
||||
get_endpoints=lambda: available_services))
|
||||
clients = osclients.Clients(self.endpoint)
|
||||
|
||||
self.assertEqual(
|
||||
|
@@ -34,8 +34,8 @@ class ConfigTestCase(test.TestCase):
|
||||
@mock.patch("rally.osclients.Clients.verified_keystone")
|
||||
@mock.patch("rally.verification.tempest.config.os.path.isfile",
|
||||
return_value=True)
|
||||
def setUp(self, mock_isfile, mock_verified_keystone, mock_services,
|
||||
mock_get):
|
||||
def setUp(self, mock_isfile, mock_clients_verified_keystone,
|
||||
mock_clients_services, mock_deployment_get):
|
||||
super(ConfigTestCase, self).setUp()
|
||||
self.endpoint = {"username": "test",
|
||||
"tenant_name": "test",
|
||||
@@ -43,10 +43,10 @@ class ConfigTestCase(test.TestCase):
|
||||
"auth_url": "http://test/v2.0",
|
||||
"permission": "admin",
|
||||
"admin_domain_name": "Default"}
|
||||
mock_get.return_value = {"admin": self.endpoint}
|
||||
mock_deployment_get.return_value = {"admin": self.endpoint}
|
||||
self.deployment = "fake_deployment"
|
||||
self.conf_generator = config.TempestConf(self.deployment)
|
||||
self.conf_generator.clients.services = mock_services
|
||||
self.conf_generator.clients.services = mock_clients_services
|
||||
|
||||
keystone_patcher = mock.patch("rally.osclients.create_keystone_client")
|
||||
keystone_patcher.start()
|
||||
@@ -96,9 +96,9 @@ class ConfigTestCase(test.TestCase):
|
||||
|
||||
@mock.patch("rally.verification.tempest.config.TempestConf"
|
||||
"._get_url")
|
||||
def test__set_boto(self, mock_get_url):
|
||||
def test__set_boto(self, mock_tempest_conf__get_url):
|
||||
url = "test_url"
|
||||
mock_get_url.return_value = url
|
||||
mock_tempest_conf__get_url.return_value = url
|
||||
self.conf_generator._set_boto()
|
||||
expected = (("ec2_url", url),
|
||||
("s3_url", url),
|
||||
@@ -317,8 +317,8 @@ class ConfigTestCase(test.TestCase):
|
||||
"service_available", "horizon"), "True")
|
||||
|
||||
@mock.patch("rally.verification.tempest.config.requests.get")
|
||||
def test__set_service_not_available_horizon(self, mock_requests_get):
|
||||
mock_requests_get.side_effect = requests.Timeout()
|
||||
def test__set_service_not_available_horizon(self, mock_get):
|
||||
mock_get.side_effect = requests.Timeout()
|
||||
self.conf_generator._set_service_available()
|
||||
self.assertEqual(self.conf_generator.conf.get(
|
||||
"service_available", "horizon"), "False")
|
||||
|
@@ -92,13 +92,13 @@ class HtmlOutputTestCase(test.TestCase):
|
||||
@mock.patch(BASE + ".json2html.ui_utils.get_template")
|
||||
@mock.patch(BASE + ".json2html.HtmlOutput._generate_report",
|
||||
return_value="report_data")
|
||||
def test_create_report(self, mock_generate, mock_get):
|
||||
def test_create_report(
|
||||
self, mock_html_output__generate_report, mock_get_template):
|
||||
obj = json2html.HtmlOutput(self.results)
|
||||
mock_render = mock.Mock(return_value="html_report")
|
||||
mock_get().render = mock_render
|
||||
mock_get.reset_mock()
|
||||
mock_get_template.return_value.render.return_value = "html_report"
|
||||
|
||||
html_report = obj.create_report()
|
||||
self.assertEqual(html_report, "html_report")
|
||||
mock_get.assert_called_once_with("verification/report.mako")
|
||||
mock_render.assert_called_once_with(report="report_data")
|
||||
mock_get_template.assert_called_once_with("verification/report.mako")
|
||||
mock_get_template.return_value.render.assert_called_once_with(
|
||||
report="report_data")
|
||||
|
@@ -67,31 +67,32 @@ class TempestUtilsTestCase(BaseTestCase):
|
||||
mock_exists.call_args_list)
|
||||
|
||||
@mock.patch("os.environ")
|
||||
def test_env_missed(self, mock_env):
|
||||
def test_env_missed(self, mock_environ):
|
||||
expected_env = {"PATH": "/some/path"}
|
||||
mock_env.copy.return_value = copy.deepcopy(expected_env)
|
||||
mock_environ.copy.return_value = copy.deepcopy(expected_env)
|
||||
expected_env.update({
|
||||
"TEMPEST_CONFIG": "tempest.conf",
|
||||
"TEMPEST_CONFIG_DIR": self.verifier.path(),
|
||||
"OS_TEST_PATH": self.verifier.path("tempest/test_discover")})
|
||||
self.assertIsNone(self.verifier._env)
|
||||
self.assertEqual(expected_env, self.verifier.env)
|
||||
self.assertTrue(mock_env.copy.called)
|
||||
self.assertTrue(mock_environ.copy.called)
|
||||
self.assertEqual(expected_env, self.verifier._env)
|
||||
|
||||
@mock.patch("os.environ")
|
||||
def test_env_loaded(self, mock_env):
|
||||
def test_env_loaded(self, mock_environ):
|
||||
self.verifier._env = {"foo": "bar"}
|
||||
self.verifier.env
|
||||
self.assertFalse(mock_env.copy.called)
|
||||
self.assertFalse(mock_environ.copy.called)
|
||||
|
||||
@mock.patch("os.path.isdir", return_value=True)
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.check_output")
|
||||
def test__venv_install_when_venv_exists(self, mock_co, mock_isdir):
|
||||
def test__venv_install_when_venv_exists(self, mock_check_output,
|
||||
mock_isdir):
|
||||
self.verifier._install_venv()
|
||||
|
||||
mock_isdir.assert_called_once_with(self.verifier.path(".venv"))
|
||||
self.assertFalse(mock_co.called)
|
||||
self.assertFalse(mock_check_output.called)
|
||||
|
||||
@mock.patch("%s.tempest.sys" % TEMPEST_PATH)
|
||||
@mock.patch("%s.tempest.costilius.get_interpreter" % TEMPEST_PATH,
|
||||
@@ -99,14 +100,15 @@ class TempestUtilsTestCase(BaseTestCase):
|
||||
@mock.patch("os.path.isdir", return_value=False)
|
||||
@mock.patch("%s.tempest.check_output" % TEMPEST_PATH,
|
||||
return_value="some_output")
|
||||
def test__venv_install_when_venv_not_exist(self, mock_co, mock_isdir,
|
||||
def test__venv_install_when_venv_not_exist(self, mock_check_output,
|
||||
mock_isdir,
|
||||
mock_get_interpreter, mock_sys):
|
||||
mock_sys.version_info = "not_py27_env"
|
||||
|
||||
self.verifier._install_venv()
|
||||
|
||||
mock_isdir.assert_called_once_with(self.verifier.path(".venv"))
|
||||
mock_co.assert_has_calls([
|
||||
mock_check_output.assert_has_calls([
|
||||
mock.call("python ./tools/install_venv.py", shell=True,
|
||||
cwd=self.verifier.path()),
|
||||
mock.call("%s python setup.py install" %
|
||||
@@ -129,32 +131,33 @@ class TempestUtilsTestCase(BaseTestCase):
|
||||
@mock.patch("os.path.isdir", return_value=True)
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.subprocess")
|
||||
def test__initialize_testr_when_testr_already_initialized(
|
||||
self, mock_sp, mock_isdir):
|
||||
self, mock_subprocess, mock_isdir):
|
||||
self.verifier._initialize_testr()
|
||||
|
||||
mock_isdir.assert_called_once_with(
|
||||
self.verifier.path(".testrepository"))
|
||||
self.assertFalse(mock_sp.called)
|
||||
self.assertFalse(mock_subprocess.called)
|
||||
|
||||
@mock.patch("os.path.isdir", return_value=False)
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.check_output")
|
||||
def test__initialize_testr_when_testr_not_initialized(
|
||||
self, mock_co, mock_isdir):
|
||||
self, mock_check_output, mock_isdir):
|
||||
self.verifier._initialize_testr()
|
||||
|
||||
mock_isdir.assert_called_once_with(
|
||||
self.verifier.path(".testrepository"))
|
||||
mock_co.assert_called_once_with(
|
||||
mock_check_output.assert_called_once_with(
|
||||
"%s testr init" % self.verifier.venv_wrapper, shell=True,
|
||||
cwd=self.verifier.path())
|
||||
|
||||
@mock.patch.object(subunit2json, "main")
|
||||
@mock.patch("os.path.isfile", return_value=False)
|
||||
def test__save_results_without_log_file(self, mock_isfile, mock_parse):
|
||||
def test__save_results_without_log_file(
|
||||
self, mock_isfile, mock_main):
|
||||
|
||||
self.verifier._save_results()
|
||||
mock_isfile.assert_called_once_with(self.verifier.log_file_raw)
|
||||
self.assertEqual(0, mock_parse.call_count)
|
||||
self.assertEqual(0, mock_main.call_count)
|
||||
|
||||
@mock.patch("os.path.isfile", return_value=True)
|
||||
def test__save_results_with_log_file(self, mock_isfile):
|
||||
@@ -175,10 +178,10 @@ class TempestUtilsTestCase(BaseTestCase):
|
||||
class TempestInstallAndUninstallTestCase(BaseTestCase):
|
||||
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.subprocess.check_call")
|
||||
def test__clone_successful(self, mock_sp):
|
||||
def test__clone_successful(self, mock_check_call):
|
||||
with self.base_repo_patcher:
|
||||
self.verifier._clone()
|
||||
mock_sp.assert_called_once_with(
|
||||
mock_check_call.assert_called_once_with(
|
||||
["git", "clone", "https://github.com/openstack/tempest",
|
||||
"foo-baserepo"])
|
||||
|
||||
@@ -188,35 +191,36 @@ class TempestInstallAndUninstallTestCase(BaseTestCase):
|
||||
|
||||
@mock.patch("subprocess.call", return_value=1)
|
||||
@mock.patch("os.path.isdir", return_value=True)
|
||||
def test__is_not_git_repo(self, mock_isdir, mock_git_status):
|
||||
def test__is_not_git_repo(self, mock_isdir, mock_call):
|
||||
self.assertFalse(self.verifier._is_git_repo("fake_dir"))
|
||||
|
||||
@mock.patch("subprocess.call", return_value=0)
|
||||
@mock.patch("os.path.isdir", return_value=True)
|
||||
def test__is_git_repo(self, mock_isdir, mock_git_status):
|
||||
def test__is_git_repo(self, mock_isdir, mock_call):
|
||||
self.assertTrue(self.verifier._is_git_repo("fake_dir"))
|
||||
|
||||
@mock.patch("%s.tempest.check_output" % TEMPEST_PATH,
|
||||
return_value="fake_url")
|
||||
def test__get_remote_origin(self, mock_co):
|
||||
def test__get_remote_origin(self, mock_check_output):
|
||||
self.assertEqual("fake_url",
|
||||
self.verifier._get_remote_origin("fake_dir"))
|
||||
|
||||
@mock.patch("shutil.rmtree")
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.os.path.exists", return_value=True)
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.subprocess.check_call")
|
||||
def test__clone_failed(self, mock_sp, mock_exists, mock_shutils):
|
||||
def test__clone_failed(self, mock_check_call, mock_exists, mock_rmtree):
|
||||
with self.base_repo_patcher:
|
||||
# Check that `subprocess.CalledProcessError` is not handled
|
||||
# by `_clone`
|
||||
mock_sp.side_effect = subprocess.CalledProcessError(0, None)
|
||||
mock_check_call.side_effect = subprocess.CalledProcessError(
|
||||
0, None)
|
||||
|
||||
self.assertRaises(subprocess.CalledProcessError,
|
||||
self.verifier._clone)
|
||||
mock_sp.assert_called_once_with(
|
||||
mock_check_call.assert_called_once_with(
|
||||
["git", "clone", "https://github.com/openstack/tempest",
|
||||
"foo-baserepo"])
|
||||
mock_shutils.assert_called_once_with(self.verifier.base_repo)
|
||||
mock_rmtree.assert_called_once_with(self.verifier.base_repo)
|
||||
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.base_repo")
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest._initialize_testr")
|
||||
@@ -225,26 +229,28 @@ class TempestInstallAndUninstallTestCase(BaseTestCase):
|
||||
@mock.patch("shutil.copytree")
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest._clone")
|
||||
@mock.patch("os.path.exists", return_value=False)
|
||||
def test_install_successful(self, mock_exists, mock_clone, mock_copytree,
|
||||
mock_sp, mock_install_venv, mock_testr_init,
|
||||
mock_base_repo):
|
||||
mock_base_repo.__get__ = mock.Mock(return_value="fake_dir")
|
||||
def test_install_successful(self, mock_exists, mock_tempest__clone,
|
||||
mock_copytree, mock_check_call,
|
||||
mock_tempest__install_venv,
|
||||
mock_tempest__initialize_testr,
|
||||
mock_tempest_base_repo):
|
||||
mock_tempest_base_repo.__get__ = mock.Mock(return_value="fake_dir")
|
||||
self.verifier.install()
|
||||
|
||||
self.assertEqual([mock.call(self.verifier.path(".venv")),
|
||||
mock.call(self.verifier.base_repo),
|
||||
mock.call(self.verifier.path())],
|
||||
mock_exists.call_args_list)
|
||||
mock_clone.assert_called_once_with()
|
||||
mock_tempest__clone.assert_called_once_with()
|
||||
mock_copytree.assert_called_once_with(
|
||||
self.verifier.base_repo,
|
||||
self.verifier.path())
|
||||
mock_sp.assert_called_once_with(
|
||||
mock_check_call.assert_called_once_with(
|
||||
"git checkout master; git pull",
|
||||
cwd=self.verifier.path("tempest"),
|
||||
shell=True)
|
||||
mock_install_venv.assert_called_once_with()
|
||||
mock_testr_init.assert_called_once_with()
|
||||
mock_tempest__install_venv.assert_called_once_with()
|
||||
mock_tempest__initialize_testr.assert_called_once_with()
|
||||
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.base_repo")
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.uninstall")
|
||||
@@ -254,11 +260,14 @@ class TempestInstallAndUninstallTestCase(BaseTestCase):
|
||||
@mock.patch("shutil.copytree")
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest._clone")
|
||||
@mock.patch("os.path.exists", return_value=False)
|
||||
def test_install_failed(self, mock_exists, mock_clone, mock_copytree,
|
||||
mock_sp, mock_install_venv, mock_testr_init,
|
||||
mock_uninstall, mock_base_repo):
|
||||
mock_base_repo.__get__ = mock.Mock(return_value="fake_dir")
|
||||
mock_sp.side_effect = subprocess.CalledProcessError(0, None)
|
||||
def test_install_failed(self, mock_exists, mock_tempest__clone,
|
||||
mock_copytree, mock_check_call,
|
||||
mock_tempest__install_venv,
|
||||
mock_tempest__initialize_testr,
|
||||
mock_tempest_uninstall,
|
||||
mock_tempest_base_repo):
|
||||
mock_tempest_base_repo.__get__ = mock.Mock(return_value="fake_dir")
|
||||
mock_check_call.side_effect = subprocess.CalledProcessError(0, None)
|
||||
|
||||
self.assertRaises(tempest.TempestSetupFailure, self.verifier.install)
|
||||
|
||||
@@ -266,24 +275,24 @@ class TempestInstallAndUninstallTestCase(BaseTestCase):
|
||||
mock.call(self.verifier.base_repo),
|
||||
mock.call(self.verifier.path())],
|
||||
mock_exists.call_args_list)
|
||||
mock_clone.assert_called_once_with()
|
||||
mock_tempest__clone.assert_called_once_with()
|
||||
mock_copytree.assert_called_once_with(
|
||||
self.verifier.base_repo,
|
||||
self.verifier.path())
|
||||
mock_sp.assert_called_once_with(
|
||||
mock_check_call.assert_called_once_with(
|
||||
"git checkout master; git pull",
|
||||
cwd=self.verifier.path("tempest"),
|
||||
shell=True)
|
||||
self.assertFalse(mock_install_venv.called)
|
||||
self.assertFalse(mock_testr_init.called)
|
||||
mock_uninstall.assert_called_once_with()
|
||||
self.assertFalse(mock_tempest__install_venv.called)
|
||||
self.assertFalse(mock_tempest__initialize_testr.called)
|
||||
mock_tempest_uninstall.assert_called_once_with()
|
||||
|
||||
@mock.patch("shutil.rmtree")
|
||||
@mock.patch("os.path.exists", return_value=True)
|
||||
def test_uninstall(self, mock_exists, mock_shutil):
|
||||
def test_uninstall(self, mock_exists, mock_rmtree):
|
||||
self.verifier.uninstall()
|
||||
mock_exists.assert_called_once_with(self.verifier.path())
|
||||
mock_shutil.assert_called_once_with(self.verifier.path())
|
||||
mock_rmtree.assert_called_once_with(self.verifier.path())
|
||||
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest._is_git_repo",
|
||||
return_value=True)
|
||||
@@ -293,11 +302,12 @@ class TempestInstallAndUninstallTestCase(BaseTestCase):
|
||||
@mock.patch("shutil.move")
|
||||
@mock.patch("os.path.exists", return_value=True)
|
||||
def test_upgrade_repo_tree(self, mock_exists, mock_move, mock_listdir,
|
||||
mock_rand, mock_isgitrepo):
|
||||
mock_generate_random_name,
|
||||
mock_tempest__is_git_repo):
|
||||
with self.base_repo_dir_patcher as foo_base:
|
||||
self.verifier._base_repo = "fake_base"
|
||||
self.verifier.base_repo
|
||||
subdir = mock_rand.return_value
|
||||
subdir = mock_generate_random_name.return_value
|
||||
mock_listdir.assert_called_once_with(foo_base)
|
||||
fake_dir = mock_listdir.return_value[0]
|
||||
source = os.path.join(self.base_repo_dir_patcher.new, fake_dir)
|
||||
@@ -324,23 +334,27 @@ class TempestVerifyTestCase(BaseTestCase):
|
||||
@mock.patch(TEMPEST_PATH + ".config.TempestConf")
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.is_configured",
|
||||
return_value=False)
|
||||
def test_verify_not_configured(self, mock_is_configured, mock_conf,
|
||||
mock_sp, mock_env, mock_parse_results):
|
||||
def test_verify_not_configured(
|
||||
self, mock_tempest_is_configured, mock_tempest_conf,
|
||||
mock_subprocess, mock_tempest_env, mock_tempest_parse_results):
|
||||
|
||||
set_name = "compute"
|
||||
fake_call = self._get_fake_call(set_name)
|
||||
|
||||
self.verifier.verify(set_name, None)
|
||||
|
||||
self.assertEqual(2, mock_is_configured.call_count)
|
||||
mock_conf.assert_called_once_with(self.verifier.deployment)
|
||||
mock_conf().generate.assert_called_once_with(self.verifier.config_file)
|
||||
self.assertEqual(2, mock_tempest_is_configured.call_count)
|
||||
mock_tempest_conf.assert_called_once_with(self.verifier.deployment)
|
||||
mock_tempest_conf.return_value.generate.assert_called_once_with(
|
||||
self.verifier.config_file
|
||||
)
|
||||
self.verifier.verification.start_verifying.assert_called_once_with(
|
||||
set_name)
|
||||
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
fake_call, env=mock_env, cwd=self.verifier.path(),
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
fake_call, env=mock_tempest_env, cwd=self.verifier.path(),
|
||||
shell=True)
|
||||
mock_parse_results.assert_called_once_with()
|
||||
mock_tempest_parse_results.assert_called_once_with()
|
||||
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.parse_results",
|
||||
return_value=(None, None))
|
||||
@@ -349,24 +363,24 @@ class TempestVerifyTestCase(BaseTestCase):
|
||||
@mock.patch(TEMPEST_PATH + ".config.TempestConf")
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.is_configured",
|
||||
return_value=True)
|
||||
def test_verify_when_tempest_configured(self, mock_is_configured,
|
||||
mock_conf, mock_sp, mock_env,
|
||||
mock_parse_results):
|
||||
def test_verify_when_tempest_configured(
|
||||
self, mock_tempest_is_configured, mock_tempest_conf,
|
||||
mock_subprocess, mock_tempest_env, mock_tempest_parse_results):
|
||||
set_name = "identity"
|
||||
fake_call = self._get_fake_call(set_name)
|
||||
|
||||
self.verifier.verify(set_name, None)
|
||||
|
||||
mock_is_configured.assert_called_once_with()
|
||||
self.assertFalse(mock_conf.called)
|
||||
self.assertFalse(mock_conf().generate.called)
|
||||
mock_tempest_is_configured.assert_called_once_with()
|
||||
self.assertFalse(mock_tempest_conf.called)
|
||||
self.assertFalse(mock_tempest_conf().generate.called)
|
||||
self.verifier.verification.start_verifying.assert_called_once_with(
|
||||
set_name)
|
||||
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
fake_call, env=mock_env, cwd=self.verifier.path(),
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
fake_call, env=mock_tempest_env, cwd=self.verifier.path(),
|
||||
shell=True)
|
||||
mock_parse_results.assert_called_once_with()
|
||||
mock_tempest_parse_results.assert_called_once_with()
|
||||
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.parse_results",
|
||||
return_value=(None, None))
|
||||
@@ -376,22 +390,22 @@ class TempestVerifyTestCase(BaseTestCase):
|
||||
@mock.patch(TEMPEST_PATH + ".tempest.Tempest.is_configured",
|
||||
return_value=True)
|
||||
def test_verify_failed_and_tempest_is_configured(
|
||||
self, mock_is_configured, mock_conf, mock_sp, mock_env,
|
||||
mock_parse_results):
|
||||
self, mock_tempest_is_configured, mock_tempest_conf,
|
||||
mock_subprocess, mock_tempest_env, mock_tempest_parse_results):
|
||||
set_name = "identity"
|
||||
fake_call = self._get_fake_call(set_name)
|
||||
mock_sp.side_effect = subprocess.CalledProcessError
|
||||
mock_subprocess.side_effect = subprocess.CalledProcessError
|
||||
|
||||
self.verifier.verify(set_name, None)
|
||||
|
||||
mock_is_configured.assert_called_once_with()
|
||||
self.assertFalse(mock_conf.called)
|
||||
self.assertFalse(mock_conf().generate.called)
|
||||
mock_tempest_is_configured.assert_called_once_with()
|
||||
self.assertFalse(mock_tempest_conf.called)
|
||||
self.assertFalse(mock_tempest_conf().generate.called)
|
||||
self.verifier.verification.start_verifying.assert_called_once_with(
|
||||
set_name)
|
||||
|
||||
mock_sp.check_call.assert_called_once_with(
|
||||
fake_call, env=mock_env, cwd=self.verifier.path(),
|
||||
mock_subprocess.check_call.assert_called_once_with(
|
||||
fake_call, env=mock_tempest_env, cwd=self.verifier.path(),
|
||||
shell=True)
|
||||
self.assertTrue(mock_parse_results.called)
|
||||
self.assertTrue(mock_tempest_parse_results.called)
|
||||
self.verifier.verification.set_failed.assert_called_once_with()
|
||||
|
Reference in New Issue
Block a user