Merge "Replace ' with " in tests/unit/benchmark"

This commit is contained in:
Jenkins 2015-01-30 02:40:53 +00:00 committed by Gerrit Code Review
commit 40f463f781
38 changed files with 504 additions and 504 deletions

View File

@ -79,7 +79,7 @@ class QuotasTestCase(test.TestCase):
except jsonschema.ValidationError:
pass
else:
self.fail('Invalid value %s must raise a validation error'
self.fail("Invalid value %s must raise a validation error"
% ctx["config"]["quotas"][service][key])
ctx["config"]["quotas"][service][key] = 2.5
@ -88,7 +88,7 @@ class QuotasTestCase(test.TestCase):
except jsonschema.ValidationError:
pass
else:
self.fail('Invalid value %s must raise a validation error'
self.fail("Invalid value %s must raise a validation error"
% ctx["config"]["quotas"][service][key])
ctx["config"]["quotas"][service][key] = "-1"
@ -97,7 +97,7 @@ class QuotasTestCase(test.TestCase):
except jsonschema.ValidationError:
pass
else:
self.fail('Invalid value %s must raise a validation error'
self.fail("Invalid value %s must raise a validation error"
% ctx["config"]["quotas"][service][key])
# Test valid values
@ -121,7 +121,7 @@ class QuotasTestCase(test.TestCase):
except jsonschema.ValidationError:
pass
else:
self.fail('Additional keys must raise a validation error')
self.fail("Additional keys must raise a validation error")
del ctx["config"]["quotas"][service]["additional"]
# Test valid keys are optional

View File

@ -42,7 +42,7 @@ class SaharaEDPTestCase(test.TestCase):
"tenant_id": str(i),
"endpoint": "endpoint"})
self.user_key = [{'id': i, 'tenant_id': j, 'endpoint': 'endpoint'}
self.user_key = [{"id": i, "tenant_id": j, "endpoint": "endpoint"}
for j in range(self.tenants_num)
for i in range(self.users_per_tenant)]

View File

@ -34,7 +34,7 @@ class KeyPairContextTestCase(test.TestCase):
"task": task
}
self.ctx_without_keys = {
"users": [{'endpoint': 'endpoint'}] * self.users,
"users": [{"endpoint": "endpoint"}] * self.users,
"task": task
}

View File

@ -34,7 +34,7 @@ class SecGroupContextTestCase(test.TestCase):
"task": task
}
@mock.patch('rally.benchmark.context.secgroup.osclients.Clients')
@mock.patch("rally.benchmark.context.secgroup.osclients.Clients")
def test_prep_ssh_sec_group(self, mock_osclients):
fake_nova = fakes.FakeNovaClient()
self.assertEqual(len(fake_nova.security_groups.list()), 1)
@ -42,7 +42,7 @@ class SecGroupContextTestCase(test.TestCase):
mock_cl.nova.return_value = fake_nova
mock_osclients.return_value = mock_cl
secgroup._prepare_open_secgroup('endpoint')
secgroup._prepare_open_secgroup("endpoint")
self.assertEqual(len(fake_nova.security_groups.list()), 2)
self.assertTrue(
@ -51,10 +51,10 @@ class SecGroupContextTestCase(test.TestCase):
])
# run prep again, check that another security group is not created
secgroup._prepare_open_secgroup('endpoint')
secgroup._prepare_open_secgroup("endpoint")
self.assertEqual(len(fake_nova.security_groups.list()), 2)
@mock.patch('rally.benchmark.context.secgroup.osclients.Clients')
@mock.patch("rally.benchmark.context.secgroup.osclients.Clients")
def test_prep_ssh_sec_group_rules(self, mock_osclients):
fake_nova = fakes.FakeNovaClient()
@ -64,14 +64,14 @@ class SecGroupContextTestCase(test.TestCase):
mock_cl.nova.return_value = fake_nova
mock_osclients.return_value = mock_cl
secgroup._prepare_open_secgroup('endpoint')
secgroup._prepare_open_secgroup("endpoint")
self.assertEqual(len(fake_nova.security_groups.list()), 2)
rally_open = fake_nova.security_groups.find(secgroup.SSH_GROUP_NAME)
self.assertEqual(len(rally_open.rules), 3)
# run prep again, check that extra rules are not created
secgroup._prepare_open_secgroup('endpoint')
secgroup._prepare_open_secgroup("endpoint")
rally_open = fake_nova.security_groups.find(secgroup.SSH_GROUP_NAME)
self.assertEqual(len(rally_open.rules), 3)

View File

@ -49,7 +49,7 @@ class TempestContextTestCase(test.TestCase):
self.assertEqual(0, mock_install.call_count)
self.assertEqual(0, mock_cfg.call_count)
self.assertEqual('/dev/null', benchmark.verifier.log_file_raw)
self.assertEqual("/dev/null", benchmark.verifier.log_file_raw)
@mock.patch(CONTEXT + ".os.mkdir")
@mock.patch(TEMPEST + ".Tempest.is_configured")
@ -87,7 +87,7 @@ class TempestContextTestCase(test.TestCase):
benchmark = tempest.Tempest(self.context)
benchmark.setup()
self.assertEqual(1, mock_is_installed.call_count)
self.assertEqual('/dev/null', benchmark.verifier.log_file_raw)
self.assertEqual("/dev/null", benchmark.verifier.log_file_raw)
self.assertEqual(1, mock_gen.call_count)
@mock.patch(CONTEXT + ".os.path.exists", return_value=True)

View File

@ -64,7 +64,7 @@ class UserGeneratorTestCase(test.TestCase):
nova_admin = mock.MagicMock()
clients = mock.MagicMock()
self.osclients.Clients.return_value = clients
clients.services.return_value = {'compute': 'nova'}
clients.services.return_value = {"compute": "nova"}
clients.nova.return_value = nova_admin
nova_admin.networks.list.return_value = networks
nova_admin.networks.get = fake_get_network
@ -73,7 +73,7 @@ class UserGeneratorTestCase(test.TestCase):
"t2": dict(id="t2", name="t2")}
user_generator._remove_associated_networks()
mock_check_service_status.assert_called_once_with(mock.ANY,
'nova-network')
"nova-network")
nova_admin.networks.disassociate.assert_called_once_with(networks[0])
@mock.patch("rally.benchmark.utils.check_service_status",
@ -90,7 +90,7 @@ class UserGeneratorTestCase(test.TestCase):
nova_admin = mock.MagicMock()
clients = mock.MagicMock()
self.osclients.Clients.return_value = clients
clients.services.return_value = {'compute': 'nova'}
clients.services.return_value = {"compute": "nova"}
clients.nova.return_value = nova_admin
nova_admin.networks.list.return_value = networks
nova_admin.networks.get = fake_get_network
@ -100,7 +100,7 @@ class UserGeneratorTestCase(test.TestCase):
"t2": dict(id="t2", name="t2")}
user_generator._remove_associated_networks()
mock_check_service_status.assert_called_once_with(mock.ANY,
'nova-network')
"nova-network")
nova_admin.networks.disassociate.assert_called_once_with(networks[0])
@mock.patch("rally.benchmark.context.users.broker.time.sleep")
@ -209,7 +209,7 @@ class UserGeneratorTestCase(test.TestCase):
"task": task
}
user_list = [mock.MagicMock(id='id_%d' % i)
user_list = [mock.MagicMock(id="id_%d" % i)
for i in range(self.users_num)]
wrapped_keystone.create_user.side_effect = user_list

View File

@ -77,26 +77,26 @@ class MathTestCase(test.TestCase):
self.assertEqual(
utils.compress(data64, limit=4,
normalize=alt_normalize, merge=alt_merge),
[(17, '012345678910111213141516'),
(33, '17181920212223242526272829303132'),
(49, '33343536373839404142434445464748'),
(64, '495051525354555657585960616263')])
[(17, "012345678910111213141516"),
(33, "17181920212223242526272829303132"),
(49, "33343536373839404142434445464748"),
(64, "495051525354555657585960616263")])
# Short list
self.assertEqual(utils.compress(data4, limit=2),
[(3, 2.0), (4, 3.0)])
self.assertEqual(utils.compress(data4, normalize=alt_normalize),
[(1, '4'), (2, '2'), (3, '1'), (4, '3')])
[(1, "4"), (2, "2"), (3, "1"), (4, "3")])
# List with mixed data types
self.assertEqual(utils.compress(mixed),
[(1, 2.0), (2, 5.0), (3, 0.0), (4, 0.5)])
self.assertEqual(utils.compress(mixed, normalize=str),
[(1, '2'), (2, '5'), (3, 'None'), (4, '0.5')])
[(1, "2"), (2, "5"), (3, "None"), (4, "0.5")])
self.assertRaises(TypeError, utils.compress, mixed, normalize=int)
self.assertEqual(
utils.compress(mixed, normalize=alt_normalize, merge=alt_merge),
[(1, '2'), (2, '5'), (3, 'None'), (4, '0.5')])
[(1, "2"), (2, "5"), (3, "None"), (4, "0.5")])
class AtomicActionsDataTestCase(test.TestCase):

View File

@ -64,7 +64,7 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
self.assertEqual(len(runner.result_queue), self.config["times"])
for result in runner.result_queue:
self.assertIsNotNone(base.ScenarioRunnerResult(result))
self.assertIn('error', runner.result_queue[0])
self.assertIn("error", runner.result_queue[0])
def test_run_scenario_constantly_for_times_timeout(self):
runner = constant.ConstantScenarioRunner(
@ -75,7 +75,7 @@ class ConstantScenarioRunnerTestCase(test.TestCase):
self.assertEqual(len(runner.result_queue), self.config["times"])
for result in runner.result_queue:
self.assertIsNotNone(base.ScenarioRunnerResult(result))
self.assertIn('error', runner.result_queue[0])
self.assertIn("error", runner.result_queue[0])
class ConstantForDurationScenarioRunnerTeestCase(test.TestCase):
@ -124,7 +124,7 @@ class ConstantForDurationScenarioRunnerTeestCase(test.TestCase):
self.assertEqual(len(runner.result_queue), expected_times)
for result in runner.result_queue:
self.assertIsNotNone(base.ScenarioRunnerResult(result))
self.assertIn('error', runner.result_queue[0])
self.assertIn("error", runner.result_queue[0])
def test_run_scenario_constantly_for_duration_timeout(self):
runner = constant.ConstantForDurationScenarioRunner(
@ -137,4 +137,4 @@ class ConstantForDurationScenarioRunnerTeestCase(test.TestCase):
self.assertEqual(len(runner.result_queue), expected_times)
for result in runner.result_queue:
self.assertIsNotNone(base.ScenarioRunnerResult(result))
self.assertIn('error', runner.result_queue[0])
self.assertIn("error", runner.result_queue[0])

View File

@ -77,8 +77,8 @@ class RPSScenarioRunnerTestCase(test.TestCase):
times = 4
context = {'users': [{'tenant_id': 't1', 'endpoint': 'e1',
'id': 'uuid1'}]}
context = {"users": [{"tenant_id": "t1", "endpoint": "e1",
"id": "uuid1"}]}
rps._worker_process(10, times, mock_queue, context, 600, 1, 1,
"Dummy", "dummy", ())
@ -119,7 +119,7 @@ class RPSScenarioRunnerTestCase(test.TestCase):
@mock.patch("rally.benchmark.runners.rps.time.sleep")
def test__run_scenario(self, mock_sleep):
context = fakes.FakeUserContext({}).context
context['task'] = {'uuid': 'fake_uuid'}
context["task"] = {"uuid": "fake_uuid"}
config = {"times": 20, "rps": 20, "timeout": 5}
runner = rps.RPSScenarioRunner(
None, config)
@ -134,7 +134,7 @@ class RPSScenarioRunnerTestCase(test.TestCase):
@mock.patch("rally.benchmark.runners.rps.time.sleep")
def test__run_scenario_exception(self, mock_sleep):
context = fakes.FakeUserContext({}).context
context['task'] = {'uuid': 'fake_uuid'}
context["task"] = {"uuid": "fake_uuid"}
config = {"times": 4, "rps": 10}
runner = rps.RPSScenarioRunner(

View File

@ -28,7 +28,7 @@ class CeilometerAlarmsTestCase(test.TestCase):
fakearg="f")
scenario._create_alarm.assert_called_once_with("fake_meter_name",
"fake_threshold",
{'fakearg': 'f'})
{"fakearg": "f"})
def test_list_alarm(self):
scenario = alarms.CeilometerAlarms()
@ -48,11 +48,11 @@ class CeilometerAlarmsTestCase(test.TestCase):
fakearg="f")
scenario._create_alarm.assert_called_once_with("fake_meter_name",
"fake_threshold",
{'fakearg': 'f'})
{"fakearg": "f"})
scenario._list_alarms.assert_called_once_with(fake_alarm.alarm_id)
def test_create_and_update_alarm(self):
fake_alram_dict_diff = {'description': 'Changed Test Description'}
fake_alram_dict_diff = {"description": "Changed Test Description"}
fake_alarm = mock.MagicMock()
scenario = alarms.CeilometerAlarms()
@ -63,7 +63,7 @@ class CeilometerAlarmsTestCase(test.TestCase):
fakearg="f")
scenario._create_alarm.assert_called_once_with("fake_meter_name",
"fake_threshold",
{'fakearg': 'f'})
{"fakearg": "f"})
scenario._update_alarm.assert_called_once_with(fake_alarm.alarm_id,
fake_alram_dict_diff)
@ -78,5 +78,5 @@ class CeilometerAlarmsTestCase(test.TestCase):
fakearg="f")
scenario._create_alarm.assert_called_once_with("fake_meter_name",
"fake_threshold",
{'fakearg': 'f'})
{"fakearg": "f"})
scenario._delete_alarm.assert_called_once_with(fake_alarm.alarm_id)

