Exemplo n.º 1
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 doesnt 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')
Exemplo n.º 2
0
    def test_volume_type_search_by_extra_spec(self):
        """Ensure volume types get by extra spec returns correct type."""
        volume_types.create(self.ctxt, "type1", {"key1": "val1",
                                                 "key2": "val2"})
        volume_types.create(self.ctxt, "type2", {"key2": "val2",
                                                 "key3": "val3"})
        volume_types.create(self.ctxt, "type3", {"key3": "another_value",
                                                 "key4": "val4"})

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key1": "val1"}})
        LOG.info("vol_types: %s" % vol_types)
        self.assertEqual(1, len(vol_types))
        self.assertIn("type1", vol_types.keys())
        self.assertEqual({"key1": "val1", "key2": "val2"},
                         vol_types['type1']['extra_specs'])

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key2": "val2"}})
        LOG.info("vol_types: %s" % vol_types)
        self.assertEqual(2, len(vol_types))
        self.assertIn("type1", vol_types.keys())
        self.assertIn("type2", vol_types.keys())

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key3": "val3"}})
        LOG.info("vol_types: %s" % vol_types)
        self.assertEqual(1, len(vol_types))
        self.assertIn("type2", vol_types.keys())
Exemplo n.º 3
0
    def test_volume_type_search_by_extra_spec(self):
        """Ensure volume types get by extra spec returns correct type."""
        volume_types.create(self.ctxt, "type1", {"key1": "val1",
                                                 "key2": "val2"})
        volume_types.create(self.ctxt, "type2", {"key2": "val2",
                                                 "key3": "val3"})
        volume_types.create(self.ctxt, "type3", {"key3": "another_value",
                                                 "key4": "val4"})

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key1": "val1"}})
        LOG.info("vol_types: %s" % vol_types)
        self.assertEqual(len(vol_types), 1)
        self.assertTrue("type1" in vol_types.keys())
        self.assertEqual(vol_types['type1']['extra_specs'],
                         {"key1": "val1", "key2": "val2"})

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key2": "val2"}})
        LOG.info("vol_types: %s" % vol_types)
        self.assertEqual(len(vol_types), 2)
        self.assertTrue("type1" in vol_types.keys())
        self.assertTrue("type2" in vol_types.keys())

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key3": "val3"}})
        LOG.info("vol_types: %s" % vol_types)
        self.assertEqual(len(vol_types), 1)
        self.assertTrue("type2" in vol_types.keys())
Exemplo n.º 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)

        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')
    def test_volume_type_search_by_extra_spec(self):
        """Ensure volume types get by extra spec returns correct type."""
        volume_types.create(self.ctxt, "type1", {"key1": "val1",
                                                 "key2": "val2"})
        volume_types.create(self.ctxt, "type2", {"key2": "val2",
                                                 "key3": "val3"})
        volume_types.create(self.ctxt, "type3", {"key3": "another_value",
                                                 "key4": "val4"})

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key1": "val1"}})
        self.assertEqual(1, len(vol_types))
        self.assertIn("type1", vol_types.keys())
        self.assertEqual({"key1": "val1", "key2": "val2"},
                         vol_types['type1']['extra_specs'])

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key2": "val2"}})
        self.assertEqual(2, len(vol_types))
        self.assertIn("type1", vol_types.keys())
        self.assertIn("type2", vol_types.keys())

        vol_types = volume_types.get_all_types(
            self.ctxt,
            search_opts={'extra_specs': {"key3": "val3"}})
        self.assertEqual(1, len(vol_types))
        self.assertIn("type2", vol_types.keys())
Exemplo n.º 6
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")
Exemplo n.º 7
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")
Exemplo n.º 8
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)
Exemplo n.º 9
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)
Exemplo n.º 10
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     # NOTE(wanghao): Currently, we still only support to filter by
     # is_public. If we want to filter by more args, we should set params
     # to filters.
     filters = {}
     context = req.environ['cinder.context']
     if not context.is_admin and self._validate_policy(context):
         context = ctx.get_admin_context()
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     utils.remove_invalid_filter_options(
         context, filters, self._get_vol_type_filter_options())
     limited_types = volume_types.get_all_types(context,
                                                filters=filters,
                                                marker=marker,
                                                limit=limit,
                                                sort_keys=sort_keys,
                                                sort_dirs=sort_dirs,
                                                offset=offset,
                                                list_result=True)
     return limited_types
