'A volume that is attached becomes detached after ``detach_volume`` is
called with its ``blockdevice_id``.'

def test_detach_volume(self):

    def fail_mount(device):
        mountpoint = FilePath(self.mktemp())
        mountpoint.makedirs()
        process = Popen(['mount', device_path.path, mountpoint.path], stdout=PIPE, stderr=STDOUT)
        output = process.stdout.read()
        process.wait()
        return output
    unrelated = self.api.create_volume(dataset_id=uuid4(), size=self.minimum_allocatable_size)
    unrelated = self.api.attach_volume(unrelated.blockdevice_id, attach_to=self.this_node)
    volume = self.api.create_volume(dataset_id=uuid4(), size=self.minimum_allocatable_size)
    volume = self.api.attach_volume(volume.blockdevice_id, attach_to=self.this_node)
    device_path = self.api.get_device_path(volume.blockdevice_id)
    attached_error = fail_mount(device_path)
    self.api.detach_volume(volume.blockdevice_id)
    self.repeat_until_consistent((lambda : self.assertEqual({unrelated, volume.set(attached_to=None)}, set(self.api.list_volumes()))))
    detached_error = fail_mount(device_path)
    self.assertNotEqual(attached_error, detached_error)
