'Test attachment_update.'

def test_attachment_update(self):

    volume_params = {'status': 'available'}
    connector = {'initiator': 'iqn.1993-08.org.debian:01:cad181614cec', 'ip': '192.168.1.20', 'platform': 'x86_64', 'host': 'tempest-1', 'os_type': 'linux2', 'multipath': False}
    vref = tests_utils.create_volume(self.context, **volume_params)
    self.manager.create_volume(self.context, vref)
    values = {'volume_id': vref.id, 'attached_host': vref.host, 'attach_status': 'reserved', 'instance_uuid': fake.UUID1}
    attachment_ref = db.volume_attach(self.context, values)
    with mock.patch.object(self.manager, '_notify_about_volume_usage'):
        with mock.patch.object(self.manager.driver, 'attach_volume') as mock_attach:
            expected = {'encrypted': False, 'qos_specs': None, 'access_mode': 'rw', 'driver_volume_type': 'iscsi', 'attachment_id': attachment_ref.id}
            self.assertEqual(expected, self.manager.attachment_update(self.context, vref, connector, attachment_ref.id))
            mock_attach.assert_called_once_with(self.context, vref, attachment_ref.instance_uuid, connector['host'], 'na')
            new_attachment_ref = db.volume_attachment_get(self.context, attachment_ref.id)
            self.assertEqual(attachment_ref.instance_uuid, new_attachment_ref['instance_uuid'])
            self.assertEqual(connector['host'], new_attachment_ref['attached_host'])
            self.assertEqual('na', new_attachment_ref['mountpoint'])
            self.assertEqual('rw', new_attachment_ref['attach_mode'])
            new_volume_ref = db.volume_get(self.context, vref.id)
            self.assertEqual('in-use', new_volume_ref.status)
            self.assertEqual(fields.VolumeAttachStatus.ATTACHED, new_volume_ref.attach_status)