View File

@ -31,7 +31,7 @@ class CeilometerQueriesTestCase(test.TestCase):
"fake_orderby_attribute", 10,
fakearg="f")
scenario._create_alarm.assert_called_once_with("fake_meter_name",
100, {'fakearg': 'f'})
100, {"fakearg": "f"})
scenario._query_alarms.assert_called_once_with(
json.dumps("fake_filter"), "fake_orderby_attribute", 10)
@ -45,13 +45,13 @@ class CeilometerQueriesTestCase(test.TestCase):
"fake_orderby_attribute", 10,
fakearg="f")
scenario._create_alarm.assert_called_once_with("fake_meter_name",
100, {'fakearg': 'f'})
100, {"fakearg": "f"})
scenario._query_alarms.assert_called_once_with(
None, "fake_orderby_attribute", 10)
def test_create_and_query_alarm_history(self):
fake_alarm = mock.MagicMock()
fake_alarm.alarm_id = 'fake_alarm_id'
fake_alarm.alarm_id = "fake_alarm_id"
scenario = queries.CeilometerQueries()
scenario._create_alarm = mock.MagicMock(return_value=fake_alarm)
scenario._query_alarm_history = mock.MagicMock()
@ -61,7 +61,7 @@ class CeilometerQueriesTestCase(test.TestCase):
"fake_orderby_attribute", 10,
fakearg="f")
scenario._create_alarm.assert_called_once_with("fake_meter_name", 100,
{'fakearg': 'f'})
{"fakearg": "f"})
scenario._query_alarm_history.assert_called_once_with(
fake_filter, "fake_orderby_attribute", 10)

View File

@ -20,7 +20,7 @@ from oslotest import mockpatch
from rally.benchmark.scenarios.cinder import utils
from tests.unit import test
BM_UTILS = 'rally.benchmark.utils'
BM_UTILS = "rally.benchmark.utils"
CINDER_UTILS = "rally.benchmark.scenarios.cinder.utils"
@ -29,7 +29,7 @@ class CinderScenarioTestCase(test.TestCase):
def setUp(self):
super(CinderScenarioTestCase, self).setUp()
self.res_is = mockpatch.Patch(BM_UTILS + ".resource_is")
self.get_fm = mockpatch.Patch(BM_UTILS + '.get_from_manager')
self.get_fm = mockpatch.Patch(BM_UTILS + ".get_from_manager")
self.wait_for = mockpatch.Patch(CINDER_UTILS + ".bench_utils.wait_for")
self.wait_for_delete = mockpatch.Patch(
CINDER_UTILS + ".bench_utils.wait_for_delete")
@ -38,32 +38,32 @@ class CinderScenarioTestCase(test.TestCase):
self.useFixture(self.res_is)
self.useFixture(self.get_fm)
self.gfm = self.get_fm.mock
self.useFixture(mockpatch.Patch('time.sleep'))
self.useFixture(mockpatch.Patch("time.sleep"))
self.scenario = utils.CinderScenario()
@mock.patch(CINDER_UTILS + '.CinderScenario.clients')
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
def test__list_volumes(self, mock_clients):
volumes_list = mock.Mock()
mock_clients("cinder").volumes.list.return_value = volumes_list
return_volumes_list = self.scenario._list_volumes()
self.assertEqual(volumes_list, return_volumes_list)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
'cinder.list_volumes')
"cinder.list_volumes")
@mock.patch(CINDER_UTILS + '.CinderScenario.clients')
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
def test__list_snapshots(self, mock_clients):
snapsht_lst = mock.Mock()
mock_clients("cinder").volume_snapshots.list.return_value = snapsht_lst
return_snapshots_list = self.scenario._list_snapshots()
self.assertEqual(snapsht_lst, return_snapshots_list)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
'cinder.list_snapshots')
"cinder.list_snapshots")
@mock.patch(CINDER_UTILS + '.CinderScenario.clients')
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
def test__create_volume(self, mock_clients):
CONF = cfg.CONF
volume = mock.Mock()
mock_clients('cinder').volumes.create.return_value = volume
mock_clients("cinder").volumes.create.return_value = volume
return_volume = self.scenario._create_volume(1)
self.wait_for.mock.assert_called_once_with(
volume,
@ -72,10 +72,10 @@ class CinderScenarioTestCase(test.TestCase):
timeout=CONF.benchmark.cinder_volume_create_timeout,
check_interval=CONF.benchmark.cinder_volume_create_poll_interval
)
self.res_is.mock.assert_has_calls([mock.call('available')])
self.res_is.mock.assert_has_calls([mock.call("available")])
self.assertEqual(self.wait_for.mock(), return_volume)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
'cinder.create_volume')
"cinder.create_volume")
def test__delete_volume(self):
cinder = mock.Mock()
@ -88,13 +88,13 @@ class CinderScenarioTestCase(test.TestCase):
check_interval=cfg.CONF.benchmark
.cinder_volume_create_poll_interval)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
'cinder.delete_volume')
"cinder.delete_volume")
@mock.patch(CINDER_UTILS + '.CinderScenario.clients')
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
def test__extend_volume(self, mock_clients):
CONF = cfg.CONF
volume = mock.Mock()
mock_clients('cinder').volumes.extend.return_value = volume
mock_clients("cinder").volumes.extend.return_value = volume
self.scenario._extend_volume(volume, 2)
self.wait_for.mock.assert_called_once_with(
volume,
@ -103,16 +103,16 @@ class CinderScenarioTestCase(test.TestCase):
timeout=CONF.benchmark.cinder_volume_create_timeout,
check_interval=CONF.benchmark.cinder_volume_create_poll_interval
)
self.res_is.mock.assert_has_calls([mock.call('available')])
self.res_is.mock.assert_has_calls([mock.call("available")])
self._test_atomic_action_timer(self.scenario.atomic_actions(),
'cinder.extend_volume')
"cinder.extend_volume")
@mock.patch(CINDER_UTILS + '.CinderScenario.clients')
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
def test__create_snapshot(self, mock_clients):
snapshot = mock.Mock()
mock_clients("cinder").volume_snapshots.create.return_value = snapshot
return_snapshot = self.scenario._create_snapshot('uuid', False)
return_snapshot = self.scenario._create_snapshot("uuid", False)
self.wait_for.mock.assert_called_once_with(
snapshot,
@ -121,10 +121,10 @@ class CinderScenarioTestCase(test.TestCase):
timeout=cfg.CONF.benchmark.cinder_volume_create_timeout,
check_interval=cfg.CONF.benchmark
.cinder_volume_create_poll_interval)
self.res_is.mock.assert_has_calls([mock.call('available')])
self.res_is.mock.assert_has_calls([mock.call("available")])
self.assertEqual(self.wait_for.mock(), return_snapshot)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
'cinder.create_snapshot')
"cinder.create_snapshot")
def test__delete_snapshot(self):
snapshot = mock.Mock()
@ -137,7 +137,7 @@ class CinderScenarioTestCase(test.TestCase):
check_interval=cfg.CONF.benchmark
.cinder_volume_create_poll_interval)
self._test_atomic_action_timer(self.scenario.atomic_actions(),
'cinder.delete_snapshot')
"cinder.delete_snapshot")
def test__get_random_server(self):
servers = [1, 2, 3]
@ -147,7 +147,7 @@ class CinderScenarioTestCase(test.TestCase):
"tenant": {"id": "fake", "servers": servers}}
self.scenario.context = context
self.scenario.clients = mock.Mock()
self.scenario.clients('nova').servers.get = mock.Mock(
self.scenario.clients("nova").servers.get = mock.Mock(
side_effect=lambda arg: arg)
server_id = self.scenario.get_random_server()

View File

@ -247,7 +247,7 @@ class CinderServersTestCase(test.TestCase):
# Make sure create volume's second arg was the correct volume type.
# fake or none (randomly selected)
self.assertTrue(scenario._create_volume.called)
vol_type = scenario._create_volume.call_args_list[0][1]['volume_type']
vol_type = scenario._create_volume.call_args_list[0][1]["volume_type"]
self.assertTrue(vol_type is fake.name or vol_type is None)
scenario._create_snapshot.assert_called_once_with(fake_volume.id,
False)

View File

@ -76,7 +76,7 @@ class DesignateBasicTestCase(test.TestCase):
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_list.assert_called_once_with(domain["id"])
@mock.patch(DESIGNATE_BASIC + "._delete_record")
@mock.patch(DESIGNATE_BASIC + "._create_record")
@ -101,7 +101,7 @@ class DesignateBasicTestCase(test.TestCase):
[mock.call(domain, atomic_action=False)]
* records_per_domain)
self.assertEqual(mock_delete.mock_calls,
[mock.call(domain['id'], "321", atomic_action=False)]
[mock.call(domain["id"], "321", atomic_action=False)]
* records_per_domain)
@mock.patch(DESIGNATE_BASIC + "._list_records")

View File

@ -29,8 +29,8 @@ class DesignateScenarioTestCase(test.TestCase):
super(DesignateScenarioTestCase, self).setUp()
self.domain = mock.Mock()
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario._generate_random_name')
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario.clients')
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
def test_create_domain(self, mock_clients, mock_random_name):
scenario = utils.DesignateScenario()
@ -44,10 +44,10 @@ class DesignateScenarioTestCase(test.TestCase):
# Check that the defaults / randoms are used if nothing is specified
domain = scenario._create_domain()
mock_clients("designate").domains.create.assert_called_once_with(
{"email": "root@random.name", "name": '%s.name.' % random_name})
{"email": "root@random.name", "name": "%s.name." % random_name})
self.assertEqual(self.domain, domain)
self._test_atomic_action_timer(scenario.atomic_actions(),
'designate.create_domain')
"designate.create_domain")
mock_clients("designate").domains.create.reset_mock()
@ -57,7 +57,7 @@ class DesignateScenarioTestCase(test.TestCase):
mock_clients("designate").domains.create.assert_called_once_with(data)
self.assertEqual(self.domain, domain)
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario.clients')
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
def test_list_domains(self, mock_clients):
scenario = utils.DesignateScenario()
domains_list = []
@ -65,25 +65,25 @@ class DesignateScenarioTestCase(test.TestCase):
return_domains_list = scenario._list_domains()
self.assertEqual(domains_list, return_domains_list)
self._test_atomic_action_timer(scenario.atomic_actions(),
'designate.list_domains')
"designate.list_domains")
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario.clients')
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
def test_delete_domain(self, mock_clients):
scenario = utils.DesignateScenario()
domain = scenario._create_domain()
scenario._delete_domain(domain['id'])
scenario._delete_domain(domain["id"])
self._test_atomic_action_timer(scenario.atomic_actions(),
'designate.delete_domain')
"designate.delete_domain")
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario._generate_random_name')
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario.clients')
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
def test_create_record(self, mock_clients, mock_random_name):
scenario = utils.DesignateScenario()
random_name = "foo"
domain_name = "zone.name."
random_record_name = '%s.%s' % (random_name, domain_name)
random_record_name = "%s.%s" % (random_name, domain_name)
mock_random_name.return_value = random_name
@ -92,7 +92,7 @@ class DesignateScenarioTestCase(test.TestCase):
# Create with randoms (name and type)
scenario._create_record(domain)
mock_clients("designate").records.create.assert_called_once_with(
domain['id'],
domain["id"],
{"name": random_record_name, "type": "A", "data": "10.0.0.1"})
self._test_atomic_action_timer(scenario.atomic_actions(),
@ -104,9 +104,9 @@ class DesignateScenarioTestCase(test.TestCase):
record = {"name": "www.zone.name.", "type": "ASD"}
scenario._create_record(domain, record)
mock_clients("designate").records.create.assert_called_once_with(
domain['id'], record)
domain["id"], record)
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario.clients')
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
def test_list_records(self, mock_clients):
scenario = utils.DesignateScenario()
records_list = []
@ -114,19 +114,19 @@ class DesignateScenarioTestCase(test.TestCase):
return_records_list = scenario._list_records("123")
self.assertEqual(records_list, return_records_list)
self._test_atomic_action_timer(scenario.atomic_actions(),
'designate.list_records')
"designate.list_records")
@mock.patch(DESIGNATE_UTILS + 'DesignateScenario.clients')
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
def test_delete_record(self, mock_clients):
scenario = utils.DesignateScenario()
mock_clients('designate').domains.create.return_value = {
mock_clients("designate").domains.create.return_value = {
"id": "123", "name": "asd"}
domain = scenario._create_domain()
mock_clients('designate').records.create.return_value = {"id": "123"}
mock_clients("designate").records.create.return_value = {"id": "123"}
record = scenario._create_record(domain)
scenario._delete_record(domain['id'], record['id'])
scenario._delete_record(domain["id"], record["id"])
self._test_atomic_action_timer(scenario.atomic_actions(),
'designate.delete_record')
"designate.delete_record")