Exemplo n.º 11
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     # NOTE(wanghao): Currently, we still only support to filter by
     # is_public. If we want to filter by more args, we should set params
     # to filters.
     filters = {}
     context = req.environ['cinder.context']
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     utils.remove_invalid_filter_options(context,
                                         filters,
                                         self._get_vol_type_filter_options()
                                         )
     limited_types = volume_types.get_all_types(context,
                                                filters=filters,
                                                marker=marker, limit=limit,
                                                sort_keys=sort_keys,
                                                sort_dirs=sort_dirs,
                                                offset=offset,
                                                list_result=True)
     return limited_types
Exemplo n.º 12
0
 def test_get_all_volume_types(self):
     """Ensures that all volume types can be retrieved."""
     with db_api.main_context_manager.writer.using(self.ctxt):
         total_volume_types = self.ctxt.session.query(
             models.VolumeType, ).count()
     vol_types = volume_types.get_all_types(self.ctxt)
     self.assertEqual(total_volume_types, len(vol_types))
Exemplo n.º 13
0
 def index(self, req):
     """Returns the list of volume types."""
     context = req.environ['cinder.context']
     vol_types = volume_types.get_all_types(context)
     vol_types = list(vol_types.values())
     req.cache_resource(vol_types, name='types')
     return self._view_builder.index(req, vol_types)
Exemplo n.º 14
0
 def index(self, req):
     """Returns the list of volume types."""
     context = req.environ['cinder.context']
     vol_types = volume_types.get_all_types(context)
     vol_types = list(vol_types.values())
     req.cache_resource(vol_types, name='types')
     return self._view_builder.index(req, vol_types)
Exemplo n.º 15
0
 def get_all(cls, context, inactive=0, search_opts=None):
     types = volume_types.get_all_types(context, inactive, search_opts)
     expected_attrs = ['extra_specs', 'projects']
     return base.obj_make_list(context,
                               cls(context),
                               objects.VolumeType,
                               types.values(),
                               expected_attrs=expected_attrs)
Exemplo n.º 16
0
    def test_volume_type_search_by_extra_spec(self):
        """Ensure volume types get by extra spec returns correct type."""
        volume_types.create(self.ctxt, "type1", {"key1": "val1", "key2": "val2"})
        volume_types.create(self.ctxt, "type2", {"key2": "val2", "key3": "val3"})
        volume_types.create(self.ctxt, "type3", {"key3": "another_value", "key4": "val4"})

        vol_types = volume_types.get_all_types(self.ctxt, filters={"extra_specs": {"key1": "val1"}})
        self.assertEqual(1, len(vol_types))
        self.assertIn("type1", vol_types.keys())
        self.assertEqual({"key1": "val1", "key2": "val2"}, vol_types["type1"]["extra_specs"])

        vol_types = volume_types.get_all_types(self.ctxt, filters={"extra_specs": {"key2": "val2"}})
        self.assertEqual(2, len(vol_types))
        self.assertIn("type1", vol_types.keys())
        self.assertIn("type2", vol_types.keys())

        vol_types = volume_types.get_all_types(self.ctxt, filters={"extra_specs": {"key3": "val3"}})
        self.assertEqual(1, len(vol_types))
        self.assertIn("type2", vol_types.keys())
Exemplo n.º 17
0
 def get_all(cls, context, inactive=0, filters=None, marker=None,
             limit=None, sort_keys=None, sort_dirs=None, offset=None):
     types = volume_types.get_all_types(context, inactive, filters,
                                        marker=marker, limit=limit,
                                        sort_keys=sort_keys,
                                        sort_dirs=sort_dirs, offset=offset)
     expected_attrs = VolumeType._get_expected_attrs(context)
     return base.obj_make_list(context, cls(context),
                               objects.VolumeType, types.values(),
                               expected_attrs=expected_attrs)
Exemplo n.º 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)

        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.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')

        # 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')
Exemplo n.º 19
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')
Exemplo n.º 20
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     filters = {}
     context = req.environ['cinder.context']
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     limited_types = volume_types.get_all_types(
         context, search_opts=filters).values()
     return limited_types
