Esempio n. 1
0
    def test_volume_list_by_status(self):
        db.volume_create(self.ctxt, {"display_name": "vol1", "status": "available"})
        db.volume_create(self.ctxt, {"display_name": "vol2", "status": "available"})
        db.volume_create(self.ctxt, {"display_name": "vol3", "status": "in-use"})

        # no status filter
        volumes = db.volume_get_all(self.ctxt, None, None, "created_at", "asc")
        self.assertEqual(len(volumes), 3)
        # single match
        volumes = db.volume_get_all(self.ctxt, None, None, "created_at", "asc", {"status": "in-use"})
        self.assertEqual(len(volumes), 1)
        self.assertEqual(volumes[0]["status"], "in-use")
        # multiple match
        volumes = db.volume_get_all(self.ctxt, None, None, "created_at", "asc", {"status": "available"})
        self.assertEqual(len(volumes), 2)
        for volume in volumes:
            self.assertEqual(volume["status"], "available")
        # multiple filters
        volumes = db.volume_get_all(
            self.ctxt, None, None, "created_at", "asc", {"status": "available", "display_name": "vol1"}
        )
        self.assertEqual(len(volumes), 1)
        self.assertEqual(volumes[0]["display_name"], "vol1")
        self.assertEqual(volumes[0]["status"], "available")
        # no match
        volumes = db.volume_get_all(
            self.ctxt, None, None, "created_at", "asc", {"status": "in-use", "display_name": "vol1"}
        )
        self.assertEqual(len(volumes), 0)
Esempio n. 2
0
    def test_volume_get_by_name(self):
        db.volume_create(self.ctxt, {"display_name": "vol1"})
        db.volume_create(self.ctxt, {"display_name": "vol2"})
        db.volume_create(self.ctxt, {"display_name": "vol3"})

        # no name filter
        volumes = db.volume_get_all(self.ctxt, None, None, "created_at", "asc")
        self.assertEqual(len(volumes), 3)
        # filter on name
        volumes = db.volume_get_all(self.ctxt, None, None, "created_at", "asc", {"display_name": "vol2"})
        self.assertEqual(len(volumes), 1)
        self.assertEqual(volumes[0]["display_name"], "vol2")
        # filter no match
        volumes = db.volume_get_all(self.ctxt, None, None, "created_at", "asc", {"display_name": "vol4"})
        self.assertEqual(len(volumes), 0)
Esempio n. 3
0
 def _assertEqualsVolumeOrderResult(
     self,
     correct_order,
     limit=None,
     sort_key="created_at",
     sort_dir="asc",
     filters=None,
     project_id=None,
     match_keys=["id", "display_name", "volume_metadata", "created_at"],
 ):
     """"Verifies that volumes are returned in the correct order."""
     if project_id:
         result = db.volume_get_all_by_project(
             self.ctxt, project_id, None, limit, sort_key, sort_dir, filters=filters
         )
     else:
         result = db.volume_get_all(self.ctxt, None, limit, sort_key, sort_dir, filters=filters)
     self.assertEqual(len(correct_order), len(result))
     for vol1, vol2 in zip(result, correct_order):
         for key in match_keys:
             val1 = vol1.get(key)
             val2 = vol2.get(key)
             # metadata is a dict, compare the 'key' and 'value' of each
             if key == "volume_metadata":
                 self.assertEqual(len(val1), len(val2))
                 val1_dict = dict((x.key, x.value) for x in val1)
                 val2_dict = dict((x.key, x.value) for x in val2)
                 self.assertDictMatch(val1_dict, val2_dict)
             else:
                 self.assertEqual(val1, val2)
Esempio n. 4
0
 def get_all(cls, context, marker, limit, sort_keys=None, sort_dirs=None,
             filters=None, offset=None):
     volumes = db.volume_get_all(context, marker, limit,
                                 sort_keys=sort_keys, sort_dirs=sort_dirs,
                                 filters=filters, offset=offset)
     expected_attrs = cls._get_expected_attrs(context)
     return base.obj_make_list(context, cls(context), objects.Volume,
                               volumes, expected_attrs=expected_attrs)
Esempio n. 5
0
 def _local_volume_references(self, cntx):
     """
     Get IDs of all volumes in Cinder.
     """
     all_vols = db.volume_get_all(
         cntx, marker=None, limit=None,
         sort_key='created_at', sort_dir='desc')
     return [vol['id'] for vol in all_vols]
Esempio n. 6
0
 def _allow_update(self, context, type_id):
     vols = db.volume_get_all(ctxt.get_admin_context(),
                              limit=1,
                              filters={'volume_type_id': type_id})
     if len(vols):
         expl = _('Volume Type is currently in use.')
         raise webob.exc.HTTPBadRequest(explanation=expl)
     return