View File

@ -52,10 +52,10 @@ class DummyTestCase(test.TestCase):
def test_dummy_dummy_with_scenario_output(self):
scenario = dummy.Dummy()
result = scenario.dummy_with_scenario_output()
self.assertEqual(result['errors'], "")
self.assertEqual(result["errors"], "")
# Since the data is generated in random,
# checking for not None
self.assertNotEqual(result['data'], None)
self.assertNotEqual(result["data"], None)
def test_dummy_random_fail_in_atomic(self):
scenario = dummy.Dummy()

View File

@ -86,7 +86,7 @@ class GlanceImagesTestCase(test.TestCase):
mock_create_image.return_value = fake_image
mock_boot_servers.return_value = fake_servers
mock_random_name.return_value = "random_name"
kwargs = {'fakearg': 'f'}
kwargs = {"fakearg": "f"}
with mock.patch("rally.benchmark.scenarios.glance.utils.time.sleep"):
glance_scenario.create_image_and_boot_instances("cf", "url",
"df", "fid",

View File

@ -23,8 +23,8 @@ from rally import exceptions as rally_exceptions
from tests.unit import fakes
from tests.unit import test
BM_UTILS = 'rally.benchmark.utils'
GLANCE_UTILS = 'rally.benchmark.scenarios.glance.utils'
BM_UTILS = "rally.benchmark.utils"
GLANCE_UTILS = "rally.benchmark.scenarios.glance.utils"
class GlanceScenarioTestCase(test.TestCase):
@ -34,7 +34,7 @@ class GlanceScenarioTestCase(test.TestCase):
self.image = mock.Mock()
self.image1 = mock.Mock()
self.res_is = mockpatch.Patch(BM_UTILS + ".resource_is")
self.get_fm = mockpatch.Patch(BM_UTILS + '.get_from_manager')
self.get_fm = mockpatch.Patch(BM_UTILS + ".get_from_manager")
self.wait_for = mockpatch.Patch(GLANCE_UTILS + ".bench_utils.wait_for")
self.wait_for_delete = mockpatch.Patch(
GLANCE_UTILS + ".bench_utils.wait_for_delete")
@ -43,7 +43,7 @@ class GlanceScenarioTestCase(test.TestCase):
self.useFixture(self.res_is)
self.useFixture(self.get_fm)
self.gfm = self.get_fm.mock
self.useFixture(mockpatch.Patch('time.sleep'))
self.useFixture(mockpatch.Patch("time.sleep"))
self.scenario = utils.GlanceScenario()
def test_failed_image_status(self):
@ -51,9 +51,9 @@ class GlanceScenarioTestCase(test.TestCase):
image_manager = fakes.FakeFailedImageManager()
self.assertRaises(rally_exceptions.GetResourceFailure,
butils.get_from_manager(),
image_manager.create('fails', 'url', 'cf', 'df'))
image_manager.create("fails", "url", "cf", "df"))
@mock.patch(GLANCE_UTILS + '.GlanceScenario.clients')
@mock.patch(GLANCE_UTILS + ".GlanceScenario.clients")
def test_list_images(self, mock_clients):
images_list = []
mock_clients("glance").images.list.return_value = images_list
@ -61,44 +61,44 @@ class GlanceScenarioTestCase(test.TestCase):
return_images_list = scenario._list_images()
self.assertEqual(images_list, return_images_list)
self._test_atomic_action_timer(scenario.atomic_actions(),
'glance.list_images')
"glance.list_images")
@mock.patch(GLANCE_UTILS + '.GlanceScenario.clients')
@mock.patch(GLANCE_UTILS + ".GlanceScenario.clients")
def test_create_image(self, mock_clients):
image_location = tempfile.NamedTemporaryFile()
mock_clients("glance").images.create.return_value = self.image
scenario = utils.GlanceScenario()
return_image = scenario._create_image('image_name',
'container_format',
return_image = scenario._create_image("image_name",
"container_format",
image_location.name,
'disk_format')
"disk_format")
self.wait_for.mock.assert_called_once_with(self.image,
update_resource=self.gfm(),
is_ready=self.res_is.mock(),
check_interval=1,
timeout=120)
self.res_is.mock.assert_has_calls([mock.call('active')])
self.res_is.mock.assert_has_calls([mock.call("active")])
self.assertEqual(self.wait_for.mock(), return_image)
self._test_atomic_action_timer(scenario.atomic_actions(),
'glance.create_image')
"glance.create_image")
@mock.patch(GLANCE_UTILS + '.GlanceScenario.clients')
@mock.patch(GLANCE_UTILS + ".GlanceScenario.clients")
def test_create_image_with_location(self, mock_clients):
mock_clients("glance").images.create.return_value = self.image
scenario = utils.GlanceScenario()
return_image = scenario._create_image('image_name',
'container_format',
'image_location',
'disk_format')
return_image = scenario._create_image("image_name",
"container_format",
"image_location",
"disk_format")
self.wait_for.mock.assert_called_once_with(self.image,
update_resource=self.gfm(),
is_ready=self.res_is.mock(),
check_interval=1,
timeout=120)
self.res_is.mock.assert_has_calls([mock.call('active')])
self.res_is.mock.assert_has_calls([mock.call("active")])
self.assertEqual(self.wait_for.mock(), return_image)
self._test_atomic_action_timer(scenario.atomic_actions(),
'glance.create_image')
"glance.create_image")
def test_delete_image(self):
scenario = utils.GlanceScenario()
@ -110,4 +110,4 @@ class GlanceScenarioTestCase(test.TestCase):
check_interval=1,
timeout=120)
self._test_atomic_action_timer(scenario.atomic_actions(),
'glance.delete_image')
"glance.delete_image")

View File

@ -20,8 +20,8 @@ from rally.benchmark.scenarios.heat import utils
from rally import exceptions
from tests.unit import test
BM_UTILS = 'rally.benchmark.utils'
HEAT_UTILS = 'rally.benchmark.scenarios.heat.utils'
BM_UTILS = "rally.benchmark.utils"
HEAT_UTILS = "rally.benchmark.scenarios.heat.utils"
class HeatScenarioTestCase(test.TestCase):
@ -30,7 +30,7 @@ class HeatScenarioTestCase(test.TestCase):
super(HeatScenarioTestCase, self).setUp()
self.stack = mock.Mock()
self.res_is = mockpatch.Patch(BM_UTILS + ".resource_is")
self.get_fm = mockpatch.Patch(BM_UTILS + '.get_from_manager')
self.get_fm = mockpatch.Patch(BM_UTILS + ".get_from_manager")
self.wait_for = mockpatch.Patch(HEAT_UTILS + ".bench_utils.wait_for")
self.wait_for_delete = mockpatch.Patch(
HEAT_UTILS + ".bench_utils.wait_for_delete")
@ -39,10 +39,10 @@ class HeatScenarioTestCase(test.TestCase):
self.useFixture(self.res_is)
self.useFixture(self.get_fm)
self.gfm = self.get_fm.mock
self.useFixture(mockpatch.Patch('time.sleep'))
self.useFixture(mockpatch.Patch("time.sleep"))
self.scenario = utils.HeatScenario()
@mock.patch(HEAT_UTILS + '.HeatScenario.clients')
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
def test_list_stacks(self, mock_clients):
stacks_list = []
mock_clients("heat").stacks.list.return_value = stacks_list
@ -50,25 +50,25 @@ class HeatScenarioTestCase(test.TestCase):
return_stacks_list = scenario._list_stacks()
self.assertEqual(stacks_list, return_stacks_list)
self._test_atomic_action_timer(scenario.atomic_actions(),
'heat.list_stacks')
"heat.list_stacks")
@mock.patch(HEAT_UTILS + '.HeatScenario.clients')
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
def test_create_stack(self, mock_clients):
mock_clients("heat").stacks.create.return_value = {
'stack': {'id': 'test_id'}
"stack": {"id": "test_id"}
}
mock_clients("heat").stacks.get.return_value = self.stack
scenario = utils.HeatScenario()
return_stack = scenario._create_stack('stack_name')
return_stack = scenario._create_stack("stack_name")
self.wait_for.mock.assert_called_once_with(self.stack,
update_resource=self.gfm(),
is_ready=self.res_is.mock(),
check_interval=1,
timeout=3600)
self.res_is.mock.assert_has_calls([mock.call('CREATE_COMPLETE')])
self.res_is.mock.assert_has_calls([mock.call("CREATE_COMPLETE")])
self.assertEqual(self.wait_for.mock(), return_stack)
self._test_atomic_action_timer(scenario.atomic_actions(),
'heat.create_stack')
"heat.create_stack")
def test_delete_stack(self):
scenario = utils.HeatScenario()
@ -80,20 +80,20 @@ class HeatScenarioTestCase(test.TestCase):
check_interval=1,
timeout=3600)
self._test_atomic_action_timer(scenario.atomic_actions(),
'heat.delete_stack')
"heat.delete_stack")
class HeatScenarioNegativeTestCase(test.TestCase):
@mock.patch(HEAT_UTILS + '.HeatScenario.clients')
@mock.patch(HEAT_UTILS + '.CONF.benchmark')
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
@mock.patch(HEAT_UTILS + ".CONF.benchmark")
def test_failed_create_stack(self, mock_bench, mock_clients):
mock_bench.heat_stack_create_prepoll_delay = 2
mock_bench.heat_stack_create_timeout = 1
mock_bench.benchmark.heat_stack_create_poll_interval = 1
mock_clients("heat").stacks.create.return_value = {
'stack': {'id': 'test_id'}
"stack": {"id": "test_id"}
}
stack = mock.Mock()
resource = mock.Mock()
@ -103,7 +103,7 @@ class HeatScenarioNegativeTestCase(test.TestCase):
scenario = utils.HeatScenario()
try:
ex = self.assertRaises(exceptions.GetResourceErrorStatus,
scenario._create_stack, 'stack_name')
self.assertIn('has CREATE_FAILED status', str(ex))
scenario._create_stack, "stack_name")
self.assertIn("has CREATE_FAILED status", str(ex))
except exceptions.TimeoutException:
raise self.fail('Unrecognized error status')
raise self.fail("Unrecognized error status")

View File

@ -71,7 +71,7 @@ class KeystoneScenarioTestCase(test.TestCase):
email=mock_gen_name.return_value + "@rally.me")
mock_uuid4.assert_called_with()
self._test_atomic_action_timer(scenario.atomic_actions(),
'keystone.create_user')
"keystone.create_user")
def test_user_delete(self):
resource = fakes.FakeResource()
@ -100,7 +100,7 @@ class KeystoneScenarioTestCase(test.TestCase):
self.assertEqual(tenant, result)
fake_keystone.tenants.create.assert_called_once_with(name)
self._test_atomic_action_timer(scenario.atomic_actions(),
'keystone.create_tenant')
"keystone.create_tenant")
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
def test_tenant_create_with_users(self, mock_gen_name):
@ -120,7 +120,7 @@ class KeystoneScenarioTestCase(test.TestCase):
name, password=name, email=name + "@rally.me",
tenant_id=tenant.id)
self._test_atomic_action_timer(scenario.atomic_actions(),
'keystone.create_users')
"keystone.create_users")
def test_list_users(self):
fake_keystone = fakes.FakeKeystoneClient()
@ -131,7 +131,7 @@ class KeystoneScenarioTestCase(test.TestCase):
scenario._list_users()
fake_keystone.users.list.assert_called_once_with()
self._test_atomic_action_timer(scenario.atomic_actions(),
'keystone.list_users')
"keystone.list_users")
def test_list_tenants(self):
fake_keystone = fakes.FakeKeystoneClient()
@ -142,4 +142,4 @@ class KeystoneScenarioTestCase(test.TestCase):
scenario._list_tenants()
fake_keystone.tenants.list.assert_called_once_with()
self._test_atomic_action_timer(scenario.atomic_actions(),
'keystone.list_tenants')
"keystone.list_tenants")

View File

@ -478,8 +478,8 @@ class NeutronNetworksTestCase(test.TestCase):
ports_per_network = 10
port_update_args = {
'name': '_updated',
'admin_state_up': False
"name": "_updated",
"admin_state_up": False
}
# Defaults

View File

