def test_attachment_delete(self):
        """Test attachment_delete."""
        volume_params = {'status': 'available'}

        vref = tests_utils.create_volume(self.context, **volume_params)
        self.manager.create_volume(self.context, vref)
        values = {'volume_id': vref.id,
                  'volume_host': vref.host,
                  'attach_status': 'reserved',
                  'instance_uuid': fake.UUID1}
        attachment_ref = db.volume_attach(self.context, values)
        attachment_ref = db.volume_attachment_get(
            self.context,
            attachment_ref['id'])

        vref.refresh()
        expected_status = (vref.status, vref.attach_status,
                           attachment_ref.attach_status)

        self.manager.attachment_delete(self.context,
                                       attachment_ref['id'],
                                       vref)
        # Manager doesn't change the resource status. It is changed on the API
        attachment_ref = db.volume_attachment_get(self.context,
                                                  attachment_ref.id)
        vref.refresh()
        self.assertEqual(
            expected_status,
            (vref.status, vref.attach_status, attachment_ref.attach_status))
    def test_attachment_delete_remove_export_fail(self):
        """attachment_delete removes attachment on remove_export failure."""
        self.mock_object(self.manager.driver, 'remove_export',
                         side_effect=Exception)
        # Report that the connection is not shared
        self.mock_object(self.manager, '_connection_terminate',
                         return_value=False)

        vref = tests_utils.create_volume(self.context, status='in-use',
                                         attach_status='attached')
        values = {'volume_id': vref.id, 'volume_host': vref.host,
                  'attach_status': 'reserved', 'instance_uuid': fake.UUID1}
        attach = db.volume_attach(self.context, values)
        # Confirm the volume OVO has the attachment before the deletion
        vref.refresh()
        expected_vol_status = (vref.status, vref.attach_status)
        self.assertEqual(1, len(vref.volume_attachment))

        self.manager.attachment_delete(self.context, attach.id, vref)

        # Manager doesn't change the resource status. It is changed on the API
        attachment = db.volume_attachment_get(self.context, attach.id)
        self.assertEqual(attach.attach_status, attachment.attach_status)

        vref = db.volume_get(self.context, vref.id)
        self.assertEqual(expected_vol_status,
                         (vref.status, vref.attach_status))
    def test_attachment_update(self):
        """Test attachment_update."""
        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,
            'attach_mode': 'rw'
        }
        attachment_ref = db.volume_attach(self.context, values)
        with mock.patch.object(
                self.manager, '_notify_about_volume_usage'),\
                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('attaching', new_volume_ref.status)
            self.assertEqual(fields.VolumeAttachStatus.ATTACHING,
                             new_volume_ref.attach_status)
Esempio n. 4
0
    def test_attachment_update(self):
        """Test attachment_update."""
        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,
                  'attach_mode': 'rw'}
        attachment_ref = db.volume_attach(self.context, values)
        with mock.patch.object(
                self.manager, '_notify_about_volume_usage'),\
                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('attaching', new_volume_ref.status)
            self.assertEqual(fields.VolumeAttachStatus.ATTACHING,
                             new_volume_ref.attach_status)
Esempio n. 5
0
    def test_reset_attached_status(self):
        # current status is available
        volume = self._create_volume(self.ctx, {
            'provider_location': '',
            'size': 1
        })
        self.volume_api.reserve_volume(self.ctx, volume)
        mountpoint = '/dev/vdb'
        attachment = self.volume_api.attach(self.ctx, volume, fake.INSTANCE_ID,
                                            None, mountpoint, 'rw')
        # volume is attached
        volume = db.volume_get(self.ctx.elevated(), volume['id'])
        attachment = db.volume_attachment_get(self.ctx, attachment['id'])

        self.assertEqual('in-use', volume['status'])
        self.assertEqual(fields.VolumeAttachStatus.ATTACHED,
                         volume['attach_status'])
        self.assertEqual(fake.INSTANCE_ID, attachment['instance_uuid'])
        self.assertEqual(mountpoint, attachment['mountpoint'])
        self.assertEqual('attached', attachment['attach_status'])
        admin_metadata = volume['volume_admin_metadata']
        self.assertEqual(2, len(admin_metadata))
        self.assertEqual('readonly', admin_metadata[0]['key'])
        self.assertEqual('False', admin_metadata[0]['value'])
        self.assertEqual('attached_mode', admin_metadata[1]['key'])
        self.assertEqual('rw', admin_metadata[1]['value'])

        # Reset attach_status
        resp = self._issue_volume_reset(
            self.ctx, volume, {
                'status': 'available',
                'attach_status': fields.VolumeAttachStatus.DETACHED
            })
        # request is accepted
        self.assertEqual(202, resp.status_int)

        # volume is detached
        volume = db.volume_get(self.ctx, volume['id'])
        self.assertEqual('detached', volume['attach_status'])
        self.assertEqual('available', volume['status'])
        admin_metadata = volume['volume_admin_metadata']
        self.assertEqual(1, len(admin_metadata))
        self.assertEqual('readonly', admin_metadata[0]['key'])
        self.assertEqual('False', admin_metadata[0]['value'])
        self.assertRaises(exception.VolumeAttachmentNotFound,
                          db.volume_attachment_get, self.ctx, attachment['id'])
