@given(device=device_path)
    def test_unexpected_device_discovered(self, device):
        unexpected_device = []

        # The implementation is going to look at the real system to see what
        # block devices exist.  It would be nice to have an abstraction in
        # place to easily manipulate these results for the tests.  Lacking
        # that, just grab the actual block devices from the system and then
        # drop one to make it look like that one has just appeared as a result
        # of the attach operation.
        blockdevices = _get_blockdevices()

        # But there are complex criteria for selection.  So be careful which
        # device we select so as to fool the implementation.
        for wrong_device in blockdevices:
            # Don't pick the one that's actually the right result
            if wrong_device.basename().endswith(device[-1]):
                continue

            if wrong_device.basename().startswith((b"sd", b"xvd")):
                size = _get_device_size(wrong_device.basename())
                volume = self.volume.set("size", size)
                blockdevices.remove(wrong_device)
                unexpected_device.append(wrong_device)
                break
        else:
            # Ideally we'd have more control over the implementation so we
            # wouldn't have to give up when running on a system lacking just
            # the right devices to let us exercise the code we want to
            # exercise.  Getting to that point involves fixing all of the
            # things in ebs.py like _get_blockdevices and _get_device_size that
            # pass around raw strings or FilePath instances representing
            # devices and then go off and interact directly with the underlying
            # system.
            #
            # We need control over (at least) what devices the code-under-test
            # can discover and what size it thinks they are.  Until then we
            # just have to give up.  If you can't get this test to run without
            # skipping, try adding another block device to your system (eg plug
            # in a usb device).
            #
            # With apologies,
            #  -jean-paul
            raise self.skipTest(
                "Could not find a suitable device to use as a bad device."
            )

        exception = self.assertRaises(
            AttachedUnexpectedDevice,
            _attach_volume_and_wait_for_device,
            volume=volume,
            attach_to=self.compute_id,
            attach_volume=lambda *a, **kw: None,
            detach_volume=lambda *a, **kw: None,
            device=device,
            blockdevices=blockdevices,
        )
        self.assertEqual(
            AttachedUnexpectedDevice(
                requested=FilePath(device),
                discovered=FilePath(b"/dev/").child(
                    unexpected_device.pop().basename()
                ),
            ),
            exception,
        )
After attaching the volume, if a new device path is discovered that's
dataset/ETHPy150Open ClusterHQ/flocker/flocker/node/agents/test/test_ebs.py/AttachVolumeAndWaitTests.test_unexpected_device_discovered