@ -29,8 +29,8 @@ class NeutronScenarioTestCase(test.TestCase):
super(NeutronScenarioTestCase, self).setUp()
self.network = mock.Mock()
@mock.patch(NEUTRON_UTILS + 'NeutronScenario._generate_random_name')
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_create_network(self, mock_clients, mock_random_name):
neutron_scenario = utils.NeutronScenario()
explicit_name = "explicit_name"
@ -46,7 +46,7 @@ class NeutronScenarioTestCase(test.TestCase):
expected_network_data)
self.assertEqual(self.network, network)
self._test_atomic_action_timer(neutron_scenario.atomic_actions(),
'neutron.create_network')
"neutron.create_network")
mock_clients("neutron").create_network.reset_mock()
@ -57,7 +57,7 @@ class NeutronScenarioTestCase(test.TestCase):
mock_clients("neutron").create_network.assert_called_once_with(
expected_network_data)
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_list_networks(self, mock_clients):
scenario = utils.NeutronScenario()
networks_list = []
@ -66,9 +66,9 @@ class NeutronScenarioTestCase(test.TestCase):
return_networks_list = scenario._list_networks()
self.assertEqual(networks_list, return_networks_list)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.list_networks')
"neutron.list_networks")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_update_network(self, mock_clients):
scenario = utils.NeutronScenario()
expected_network = {
@ -87,9 +87,9 @@ class NeutronScenarioTestCase(test.TestCase):
network["network"]["id"], expected_network)
self.assertEqual(result_network, expected_network)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.update_network')
"neutron.update_network")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_delete_network(self, mock_clients):
scenario = utils.NeutronScenario()
@ -97,23 +97,23 @@ class NeutronScenarioTestCase(test.TestCase):
network = scenario._create_network(network_create_args)
scenario._delete_network(network)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.delete_network')
"neutron.delete_network")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario._generate_random_name',
return_value='test_subnet')
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name",
return_value="test_subnet")
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_create_subnet(self, mock_clients, mock_random_name):
scenario = utils.NeutronScenario()
network_id = 'fake-id'
start_cidr = '192.168.0.0/24'
network_id = "fake-id"
start_cidr = "192.168.0.0/24"
network = {'network': {'id': network_id}}
network = {"network": {"id": network_id}}
expected_subnet_data = {
'subnet': {
'network_id': network_id,
'cidr': start_cidr,
'ip_version': scenario.SUBNET_IP_VERSION,
'name': mock_random_name.return_value
"subnet": {
"network_id": network_id,
"cidr": start_cidr,
"ip_version": scenario.SUBNET_IP_VERSION,
"name": mock_random_name.return_value
}
}
@ -128,7 +128,7 @@ class NeutronScenarioTestCase(test.TestCase):
mock_clients("neutron").create_subnet.reset_mock()
# Custom options
extras = {'cidr': '192.168.16.0/24', 'allocation_pools': []}
extras = {"cidr": "192.168.16.0/24", "allocation_pools": []}
subnet_data.update(extras)
expected_subnet_data["subnet"].update(extras)
scenario._create_subnet(network, subnet_data)
@ -147,7 +147,7 @@ class NeutronScenarioTestCase(test.TestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.list_subnets")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_update_subnet(self, mock_clients):
scenario = utils.NeutronScenario()
expected_subnet = {
@ -166,9 +166,9 @@ class NeutronScenarioTestCase(test.TestCase):
subnet["subnet"]["id"], expected_subnet)
self.assertEqual(result_subnet, expected_subnet)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.update_subnet')
"neutron.update_subnet")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_delete_subnet(self, mock_clients):
scenario = utils.NeutronScenario()
@ -177,10 +177,10 @@ class NeutronScenarioTestCase(test.TestCase):
scenario._delete_subnet(subnet)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.delete_subnet')
"neutron.delete_subnet")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario._generate_random_name')
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_create_router(self, mock_clients, mock_random_name):
scenario = utils.NeutronScenario()
router = mock.Mock()
@ -195,7 +195,7 @@ class NeutronScenarioTestCase(test.TestCase):
{"router": {"name": random_name}})
self.assertEqual(result_router, router)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.create_router')
"neutron.create_router")
mock_clients("neutron").create_router.reset_mock()
@ -205,7 +205,7 @@ class NeutronScenarioTestCase(test.TestCase):
mock_clients("neutron").create_router.assert_called_once_with(
{"router": router_data})
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_list_routers(self, mock_clients):
scenario = utils.NeutronScenario()
routers = [mock.Mock()]
@ -213,15 +213,15 @@ class NeutronScenarioTestCase(test.TestCase):
"routers": routers}
self.assertEqual(routers, scenario._list_routers())
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.list_routers')
"neutron.list_routers")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_update_router(self, mock_clients):
scenario = utils.NeutronScenario()
expected_router = {
"router": {
"name": "router-name_updated",
'admin_state_up': False
"admin_state_up": False
}
}
mock_clients("neutron").update_router.return_value = expected_router
@ -230,17 +230,17 @@ class NeutronScenarioTestCase(test.TestCase):
"router": {
"id": "router-id",
"name": "router-name",
'admin_state_up': True
"admin_state_up": True
}
}
router_update_args = {"name": "_updated", "admin_state_up": False}
result_router = scenario._update_router(router, router_update_args)
mock_clients("neutron").update_router.assert_called_once_with(
router['router']['id'], expected_router)
router["router"]["id"], expected_router)
self.assertEqual(result_router, expected_router)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.update_router')
"neutron.update_router")
def test_SUBNET_IP_VERSION(self):
"""Curent NeutronScenario implementation supports only IPv4."""
@ -288,7 +288,7 @@ class NeutronScenarioTestCase(test.TestCase):
self._test_atomic_action_timer(scenario.atomic_actions(),
"neutron.list_ports")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_update_port(self, mock_clients):
scenario = utils.NeutronScenario()
expected_port = {
@ -317,12 +317,12 @@ class NeutronScenarioTestCase(test.TestCase):
result_port = scenario._update_port(port, port_update_args)
mock_clients("neutron").update_port.assert_called_once_with(
port['port']['id'], expected_port)
port["port"]["id"], expected_port)
self.assertEqual(result_port, expected_port)
self._test_atomic_action_timer(scenario.atomic_actions(),
'neutron.update_port')
"neutron.update_port")
@mock.patch(NEUTRON_UTILS + 'NeutronScenario.clients')
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
def test_delete_port(self, mock_clients):
scenario = utils.NeutronScenario()

View File

@ -30,7 +30,7 @@ NOVA_SERVERS = NOVA_SERVERS_MODULE + ".NovaServers"
class NovaServersTestCase(test.TestCase):
def test_boot_rescue_unrescue(self):
actions = [{'rescue_unrescue': 5}]
actions = [{"rescue_unrescue": 5}]
fake_server = mock.MagicMock()
scenario = servers.NovaServers()
scenario._boot_server = mock.MagicMock(return_value=fake_server)
@ -54,7 +54,7 @@ class NovaServersTestCase(test.TestCase):
force=False)
def test_boot_stop_start(self):
actions = [{'stop_start': 5}]
actions = [{"stop_start": 5}]
fake_server = mock.MagicMock()
scenario = servers.NovaServers()
scenario._boot_server = mock.MagicMock(return_value=fake_server)
@ -79,7 +79,7 @@ class NovaServersTestCase(test.TestCase):
force=False)
def test_multiple_bounce_actions(self):
actions = [{'hard_reboot': 5}, {'stop_start': 8}]
actions = [{"hard_reboot": 5}, {"stop_start": 8}]
fake_server = mock.MagicMock()
scenario = servers.NovaServers()
@ -87,7 +87,7 @@ class NovaServersTestCase(test.TestCase):
scenario._delete_server = mock.MagicMock()
scenario._reboot_server = mock.MagicMock()
scenario._stop_and_start_server = mock.MagicMock()
scenario._generate_random_name = mock.MagicMock(return_value='name')
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.boot_and_bounce_server("img", 1, actions=actions)
scenario._boot_server.assert_called_once_with("name", "img", 1)
@ -131,7 +131,7 @@ class NovaServersTestCase(test.TestCase):
1, 1, actions=actions)
def _verify_reboot(self, soft=True):
actions = [{'soft_reboot' if soft else 'hard_reboot': 5}]
actions = [{"soft_reboot" if soft else "hard_reboot": 5}]
fake_server = mock.MagicMock()
scenario = servers.NovaServers()
@ -139,7 +139,7 @@ class NovaServersTestCase(test.TestCase):
scenario._soft_reboot_server = mock.MagicMock()
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._delete_server = mock.MagicMock()
scenario._generate_random_name = mock.MagicMock(return_value='name')
scenario._generate_random_name = mock.MagicMock(return_value="name")
scenario.boot_and_bounce_server("img", 1, actions=actions)
@ -217,7 +217,7 @@ class NovaServersTestCase(test.TestCase):
scenario._create_volume.assert_called_once_with(5, imageRef="img")
scenario._boot_server.assert_called_once_with(
"name", "img", 0,
block_device_mapping={'vda': 'volume_id:::1'},
block_device_mapping={"vda": "volume_id:::1"},
fakearg="f")
scenario.sleep_between.assert_called_once_with(10, 20)
scenario._delete_server.assert_called_once_with(fake_server,
@ -238,15 +238,15 @@ class NovaServersTestCase(test.TestCase):
scenario._boot_server = mock.MagicMock(return_value=fake_server)
scenario._generate_random_name = mock.MagicMock(return_value="name")
kwargs = {'fakearg': 'f'}
expected_kwargs = {'fakearg': 'f'}
kwargs = {"fakearg": "f"}
expected_kwargs = {"fakearg": "f"}
assert_nic = nic or assert_nic
if nic:
kwargs['nics'] = nic
kwargs["nics"] = nic
if assert_nic:
nova.networks.create('net-1')
expected_kwargs['nics'] = nic or [{'net-id': 'net-2'}]
nova.networks.create("net-1")
expected_kwargs["nics"] = nic or [{"net-id": "net-2"}]
print(kwargs)
print(expected_kwargs)
@ -272,7 +272,7 @@ class NovaServersTestCase(test.TestCase):
@mock.patch("rally.benchmark.runners.base.osclients")
def test_boot_server_with_nic(self, mock_osclients):
self._verify_boot_server(mock_osclients=mock_osclients,
nic=[{'net-id': 'net-1'}], assert_nic=True)
nic=[{"net-id": "net-1"}], assert_nic=True)
def test_snapshot_server(self):
fake_server = object()
@ -312,7 +312,7 @@ class NovaServersTestCase(test.TestCase):
scenario._resize = mock.MagicMock()
scenario._delete_server = mock.MagicMock()
kwargs = {'confirm': confirm}
kwargs = {"confirm": confirm}
scenario.resize_server(fake_image, flavor, to_flavor, **kwargs)
scenario._resize.assert_called_once_with(fake_server, to_flavor)

View File