Esempio n. 6
0
    def test_reset_attached_status(self):
        # current status is available
        volume = self._create_volume(self.ctx, {
            'provider_location': '',
            'size': 1
        })
        self.volume_api.reserve_volume(self.ctx, volume)
        mountpoint = '/dev/vdb'
        attachment = self.volume_api.attach(self.ctx, volume, fake.INSTANCE_ID,
                                            None, mountpoint, 'rw')
        # volume is attached
        volume = db.volume_get(self.ctx.elevated(), volume['id'])
        attachment = db.volume_attachment_get(self.ctx, attachment['id'])

        self.assertEqual('in-use', volume['status'])
        self.assertEqual('attached', volume['attach_status'])
        self.assertEqual(fake.INSTANCE_ID, attachment['instance_uuid'])
        self.assertEqual(mountpoint, attachment['mountpoint'])
        self.assertEqual('attached', attachment['attach_status'])
        admin_metadata = volume['volume_admin_metadata']
        self.assertEqual(2, len(admin_metadata))
        self.assertEqual('readonly', admin_metadata[0]['key'])
        self.assertEqual('False', admin_metadata[0]['value'])
        self.assertEqual('attached_mode', admin_metadata[1]['key'])
        self.assertEqual('rw', admin_metadata[1]['value'])

        # Reset attach_status
        resp = self._issue_volume_reset(self.ctx, volume, {
            'status': 'available',
            'attach_status': 'detached'
        })
        # request is accepted
        self.assertEqual(202, resp.status_int)

        # volume is detached
        volume = db.volume_get(self.ctx, volume['id'])
        self.assertEqual('detached', volume['attach_status'])
        self.assertEqual('available', volume['status'])
        admin_metadata = volume['volume_admin_metadata']
        self.assertEqual(1, len(admin_metadata))
        self.assertEqual('readonly', admin_metadata[0]['key'])
        self.assertEqual('False', admin_metadata[0]['value'])
        self.assertRaises(exception.VolumeAttachmentNotFound,
                          db.volume_attachment_get, self.ctx, attachment['id'])
Esempio n. 7
0
    def test_attachment_delete(self):
        """Test attachment_delete."""
        volume_params = {'status': 'available'}

        vref = tests_utils.create_volume(self.context, **volume_params)
        self.manager.create_volume(self.context, vref)
        values = {
            'volume_id': vref.id,
            'volume_host': vref.host,
            'attach_status': 'reserved',
            'instance_uuid': fake.UUID1
        }
        attachment_ref = db.volume_attach(self.context, values)
        attachment_ref = db.volume_attachment_get(self.context,
                                                  attachment_ref['id'])
        self.manager.attachment_delete(self.context, attachment_ref['id'],
                                       vref)
        self.assertRaises(exception.VolumeAttachmentNotFound,
                          db.volume_attachment_get, self.context,
                          attachment_ref.id)
    def test_attachment_delete(self):
        """Test attachment_delete."""
        volume_params = {'status': 'available'}

        vref = tests_utils.create_volume(self.context, **volume_params)
        self.manager.create_volume(self.context, vref)
        values = {'volume_id': vref.id,
                  'volume_host': vref.host,
                  'attach_status': 'reserved',
                  'instance_uuid': fake.UUID1}
        attachment_ref = db.volume_attach(self.context, values)
        attachment_ref = db.volume_attachment_get(
            self.context,
            attachment_ref['id'])
        self.manager.attachment_delete(self.context,
                                       attachment_ref['id'],
                                       vref)
        self.assertRaises(exception.VolumeAttachmentNotFound,
                          db.volume_attachment_get,
                          self.context,
                          attachment_ref.id)
