'``attach_volume`` does not attempt to use device paths that are already
assigned to volumes that have been attached outside of Flocker.'

def test_attach_when_foreign_device_has_next_device(self):

    try:
        config = get_blockdevice_config()
    except InvalidConfig as e:
        self.skipTest(str(e))
    dataset_id = uuid4()
    ec2_client = get_ec2_client_for_test(config)
    meta_client = ec2_client.connection.meta.client
    requested_volume = meta_client.create_volume(Size=1, AvailabilityZone=ec2_client.zone)
    created_volume = ec2_client.connection.Volume(requested_volume['VolumeId'])
    def clean_volume(volume):
        volume.detach_from_instance()
        _wait_for_volume_state_change(VolumeOperations.DETACH, volume)
        volume.delete()
    self.addCleanup(clean_volume, created_volume)
    _wait_for_volume_state_change(VolumeOperations.CREATE, created_volume)
    instance_id = self.api.compute_instance_id()
    device_name = _next_device().replace(u'/sd', u'/xvd')
    self.api._attach_ebs_volume(created_volume.id, instance_id, device_name)
    _wait_for_volume_state_change(VolumeOperations.ATTACH, created_volume)
    blockdevice_volume = self.api.create_volume(dataset_id=dataset_id, size=ONE_GIB)
    flocker_volume = ec2_client.connection.Volume(blockdevice_volume.blockdevice_id)
    self.addCleanup(clean_volume, flocker_volume)
    self.api.attach_volume(blockdevice_volume.blockdevice_id, instance_id)
