Пример #1
0
    def _check_volume_size_quota(self, context, requested_size=1):
        allowed_volume_size = quota.allowed_volume_size(context, requested_size)
        LOG.debug('size of volume allowed to create %s' % allowed_volume_size)
        if allowed_volume_size < requested_size:
            tid = context.tenant
            if allowed_volume_size <= 0:
                msg = _("Cannot allocated any more volume space.")
            else:
                msg = (_("Can only allocated %s more space for volumes.") %
                       allowed_volume_size)
            LOG.warn(_("Quota exceeded for %(tid)s,"
                  " tried to allocate %(requested_size)s volume space. %(msg)s"), locals())
            
            raise exception.QuotaError("VolumeSizeLimitExceeded")

        return allowed_volume_size
Пример #2
0
    def test_allowed_volume_size_exceeds_quota(self):
        """ Ensure that a 0 is returned when used volume size == quota limit """
        DUMMY_DBVOLUME_LIST = [{"size": 4}, {"size": 6}]

        # Pretend that 2 volume exists for this tenant
        self.mock.StubOutWithMock(models.DBVolume, "find_all")
        models.DBVolume.find_all(tenant_id="12345", deleted=False).AndReturn(DUMMY_DBVOLUME_LIST)

        # Allow up to 20 GBs of volume space
        default_quotas = [{"tenant_id": "12345", "hard_limit": 10, "resource": "volume_space"}]
        self.mock.StubOutWithMock(models.Quota, "find_all")
        models.Quota.find_all(tenant_id="12345", deleted=False).AndReturn(default_quotas)

        self.mock.ReplayAll()

        # Check if we are allowed to create 1 snapshot
        allowed = quota.allowed_volume_size(self.DUMMY_CONTEXT, 1)
        self.assertTrue(allowed == 0, "Expected 0 allowed volume space, instead got %s" % allowed)
Пример #3
0
    def test_allowed_volume_size_truncated(self):
        """ Ensure that the request for a volume size that exceeds quota
        gets truncated to the maximum allowed """
        DUMMY_DBVOLUME_LIST = [{"size": 4}, {"size": 2}]

        # Pretend that 2 volumes exists for this tenant
        self.mock.StubOutWithMock(models.DBVolume, "find_all")
        models.DBVolume.find_all(tenant_id="12345", deleted=False).AndReturn(DUMMY_DBVOLUME_LIST)

        # Allow up to 5 snapshots to be created
        default_quotas = [{"tenant_id": "12345", "hard_limit": 10, "resource": "volume_space"}]
        self.mock.StubOutWithMock(models.Quota, "find_all")
        models.Quota.find_all(tenant_id="12345", deleted=False).AndReturn(default_quotas)

        self.mock.ReplayAll()

        # Check if we are allowed to create 1 snapshot
        allowed = quota.allowed_volume_size(self.DUMMY_CONTEXT, 5)
        self.assertTrue(allowed == 4, "Expected 4 GB allowed volume space, instead got %s" % allowed)
Пример #4
0
    def test_allowed_volume_size(self):
        """Tests that given a quota on volume_space, the size of 
        volume allowed to be created is calculated appropriately"""

        DUMMY_DBVOLUME_LIST = [{"size": 4}, {"size": 2}]

        # Pretend that 2 volume exists for this tenant
        self.mock.StubOutWithMock(models.DBVolume, "find_all")
        models.DBVolume.find_all(tenant_id="12345", deleted=False).AndReturn(DUMMY_DBVOLUME_LIST)

        # Allow up to 20 GBs of volume space
        default_quotas = [{"tenant_id": "12345", "hard_limit": 20, "resource": "volume_space"}]
        self.mock.StubOutWithMock(models.Quota, "find_all")
        models.Quota.find_all(tenant_id="12345", deleted=False).AndReturn(default_quotas)

        self.mock.ReplayAll()

        # Check if we are allowed to create volume of 5 GBs
        allowed = quota.allowed_volume_size(self.DUMMY_CONTEXT, 5)
        self.assertTrue(allowed == 5, "Expected size of 5 allowed for volumes size, instead got %s" % allowed)