manchandavishal c2a3c62039 Add volume group list/show support for admin panel
This commit allows admin to list /show cinder volume groups
using horizon dashboard.

TODO:
1. Modify/Delete volume groups

Partially-Implements blueprint cinder-generic-volume-groups

Change-Id: I75d463204cf83492b30523f46dd0507bbb86dd2e
2019-01-23 10:11:53 +00:00

86 lines
3.5 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from django.urls import reverse
from openstack_dashboard import api
from openstack_dashboard.api import cinder
from openstack_dashboard.test import helpers as test
INDEX_URL = reverse('horizon:admin:volume_groups:index')
INDEX_TEMPLATE = 'horizon/common/_data_table_view.html'
class AdminVolumeGroupTests(test.BaseAdminViewTests):
@test.create_mocks({api.cinder: ['group_list_with_vol_type_names',
'group_snapshot_list']})
def test_index(self):
group = self.cinder_groups.list()
vg_snapshot = self.cinder_group_snapshots.list()
self.mock_group_list_with_vol_type_names.return_value = group
self.mock_group_snapshot_list.return_value = vg_snapshot
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, INDEX_TEMPLATE)
self.assertIn('volume_groups_table', res.context)
volume_groups_table = res.context['volume_groups_table']
volume_groups = volume_groups_table.data
self.assertEqual(len(volume_groups), 1)
self.mock_group_list_with_vol_type_names.assert_called_once_with(
test.IsHttpRequest(), {'all_tenants': 1})
self.mock_group_snapshot_list.assert_called_once_with(
test.IsHttpRequest())
@test.create_mocks({cinder: ['group_get_with_vol_type_names',
'volume_list',
'group_snapshot_list']})
def test_detail_view(self):
group = self.cinder_groups.first()
volumes = self.cinder_volumes.list()
vg_snapshot = self.cinder_group_snapshots.list()
self.mock_group_get_with_vol_type_names.return_value = group
self.mock_volume_list.return_value = volumes
self.mock_group_snapshot_list.return_value = vg_snapshot
url = reverse('horizon:admin:volume_groups:detail',
args=[group.id])
res = self.client.get(url)
self.assertNoFormErrors(res)
self.assertEqual(res.status_code, 200)
self.assertTrue(group.has_snapshots)
self.mock_group_get_with_vol_type_names.assert_called_once_with(
test.IsHttpRequest(), group.id)
search_opts = {'group_id': group.id}
self.mock_volume_list.assert_called_once_with(
test.IsHttpRequest(), search_opts=search_opts)
self.mock_group_snapshot_list.assert_called_once_with(
test.IsHttpRequest(), search_opts=search_opts)
@test.create_mocks({cinder: ['group_get']})
def test_detail_view_with_exception(self):
group = self.cinder_groups.first()
self.mock_group_get.side_effect = self.exceptions.cinder
url = reverse('horizon:admin:volume_groups:detail',
args=[group.id])
res = self.client.get(url)
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL)
self.mock_group_get.assert_called_once_with(
test.IsHttpRequest(), group.id)