コード例 #1
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'extra_specs':
            self.extra_specs = db.volume_type_extra_specs_get(self._context,
                                                              self.id)

        elif attrname == 'qos_specs':
            if self.qos_specs_id:
                self.qos_specs = objects.QualityOfServiceSpecs.get_by_id(
                    self._context, self.qos_specs_id)
            else:
                self.qos_specs = None

        elif attrname == 'projects':
            volume_type_projects = db.volume_type_access_get_all(self._context,
                                                                 self.id)
            self.projects = [x.project_id for x in volume_type_projects]

        self.obj_reset_changes(fields=[attrname])
コード例 #2
0
    def obj_load_attr(self, attrname):
        if attrname not in self.OPTIONAL_FIELDS:
            raise exception.ObjectActionError(
                action='obj_load_attr',
                reason=_('attribute %s not lazy-loadable') % attrname)
        if not self._context:
            raise exception.OrphanedObjectError(method='obj_load_attr',
                                                objtype=self.obj_name())

        if attrname == 'extra_specs':
            self.extra_specs = db.volume_type_extra_specs_get(
                self._context, self.id)

        elif attrname == 'qos_specs':
            if self.qos_specs_id:
                self.qos_specs = objects.QualityOfServiceSpecs.get_by_id(
                    self._context, self.qos_specs_id)
            else:
                self.qos_specs = None

        elif attrname == 'projects':
            volume_type_projects = db.volume_type_access_get_all(
                self._context, self.id)
            self.projects = [x.project_id for x in volume_type_projects]

        self.obj_reset_changes(fields=[attrname])
コード例 #3
0
ファイル: test_volume_types.py プロジェクト: NxtCloud/cinder
    def test_remove_access(self):
        project_id = '456'
        vtype = volume_types.create(self.ctxt, 'type1', projects=['456'])
        vtype_id = vtype.get('id')

        volume_types.remove_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertNotIn(project_id, vtype_access)
コード例 #4
0
ファイル: test_volume_types.py プロジェクト: NxtCloud/cinder
    def test_add_access(self):
        project_id = '456'
        vtype = volume_types.create(self.ctxt, 'type1')
        vtype_id = vtype.get('id')

        volume_types.add_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertIn(project_id, [a.project_id for a in vtype_access])
コード例 #5
0
    def test_add_access(self):
        project_id = '456'
        vtype = volume_types.create(self.ctxt, 'type1', is_public=False)
        vtype_id = vtype.get('id')

        volume_types.add_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertIn(project_id, [a.project_id for a in vtype_access])
コード例 #6
0
    def test_add_access(self):
        project_id = fake.PROJECT_ID
        vtype = volume_types.create(self.ctxt, 'type1', is_public=False)
        vtype_id = vtype.get('id')

        volume_types.add_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertIn(project_id, [a.project_id for a in vtype_access])
コード例 #7
0
    def test_remove_access(self):
        project_id = '456'
        vtype = volume_types.create(self.ctxt, 'type1', projects=['456'])
        vtype_id = vtype.get('id')

        volume_types.remove_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertNotIn(project_id, vtype_access)
コード例 #8
0
    def test_remove_access(self):
        project_id = "456"
        vtype = volume_types.create(self.ctxt, "type1", projects=["456"], is_public=False)
        vtype_id = vtype.get("id")

        volume_types.remove_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertNotIn(project_id, vtype_access)
コード例 #9
0
    def test_add_access(self):
        project_id = "456"
        vtype = volume_types.create(self.ctxt, "type1", is_public=False)
        vtype_id = vtype.get("id")

        volume_types.add_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertIn(project_id, [a.project_id for a in vtype_access])
コード例 #10
0
    def test_remove_access_with_non_admin(self):
        self.ctxt = context.RequestContext("fake", "fake", is_admin=False)
        project_id = fake.PROJECT_ID
        vtype = volume_types.create(self.ctxt, "type1", projects=[project_id], is_public=False)
        vtype_id = vtype.get("id")

        volume_types.remove_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt.elevated(), vtype_id)
        self.assertNotIn(project_id, vtype_access)
コード例 #11
0
    def test_remove_access(self):
        project_id = fake.PROJECT_ID
        vtype = volume_types.create(self.ctxt, 'type1', projects=[project_id],
                                    is_public=False)
        vtype_id = vtype.get('id')

        volume_types.remove_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertNotIn(project_id, vtype_access)