@ -24,7 +24,7 @@ from tests.unit import fakes
from tests.unit import test
BM_UTILS = 'rally.benchmark.utils'
BM_UTILS = "rally.benchmark.utils"
NOVA_UTILS = "rally.benchmark.scenarios.nova.utils"
CONF = cfg.CONF
@ -39,7 +39,7 @@ class NovaScenarioTestCase(test.TestCase):
self.floating_ip = mock.Mock()
self.image = mock.Mock()
self.res_is = mockpatch.Patch(BM_UTILS + ".resource_is")
self.get_fm = mockpatch.Patch(BM_UTILS + '.get_from_manager')
self.get_fm = mockpatch.Patch(BM_UTILS + ".get_from_manager")
self.wait_for = mockpatch.Patch(NOVA_UTILS + ".bench_utils.wait_for")
self.wait_for_delete = mockpatch.Patch(NOVA_UTILS +
".bench_utils.wait_for_delete")
@ -48,14 +48,14 @@ class NovaScenarioTestCase(test.TestCase):
self.useFixture(self.res_is)
self.useFixture(self.get_fm)
self.gfm = self.get_fm.mock
self.useFixture(mockpatch.Patch('time.sleep'))
self.useFixture(mockpatch.Patch("time.sleep"))
def test_failed_server_status(self):
self.get_fm.cleanUp()
server_manager = fakes.FakeFailedServerManager()
self.assertRaises(rally_exceptions.GetResourceFailure,
butils.get_from_manager(),
server_manager.create('fails', '1', '2'))
server_manager.create("fails", "1", "2"))
def _test_assert_called_once_with(self, mock, resource,
chk_interval, time_out, **kwargs):
@ -71,7 +71,7 @@ class NovaScenarioTestCase(test.TestCase):
isready = self.res_is.mock()
if kwargs:
if kwargs['is_ready']:
if kwargs["is_ready"]:
mock.assert_called_once_with(
resource,
update_resource=self.gfm(),
@ -85,7 +85,7 @@ class NovaScenarioTestCase(test.TestCase):
check_interval=chk_interval,
timeout=time_out)
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__list_servers(self, mock_clients):
servers_list = []
mock_clients("nova").servers.list.return_value = servers_list
@ -93,22 +93,22 @@ class NovaScenarioTestCase(test.TestCase):
return_servers_list = nova_scenario._list_servers(True)
self.assertEqual(servers_list, return_servers_list)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.list_servers')
"nova.list_servers")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__boot_server(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={})
return_server = nova_scenario._boot_server('server_name', 'image_id',
'flavor_id')
return_server = nova_scenario._boot_server("server_name", "image_id",
"flavor_id")
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval,
CONF.benchmark.nova_server_boot_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self.assertEqual(self.wait_for.mock(), return_server)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.boot_server')
"nova.boot_server")
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__boot_server_with_network(self, mock_clients):
@ -141,52 +141,52 @@ class NovaScenarioTestCase(test.TestCase):
"server_name", "image_id", "flavor_id",
auto_assign_nic=True)
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__boot_server_with_ssh(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={"allow_ssh": "test"})
return_server = nova_scenario._boot_server('server_name', 'image_id',
'flavor_id')
return_server = nova_scenario._boot_server("server_name", "image_id",
"flavor_id")
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval,
CONF.benchmark.nova_server_boot_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self.assertEqual(self.wait_for.mock(), return_server)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.boot_server')
"nova.boot_server")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__boot_server_with_sec_group(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={"allow_ssh": "new"})
return_server = nova_scenario._boot_server(
'server_name', 'image_id', 'flavor_id',
security_groups=['test1'])
"server_name", "image_id", "flavor_id",
security_groups=["test1"])
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval,
CONF.benchmark.nova_server_boot_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self.assertEqual(self.wait_for.mock(), return_server)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.boot_server')
"nova.boot_server")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__boot_server_with_similar_sec_group(self, mock_clients):
mock_clients("nova").servers.create.return_value = self.server
nova_scenario = utils.NovaScenario(context={"allow_ssh": "test1"})
return_server = nova_scenario._boot_server(
'server_name', 'image_id', 'flavor_id',
security_groups=['test1'])
"server_name", "image_id", "flavor_id",
security_groups=["test1"])
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_boot_poll_interval,
CONF.benchmark.nova_server_boot_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self.assertEqual(self.wait_for.mock(), return_server)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.boot_server')
"nova.boot_server")
def test__suspend_server(self):
nova_scenario = utils.NovaScenario()
@ -196,11 +196,11 @@ class NovaScenarioTestCase(test.TestCase):
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_suspend_poll_interval,
CONF.benchmark.nova_server_suspend_timeout)
self.res_is.mock.assert_has_calls([mock.call('SUSPENDED')])
self.res_is.mock.assert_has_calls([mock.call("SUSPENDED")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.suspend_server')
"nova.suspend_server")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__create_image(self, mock_clients):
mock_clients("nova").images.get.return_value = self.image
nova_scenario = utils.NovaScenario()
@ -209,10 +209,10 @@ class NovaScenarioTestCase(test.TestCase):
self.wait_for.mock, self.image,
CONF.benchmark.nova_server_image_create_poll_interval,
CONF.benchmark.nova_server_image_create_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self.assertEqual(self.wait_for.mock(), return_image)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.create_image')
"nova.create_image")
def test__default_delete_server(self):
nova_scenario = utils.NovaScenario()
@ -224,7 +224,7 @@ class NovaScenarioTestCase(test.TestCase):
CONF.benchmark.nova_server_delete_timeout,
is_ready=None)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.delete_server')
"nova.delete_server")
def test__force_delete_server(self):
nova_scenario = utils.NovaScenario()
@ -236,31 +236,31 @@ class NovaScenarioTestCase(test.TestCase):
CONF.benchmark.nova_server_delete_timeout,
is_ready=None)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.force_delete_server')
"nova.force_delete_server")
def test__reboot_server(self):
nova_scenario = utils.NovaScenario()
nova_scenario._reboot_server(self.server)
self.server.reboot.assert_called_once_with(reboot_type='HARD')
self.server.reboot.assert_called_once_with(reboot_type="HARD")
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_reboot_poll_interval,
CONF.benchmark.nova_server_reboot_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.reboot_server')
"nova.reboot_server")
def test__soft_reboot_server(self):
nova_scenario = utils.NovaScenario()
nova_scenario._soft_reboot_server(self.server)
self.server.reboot.assert_called_once_with(reboot_type='SOFT')
self.server.reboot.assert_called_once_with(reboot_type="SOFT")
self._test_assert_called_once_with(
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_reboot_poll_interval,
CONF.benchmark.nova_server_reboot_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.soft_reboot_server')
"nova.soft_reboot_server")
def test__start_server(self):
nova_scenario = utils.NovaScenario()
@ -270,9 +270,9 @@ class NovaScenarioTestCase(test.TestCase):
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_start_poll_interval,
CONF.benchmark.nova_server_start_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.start_server')
"nova.start_server")
def test__stop_server(self):
nova_scenario = utils.NovaScenario()
@ -282,9 +282,9 @@ class NovaScenarioTestCase(test.TestCase):
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_stop_poll_interval,
CONF.benchmark.nova_server_stop_timeout)
self.res_is.mock.assert_has_calls([mock.call('SHUTOFF')])
self.res_is.mock.assert_has_calls([mock.call("SHUTOFF")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.stop_server')
"nova.stop_server")
def test__rescue_server(self):
nova_scenario = utils.NovaScenario()
@ -294,9 +294,9 @@ class NovaScenarioTestCase(test.TestCase):
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_rescue_poll_interval,
CONF.benchmark.nova_server_rescue_timeout)
self.res_is.mock.assert_has_calls([mock.call('RESCUE')])
self.res_is.mock.assert_has_calls([mock.call("RESCUE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.rescue_server')
"nova.rescue_server")
def test__unrescue_server(self):
nova_scenario = utils.NovaScenario()
@ -306,11 +306,11 @@ class NovaScenarioTestCase(test.TestCase):
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_unrescue_poll_interval,
CONF.benchmark.nova_server_unrescue_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.unrescue_server')
"nova.unrescue_server")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__default_delete_all_servers(self, mock_clients):
mock_clients("nova").servers.list.return_value = [self.server,
self.server1]
@ -331,9 +331,9 @@ class NovaScenarioTestCase(test.TestCase):
]
self.assertEqual(expected, self.wait_for_delete.mock.mock_calls)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.delete_all_servers')
"nova.delete_all_servers")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__force_delete_all_servers(self, mock_clients):
mock_clients("nova").servers.list.return_value = [self.server,
self.server1]
@ -354,7 +354,7 @@ class NovaScenarioTestCase(test.TestCase):
]
self.assertEqual(expected, self.wait_for_delete.mock.mock_calls)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.force_delete_all_servers')
"nova.force_delete_all_servers")
def test__delete_image(self):
nova_scenario = utils.NovaScenario()
@ -366,14 +366,14 @@ class NovaScenarioTestCase(test.TestCase):
CONF.benchmark.nova_server_image_delete_timeout,
is_ready=None)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.delete_image')
"nova.delete_image")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__boot_servers(self, mock_clients):
mock_clients("nova").servers.list.return_value = [self.server,
self.server1]
nova_scenario = utils.NovaScenario()
nova_scenario._boot_servers('prefix', 'image', 'flavor', 2)
nova_scenario._boot_servers("prefix", "image", "flavor", 2)
expected = [
mock.call(
self.server, is_ready=self.res_is.mock(),
@ -389,11 +389,11 @@ class NovaScenarioTestCase(test.TestCase):
)
]
self.assertEqual(expected, self.wait_for.mock.mock_calls)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.boot_servers')
"nova.boot_servers")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__list_floating_ip_pools(self, mock_clients):
pools_list = []
mock_clients("nova").floating_ip_pools.list.return_value = pools_list
@ -401,9 +401,9 @@ class NovaScenarioTestCase(test.TestCase):
return_pools_list = nova_scenario._list_floating_ip_pools()
self.assertEqual(pools_list, return_pools_list)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.list_floating_ip_pools')
"nova.list_floating_ip_pools")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__list_floating_ips(self, mock_clients):
floating_ips_list = []
mock_clients("nova").floating_ips.list.return_value = floating_ips_list
@ -411,9 +411,9 @@ class NovaScenarioTestCase(test.TestCase):
return_floating_ips_list = nova_scenario._list_floating_ips()
self.assertEqual(floating_ips_list, return_floating_ips_list)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.list_floating_ips')
"nova.list_floating_ips")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__create_floating_ip(self, mock_clients):
(mock_clients("nova").floating_ips.create.
return_value) = self.floating_ip
@ -421,16 +421,16 @@ class NovaScenarioTestCase(test.TestCase):
return_floating_ip = nova_scenario._create_floating_ip("public")
self.assertEqual(self.floating_ip, return_floating_ip)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.create_floating_ip')
"nova.create_floating_ip")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__delete_floating_ip(self, mock_clients):
nova_scenario = utils.NovaScenario()
nova_scenario._delete_floating_ip(self.floating_ip)
mock_clients("nova").floating_ips.delete.assert_called_once_with(
self.floating_ip)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.delete_floating_ip')
"nova.delete_floating_ip")
def test__associate_floating_ip(self):
nova_scenario = utils.NovaScenario()
@ -438,7 +438,7 @@ class NovaScenarioTestCase(test.TestCase):
self.server.add_floating_ip.assert_called_once_with(self.floating_ip,
fixed_address=None)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.associate_floating_ip')
"nova.associate_floating_ip")
def test__dissociate_floating_ip(self):
nova_scenario = utils.NovaScenario()
@ -446,7 +446,7 @@ class NovaScenarioTestCase(test.TestCase):
self.server.remove_floating_ip.assert_called_once_with(
self.floating_ip)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.dissociate_floating_ip')
"nova.dissociate_floating_ip")
def test__check_ip_address(self):
nova_scenario = utils.NovaScenario()
@ -478,7 +478,7 @@ class NovaScenarioTestCase(test.TestCase):
nova_scenario.check_ip_address(floating_ip, must_exist=False)
(fake_server))
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__list_networks(self, mock_clients):
network_list = []
mock_clients("nova").networks.list.return_value = network_list
@ -486,44 +486,44 @@ class NovaScenarioTestCase(test.TestCase):
return_network_list = nova_scenario._list_networks()
self.assertEqual(network_list, return_network_list)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.list_networks')
"nova.list_networks")
def test__resize(self):
nova_scenario = utils.NovaScenario()
to_flavor = mock.Mock()
nova_scenario._resize(self.server, to_flavor)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.resize')
"nova.resize")
def test__resize_confirm(self):
nova_scenario = utils.NovaScenario()
nova_scenario._resize_confirm(self.server)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.resize_confirm')
"nova.resize_confirm")
def test__resize_revert(self):
nova_scenario = utils.NovaScenario()
nova_scenario._resize_revert(self.server)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.resize_revert')
"nova.resize_revert")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__attach_volume(self, mock_clients):
mock_clients("nova").volumes.create_server_volume.return_value = None
nova_scenario = utils.NovaScenario()
nova_scenario._attach_volume(self.server, self.volume)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.attach_volume')
"nova.attach_volume")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__detach_volume(self, mock_clients):
mock_clients("nova").volumes.delete_server_volume.return_value = None
nova_scenario = utils.NovaScenario()
nova_scenario._detach_volume(self.server, self.volume)
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.detach_volume')
"nova.detach_volume")
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__live_migrate_server(self, mock_clients):
fake_host = mock.MagicMock()
mock_clients("nova").servers.get(return_value=self.server)
@ -538,11 +538,11 @@ class NovaScenarioTestCase(test.TestCase):
self.wait_for.mock, self.server,
CONF.benchmark.nova_server_live_migrate_poll_interval,
CONF.benchmark.nova_server_live_migrate_timeout)
self.res_is.mock.assert_has_calls([mock.call('ACTIVE')])
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
'nova.live_migrate')
"nova.live_migrate")
@mock.patch(NOVA_UTILS + '.NovaScenario.admin_clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.admin_clients")
def test__find_host_to_migrate(self, mock_clients):
fake_server = self.server
fake_host = {"nova-compute": {"available": True}}
@ -567,7 +567,7 @@ class NovaScenarioTestCase(test.TestCase):
self.assertIn(
nova_scenario._find_host_to_migrate(fake_server), ["b1", "b3"])
@mock.patch(NOVA_UTILS + '.NovaScenario.clients')
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
def test__migrate_server(self, mock_clients):
fake_server = self.server
setattr(fake_server, "OS-EXT-SRV-ATTR:host", "a1")
@ -606,7 +606,7 @@ class NovaScenarioTestCase(test.TestCase):
clients().security_groups.create.call_count)
self._test_atomic_action_timer(
nova_scenario.atomic_actions(),
'nova.create_%s_security_groups' % security_group_count)
"nova.create_%s_security_groups" % security_group_count)
def test__create_rules_for_security_group(self):
clients = mock.MagicMock()
@ -646,7 +646,7 @@ class NovaScenarioTestCase(test.TestCase):
clients().security_groups.delete.call_args_list)
self._test_atomic_action_timer(
nova_scenario.atomic_actions(),
'nova.delete_%s_security_groups' % len(fake_secgroups))
"nova.delete_%s_security_groups" % len(fake_secgroups))
def test__list_security_groups(self):
clients = mock.MagicMock()

View File

