Merge "Fix cinder scenario: create nested snapshots"
This commit is contained in:
commit
d431a0b749
@ -327,25 +327,23 @@ class CinderVolumes(utils.CinderScenario,
|
||||
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)
|
||||
|
@ -291,3 +291,40 @@ class CinderServersTestCase(test.TestCase):
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user