Skip to content

Commit

Permalink
Merge "Fix cinder scenario: create nested snapshots"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jan 26, 2015
2 parents 6c0b3c0 + e55b9c4 commit d431a0b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 11 deletions.
20 changes: 9 additions & 11 deletions rally/benchmark/scenarios/cinder/volumes.py
Expand Up @@ -327,25 +327,23 @@ def create_nested_snapshots_and_attach_volume(self,
size = random.randint(size["min"], size["max"])
nested_level = random.randint(nested_level["min"], nested_level["max"])

servers = [self.get_random_server()]
volumes = [self._create_volume(size)]
snapshots = [self._create_snapshot(volumes[0].id, False, **kwargs)]
source_vol = self._create_volume(size)
nes_objs = [(self.get_random_server(), source_vol,
self._create_snapshot(source_vol.id, False, **kwargs))]

self._attach_volume(servers[0], volumes[0])
self._attach_volume(nes_objs[0][0], nes_objs[0][1])
snapshot = nes_objs[0][2]

snapshot = snapshots[0]
for i in range(nested_level - 1):
volume = self._create_volume(size, snapshot_id=snapshot.id)
snapshot = self._create_snapshot(volume.id, False, **kwargs)
server = self.get_random_server()

servers.append(server)
volumes.append(volume)
snapshots.append(snapshot)

self._attach_volume(server, volume)

for server, volume, snapshot in zip(servers, volumes, snapshots):
nes_objs.append((server, volume, snapshot))

nes_objs.reverse()
for server, volume, snapshot in nes_objs:
self._detach_volume(server, volume)
self._delete_snapshot(snapshot)
self._delete_volume(volume)
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/benchmark/scenarios/cinder/test_volumes.py
Expand Up @@ -291,3 +291,40 @@ def test_create_nested_snapshots_and_attach_volume(self):
self.assertEqual(scenario._delete_volume.call_count, volume_count)
self.assertEqual(scenario._delete_snapshot.call_count, snapshots_count)
self.assertEqual(scenario._detach_volume.call_count, attached_count)

def test_create_nested_snapshots_calls_order(self):
fake_volume1 = mock.MagicMock()
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(

context={"user": {"tenant_id": "fake"},
"users": [{"tenant_id": "fake", "users_per_tenant": 1}],
"tenant": {"id": "fake", "name": "fake",
"servers": [fake_server.uuid]}})

scenario._attach_volume = mock.MagicMock()
scenario._detach_volume = mock.MagicMock()
scenario._delete_server = mock.MagicMock()
scenario._create_volume = mock.MagicMock(
side_effect=[fake_volume1, fake_volume2])
scenario._delete_volume = mock.MagicMock()
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})

vol_delete_calls = [mock.call(fake_volume2), mock.call(fake_volume1)]
snap_delete_calls = [mock.call(fake_snapshot2),
mock.call(fake_snapshot1)]

scenario._delete_volume.assert_has_calls(vol_delete_calls)
scenario._delete_snapshot.assert_has_calls(snap_delete_calls)

0 comments on commit d431a0b

Please sign in to comment.