diff --git a/flocker/node/agents/test/test_blockdevice.py b/flocker/node/agents/test/test_blockdevice.py index 49b4923582..4e1399ccf1 100644 --- a/flocker/node/agents/test/test_blockdevice.py +++ b/flocker/node/agents/test/test_blockdevice.py @@ -3266,6 +3266,54 @@ 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: + 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) + changes = in_parallel([change1, change2]) + + expected_volume2 = volume2.set( + attached_to=api.compute_instance_id() + ) + + def check_volumes(result): + self.flushLoggedErrors() + self.assertEqual( + set([volume1, expected_volume2]), + set(api.list_volumes()) + ) + + changing = run_state_change(changes, deployer) + changing.addBoth(check_volumes) + return changing + class AllocatedSizeTypeTests(SynchronousTestCase): """