Skip to content

Commit

Permalink
Check the display name for volumes on AJAX polls.
Browse files Browse the repository at this point in the history
If a volume is created from the CLI without a name,
its displayed name on the Dashboard will be its id.

Change-Id: I806df643d7a2e0e93db673ea9718fe30927d930e
Implements: Display name check for unnamed volumes
Fixes: bug #1070042
  • Loading branch information
vkmc committed Jan 9, 2013
1 parent 511cac9 commit 158ce5c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
20 changes: 11 additions & 9 deletions openstack_dashboard/dashboards/project/volumes/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,19 @@ def handle(self, request, data):
# it, so let's slice that off...
instance_name = instance_name.rsplit(" (")[0]
try:
vol = api.instance_volume_attach(request,
data['volume_id'],
data['instance'],
data.get('device', ''))
vol_name = cinder.volume_get(request,
data['volume_id']).display_name

attach = api.instance_volume_attach(request,
data['volume_id'],
data['instance'],
data.get('device', ''))
volume = cinder.volume_get(request, data['volume_id'])
if not volume.display_name:
volume_name = volume.id
else:
volume_name = volume.display_name
message = _('Attaching volume %(vol)s to instance '
'%(inst)s on %(dev)s.') % {"vol": vol_name,
'%(inst)s on %(dev)s.') % {"vol": volume_name,
"inst": instance_name,
"dev": vol.device}
"dev": attach.device}
messages.info(request, message)
return True
except:
Expand Down
2 changes: 2 additions & 0 deletions openstack_dashboard/dashboards/project/volumes/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class UpdateRow(tables.Row):

def get_data(self, request, volume_id):
volume = cinder.volume_get(request, volume_id)
if not volume.display_name:
volume.display_name = volume_id
return volume


Expand Down
18 changes: 18 additions & 0 deletions openstack_dashboard/dashboards/project/volumes/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,21 @@ def test_detail_view(self):
200)

self.assertNoMessages()

@test.create_stubs({cinder: ('volume_get',)})
def test_get_data(self):
volume = self.volumes.first()
volume.display_name = ''

cinder.volume_get(IsA(http.HttpRequest), volume.id).AndReturn(volume)

self.mox.ReplayAll()

url = reverse('horizon:project:volumes:index') + \
"?action=row_update&table=volumes&obj_id=" + volume.id

res = self.client.get(url, {},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')

self.assertEqual(res.status_code, 200)
self.assertEqual(volume.display_name, volume.id)

0 comments on commit 158ce5c

Please sign in to comment.