Merge "Better mocking for self.[admin_]clients in Scenario tests"
This commit is contained in:
commit
ed2996dac1
@ -13,8 +13,6 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from rally.benchmark.scenarios import base
|
||||
from rally.plugins.openstack.scenarios.authenticate import authenticate
|
||||
from tests.unit import test
|
||||
@ -24,55 +22,43 @@ AUTHENTICATE_MODULE = (
|
||||
"rally.plugins.openstack.scenarios.authenticate.authenticate")
|
||||
|
||||
|
||||
class AuthenticateTestCase(test.TestCase):
|
||||
class AuthenticateTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients")
|
||||
def test_keystone(self, mock_clients):
|
||||
def test_keystone(self):
|
||||
scenario = authenticate.Authenticate()
|
||||
scenario.keystone()
|
||||
mock_clients.assert_called_once_with("keystone")
|
||||
self.assertTrue(self.client_created("keystone"))
|
||||
|
||||
@mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients")
|
||||
def test_validate_glance(self, mock_clients):
|
||||
def test_validate_glance(self):
|
||||
scenario = authenticate.Authenticate()
|
||||
mock_clients.return_value.images.list = mock.MagicMock()
|
||||
image_name = "__intentionally_non_existent_image___"
|
||||
with base.AtomicAction(scenario, "authenticate.validate_glance"):
|
||||
scenario.validate_glance(5)
|
||||
mock_clients.return_value.images.list.assert_called_with(
|
||||
name=image_name)
|
||||
self.assertEqual(mock_clients.return_value.images.list.call_count, 5)
|
||||
self.clients("glance").images.list.assert_called_with(name=image_name)
|
||||
self.assertEqual(self.clients("glance").images.list.call_count, 5)
|
||||
|
||||
@mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients")
|
||||
def test_validate_nova(self, mock_clients):
|
||||
def test_validate_nova(self):
|
||||
scenario = authenticate.Authenticate()
|
||||
mock_clients.return_value.flavors.list = mock.MagicMock()
|
||||
with base.AtomicAction(scenario, "authenticate.validate_nova"):
|
||||
scenario.validate_nova(5)
|
||||
self.assertEqual(mock_clients.return_value.flavors.list.call_count, 5)
|
||||
self.assertEqual(self.clients("nova").flavors.list.call_count, 5)
|
||||
|
||||
@mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients")
|
||||
def test_validate_cinder(self, mock_clients):
|
||||
def test_validate_cinder(self):
|
||||
scenario = authenticate.Authenticate()
|
||||
mock_clients.return_value.volume_types.list = mock.MagicMock()
|
||||
with base.AtomicAction(scenario, "authenticate.validate_cinder"):
|
||||
scenario.validate_cinder(5)
|
||||
self.assertEqual(mock_clients.return_value.volume_types.
|
||||
list.call_count, 5)
|
||||
self.assertEqual(self.clients("cinder").volume_types.list.call_count,
|
||||
5)
|
||||
|
||||
@mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients")
|
||||
def test_validate_neutron(self, mock_clients):
|
||||
def test_validate_neutron(self):
|
||||
scenario = authenticate.Authenticate()
|
||||
mock_clients.return_value.get_auth_info = mock.MagicMock()
|
||||
with base.AtomicAction(scenario, "authenticate.validate_neutron"):
|
||||
scenario.validate_neutron(5)
|
||||
self.assertEqual(mock_clients.return_value.get_auth_info.call_count, 5)
|
||||
self.assertEqual(self.clients("neutron").get_auth_info.call_count, 5)
|
||||
|
||||
@mock.patch(AUTHENTICATE_MODULE + ".Authenticate.clients")
|
||||
def test_validate_heat(self, mock_clients):
|
||||
def test_validate_heat(self):
|
||||
scenario = authenticate.Authenticate()
|
||||
mock_clients.return_value.stacks.list = mock.MagicMock()
|
||||
with base.AtomicAction(scenario, "authenticate.validate_heat"):
|
||||
scenario.validate_heat(5)
|
||||
mock_clients.return_value.stacks.list.assert_called_with(limit=0)
|
||||
self.assertEqual(mock_clients.return_value.stacks.list.call_count, 5)
|
||||
self.clients("heat").stacks.list.assert_called_with(limit=0)
|
||||
self.assertEqual(self.clients("heat").stacks.list.call_count, 5)
|
||||
|
@ -23,7 +23,7 @@ BM_UTILS = "rally.benchmark.utils"
|
||||
CEILOMETER_UTILS = "rally.plugins.openstack.scenarios.ceilometer.utils"
|
||||
|
||||
|
||||
class CeilometerScenarioTestCase(test.TestCase):
|
||||
class CeilometerScenarioTestCase(test.ClientsTestCase):
|
||||
def setUp(self):
|
||||
super(CeilometerScenarioTestCase, self).setUp()
|
||||
self.scenario = utils.CeilometerScenario()
|
||||
@ -92,10 +92,9 @@ class CeilometerScenarioTestCase(test.TestCase):
|
||||
fake_state = self.scenario._get_alarm_state(fake_alarm.alarm_id)
|
||||
self.assertEqual(fake_state, "alarm-state")
|
||||
|
||||
@mock.patch(CEILOMETER_UTILS + ".CeilometerScenario.clients")
|
||||
def test__set_alarm_state(self, mock_clients):
|
||||
def test__set_alarm_state(self):
|
||||
alarm = mock.Mock()
|
||||
mock_clients("ceilometer").alarms.create.return_value = alarm
|
||||
self.clients("ceilometer").alarms.create.return_value = alarm
|
||||
return_alarm = self.scenario._set_alarm_state(alarm, "ok", 100)
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
alarm,
|
||||
|
@ -26,7 +26,7 @@ BM_UTILS = "rally.benchmark.utils"
|
||||
CINDER_UTILS = "rally.plugins.openstack.scenarios.cinder.utils"
|
||||
|
||||
|
||||
class CinderScenarioTestCase(test.TestCase):
|
||||
class CinderScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CinderScenarioTestCase, self).setUp()
|
||||
@ -43,30 +43,26 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self.useFixture(mockpatch.Patch("time.sleep"))
|
||||
self.scenario = utils.CinderScenario()
|
||||
|
||||
@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
|
||||
def test__list_volumes(self):
|
||||
return_volumes_list = self.scenario._list_volumes()
|
||||
self.assertEqual(volumes_list, return_volumes_list)
|
||||
self.assertEqual(self.clients("cinder").volumes.list.return_value,
|
||||
return_volumes_list)
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.list_volumes")
|
||||
|
||||
@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
|
||||
def test__list_snapshots(self):
|
||||
return_snapshots_list = self.scenario._list_snapshots()
|
||||
self.assertEqual(snapsht_lst, return_snapshots_list)
|
||||
self.assertEqual(
|
||||
self.clients("cinder").volume_snapshots.list.return_value,
|
||||
return_snapshots_list)
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.list_snapshots")
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__set_metadata(self, mock_clients):
|
||||
def test__set_metadata(self):
|
||||
volume = fakes.FakeVolume()
|
||||
|
||||
self.scenario._set_metadata(volume, sets=2, set_size=4)
|
||||
calls = mock_clients("cinder").volumes.set_metadata.call_args_list
|
||||
calls = self.clients("cinder").volumes.set_metadata.call_args_list
|
||||
self.assertEqual(len(calls), 2)
|
||||
for call in calls:
|
||||
call_volume, metadata = call[0]
|
||||
@ -76,13 +72,12 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.set_4_metadatas_2_times")
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__delete_metadata(self, mock_clients):
|
||||
def test__delete_metadata(self):
|
||||
volume = fakes.FakeVolume()
|
||||
|
||||
keys = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"]
|
||||
self.scenario._delete_metadata(volume, keys, deletes=3, delete_size=4)
|
||||
calls = mock_clients("cinder").volumes.delete_metadata.call_args_list
|
||||
calls = self.clients("cinder").volumes.delete_metadata.call_args_list
|
||||
self.assertEqual(len(calls), 3)
|
||||
all_deleted = []
|
||||
for call in calls:
|
||||
@ -97,8 +92,7 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.delete_4_metadatas_3_times")
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__delete_metadata_not_enough_keys(self, mock_clients):
|
||||
def test__delete_metadata_not_enough_keys(self):
|
||||
volume = fakes.FakeVolume()
|
||||
|
||||
keys = ["a", "b", "c", "d", "e"]
|
||||
@ -106,14 +100,11 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self.scenario._delete_metadata,
|
||||
volume, keys, deletes=2, delete_size=3)
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__create_volume(self, mock_clients):
|
||||
def test__create_volume(self):
|
||||
CONF = cfg.CONF
|
||||
volume = mock.Mock()
|
||||
mock_clients("cinder").volumes.create.return_value = volume
|
||||
return_volume = self.scenario._create_volume(1)
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
volume,
|
||||
self.clients("cinder").volumes.create.return_value,
|
||||
is_ready=self.res_is.mock(),
|
||||
update_resource=self.gfm(),
|
||||
timeout=CONF.benchmark.cinder_volume_create_timeout,
|
||||
@ -125,22 +116,19 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
"cinder.create_volume")
|
||||
|
||||
@mock.patch("rally.plugins.openstack.scenarios.cinder.utils.random")
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__create_volume_with_size_range(self, mock_clients, mock_random):
|
||||
def test__create_volume_with_size_range(self, mock_random):
|
||||
CONF = cfg.CONF
|
||||
volume = mock.Mock()
|
||||
mock_clients("cinder").volumes.create.return_value = volume
|
||||
mock_random.randint.return_value = 3
|
||||
|
||||
return_volume = self.scenario._create_volume(
|
||||
size={"min": 1, "max": 5},
|
||||
display_name="TestVolume")
|
||||
|
||||
mock_clients("cinder").volumes.create.assert_called_once_with(
|
||||
self.clients("cinder").volumes.create.assert_called_once_with(
|
||||
3, display_name="TestVolume")
|
||||
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
volume,
|
||||
self.clients("cinder").volumes.create.return_value,
|
||||
is_ready=self.res_is.mock(),
|
||||
update_resource=self.gfm(),
|
||||
timeout=CONF.benchmark.cinder_volume_create_timeout,
|
||||
@ -165,12 +153,11 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
"cinder.delete_volume")
|
||||
|
||||
@mock.patch("rally.plugins.openstack.scenarios.cinder.utils.random")
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__extend_volume_with_size_range(self, mock_clients, mock_random):
|
||||
def test__extend_volume_with_size_range(self, mock_random):
|
||||
CONF = cfg.CONF
|
||||
volume = mock.Mock()
|
||||
mock_random.randint.return_value = 3
|
||||
mock_clients("cinder").volumes.extend.return_value = volume
|
||||
self.clients("cinder").volumes.extend.return_value = volume
|
||||
|
||||
self.scenario._extend_volume(volume, new_size={"min": 1, "max": 5})
|
||||
|
||||
@ -186,11 +173,10 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.extend_volume")
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__extend_volume(self, mock_clients):
|
||||
def test__extend_volume(self):
|
||||
CONF = cfg.CONF
|
||||
volume = mock.Mock()
|
||||
mock_clients("cinder").volumes.extend.return_value = volume
|
||||
self.clients("cinder").volumes.extend.return_value = volume
|
||||
self.scenario._extend_volume(volume, 2)
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
volume,
|
||||
@ -203,12 +189,11 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.extend_volume")
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__upload_volume_to_image(self, mock_clients):
|
||||
def test__upload_volume_to_image(self):
|
||||
volume = mock.Mock()
|
||||
image = {"os-volume_upload_image": {"image_id": 1}}
|
||||
volume.upload_to_image.return_value = (None, image)
|
||||
mock_clients("cinder").images.get.return_value = image
|
||||
self.clients("cinder").images.get.return_value = image
|
||||
|
||||
self.scenario._generate_random_name = mock.Mock(
|
||||
return_value="test_vol")
|
||||
@ -220,15 +205,11 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self.assertTrue(self.wait_for.mock.called)
|
||||
self.assertEqual(2, self.wait_for.mock.call_count)
|
||||
|
||||
@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
|
||||
|
||||
def test__create_snapshot(self):
|
||||
return_snapshot = self.scenario._create_snapshot("uuid", False)
|
||||
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
snapshot,
|
||||
self.clients("cinder").volume_snapshots.create.return_value,
|
||||
is_ready=self.res_is.mock(),
|
||||
update_resource=self.gfm(),
|
||||
timeout=cfg.CONF.benchmark.cinder_volume_create_timeout,
|
||||
@ -252,15 +233,11 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.delete_snapshot")
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__create_backup(self, mock_clients):
|
||||
backup = mock.Mock()
|
||||
mock_clients("cinder").backups.create.return_value = backup
|
||||
|
||||
def test__create_backup(self):
|
||||
return_backup = self.scenario._create_backup("uuid")
|
||||
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
backup,
|
||||
self.clients("cinder").backups.create.return_value,
|
||||
is_ready=self.res_is.mock(),
|
||||
update_resource=self.gfm(),
|
||||
timeout=cfg.CONF.benchmark.cinder_volume_create_timeout,
|
||||
@ -284,12 +261,11 @@ class CinderScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(self.scenario.atomic_actions(),
|
||||
"cinder.delete_backup")
|
||||
|
||||
@mock.patch(CINDER_UTILS + ".CinderScenario.clients")
|
||||
def test__restore_backup(self, mock_clients):
|
||||
def test__restore_backup(self):
|
||||
backup = mock.Mock()
|
||||
restore = mock.Mock()
|
||||
mock_clients("cinder").restores.restore.return_value = backup
|
||||
mock_clients("cinder").volumes.get.return_value = restore
|
||||
self.clients("cinder").restores.restore.return_value = backup
|
||||
self.clients("cinder").volumes.get.return_value = restore
|
||||
|
||||
return_restore = self.scenario._restore_backup(backup.id, None)
|
||||
|
||||
|
@ -16,7 +16,6 @@
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.cinder import volumes
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
CINDER_VOLUMES = ("rally.plugins.openstack.scenarios.cinder.volumes"
|
||||
@ -27,7 +26,7 @@ class fake_type(object):
|
||||
name = "fake"
|
||||
|
||||
|
||||
class CinderServersTestCase(test.TestCase):
|
||||
class CinderServersTestCase(test.ClientsTestCase):
|
||||
|
||||
def test_create_and_list_volume(self):
|
||||
scenario = volumes.CinderVolumes()
|
||||
@ -250,8 +249,7 @@ class CinderServersTestCase(test.TestCase):
|
||||
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
|
||||
scenario._delete_snapshot = mock.MagicMock()
|
||||
|
||||
scenario.clients = mock.MagicMock()
|
||||
scenario.clients("nova").servers.get = mock.MagicMock(
|
||||
self.clients("nova").servers.get = mock.MagicMock(
|
||||
return_value=fake_server)
|
||||
|
||||
scenario.create_snapshot_and_attach_volume()
|
||||
@ -286,10 +284,9 @@ class CinderServersTestCase(test.TestCase):
|
||||
scenario._delete_snapshot = mock.MagicMock()
|
||||
fake = fake_type()
|
||||
|
||||
scenario.clients = mock.MagicMock()
|
||||
scenario.clients("cinder").volume_types.list = mock.MagicMock(
|
||||
self.clients("cinder").volume_types.list = mock.MagicMock(
|
||||
return_value=[fake])
|
||||
scenario.clients("nova").servers.get = mock.MagicMock(
|
||||
self.clients("nova").servers.get = mock.MagicMock(
|
||||
return_value=fake_server)
|
||||
|
||||
scenario.create_snapshot_and_attach_volume(volume_type=True)
|
||||
@ -311,12 +308,8 @@ class CinderServersTestCase(test.TestCase):
|
||||
def test_create_nested_snapshots_and_attach_volume(self):
|
||||
fake_volume = mock.MagicMock()
|
||||
fake_snapshot = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_server = fake_clients.nova().servers.create("test_server",
|
||||
"image_id_01",
|
||||
"flavor_id_01")
|
||||
fake_server = mock.MagicMock()
|
||||
scenario = volumes.CinderVolumes(
|
||||
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
@ -330,8 +323,6 @@ class CinderServersTestCase(test.TestCase):
|
||||
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
|
||||
scenario._delete_snapshot = mock.MagicMock()
|
||||
|
||||
scenario._clients = fake_clients
|
||||
|
||||
scenario.create_nested_snapshots_and_attach_volume()
|
||||
|
||||
volume_count = scenario._create_volume.call_count
|
||||
@ -347,12 +338,9 @@ class CinderServersTestCase(test.TestCase):
|
||||
fake_volume2 = mock.MagicMock()
|
||||
fake_snapshot1 = mock.MagicMock()
|
||||
fake_snapshot2 = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_server = fake_clients.nova().servers.create("test_server",
|
||||
"image_id_01",
|
||||
"flavor_id_01")
|
||||
scenario = volumes.CinderVolumes(
|
||||
fake_server = mock.MagicMock()
|
||||
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
@ -367,7 +355,6 @@ class CinderServersTestCase(test.TestCase):
|
||||
scenario._create_snapshot = mock.MagicMock(
|
||||
side_effect=[fake_snapshot1, fake_snapshot2])
|
||||
scenario._delete_snapshot = mock.MagicMock()
|
||||
scenario._clients = fake_clients
|
||||
|
||||
scenario.create_nested_snapshots_and_attach_volume(
|
||||
nested_level={"min": 2, "max": 2})
|
||||
@ -384,12 +371,9 @@ class CinderServersTestCase(test.TestCase):
|
||||
mock_random.randint.return_value = 3
|
||||
fake_volume = mock.MagicMock()
|
||||
fake_snapshot = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_server = fake_clients.nova().servers.create("test_server",
|
||||
"image_id_01",
|
||||
"flavor_id_01")
|
||||
scenario = volumes.CinderVolumes(
|
||||
fake_server = mock.MagicMock()
|
||||
|
||||
scenario = volumes.CinderVolumes(
|
||||
context={"user": {"tenant_id": "fake"},
|
||||
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
|
||||
"tenant": {"id": "fake", "name": "fake",
|
||||
@ -403,7 +387,6 @@ class CinderServersTestCase(test.TestCase):
|
||||
scenario._delete_volume = mock.MagicMock()
|
||||
scenario._create_snapshot = mock.MagicMock(return_value=fake_snapshot)
|
||||
scenario._delete_snapshot = mock.MagicMock()
|
||||
scenario._clients = fake_clients
|
||||
|
||||
scenario.create_nested_snapshots_and_attach_volume()
|
||||
|
||||
|
@ -22,7 +22,7 @@ from tests.unit import test
|
||||
DESIGNATE_UTILS = "rally.plugins.openstack.scenarios.designate.utils."
|
||||
|
||||
|
||||
class DesignateScenarioTestCase(test.TestCase):
|
||||
class DesignateScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(DesignateScenarioTestCase, self).setUp()
|
||||
@ -30,8 +30,7 @@ class DesignateScenarioTestCase(test.TestCase):
|
||||
self.server = mock.Mock()
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
|
||||
def test_create_domain(self, mock_clients, mock_random_name):
|
||||
def test_create_domain(self, mock_random_name):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
random_name = "foo"
|
||||
@ -39,36 +38,33 @@ class DesignateScenarioTestCase(test.TestCase):
|
||||
email = "root@zone.name"
|
||||
|
||||
mock_random_name.return_value = random_name
|
||||
mock_clients("designate").domains.create.return_value = self.domain
|
||||
self.clients("designate").domains.create.return_value = self.domain
|
||||
|
||||
# Check that the defaults / randoms are used if nothing is specified
|
||||
domain = scenario._create_domain()
|
||||
mock_clients("designate").domains.create.assert_called_once_with(
|
||||
self.clients("designate").domains.create.assert_called_once_with(
|
||||
{"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")
|
||||
|
||||
mock_clients("designate").domains.create.reset_mock()
|
||||
self.clients("designate").domains.create.reset_mock()
|
||||
|
||||
# Check that when specifying zone defaults are not used...
|
||||
data = {"email": email, "name": explicit_name}
|
||||
domain = scenario._create_domain(data)
|
||||
mock_clients("designate").domains.create.assert_called_once_with(data)
|
||||
self.clients("designate").domains.create.assert_called_once_with(data)
|
||||
self.assertEqual(self.domain, domain)
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
|
||||
def test_list_domains(self, mock_clients):
|
||||
def test_list_domains(self):
|
||||
scenario = utils.DesignateScenario()
|
||||
domains_list = []
|
||||
mock_clients("designate").domains.list.return_value = domains_list
|
||||
return_domains_list = scenario._list_domains()
|
||||
self.assertEqual(domains_list, return_domains_list)
|
||||
self.assertEqual(self.clients("designate").domains.list.return_value,
|
||||
return_domains_list)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"designate.list_domains")
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
|
||||
def test_delete_domain(self, mock_clients):
|
||||
def test_delete_domain(self):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
domain = scenario._create_domain()
|
||||
@ -77,8 +73,7 @@ class DesignateScenarioTestCase(test.TestCase):
|
||||
"designate.delete_domain")
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
|
||||
def test_create_record(self, mock_clients, mock_random_name):
|
||||
def test_create_record(self, mock_random_name):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
random_name = "foo"
|
||||
@ -91,79 +86,78 @@ class DesignateScenarioTestCase(test.TestCase):
|
||||
|
||||
# Create with randoms (name and type)
|
||||
scenario._create_record(domain)
|
||||
mock_clients("designate").records.create.assert_called_once_with(
|
||||
self.clients("designate").records.create.assert_called_once_with(
|
||||
domain["id"],
|
||||
{"name": random_record_name, "type": "A", "data": "10.0.0.1"})
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"designate.create_record")
|
||||
|
||||
mock_clients("designate").records.create.reset_mock()
|
||||
self.clients("designate").records.create.reset_mock()
|
||||
|
||||
# Specify name
|
||||
record = {"name": "www.zone.name.", "type": "ASD"}
|
||||
scenario._create_record(domain, record)
|
||||
mock_clients("designate").records.create.assert_called_once_with(
|
||||
self.clients("designate").records.create.assert_called_once_with(
|
||||
domain["id"], record)
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
|
||||
def test_list_records(self, mock_clients):
|
||||
def test_list_records(self):
|
||||
scenario = utils.DesignateScenario()
|
||||
records_list = []
|
||||
mock_clients("designate").records.list.return_value = records_list
|
||||
return_records_list = scenario._list_records("123")
|
||||
self.assertEqual(records_list, return_records_list)
|
||||
self.assertEqual(self.clients("designate").records.list.return_value,
|
||||
return_records_list)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"designate.list_records")
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.clients")
|
||||
def test_delete_record(self, mock_clients):
|
||||
def test_delete_record(self):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
mock_clients("designate").domains.create.return_value = {
|
||||
"id": "123", "name": "asd"}
|
||||
domain = scenario._create_domain()
|
||||
|
||||
mock_clients("designate").records.create.return_value = {"id": "123"}
|
||||
record = scenario._create_record(domain)
|
||||
|
||||
scenario._delete_record(domain["id"], record["id"])
|
||||
domain_id = mock.Mock()
|
||||
record_id = mock.Mock()
|
||||
scenario._delete_record(domain_id, record_id)
|
||||
self.clients("designate").records.delete.assert_called_once_with(
|
||||
domain_id, record_id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"designate.delete_record")
|
||||
|
||||
self.clients("designate").records.delete.reset_mock()
|
||||
scenario._delete_record(domain_id, record_id, atomic_action=False)
|
||||
self.clients("designate").records.delete.assert_called_once_with(
|
||||
domain_id, record_id)
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario._generate_random_name")
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.admin_clients")
|
||||
def test_create_server(self, mock_clients, mock_random_name):
|
||||
def test_create_server(self, mock_random_name):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
random_name = "foo"
|
||||
explicit_name = "bar.io."
|
||||
|
||||
mock_random_name.return_value = random_name
|
||||
mock_clients("designate").servers.create.return_value = self.server
|
||||
self.admin_clients(
|
||||
"designate").servers.create.return_value = self.server
|
||||
|
||||
# Check that the defaults / randoms are used if nothing is specified
|
||||
server = scenario._create_server()
|
||||
mock_clients("designate").servers.create.assert_called_once_with(
|
||||
self.admin_clients("designate").servers.create.assert_called_once_with(
|
||||
{"name": "name.%s." % random_name})
|
||||
self.assertEqual(self.server, server)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"designate.create_server")
|
||||
|
||||
mock_clients("designate").servers.create.reset_mock()
|
||||
self.admin_clients("designate").servers.create.reset_mock()
|
||||
|
||||
# Check that when specifying server name defaults are not used...
|
||||
data = {"name": explicit_name}
|
||||
server = scenario._create_server(data)
|
||||
mock_clients("designate").servers.create.assert_called_once_with(data)
|
||||
self.admin_clients(
|
||||
"designate").servers.create.assert_called_once_with(data)
|
||||
self.assertEqual(self.server, server)
|
||||
|
||||
@mock.patch(DESIGNATE_UTILS + "DesignateScenario.admin_clients")
|
||||
def test_delete_server(self, mock_clients):
|
||||
def test_delete_server(self):
|
||||
scenario = utils.DesignateScenario()
|
||||
|
||||
scenario._delete_server("foo_id")
|
||||
mock_clients("designate").servers.delete.assert_called_once_with(
|
||||
self.admin_clients("designate").servers.delete.assert_called_once_with(
|
||||
"foo_id")
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"designate.delete_server")
|
||||
|
@ -21,7 +21,7 @@ from tests.unit import test
|
||||
UTILS = "rally.plugins.openstack.scenarios.ec2.utils."
|
||||
|
||||
|
||||
class EC2ServersTestCase(test.TestCase):
|
||||
class EC2ServersTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch("rally.benchmark.utils.wait_for",
|
||||
return_value="running_server")
|
||||
@ -36,8 +36,7 @@ class EC2ServersTestCase(test.TestCase):
|
||||
scenario = servers.EC2Servers()
|
||||
scenario._update_resource = "foo_update"
|
||||
mock_instances = mock.Mock(instances=["foo_inst"])
|
||||
scenario.clients = mock.Mock()
|
||||
scenario.clients("ec2").run_instances.return_value = mock_instances
|
||||
self.clients("ec2").run_instances.return_value = mock_instances
|
||||
server = scenario._boot_server("foo_image", "foo_flavor", foo="bar")
|
||||
|
||||
mock_wait.assert_called_once_with("foo_inst", is_ready="foo_state",
|
||||
|
@ -38,7 +38,7 @@ class EC2UtilsTestCase(test.TestCase):
|
||||
resource.update.assert_called_once_with()
|
||||
|
||||
|
||||
class EC2ScenarioTestCase(test.TestCase):
|
||||
class EC2ScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(EC2ScenarioTestCase, self).setUp()
|
||||
@ -58,9 +58,8 @@ class EC2ScenarioTestCase(test.TestCase):
|
||||
self.assertIsNotNone(action_duration)
|
||||
self.assertIsInstance(action_duration, float)
|
||||
|
||||
@mock.patch(EC2_UTILS + ".EC2Scenario.clients")
|
||||
def test__boot_server(self, mock_clients):
|
||||
mock_clients("ec2").run_instances.return_value = self.reservation
|
||||
def test__boot_server(self):
|
||||
self.clients("ec2").run_instances.return_value = self.reservation
|
||||
ec2_scenario = utils.EC2Scenario(context={})
|
||||
return_server = ec2_scenario._boot_server("image", "flavor")
|
||||
expected = mock.call(
|
||||
|
@ -15,10 +15,7 @@
|
||||
|
||||
import mock
|
||||
|
||||
from rally import objects
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.scenarios.glance import images
|
||||
from rally.plugins.openstack.scenarios.nova import servers
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
@ -64,23 +61,12 @@ class GlanceImagesTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(GLANCE_IMAGES + "._boot_servers")
|
||||
@mock.patch(GLANCE_IMAGES + "._create_image")
|
||||
@mock.patch("rally.benchmark.runner.osclients")
|
||||
def test_create_image_and_boot_instances(self,
|
||||
mock_osclients,
|
||||
mock_create_image,
|
||||
mock_boot_servers):
|
||||
glance_scenario = images.GlanceImages()
|
||||
nova_scenario = servers.NovaServers()
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
fake_glance = fakes.FakeGlanceClient()
|
||||
fc.glance = lambda: fake_glance
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
fc.nova = lambda: fake_nova
|
||||
user_endpoint = objects.Endpoint("url", "user", "password", "tenant")
|
||||
nova_scenario._clients = osclients.Clients(user_endpoint)
|
||||
fake_image = fakes.FakeImage()
|
||||
fake_servers = [object() for i in range(5)]
|
||||
fake_servers = [mock.Mock() for i in range(5)]
|
||||
mock_create_image.return_value = fake_image
|
||||
mock_boot_servers.return_value = fake_servers
|
||||
kwargs = {"fakearg": "f"}
|
||||
|
@ -27,7 +27,7 @@ BM_UTILS = "rally.benchmark.utils"
|
||||
GLANCE_UTILS = "rally.plugins.openstack.scenarios.glance.utils"
|
||||
|
||||
|
||||
class GlanceScenarioTestCase(test.TestCase):
|
||||
class GlanceScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(GlanceScenarioTestCase, self).setUp()
|
||||
@ -53,20 +53,18 @@ class GlanceScenarioTestCase(test.TestCase):
|
||||
butils.get_from_manager(),
|
||||
image_manager.create("fails", "url", "cf", "df"))
|
||||
|
||||
@mock.patch(GLANCE_UTILS + ".GlanceScenario.clients")
|
||||
def test_list_images(self, mock_clients):
|
||||
images_list = []
|
||||
mock_clients("glance").images.list.return_value = images_list
|
||||
def test_list_images(self):
|
||||
scenario = utils.GlanceScenario()
|
||||
return_images_list = scenario._list_images()
|
||||
self.assertEqual(images_list, return_images_list)
|
||||
self.clients("glance").images.list.assert_called_once_with()
|
||||
self.assertEqual(list(self.clients("glance").images.list.return_value),
|
||||
return_images_list)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"glance.list_images")
|
||||
|
||||
@mock.patch(GLANCE_UTILS + ".GlanceScenario.clients")
|
||||
def test_create_image(self, mock_clients):
|
||||
def test_create_image(self):
|
||||
image_location = tempfile.NamedTemporaryFile()
|
||||
mock_clients("glance").images.create.return_value = self.image
|
||||
self.clients("glance").images.create.return_value = self.image
|
||||
scenario = utils.GlanceScenario()
|
||||
return_image = scenario._create_image("container_format",
|
||||
image_location.name,
|
||||
@ -81,9 +79,8 @@ class GlanceScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"glance.create_image")
|
||||
|
||||
@mock.patch(GLANCE_UTILS + ".GlanceScenario.clients")
|
||||
def test_create_image_with_location(self, mock_clients):
|
||||
mock_clients("glance").images.create.return_value = self.image
|
||||
def test_create_image_with_location(self):
|
||||
self.clients("glance").images.create.return_value = self.image
|
||||
scenario = utils.GlanceScenario()
|
||||
return_image = scenario._create_image("container_format",
|
||||
"image_location",
|
||||
|
@ -21,7 +21,7 @@ from tests.unit import test
|
||||
HEAT_STACKS = "rally.plugins.openstack.scenarios.heat.stacks.HeatStacks"
|
||||
|
||||
|
||||
class HeatStacksTestCase(test.TestCase):
|
||||
class HeatStacksTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(HeatStacksTestCase, self).setUp()
|
||||
@ -49,25 +49,23 @@ class HeatStacksTestCase(test.TestCase):
|
||||
self.default_environment)
|
||||
mock_list.assert_called_once_with()
|
||||
|
||||
@mock.patch(HEAT_STACKS + ".clients")
|
||||
@mock.patch(HEAT_STACKS + "._list_stacks")
|
||||
def test_list_stack_and_resources(self, mock_list_stack, mock_clients):
|
||||
def test_list_stack_and_resources(self, mock_list_stack):
|
||||
stack = mock.Mock()
|
||||
mock_list_stack.return_value = [stack]
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
heat_scenario.list_stacks_and_resources()
|
||||
mock_clients("heat").resources.list.assert_called_once_with(stack.id)
|
||||
self.clients("heat").resources.list.assert_called_once_with(stack.id)
|
||||
self._test_atomic_action_timer(
|
||||
heat_scenario.atomic_actions(), "heat.list_resources_of_1_stacks")
|
||||
|
||||
@mock.patch(HEAT_STACKS + ".clients")
|
||||
@mock.patch(HEAT_STACKS + "._list_stacks")
|
||||
def test_list_stack_and_events(self, mock_list_stack, mock_clients):
|
||||
def test_list_stack_and_events(self, mock_list_stack):
|
||||
stack = mock.Mock()
|
||||
mock_list_stack.return_value = [stack]
|
||||
heat_scenario = stacks.HeatStacks()
|
||||
heat_scenario.list_stacks_and_events()
|
||||
mock_clients("heat").events.list.assert_called_once_with(stack.id)
|
||||
self.clients("heat").events.list.assert_called_once_with(stack.id)
|
||||
self._test_atomic_action_timer(
|
||||
heat_scenario.atomic_actions(), "heat.list_events_of_1_stacks")
|
||||
|
||||
|
@ -26,7 +26,7 @@ HEAT_UTILS = "rally.plugins.openstack.scenarios.heat.utils"
|
||||
CONF = utils.CONF
|
||||
|
||||
|
||||
class HeatScenarioTestCase(test.TestCase):
|
||||
class HeatScenarioTestCase(test.ClientsTestCase):
|
||||
def setUp(self):
|
||||
super(HeatScenarioTestCase, self).setUp()
|
||||
self.stack = mock.Mock()
|
||||
@ -47,28 +47,26 @@ class HeatScenarioTestCase(test.TestCase):
|
||||
self.dummy_files = ["dummy_file.yaml"]
|
||||
self.dummy_environment = {"dummy_env": "dummy_env_value"}
|
||||
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_list_stacks(self, mock_clients):
|
||||
stacks_list = []
|
||||
mock_clients("heat").stacks.list.return_value = stacks_list
|
||||
def test_list_stacks(self):
|
||||
scenario = utils.HeatScenario()
|
||||
return_stacks_list = scenario._list_stacks()
|
||||
self.assertEqual(stacks_list, return_stacks_list)
|
||||
self.clients("heat").stacks.list.assert_called_once_with()
|
||||
self.assertEqual(list(self.clients("heat").stacks.list.return_value),
|
||||
return_stacks_list)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"heat.list_stacks")
|
||||
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_create_stack(self, mock_clients):
|
||||
mock_clients("heat").stacks.create.return_value = {
|
||||
def test_create_stack(self):
|
||||
self.clients("heat").stacks.create.return_value = {
|
||||
"stack": {"id": "test_id"}
|
||||
}
|
||||
mock_clients("heat").stacks.get.return_value = self.stack
|
||||
self.clients("heat").stacks.get.return_value = self.stack
|
||||
scenario = utils.HeatScenario()
|
||||
return_stack = scenario._create_stack(self.default_template,
|
||||
self.dummy_parameters,
|
||||
self.dummy_files,
|
||||
self.dummy_environment)
|
||||
args, kwargs = mock_clients("heat").stacks.create.call_args
|
||||
args, kwargs = self.clients("heat").stacks.create.call_args
|
||||
self.assertIn(self.dummy_parameters, kwargs.values())
|
||||
self.assertIn(self.default_template, kwargs.values())
|
||||
self.assertIn(self.dummy_files, kwargs.values())
|
||||
@ -84,14 +82,13 @@ class HeatScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"heat.create_stack")
|
||||
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_update_stack(self, mock_clients):
|
||||
mock_clients("heat").stacks.update.return_value = None
|
||||
def test_update_stack(self):
|
||||
self.clients("heat").stacks.update.return_value = None
|
||||
scenario = utils.HeatScenario()
|
||||
scenario._update_stack(self.stack, self.default_template,
|
||||
self.dummy_parameters, self.dummy_files,
|
||||
self.dummy_environment)
|
||||
args, kwargs = mock_clients("heat").stacks.update.call_args
|
||||
args, kwargs = self.clients("heat").stacks.update.call_args
|
||||
self.assertIn(self.dummy_parameters, kwargs.values())
|
||||
self.assertIn(self.default_template, kwargs.values())
|
||||
self.assertIn(self.dummy_files, kwargs.values())
|
||||
@ -107,11 +104,10 @@ class HeatScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"heat.update_stack")
|
||||
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_check_stack(self, mock_clients):
|
||||
def test_check_stack(self):
|
||||
scenario = utils.HeatScenario()
|
||||
scenario._check_stack(self.stack)
|
||||
mock_clients("heat").actions.check.assert_called_once_with(
|
||||
self.clients("heat").actions.check.assert_called_once_with(
|
||||
self.stack.id)
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
self.stack,
|
||||
@ -135,11 +131,10 @@ class HeatScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"heat.delete_stack")
|
||||
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_suspend_stack(self, mock_clients):
|
||||
def test_suspend_stack(self):
|
||||
scenario = utils.HeatScenario()
|
||||
scenario._suspend_stack(self.stack)
|
||||
mock_clients("heat").actions.suspend.assert_called_once_with(
|
||||
self.clients("heat").actions.suspend.assert_called_once_with(
|
||||
self.stack.id)
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
self.stack,
|
||||
@ -151,11 +146,10 @@ class HeatScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"heat.suspend_stack")
|
||||
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_resume_stack(self, mock_clients):
|
||||
def test_resume_stack(self):
|
||||
scenario = utils.HeatScenario()
|
||||
scenario._resume_stack(self.stack)
|
||||
mock_clients("heat").actions.resume.assert_called_once_with(
|
||||
self.clients("heat").actions.resume.assert_called_once_with(
|
||||
self.stack.id)
|
||||
self.wait_for.mock.assert_called_once_with(
|
||||
self.stack,
|
||||
@ -168,17 +162,16 @@ class HeatScenarioTestCase(test.TestCase):
|
||||
"heat.resume_stack")
|
||||
|
||||
|
||||
class HeatScenarioNegativeTestCase(test.TestCase):
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_failed_create_stack(self, mock_clients):
|
||||
mock_clients("heat").stacks.create.return_value = {
|
||||
class HeatScenarioNegativeTestCase(test.ClientsTestCase):
|
||||
def test_failed_create_stack(self):
|
||||
self.clients("heat").stacks.create.return_value = {
|
||||
"stack": {"id": "test_id"}
|
||||
}
|
||||
stack = mock.Mock()
|
||||
resource = mock.Mock()
|
||||
resource.stack_status = "CREATE_FAILED"
|
||||
stack.manager.get.return_value = resource
|
||||
mock_clients("heat").stacks.get.return_value = stack
|
||||
self.clients("heat").stacks.get.return_value = stack
|
||||
scenario = utils.HeatScenario()
|
||||
try:
|
||||
ex = self.assertRaises(exceptions.GetResourceErrorStatus,
|
||||
@ -187,13 +180,12 @@ class HeatScenarioNegativeTestCase(test.TestCase):
|
||||
except exceptions.TimeoutException:
|
||||
raise self.fail("Unrecognized error status")
|
||||
|
||||
@mock.patch(HEAT_UTILS + ".HeatScenario.clients")
|
||||
def test_failed_update_stack(self, mock_clients):
|
||||
def test_failed_update_stack(self):
|
||||
stack = mock.Mock()
|
||||
resource = mock.Mock()
|
||||
resource.stack_status = "UPDATE_FAILED"
|
||||
stack.manager.get.return_value = resource
|
||||
mock_clients("heat").stacks.get.return_value = stack
|
||||
self.clients("heat").stacks.get.return_value = stack
|
||||
scenario = utils.HeatScenario()
|
||||
try:
|
||||
ex = self.assertRaises(exceptions.GetResourceErrorStatus,
|
||||
|
@ -45,23 +45,18 @@ class KeystoneUtilsTestCase(test.TestCase):
|
||||
self.assertEqual(utils.is_temporary(resource), is_valid)
|
||||
|
||||
|
||||
class KeystoneScenarioTestCase(test.TestCase):
|
||||
class KeystoneScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(UTILS + "uuid.uuid4", return_value="pwd")
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name",
|
||||
return_value="abc")
|
||||
def test_user_create(self, mock_gen_name, mock_uuid4):
|
||||
user = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.create = mock.MagicMock(return_value=user)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
result = scenario._user_create()
|
||||
|
||||
self.assertEqual(user, result)
|
||||
fake_keystone.users.create.assert_called_once_with(
|
||||
self.assertEqual(
|
||||
self.admin_clients("keystone").users.create.return_value, result)
|
||||
self.admin_clients("keystone").users.create.assert_called_once_with(
|
||||
mock_gen_name.return_value,
|
||||
password=mock_uuid4.return_value,
|
||||
email=mock_gen_name.return_value + "@rally.me")
|
||||
@ -71,36 +66,26 @@ class KeystoneScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_role_create(self, mock_gen_name):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
|
||||
role = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.roles.create = mock.MagicMock(return_value=role)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
result = scenario._role_create()
|
||||
|
||||
self.assertEqual(role, result)
|
||||
fake_keystone.roles.create.assert_called_once_with(name)
|
||||
self.assertEqual(
|
||||
self.admin_clients("keystone").roles.create.return_value, result)
|
||||
self.admin_clients("keystone").roles.create.assert_called_once_with(
|
||||
mock_gen_name.return_value)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_role")
|
||||
|
||||
def test_list_roles_for_user(self):
|
||||
user = mock.MagicMock()
|
||||
tenant = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.roles.roles_for_user = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
|
||||
scenario._list_roles_for_user(user, tenant)
|
||||
|
||||
fake_keystone.roles.roles_for_user.assert_called_once_with(user,
|
||||
tenant)
|
||||
self.admin_clients(
|
||||
"keystone").roles.roles_for_user.assert_called_once_with(user,
|
||||
tenant)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.list_roles")
|
||||
|
||||
@ -108,17 +93,14 @@ class KeystoneScenarioTestCase(test.TestCase):
|
||||
user = mock.MagicMock()
|
||||
role = mock.MagicMock()
|
||||
tenant = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.roles.add_user_role = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
|
||||
scenario._role_add(user=user.id, role=role.id, tenant=tenant.id)
|
||||
|
||||
fake_keystone.roles.add_user_role.assert_called_once_with(user.id,
|
||||
role.id,
|
||||
tenant.id)
|
||||
self.admin_clients(
|
||||
"keystone").roles.add_user_role.assert_called_once_with(user.id,
|
||||
role.id,
|
||||
tenant.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.add_role")
|
||||
|
||||
@ -136,61 +118,45 @@ class KeystoneScenarioTestCase(test.TestCase):
|
||||
user = mock.MagicMock()
|
||||
role = mock.MagicMock()
|
||||
tenant = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.roles.remove_user_role = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
|
||||
scenario._role_remove(user=user, role=role, tenant=tenant)
|
||||
|
||||
fake_keystone.roles.remove_user_role.assert_called_once_with(user,
|
||||
role,
|
||||
tenant)
|
||||
self.admin_clients(
|
||||
"keystone").roles.remove_user_role.assert_called_once_with(user,
|
||||
role,
|
||||
tenant)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.remove_role")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_tenant_create(self, mock_gen_name):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
|
||||
tenant = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.create = mock.MagicMock(return_value=tenant)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
result = scenario._tenant_create()
|
||||
|
||||
self.assertEqual(tenant, result)
|
||||
fake_keystone.tenants.create.assert_called_once_with(name)
|
||||
self.assertEqual(
|
||||
self.admin_clients("keystone").tenants.create.return_value, result)
|
||||
self.admin_clients("keystone").tenants.create.assert_called_once_with(
|
||||
mock_gen_name.return_value)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_tenant")
|
||||
|
||||
@mock.patch(UTILS + "KeystoneScenario._generate_random_name")
|
||||
def test_service_create(self, mock_gen_name):
|
||||
def test_service_create(self):
|
||||
name = "abc"
|
||||
mock_gen_name.return_value = name
|
||||
service_type = name + "service_type"
|
||||
description = name + "_description"
|
||||
|
||||
service = {}
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.create = mock.MagicMock(return_value=service)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
|
||||
result = scenario._service_create(name=name,
|
||||
service_type=service_type,
|
||||
description=description)
|
||||
|
||||
self.assertEqual(service, result)
|
||||
fake_keystone.services.create.assert_called_once_with(name,
|
||||
service_type,
|
||||
description)
|
||||
self.assertEqual(
|
||||
self.admin_clients("keystone").services.create.return_value,
|
||||
result)
|
||||
self.admin_clients("keystone").services.create.assert_called_once_with(
|
||||
name, service_type, description)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_service")
|
||||
|
||||
@ -200,122 +166,85 @@ class KeystoneScenarioTestCase(test.TestCase):
|
||||
mock_gen_name.return_value = name
|
||||
|
||||
tenant = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.create = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
|
||||
scenario._users_create(tenant, users_per_tenant=1, name_length=10)
|
||||
|
||||
fake_keystone.users.create.assert_called_once_with(
|
||||
self.admin_clients("keystone").users.create.assert_called_once_with(
|
||||
name, password=name, email=name + "@rally.me",
|
||||
tenant_id=tenant.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.create_users")
|
||||
|
||||
def test_list_users(self):
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.list = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._list_users()
|
||||
fake_keystone.users.list.assert_called_once_with()
|
||||
self.admin_clients("keystone").users.list.assert_called_once_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.list_users")
|
||||
|
||||
def test_list_tenants(self):
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.list = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._list_tenants()
|
||||
fake_keystone.tenants.list.assert_called_once_with()
|
||||
self.admin_clients("keystone").tenants.list.assert_called_once_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.list_tenants")
|
||||
|
||||
def test_list_services(self):
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.list = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._list_services()
|
||||
|
||||
fake_keystone.services.list.assert_called_once_with()
|
||||
self.admin_clients("keystone").services.list.assert_called_once_with()
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.service_list")
|
||||
|
||||
def test_delete_service(self):
|
||||
service = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.delete = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._delete_service(service_id=service.id)
|
||||
|
||||
fake_keystone.services.delete.assert_called_once_with(service.id)
|
||||
self.admin_clients("keystone").services.delete.assert_called_once_with(
|
||||
service.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.delete_service")
|
||||
|
||||
def test_get_tenant(self):
|
||||
tenant = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.get = mock.MagicMock(return_value=tenant)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._get_tenant(tenant_id=tenant.id)
|
||||
|
||||
fake_keystone.tenants.get.assert_called_once_with(tenant.id)
|
||||
self.admin_clients("keystone").tenants.get.assert_called_once_with(
|
||||
tenant.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_tenant")
|
||||
|
||||
def test_get_user(self):
|
||||
user = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.get = mock.MagicMock(return_value=user)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._get_user(user_id=user.id)
|
||||
|
||||
fake_keystone.users.get.assert_called_once_with(user.id)
|
||||
self.admin_clients("keystone").users.get.assert_called_once_with(
|
||||
user.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_user")
|
||||
|
||||
def test_get_role(self):
|
||||
role = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.roles.get = mock.MagicMock(return_value=role)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._get_role(role_id=role.id)
|
||||
|
||||
fake_keystone.roles.get.assert_called_once_with(role.id)
|
||||
self.admin_clients("keystone").roles.get.assert_called_once_with(
|
||||
role.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_role")
|
||||
|
||||
def test_get_service(self):
|
||||
service = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.services.get = mock.MagicMock(return_value=service)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._get_service(service_id=service.id)
|
||||
|
||||
fake_keystone.services.get.assert_called_once_with(service.id)
|
||||
self.admin_clients("keystone").services.get.assert_called_once_with(
|
||||
service.id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.get_service")
|
||||
|
||||
@ -323,33 +252,25 @@ class KeystoneScenarioTestCase(test.TestCase):
|
||||
tenant = mock.MagicMock()
|
||||
description = tenant.name + "_description_updated_test"
|
||||
name = tenant.name + "test_updated_test"
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.tenants.update = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
|
||||
scenario = utils.KeystoneScenario()
|
||||
scenario._update_tenant(tenant=tenant, name=name,
|
||||
description=description)
|
||||
|
||||
fake_keystone.tenants.update.assert_called_once_with(tenant.id, name,
|
||||
description)
|
||||
self.admin_clients("keystone").tenants.update.assert_called_once_with(
|
||||
tenant.id, name, description)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.update_tenant")
|
||||
|
||||
def test_update_user_password(self):
|
||||
password = "pswd"
|
||||
user = mock.MagicMock()
|
||||
fake_keystone = fakes.FakeKeystoneClient()
|
||||
fake_keystone.users.update_password = mock.MagicMock()
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._keystone = fake_keystone
|
||||
scenario = utils.KeystoneScenario(admin_clients=fake_clients)
|
||||
scenario = utils.KeystoneScenario()
|
||||
|
||||
scenario._update_user_password(password=password, user_id=user.id)
|
||||
|
||||
fake_keystone.users.update_password.assert_called_once_with(user.id,
|
||||
password)
|
||||
self.admin_clients(
|
||||
"keystone").users.update_password.assert_called_once_with(user.id,
|
||||
password)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"keystone.update_user_password")
|
||||
|
||||
|
@ -13,50 +13,35 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.mistral import utils
|
||||
from tests.unit import test
|
||||
|
||||
MISTRAL_UTILS = "rally.plugins.openstack.scenarios.mistral.utils"
|
||||
|
||||
|
||||
class MistralScenarioTestCase(test.TestCase):
|
||||
class MistralScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def _test_atomic_action_timer(self, atomic_actions, name):
|
||||
action_duration = atomic_actions.get(name)
|
||||
self.assertIsNotNone(action_duration)
|
||||
self.assertIsInstance(action_duration, float)
|
||||
|
||||
@mock.patch(MISTRAL_UTILS + ".MistralScenario.clients")
|
||||
def test_list_workbooks(self, mock_clients):
|
||||
wbs_list = []
|
||||
mock_clients("mistral").workbooks.list.return_value = wbs_list
|
||||
def test_list_workbooks(self):
|
||||
scenario = utils.MistralScenario()
|
||||
return_wbs_list = scenario._list_workbooks()
|
||||
self.assertEqual(wbs_list, return_wbs_list)
|
||||
self.assertEqual(
|
||||
self.clients("mistral").workbooks.list.return_value,
|
||||
return_wbs_list)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"mistral.list_workbooks")
|
||||
|
||||
@mock.patch(MISTRAL_UTILS + ".MistralScenario.clients")
|
||||
def test_create_workbook(self, mock_clients):
|
||||
def test_create_workbook(self):
|
||||
definition = "version: \"2.0\"\nname: wb"
|
||||
mock_clients("mistral").workbooks.create.return_value = "wb"
|
||||
scenario = utils.MistralScenario()
|
||||
wb = scenario._create_workbook(definition)
|
||||
self.assertEqual("wb", wb)
|
||||
self.assertEqual(scenario._create_workbook(definition),
|
||||
self.clients("mistral").workbooks.create.return_value)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"mistral.create_workbook")
|
||||
|
||||
@mock.patch(MISTRAL_UTILS + ".MistralScenario.clients")
|
||||
def test_delete_workbook(self, mock_clients):
|
||||
wb = mock.Mock()
|
||||
wb.name = "wb"
|
||||
mock_clients("mistral").workbooks.delete.return_value = "ok"
|
||||
def test_delete_workbook(self):
|
||||
scenario = utils.MistralScenario()
|
||||
scenario._delete_workbook(wb.name)
|
||||
mock_clients("mistral").workbooks.delete.assert_called_once_with(
|
||||
wb.name
|
||||
)
|
||||
scenario._delete_workbook("wb_name")
|
||||
self.clients("mistral").workbooks.delete.assert_called_once_with(
|
||||
"wb_name")
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"mistral.delete_workbook")
|
||||
|
@ -23,7 +23,7 @@ BM_UTILS = "rally.benchmark.utils"
|
||||
MRN_UTILS = "rally.plugins.openstack.scenarios.murano.utils"
|
||||
|
||||
|
||||
class MuranoScenarioTestCase(test.TestCase):
|
||||
class MuranoScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MuranoScenarioTestCase, self).setUp()
|
||||
@ -39,20 +39,17 @@ class MuranoScenarioTestCase(test.TestCase):
|
||||
self.gfm = self.get_fm.mock
|
||||
self.useFixture(mockpatch.Patch("time.sleep"))
|
||||
|
||||
@mock.patch(MRN_UTILS + ".MuranoScenario.clients")
|
||||
def test_list_environments(self, mock_clients):
|
||||
|
||||
mock_clients("murano").environments.list.return_value = []
|
||||
def test_list_environments(self):
|
||||
self.clients("murano").environments.list.return_value = []
|
||||
scenario = utils.MuranoScenario()
|
||||
return_environments_list = scenario._list_environments()
|
||||
self.assertEqual([], return_environments_list)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"murano.list_environments")
|
||||
|
||||
@mock.patch(MRN_UTILS + ".MuranoScenario.clients")
|
||||
def test_create_environments(self, mock_clients):
|
||||
def test_create_environments(self):
|
||||
mock_create = mock.Mock(return_value="foo_env")
|
||||
mock_clients("murano").environments.create = mock_create
|
||||
self.clients("murano").environments.create = mock_create
|
||||
scenario = utils.MuranoScenario()
|
||||
create_env = scenario._create_environment("env_name")
|
||||
self.assertEqual("foo_env", create_env)
|
||||
@ -60,13 +57,12 @@ class MuranoScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"murano.create_environment")
|
||||
|
||||
@mock.patch(MRN_UTILS + ".MuranoScenario.clients")
|
||||
def test_delete_environment(self, mock_clients):
|
||||
def test_delete_environment(self):
|
||||
environment = mock.Mock(id="id")
|
||||
mock_clients("murano").environments.delete.return_value = "ok"
|
||||
self.clients("murano").environments.delete.return_value = "ok"
|
||||
scenario = utils.MuranoScenario()
|
||||
scenario._delete_environment(environment)
|
||||
mock_clients("murano").environments.delete.assert_called_once_with(
|
||||
self.clients("murano").environments.delete.assert_called_once_with(
|
||||
environment.id
|
||||
)
|
||||
|
||||
@ -78,18 +74,16 @@ class MuranoScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"murano.delete_environment")
|
||||
|
||||
@mock.patch(MRN_UTILS + ".MuranoScenario.clients")
|
||||
def test_create_session(self, mock_clients):
|
||||
mock_clients("murano").sessions.configure.return_value = "sess"
|
||||
def test_create_session(self):
|
||||
self.clients("murano").sessions.configure.return_value = "sess"
|
||||
scenario = utils.MuranoScenario()
|
||||
create_sess = scenario._create_session("id")
|
||||
self.assertEqual("sess", create_sess)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"murano.create_session")
|
||||
|
||||
@mock.patch(MRN_UTILS + ".MuranoScenario.clients")
|
||||
def test__create_service(self, mock_clients,):
|
||||
mock_clients("murano").services.post.return_value = "app"
|
||||
def test__create_service(self,):
|
||||
self.clients("murano").services.post.return_value = "app"
|
||||
mock_env = mock.Mock(id="ip")
|
||||
mock_sess = mock.Mock(id="ip")
|
||||
scenario = utils.MuranoScenario()
|
||||
@ -102,15 +96,14 @@ class MuranoScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"murano.create_service")
|
||||
|
||||
@mock.patch(MRN_UTILS + ".MuranoScenario.clients")
|
||||
def test_deploy_environment(self, mock_clients):
|
||||
def test_deploy_environment(self):
|
||||
environment = mock.Mock(id="id")
|
||||
session = mock.Mock(id="id")
|
||||
mock_clients("murano").sessions.deploy.return_value = "ok"
|
||||
self.clients("murano").sessions.deploy.return_value = "ok"
|
||||
scenario = utils.MuranoScenario()
|
||||
scenario._deploy_environment(environment, session)
|
||||
|
||||
mock_clients("murano").sessions.deploy.assert_called_once_with(
|
||||
self.clients("murano").sessions.deploy.assert_called_once_with(
|
||||
environment.id, session.id
|
||||
)
|
||||
|
||||
|
@ -22,7 +22,7 @@ NEUTRON_NETWORKS = ("rally.plugins.openstack.scenarios.neutron.network"
|
||||
".NeutronNetworks")
|
||||
|
||||
|
||||
class NeutronNetworksTestCase(test.TestCase):
|
||||
class NeutronNetworksTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(NEUTRON_NETWORKS + "._list_networks")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network")
|
||||
@ -248,9 +248,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
@mock.patch(NEUTRON_NETWORKS + "._list_routers")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
@mock.patch(NEUTRON_NETWORKS + ".clients")
|
||||
def test_create_and_list_routers(self,
|
||||
mock_clients,
|
||||
mock_create_network_and_subnets,
|
||||
mock_create_router,
|
||||
mock_list):
|
||||
@ -271,7 +269,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
}
|
||||
}
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock_clients("neutron").add_interface_router = mock.Mock()
|
||||
self.clients("neutron").add_interface_router = mock.Mock()
|
||||
router = {
|
||||
"router": {
|
||||
"name": "router-name",
|
||||
@ -290,7 +288,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
mock_create_router.assert_has_calls(
|
||||
[mock.call({})] * subnets_per_network)
|
||||
|
||||
mock_clients("neutron").add_interface_router.assert_has_calls(
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
@ -298,7 +296,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_create_router.reset_mock()
|
||||
|
||||
mock_clients("neutron").add_interface_router.reset_mock()
|
||||
self.clients("neutron").add_interface_router.reset_mock()
|
||||
mock_list.reset_mock()
|
||||
|
||||
# Custom options
|
||||
@ -317,7 +315,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
[mock.call(router_create_args)] * subnets_per_network)
|
||||
mock_clients("neutron").add_interface_router.assert_has_calls(
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
@ -327,9 +325,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
@mock.patch(NEUTRON_NETWORKS + "._update_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
@mock.patch(NEUTRON_NETWORKS + ".clients")
|
||||
def test_create_and_update_routers(self,
|
||||
mock_clients,
|
||||
mock_create_network_and_subnets,
|
||||
mock_create_router,
|
||||
mock_update_router):
|
||||
@ -361,7 +357,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
}
|
||||
mock_create_router.return_value = router
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock_clients("neutron").add_interface_router = mock.Mock()
|
||||
self.clients("neutron").add_interface_router = mock.Mock()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_update_routers(
|
||||
@ -374,7 +370,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
[mock.call({})] * subnets_per_network)
|
||||
mock_clients("neutron").add_interface_router.assert_has_calls(
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
@ -385,7 +381,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_create_router.reset_mock()
|
||||
mock_clients("neutron").add_interface_router.reset_mock()
|
||||
self.clients("neutron").add_interface_router.reset_mock()
|
||||
mock_update_router.reset_mock()
|
||||
|
||||
# Custom options
|
||||
@ -405,7 +401,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
[mock.call(router_create_args)] * subnets_per_network)
|
||||
mock_clients("neutron").add_interface_router.assert_has_calls(
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
@ -417,9 +413,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
@mock.patch(NEUTRON_NETWORKS + "._delete_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_router")
|
||||
@mock.patch(NEUTRON_NETWORKS + "._create_network_and_subnets")
|
||||
@mock.patch(NEUTRON_NETWORKS + ".clients")
|
||||
def test_create_and_delete_routers(self,
|
||||
mock_clients,
|
||||
mock_create_network_and_subnets,
|
||||
mock_create_router,
|
||||
mock_delete_router):
|
||||
@ -448,7 +442,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_router.return_value = router
|
||||
mock_create_network_and_subnets.return_value = (net, [subnet])
|
||||
mock_clients("neutron").add_interface_router = mock.Mock()
|
||||
self.clients("neutron").add_interface_router = mock.Mock()
|
||||
|
||||
# Default options
|
||||
scenario.create_and_delete_routers(
|
||||
@ -460,7 +454,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
[mock.call({})] * subnets_per_network)
|
||||
mock_clients("neutron").add_interface_router.assert_has_calls(
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
@ -470,7 +464,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_network_and_subnets.reset_mock()
|
||||
mock_create_router.reset_mock()
|
||||
mock_clients("neutron").add_interface_router.reset_mock()
|
||||
self.clients("neutron").add_interface_router.reset_mock()
|
||||
mock_delete_router.reset_mock()
|
||||
|
||||
# Custom options
|
||||
@ -489,7 +483,7 @@ class NeutronNetworksTestCase(test.TestCase):
|
||||
|
||||
mock_create_router.assert_has_calls(
|
||||
[mock.call(router_create_args)] * subnets_per_network)
|
||||
mock_clients("neutron").add_interface_router.assert_has_calls(
|
||||
self.clients("neutron").add_interface_router.assert_has_calls(
|
||||
[mock.call(router["router"]["id"],
|
||||
{"subnet_id": subnet["subnet"]["id"]})
|
||||
] * subnets_per_network)
|
||||
|
@ -16,60 +16,56 @@
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.neutron import utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
NEUTRON_UTILS = "rally.plugins.openstack.scenarios.neutron.utils."
|
||||
|
||||
|
||||
class NeutronScenarioTestCase(test.TestCase):
|
||||
class NeutronScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NeutronScenarioTestCase, self).setUp()
|
||||
self.network = mock.Mock()
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_create_network(self, mock_clients, mock_random_name):
|
||||
def test_create_network(self, mock_random_name):
|
||||
neutron_scenario = utils.NeutronScenario()
|
||||
explicit_name = "explicit_name"
|
||||
random_name = "random_name"
|
||||
mock_random_name.return_value = random_name
|
||||
mock_clients("neutron").create_network.return_value = self.network
|
||||
self.clients("neutron").create_network.return_value = self.network
|
||||
|
||||
# Network name is specified
|
||||
network_data = {"name": explicit_name, "admin_state_up": False}
|
||||
expected_network_data = {"network": network_data}
|
||||
network = neutron_scenario._create_network(network_data)
|
||||
mock_clients("neutron").create_network.assert_called_once_with(
|
||||
self.clients("neutron").create_network.assert_called_once_with(
|
||||
expected_network_data)
|
||||
self.assertEqual(self.network, network)
|
||||
self._test_atomic_action_timer(neutron_scenario.atomic_actions(),
|
||||
"neutron.create_network")
|
||||
|
||||
mock_clients("neutron").create_network.reset_mock()
|
||||
self.clients("neutron").create_network.reset_mock()
|
||||
|
||||
# Network name is random generated
|
||||
network_data = {"admin_state_up": False}
|
||||
expected_network_data["network"]["name"] = random_name
|
||||
network = neutron_scenario._create_network(network_data)
|
||||
mock_clients("neutron").create_network.assert_called_once_with(
|
||||
self.clients("neutron").create_network.assert_called_once_with(
|
||||
expected_network_data)
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_list_networks(self, mock_clients):
|
||||
def test_list_networks(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
networks_list = []
|
||||
networks_dict = {"networks": networks_list}
|
||||
mock_clients("neutron").list_networks.return_value = networks_dict
|
||||
self.clients("neutron").list_networks.return_value = networks_dict
|
||||
return_networks_list = scenario._list_networks()
|
||||
self.assertEqual(networks_list, return_networks_list)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.list_networks")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_update_network(self, mock_clients):
|
||||
def test_update_network(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
expected_network = {
|
||||
"network": {
|
||||
@ -77,20 +73,19 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
"admin_state_up": False
|
||||
}
|
||||
}
|
||||
mock_clients("neutron").update_network.return_value = expected_network
|
||||
self.clients("neutron").update_network.return_value = expected_network
|
||||
|
||||
network = {"network": {"name": "network-name", "id": "network-id"}}
|
||||
network_update_args = {"name": "_updated", "admin_state_up": False}
|
||||
|
||||
result_network = scenario._update_network(network, network_update_args)
|
||||
mock_clients("neutron").update_network.assert_called_once_with(
|
||||
self.clients("neutron").update_network.assert_called_once_with(
|
||||
network["network"]["id"], expected_network)
|
||||
self.assertEqual(result_network, expected_network)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.update_network")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_delete_network(self, mock_clients):
|
||||
def test_delete_network(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
|
||||
network_create_args = {}
|
||||
@ -101,8 +96,7 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
|
||||
@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):
|
||||
def test_create_subnet(self, mock_random_name):
|
||||
scenario = utils.NeutronScenario()
|
||||
network_id = "fake-id"
|
||||
start_cidr = "192.168.0.0/24"
|
||||
@ -120,25 +114,24 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
# Default options
|
||||
subnet_data = {"network_id": network_id}
|
||||
scenario._create_subnet(network, subnet_data, start_cidr)
|
||||
mock_clients("neutron").create_subnet.assert_called_once_with(
|
||||
self.clients("neutron").create_subnet.assert_called_once_with(
|
||||
expected_subnet_data)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.create_subnet")
|
||||
|
||||
mock_clients("neutron").create_subnet.reset_mock()
|
||||
self.clients("neutron").create_subnet.reset_mock()
|
||||
|
||||
# Custom options
|
||||
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)
|
||||
mock_clients("neutron").create_subnet.assert_called_once_with(
|
||||
self.clients("neutron").create_subnet.assert_called_once_with(
|
||||
expected_subnet_data)
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_list_subnets(self, mock_clients):
|
||||
def test_list_subnets(self):
|
||||
subnets = [{"name": "fake1"}, {"name": "fake2"}]
|
||||
mock_clients("neutron").list_subnets.return_value = {
|
||||
self.clients("neutron").list_subnets.return_value = {
|
||||
"subnets": subnets
|
||||
}
|
||||
scenario = utils.NeutronScenario()
|
||||
@ -147,8 +140,7 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.list_subnets")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_update_subnet(self, mock_clients):
|
||||
def test_update_subnet(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
expected_subnet = {
|
||||
"subnet": {
|
||||
@ -156,20 +148,19 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
"enable_dhcp": False
|
||||
}
|
||||
}
|
||||
mock_clients("neutron").update_subnet.return_value = expected_subnet
|
||||
self.clients("neutron").update_subnet.return_value = expected_subnet
|
||||
|
||||
subnet = {"subnet": {"name": "subnet-name", "id": "subnet-id"}}
|
||||
subnet_update_args = {"name": "_updated", "enable_dhcp": False}
|
||||
|
||||
result_subnet = scenario._update_subnet(subnet, subnet_update_args)
|
||||
mock_clients("neutron").update_subnet.assert_called_once_with(
|
||||
self.clients("neutron").update_subnet.assert_called_once_with(
|
||||
subnet["subnet"]["id"], expected_subnet)
|
||||
self.assertEqual(result_subnet, expected_subnet)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.update_subnet")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_delete_subnet(self, mock_clients):
|
||||
def test_delete_subnet(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
|
||||
network = scenario._create_network({})
|
||||
@ -180,43 +171,40 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
"neutron.delete_subnet")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_create_router(self, mock_clients, mock_random_name):
|
||||
def test_create_router(self, mock_random_name):
|
||||
scenario = utils.NeutronScenario()
|
||||
router = mock.Mock()
|
||||
explicit_name = "explicit_name"
|
||||
random_name = "random_name"
|
||||
mock_random_name.return_value = random_name
|
||||
mock_clients("neutron").create_router.return_value = router
|
||||
self.clients("neutron").create_router.return_value = router
|
||||
|
||||
# Default options
|
||||
result_router = scenario._create_router({})
|
||||
mock_clients("neutron").create_router.assert_called_once_with(
|
||||
self.clients("neutron").create_router.assert_called_once_with(
|
||||
{"router": {"name": random_name}})
|
||||
self.assertEqual(result_router, router)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.create_router")
|
||||
|
||||
mock_clients("neutron").create_router.reset_mock()
|
||||
self.clients("neutron").create_router.reset_mock()
|
||||
|
||||
# Custom options
|
||||
router_data = {"name": explicit_name, "admin_state_up": True}
|
||||
result_router = scenario._create_router(router_data)
|
||||
mock_clients("neutron").create_router.assert_called_once_with(
|
||||
self.clients("neutron").create_router.assert_called_once_with(
|
||||
{"router": router_data})
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_list_routers(self, mock_clients):
|
||||
def test_list_routers(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
routers = [mock.Mock()]
|
||||
mock_clients("neutron").list_routers.return_value = {
|
||||
self.clients("neutron").list_routers.return_value = {
|
||||
"routers": routers}
|
||||
self.assertEqual(routers, scenario._list_routers())
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.list_routers")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_update_router(self, mock_clients):
|
||||
def test_update_router(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
expected_router = {
|
||||
"router": {
|
||||
@ -224,7 +212,7 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
"admin_state_up": False
|
||||
}
|
||||
}
|
||||
mock_clients("neutron").update_router.return_value = expected_router
|
||||
self.clients("neutron").update_router.return_value = expected_router
|
||||
|
||||
router = {
|
||||
"router": {
|
||||
@ -236,31 +224,29 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
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(
|
||||
self.clients("neutron").update_router.assert_called_once_with(
|
||||
router["router"]["id"], expected_router)
|
||||
self.assertEqual(result_router, expected_router)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.update_router")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_delete_router(self, mock_clients):
|
||||
def test_delete_router(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
router = scenario._create_router({})
|
||||
scenario._delete_router(router)
|
||||
mock_clients("neutron").delete_router.assert_called_once_with(
|
||||
self.clients("neutron").delete_router.assert_called_once_with(
|
||||
router["router"]["id"])
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.delete_router")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_remove_interface_router(self, mock_clients):
|
||||
def test_remove_interface_router(self):
|
||||
subnet = {"name": "subnet-name", "id": "subnet-id"}
|
||||
router_data = {"id": 1}
|
||||
scenario = utils.NeutronScenario()
|
||||
router = scenario._create_router(router_data)
|
||||
scenario._add_interface_router(subnet, router)
|
||||
scenario._remove_interface_router(subnet, router)
|
||||
mock_remove_router = mock_clients("neutron").remove_interface_router
|
||||
mock_remove_router = self.clients("neutron").remove_interface_router
|
||||
mock_remove_router.assert_called_once_with(
|
||||
router["id"], {"subnet_id": subnet["id"]})
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
@ -271,8 +257,7 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
self.assertEqual(utils.NeutronScenario.SUBNET_IP_VERSION, 4)
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario._generate_random_name")
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_create_port(self, mock_clients, mock_rand_name):
|
||||
def test_create_port(self, mock_rand_name):
|
||||
scenario = utils.NeutronScenario()
|
||||
|
||||
net_id = "network-id"
|
||||
@ -289,31 +274,29 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
# Defaults
|
||||
port_create_args = {}
|
||||
scenario._create_port(net, port_create_args)
|
||||
mock_clients("neutron"
|
||||
self.clients("neutron"
|
||||
).create_port.assert_called_once_with(expected_port_args)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.create_port")
|
||||
|
||||
mock_clients("neutron").create_port.reset_mock()
|
||||
self.clients("neutron").create_port.reset_mock()
|
||||
|
||||
# Custom options
|
||||
port_args = {"admin_state_up": True}
|
||||
expected_port_args["port"].update(port_args)
|
||||
scenario._create_port(net, port_args)
|
||||
mock_clients("neutron"
|
||||
self.clients("neutron"
|
||||
).create_port.assert_called_once_with(expected_port_args)
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_list_ports(self, mock_clients):
|
||||
def test_list_ports(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
ports = [{"name": "port1"}, {"name": "port2"}]
|
||||
mock_clients("neutron").list_ports.return_value = {"ports": ports}
|
||||
self.clients("neutron").list_ports.return_value = {"ports": ports}
|
||||
self.assertEqual(ports, scenario._list_ports())
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.list_ports")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_update_port(self, mock_clients):
|
||||
def test_update_port(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
expected_port = {
|
||||
"port": {
|
||||
@ -323,7 +306,7 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
"device_owner": "dummy_owner"
|
||||
}
|
||||
}
|
||||
mock_clients("neutron").update_port.return_value = expected_port
|
||||
self.clients("neutron").update_port.return_value = expected_port
|
||||
|
||||
port = {
|
||||
"port": {
|
||||
@ -340,14 +323,13 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
result_port = scenario._update_port(port, port_update_args)
|
||||
mock_clients("neutron").update_port.assert_called_once_with(
|
||||
self.clients("neutron").update_port.assert_called_once_with(
|
||||
port["port"]["id"], expected_port)
|
||||
self.assertEqual(result_port, expected_port)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"neutron.update_port")
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "NeutronScenario.clients")
|
||||
def test_delete_port(self, mock_clients):
|
||||
def test_delete_port(self):
|
||||
scenario = utils.NeutronScenario()
|
||||
|
||||
network = scenario._create_network({})
|
||||
@ -409,9 +391,12 @@ class NeutronScenarioTestCase(test.TestCase):
|
||||
{"allocation_pools": []},
|
||||
"10.10.10.0/24")] * subnets_per_network)
|
||||
|
||||
|
||||
class NeutronScenarioFunctionalTestCase(test.FakeClientsTestCase):
|
||||
|
||||
@mock.patch(NEUTRON_UTILS + "network_wrapper.generate_cidr")
|
||||
def test_functional_create_network_and_subnets(self, mock_generate_cidr):
|
||||
scenario = utils.NeutronScenario(clients=fakes.FakeClients())
|
||||
scenario = utils.NeutronScenario()
|
||||
network_create_args = {"name": "foo_network"}
|
||||
subnet_create_args = {}
|
||||
subnets_per_network = 5
|
||||
|
@ -16,8 +16,6 @@
|
||||
import mock
|
||||
|
||||
from rally import exceptions as rally_exceptions
|
||||
from rally import objects
|
||||
from rally import osclients
|
||||
from rally.plugins.openstack.scenarios.nova import servers
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
@ -27,7 +25,7 @@ NOVA_SERVERS_MODULE = "rally.plugins.openstack.scenarios.nova.servers"
|
||||
NOVA_SERVERS = NOVA_SERVERS_MODULE + ".NovaServers"
|
||||
|
||||
|
||||
class NovaServersTestCase(test.TestCase):
|
||||
class NovaServersTestCase(test.ClientsTestCase):
|
||||
|
||||
def test_boot_rescue_unrescue(self):
|
||||
actions = [{"rescue_unrescue": 5}]
|
||||
@ -202,10 +200,7 @@ class NovaServersTestCase(test.TestCase):
|
||||
scenario._delete_server.assert_called_once_with(fake_server,
|
||||
force=False)
|
||||
|
||||
@mock.patch(NOVA_SERVERS_MODULE + ".NovaServers.clients")
|
||||
def test_boot_and_delete_multiple_servers(self, mock_nova_clients):
|
||||
mock_nova_clients.return_value = fakes.FakeNovaClient()
|
||||
|
||||
def test_boot_and_delete_multiple_servers(self):
|
||||
scenario = servers.NovaServers()
|
||||
scenario._boot_servers = mock.Mock()
|
||||
scenario._delete_servers = mock.Mock()
|
||||
@ -323,17 +318,10 @@ class NovaServersTestCase(test.TestCase):
|
||||
scenario._delete_server.assert_called_once_with(fake_server,
|
||||
force=False)
|
||||
|
||||
def _prepare_boot(self, mock_osclients, nic=None, assert_nic=False):
|
||||
def _prepare_boot(self, nic=None, assert_nic=False):
|
||||
fake_server = mock.MagicMock()
|
||||
|
||||
fc = fakes.FakeClients()
|
||||
mock_osclients.Clients.return_value = fc
|
||||
nova = fakes.FakeNovaClient()
|
||||
fc.nova = lambda: nova
|
||||
|
||||
user_endpoint = objects.Endpoint("url", "user", "password", "tenant")
|
||||
clients = osclients.Clients(user_endpoint)
|
||||
scenario = servers.NovaServers(clients=clients)
|
||||
scenario = servers.NovaServers()
|
||||
|
||||
scenario._boot_server = mock.MagicMock(return_value=fake_server)
|
||||
scenario._generate_random_name = mock.MagicMock(return_value="name")
|
||||
@ -345,35 +333,24 @@ class NovaServersTestCase(test.TestCase):
|
||||
if nic:
|
||||
kwargs["nics"] = nic
|
||||
if assert_nic:
|
||||
nova.networks.create("net-1")
|
||||
self.clients("nova").networks.create("net-1")
|
||||
expected_kwargs["nics"] = nic or [{"net-id": "net-2"}]
|
||||
|
||||
print(kwargs)
|
||||
print(expected_kwargs)
|
||||
|
||||
return scenario, kwargs, expected_kwargs
|
||||
|
||||
def _verify_boot_server(self, mock_osclients, nic=None, assert_nic=False):
|
||||
def _verify_boot_server(self, nic=None, assert_nic=False):
|
||||
scenario, kwargs, expected_kwargs = self._prepare_boot(
|
||||
mock_osclients=mock_osclients,
|
||||
nic=nic, assert_nic=assert_nic)
|
||||
|
||||
scenario.boot_server("img", 0, **kwargs)
|
||||
scenario._boot_server.assert_called_once_with(
|
||||
"img", 0, auto_assign_nic=False, **expected_kwargs)
|
||||
|
||||
@mock.patch("rally.plugins.openstack.scenarios"
|
||||
".nova.servers.NovaServers.clients")
|
||||
@mock.patch("rally.benchmark.runner.osclients")
|
||||
def test_boot_server_no_nics(self, mock_osclients, mock_nova_clients):
|
||||
mock_nova_clients.return_value = fakes.FakeNovaClient()
|
||||
self._verify_boot_server(mock_osclients=mock_osclients,
|
||||
nic=None, assert_nic=False)
|
||||
def test_boot_server_no_nics(self):
|
||||
self._verify_boot_server(nic=None, assert_nic=False)
|
||||
|
||||
@mock.patch("rally.benchmark.runner.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)
|
||||
def test_boot_server_with_nic(self):
|
||||
self._verify_boot_server(nic=[{"net-id": "net-1"}], assert_nic=True)
|
||||
|
||||
def test_snapshot_server(self):
|
||||
fake_server = object()
|
||||
|
@ -29,7 +29,7 @@ SCN = "rally.benchmark.scenarios.base"
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class NovaScenarioTestCase(test.TestCase):
|
||||
class NovaScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(NovaScenarioTestCase, self).setUp()
|
||||
@ -86,10 +86,9 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
check_interval=chk_interval,
|
||||
timeout=time_out)
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__list_servers(self, mock_clients):
|
||||
def test__list_servers(self):
|
||||
servers_list = []
|
||||
mock_clients("nova").servers.list.return_value = servers_list
|
||||
self.clients("nova").servers.list.return_value = servers_list
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_servers_list = nova_scenario._list_servers(True)
|
||||
self.assertEqual(servers_list, return_servers_list)
|
||||
@ -98,9 +97,8 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__boot_server(self, mock_clients, mock_generate_random_name):
|
||||
mock_clients("nova").servers.create.return_value = self.server
|
||||
def test__boot_server(self, mock_generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={})
|
||||
return_server = nova_scenario._boot_server("image_id",
|
||||
"flavor_id")
|
||||
@ -110,20 +108,18 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
CONF.benchmark.nova_server_boot_timeout)
|
||||
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
|
||||
self.assertEqual(self.wait_for.mock(), return_server)
|
||||
mock_clients("nova").servers.create.assert_called_once_with(
|
||||
self.clients("nova").servers.create.assert_called_once_with(
|
||||
"foo_server_name", "image_id", "flavor_id")
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.boot_server")
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__boot_server_with_network(self, mock_clients,
|
||||
mock_generate_random_name):
|
||||
mock_clients("nova").servers.create.return_value = self.server
|
||||
def test__boot_server_with_network(self, mock_generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
networks = [{"id": "foo_id", "external": False},
|
||||
{"id": "bar_id", "external": False}]
|
||||
mock_clients("nova").networks.list.return_value = networks
|
||||
self.clients("nova").networks.list.return_value = networks
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"iteration": 3,
|
||||
"config": {"users": {"tenants": 2}},
|
||||
@ -136,16 +132,15 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
CONF.benchmark.nova_server_boot_poll_interval,
|
||||
CONF.benchmark.nova_server_boot_timeout)
|
||||
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
|
||||
mock_clients("nova").servers.create.assert_called_once_with(
|
||||
self.clients("nova").servers.create.assert_called_once_with(
|
||||
"foo_server_name", "image_id", "flavor_id",
|
||||
nics=[{"net-id": "bar_id"}])
|
||||
self.assertEqual(self.wait_for.mock(), return_server)
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.boot_server")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__boot_server_with_network_exception(self, mock_clients):
|
||||
mock_clients("nova").servers.create.return_value = self.server
|
||||
def test__boot_server_with_network_exception(self):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(
|
||||
context={"tenant": {"networks": None}})
|
||||
self.assertRaises(TypeError, nova_scenario._boot_server,
|
||||
@ -154,10 +149,8 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__boot_server_with_ssh(self, mock_clients,
|
||||
mock_generate_random_name):
|
||||
mock_clients("nova").servers.create.return_value = self.server
|
||||
def test__boot_server_with_ssh(self, mock_generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "test"}}}
|
||||
)
|
||||
@ -168,7 +161,7 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
CONF.benchmark.nova_server_boot_timeout)
|
||||
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
|
||||
self.assertEqual(self.wait_for.mock(), return_server)
|
||||
mock_clients("nova").servers.create.assert_called_once_with(
|
||||
self.clients("nova").servers.create.assert_called_once_with(
|
||||
"foo_server_name", "image_id", "flavor_id",
|
||||
security_groups=["test"])
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
@ -176,10 +169,8 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__boot_server_with_sec_group(self, mock_clients,
|
||||
mock_generate_random_name):
|
||||
mock_clients("nova").servers.create.return_value = self.server
|
||||
def test__boot_server_with_sec_group(self, mock_generate_random_name):
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "new"}}}
|
||||
)
|
||||
@ -192,7 +183,7 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
CONF.benchmark.nova_server_boot_timeout)
|
||||
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
|
||||
self.assertEqual(self.wait_for.mock(), return_server)
|
||||
mock_clients("nova").servers.create.assert_called_once_with(
|
||||
self.clients("nova").servers.create.assert_called_once_with(
|
||||
"foo_server_name", "image_id", "flavor_id",
|
||||
security_groups=["test", "new"])
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
@ -200,10 +191,9 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SCN + ".Scenario._generate_random_name",
|
||||
return_value="foo_server_name")
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__boot_server_with_similar_sec_group(self, mock_clients,
|
||||
def test__boot_server_with_similar_sec_group(self,
|
||||
mock_generate_random_name):
|
||||
mock_clients("nova").servers.create.return_value = self.server
|
||||
self.clients("nova").servers.create.return_value = self.server
|
||||
nova_scenario = utils.NovaScenario(context={
|
||||
"user": {"secgroup": {"name": "test1"}}}
|
||||
)
|
||||
@ -216,7 +206,7 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
CONF.benchmark.nova_server_boot_timeout)
|
||||
self.res_is.mock.assert_has_calls([mock.call("ACTIVE")])
|
||||
self.assertEqual(self.wait_for.mock(), return_server)
|
||||
mock_clients("nova").servers.create.assert_called_once_with(
|
||||
self.clients("nova").servers.create.assert_called_once_with(
|
||||
"foo_server_name", "image_id", "flavor_id",
|
||||
security_groups=["test1"])
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
@ -294,9 +284,8 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.unshelve_server")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__create_image(self, mock_clients):
|
||||
mock_clients("nova").images.get.return_value = self.image
|
||||
def test__create_image(self):
|
||||
self.clients("nova").images.get.return_value = self.image
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_image = nova_scenario._create_image(self.server)
|
||||
self._test_assert_called_once_with(
|
||||
@ -416,8 +405,7 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.unrescue_server")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def _test_delete_servers(self, mock_clients, force=False):
|
||||
def _test_delete_servers(self, force=False):
|
||||
servers = [self.server, self.server1]
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._delete_servers(servers, force=force)
|
||||
@ -458,9 +446,8 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.delete_image")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__boot_servers(self, mock_clients):
|
||||
mock_clients("nova").servers.list.return_value = [self.server,
|
||||
def test__boot_servers(self):
|
||||
self.clients("nova").servers.list.return_value = [self.server,
|
||||
self.server1]
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._boot_servers("image", "flavor", 2)
|
||||
@ -529,10 +516,9 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
nova_scenario.check_ip_address(floating_ip, must_exist=False)
|
||||
(fake_server))
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__list_networks(self, mock_clients):
|
||||
def test__list_networks(self):
|
||||
network_list = []
|
||||
mock_clients("nova").networks.list.return_value = network_list
|
||||
self.clients("nova").networks.list.return_value = network_list
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_network_list = nova_scenario._list_networks()
|
||||
self.assertEqual(network_list, return_network_list)
|
||||
@ -558,27 +544,24 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.resize_revert")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__attach_volume(self, mock_clients):
|
||||
mock_clients("nova").volumes.create_server_volume.return_value = None
|
||||
def test__attach_volume(self):
|
||||
self.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")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__detach_volume(self, mock_clients):
|
||||
mock_clients("nova").volumes.delete_server_volume.return_value = None
|
||||
def test__detach_volume(self):
|
||||
self.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")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__live_migrate_server(self, mock_clients):
|
||||
def test__live_migrate_server(self):
|
||||
fake_host = mock.MagicMock()
|
||||
mock_clients("nova").servers.get(return_value=self.server)
|
||||
nova_scenario = utils.NovaScenario(admin_clients=mock_clients)
|
||||
self.admin_clients("nova").servers.get(return_value=self.server)
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._live_migrate(self.server,
|
||||
fake_host,
|
||||
block_migration=False,
|
||||
@ -593,14 +576,11 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.live_migrate")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.admin_clients")
|
||||
def test__find_host_to_migrate(self, mock_clients):
|
||||
def test__find_host_to_migrate(self):
|
||||
fake_server = self.server
|
||||
fake_host = {"nova-compute": {"available": True}}
|
||||
nova_client = mock.MagicMock()
|
||||
mock_clients.return_value = nova_client
|
||||
nova_client.servers.get.return_value = fake_server
|
||||
nova_client.availability_zones.list.return_value = [
|
||||
self.admin_clients("nova").servers.get.return_value = fake_server
|
||||
self.admin_clients("nova").availability_zones.list.return_value = [
|
||||
mock.MagicMock(zoneName="a",
|
||||
hosts={"a1": fake_host, "a2": fake_host,
|
||||
"a3": fake_host}),
|
||||
@ -613,17 +593,16 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
]
|
||||
setattr(fake_server, "OS-EXT-SRV-ATTR:host", "b2")
|
||||
setattr(fake_server, "OS-EXT-AZ:availability_zone", "b")
|
||||
nova_scenario = utils.NovaScenario(admin_clients=fakes.FakeClients())
|
||||
nova_scenario = utils.NovaScenario()
|
||||
|
||||
self.assertIn(
|
||||
nova_scenario._find_host_to_migrate(fake_server), ["b1", "b3"])
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__migrate_server(self, mock_clients):
|
||||
def test__migrate_server(self):
|
||||
fake_server = self.server
|
||||
setattr(fake_server, "OS-EXT-SRV-ATTR:host", "a1")
|
||||
mock_clients("nova").servers.get(return_value=fake_server)
|
||||
nova_scenario = utils.NovaScenario(admin_clients=mock_clients)
|
||||
self.clients("nova").servers.get(return_value=fake_server)
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._migrate(fake_server, skip_host_check=True)
|
||||
|
||||
self._test_assert_called_once_with(
|
||||
@ -639,9 +618,7 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
fake_server, skip_host_check=False)
|
||||
|
||||
def test__create_security_groups(self):
|
||||
clients = mock.MagicMock()
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario.clients = clients
|
||||
nova_scenario._generate_random_name = mock.MagicMock()
|
||||
|
||||
security_group_count = 5
|
||||
@ -649,20 +626,18 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
sec_groups = nova_scenario._create_security_groups(
|
||||
security_group_count)
|
||||
|
||||
self.assertEqual(security_group_count, clients.call_count)
|
||||
self.assertEqual(security_group_count, len(sec_groups))
|
||||
self.assertEqual(security_group_count,
|
||||
nova_scenario._generate_random_name.call_count)
|
||||
self.assertEqual(security_group_count,
|
||||
clients().security_groups.create.call_count)
|
||||
self.assertEqual(
|
||||
security_group_count,
|
||||
self.clients("nova").security_groups.create.call_count)
|
||||
self._test_atomic_action_timer(
|
||||
nova_scenario.atomic_actions(),
|
||||
"nova.create_%s_security_groups" % security_group_count)
|
||||
|
||||
def test__create_rules_for_security_group(self):
|
||||
clients = mock.MagicMock()
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario.clients = clients
|
||||
|
||||
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
|
||||
fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
|
||||
@ -671,80 +646,66 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
nova_scenario._create_rules_for_security_group(
|
||||
fake_secgroups, rules_per_security_group)
|
||||
|
||||
self.assertEqual(len(fake_secgroups) * rules_per_security_group,
|
||||
clients.call_count)
|
||||
self.assertEqual(len(fake_secgroups) * rules_per_security_group,
|
||||
clients().security_group_rules.create.call_count)
|
||||
self.assertEqual(
|
||||
len(fake_secgroups) * rules_per_security_group,
|
||||
self.clients("nova").security_group_rules.create.call_count)
|
||||
self._test_atomic_action_timer(
|
||||
nova_scenario.atomic_actions(),
|
||||
"nova.create_%s_rules" %
|
||||
(rules_per_security_group * len(fake_secgroups)))
|
||||
|
||||
def test__delete_security_groups(self):
|
||||
clients = mock.MagicMock()
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario.clients = clients
|
||||
|
||||
fake_secgroups = [fakes.FakeSecurityGroup(None, None, 1, "uuid1"),
|
||||
fakes.FakeSecurityGroup(None, None, 2, "uuid2")]
|
||||
|
||||
nova_scenario._delete_security_groups(fake_secgroups)
|
||||
|
||||
self.assertEqual(len(fake_secgroups), clients.call_count)
|
||||
|
||||
self.assertSequenceEqual(
|
||||
map(lambda x: mock.call(x.id), fake_secgroups),
|
||||
clients().security_groups.delete.call_args_list)
|
||||
self.clients("nova").security_groups.delete.call_args_list)
|
||||
self._test_atomic_action_timer(
|
||||
nova_scenario.atomic_actions(),
|
||||
"nova.delete_%s_security_groups" % len(fake_secgroups))
|
||||
|
||||
def test__list_security_groups(self):
|
||||
clients = mock.MagicMock()
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario.clients = clients
|
||||
|
||||
nova_scenario._list_security_groups()
|
||||
|
||||
clients.assert_called_once_with("nova")
|
||||
clients().security_groups.list.assert_called_once_with()
|
||||
self.clients("nova").security_groups.list.assert_called_once_with()
|
||||
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.list_security_groups")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__list_keypairs(self, mock_clients):
|
||||
def test__list_keypairs(self):
|
||||
keypairs_list = ["foo_keypair"]
|
||||
mock_clients("nova").keypairs.list.return_value = keypairs_list
|
||||
self.clients("nova").keypairs.list.return_value = keypairs_list
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_keypairs_list = nova_scenario._list_keypairs()
|
||||
self.assertEqual(keypairs_list, return_keypairs_list)
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.list_keypairs")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__create_keypair(self, mock_clients):
|
||||
(mock_clients("nova").keypairs.create.
|
||||
return_value.name) = self.keypair
|
||||
def test__create_keypair(self):
|
||||
self.clients("nova").keypairs.create.return_value.name = self.keypair
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_keypair = nova_scenario._create_keypair()
|
||||
self.assertEqual(self.keypair, return_keypair)
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.create_keypair")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.clients")
|
||||
def test__delete_keypair(self, mock_clients):
|
||||
def test__delete_keypair(self):
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._delete_keypair(self.keypair)
|
||||
mock_clients("nova").keypairs.delete.assert_called_once_with(
|
||||
self.clients("nova").keypairs.delete.assert_called_once_with(
|
||||
self.keypair)
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.delete_keypair")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.admin_clients")
|
||||
def test__list_floating_ips_bulk(self, mock_clients):
|
||||
def test__list_floating_ips_bulk(self):
|
||||
floating_ips_bulk_list = ["foo_floating_ips_bulk"]
|
||||
mock_clients("nova").floating_ips_bulk.list.return_value = (
|
||||
self.admin_clients("nova").floating_ips_bulk.list.return_value = (
|
||||
floating_ips_bulk_list)
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_floating_ips_bulk_list = nova_scenario._list_floating_ips_bulk()
|
||||
@ -753,14 +714,13 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
"nova.list_floating_ips_bulk")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".network_wrapper.generate_cidr")
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.admin_clients")
|
||||
def test__create_floating_ips_bulk(self, mock_clients, mock_gencidr):
|
||||
def test__create_floating_ips_bulk(self, mock_gencidr):
|
||||
fake_cidr = "10.2.0.0/24"
|
||||
fake_pool = "test1"
|
||||
fake_floating_ips_bulk = mock.MagicMock()
|
||||
fake_floating_ips_bulk.ip_range = fake_cidr
|
||||
fake_floating_ips_bulk.pool = fake_pool
|
||||
mock_clients("nova").floating_ips_bulk.create.return_value = (
|
||||
self.admin_clients("nova").floating_ips_bulk.create.return_value = (
|
||||
fake_floating_ips_bulk)
|
||||
nova_scenario = utils.NovaScenario()
|
||||
return_iprange = nova_scenario._create_floating_ips_bulk(fake_cidr)
|
||||
@ -769,21 +729,20 @@ class NovaScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.create_floating_ips_bulk")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.admin_clients")
|
||||
def test__delete_floating_ips_bulk(self, mock_clients):
|
||||
def test__delete_floating_ips_bulk(self):
|
||||
fake_cidr = "10.2.0.0/24"
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._delete_floating_ips_bulk(fake_cidr)
|
||||
mock_clients("nova").floating_ips_bulk.delete.assert_called_once_with(
|
||||
fake_cidr)
|
||||
self.admin_clients(
|
||||
"nova").floating_ips_bulk.delete.assert_called_once_with(fake_cidr)
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.delete_floating_ips_bulk")
|
||||
|
||||
@mock.patch(NOVA_UTILS + ".NovaScenario.admin_clients")
|
||||
def test__list_hypervisors(self, mock_clients):
|
||||
def test__list_hypervisors(self):
|
||||
nova_scenario = utils.NovaScenario()
|
||||
nova_scenario._list_hypervisors(detailed=False)
|
||||
mock_clients("nova").hypervisors.list.assert_called_once_with(False)
|
||||
self.admin_clients("nova").hypervisors.list.assert_called_once_with(
|
||||
False)
|
||||
self._test_atomic_action_timer(nova_scenario.atomic_actions(),
|
||||
"nova.list_hypervisors")
|
||||
|
||||
|
@ -19,7 +19,7 @@ from rally.plugins.openstack.scenarios.quotas import quotas
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
class QuotasTestCase(test.TestCase):
|
||||
class QuotasTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(QuotasTestCase, self).setUp()
|
||||
@ -56,12 +56,11 @@ class QuotasTestCase(test.TestCase):
|
||||
scenario._update_quotas.assert_called_once_with("cinder", "fake", 1024)
|
||||
scenario._delete_quotas.assert_called_once_with("cinder", "fake")
|
||||
|
||||
@mock.patch("rally.benchmark.scenarios.base.Scenario.admin_clients")
|
||||
def test_neutron_update(self, mock_clients):
|
||||
def test_neutron_update(self):
|
||||
scenario = quotas.Quotas(self.context)
|
||||
|
||||
scenario._update_quotas = mock.MagicMock()
|
||||
mock_quota_update_fn = mock_clients().update_quota
|
||||
mock_quota_update_fn = self.admin_clients("neutron").update_quota
|
||||
scenario.neutron_update(max_quota=1024)
|
||||
scenario._update_quotas.assert_called_once_with("neutron", "fake",
|
||||
1024,
|
||||
|
@ -17,14 +17,10 @@ import mock
|
||||
import six
|
||||
|
||||
from rally.plugins.openstack.scenarios.quotas import utils
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
class QuotasScenarioTestCase(test.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(QuotasScenarioTestCase, self).setUp()
|
||||
class QuotasScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
def test__update_quotas(self):
|
||||
tenant_id = "fake_tenant"
|
||||
@ -38,17 +34,15 @@ class QuotasScenarioTestCase(test.TestCase):
|
||||
"injected_files": 10,
|
||||
"cores": 10,
|
||||
}
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
fake_nova.quotas.update = mock.MagicMock(return_value=quotas)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._nova = fake_nova
|
||||
scenario = utils.QuotasScenario(admin_clients=fake_clients)
|
||||
self.admin_clients("nova").quotas.update.return_value = quotas
|
||||
scenario = utils.QuotasScenario()
|
||||
scenario._generate_quota_values = mock.MagicMock(return_value=quotas)
|
||||
|
||||
result = scenario._update_quotas("nova", tenant_id)
|
||||
|
||||
self.assertEqual(quotas, result)
|
||||
fake_nova.quotas.update.assert_called_once_with(tenant_id, **quotas)
|
||||
self.admin_clients("nova").quotas.update.assert_called_once_with(
|
||||
tenant_id, **quotas)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"quotas.update_quotas")
|
||||
|
||||
@ -64,11 +58,8 @@ class QuotasScenarioTestCase(test.TestCase):
|
||||
"injected_files": 10,
|
||||
"cores": 10,
|
||||
}
|
||||
fake_nova = fakes.FakeNovaClient()
|
||||
fake_nova.quotas.update = mock.MagicMock(return_value=quotas)
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._nova = fake_nova
|
||||
scenario = utils.QuotasScenario(admin_clients=fake_clients)
|
||||
self.admin_clients("nova").quotas.update.return_value = quotas
|
||||
scenario = utils.QuotasScenario()
|
||||
scenario._generate_quota_values = mock.MagicMock(return_value=quotas)
|
||||
|
||||
mock_quota = mock.Mock(return_value=quotas)
|
||||
@ -82,21 +73,21 @@ class QuotasScenarioTestCase(test.TestCase):
|
||||
|
||||
def test__generate_quota_values_nova(self):
|
||||
max_quota = 1024
|
||||
scenario = utils.QuotasScenario(admin_clients=fakes.FakeClients())
|
||||
scenario = utils.QuotasScenario()
|
||||
quotas = scenario._generate_quota_values(max_quota, "nova")
|
||||
for k, v in six.iteritems(quotas):
|
||||
self.assertTrue(-1 <= v <= max_quota)
|
||||
|
||||
def test__generate_quota_values_cinder(self):
|
||||
max_quota = 1024
|
||||
scenario = utils.QuotasScenario(admin_clients=fakes.FakeClients())
|
||||
scenario = utils.QuotasScenario()
|
||||
quotas = scenario._generate_quota_values(max_quota, "cinder")
|
||||
for k, v in six.iteritems(quotas):
|
||||
self.assertTrue(-1 <= v <= max_quota)
|
||||
|
||||
def test__generate_quota_values_neutron(self):
|
||||
max_quota = 1024
|
||||
scenario = utils.QuotasScenario(admin_clients=fakes.FakeClients())
|
||||
scenario = utils.QuotasScenario()
|
||||
quotas = scenario._generate_quota_values(max_quota, "neutron")
|
||||
for v in six.itervalues(quotas):
|
||||
for v1 in six.itervalues(v):
|
||||
@ -105,14 +96,10 @@ class QuotasScenarioTestCase(test.TestCase):
|
||||
|
||||
def test__delete_quotas(self):
|
||||
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 = utils.QuotasScenario()
|
||||
scenario._delete_quotas("nova", tenant_id)
|
||||
|
||||
fake_nova.quotas.delete.assert_called_once_with(tenant_id)
|
||||
self.admin_clients("nova").quotas.delete.assert_called_once_with(
|
||||
tenant_id)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"quotas.delete_quotas")
|
||||
|
@ -23,15 +23,13 @@ SAHARA_CLUSTERS = ("rally.plugins.openstack.scenarios.sahara.clusters"
|
||||
SAHARA_UTILS = "rally.plugins.openstack.scenarios.sahara.utils"
|
||||
|
||||
|
||||
class SaharaClustersTestCase(test.TestCase):
|
||||
class SaharaClustersTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(SAHARA_CLUSTERS + "._delete_cluster")
|
||||
@mock.patch(SAHARA_CLUSTERS + "._launch_cluster",
|
||||
return_value=mock.MagicMock(id=42))
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_create_and_delete_cluster(self, mock_clients, mock_launch_cluster,
|
||||
def test_create_and_delete_cluster(self, mock_launch_cluster,
|
||||
mock_delete_cluster):
|
||||
|
||||
clusters_scenario = clusters.SaharaClusters()
|
||||
|
||||
clusters_scenario.context = {
|
||||
@ -67,14 +65,10 @@ 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")
|
||||
def test_create_scale_delete_cluster(self, mock_clients,
|
||||
mock_launch_cluster,
|
||||
def test_create_scale_delete_cluster(self, mock_launch_cluster,
|
||||
mock_scale_cluster,
|
||||
mock_delete_cluster):
|
||||
|
||||
mock_sahara = mock_clients("sahara")
|
||||
mock_sahara.clusters.get.return_value = mock.MagicMock(
|
||||
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
id=42, status="active"
|
||||
)
|
||||
clusters_scenario = clusters.SaharaClusters()
|
||||
@ -108,9 +102,9 @@ class SaharaClustersTestCase(test.TestCase):
|
||||
enable_anti_affinity=False)
|
||||
|
||||
mock_scale_cluster.assert_has_calls([
|
||||
mock.call(mock_sahara.clusters.get.return_value, 1),
|
||||
mock.call(mock_sahara.clusters.get.return_value, -1),
|
||||
mock.call(self.clients("sahara").clusters.get.return_value, 1),
|
||||
mock.call(self.clients("sahara").clusters.get.return_value, -1),
|
||||
])
|
||||
|
||||
mock_delete_cluster.assert_called_once_with(
|
||||
mock_sahara.clusters.get.return_value)
|
||||
self.clients("sahara").clusters.get.return_value)
|
||||
|
@ -25,7 +25,7 @@ SAHARA_JOB = "rally.plugins.openstack.scenarios.sahara.jobs.SaharaJob"
|
||||
SAHARA_UTILS = "rally.plugins.openstack.scenarios.sahara.utils"
|
||||
|
||||
|
||||
class SaharaJobTestCase(test.TestCase):
|
||||
class SaharaJobTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SaharaJobTestCase, self).setUp()
|
||||
@ -36,12 +36,10 @@ class SaharaJobTestCase(test.TestCase):
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="job_42")
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_create_launch_job_java(self, mock_osclients, mock_run_execution,
|
||||
def test_create_launch_job_java(self, mock_run_execution,
|
||||
mock_random_name):
|
||||
|
||||
mock_sahara = mock_osclients("sahara")
|
||||
mock_sahara.jobs.create.return_value = mock.MagicMock(id="42")
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
|
||||
jobs_scenario = jobs.SaharaJob()
|
||||
|
||||
@ -59,7 +57,7 @@ class SaharaJobTestCase(test.TestCase):
|
||||
configs={"conf_key": "conf_val"},
|
||||
job_idx=0
|
||||
)
|
||||
mock_sahara.jobs.create.assert_called_once_with(
|
||||
self.clients("sahara").jobs.create.assert_called_once_with(
|
||||
name=mock_random_name.return_value,
|
||||
type="java",
|
||||
description="",
|
||||
@ -81,12 +79,10 @@ class SaharaJobTestCase(test.TestCase):
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
@mock.patch(SAHARA_JOB + "._create_output_ds",
|
||||
return_value=mock.MagicMock(id="out_42"))
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_create_launch_job_pig(self, mock_osclients, mock_create_ds,
|
||||
def test_create_launch_job_pig(self, mock_create_ds,
|
||||
mock_run_execution, mock_random_name):
|
||||
|
||||
mock_sahara = mock_osclients("sahara")
|
||||
mock_sahara.jobs.create.return_value = mock.MagicMock(id="42")
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
|
||||
jobs_scenario = jobs.SaharaJob()
|
||||
|
||||
@ -104,7 +100,7 @@ class SaharaJobTestCase(test.TestCase):
|
||||
configs={"conf_key": "conf_val"},
|
||||
job_idx=0
|
||||
)
|
||||
mock_sahara.jobs.create.assert_called_once_with(
|
||||
self.clients("sahara").jobs.create.assert_called_once_with(
|
||||
name=mock_random_name.return_value,
|
||||
type="pig",
|
||||
description="",
|
||||
@ -124,12 +120,10 @@ class SaharaJobTestCase(test.TestCase):
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="job_42")
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_create_launch_job_sequence(self, mock_osclients,
|
||||
mock_run_execution, mock_random_name):
|
||||
|
||||
mock_sahara = mock_osclients("sahara")
|
||||
mock_sahara.jobs.create.return_value = mock.MagicMock(id="42")
|
||||
def test_create_launch_job_sequence(self, mock_run_execution,
|
||||
mock_random_name):
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
|
||||
jobs_scenario = jobs.SaharaJob()
|
||||
|
||||
@ -159,8 +153,8 @@ class SaharaJobTestCase(test.TestCase):
|
||||
mains=["main_42"],
|
||||
libs=["lib_42"])
|
||||
|
||||
mock_sahara.jobs.create.assert_has_calls([jobs_create_call,
|
||||
jobs_create_call])
|
||||
self.clients("sahara").jobs.create.assert_has_calls([jobs_create_call,
|
||||
jobs_create_call])
|
||||
|
||||
mock_run_execution.assert_has_calls([
|
||||
mock.call(
|
||||
@ -183,15 +177,12 @@ class SaharaJobTestCase(test.TestCase):
|
||||
return_value="job_42")
|
||||
@mock.patch(SAHARA_JOB + "._run_job_execution")
|
||||
@mock.patch(SAHARA_JOB + "._scale_cluster")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_create_launch_job_sequence_with_scaling(self, mock_osclients,
|
||||
mock_scale,
|
||||
def test_create_launch_job_sequence_with_scaling(self, mock_scale,
|
||||
mock_run_execution,
|
||||
mock_random_name):
|
||||
|
||||
mock_sahara = mock_osclients("sahara")
|
||||
mock_sahara.jobs.create.return_value = mock.MagicMock(id="42")
|
||||
mock_sahara.clusters.get.return_value = mock.MagicMock(
|
||||
self.clients("sahara").jobs.create.return_value = mock.MagicMock(
|
||||
id="42")
|
||||
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
id="cl_42",
|
||||
status="active")
|
||||
|
||||
@ -224,8 +215,8 @@ class SaharaJobTestCase(test.TestCase):
|
||||
mains=["main_42"],
|
||||
libs=["lib_42"])
|
||||
|
||||
mock_sahara.jobs.create.assert_has_calls([jobs_create_call,
|
||||
jobs_create_call])
|
||||
self.clients("sahara").jobs.create.assert_has_calls([jobs_create_call,
|
||||
jobs_create_call])
|
||||
|
||||
je_0 = mock.call(job_id="42", cluster_id="cl_42", input_id=None,
|
||||
output_id=None, configs={"conf_key": "conf_val"},
|
||||
|
@ -28,7 +28,7 @@ CONF = cfg.CONF
|
||||
SAHARA_UTILS = "rally.plugins.openstack.scenarios.sahara.utils"
|
||||
|
||||
|
||||
class SaharaUtilsTestCase(test.TestCase):
|
||||
class SaharaUtilsTestCase(test.ClientsTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(SaharaUtilsTestCase, self).setUp()
|
||||
@ -36,10 +36,9 @@ 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")
|
||||
def test_list_node_group_templates(self, mock_clients):
|
||||
def test_list_node_group_templates(self):
|
||||
ngts = []
|
||||
mock_clients("sahara").node_group_templates.list.return_value = ngts
|
||||
self.clients("sahara").node_group_templates.list.return_value = ngts
|
||||
|
||||
scenario = utils.SaharaScenario()
|
||||
return_ngts_list = scenario._list_node_group_templates()
|
||||
@ -50,11 +49,9 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="random_name")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
@mock.patch(SAHARA_UTILS + ".sahara_consts")
|
||||
def test_create_node_group_templates(self, mock_constants, mock_clients,
|
||||
def test_create_node_group_templates(self, mock_constants,
|
||||
mock_random_name):
|
||||
|
||||
scenario = utils.SaharaScenario()
|
||||
mock_processes = {
|
||||
"test_plugin": {
|
||||
@ -92,7 +89,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
flavor_id="test_flavor",
|
||||
node_processes=["p2"]
|
||||
)]
|
||||
mock_clients("sahara").node_group_templates.create.assert_has_calls(
|
||||
self.clients("sahara").node_group_templates.create.assert_has_calls(
|
||||
create_calls)
|
||||
|
||||
self._test_atomic_action_timer(
|
||||
@ -102,15 +99,13 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
scenario.atomic_actions(),
|
||||
"sahara.create_worker_node_group_template")
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_delete_node_group_templates(self, mock_clients):
|
||||
|
||||
def test_delete_node_group_templates(self):
|
||||
scenario = utils.SaharaScenario()
|
||||
ng = mock.MagicMock(id=42)
|
||||
|
||||
scenario._delete_node_group_template(ng)
|
||||
|
||||
delete_mock = mock_clients("sahara").node_group_templates.delete
|
||||
delete_mock = self.clients("sahara").node_group_templates.delete
|
||||
delete_mock.assert_called_once_with(42)
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
@ -118,14 +113,8 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="random_name")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
@mock.patch(SAHARA_UTILS + ".sahara_consts")
|
||||
def test_launch_cluster(self, mock_constants,
|
||||
mock_clients, mock_random_name):
|
||||
|
||||
clients_values = mock.MagicMock(return_value=[consts.Service.NEUTRON])
|
||||
mock_clients.services.return_value = mock.MagicMock(
|
||||
values=clients_values)
|
||||
def test_launch_cluster(self, mock_constants, mock_random_name):
|
||||
|
||||
context = {
|
||||
"tenant": {
|
||||
@ -138,7 +127,10 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
}
|
||||
}
|
||||
|
||||
scenario = utils.SaharaScenario(context=context, clients=mock_clients)
|
||||
clients = mock.Mock(services=mock.Mock(
|
||||
return_value={"neutron": consts.Service.NEUTRON}))
|
||||
scenario = utils.SaharaScenario(context=context,
|
||||
clients=clients)
|
||||
|
||||
mock_processes = {
|
||||
"test_plugin": {
|
||||
@ -188,10 +180,10 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
mock_constants.NODE_PROCESSES = mock_processes
|
||||
mock_constants.REPLICATION_CONFIGS = mock_configs
|
||||
|
||||
mock_clients("sahara").clusters.create.return_value = mock.MagicMock(
|
||||
self.clients("sahara").clusters.create.return_value = mock.MagicMock(
|
||||
id="test_cluster_id")
|
||||
|
||||
mock_clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
status="active")
|
||||
|
||||
scenario._launch_cluster(
|
||||
@ -208,7 +200,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
node_configs={"HDFS": {"local_config": "local_value"}}
|
||||
)
|
||||
|
||||
mock_clients("sahara").clusters.create.assert_called_once_with(
|
||||
self.clients("sahara").clusters.create.assert_called_once_with(
|
||||
name="random_name",
|
||||
plugin_name="test_plugin",
|
||||
hadoop_version="test_version",
|
||||
@ -224,11 +216,8 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="random_name")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
@mock.patch(SAHARA_UTILS + ".sahara_consts")
|
||||
def test_launch_cluster_error(self, mock_constants, mock_clients,
|
||||
mock_random_name):
|
||||
|
||||
def test_launch_cluster_error(self, mock_constants, mock_random_name):
|
||||
scenario = utils.SaharaScenario(clients=mock.MagicMock())
|
||||
mock_processes = {
|
||||
"test_plugin": {
|
||||
@ -251,10 +240,10 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
mock_constants.NODE_PROCESSES = mock_processes
|
||||
mock_constants.REPLICATION_CONFIGS = mock_configs
|
||||
|
||||
mock_clients("sahara").clusters.create.return_value = mock.MagicMock(
|
||||
self.clients("sahara").clusters.create.return_value = mock.MagicMock(
|
||||
id="test_cluster_id")
|
||||
|
||||
mock_clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
status="error")
|
||||
|
||||
self.assertRaises(exceptions.SaharaClusterFailure,
|
||||
@ -270,9 +259,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
node_configs={"HDFS": {"local_config":
|
||||
"local_value"}})
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_scale_cluster(self, mock_clients):
|
||||
|
||||
def test_scale_cluster(self):
|
||||
scenario = utils.SaharaScenario()
|
||||
cluster = mock.MagicMock(id=42, node_groups=[{
|
||||
"name": "random_master",
|
||||
@ -281,7 +268,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
"name": "random_worker",
|
||||
"count": 41
|
||||
}])
|
||||
mock_clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
self.clients("sahara").clusters.get.return_value = mock.MagicMock(
|
||||
id=42,
|
||||
status="active")
|
||||
|
||||
@ -293,25 +280,22 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
}
|
||||
|
||||
scenario._scale_cluster(cluster, 1)
|
||||
mock_clients("sahara").clusters.scale.assert_called_once_with(
|
||||
self.clients("sahara").clusters.scale.assert_called_once_with(
|
||||
42, expected_scale_object)
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_delete_cluster(self, mock_clients):
|
||||
|
||||
def test_delete_cluster(self):
|
||||
scenario = utils.SaharaScenario()
|
||||
cluster = mock.MagicMock(id=42)
|
||||
mock_clients("sahara").clusters.get.side_effect = [
|
||||
self.clients("sahara").clusters.get.side_effect = [
|
||||
cluster, sahara_base.APIException()
|
||||
]
|
||||
|
||||
scenario._delete_cluster(cluster)
|
||||
|
||||
delete_mock = mock_clients("sahara").clusters.delete
|
||||
delete_mock = self.clients("sahara").clusters.delete
|
||||
delete_mock.assert_called_once_with(42)
|
||||
|
||||
cl_get_expected = mock.call(42)
|
||||
mock_clients("sahara").clusters.get.assert_has_calls([cl_get_expected,
|
||||
self.clients("sahara").clusters.get.assert_has_calls([cl_get_expected,
|
||||
cl_get_expected])
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
@ -319,9 +303,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="42")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_create_output_ds(self, mock_clients, mock_random_name):
|
||||
|
||||
def test_create_output_ds(self, mock_random_name):
|
||||
ctxt = {
|
||||
"sahara_output_conf": {
|
||||
"output_type": "hdfs",
|
||||
@ -332,7 +314,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
scenario = utils.SaharaScenario(ctxt)
|
||||
scenario._create_output_ds()
|
||||
|
||||
mock_clients("sahara").data_sources.create.assert_called_once_with(
|
||||
self.clients("sahara").data_sources.create.assert_called_once_with(
|
||||
name="42",
|
||||
description="",
|
||||
data_source_type="hdfs",
|
||||
@ -341,9 +323,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario._generate_random_name",
|
||||
return_value="42")
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_create_output_ds_swift(self, mock_clients, mock_random_name):
|
||||
|
||||
def test_create_output_ds_swift(self, mock_random_name):
|
||||
ctxt = {
|
||||
"sahara_output_conf": {
|
||||
"output_type": "swift",
|
||||
@ -355,14 +335,12 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
self.assertRaises(exceptions.RallyException,
|
||||
scenario._create_output_ds)
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_run_job_execution(self, mock_clients):
|
||||
|
||||
mock_clients("sahara").job_executions.get.side_effect = [
|
||||
def test_run_job_execution(self):
|
||||
self.clients("sahara").job_executions.get.side_effect = [
|
||||
mock.MagicMock(info={"status": "pending"}, id="42"),
|
||||
mock.MagicMock(info={"status": "SUCCESS"}, id="42")]
|
||||
|
||||
mock_clients("sahara").job_executions.create.return_value = (
|
||||
self.clients("sahara").job_executions.create.return_value = (
|
||||
mock.MagicMock(id="42"))
|
||||
|
||||
scenario = utils.SaharaScenario()
|
||||
@ -373,7 +351,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
configs={"k": "v"},
|
||||
job_idx=0)
|
||||
|
||||
mock_clients("sahara").job_executions.create.assert_called_once_with(
|
||||
self.clients("sahara").job_executions.create.assert_called_once_with(
|
||||
job_id="test_job_id",
|
||||
cluster_id="test_cluster_id",
|
||||
input_id="test_input_id",
|
||||
@ -382,18 +360,16 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
)
|
||||
|
||||
je_get_expected = mock.call("42")
|
||||
mock_clients("sahara").job_executions.get.assert_has_calls(
|
||||
self.clients("sahara").job_executions.get.assert_has_calls(
|
||||
[je_get_expected, je_get_expected]
|
||||
)
|
||||
|
||||
@mock.patch(SAHARA_UTILS + ".SaharaScenario.clients")
|
||||
def test_run_job_execution_fail(self, mock_clients):
|
||||
|
||||
mock_clients("sahara").job_executions.get.side_effect = [
|
||||
def test_run_job_execution_fail(self):
|
||||
self.clients("sahara").job_executions.get.side_effect = [
|
||||
mock.MagicMock(info={"status": "pending"}, id="42"),
|
||||
mock.MagicMock(info={"status": "killed"}, id="42")]
|
||||
|
||||
mock_clients("sahara").job_executions.create.return_value = (
|
||||
self.clients("sahara").job_executions.create.return_value = (
|
||||
mock.MagicMock(id="42"))
|
||||
|
||||
scenario = utils.SaharaScenario()
|
||||
@ -406,7 +382,7 @@ class SaharaUtilsTestCase(test.TestCase):
|
||||
configs={"k": "v"},
|
||||
job_idx=0)
|
||||
|
||||
mock_clients("sahara").job_executions.create.assert_called_once_with(
|
||||
self.clients("sahara").job_executions.create.assert_called_once_with(
|
||||
job_id="test_job_id",
|
||||
cluster_id="test_cluster_id",
|
||||
input_id="test_input_id",
|
||||
|
@ -16,11 +16,10 @@
|
||||
import mock
|
||||
|
||||
from rally.plugins.openstack.scenarios.swift import objects
|
||||
from tests.unit import fakes
|
||||
from tests.unit import test
|
||||
|
||||
|
||||
class SwiftObjectsTestCase(test.TestCase):
|
||||
class SwiftObjectsTestCase(test.ClientsTestCase):
|
||||
|
||||
def test_create_container_and_object_then_list_objects(self):
|
||||
scenario = objects.SwiftObjects()
|
||||
@ -88,7 +87,7 @@ class SwiftObjectsTestCase(test.TestCase):
|
||||
def test_functional_create_container_and_object_then_list_objects(self):
|
||||
names_list = ["AA", "BB", "CC", "DD"]
|
||||
|
||||
scenario = objects.SwiftObjects(clients=fakes.FakeClients())
|
||||
scenario = objects.SwiftObjects()
|
||||
scenario._generate_random_name = mock.MagicMock(side_effect=names_list)
|
||||
scenario._list_objects = mock.MagicMock()
|
||||
|
||||
@ -104,7 +103,7 @@ class SwiftObjectsTestCase(test.TestCase):
|
||||
def test_functional_create_container_and_object_then_delete_all(self):
|
||||
names_list = ["111", "222", "333", "444", "555"]
|
||||
|
||||
scenario = objects.SwiftObjects(clients=fakes.FakeClients())
|
||||
scenario = objects.SwiftObjects()
|
||||
scenario._generate_random_name = mock.MagicMock(side_effect=names_list)
|
||||
scenario._delete_object = mock.MagicMock()
|
||||
scenario._delete_container = mock.MagicMock()
|
||||
@ -126,7 +125,7 @@ class SwiftObjectsTestCase(test.TestCase):
|
||||
def test_functional_create_container_and_object_then_download_object(self):
|
||||
names_list = ["aaa", "bbb", "ccc", "ddd", "eee", "fff"]
|
||||
|
||||
scenario = objects.SwiftObjects(clients=fakes.FakeClients())
|
||||
scenario = objects.SwiftObjects()
|
||||
scenario._generate_random_name = mock.MagicMock(side_effect=names_list)
|
||||
scenario._download_object = mock.MagicMock()
|
||||
|
||||
|
@ -21,26 +21,24 @@ from tests.unit import test
|
||||
SWIFT_UTILS = "rally.plugins.openstack.scenarios.swift.utils"
|
||||
|
||||
|
||||
class SwiftScenarioTestCase(test.TestCase):
|
||||
class SwiftScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(SWIFT_UTILS + ".SwiftScenario.clients")
|
||||
def test__list_containers(self, mock_clients):
|
||||
def test__list_containers(self):
|
||||
headers_dict = mock.MagicMock()
|
||||
containers_list = mock.MagicMock()
|
||||
mock_clients("swift").get_account.return_value = (headers_dict,
|
||||
self.clients("swift").get_account.return_value = (headers_dict,
|
||||
containers_list)
|
||||
scenario = utils.SwiftScenario()
|
||||
|
||||
self.assertEqual((headers_dict, containers_list),
|
||||
scenario._list_containers(fargs="f"))
|
||||
kw = {"full_listing": True, "fargs": "f"}
|
||||
mock_clients("swift").get_account.assert_called_once_with(**kw)
|
||||
self.clients("swift").get_account.assert_called_once_with(**kw)
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"swift.list_containers")
|
||||
|
||||
@mock.patch(SWIFT_UTILS + ".SwiftScenario.clients")
|
||||
def test__create_container(self, mock_clients):
|
||||
def test__create_container(self):
|
||||
container_name = mock.MagicMock()
|
||||
scenario = utils.SwiftScenario()
|
||||
|
||||
@ -49,11 +47,11 @@ class SwiftScenarioTestCase(test.TestCase):
|
||||
scenario._create_container(container_name,
|
||||
public=True, fargs="f"))
|
||||
kw = {"headers": {"X-Container-Read": ".r:*,.rlistings"}, "fargs": "f"}
|
||||
mock_clients("swift").put_container.assert_called_once_with(
|
||||
self.clients("swift").put_container.assert_called_once_with(
|
||||
container_name,
|
||||
**kw)
|
||||
# name + public=True + additional header + kw
|
||||
mock_clients("swift").put_container.reset_mock()
|
||||
self.clients("swift").put_container.reset_mock()
|
||||
self.assertEqual(container_name,
|
||||
scenario._create_container(container_name,
|
||||
public=True,
|
||||
@ -62,11 +60,11 @@ class SwiftScenarioTestCase(test.TestCase):
|
||||
fargs="f"))
|
||||
kw = {"headers": {"X-Container-Read": ".r:*,.rlistings",
|
||||
"X-fake-name": "fake-value"}, "fargs": "f"}
|
||||
mock_clients("swift").put_container.assert_called_once_with(
|
||||
self.clients("swift").put_container.assert_called_once_with(
|
||||
container_name,
|
||||
**kw)
|
||||
# name + public=False + additional header + kw
|
||||
mock_clients("swift").put_container.reset_mock()
|
||||
self.clients("swift").put_container.reset_mock()
|
||||
self.assertEqual(container_name,
|
||||
scenario._create_container(container_name,
|
||||
public=False,
|
||||
@ -74,25 +72,25 @@ class SwiftScenarioTestCase(test.TestCase):
|
||||
"fake-value"},
|
||||
fargs="f"))
|
||||
kw = {"headers": {"X-fake-name": "fake-value"}, "fargs": "f"}
|
||||
mock_clients("swift").put_container.assert_called_once_with(
|
||||
self.clients("swift").put_container.assert_called_once_with(
|
||||
container_name,
|
||||
**kw)
|
||||
# name + kw
|
||||
mock_clients("swift").put_container.reset_mock()
|
||||
self.clients("swift").put_container.reset_mock()
|
||||
self.assertEqual(container_name,
|
||||
scenario._create_container(container_name, fargs="f"))
|
||||
kw = {"fargs": "f"}
|
||||
mock_clients("swift").put_container.assert_called_once_with(
|
||||
self.clients("swift").put_container.assert_called_once_with(
|
||||
container_name,
|
||||
**kw)
|
||||
# kw
|
||||
scenario._generate_random_name = mock.MagicMock(
|
||||
return_value=container_name)
|
||||
mock_clients("swift").put_container.reset_mock()
|
||||
self.clients("swift").put_container.reset_mock()
|
||||
self.assertEqual(container_name,
|
||||
scenario._create_container(fargs="f"))
|
||||
kw = {"fargs": "f"}
|
||||
mock_clients("swift").put_container.assert_called_once_with(
|
||||
self.clients("swift").put_container.assert_called_once_with(
|
||||
container_name,
|
||||
**kw)
|
||||
self.assertEqual(1, scenario._generate_random_name.call_count)
|
||||
@ -100,46 +98,43 @@ class SwiftScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"swift.create_container")
|
||||
|
||||
@mock.patch(SWIFT_UTILS + ".SwiftScenario.clients")
|
||||
def test__delete_container(self, mock_clients):
|
||||
def test__delete_container(self):
|
||||
container_name = mock.MagicMock()
|
||||
scenario = utils.SwiftScenario()
|
||||
scenario._delete_container(container_name, fargs="f")
|
||||
|
||||
kw = {"fargs": "f"}
|
||||
mock_clients("swift").delete_container.assert_called_once_with(
|
||||
self.clients("swift").delete_container.assert_called_once_with(
|
||||
container_name,
|
||||
**kw)
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"swift.delete_container")
|
||||
|
||||
@mock.patch(SWIFT_UTILS + ".SwiftScenario.clients")
|
||||
def test__list_objects(self, mock_clients):
|
||||
def test__list_objects(self):
|
||||
container_name = mock.MagicMock()
|
||||
headers_dict = mock.MagicMock()
|
||||
objects_list = mock.MagicMock()
|
||||
mock_clients("swift").get_container.return_value = (headers_dict,
|
||||
self.clients("swift").get_container.return_value = (headers_dict,
|
||||
objects_list)
|
||||
scenario = utils.SwiftScenario()
|
||||
|
||||
self.assertEqual((headers_dict, objects_list),
|
||||
scenario._list_objects(container_name, fargs="f"))
|
||||
kw = {"full_listing": True, "fargs": "f"}
|
||||
mock_clients("swift").get_container.assert_called_once_with(
|
||||
self.clients("swift").get_container.assert_called_once_with(
|
||||
container_name,
|
||||
**kw)
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"swift.list_objects")
|
||||
|
||||
@mock.patch(SWIFT_UTILS + ".SwiftScenario.clients")
|
||||
def test__upload_object(self, mock_clients):
|
||||
def test__upload_object(self):
|
||||
container_name = mock.MagicMock()
|
||||
object_name = mock.MagicMock()
|
||||
content = mock.MagicMock()
|
||||
etag = mock.MagicMock()
|
||||
mock_clients("swift").put_object.return_value = etag
|
||||
self.clients("swift").put_object.return_value = etag
|
||||
scenario = utils.SwiftScenario()
|
||||
|
||||
# container + content + name + kw
|
||||
@ -148,18 +143,18 @@ class SwiftScenarioTestCase(test.TestCase):
|
||||
object_name=object_name,
|
||||
fargs="f"))
|
||||
kw = {"fargs": "f"}
|
||||
mock_clients("swift").put_object.assert_called_once_with(
|
||||
self.clients("swift").put_object.assert_called_once_with(
|
||||
container_name, object_name,
|
||||
content, **kw)
|
||||
# container + content + kw
|
||||
scenario._generate_random_name = mock.MagicMock(
|
||||
return_value=object_name)
|
||||
mock_clients("swift").put_object.reset_mock()
|
||||
self.clients("swift").put_object.reset_mock()
|
||||
self.assertEqual((etag, object_name),
|
||||
scenario._upload_object(container_name, content,
|
||||
fargs="f"))
|
||||
kw = {"fargs": "f"}
|
||||
mock_clients("swift").put_object.assert_called_once_with(
|
||||
self.clients("swift").put_object.assert_called_once_with(
|
||||
container_name, object_name,
|
||||
content, **kw)
|
||||
self.assertEqual(1, scenario._generate_random_name.call_count)
|
||||
@ -167,35 +162,33 @@ class SwiftScenarioTestCase(test.TestCase):
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"swift.upload_object")
|
||||
|
||||
@mock.patch(SWIFT_UTILS + ".SwiftScenario.clients")
|
||||
def test__download_object(self, mock_clients):
|
||||
def test__download_object(self):
|
||||
container_name = mock.MagicMock()
|
||||
object_name = mock.MagicMock()
|
||||
headers_dict = mock.MagicMock()
|
||||
content = mock.MagicMock()
|
||||
mock_clients("swift").get_object.return_value = (headers_dict, content)
|
||||
self.clients("swift").get_object.return_value = (headers_dict, content)
|
||||
scenario = utils.SwiftScenario()
|
||||
|
||||
self.assertEqual((headers_dict, content),
|
||||
scenario._download_object(container_name, object_name,
|
||||
fargs="f"))
|
||||
kw = {"fargs": "f"}
|
||||
mock_clients("swift").get_object.assert_called_once_with(
|
||||
self.clients("swift").get_object.assert_called_once_with(
|
||||
container_name, object_name,
|
||||
**kw)
|
||||
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"swift.download_object")
|
||||
|
||||
@mock.patch(SWIFT_UTILS + ".SwiftScenario.clients")
|
||||
def test__delete_object(self, mock_clients):
|
||||
def test__delete_object(self):
|
||||
container_name = mock.MagicMock()
|
||||
object_name = mock.MagicMock()
|
||||
scenario = utils.SwiftScenario()
|
||||
scenario._delete_object(container_name, object_name, fargs="f")
|
||||
|
||||
kw = {"fargs": "f"}
|
||||
mock_clients("swift").delete_object.assert_called_once_with(
|
||||
self.clients("swift").delete_object.assert_called_once_with(
|
||||
container_name, object_name,
|
||||
**kw)
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
|
@ -21,24 +21,16 @@ from tests.unit import test
|
||||
UTILS = "rally.plugins.openstack.scenarios.zaqar.utils."
|
||||
|
||||
|
||||
class ZaqarScenarioTestCase(test.TestCase):
|
||||
class ZaqarScenarioTestCase(test.ClientsTestCase):
|
||||
|
||||
@mock.patch(UTILS + "ZaqarScenario._generate_random_name",
|
||||
return_value="kitkat")
|
||||
def test_queue_create(self, mock_gen_name):
|
||||
queue = {}
|
||||
fake_zaqar = fakes.FakeZaqarClient()
|
||||
fake_zaqar.queue = mock.MagicMock(return_value=queue)
|
||||
|
||||
fake_clients = fakes.FakeClients()
|
||||
fake_clients._zaqar = fake_zaqar
|
||||
scenario = utils.ZaqarScenario(clients=fake_clients)
|
||||
|
||||
scenario = utils.ZaqarScenario()
|
||||
result = scenario._queue_create(name_length=10)
|
||||
|
||||
self.assertEqual(queue, result)
|
||||
|
||||
fake_zaqar.queue.assert_called_once_with("kitkat")
|
||||
self.assertEqual(self.clients("zaqar").queue.return_value, result)
|
||||
self.clients("zaqar").queue.assert_called_once_with("kitkat")
|
||||
self._test_atomic_action_timer(scenario.atomic_actions(),
|
||||
"zaqar.create_queue")
|
||||
|
||||
|
@ -20,6 +20,7 @@ from oslo_config import fixture
|
||||
from oslotest import base
|
||||
|
||||
from rally import db
|
||||
from tests.unit import fakes
|
||||
|
||||
|
||||
class DatabaseFixture(fixture.Config):
|
||||
@ -55,3 +56,64 @@ class DBTestCase(TestCase):
|
||||
def setUp(self):
|
||||
super(DBTestCase, self).setUp()
|
||||
self.useFixture(DatabaseFixture())
|
||||
|
||||
|
||||
class ClientsTestCase(TestCase):
|
||||
"""Base class for Scenario tests using mocked self.clients."""
|
||||
|
||||
def client_factory(self, client_type, version=None, admin=False):
|
||||
"""Create a new client object."""
|
||||
return mock.MagicMock(client_type=client_type,
|
||||
version=version,
|
||||
admin=admin)
|
||||
|
||||
def clients(self, client_type, version=None, admin=False):
|
||||
"""Get a mocked client."""
|
||||
key = (client_type, version, admin)
|
||||
if key not in self._clients:
|
||||
self._clients[key] = self.client_factory(client_type,
|
||||
version=version,
|
||||
admin=admin)
|
||||
return self._clients[key]
|
||||
|
||||
def admin_clients(self, client_type, version=None):
|
||||
"""Get a mocked admin client."""
|
||||
return self.clients(client_type, version=version, admin=True)
|
||||
|
||||
def client_created(self, client_type, version=None, admin=False):
|
||||
"""Determine if a client has been created.
|
||||
|
||||
This can be used to see if a scenario calls
|
||||
'self.clients("foo")', without checking to see what was done
|
||||
with the client object returned by that call.
|
||||
"""
|
||||
key = (client_type, version, admin)
|
||||
return key in self._clients
|
||||
|
||||
def setUp(self):
|
||||
super(ClientsTestCase, self).setUp()
|
||||
self._clients = {}
|
||||
self._client_mocks = [
|
||||
mock.patch("rally.benchmark.scenarios.base.Scenario.clients",
|
||||
mock.Mock(side_effect=self.clients)),
|
||||
mock.patch("rally.benchmark.scenarios.base.Scenario.admin_clients",
|
||||
mock.Mock(side_effect=self.admin_clients))
|
||||
]
|
||||
for patcher in self._client_mocks:
|
||||
patcher.start()
|
||||
|
||||
def tearDown(self):
|
||||
for patcher in self._client_mocks:
|
||||
patcher.stop()
|
||||
super(ClientsTestCase, self).tearDown()
|
||||
|
||||
|
||||
class FakeClientsTestCase(ClientsTestCase):
|
||||
"""Base class for Scenario tests using fake (not mocked) self.clients."""
|
||||
|
||||
def client_factory(self, client_type, version=None, admin=False):
|
||||
return getattr(self._fake_clients, client_type)()
|
||||
|
||||
def setUp(self):
|
||||
super(FakeClientsTestCase, self).setUp()
|
||||
self._fake_clients = fakes.FakeClients()
|
||||
|
Loading…
Reference in New Issue
Block a user