コード例 #12
0
    def test_remove_access(self):
        project_id = fake.PROJECT_ID
        vtype = volume_types.create(self.ctxt, 'type1', projects=[project_id],
                                    is_public=False)
        vtype_id = vtype.get('id')

        volume_types.remove_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt, vtype_id)
        self.assertNotIn(project_id, vtype_access)
コード例 #13
0
    def test_add_access_with_non_admin(self):
        self.ctxt = context.RequestContext('fake', 'fake', is_admin=False)
        project_id = fake.PROJECT_ID
        vtype = volume_types.create(self.ctxt, 'type1', is_public=False)
        vtype_id = vtype.get('id')

        volume_types.add_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt.elevated(),
                                                     vtype_id)
        self.assertIn(project_id, [a.project_id for a in vtype_access])
コード例 #14
0
    def test_add_access_with_non_admin(self):
        self.ctxt = context.RequestContext('fake', 'fake', is_admin=False)
        project_id = fake.PROJECT_ID
        vtype = volume_types.create(self.ctxt, 'type1', is_public=False)
        vtype_id = vtype.get('id')

        volume_types.add_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt.elevated(),
                                                     vtype_id)
        self.assertIn(project_id, [a.project_id for a in vtype_access])
コード例 #15
0
ファイル: test_volume_types.py プロジェクト: bopopescu/stack
    def test_remove_access_with_non_admin(self):
        self.ctxt = context.RequestContext('fake', 'fake', is_admin=False)
        project_id = '456'
        vtype = volume_types.create(self.ctxt, 'type1', projects=['456'],
                                    is_public=False)
        vtype_id = vtype.get('id')

        volume_types.remove_volume_type_access(self.ctxt, vtype_id, project_id)
        vtype_access = db.volume_type_access_get_all(self.ctxt.elevated(),
                                                     vtype_id)
        self.assertNotIn(project_id, vtype_access)
コード例 #16
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'
        volume_types.update(self.ctxt, type_ref.id, new_type_name,
                            new_type_desc)
        type_ref_updated = volume_types.get_volume_type(self.ctxt, type_ref.id)
        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
        with db_api.main_context_manager.reader.using(self.ctxt):
            vol_type_access = db_api._volume_type_access_query(
                self.ctxt).filter_by(volume_type_id=type_ref['id']).all()
        self.assertEqual([], vol_type_access)
コード例 #17
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)
コード例 #18
0
    def backend_passes(self, backend_state, filter_properties):
        # get the volume type from the filter properties or return None
        volume_type = filter_properties.get('volume_type', None)
        """
        if the user passed a volume type then this filter has nothing to do
        so just return True with the assumption that the other mechanisms in
        place will determine if this is possible or not
        """
        if volume_type is not None:
            return True

        # get the request context object
        r_context = filter_properties.get('context')

        # we can't do anything without the request context
        if r_context is None:
            LOG.fatal("context not found in filter_properties")
            return False

        # get the project id from the request context
        project_id = None

        if hasattr(r_context, 'project_id'):
            project_id = r_context.project_id

        # we can't do anything without a project id
        if project_id is None:
            LOG.fatal("project id not found in the request context")
            return False

        # we need the admin context to fetch the list of backend types
        # and access ids
        admin_context = context.get_admin_context()

        # get all backend types
        backend_types = volume_types.get_all_types(admin_context)

        # get the type name from the backend state
        backend_type_name = backend_state.pool_name

        # get backend state information
        backend_type_info = backend_types.get(backend_type_name)

        # we can't do anything without the backend type information
        if backend_type_info is None:
            LOG.info("no backend type information found for {}. "
                     "skipping".format(backend_type_name))
            return False

        # we're only looking for private backend types
        if backend_type_info['is_public']:
            LOG.info("backend type {} is not private. "
                     "skipping".format(backend_type_name))
            return False

        # get the backend type id
        backend_type_id = backend_type_info['id']

        # get list of access ids for current backend type
        backend_type_access = db.volume_type_access_get_all(
            admin_context, backend_type_id)

        # look for project id in list of access ids
        backend_type_found = [
            access for access in backend_type_access
            if access.project_id == project_id
        ]

        if len(backend_type_found) > 0:
            LOG.info("{} is a valid backend type".format(backend_type_name))
            return True

        LOG.info("could not find project id {} in the {} backend type. "
                 "skipping".format(project_id, backend_type_name))

        return False