Merge "Add Project Information column in group-snapshot table"
This commit is contained in:
commit
85aac1b32c
|
@ -197,7 +197,7 @@ class Group(base.APIResourceWrapper):
|
|||
|
||||
class GroupSnapshot(base.APIResourceWrapper):
|
||||
_attrs = ['id', 'name', 'description', 'status', 'created_at',
|
||||
'group_id', 'group_type_id']
|
||||
'group_id', 'group_type_id', 'project_id']
|
||||
|
||||
|
||||
class GroupType(base.APIResourceWrapper):
|
||||
|
|
|
@ -14,14 +14,35 @@
|
|||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.dashboards.project.vg_snapshots \
|
||||
import tables as project_tables
|
||||
|
||||
|
||||
class UpdateRow(tables.Row):
|
||||
ajax = True
|
||||
|
||||
def get_data(self, request, vg_snapshot_id):
|
||||
vg_snapshot = api.cinder.group_snapshot_get(request, vg_snapshot_id)
|
||||
vg_snapshot.group = api.cinder.group_get(request,
|
||||
vg_snapshot.group_id)
|
||||
tenant_id = getattr(vg_snapshot.group, 'project_id')
|
||||
|
||||
try:
|
||||
tenant = api.keystone.tenant_get(request, tenant_id)
|
||||
vg_snapshot.tenant_name = getattr(tenant, "name")
|
||||
except Exception:
|
||||
msg = _('Unable to retrieve group snapshot project information.')
|
||||
exceptions.handle(request, msg)
|
||||
|
||||
return vg_snapshot
|
||||
|
||||
|
||||
class GroupSnapshotsTable(project_tables.GroupSnapshotsTable):
|
||||
# TODO(vishalmanchanda): Add Project Info.column in table
|
||||
project = tables.Column("tenant_name", verbose_name=_("Project"))
|
||||
name = tables.Column("name_or_id",
|
||||
verbose_name=_("Name"),
|
||||
link="horizon:admin:vg_snapshots:detail")
|
||||
|
@ -39,5 +60,7 @@ class GroupSnapshotsTable(project_tables.GroupSnapshotsTable):
|
|||
row_actions = (
|
||||
project_tables.DeleteGroupSnapshot,
|
||||
)
|
||||
row_class = project_tables.UpdateRow
|
||||
row_class = UpdateRow
|
||||
status_columns = ("status",)
|
||||
columns = ('project', 'name', 'description', 'status',
|
||||
'group')
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
<dt>{% trans "Description" %}</dt>
|
||||
<dd>{{ vg_snapshot.description }}</dd>
|
||||
{% endif %}
|
||||
<dt>{% trans "Project ID" %}</dt>
|
||||
<dd>{{ vg_snapshot.project_id|default:_("-") }}</dd>
|
||||
<dt>{% trans "Status" %}</dt>
|
||||
<dd>{{ vg_snapshot.status|capfirst }}</dd>
|
||||
<dt>{% trans "Group" %}</dt>
|
||||
|
|
|
@ -26,13 +26,16 @@ INDEX_TEMPLATE = 'horizon/common/_data_table_view.html'
|
|||
|
||||
class AdminGroupSnapshotTests(test.BaseAdminViewTests):
|
||||
@test.create_mocks({
|
||||
api.keystone: ['tenant_list'],
|
||||
api.cinder: ['group_list',
|
||||
'group_snapshot_list']})
|
||||
def test_index(self):
|
||||
vg_snapshots = self.cinder_group_snapshots.list()
|
||||
groups = self.cinder_groups.list()
|
||||
tenants = self.tenants.list()
|
||||
self.mock_group_snapshot_list.return_value = vg_snapshots
|
||||
self.mock_group_list.return_value = groups
|
||||
self.mock_tenant_list.return_value = [tenants, False]
|
||||
|
||||
res = self.client.get(INDEX_URL)
|
||||
self.assertTemplateUsed(res, INDEX_TEMPLATE)
|
||||
|
@ -41,21 +44,25 @@ class AdminGroupSnapshotTests(test.BaseAdminViewTests):
|
|||
volume_vg_snapshots = volume_vg_snapshots_table.data
|
||||
self.assertEqual(len(volume_vg_snapshots), 1)
|
||||
|
||||
self.mock_tenant_list.assert_called_once_with(test.IsHttpRequest())
|
||||
self.mock_group_snapshot_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), {'all_tenants': 1})
|
||||
self.mock_group_list.assert_called_once_with(
|
||||
test.IsHttpRequest(), {'all_tenants': 1})
|
||||
|
||||
@test.create_mocks({
|
||||
api.keystone: ['tenant_list'],
|
||||
api.cinder: ['group_list',
|
||||
'group_snapshot_delete',
|
||||
'group_snapshot_list']})
|
||||
def test_delete_group_snapshot(self):
|
||||
vg_snapshots = self.cinder_group_snapshots.list()
|
||||
vg_snapshot = self.cinder_group_snapshots.first()
|
||||
tenants = self.tenants.list()
|
||||
self.mock_group_snapshot_list.return_value = vg_snapshots
|
||||
self.mock_group_snapshot_delete.return_value = None
|
||||
self.mock_group_list.return_value = self.cinder_groups.list()
|
||||
self.mock_tenant_list.return_value = [tenants, False]
|
||||
|
||||
form_data = {'action': 'volume_vg_snapshots__delete_vg_snapshot__%s'
|
||||
% vg_snapshot.id}
|
||||
|
@ -74,15 +81,18 @@ class AdminGroupSnapshotTests(test.BaseAdminViewTests):
|
|||
mock.call(test.IsHttpRequest(), {'all_tenants': 1}))
|
||||
|
||||
@test.create_mocks({
|
||||
api.keystone: ['tenant_list'],
|
||||
api.cinder: ['group_list',
|
||||
'group_snapshot_delete',
|
||||
'group_snapshot_list']})
|
||||
def test_delete_group_snapshot_exception(self):
|
||||
vg_snapshots = self.cinder_group_snapshots.list()
|
||||
vg_snapshot = self.cinder_group_snapshots.first()
|
||||
tenants = self.tenants.list()
|
||||
self.mock_group_snapshot_list.return_value = vg_snapshots
|
||||
self.mock_group_snapshot_delete.side_effect = self.exceptions.cinder
|
||||
self.mock_group_list.return_value = self.cinder_groups.list()
|
||||
self.mock_tenant_list.return_value = [tenants, False]
|
||||
|
||||
form_data = {'action': 'volume_vg_snapshots__delete_vg_snapshot__%s'
|
||||
% vg_snapshot.id}
|
||||
|
|
|
@ -49,8 +49,25 @@ class IndexView(tables.DataTableView):
|
|||
groups = {}
|
||||
exceptions.handle(self.request,
|
||||
_("Unable to retrieve volume groups."))
|
||||
|
||||
# Gather our tenants to correlate against Group IDs
|
||||
try:
|
||||
tenants, has_more = api.keystone.tenant_list(self.request)
|
||||
except Exception:
|
||||
tenants = []
|
||||
msg = _('Unable to retrieve group snapshot project information.')
|
||||
exceptions.handle(self.request, msg)
|
||||
|
||||
tenant_dict = dict((t.id, t) for t in tenants)
|
||||
for vg_snapshot in vg_snapshots:
|
||||
vg_snapshot.group = groups.get(vg_snapshot.group_id)
|
||||
tenant_id = getattr(vg_snapshot, "project_id", None)
|
||||
tenant = tenant_dict.get(tenant_id)
|
||||
|
||||
# NOTE: If horizon is using cinder API microversion below '3.58',
|
||||
# it doesn't include any 'project id' information in group
|
||||
# snapshot's object.
|
||||
vg_snapshot.tenant_name = getattr(tenant, "name", None)
|
||||
return vg_snapshots
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue