コード例 #1
0
 def test_volume_type_delete(self):
     volume_type = db.volume_type_create(self.ctxt, {'name':
                                                     'fake volume type'})
     volume_types.destroy(self.ctxt, volume_type['id'])
     self.assertRaises(exception.VolumeTypeNotFound,
                       volume_types.get_by_name_or_id, self.ctxt,
                       volume_type['id'])
コード例 #2
0
ファイル: types_manage.py プロジェクト: DijonLin/cinder
    def _delete(self, req, id):
        """Deletes an existing volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        try:
            vol_type = volume_types.get_volume_type(context, id)
            volume_types.destroy(context, vol_type['id'])
            notifier_info = dict(volume_types=vol_type)
            notifier_api.notify(context, 'volumeType',
                                'volume_type.delete',
                                notifier_api.INFO, notifier_info)
        except exception.VolumeTypeInUse as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_voloume_type_error(context,
                                            'volume_type.delete',
                                            notifier_err)
            msg = 'Target volume type is still in use.'
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.NotFound as err:
            notifier_err = dict(id=id, error_message=str(err))
            self._notify_voloume_type_error(context,
                                            'volume_type.delete',
                                            notifier_err)

            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=202)
コード例 #3
0
    def test_volume_type_create_then_destroy_with_non_admin(self):
        """Ensure volume types can be created and deleted by non-admin user.

        If a non-admn user is authorized at API, volume type operations
        should be permitted.
        """
        prev_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.ctxt = context.RequestContext("fake", "fake", is_admin=False)

        # create
        type_ref = volume_types.create(
            self.ctxt, self.vol_type1_name, self.vol_type1_specs, description=self.vol_type1_description
        )
        new = volume_types.get_volume_type_by_name(self.ctxt, self.vol_type1_name)
        self.assertEqual(self.vol_type1_description, new["description"])
        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(len(prev_all_vtypes) + 1, len(new_all_vtypes), "drive type was not created")

        # update
        new_type_name = self.vol_type1_name + "_updated"
        new_type_desc = self.vol_type1_description + "_updated"
        type_ref_updated = volume_types.update(self.ctxt, type_ref.id, new_type_name, new_type_desc)
        self.assertEqual(new_type_name, type_ref_updated["name"])
        self.assertEqual(new_type_desc, type_ref_updated["description"])

        # destroy
        volume_types.destroy(self.ctxt, type_ref["id"])
        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(prev_all_vtypes, new_all_vtypes, "drive type was not deleted")
コード例 #4
0
    def test_volume_type_create_then_destroy(self):
        """Ensure volume types can be created and deleted."""
        prev_all_vtypes = volume_types.get_all_types(self.ctxt)

        # create
        type_ref = volume_types.create(
            self.ctxt, self.vol_type1_name, self.vol_type1_specs, description=self.vol_type1_description
        )
        new = volume_types.get_volume_type_by_name(self.ctxt, self.vol_type1_name)

        LOG.info(_("Given data: %s"), self.vol_type1_specs)
        LOG.info(_("Result data: %s"), new)

        self.assertEqual(self.vol_type1_description, new["description"])

        for k, v in self.vol_type1_specs.items():
            self.assertEqual(v, new["extra_specs"][k], "one of fields does not match")

        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(len(prev_all_vtypes) + 1, len(new_all_vtypes), "drive type was not created")

        # update
        new_type_name = self.vol_type1_name + "_updated"
        new_type_desc = self.vol_type1_description + "_updated"
        type_ref_updated = volume_types.update(self.ctxt, type_ref.id, new_type_name, new_type_desc)
        self.assertEqual(new_type_name, type_ref_updated["name"])
        self.assertEqual(new_type_desc, type_ref_updated["description"])

        # destroy
        volume_types.destroy(self.ctxt, type_ref["id"])
        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(prev_all_vtypes, new_all_vtypes, "drive type was not deleted")
コード例 #5
0
    def test_volume_type_create_then_destroy(self):
        """Ensure volume types can be created and deleted."""
        prev_all_vtypes = volume_types.get_all_types(self.ctxt)

        type_ref = volume_types.create(self.ctxt,
                                       self.vol_type1_name,
                                       self.vol_type1_specs)
        new = volume_types.get_volume_type_by_name(self.ctxt,
                                                   self.vol_type1_name)

        LOG.info(_("Given data: %s"), self.vol_type1_specs)
        LOG.info(_("Result data: %s"), new)

        for k, v in self.vol_type1_specs.iteritems():
            self.assertEqual(v, new['extra_specs'][k],
                             'one of fields does not match')

        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(len(prev_all_vtypes) + 1,
                         len(new_all_vtypes),
                         'drive type was not created')

        volume_types.destroy(self.ctxt, type_ref['id'])
        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(prev_all_vtypes,
                         new_all_vtypes,
                         'drive type was not deleted')
コード例 #6
0
 def test_update_volume_type_name(self, mock_update_quota):
     type_ref = volume_types.create(
         self.ctxt, self.vol_type1_name, self.vol_type1_specs, description=self.vol_type1_description
     )
     new_type_name = self.vol_type1_name + "_updated"
     volume_types.update(self.ctxt, type_ref.id, new_type_name, None)
     mock_update_quota.assert_called_once_with(self.ctxt, self.vol_type1_name, new_type_name)
     volume_types.destroy(self.ctxt, type_ref.id)
コード例 #7
0
ファイル: test_volume_type.py プロジェクト: whitepages/cinder
 def test_volume_type_update(self):
     vol_type_ref = volume_types.create(self.ctxt, 'fake volume type')
     updates = dict(name = 'test_volume_type_update',
                    description = None,
                    is_public = None)
     updated_vol_type = db.volume_type_update(
         self.ctxt, vol_type_ref.id, updates)
     self.assertEqual('test_volume_type_update', updated_vol_type.name)
     volume_types.destroy(self.ctxt, vol_type_ref.id)
コード例 #8
0
 def test_volume_type_delete_with_volume_in_use(self):
     volume_type = db.volume_type_create(self.ctxt, {'name':
                                                     'fake volume type'})
     volume = db.volume_create(self.ctxt, {'volume_type_id':
                                           volume_type['id']})
     self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                       self.ctxt, volume_type['id'])
     db.volume_destroy(self.ctxt, volume['id'])
     volume_types.destroy(self.ctxt, volume_type['id'])
コード例 #9
0
    def test_volume_type_delete_with_group_in_use(self):
        volume_type = db.volume_type_create(self.ctxt, {'name':
                                                        'fake volume type'})

        group = db.group_create(self.ctxt, {})
        db.group_volume_type_mapping_create(self.ctxt, group['id'],
                                            volume_type['id'])
        self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                          self.ctxt, volume_type['id'])
        db.group_destroy(self.ctxt, group['id'])
        volume_types.destroy(self.ctxt, volume_type['id'])
コード例 #10
0
    def _delete(self, req, id):
        """ Deletes an existing volume type """
        context = req.environ['cinder.context']
        authorize(context)

        try:
            vol_type = volume_types.get_volume_type(context, id)
            volume_types.destroy(context, vol_type['name'])
        except exception.NotFound:
            raise webob.exc.HTTPNotFound()

        return webob.Response(status_int=202)
コード例 #11
0
    def test_volume_type_create_then_destroy(self):
        """Ensure volume types can be created and deleted."""
        project_id = fake.PROJECT_ID
        prev_all_vtypes = volume_types.get_all_types(self.ctxt)

        # create
        type_ref = volume_types.create(self.ctxt,
                                       self.vol_type1_name,
                                       self.vol_type1_specs,
                                       description=self.vol_type1_description,
                                       projects=[project_id], is_public=False)
        new = volume_types.get_volume_type_by_name(self.ctxt,
                                                   self.vol_type1_name)

        self.assertEqual(self.vol_type1_description, new['description'])

        for k, v in self.vol_type1_specs.items():
            self.assertEqual(v, new['extra_specs'][k],
                             'one of fields does not match')

        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(len(prev_all_vtypes) + 1,
                         len(new_all_vtypes),
                         'drive type was not created')
        # Assert that volume type is associated to a project
        vol_type_access = db.volume_type_access_get_all(self.ctxt,
                                                        type_ref['id'])
        self.assertIn(project_id, [a.project_id for a in vol_type_access])

        # update
        new_type_name = self.vol_type1_name + '_updated'
        new_type_desc = self.vol_type1_description + '_updated'
        type_ref_updated = volume_types.update(self.ctxt,
                                               type_ref.id,
                                               new_type_name,
                                               new_type_desc)
        self.assertEqual(new_type_name, type_ref_updated['name'])
        self.assertEqual(new_type_desc, type_ref_updated['description'])

        # destroy
        volume_types.destroy(self.ctxt, type_ref['id'])
        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(prev_all_vtypes,
                         new_all_vtypes,
                         'drive type was not deleted')
        # Assert that associated volume type access is deleted successfully
        # on destroying the volume type
        vol_type_access = db_api._volume_type_access_query(
            self.ctxt).filter_by(volume_type_id=type_ref['id']).all()
        self.assertFalse(vol_type_access)
コード例 #12
0
 def test_volume_type_delete_with_consistencygroups_in_use(self):
     volume_type = db.volume_type_create(self.ctxt, {'name':
                                                     'fake volume type'})
     consistency_group1 = db.consistencygroup_create(self.ctxt,
                                                     {'volume_type_id':
                                                      volume_type['id']})
     consistency_group2 = db.consistencygroup_create(self.ctxt,
                                                     {'volume_type_id':
                                                      volume_type['id']})
     self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                       self.ctxt, volume_type['id'])
     db.consistencygroup_destroy(self.ctxt, consistency_group1['id'])
     self.assertRaises(exception.VolumeTypeInUse, volume_types.destroy,
                       self.ctxt, volume_type['id'])
     db.consistencygroup_destroy(self.ctxt, consistency_group2['id'])
     volume_types.destroy(self.ctxt, volume_type['id'])
コード例 #13
0
ファイル: test_volume_types.py プロジェクト: mahak/cinder
    def test_volume_type_destroy_with_encryption(self):
        volume_type = volume_types.create(self.ctxt, "type1")
        volume_type_id = volume_type.get('id')

        encryption = {
            'control_location': 'front-end',
            'provider': 'fake_provider',
        }
        db_api.volume_type_encryption_create(self.ctxt, volume_type_id,
                                             encryption)
        ret = volume_types.get_volume_type_encryption(self.ctxt,
                                                      volume_type_id)
        self.assertIsNotNone(ret)

        volume_types.destroy(self.ctxt, volume_type_id)
        ret = volume_types.get_volume_type_encryption(self.ctxt,
                                                      volume_type_id)
        self.assertIsNone(ret)
コード例 #14
0
ファイル: types_manage.py プロジェクト: shishirng/cinder
    def _delete(self, req, id):
        """Deletes an existing volume type."""
        context = req.environ["cinder.context"]
        authorize(context)

        try:
            vol_type = volume_types.get_volume_type(context, id)
            volume_types.destroy(context, vol_type["id"])
            self._notify_volume_type_info(context, "volume_type.delete", vol_type)
        except exception.VolumeTypeInUse as err:
            self._notify_volume_type_error(context, "volume_type.delete", err, volume_type=vol_type)
            msg = _("Target volume type is still in use.")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.VolumeTypeNotFound as err:
            self._notify_volume_type_error(context, "volume_type.delete", err, id=id)
            raise webob.exc.HTTPNotFound(explanation=err.msg)

        return webob.Response(status_int=202)
コード例 #15
0
ファイル: test_volume_types.py プロジェクト: mahak/cinder
 def test_update_volume_type_name_with_db_error(self, mock_update_quota):
     type_ref = volume_types.create(self.ctxt,
                                    self.vol_type1_name,
                                    self.vol_type1_specs,
                                    description=self.vol_type1_description)
     mock_update_quota.side_effect = db_exc.DBError
     new_type_name = self.vol_type1_name + '_updated'
     description = 'new_test'
     is_public = False
     self.assertRaises(exception.VolumeTypeUpdateFailed,
                       volume_types.update, self.ctxt, type_ref.id,
                       new_type_name, description, is_public)
     mock_update_quota.assert_called_once_with(self.ctxt,
                                               self.vol_type1_name,
                                               new_type_name)
     new = volume_types.get_volume_type_by_name(self.ctxt,
                                                self.vol_type1_name)
     self.assertEqual(self.vol_type1_name, new.get('name'))
     self.assertEqual(self.vol_type1_description, new.get('description'))
     self.assertTrue(new.get('is_public'))
     volume_types.destroy(self.ctxt, type_ref.id)
コード例 #16
0
    def test_flashsystem_get_vdisk_params(self):
        # case 1: use default params
        self.driver._get_vdisk_params(None)

        # case 2: use extra params from type
        opts1 = {'storage_protocol': 'iSCSI'}
        opts2 = {'capabilities:storage_protocol': 'iSCSI'}
        opts3 = {'storage_protocol': 'FC'}
        type1 = volume_types.create(self.ctxt, 'opts1', opts1)
        type2 = volume_types.create(self.ctxt, 'opts2', opts2)
        type3 = volume_types.create(self.ctxt, 'opts3', opts3)
        self.assertEqual(
            'iSCSI',
            self.driver._get_vdisk_params(type1['id'])['protocol'])
        self.assertEqual(
            'iSCSI',
            self.driver._get_vdisk_params(type2['id'])['protocol'])
        self.assertRaises(exception.InvalidInput,
                          self.driver._get_vdisk_params,
                          type3['id'])

        # clear environment
        volume_types.destroy(self.ctxt, type1['id'])
        volume_types.destroy(self.ctxt, type2['id'])
        volume_types.destroy(self.ctxt, type3['id'])
コード例 #17
0
    def _delete(self, req, id):
        """Deletes an existing volume type."""
        context = req.environ['cinder.context']
        authorize(context)

        try:
            vol_type = volume_types.get_volume_type(context, id)
            volume_types.destroy(context, vol_type['id'])
            self._notify_volume_type_info(
                context, 'volume_type.delete', vol_type)
        except exception.VolumeTypeInUse as err:
            self._notify_volume_type_error(
                context, 'volume_type.delete', err, volume_type=vol_type)
            msg = _('Target volume type is still in use.')
            raise webob.exc.HTTPBadRequest(explanation=msg)
        except exception.VolumeTypeNotFound as err:
            self._notify_volume_type_error(
                context, 'volume_type.delete', err, id=id)
            # Not found exception will be handled at the wsgi level
            raise

        return webob.Response(status_int=http_client.ACCEPTED)
コード例 #18
0
    def test_volume_type_create_then_destroy(self):
        """Ensure volume types can be created and deleted."""
        prev_all_vtypes = volume_types.get_all_types(self.ctxt)

        # create
        type_ref = volume_types.create(self.ctxt,
                                       self.vol_type1_name,
                                       self.vol_type1_specs,
                                       description=self.vol_type1_description)
        new = volume_types.get_volume_type_by_name(self.ctxt,
                                                   self.vol_type1_name)

        self.assertEqual(self.vol_type1_description, new['description'])

        for k, v in self.vol_type1_specs.items():
            self.assertEqual(v, new['extra_specs'][k],
                             'one of fields does not match')

        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(len(prev_all_vtypes) + 1,
                         len(new_all_vtypes),
                         'drive type was not created')

        # update
        new_type_name = self.vol_type1_name + '_updated'
        new_type_desc = self.vol_type1_description + '_updated'
        type_ref_updated = volume_types.update(self.ctxt,
                                               type_ref.id,
                                               new_type_name,
                                               new_type_desc)
        self.assertEqual(new_type_name, type_ref_updated['name'])
        self.assertEqual(new_type_desc, type_ref_updated['description'])

        # destroy
        volume_types.destroy(self.ctxt, type_ref['id'])
        new_all_vtypes = volume_types.get_all_types(self.ctxt)
        self.assertEqual(prev_all_vtypes,
                         new_all_vtypes,
                         'drive type was not deleted')
コード例 #19
0
ファイル: test_iscsi_driver.py プロジェクト: lubidl0/cinder-1
    def test_instorage_mcs_iscsi_host_maps(self):
        # Create two volumes to be used in mappings

        ctxt = context.get_admin_context()
        volume1 = self._generate_vol_info(None, None)
        self.iscsi_driver.create_volume(volume1)
        volume2 = self._generate_vol_info(None, None)
        self.iscsi_driver.create_volume(volume2)

        # Create volume types that we created
        types = {}
        for protocol in ['iSCSI']:
            opts = {'storage_protocol': '<in> ' + protocol}
            types[protocol] = volume_types.create(ctxt, protocol, opts)

        expected = {
            'iSCSI': {
                'driver_volume_type': 'iscsi',
                'data': {
                    'target_discovered': False,
                    'target_iqn': 'iqn.1982-01.com.inspur:1234.sim.node1',
                    'target_portal': '1.234.56.78:3260',
                    'target_lun': 0,
                    'auth_method': 'CHAP',
                    'discovery_auth_method': 'CHAP'
                }
            }
        }

        volume1['volume_type_id'] = types[protocol]['id']
        volume2['volume_type_id'] = types[protocol]['id']

        # Check case where no hosts exist
        ret = self.iscsi_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNone(ret)

        # Make sure that the volumes have been created
        self._assert_vol_exists(volume1['name'], True)
        self._assert_vol_exists(volume2['name'], True)

        # Initialize connection from the first volume to a host
        ret = self.iscsi_driver.initialize_connection(volume1, self._connector)
        self.assertEqual(expected[protocol]['driver_volume_type'],
                         ret['driver_volume_type'])
        for k, v in expected[protocol]['data'].items():
            self.assertEqual(v, ret['data'][k])

        # Initialize again, should notice it and do nothing
        ret = self.iscsi_driver.initialize_connection(volume1, self._connector)
        self.assertEqual(expected[protocol]['driver_volume_type'],
                         ret['driver_volume_type'])
        for k, v in expected[protocol]['data'].items():
            self.assertEqual(v, ret['data'][k])

        # Try to delete the 1st volume (should fail because it is mapped)
        self.assertRaises(exception.VolumeBackendAPIException,
                          self.iscsi_driver.delete_volume, volume1)

        ret = self.iscsi_driver.terminate_connection(volume1, self._connector)
        ret = self.iscsi_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNone(ret)

        # Check cases with no auth set for host
        for auth_enabled in [True, False]:
            for host_exists in ['yes-auth', 'yes-noauth', 'no']:
                self._set_flag('instorage_mcs_iscsi_chap_enabled',
                               auth_enabled)
                case = 'en' + six.text_type(
                    auth_enabled) + 'ex' + six.text_type(host_exists)
                conn_na = {
                    'initiator': 'test:init:%s' % 56789,
                    'ip': '11.11.11.11',
                    'host': 'host-%s' % case
                }
                if host_exists.startswith('yes'):
                    self.sim._add_host_to_list(conn_na)
                    if host_exists == 'yes-auth':
                        kwargs = {'chapsecret': 'foo', 'obj': conn_na['host']}
                        self.sim._cmd_chhost(**kwargs)
                volume1['volume_type_id'] = types['iSCSI']['id']

                init_ret = self.iscsi_driver.initialize_connection(
                    volume1, conn_na)
                host_name = self.sim._host_in_list(conn_na['host'])
                chap_ret = (self.iscsi_driver._assistant.
                            get_chap_secret_for_host(host_name))
                if auth_enabled or host_exists == 'yes-auth':
                    self.assertIn('auth_password', init_ret['data'])
                    self.assertIsNotNone(chap_ret)
                else:
                    self.assertNotIn('auth_password', init_ret['data'])
                    self.assertIsNone(chap_ret)
                self.iscsi_driver.terminate_connection(volume1, conn_na)
        self._set_flag('instorage_mcs_iscsi_chap_enabled', True)

        # Test no preferred node
        self.sim.error_injection('lsvdisk', 'no_pref_node')
        self.assertRaises(exception.VolumeBackendAPIException,
                          self.iscsi_driver.initialize_connection, volume1,
                          self._connector)

        # Initialize connection from the second volume to the host with no
        # preferred node set if in simulation mode, otherwise, just
        # another initialize connection.
        self.sim.error_injection('lsvdisk', 'blank_pref_node')
        self.iscsi_driver.initialize_connection(volume2, self._connector)

        # Try to remove connection from host that doesn't exist (should fail)
        conn_no_exist = self._connector.copy()
        conn_no_exist['initiator'] = 'i_dont_exist'
        conn_no_exist['wwpns'] = ['0000000000000000']
        self.assertRaises(exception.VolumeDriverException,
                          self.iscsi_driver.terminate_connection, volume1,
                          conn_no_exist)

        # Try to remove connection from volume that isn't mapped (should print
        # message but NOT fail)
        unmapped_vol = self._generate_vol_info(None, None)
        self.iscsi_driver.create_volume(unmapped_vol)
        self.iscsi_driver.terminate_connection(unmapped_vol, self._connector)
        self.iscsi_driver.delete_volume(unmapped_vol)

        # Remove the mapping from the 1st volume and delete it
        self.iscsi_driver.terminate_connection(volume1, self._connector)
        self.iscsi_driver.delete_volume(volume1)
        self._assert_vol_exists(volume1['name'], False)

        # Make sure our host still exists
        host_name = self.iscsi_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNotNone(host_name)

        # Remove the mapping from the 2nd volume. The host should
        # be automatically removed because there are no more mappings.
        self.iscsi_driver.terminate_connection(volume2, self._connector)

        # Check if we successfully terminate connections when the host is not
        # specified
        fake_conn = {'ip': '127.0.0.1', 'initiator': 'iqn.fake'}
        self.iscsi_driver.initialize_connection(volume2, self._connector)
        host_name = self.iscsi_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNotNone(host_name)
        self.iscsi_driver.terminate_connection(volume2, fake_conn)
        host_name = self.iscsi_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNone(host_name)
        self.iscsi_driver.delete_volume(volume2)
        self._assert_vol_exists(volume2['name'], False)

        # Delete volume types that we created
        for protocol in ['iSCSI']:
            volume_types.destroy(ctxt, types[protocol]['id'])

        # Check if our host still exists (it should not)
        ret = (self.iscsi_driver._assistant.get_host_from_connector(
            self._connector))
        self.assertIsNone(ret)
コード例 #20
0
 def test_repeated_vol_types_shouldnt_raise(self):
     """Ensures that volume duplicates don't raise."""
     new_name = self.vol_type1_name + "dup"
     type_ref = volume_types.create(self.ctxt, new_name)
     volume_types.destroy(self.ctxt, type_ref['id'])
     type_ref = volume_types.create(self.ctxt, new_name)
