From fccccbce690c4e00907ac1825fac14985cba7a0c Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Tue, 14 Jul 2015 11:36:23 +0100 Subject: [PATCH 1/2] trying to understand the problem using loopback API --- flocker/node/agents/test/test_blockdevice.py | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/flocker/node/agents/test/test_blockdevice.py b/flocker/node/agents/test/test_blockdevice.py index 49b4923582..dcde8e4b2a 100644 --- a/flocker/node/agents/test/test_blockdevice.py +++ b/flocker/node/agents/test/test_blockdevice.py @@ -3266,6 +3266,47 @@ def test_missing(self): DatasetWithoutVolume(dataset_id=dataset_id), failure.value ) + def test_run_error(self): + """ + ``AttachVolume.run`` + """ + host = u"192.0.7.8" + + deployer = create_blockdevicedeployer(self, hostname=host) + api = deployer.block_device_api + + change1 = AttachVolume(dataset_id=uuid4()) + volume1 = api.create_volume( + dataset_id=change1.dataset_id, size=LOOPBACK_MINIMUM_ALLOCATABLE_SIZE + ) + + change2 = AttachVolume(dataset_id=uuid4()) + volume2 = api.create_volume( + dataset_id=change2.dataset_id, size=LOOPBACK_MINIMUM_ALLOCATABLE_SIZE + ) + + original_attach_volume = api.attach_volume + + def fake_attach_volume(blockdevice_id, attach_to): + if blockdevice_id == volume1.blockdevice_id: + 1/0 + return original_attach_volume(blockdevice_id, attach_to) + + self.patch(api, 'attach_volume', fake_attach_volume) + changes = in_parallel([change1, change2]) + + expected_volume2 = volume2.set( + attached_to=api.compute_instance_id() + ) + + def check_volumes(result): + import pdb; pdb.set_trace() + self.assertEqual([expected_volume2], api.list_volumes()) + + changing = run_state_change(changes, deployer) + changing.addBoth(check_volumes) + return changing + class AllocatedSizeTypeTests(SynchronousTestCase): """ From c9e0bb19f6bf5c869c40d0cc8de7049f8082d2cd Mon Sep 17 00:00:00 2001 From: Richard Wall Date: Tue, 14 Jul 2015 15:53:24 +0100 Subject: [PATCH 2/2] This test passes --- flocker/node/agents/test/test_blockdevice.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/flocker/node/agents/test/test_blockdevice.py b/flocker/node/agents/test/test_blockdevice.py index dcde8e4b2a..4e1399ccf1 100644 --- a/flocker/node/agents/test/test_blockdevice.py +++ b/flocker/node/agents/test/test_blockdevice.py @@ -3277,19 +3277,23 @@ def test_run_error(self): change1 = AttachVolume(dataset_id=uuid4()) volume1 = api.create_volume( - dataset_id=change1.dataset_id, size=LOOPBACK_MINIMUM_ALLOCATABLE_SIZE + dataset_id=change1.dataset_id, + size=LOOPBACK_MINIMUM_ALLOCATABLE_SIZE ) change2 = AttachVolume(dataset_id=uuid4()) volume2 = api.create_volume( - dataset_id=change2.dataset_id, size=LOOPBACK_MINIMUM_ALLOCATABLE_SIZE + dataset_id=change2.dataset_id, + size=LOOPBACK_MINIMUM_ALLOCATABLE_SIZE ) original_attach_volume = api.attach_volume def fake_attach_volume(blockdevice_id, attach_to): if blockdevice_id == volume1.blockdevice_id: - 1/0 + raise Exception( + 'Block device cannot be attached', blockdevice_id + ) return original_attach_volume(blockdevice_id, attach_to) self.patch(api, 'attach_volume', fake_attach_volume) @@ -3300,8 +3304,11 @@ def fake_attach_volume(blockdevice_id, attach_to): ) def check_volumes(result): - import pdb; pdb.set_trace() - self.assertEqual([expected_volume2], api.list_volumes()) + self.flushLoggedErrors() + self.assertEqual( + set([volume1, expected_volume2]), + set(api.list_volumes()) + ) changing = run_state_change(changes, deployer) changing.addBoth(check_volumes)