@ -25,26 +25,26 @@ class QuotasTestCase(test.TestCase):
scenario = quotas.Quotas(context={"user": {"tenant_id": "fake"}})
scenario._update_quotas = mock.MagicMock()
scenario.nova_update(max_quota=1024)
scenario._update_quotas.assert_called_once_with('nova', 'fake', 1024)
scenario._update_quotas.assert_called_once_with("nova", "fake", 1024)
def test_nova_update_and_delete(self):
scenario = quotas.Quotas(context={"user": {"tenant_id": "fake"}})
scenario._update_quotas = mock.MagicMock()
scenario._delete_quotas = mock.MagicMock()
scenario.nova_update_and_delete(max_quota=1024)
scenario._update_quotas.assert_called_once_with('nova', 'fake', 1024)
scenario._delete_quotas.assert_called_once_with('nova', 'fake')
scenario._update_quotas.assert_called_once_with("nova", "fake", 1024)
scenario._delete_quotas.assert_called_once_with("nova", "fake")
def test_cinder_update(self):
scenario = quotas.Quotas(context={"user": {"tenant_id": "fake"}})
scenario._update_quotas = mock.MagicMock()
scenario.cinder_update(max_quota=1024)
scenario._update_quotas.assert_called_once_with('cinder', 'fake', 1024)
scenario._update_quotas.assert_called_once_with("cinder", "fake", 1024)
def test_cinder_update_and_delete(self):
scenario = quotas.Quotas(context={"user": {"tenant_id": "fake"}})
scenario._update_quotas = mock.MagicMock()
scenario._delete_quotas = mock.MagicMock()
scenario.cinder_update_and_delete(max_quota=1024)
scenario._update_quotas.assert_called_once_with('cinder', 'fake', 1024)
scenario._delete_quotas.assert_called_once_with('cinder', 'fake')
scenario._update_quotas.assert_called_once_with("cinder", "fake", 1024)
scenario._delete_quotas.assert_called_once_with("cinder", "fake")

View File

@ -27,16 +27,16 @@ class QuotasScenarioTestCase(test.TestCase):
super(QuotasScenarioTestCase, self).setUp()
def test__update_quotas(self):
tenant_id = 'fake_tenant'
tenant_id = "fake_tenant"
quotas = {
'metadata_items': 10,
'key_pairs': 10,
'injected_file_content_bytes': 1024,
'injected_file_path_bytes': 1024,
'ram': 5120,
'instances': 10,
'injected_files': 10,
'cores': 10,
"metadata_items": 10,
"key_pairs": 10,
"injected_file_content_bytes": 1024,
"injected_file_path_bytes": 1024,
"ram": 5120,
"instances": 10,
"injected_files": 10,
"cores": 10,
}
fake_nova = fakes.FakeNovaClient()
fake_nova.quotas.update = mock.MagicMock(return_value=quotas)
@ -45,12 +45,12 @@ class QuotasScenarioTestCase(test.TestCase):
scenario = utils.QuotasScenario(admin_clients=fake_clients)
scenario._generate_quota_values = mock.MagicMock(return_value=quotas)
result = scenario._update_quotas('nova', tenant_id)
result = scenario._update_quotas("nova", tenant_id)
self.assertEqual(quotas, result)
fake_nova.quotas.update.assert_called_once_with(tenant_id, **quotas)
self._test_atomic_action_timer(scenario.atomic_actions(),
'quotas.update_quotas')
"quotas.update_quotas")
def test__generate_quota_values_nova(self):
max_quota = 1024
@ -67,15 +67,15 @@ class QuotasScenarioTestCase(test.TestCase):
self.assertTrue(-1 <= v <= max_quota)
def test__delete_quotas(self):
tenant_id = 'fake_tenant'
tenant_id = "fake_tenant"
fake_nova = fakes.FakeNovaClient()
fake_nova.quotas.delete = mock.MagicMock()
fake_clients = fakes.FakeClients()
fake_clients._nova = fake_nova
scenario = utils.QuotasScenario(admin_clients=fake_clients)
scenario._delete_quotas('nova', tenant_id)
scenario._delete_quotas("nova", tenant_id)
fake_nova.quotas.delete.assert_called_once_with(tenant_id)
self._test_atomic_action_timer(scenario.atomic_actions(),
'quotas.delete_quotas')
"quotas.delete_quotas")

View File

@ -19,7 +19,7 @@ from rally.benchmark.scenarios.sahara import clusters
from tests.unit import test
SAHARA_CLUSTERS = "rally.benchmark.scenarios.sahara.clusters.SaharaClusters"
SAHARA_UTILS = 'rally.benchmark.scenarios.sahara.utils'
SAHARA_UTILS = "rally.benchmark.scenarios.sahara.utils"
class SaharaClustersTestCase(test.TestCase):
@ -27,7 +27,7 @@ class SaharaClustersTestCase(test.TestCase):
@mock.patch(SAHARA_CLUSTERS + "._delete_cluster")
@mock.patch(SAHARA_CLUSTERS + "._launch_cluster",
return_value=mock.MagicMock(id=42))
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_and_delete_cluster(self, mock_clients, mock_launch_cluster,
mock_delete_cluster):
@ -65,7 +65,7 @@ class SaharaClustersTestCase(test.TestCase):
@mock.patch(SAHARA_CLUSTERS + "._scale_cluster")
@mock.patch(SAHARA_CLUSTERS + "._launch_cluster",
return_value=mock.MagicMock(id=42))
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_scale_delete_cluster(self, mock_clients,
mock_launch_cluster,
mock_scale_cluster,

View File

@ -25,7 +25,7 @@ from tests.unit import test
CONF = cfg.CONF
SAHARA_UTILS = 'rally.benchmark.scenarios.sahara.utils'
SAHARA_UTILS = "rally.benchmark.scenarios.sahara.utils"
class SaharaUtilsTestCase(test.TestCase):
@ -36,7 +36,7 @@ class SaharaUtilsTestCase(test.TestCase):
CONF.set_override("cluster_check_interval", 0, "benchmark")
CONF.set_override("job_check_interval", 0, "benchmark")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_list_node_group_templates(self, mock_clients):
ngts = []
mock_clients("sahara").node_group_templates.list.return_value = ngts
@ -46,11 +46,11 @@ class SaharaUtilsTestCase(test.TestCase):
self.assertEqual(ngts, return_ngts_list)
self._test_atomic_action_timer(scenario.atomic_actions(),
'sahara.list_node_group_templates')
"sahara.list_node_group_templates")
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="random_name")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_node_group_templates(self, mock_clients, mock_random_name):
scenario = utils.SaharaScenario()
@ -95,12 +95,12 @@ class SaharaUtilsTestCase(test.TestCase):
self._test_atomic_action_timer(
scenario.atomic_actions(),
'sahara.create_master_node_group_template')
"sahara.create_master_node_group_template")
self._test_atomic_action_timer(
scenario.atomic_actions(),
'sahara.create_worker_node_group_template')
"sahara.create_worker_node_group_template")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_delete_node_group_templates(self, mock_clients):
scenario = utils.SaharaScenario()
@ -112,11 +112,11 @@ class SaharaUtilsTestCase(test.TestCase):
delete_mock.assert_called_once_with(42)
self._test_atomic_action_timer(scenario.atomic_actions(),
'sahara.delete_node_group_template')
"sahara.delete_node_group_template")
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="random_name")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_launch_cluster(self, mock_clients, mock_random_name):
clients_values = mock.MagicMock(return_value=[consts.Service.NEUTRON])
@ -215,11 +215,11 @@ class SaharaUtilsTestCase(test.TestCase):
)
self._test_atomic_action_timer(scenario.atomic_actions(),
'sahara.launch_cluster')
"sahara.launch_cluster")
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="random_name")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_launch_cluster_error(self, mock_clients, mock_random_name):
scenario = utils.SaharaScenario(clients=mock.MagicMock())
@ -263,7 +263,7 @@ class SaharaUtilsTestCase(test.TestCase):
node_configs={"HDFS": {"local_config":
"local_value"}})
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_scale_cluster(self, mock_clients):
scenario = utils.SaharaScenario()
@ -289,7 +289,7 @@ class SaharaUtilsTestCase(test.TestCase):
mock_clients("sahara").clusters.scale.assert_called_once_with(
42, expected_scale_object)
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_delete_cluster(self, mock_clients):
scenario = utils.SaharaScenario()
@ -308,11 +308,11 @@ class SaharaUtilsTestCase(test.TestCase):
cl_get_expected])
self._test_atomic_action_timer(scenario.atomic_actions(),
'sahara.delete_cluster')
"sahara.delete_cluster")
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="42")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_output_ds(self, mock_clients, mock_random_name):
ctxt = {
@ -332,9 +332,9 @@ class SaharaUtilsTestCase(test.TestCase):
url="hdfs://test_out/42"
)
@mock.patch(SAHARA_UTILS + '.SaharaScenario._generate_random_name',
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
return_value="42")
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_create_output_ds_swift(self, mock_clients, mock_random_name):
ctxt = {
@ -348,7 +348,7 @@ class SaharaUtilsTestCase(test.TestCase):
self.assertRaises(exceptions.RallyException,
scenario._create_output_ds)
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_run_job_execution(self, mock_clients):
mock_clients("sahara").job_executions.get.side_effect = [
@ -379,7 +379,7 @@ class SaharaUtilsTestCase(test.TestCase):
[je_get_expected, je_get_expected]
)
@mock.patch(SAHARA_UTILS + '.SaharaScenario.clients')
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
def test_run_job_execution_fail(self, mock_clients):
mock_clients("sahara").job_executions.get.side_effect = [

View File

@ -52,7 +52,7 @@ class TempestLogWrappersTestCase(test.TestCase):
target_func.__name__ = "target_func"
func = utils.tempest_log_wrapper(target_func)
func(self.scenario, log_file='log_file')
func(self.scenario, log_file="log_file")
target_func.assert_called_once_with(self.scenario,
log_file="log_file")

View File

@ -95,7 +95,7 @@ class ScenarioTestCase(test.TestCase):
args = {"a": 1, "b": 2}
self.assertRaises(exceptions.InvalidScenarioArgument,
base.Scenario._validate_helper,
validators, clients, args, 'fake_uuid')
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):
@ -164,7 +164,7 @@ class ScenarioTestCase(test.TestCase):
class MyFakeScenario(fakes.FakeScenario):
pass
attr_name = 'preprocessors'
attr_name = "preprocessors"
preprocessors = [mock.MagicMock(), mock.MagicMock()]
MyFakeScenario.do_it.__dict__[attr_name] = preprocessors
@ -177,7 +177,7 @@ class ScenarioTestCase(test.TestCase):
class MyFakeScenario(fakes.FakeScenario):
pass
attr_name = 'preprocessors'
attr_name = "preprocessors"
preprocessors = [mock.MagicMock(), mock.MagicMock()]
MyFakeScenario.do_it.__dict__[attr_name] = preprocessors
@ -339,16 +339,16 @@ class ScenarioTestCase(test.TestCase):
class AtomicActionTestCase(test.TestCase):
def test__init__(self):
fake_scenario_instance = fakes.FakeScenario()
c = base.AtomicAction(fake_scenario_instance, 'asdf')
c = base.AtomicAction(fake_scenario_instance, "asdf")
self.assertEqual(c.scenario_instance, fake_scenario_instance)
self.assertEqual(c.name, 'asdf')
self.assertEqual(c.name, "asdf")
@mock.patch('tests.unit.fakes.FakeScenario._add_atomic_actions')
@mock.patch('rally.common.utils.time')
@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):
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__add_atomic_actions.assert_called_once_with("asdf", duration)

View File

