Merge "Validation check if exceeding vol snapshot quota"
This commit is contained in:
commit
9d4d2740b1
@ -177,6 +177,19 @@ class CreateSnapshot(tables.LinkAction):
|
||||
return {"project_id": project_id}
|
||||
|
||||
def allowed(self, request, volume=None):
|
||||
try:
|
||||
limits = api.cinder.tenant_absolute_limits(request)
|
||||
except Exception:
|
||||
exceptions.handle(request, _('Unable to retrieve tenant limits.'))
|
||||
limits = {}
|
||||
|
||||
snapshots_available = (limits.get('maxTotalSnapshots', float("inf"))
|
||||
- limits.get('totalSnapshotsUsed', 0))
|
||||
|
||||
if snapshots_available <= 0 and "disabled" not in self.classes:
|
||||
self.classes = [c for c in self.classes] + ['disabled']
|
||||
self.verbose_name = string_concat(self.verbose_name, ' ',
|
||||
_("(Quota exceeded)"))
|
||||
return volume.status in ("available", "in-use")
|
||||
|
||||
|
||||
|
@ -877,6 +877,36 @@ class VolumeViewTests(test.TestCase):
|
||||
server.id)
|
||||
self.assertEqual(res.status_code, 200)
|
||||
|
||||
@test.create_stubs({cinder: ('tenant_absolute_limits',
|
||||
'volume_get',)})
|
||||
def test_create_snapshot_button_disabled_when_quota_exceeded(self):
|
||||
limits = {'maxTotalSnapshots': 1}
|
||||
limits['totalSnapshotsUsed'] = limits['maxTotalSnapshots']
|
||||
volume = self.cinder_volumes.first()
|
||||
|
||||
cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
|
||||
cinder.tenant_absolute_limits(IsA(http.HttpRequest)).AndReturn(limits)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
create_link = tables.CreateSnapshot()
|
||||
url = reverse(create_link.get_link_url(), args=[volume.id])
|
||||
res_url = VOLUME_INDEX_URL + \
|
||||
"?action=row_update&table=volumes&obj_id=" + volume.id
|
||||
|
||||
res = self.client.get(res_url, {},
|
||||
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
|
||||
classes = list(create_link.get_default_classes())\
|
||||
+ list(create_link.classes)
|
||||
link_name = "%s (%s)" % (unicode(create_link.verbose_name),
|
||||
"Quota exceeded")
|
||||
expected_string = "<a href='%s' class=\"%s disabled\" "\
|
||||
"id=\"volumes__row_%s__action_snapshots\">%s</a>" \
|
||||
% (url, " ".join(classes), volume.id, link_name)
|
||||
|
||||
self.assertContains(res, expected_string, html=True,
|
||||
msg_prefix="The create snapshot button is not disabled")
|
||||
|
||||
@test.create_stubs({cinder: ('tenant_absolute_limits',
|
||||
'volume_list',
|
||||
'volume_backup_supported',),
|
||||
@ -947,13 +977,17 @@ class VolumeViewTests(test.TestCase):
|
||||
|
||||
self.assertNoMessages()
|
||||
|
||||
@test.create_stubs({cinder: ('volume_get',)})
|
||||
@test.create_stubs({cinder: ('tenant_absolute_limits',
|
||||
'volume_get',)})
|
||||
def test_get_data(self):
|
||||
volume = self.cinder_volumes.get(name='v2_volume')
|
||||
volume._apiresource.name = ""
|
||||
|
||||
cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)
|
||||
|
||||
cinder.tenant_absolute_limits(IsA(http.HttpRequest))\
|
||||
.MultipleTimes().AndReturn(self.cinder_limits['absolute'])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = VOLUME_INDEX_URL + \
|
||||
|
Loading…
x
Reference in New Issue
Block a user