Exemplo n.º 21
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     filters = {}
     context = req.environ['cinder.context']
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     limited_types = volume_types.get_all_types(
         context, search_opts=filters).values()
     return limited_types
Exemplo n.º 22
0
    def test_volume_type_search_by_extra_spec_multiple(self):
        """Ensure volume types get by extra spec returns correct type."""
        volume_types.create(self.ctxt, "type1", {"key1": "val1", "key2": "val2", "key3": "val3"})
        volume_types.create(self.ctxt, "type2", {"key2": "val2", "key3": "val3"})
        volume_types.create(self.ctxt, "type3", {"key1": "val1", "key3": "val3", "key4": "val4"})

        vol_types = volume_types.get_all_types(self.ctxt, search_opts={"extra_specs": {"key1": "val1", "key3": "val3"}})
        LOG.info("vol_types: %s" % vol_types)
        self.assertEqual(len(vol_types), 2)
        self.assertIn("type1", vol_types.keys())
        self.assertIn("type3", vol_types.keys())
        self.assertEqual(vol_types["type1"]["extra_specs"], {"key1": "val1", "key2": "val2", "key3": "val3"})
        self.assertEqual(vol_types["type3"]["extra_specs"], {"key1": "val1", "key3": "val3", "key4": "val4"})
Exemplo n.º 23
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')
Exemplo n.º 24
0
    def _get_volume_types(self, req):
        """Helper function that returns a list of type dicts."""
        params = req.params.copy()
        marker, limit, offset = common.get_pagination_params(params)
        sort_keys, sort_dirs = common.get_sort_params(params)
        filters = params
        context = req.environ['cinder.context']
        req_version = req.api_version_request
        if req_version.matches(mv.SUPPORT_VOLUME_TYPE_FILTER):
            self._process_volume_type_filtering(context=context,
                                                filters=filters,
                                                req_version=req_version)
        else:
            api_utils.remove_invalid_filter_options(
                context, filters, self._get_vol_type_filter_options())
        if context.is_admin:
            # Only admin has query access to all volume types
            filters['is_public'] = api_utils._parse_is_public(
                req.params.get('is_public', None))
        else:
            filters['is_public'] = True
        if 'extra_specs' in filters:
            try:
                filters['extra_specs'] = ast.literal_eval(
                    filters['extra_specs'])
            except (ValueError, SyntaxError):
                LOG.debug(
                    'Could not evaluate "extra_specs" %s, assuming '
                    'dictionary string.', filters['extra_specs'])

            # Do not allow sensitive extra specs to be used in a filter if
            # the context only allows access to user visible extra specs.
            # Removing the filter would yield inaccurate results, so an
            # empty result is returned because as far as an unauthorized
            # user goes, the list of volume-types meeting their filtering
            # criteria is empty.
            if not context.authorize(extra_specs_policy.READ_SENSITIVE_POLICY,
                                     fatal=False):
                for k in filters['extra_specs'].keys():
                    if k not in extra_specs_policy.USER_VISIBLE_EXTRA_SPECS:
                        return []
        limited_types = volume_types.get_all_types(context,
                                                   filters=filters,
                                                   marker=marker,
                                                   limit=limit,
                                                   sort_keys=sort_keys,
                                                   sort_dirs=sort_dirs,
                                                   offset=offset,
                                                   list_result=True)
        return limited_types
Exemplo n.º 25
0
    def test_volume_type_search_by_extra_spec_multiple(self):
        """Ensure volume types get by extra spec returns correct type."""
        volume_types.create(self.ctxt, "type1", {"key1": "val1",
                                                 "key2": "val2",
                                                 "key3": "val3"})
        volume_types.create(self.ctxt, "type2", {"key2": "val2",
                                                 "key3": "val3"})
        volume_types.create(self.ctxt, "type3", {"key1": "val1",
                                                 "key3": "val3",
                                                 "key4": "val4"})

        vol_types = volume_types.get_all_types(
            self.ctxt,
            filters={'extra_specs': {"key1": "val1", "key3": "val3"}})
        self.assertEqual(2, len(vol_types))
        self.assertIn("type1", vol_types.keys())
        self.assertIn("type3", vol_types.keys())
        self.assertEqual({"key1": "val1", "key2": "val2", "key3": "val3"},
                         vol_types['type1']['extra_specs'])
        self.assertEqual({"key1": "val1", "key3": "val3", "key4": "val4"},
                         vol_types['type3']['extra_specs'])