コード例 #21
0
ファイル: volume_type.py プロジェクト: Nexenta/cinder
 def destroy(self):
     with self.obj_as_admin():
         updated_values = volume_types.destroy(self._context, self.id)
     self.update(updated_values)
     self.obj_reset_changes(updated_values.keys())
コード例 #22
0
ファイル: test_fc_driver.py プロジェクト: mahak/cinder
    def test_instorage_mcs_fc_host_maps(self):
        # Create two volumes to be used in mappings

        ctxt = context.get_admin_context()
        volume1 = self._generate_vol_info(None, None)
        self.fc_driver.create_volume(volume1)
        volume2 = self._generate_vol_info(None, None)
        self.fc_driver.create_volume(volume2)

        # FIbre Channel volume type
        extra_spec = {'capabilities:storage_protocol': '<in> FC'}
        vol_type = volume_types.create(self.ctxt, 'FC', extra_spec)

        expected = {'driver_volume_type': 'fibre_channel',
                    'data': {'target_lun': 0,
                             'target_wwn': ['AABBCCDDEEFF0011'],
                             'target_discovered': False}}

        volume1['volume_type_id'] = vol_type['id']
        volume2['volume_type_id'] = vol_type['id']

        ret = self.fc_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNone(ret)

        # Make sure that the volumes have been created
        self._assert_vol_exists(volume1['name'], True)
        self._assert_vol_exists(volume2['name'], True)

        # Initialize connection from the first volume to a host
        ret = self.fc_driver.initialize_connection(
            volume1, self._connector)
        self.assertEqual(expected['driver_volume_type'],
                         ret['driver_volume_type'])
        for k, v in expected['data'].items():
            self.assertEqual(v, ret['data'][k])

        # Initialize again, should notice it and do nothing
        ret = self.fc_driver.initialize_connection(
            volume1, self._connector)
        self.assertEqual(expected['driver_volume_type'],
                         ret['driver_volume_type'])
        for k, v in expected['data'].items():
            self.assertEqual(v, ret['data'][k])

        # Try to delete the 1st volume (should fail because it is mapped)
        self.assertRaises(exception.VolumeBackendAPIException,
                          self.fc_driver.delete_volume,
                          volume1)

        # Check bad output from lsfabric for the 2nd volume
        for error in ['remove_field', 'header_mismatch']:
            self.sim.error_injection('lsfabric', error)
            self.assertRaises(exception.VolumeBackendAPIException,
                              self.fc_driver.initialize_connection,
                              volume2, self._connector)

        with mock.patch.object(instorage_common.InStorageAssistant,
                               'get_conn_fc_wwpns') as conn_fc_wwpns:
            conn_fc_wwpns.return_value = []
            ret = self.fc_driver.initialize_connection(volume2,
                                                       self._connector)

        ret = self.fc_driver.terminate_connection(volume1, self._connector)
        # For the first volume detach, ret['data'] should be empty
        # only ret['driver_volume_type'] returned
        self.assertEqual({}, ret['data'])
        self.assertEqual('fibre_channel', ret['driver_volume_type'])
        ret = self.fc_driver.terminate_connection(volume2,
                                                  self._connector)
        self.assertEqual('fibre_channel', ret['driver_volume_type'])
        # wwpn is randomly created
        self.assertNotEqual({}, ret['data'])

        ret = self.fc_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNone(ret)

        # Test no preferred node
        self.sim.error_injection('lsvdisk', 'no_pref_node')
        self.assertRaises(exception.VolumeBackendAPIException,
                          self.fc_driver.initialize_connection,
                          volume1, self._connector)

        # Initialize connection from the second volume to the host with no
        # preferred node set if in simulation mode, otherwise, just
        # another initialize connection.
        self.sim.error_injection('lsvdisk', 'blank_pref_node')
        self.fc_driver.initialize_connection(volume2, self._connector)

        # Try to remove connection from host that doesn't exist (should fail)
        conn_no_exist = self._connector.copy()
        conn_no_exist['initiator'] = 'i_dont_exist'
        conn_no_exist['wwpns'] = ['0000000000000000']
        self.assertRaises(exception.VolumeDriverException,
                          self.fc_driver.terminate_connection,
                          volume1,
                          conn_no_exist)

        # Try to remove connection from volume that isn't mapped (should print
        # message but NOT fail)
        unmapped_vol = self._generate_vol_info(None, None)
        self.fc_driver.create_volume(unmapped_vol)
        self.fc_driver.terminate_connection(unmapped_vol, self._connector)
        self.fc_driver.delete_volume(unmapped_vol)

        # Remove the mapping from the 1st volume and delete it
        self.fc_driver.terminate_connection(volume1, self._connector)
        self.fc_driver.delete_volume(volume1)
        self._assert_vol_exists(volume1['name'], False)

        # Make sure our host still exists
        host_name = self.fc_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNotNone(host_name)

        # Remove the mapping from the 2nd volume. The host should
        # be automatically removed because there are no more mappings.
        self.fc_driver.terminate_connection(volume2, self._connector)

        # Check if we successfully terminate connections when the host is not
        # specified
        fake_conn = {'ip': '127.0.0.1', 'initiator': 'iqn.fake'}
        self.fc_driver.initialize_connection(volume2, self._connector)
        host_name = self.fc_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNotNone(host_name)
        self.fc_driver.terminate_connection(volume2, fake_conn)
        host_name = self.fc_driver._assistant.get_host_from_connector(
            self._connector)
        self.assertIsNone(host_name)
        self.fc_driver.delete_volume(volume2)
        self._assert_vol_exists(volume2['name'], False)

        # Delete volume types that we created
        volume_types.destroy(ctxt, vol_type['id'])

        ret = (self.fc_driver._assistant.get_host_from_connector(
            self._connector))
        self.assertIsNone(ret)
コード例 #23
0
ファイル: volume_type.py プロジェクト: kleopatra999/cinder
 def destroy(self):
     with self.obj_as_admin():
         volume_types.destroy(self._context, self.id)
コード例 #24
0
ファイル: test_coprhd.py プロジェクト: bravandi/cinder
 def delete_vipr_volume_type(self):
     ctx = context.get_admin_context()
     volume_types.destroy(ctx, self.volume_type_id)