'Make sure volume can\'t be attached to more than one host.'

def test_run_attach_detach_not_multiattach_volume_for_hosts(self):

    mountpoint = '/dev/sdf'
    volume = tests_utils.create_volume(self.context, admin_metadata={'readonly': 'False'}, multiattach=False, **self.volume_params)
    volume_id = volume['id']
    self.volume.create_volume(self.context, volume)
    attachment = self.volume.attach_volume(self.context, volume_id, None, 'fake_host', mountpoint, 'rw')
    vol = db.volume_get(context.get_admin_context(), volume_id)
    self.assertEqual('in-use', vol['status'])
    self.assertFalse(vol['multiattach'])
    self.assertEqual(fields.VolumeAttachStatus.ATTACHED, attachment['attach_status'])
    self.assertEqual(mountpoint, attachment['mountpoint'])
    self.assertIsNone(attachment['instance_uuid'])
    self.assertEqual('fake-host', attachment['attached_host'])
    admin_metadata = vol['volume_admin_metadata']
    self.assertEqual(2, len(admin_metadata))
    expected = dict(readonly='False', attached_mode='rw')
    ret = {}
    for item in admin_metadata:
        ret.update({item['key']: item['value']})
    self.assertDictEqual(expected, ret)
    connector = {'initiator': 'iqn.2012-07.org.fake:01'}
    conn_info = self.volume.initialize_connection(self.context, volume, connector)
    self.assertEqual('rw', conn_info['data']['access_mode'])
    mountpoint2 = '/dev/sdx'
    self.assertRaises(exception.InvalidVolume, self.volume.attach_volume, self.context, volume_id, None, 'fake_host2', mountpoint2, 'rw')
    vol = db.volume_get(context.get_admin_context(), volume_id)
    self.assertEqual('in-use', vol['status'])
    self.assertEqual(fields.VolumeAttachStatus.ATTACHED, attachment['attach_status'])
    self.assertEqual(mountpoint, attachment['mountpoint'])
    self.assertIsNone(attachment['instance_uuid'])
    self.assertEqual('fake-host', attachment['attached_host'])
    self.assertRaises(exception.VolumeAttached, self.volume.delete_volume, self.context, volume)
    self.volume.detach_volume(self.context, volume_id, attachment['id'])
    vol = db.volume_get(self.context, volume_id)
    self.assertEqual('available', vol['status'])
    self.volume.delete_volume(self.context, volume)
    self.assertRaises(exception.VolumeNotFound, db.volume_get, self.context, volume_id)