Exemplo n.º 26
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     filters = params
     context = req.environ['cinder.context']
     req_version = req.api_version_request
     if req_version.matches(mv.SUPPORT_VOLUME_TYPE_FILTER):
         self._process_volume_type_filtering(context=context,
                                             filters=filters,
                                             req_version=req_version)
     else:
         api_utils.remove_invalid_filter_options(
             context, filters, self._get_vol_type_filter_options())
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = api_utils._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     if 'extra_specs' in filters:
         try:
             filters['extra_specs'] = ast.literal_eval(
                 filters['extra_specs'])
         except (ValueError, SyntaxError):
             LOG.debug(
                 'Could not evaluate "extra_specs" %s, assuming '
                 'dictionary string.', filters['extra_specs'])
     limited_types = volume_types.get_all_types(context,
                                                filters=filters,
                                                marker=marker,
                                                limit=limit,
                                                sort_keys=sort_keys,
                                                sort_dirs=sort_dirs,
                                                offset=offset,
                                                list_result=True)
     return limited_types
Exemplo n.º 27
0
 def _get_volume_types(self, req):
     """Helper function that returns a list of type dicts."""
     params = req.params.copy()
     marker, limit, offset = common.get_pagination_params(params)
     sort_keys, sort_dirs = common.get_sort_params(params)
     filters = params
     context = req.environ['cinder.context']
     req_version = req.api_version_request
     if req_version.matches(mv.SUPPORT_VOLUME_TYPE_FILTER):
         self._process_volume_type_filtering(context=context,
                                             filters=filters,
                                             req_version=req_version)
     else:
         utils.remove_invalid_filter_options(
             context, filters, self._get_vol_type_filter_options())
     if context.is_admin:
         # Only admin has query access to all volume types
         filters['is_public'] = self._parse_is_public(
             req.params.get('is_public', None))
     else:
         filters['is_public'] = True
     if 'extra_specs' in filters:
         try:
             filters['extra_specs'] = ast.literal_eval(
                 filters['extra_specs'])
         except (ValueError, SyntaxError):
             LOG.debug('Could not evaluate "extra_specs" %s, assuming '
                       'dictionary string.', filters['extra_specs'])
     limited_types = volume_types.get_all_types(context,
                                                filters=filters,
                                                marker=marker, limit=limit,
                                                sort_keys=sort_keys,
                                                sort_dirs=sort_dirs,
                                                offset=offset,
                                                list_result=True)
     return limited_types
Exemplo n.º 28
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
Exemplo n.º 29
0
 def index(self, req):
     """ Returns the list of volume types """
     context = req.environ['cinder.context']
     return {'volume_types': volume_types.get_all_types(context).values()}
Exemplo n.º 30
0
 def test_get_all_volume_types(self):
     """Ensures that all volume types can be retrieved."""
     session = db_api.get_session()
     total_volume_types = session.query(models.VolumeTypes).count()
     vol_types = volume_types.get_all_types(self.ctxt)
     self.assertEqual(total_volume_types, len(vol_types))
Exemplo n.º 31
0
 def get_all(cls, context, inactive=0, search_opts=None):
     types = volume_types.get_all_types(context, inactive, search_opts)
     expected_attrs = ["extra_specs", "projects"]
     return base.obj_make_list(
         context, cls(context), objects.VolumeType, types.values(), expected_attrs=expected_attrs
     )
Exemplo n.º 32
0
 def index(self, req):
     """Returns the list of volume types."""
     context = req.environ['cinder.context']
     vol_types = volume_types.get_all_types(context).values()
     return self._view_builder.index(req, vol_types)
Exemplo n.º 33
0
 def test_get_all_volume_types(self):
     """Ensures that all volume types can be retrieved."""
     session = db_api.get_session()
     total_volume_types = session.query(models.VolumeTypes).count()
     vol_types = volume_types.get_all_types(self.ctxt)
     self.assertEqual(total_volume_types, len(vol_types))
Exemplo n.º 34
0
 def index(self, req):
     """Returns the list of volume types."""
     context = req.environ['cinder.context']
     vol_types = volume_types.get_all_types(context).values()
     return self._view_builder.index(req, vol_types)