@ -35,88 +35,88 @@ class ActionBuilderTestCase(test.TestCase):
self.mock_two = "%s.action_two" % __name__
def test_invalid_keyword(self):
builder = utils.ActionBuilder(['action_one', 'action_two'])
builder = utils.ActionBuilder(["action_one", "action_two"])
self.assertRaises(schema_exceptions.ValidationError,
builder.build_actions, [{'missing': 1}])
builder.build_actions, [{"missing": 1}])
def test_invalid_bind(self):
builder = utils.ActionBuilder(['action_one'])
builder = utils.ActionBuilder(["action_one"])
self.assertRaises(schema_exceptions.ValidationError,
builder.bind_action, 'missing', action_one)
builder.bind_action, "missing", action_one)
def test_invalid_schema(self):
builder = utils.ActionBuilder(['action_one', 'action_two'])
builder = utils.ActionBuilder(["action_one", "action_two"])
self.assertRaises(schema_exceptions.ValidationError,
builder.validate, [{'action_oone': 1},
{'action_twoo': 2}])
builder.validate, [{"action_oone": 1},
{"action_twoo": 2}])
self.assertRaises(schema_exceptions.ValidationError,
builder.validate, [{'action_one': -1},
{'action_two': 2}])
builder.validate, [{"action_one": -1},
{"action_two": 2}])
self.assertRaises(schema_exceptions.ValidationError,
builder.validate, [{'action_one': 0},
{'action_two': 2}])
builder.validate, [{"action_one": 0},
{"action_two": 2}])
self.assertRaises(schema_exceptions.ValidationError,
builder.validate, [{1: 0},
{'action_two': 2}])
{"action_two": 2}])
self.assertRaises(schema_exceptions.ValidationError,
builder.validate, [{'action_two': 'action_two'}])
builder.validate, [{"action_two": "action_two"}])
def test_positional_args(self):
with mock.patch(self.mock_one) as mock_action_one:
with mock.patch(self.mock_two) as mock_action_two:
builder = utils.ActionBuilder(['action_one', 'action_two'])
builder.bind_action('action_one', mock_action_one, 'a', 'b')
builder.bind_action('action_two', mock_action_two, 'c')
actions = builder.build_actions([{'action_two': 3},
{'action_one': 4}])
builder = utils.ActionBuilder(["action_one", "action_two"])
builder.bind_action("action_one", mock_action_one, "a", "b")
builder.bind_action("action_two", mock_action_two, "c")
actions = builder.build_actions([{"action_two": 3},
{"action_one": 4}])
for action in actions:
action()
self.assertEqual(4, mock_action_one.call_count,
"action one not called 4 times")
mock_calls = []
for i in range(4):
mock_calls.append(mock.call('a', 'b'))
mock_calls.append(mock.call("a", "b"))
mock_action_one.assert_has_calls(mock_calls)
self.assertEqual(3, mock_action_two.call_count,
"action two not called 3 times")
mock_calls = []
for i in range(3):
mock_calls.append(mock.call('c'))
mock_calls.append(mock.call("c"))
mock_action_two.assert_has_calls(mock_calls)
with mock.patch(self.mock_one) as mock_action_one:
with mock.patch(self.mock_two) as mock_action_two:
builder = utils.ActionBuilder(['action_one', 'action_two'])
builder.bind_action('action_one', mock_action_one, 'a', 'b')
builder.bind_action('action_two', mock_action_two, 'c')
actions = builder.build_actions([{'action_two': 3},
{'action_one': 4}],
'd', 5)
builder = utils.ActionBuilder(["action_one", "action_two"])
builder.bind_action("action_one", mock_action_one, "a", "b")
builder.bind_action("action_two", mock_action_two, "c")
actions = builder.build_actions([{"action_two": 3},
{"action_one": 4}],
"d", 5)
for action in actions:
action()
self.assertEqual(4, mock_action_one.call_count,
"action one not called 4 times")
mock_calls = []
for i in range(4):
mock_calls.append(mock.call('a', 'b', 'd', 5))
mock_calls.append(mock.call("a", "b", "d", 5))
mock_action_one.assert_has_calls(mock_calls)
self.assertEqual(3, mock_action_two.call_count,
"action two not called 3 times")
mock_calls = []
for i in range(3):
mock_calls.append(mock.call('c', 'd', 5))
mock_calls.append(mock.call("c", "d", 5))
mock_action_two.assert_has_calls(mock_calls)
def test_kwargs(self):
with mock.patch(self.mock_one) as mock_action_one:
with mock.patch(self.mock_two) as mock_action_two:
builder = utils.ActionBuilder(['action_one', 'action_two'])
builder.bind_action('action_one', mock_action_one, a=1, b=2)
builder.bind_action('action_two', mock_action_two, c=3)
actions = builder.build_actions([{'action_two': 3},
{'action_one': 4}])
builder = utils.ActionBuilder(["action_one", "action_two"])
builder.bind_action("action_one", mock_action_one, a=1, b=2)
builder.bind_action("action_two", mock_action_two, c=3)
actions = builder.build_actions([{"action_two": 3},
{"action_one": 4}])
for action in actions:
action()
self.assertEqual(4, mock_action_one.call_count,
@ -135,11 +135,11 @@ class ActionBuilderTestCase(test.TestCase):
with mock.patch(self.mock_one) as mock_action_one:
with mock.patch(self.mock_two) as mock_action_two:
builder = utils.ActionBuilder(['action_one', 'action_two'])
builder.bind_action('action_one', mock_action_one, a=1, b=2)
builder.bind_action('action_two', mock_action_two, c=3)
actions = builder.build_actions([{'action_two': 3},
{'action_one': 4}],
builder = utils.ActionBuilder(["action_one", "action_two"])
builder.bind_action("action_one", mock_action_one, a=1, b=2)
builder.bind_action("action_two", mock_action_two, c=3)
actions = builder.build_actions([{"action_two": 3},
{"action_one": 4}],
d=4, e=5)
for action in actions:
action()
@ -160,25 +160,25 @@ class ActionBuilderTestCase(test.TestCase):
def test_mixed_args(self):
with mock.patch(self.mock_one) as mock_action_one:
with mock.patch(self.mock_two) as mock_action_two:
builder = utils.ActionBuilder(['action_one', 'action_two'])
builder.bind_action('action_one', mock_action_one, 'one',
builder = utils.ActionBuilder(["action_one", "action_two"])
builder.bind_action("action_one", mock_action_one, "one",
a=1, b=2)
builder.bind_action('action_two', mock_action_two, 'two', c=3)
actions = builder.build_actions([{'action_two': 3},
{'action_one': 4}],
'three', d=4)
builder.bind_action("action_two", mock_action_two, "two", c=3)
actions = builder.build_actions([{"action_two": 3},
{"action_one": 4}],
"three", d=4)
for action in actions:
action()
self.assertEqual(4, mock_action_one.call_count,
"action one not called 4 times")
mock_calls = []
for i in range(4):
mock_calls.append(mock.call('one', 'three', a=1, b=2, d=4))
mock_calls.append(mock.call("one", "three", a=1, b=2, d=4))
mock_action_one.assert_has_calls(mock_calls)
self.assertEqual(3, mock_action_two.call_count,
"action two not called 3 times")
mock_calls = []
for i in range(3):
mock_calls.append(mock.call('two', 'three', c=3, d=4))
mock_calls.append(mock.call("two", "three", c=3, d=4))
mock_action_two.assert_has_calls(mock_calls)

View File

@ -39,8 +39,8 @@ class VMScenarioTestCase(test.TestCase):
def test_run_action(self, mock_open):
mock_ssh = mock.MagicMock()
vm_scenario = utils.VMScenario()
vm_scenario.run_action(mock_ssh, 'interpreter', 'script')
mock_ssh.execute.assert_called_once_with('interpreter',
vm_scenario.run_action(mock_ssh, "interpreter", "script")
mock_ssh.execute.assert_called_once_with("interpreter",
stdin=mock_open.side_effect())
def test_wait_for_ssh(self):
@ -69,12 +69,12 @@ class VMScenarioTestCase(test.TestCase):
vm_scenario = utils.VMScenario()
vm_scenario.context = {"user": {"keypair": {"private": "ssh"}}}
vm_scenario.run_command("1.2.3.4", 22, "username",
'password', "int", "script")
"password", "int", "script")
mock_wait_ping.assert_called_once_with("1.2.3.4")
mock_ssh_class.assert_called_once_with("username", "1.2.3.4", port=22,
pkey="ssh",
password='password')
password="password")
mock_ssh_instance.wait.assert_called_once_with()
mock_run_action.assert_called_once_with(mock_ssh_instance,
"int", "script")
@ -85,14 +85,14 @@ class VMScenarioTestCase(test.TestCase):
ping_process = mock.MagicMock()
ping_process.returncode = 0
mock_subprocess.return_value = ping_process
mock_sys.platform = 'linux2'
mock_sys.platform = "linux2"
vm_scenario = utils.VMScenario()
host_ip = "1.2.3.4"
self.assertTrue(vm_scenario.ping_ip_address(host_ip))
mock_subprocess.assert_called_once_with(
['ping', '-c1', '-w1', host_ip],
["ping", "-c1", "-w1", host_ip],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
ping_process.wait.assert_called_once_with()
@ -102,14 +102,14 @@ class VMScenarioTestCase(test.TestCase):
ping_process = mock.MagicMock()
ping_process.returncode = 0
mock_subprocess.return_value = ping_process
mock_sys.platform = 'linux2'
mock_sys.platform = "linux2"
vm_scenario = utils.VMScenario()
host_ip = "1ce:c01d:bee2:15:a5:900d:a5:11fe"
self.assertTrue(vm_scenario.ping_ip_address(host_ip))
mock_subprocess.assert_called_once_with(
['ping6', '-c1', '-w1', host_ip],
["ping6", "-c1", "-w1", host_ip],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
ping_process.wait.assert_called_once_with()
@ -119,14 +119,14 @@ class VMScenarioTestCase(test.TestCase):
ping_process = mock.MagicMock()
ping_process.returncode = 0
mock_subprocess.return_value = ping_process
mock_sys.platform = 'freebsd10'
mock_sys.platform = "freebsd10"
vm_scenario = utils.VMScenario()
host_ip = "1.2.3.4"
self.assertTrue(vm_scenario.ping_ip_address(host_ip))
mock_subprocess.assert_called_once_with(
['ping', '-c1', host_ip],
["ping", "-c1", host_ip],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
ping_process.wait.assert_called_once_with()
@ -136,13 +136,13 @@ class VMScenarioTestCase(test.TestCase):
ping_process = mock.MagicMock()
ping_process.returncode = 0
mock_subprocess.return_value = ping_process
mock_sys.platform = 'freebsd10'
mock_sys.platform = "freebsd10"
vm_scenario = utils.VMScenario()
host_ip = "1ce:c01d:bee2:15:a5:900d:a5:11fe"
self.assertTrue(vm_scenario.ping_ip_address(host_ip))
mock_subprocess.assert_called_once_with(
['ping6', '-c1', host_ip],
["ping6", "-c1", host_ip],
stderr=subprocess.PIPE, stdout=subprocess.PIPE)
ping_process.wait.assert_called_once_with()

View File

@ -33,7 +33,7 @@ class ZaqarBasicTestCase(test.TestCase):
@mock.patch(BASIC + "_generate_random_name", return_value="kitkat")
def test_producer_consumer(self, mock_gen_name):
scenario = basic.ZaqarBasic()
messages = [{'body': {'id': idx}, 'ttl': 360} for idx
messages = [{"body": {"id": idx}, "ttl": 360} for idx
in range(20)]
queue = mock.MagicMock()

View File

@ -40,7 +40,7 @@ class ZaqarScenarioTestCase(test.TestCase):
fake_zaqar.queue.assert_called_once_with("kitkat")
self._test_atomic_action_timer(scenario.atomic_actions(),
'zaqar.create_queue')
"zaqar.create_queue")
def test_queue_delete(self):
queue = fakes.FakeQueue()
@ -50,15 +50,15 @@ class ZaqarScenarioTestCase(test.TestCase):
scenario._queue_delete(queue)
queue.delete.assert_called_once_with()
self._test_atomic_action_timer(scenario.atomic_actions(),
'zaqar.delete_queue')
"zaqar.delete_queue")
def test_messages_post(self):
queue = fakes.FakeQueue()
queue.post = mock.MagicMock()
messages = [{'body': {'id': 'one'}, 'ttl': 100},
{'body': {'id': 'two'}, 'ttl': 120},
{'body': {'id': 'three'}, 'ttl': 140}]
messages = [{"body": {"id": "one"}, "ttl": 100},
{"body": {"id": "two"}, "ttl": 120},
{"body": {"id": "three"}, "ttl": 140}]
min_msg_count = max_msg_count = len(messages)
scenario = utils.ZaqarScenario()
@ -73,4 +73,4 @@ class ZaqarScenarioTestCase(test.TestCase):
scenario._messages_list(queue)
queue.messages.assert_called_once_with()
self._test_atomic_action_timer(scenario.atomic_actions(),
'zaqar.list_messages')
"zaqar.list_messages")

View File

@ -28,7 +28,7 @@ class TestCriterion(base.SLA):
@staticmethod
def check(criterion_value, result):
return base.SLAResult(criterion_value == result,
msg='detail')
msg="detail")
class BaseSLATestCase(test.TestCase):
@ -59,15 +59,15 @@ class BaseSLATestCase(test.TestCase):
result = {"key": {"kw": config, "name": "fake", "pos": 0},
"data": 42}
results = list(base.SLA.check_all(config, result["data"]))
expected = [{'criterion': 'test_criterion',
'detail': 'detail',
'success': True}]
expected = [{"criterion": "test_criterion",
"detail": "detail",
"success": True}]
self.assertEqual(expected, results)
result["data"] = 43
results = list(base.SLA.check_all(config, result["data"]))
expected = [{'criterion': 'test_criterion',
'detail': 'detail',
'success': False}]
expected = [{"criterion": "test_criterion",
"detail": "detail",
"success": False}]
self.assertEqual(expected, results)

View File

@ -26,13 +26,13 @@ class FlavorResourceTypeTestCase(test.TestCase):
def setUp(self):
super(FlavorResourceTypeTestCase, self).setUp()
self.clients = fakes.FakeClients()
self.clients.nova().flavors._cache(fakes.FakeResource(name='m1.tiny',
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.tiny",
id="1"))
self.clients.nova().flavors._cache(fakes.FakeResource(name='m1.nano',
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.nano",
id="42"))
self.clients.nova().flavors._cache(fakes.FakeResource(name='m1.large',
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.large",
id="44"))
self.clients.nova().flavors._cache(fakes.FakeResource(name='m1.large',
self.clients.nova().flavors._cache(fakes.FakeResource(name="m1.large",
id="45"))
def test_transform_by_id(self):
@ -154,7 +154,7 @@ class VolumeTypeResourceTypeTestCase(test.TestCase):
def setUp(self):
super(VolumeTypeResourceTypeTestCase, self).setUp()
self.clients = fakes.FakeClients()
volume_type1 = fakes.FakeResource(name='lvmdriver-1', id=100)
volume_type1 = fakes.FakeResource(name="lvmdriver-1", id=100)
self.clients.cinder().volume_types._cache(volume_type1)
def test_transform_by_id(self):

View File

@ -137,10 +137,10 @@ class BenchmarkUtilsTestCase(test.TestCase):
return self.name
client = mock.MagicMock()
client.services.list.return_value = [service('nova-compute'),
service('nova-network'),
service('glance-api')]
ret = utils.check_service_status(client, 'nova-network')
client.services.list.return_value = [service("nova-compute"),
service("nova-network"),
service("glance-api")]
ret = utils.check_service_status(client, "nova-network")
self.assertTrue(ret)
self.assertTrue(client.services.list.called)
@ -155,10 +155,10 @@ class BenchmarkUtilsTestCase(test.TestCase):
return self.name
client = mock.MagicMock()
client.services.list.return_value = [service('nova-compute'),
service('nova-network'),
service('glance-api')]
ret = utils.check_service_status(client, 'nova-network')
client.services.list.return_value = [service("nova-compute"),
service("nova-network"),
service("glance-api")]
ret = utils.check_service_status(client, "nova-network")
self.assertFalse(ret)
self.assertTrue(client.services.list.called)

View File

@ -23,15 +23,15 @@ from tests.unit import test
class KeystoneWrapperTestBase(object):
def test_list_services(self):
service = mock.MagicMock()
service.id = 'fake_id'
service.name = 'Foobar'
service.extra_field = 'extra_field'
service.id = "fake_id"
service.name = "Foobar"
service.extra_field = "extra_field"
self.client.services.list.return_value = [service]
result = list(self.wrapped_client.list_services())
self.assertEqual([('fake_id', 'Foobar')], result)
self.assertEqual('fake_id', result[0].id)
self.assertEqual('Foobar', result[0].name)
self.assertFalse(hasattr(result[0], 'extra_field'))
self.assertEqual([("fake_id", "Foobar")], result)
self.assertEqual("fake_id", result[0].id)
self.assertEqual("Foobar", result[0].name)
self.assertFalse(hasattr(result[0], "extra_field"))
def test_wrap(self):
client = mock.MagicMock()
@ -39,171 +39,171 @@ class KeystoneWrapperTestBase(object):
self.assertRaises(NotImplementedError, keystone.wrap, client)
def test_delete_service(self):
self.wrapped_client.delete_service('fake_id')
self.client.services.delete.assert_called_once_with('fake_id')
self.wrapped_client.delete_service("fake_id")
self.client.services.delete.assert_called_once_with("fake_id")
def test_list_roles(self):
role = mock.MagicMock()
role.id = 'fake_id'
role.name = 'Foobar'
role.extra_field = 'extra_field'
role.id = "fake_id"
role.name = "Foobar"
role.extra_field = "extra_field"
self.client.roles.list.return_value = [role]
result = list(self.wrapped_client.list_roles())
self.assertEqual([('fake_id', 'Foobar')], result)
self.assertEqual('fake_id', result[0].id)
self.assertEqual('Foobar', result[0].name)
self.assertFalse(hasattr(result[0], 'extra_field'))
self.assertEqual([("fake_id", "Foobar")], result)
self.assertEqual("fake_id", result[0].id)
self.assertEqual("Foobar", result[0].name)
self.assertFalse(hasattr(result[0], "extra_field"))
def test_delete_role(self):
self.wrapped_client.delete_role('fake_id')
self.client.roles.delete.assert_called_once_with('fake_id')
self.wrapped_client.delete_role("fake_id")
self.client.roles.delete.assert_called_once_with("fake_id")
class KeystoneV2WrapperTestCase(test.TestCase, KeystoneWrapperTestBase):
def setUp(self):
super(KeystoneV2WrapperTestCase, self).setUp()
self.client = mock.MagicMock()
self.client.version = 'v2.0'
self.client.version = "v2.0"
self.wrapped_client = keystone.wrap(self.client)
def test_create_project(self):
self.wrapped_client.create_project('Foobar')
self.client.tenants.create.assert_called_once_with('Foobar')
self.wrapped_client.create_project("Foobar")
self.client.tenants.create.assert_called_once_with("Foobar")
def test_create_project_in_non_default_domain_fail(self):
self.assertRaises(
NotImplementedError, self.wrapped_client.create_project,
'Foobar', 'non-default-domain')
"Foobar", "non-default-domain")
def test_delete_project(self):
self.wrapped_client.delete_project('fake_id')
self.client.tenants.delete.assert_called_once_with('fake_id')
self.wrapped_client.delete_project("fake_id")
self.client.tenants.delete.assert_called_once_with("fake_id")
def test_list_projects(self):
tenant = mock.MagicMock()
tenant.id = 'fake_id'
tenant.name = 'Foobar'
tenant.extra_field = 'extra_field'
tenant.id = "fake_id"
tenant.name = "Foobar"
tenant.extra_field = "extra_field"
self.client.tenants.list.return_value = [tenant]
result = list(self.wrapped_client.list_projects())
self.assertEqual([('fake_id', 'Foobar', 'default')], result)
self.assertEqual('fake_id', result[0].id)
self.assertEqual('Foobar', result[0].name)
self.assertEqual('default', result[0].domain_id)
self.assertFalse(hasattr(result[0], 'extra_field'))
self.assertEqual([("fake_id", "Foobar", "default")], result)
self.assertEqual("fake_id", result[0].id)
self.assertEqual("Foobar", result[0].name)
self.assertEqual("default", result[0].domain_id)
self.assertFalse(hasattr(result[0], "extra_field"))
def test_create_user(self):
self.wrapped_client.create_user('foo', 'bar', email='foo@bar.com',
project_id='tenant_id',
domain_name='default')
self.wrapped_client.create_user("foo", "bar", email="foo@bar.com",
project_id="tenant_id",
domain_name="default")
self.client.users.create.assert_called_once_with(
'foo', 'bar', 'foo@bar.com', 'tenant_id')
"foo", "bar", "foo@bar.com", "tenant_id")
def test_create_user_in_non_default_domain_fail(self):
self.assertRaises(
NotImplementedError, self.wrapped_client.create_user,
'foo', 'bar', email='foo@bar.com', project_id='tenant_id',
domain_name='non-default-domain')
"foo", "bar", email="foo@bar.com", project_id="tenant_id",
domain_name="non-default-domain")
def test_delete_user(self):
self.wrapped_client.delete_user('fake_id')
self.client.users.delete.assert_called_once_with('fake_id')
self.wrapped_client.delete_user("fake_id")
self.client.users.delete.assert_called_once_with("fake_id")
def test_list_users(self):
user = mock.MagicMock()
user.id = 'fake_id'
user.name = 'foo'
user.tenantId = 'tenant_id'
user.extra_field = 'extra_field'
user.id = "fake_id"
user.name = "foo"
user.tenantId = "tenant_id"
user.extra_field = "extra_field"
self.client.users.list.return_value = [user]
result = list(self.wrapped_client.list_users())
self.assertEqual([('fake_id', 'foo', 'tenant_id', 'default')], result)
self.assertEqual('fake_id', result[0].id)
self.assertEqual('foo', result[0].name)
self.assertEqual('tenant_id', result[0].project_id)
self.assertEqual('default', result[0].domain_id)
self.assertFalse(hasattr(result[0], 'extra_field'))
self.assertEqual([("fake_id", "foo", "tenant_id", "default")], result)
self.assertEqual("fake_id", result[0].id)
self.assertEqual("foo", result[0].name)
self.assertEqual("tenant_id", result[0].project_id)
self.assertEqual("default", result[0].domain_id)
self.assertFalse(hasattr(result[0], "extra_field"))
class KeystoneV3WrapperTestCase(test.TestCase, KeystoneWrapperTestBase):
def setUp(self):
super(KeystoneV3WrapperTestCase, self).setUp()
self.client = mock.MagicMock()
self.client.version = 'v3'
self.client.version = "v3"
self.wrapped_client = keystone.wrap(self.client)
self.client.domains.get.side_effect = exceptions.NotFound
self.client.domains.list.return_value = [
mock.MagicMock(id='domain_id')]
mock.MagicMock(id="domain_id")]
def test_create_project(self):
self.wrapped_client.create_project('Foobar', 'domain')
self.wrapped_client.create_project("Foobar", "domain")
self.client.projects.create.assert_called_once_with(
name='Foobar', domain='domain_id')
name="Foobar", domain="domain_id")
def test_create_project_with_non_existing_domain_fail(self):
self.client.domains.list.return_value = []
self.assertRaises(exceptions.NotFound,
self.wrapped_client.create_project,
'Foobar', 'non-existing-domain')
"Foobar", "non-existing-domain")
def test_delete_project(self):
self.wrapped_client.delete_project('fake_id')
self.client.projects.delete.assert_called_once_with('fake_id')
self.wrapped_client.delete_project("fake_id")
self.client.projects.delete.assert_called_once_with("fake_id")
def test_list_projects(self):
project = mock.MagicMock()
project.id = 'fake_id'
project.name = 'Foobar'
project.domain_id = 'domain_id'
project.extra_field = 'extra_field'
project.id = "fake_id"
project.name = "Foobar"
project.domain_id = "domain_id"
project.extra_field = "extra_field"
self.client.projects.list.return_value = [project]
result = list(self.wrapped_client.list_projects())
self.assertEqual([('fake_id', 'Foobar', 'domain_id')], result)
self.assertEqual('fake_id', result[0].id)
self.assertEqual('Foobar', result[0].name)
self.assertEqual('domain_id', result[0].domain_id)
self.assertFalse(hasattr(result[0], 'extra_field'))
self.assertEqual([("fake_id", "Foobar", "domain_id")], result)
self.assertEqual("fake_id", result[0].id)
self.assertEqual("Foobar", result[0].name)
self.assertEqual("domain_id", result[0].domain_id)
self.assertFalse(hasattr(result[0], "extra_field"))
def test_create_user(self):
self.client.roles.list.return_value = [
mock.MagicMock(id='fake_role_id')]
mock.MagicMock(id="fake_role_id")]
self.client.users.create.return_value = mock.MagicMock(
id='fake_user_id')
id="fake_user_id")
self.wrapped_client.create_user(
'foo', 'bar', email='foo@bar.com',
project_id='project_id', domain_name='domain')
"foo", "bar", email="foo@bar.com",
project_id="project_id", domain_name="domain")
self.client.users.create.assert_called_once_with(
name='foo', password='bar',
email='foo@bar.com', default_project='project_id',
domain='domain_id')
name="foo", password="bar",
email="foo@bar.com", default_project="project_id",
domain="domain_id")
self.client.roles.grant.assert_called_once_with(
'fake_role_id', user='fake_user_id', project='project_id')
"fake_role_id", user="fake_user_id", project="project_id")
def test_create_user_with_non_existing_domain_fail(self):
self.client.domains.list.return_value = []
self.assertRaises(exceptions.NotFound,
self.wrapped_client.create_user, 'foo', 'bar',
email='foo@bar.com', project_id='project_id',
domain_name='non-existing-domain')
self.wrapped_client.create_user, "foo", "bar",
email="foo@bar.com", project_id="project_id",
domain_name="non-existing-domain")
def test_delete_user(self):
self.wrapped_client.delete_user('fake_id')
self.client.users.delete.assert_called_once_with('fake_id')
self.wrapped_client.delete_user("fake_id")
self.client.users.delete.assert_called_once_with("fake_id")
def test_list_users(self):
user = mock.MagicMock()
user.id = 'fake_id'
user.name = 'foo'
user.default_project_id = 'project_id'
user.domain_id = 'domain_id'
user.extra_field = 'extra_field'
user.id = "fake_id"
user.name = "foo"
user.default_project_id = "project_id"
user.domain_id = "domain_id"
user.extra_field = "extra_field"
self.client.users.list.return_value = [user]
result = list(self.wrapped_client.list_users())
self.assertEqual([('fake_id', 'foo', 'project_id', 'domain_id')],
self.assertEqual([("fake_id", "foo", "project_id", "domain_id")],
result)
self.assertEqual('fake_id', result[0].id)
self.assertEqual('foo', result[0].name)
self.assertEqual('project_id', result[0].project_id)
self.assertEqual('domain_id', result[0].domain_id)
self.assertFalse(hasattr(result[0], 'extra_field'))
self.assertEqual("fake_id", result[0].id)
self.assertEqual("foo", result[0].name)
self.assertEqual("project_id", result[0].project_id)
self.assertEqual("domain_id", result[0].domain_id)
self.assertFalse(hasattr(result[0], "extra_field"))