Esempio n. 9
0
    def test_attachment_update_with_readonly_volume(self, mock_update):
        mock_update.return_value = {'readonly': 'True'}
        vref = tests_utils.create_volume(self.context, **{'status':
                                                          'available'})
        self.manager.create_volume(self.context, vref)
        attachment_ref = db.volume_attach(self.context,
                                          {'volume_id': vref.id,
                                           'volume_host': vref.host,
                                           'attach_status': 'reserved',
                                           'instance_uuid': fake.UUID1})

        with mock.patch.object(self.manager,
                               '_notify_about_volume_usage',
                               return_value=None), mock.patch.object(
                self.manager, '_connection_create'):
            self.assertRaises(exception.InvalidVolumeAttachMode,
                              self.manager.attachment_update,
                              self.context, vref, {}, attachment_ref.id)
            attachment = db.volume_attachment_get(self.context,
                                                  attachment_ref.id)
            self.assertEqual(fields.VolumeAttachStatus.ERROR_ATTACHING,
                             attachment['attach_status'])
    def test_attachment_update_with_readonly_volume(self, mock_update):
        mock_update.return_value = {'readonly': 'True'}
        vref = tests_utils.create_volume(self.context, **{'status':
                                                          'available'})
        self.manager.create_volume(self.context, vref)
        attachment_ref = db.volume_attach(self.context,
                                          {'volume_id': vref.id,
                                           'volume_host': vref.host,
                                           'attach_status': 'reserved',
                                           'instance_uuid': fake.UUID1})

        with mock.patch.object(self.manager,
                               '_notify_about_volume_usage',
                               return_value=None), mock.patch.object(
                self.manager, '_connection_create'):
            self.assertRaises(exception.InvalidVolumeAttachMode,
                              self.manager.attachment_update,
                              self.context, vref, {}, attachment_ref.id)
            attachment = db.volume_attachment_get(self.context,
                                                  attachment_ref.id)
            self.assertEqual(fields.VolumeAttachStatus.ERROR_ATTACHING,
                             attachment['attach_status'])
Esempio n. 11
0
    def test_reset_attached_status(self):
        # current status is available
        volume = self._create_volume(self.ctx, {"provider_location": "", "size": 1})
        self.volume_api.reserve_volume(self.ctx, volume)
        mountpoint = "/dev/vdb"
        attachment = self.volume_api.attach(self.ctx, volume, fake.INSTANCE_ID, None, mountpoint, "rw")
        # volume is attached
        volume = db.volume_get(self.ctx.elevated(), volume["id"])
        attachment = db.volume_attachment_get(self.ctx, attachment["id"])

        self.assertEqual("in-use", volume["status"])
        self.assertEqual("attached", volume["attach_status"])
        self.assertEqual(fake.INSTANCE_ID, attachment["instance_uuid"])
        self.assertEqual(mountpoint, attachment["mountpoint"])
        self.assertEqual("attached", attachment["attach_status"])
        admin_metadata = volume["volume_admin_metadata"]
        self.assertEqual(2, len(admin_metadata))
        self.assertEqual("readonly", admin_metadata[0]["key"])
        self.assertEqual("False", admin_metadata[0]["value"])
        self.assertEqual("attached_mode", admin_metadata[1]["key"])
        self.assertEqual("rw", admin_metadata[1]["value"])

        # Reset attach_status
        resp = self._issue_volume_reset(self.ctx, volume, {"status": "available", "attach_status": "detached"})
        # request is accepted
        self.assertEqual(202, resp.status_int)

        # volume is detached
        volume = db.volume_get(self.ctx, volume["id"])
        self.assertEqual("detached", volume["attach_status"])
        self.assertEqual("available", volume["status"])
        admin_metadata = volume["volume_admin_metadata"]
        self.assertEqual(1, len(admin_metadata))
        self.assertEqual("readonly", admin_metadata[0]["key"])
        self.assertEqual("False", admin_metadata[0]["value"])
        self.assertRaises(exception.VolumeAttachmentNotFound, db.volume_attachment_get, self.ctx, attachment["id"])
 def get_by_id(cls, context, id):
     db_attach = db.volume_attachment_get(context, id)
     return cls._from_db_object(context, cls(context), db_attach)
 def get_by_id(cls, context, id):
     db_attach = db.volume_attachment_get(context, id)
     return cls._from_db_object(context, cls(context), db_attach)