Esempio n. 7
0
 def get_all(cls, context, marker, limit, sort_key, sort_dir, filters=None):
     volumes = db.volume_get_all(context,
                                 marker,
                                 limit,
                                 sort_key,
                                 sort_dir,
                                 filters=filters)
     return base.obj_make_list(context, cls(context), objects.Volume,
                               volumes)
Esempio n. 8
0
 def test_volume_get_all(self):
     volumes = [
         db.volume_create(self.ctxt, {
             'host': 'h%d' % i,
             'size': i
         }) for i in xrange(3)
     ]
     self._assertEqualListsOfObjects(
         volumes, db.volume_get_all(self.ctxt, None, None, 'host', None))
Esempio n. 9
0
 def _allow_update(self, context, type_id):
     vols = db.volume_get_all(
         ctxt.get_admin_context(),
         limit=1,
         filters={'volume_type_id': type_id})
     if len(vols):
         expl = _('Volume Type is currently in use.')
         raise webob.exc.HTTPBadRequest(explanation=expl)
     return
Esempio n. 10
0
    def test_volume_get_all_marker_passed(self):
        volumes = [
            db.volume_create(self.ctxt, {"id": 1}),
            db.volume_create(self.ctxt, {"id": 2}),
            db.volume_create(self.ctxt, {"id": 3}),
            db.volume_create(self.ctxt, {"id": 4}),
        ]

        self._assertEqualListsOfObjects(volumes[2:], db.volume_get_all(self.ctxt, 2, 2, "id", None))
Esempio n. 11
0
    def test_volume_get_all_marker_passed(self):
        volumes = [
            db.volume_create(self.ctxt, {'id': 1}),
            db.volume_create(self.ctxt, {'id': 2}),
            db.volume_create(self.ctxt, {'id': 3}),
            db.volume_create(self.ctxt, {'id': 4}),
        ]

        self._assertEqualListsOfObjects(
            volumes[2:], db.volume_get_all(self.ctxt, 2, 2, 'id', None))
Esempio n. 12
0
 def _check_service_uuid(self):
     try:
         db.service_get_by_uuid(self.context, None)
     except exception.ServiceNotFound:
         volumes = db.volume_get_all(self.context,
                                     limit=1,
                                     filters={'service_uuid': None})
         if not volumes:
             return uc.Result(SUCCESS)
     return uc.Result(
         FAILURE,
         'Services and volumes must have a service UUID. Please fix this '
         'issue by running Queens online data migrations.')
Esempio n. 13
0
 def _allow_update(self, context, type_id):
     if (not CONF.allow_inuse_volume_type_modification):
         vols = db.volume_get_all(ctxt.get_admin_context(),
                                  limit=1,
                                  filters={'volume_type_id': type_id})
         if len(vols):
             expl = _('Volume Type is currently in use.')
             raise webob.exc.HTTPBadRequest(explanation=expl)
     else:
         msg = ("The option 'allow_inuse_volume_type_modification' "
                "is deprecated and will be removed in a future "
                "release.  The default behavior going forward will "
                "be to disallow modificaton of in-use types.")
         versionutils.report_deprecated_feature(LOG, msg)
     return
Esempio n. 14
0
 def _allow_update(self, context, type_id):
     if (not CONF.allow_inuse_volume_type_modification):
         vols = db.volume_get_all(
             ctxt.get_admin_context(),
             limit=1,
             filters={'volume_type_id': type_id})
         if len(vols):
             expl = _('Volume Type is currently in use.')
             raise webob.exc.HTTPBadRequest(explanation=expl)
     else:
         msg = ("The option 'allow_inuse_volume_type_modification' "
                "is deprecated and will be removed in a future "
                "release.  The default behavior going forward will "
                "be to disallow modificaton of in-use types.")
         versionutils.report_deprecated_feature(LOG, msg)
     return
Esempio n. 15
0
 def get_all(cls, context, marker, limit, sort_key, sort_dir,
             filters=None):
     volumes = db.volume_get_all(context, marker, limit, sort_key,
                                 sort_dir, filters=filters)
     return base.obj_make_list(context, cls(context), objects.Volume,
                               volumes)
Esempio n. 16
0
 def test_volume_get_all(self):
     volumes = [db.volume_create(self.ctxt,
                {'host': 'h%d' % i, 'size': i})
                for i in xrange(3)]
     self._assertEqualListsOfObjects(volumes, db.volume_get_all(
                                     self.ctxt, None, None, 'host', None))
Esempio n. 17
0
 def test_volume_get_all(self):
     volumes = [db.volume_create(self.ctxt, {"host": "h%d" % i, "size": i}) for i in xrange(3)]
     self._assertEqualListsOfObjects(volumes, db.volume_get_all(self.ctxt, None, None, "host", None))