Move Admin Volume Snapshots out of tabbed panel
Change-Id: I8c569a0d0fa5e990524012cacee50f9a249aa5e1 Implements: blueprint reorganise-volumes
This commit is contained in:
parent
46ad19dbf0
commit
e89c377599
@ -61,7 +61,7 @@ class UpdateStatus(forms.SelfHandlingForm):
|
||||
' status: "%s".') % choice)
|
||||
return True
|
||||
except Exception:
|
||||
redirect = reverse("horizon:admin:volumes:index")
|
||||
redirect = reverse("horizon:admin:snapshots:index")
|
||||
exceptions.handle(request,
|
||||
_('Unable to update volume snapshot status.'),
|
||||
redirect=redirect)
|
26
openstack_dashboard/dashboards/admin/snapshots/panel.py
Normal file
26
openstack_dashboard/dashboards/admin/snapshots/panel.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright 2017 Rackspace, Inc.
|
||||
#
|
||||
# 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.utils.translation import ugettext_lazy as _
|
||||
|
||||
import horizon
|
||||
|
||||
|
||||
class Snapshots(horizon.Panel):
|
||||
name = _("Snapshots")
|
||||
slug = 'snapshots'
|
||||
permissions = (
|
||||
('openstack.services.volume', 'openstack.services.volumev2'),
|
||||
)
|
||||
policy_rules = (("volume", "context_is_admin"),)
|
@ -27,7 +27,7 @@ from openstack_dashboard.dashboards.project.volumes \
|
||||
class UpdateVolumeSnapshotStatus(tables.LinkAction):
|
||||
name = "update_status"
|
||||
verbose_name = _("Update Status")
|
||||
url = "horizon:admin:volumes:snapshots:update_status"
|
||||
url = "horizon:admin:snapshots:update_status"
|
||||
classes = ("ajax-modal",)
|
||||
icon = "pencil"
|
||||
policy_rules = (("volume",
|
||||
@ -57,7 +57,7 @@ class UpdateRow(tables.Row):
|
||||
|
||||
class VolumeSnapshotsTable(volumes_tables.VolumesTableBase):
|
||||
name = tables.WrappingColumn("name", verbose_name=_("Name"),
|
||||
link="horizon:admin:volumes:snapshots:detail")
|
||||
link="horizon:admin:snapshots:detail")
|
||||
volume_name = snapshots_tables.SnapshotVolumeNameColumn(
|
||||
"name", verbose_name=_("Volume Name"),
|
||||
link="horizon:admin:volumes:volumes:detail")
|
@ -25,7 +25,7 @@ class OverviewTab(overview_tab.OverviewTab):
|
||||
template_name = ("project/snapshots/_detail_overview.html")
|
||||
|
||||
def get_redirect_url(self):
|
||||
return reverse('horizon:admin:volumes:index')
|
||||
return reverse('horizon:admin:snapshots:index')
|
||||
|
||||
|
||||
class SnapshotDetailsTabs(tabs.TabGroup):
|
241
openstack_dashboard/dashboards/admin/snapshots/tests.py
Normal file
241
openstack_dashboard/dashboards/admin/snapshots/tests.py
Normal file
@ -0,0 +1,241 @@
|
||||
# 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.conf import settings
|
||||
from django.core.urlresolvers import reverse
|
||||
from django import http
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.http import urlunquote
|
||||
from mox3.mox import IsA # noqa
|
||||
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.api import keystone
|
||||
from openstack_dashboard.test import helpers as test
|
||||
|
||||
from openstack_dashboard.dashboards.admin.snapshots import forms
|
||||
from openstack_dashboard.dashboards.admin.snapshots import tables
|
||||
|
||||
INDEX_URL = 'horizon:admin:snapshots:index'
|
||||
|
||||
|
||||
class VolumeSnapshotsViewTests(test.BaseAdminViewTests):
|
||||
@test.create_stubs({cinder: ('volume_list',
|
||||
'volume_snapshot_list_paged',),
|
||||
keystone: ('tenant_list',)})
|
||||
def test_snapshots_tab(self):
|
||||
cinder.volume_snapshot_list_paged(
|
||||
IsA(http.HttpRequest), paginate=True, marker=None, sort_dir='desc',
|
||||
search_opts={'all_tenants': True},).AndReturn(
|
||||
[self.cinder_volume_snapshots.list(), False, False])
|
||||
cinder.volume_list(IsA(http.HttpRequest), search_opts={
|
||||
'all_tenants': True}).\
|
||||
AndReturn(self.cinder_volumes.list())
|
||||
keystone.tenant_list(IsA(http.HttpRequest)). \
|
||||
AndReturn([self.tenants.list(), False])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
url = reverse(INDEX_URL)
|
||||
res = self.client.get(urlunquote(url))
|
||||
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, self.cinder_volume_snapshots.list())
|
||||
|
||||
@test.create_stubs({cinder: ('volume_list',
|
||||
'volume_snapshot_list_paged',),
|
||||
keystone: ('tenant_list',)})
|
||||
def _test_snapshots_index_paginated(self, marker, sort_dir, snapshots, url,
|
||||
has_more, has_prev):
|
||||
cinder.volume_snapshot_list_paged(
|
||||
IsA(http.HttpRequest), paginate=True, marker=marker,
|
||||
sort_dir=sort_dir, search_opts={'all_tenants': True}) \
|
||||
.AndReturn([snapshots, has_more, has_prev])
|
||||
cinder.volume_list(IsA(http.HttpRequest), search_opts={
|
||||
'all_tenants': True}).\
|
||||
AndReturn(self.cinder_volumes.list())
|
||||
keystone.tenant_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn([self.tenants.list(), False])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(urlunquote(url))
|
||||
|
||||
self.assertTemplateUsed(res, 'horizon/common/_data_table_view.html')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
|
||||
self.mox.UnsetStubs()
|
||||
return res
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=1)
|
||||
def test_snapshots_index_paginated(self):
|
||||
size = settings.API_RESULT_PAGE_SIZE
|
||||
mox_snapshots = self.cinder_volume_snapshots.list()
|
||||
base_url = reverse(INDEX_URL)
|
||||
next = tables.VolumeSnapshotsTable._meta.pagination_param
|
||||
|
||||
# get first page
|
||||
expected_snapshots = mox_snapshots[:size]
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=None, sort_dir="desc", snapshots=expected_snapshots,
|
||||
url=base_url, has_more=True, has_prev=False)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
# get second page
|
||||
expected_snapshots = mox_snapshots[size:2 * size]
|
||||
marker = expected_snapshots[0].id
|
||||
url = base_url + "?%s=%s" % (next, marker)
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="desc", snapshots=expected_snapshots,
|
||||
url=url, has_more=True, has_prev=True)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
# get last page
|
||||
expected_snapshots = mox_snapshots[-size:]
|
||||
marker = expected_snapshots[0].id
|
||||
url = base_url + "?%s=%s" % (next, marker)
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="desc", snapshots=expected_snapshots,
|
||||
url=url, has_more=False, has_prev=True)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=1)
|
||||
def test_snapshots_index_paginated_prev(self):
|
||||
size = settings.API_RESULT_PAGE_SIZE
|
||||
max_snapshots = self.cinder_volume_snapshots.list()
|
||||
base_url = reverse('horizon:admin:snapshots:index')
|
||||
prev = tables.VolumeSnapshotsTable._meta.prev_pagination_param
|
||||
|
||||
# prev from some page
|
||||
expected_snapshots = max_snapshots[size:2 * size]
|
||||
marker = max_snapshots[0].id
|
||||
url = base_url + "?%s=%s" % (prev, marker)
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="asc", snapshots=expected_snapshots,
|
||||
url=url, has_more=False, has_prev=True)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
# back to first page
|
||||
expected_snapshots = max_snapshots[:size]
|
||||
marker = max_snapshots[0].id
|
||||
url = base_url + "?%s=%s" % (prev, marker)
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="asc", snapshots=expected_snapshots,
|
||||
url=url, has_more=True, has_prev=False)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_reset_state',
|
||||
'volume_snapshot_get')})
|
||||
def test_update_snapshot_status(self):
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
state = 'error'
|
||||
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id) \
|
||||
.AndReturn(snapshot)
|
||||
cinder.volume_snapshot_reset_state(IsA(http.HttpRequest),
|
||||
snapshot.id,
|
||||
state)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
formData = {'status': state}
|
||||
url = reverse('horizon:admin:snapshots:update_status',
|
||||
args=(snapshot.id,))
|
||||
res = self.client.post(url, formData)
|
||||
self.assertNoFormErrors(res)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',
|
||||
'volume_get')})
|
||||
def test_get_volume_snapshot_details(self):
|
||||
volume = self.cinder_volumes.first()
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
|
||||
cinder.volume_get(IsA(http.HttpRequest), volume.id). \
|
||||
AndReturn(volume)
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id). \
|
||||
AndReturn(snapshot)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:snapshots:detail',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
|
||||
self.assertEqual(res.context['snapshot'].id, snapshot.id)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',
|
||||
'volume_get')})
|
||||
def test_get_volume_snapshot_details_with_snapshot_exception(self):
|
||||
# Test to verify redirect if get volume snapshot fails
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id).\
|
||||
AndRaise(self.exceptions.cinder)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:snapshots:detail',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, reverse(INDEX_URL))
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',
|
||||
'volume_get')})
|
||||
def test_get_volume_snapshot_details_with_volume_exception(self):
|
||||
# Test to verify redirect if get volume fails
|
||||
volume = self.cinder_volumes.first()
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
|
||||
cinder.volume_get(IsA(http.HttpRequest), volume.id). \
|
||||
AndRaise(self.exceptions.cinder)
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id). \
|
||||
AndReturn(snapshot)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:snapshots:detail',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, reverse(INDEX_URL))
|
||||
|
||||
def test_get_snapshot_status_choices_without_current(self):
|
||||
current_status = {'status': 'available'}
|
||||
status_choices = forms.populate_status_choices(current_status,
|
||||
forms.STATUS_CHOICES)
|
||||
self.assertEqual(len(status_choices), len(forms.STATUS_CHOICES))
|
||||
self.assertNotIn(current_status['status'],
|
||||
[status[0] for status in status_choices])
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',)})
|
||||
def test_update_volume_status_get(self):
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id). \
|
||||
AndReturn(snapshot)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:snapshots:update_status',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
status_option = "<option value=\"%s\"></option>" % snapshot.status
|
||||
self.assertNotContains(res, status_option)
|
@ -12,10 +12,11 @@
|
||||
|
||||
from django.conf.urls import url
|
||||
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots import views
|
||||
from openstack_dashboard.dashboards.admin.snapshots import views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.SnapshotsView.as_view(), name='index'),
|
||||
url(r'^(?P<snapshot_id>[^/]+)$',
|
||||
views.DetailView.as_view(),
|
||||
name='detail'),
|
@ -16,25 +16,76 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import tables
|
||||
from horizon.utils import memoized
|
||||
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.api import keystone
|
||||
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots \
|
||||
from openstack_dashboard.dashboards.admin.snapshots \
|
||||
import forms as vol_snapshot_forms
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots \
|
||||
from openstack_dashboard.dashboards.admin.snapshots \
|
||||
import tables as vol_snapshot_tables
|
||||
from openstack_dashboard.dashboards.admin.snapshots \
|
||||
import tabs as vol_snapshot_tabs
|
||||
from openstack_dashboard.dashboards.project.snapshots \
|
||||
import views
|
||||
|
||||
|
||||
class SnapshotsView(tables.DataTableView, tables.PagedTableMixin):
|
||||
table_class = vol_snapshot_tables.VolumeSnapshotsTable
|
||||
name = _("Volume Snapshots")
|
||||
|
||||
def get_data(self):
|
||||
if cinder.is_volume_service_enabled(self.request):
|
||||
try:
|
||||
marker, sort_dir = self._get_marker()
|
||||
snapshots, self._has_more_data, self._has_prev_data = \
|
||||
cinder.volume_snapshot_list_paged(
|
||||
self.request, paginate=True, marker=marker,
|
||||
sort_dir=sort_dir, search_opts={'all_tenants': True})
|
||||
volumes = cinder.volume_list(
|
||||
self.request,
|
||||
search_opts={'all_tenants': True})
|
||||
volumes = dict((v.id, v) for v in volumes)
|
||||
except Exception:
|
||||
snapshots = []
|
||||
volumes = {}
|
||||
exceptions.handle(self.request, _("Unable to retrieve "
|
||||
"volume snapshots."))
|
||||
|
||||
# Gather our tenants to correlate against volume IDs
|
||||
try:
|
||||
tenants, has_more = keystone.tenant_list(self.request)
|
||||
except Exception:
|
||||
tenants = []
|
||||
msg = _('Unable to retrieve volume project information.')
|
||||
exceptions.handle(self.request, msg)
|
||||
|
||||
tenant_dict = dict([(t.id, t) for t in tenants])
|
||||
for snapshot in snapshots:
|
||||
volume = volumes.get(snapshot.volume_id)
|
||||
tenant_id = getattr(volume,
|
||||
'os-vol-tenant-attr:tenant_id', None)
|
||||
tenant = tenant_dict.get(tenant_id, None)
|
||||
snapshot._volume = volume
|
||||
snapshot.tenant_name = getattr(tenant, "name", None)
|
||||
snapshot.host_name = getattr(
|
||||
volume, 'os-vol-host-attr:host', None)
|
||||
|
||||
else:
|
||||
snapshots = []
|
||||
return sorted(snapshots,
|
||||
key=lambda snapshot: snapshot.tenant_name or '')
|
||||
|
||||
|
||||
class UpdateStatusView(forms.ModalFormView):
|
||||
form_class = vol_snapshot_forms.UpdateStatus
|
||||
modal_id = "update_volume_snapshot_status"
|
||||
template_name = 'admin/volumes/snapshots/update_status.html'
|
||||
template_name = 'admin/snapshots/update_status.html'
|
||||
submit_label = _("Update Status")
|
||||
submit_url = "horizon:admin:volumes:snapshots:update_status"
|
||||
success_url = reverse_lazy("horizon:admin:volumes:snapshots_tab")
|
||||
submit_url = "horizon:admin:snapshots:update_status"
|
||||
success_url = reverse_lazy("horizon:admin:snapshots:index")
|
||||
page_title = _("Update Volume Snapshot Status")
|
||||
|
||||
@memoized.memoized_method
|
||||
@ -76,4 +127,4 @@ class DetailView(views.DetailView):
|
||||
|
||||
@staticmethod
|
||||
def get_redirect_url():
|
||||
return reverse('horizon:admin:volumes:index')
|
||||
return reverse('horizon:admin:snapshots:index')
|
@ -1,126 +0,0 @@
|
||||
# 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.core.urlresolvers import reverse
|
||||
from django import http
|
||||
from mox3.mox import IsA # noqa
|
||||
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.test import helpers as test
|
||||
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots import forms
|
||||
|
||||
INDEX_URL = 'horizon:admin:volumes:index'
|
||||
|
||||
|
||||
class VolumeSnapshotsViewTests(test.BaseAdminViewTests):
|
||||
@test.create_stubs({cinder: ('volume_snapshot_reset_state',
|
||||
'volume_snapshot_get')})
|
||||
def test_update_snapshot_status(self):
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
state = 'error'
|
||||
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id) \
|
||||
.AndReturn(snapshot)
|
||||
cinder.volume_snapshot_reset_state(IsA(http.HttpRequest),
|
||||
snapshot.id,
|
||||
state)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
formData = {'status': state}
|
||||
url = reverse('horizon:admin:volumes:snapshots:update_status',
|
||||
args=(snapshot.id,))
|
||||
res = self.client.post(url, formData)
|
||||
self.assertNoFormErrors(res)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',
|
||||
'volume_get')})
|
||||
def test_get_volume_snapshot_details(self):
|
||||
volume = self.cinder_volumes.first()
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
|
||||
cinder.volume_get(IsA(http.HttpRequest), volume.id). \
|
||||
AndReturn(volume)
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id). \
|
||||
AndReturn(snapshot)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:volumes:snapshots:detail',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertTemplateUsed(res, 'horizon/common/_detail.html')
|
||||
self.assertEqual(res.context['snapshot'].id, snapshot.id)
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',
|
||||
'volume_get')})
|
||||
def test_get_volume_snapshot_details_with_snapshot_exception(self):
|
||||
# Test to verify redirect if get volume snapshot fails
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id).\
|
||||
AndRaise(self.exceptions.cinder)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:volumes:snapshots:detail',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, reverse(INDEX_URL))
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',
|
||||
'volume_get')})
|
||||
def test_get_volume_snapshot_details_with_volume_exception(self):
|
||||
# Test to verify redirect if get volume fails
|
||||
volume = self.cinder_volumes.first()
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
|
||||
cinder.volume_get(IsA(http.HttpRequest), volume.id). \
|
||||
AndRaise(self.exceptions.cinder)
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id). \
|
||||
AndReturn(snapshot)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:volumes:snapshots:detail',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertMessageCount(error=1)
|
||||
self.assertRedirectsNoFollow(res, reverse(INDEX_URL))
|
||||
|
||||
def test_get_snapshot_status_choices_without_current(self):
|
||||
current_status = {'status': 'available'}
|
||||
status_choices = forms.populate_status_choices(current_status,
|
||||
forms.STATUS_CHOICES)
|
||||
self.assertEqual(len(status_choices), len(forms.STATUS_CHOICES))
|
||||
self.assertNotIn(current_status['status'],
|
||||
[status[0] for status in status_choices])
|
||||
|
||||
@test.create_stubs({cinder: ('volume_snapshot_get',)})
|
||||
def test_update_volume_status_get(self):
|
||||
snapshot = self.cinder_volume_snapshots.first()
|
||||
cinder.volume_snapshot_get(IsA(http.HttpRequest), snapshot.id). \
|
||||
AndReturn(snapshot)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
url = reverse('horizon:admin:volumes:snapshots:update_status',
|
||||
args=[snapshot.id])
|
||||
res = self.client.get(url)
|
||||
status_option = "<option value=\"%s\"></option>" % snapshot.status
|
||||
self.assertNotContains(res, status_option)
|
@ -23,8 +23,6 @@ from openstack_dashboard import policy
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.api import keystone
|
||||
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots \
|
||||
import tables as snapshots_tables
|
||||
from openstack_dashboard.dashboards.admin.volumes.volume_types \
|
||||
import tables as volume_types_tables
|
||||
from openstack_dashboard.dashboards.admin.volumes.volumes \
|
||||
@ -159,57 +157,7 @@ class VolumeTypesTab(tabs.TableTab, volumes_views.VolumeTableMixIn):
|
||||
return qos_specs
|
||||
|
||||
|
||||
class SnapshotTab(tables.PagedTableMixin, tabs.TableTab):
|
||||
table_classes = (snapshots_tables.VolumeSnapshotsTable,)
|
||||
name = _("Volume Snapshots")
|
||||
slug = "snapshots_tab"
|
||||
template_name = ("horizon/common/_detail_table.html")
|
||||
preload = False
|
||||
|
||||
def get_volume_snapshots_data(self):
|
||||
if cinder.is_volume_service_enabled(self.request):
|
||||
try:
|
||||
marker, sort_dir = self._get_marker()
|
||||
snapshots, self._has_more_data, self._has_prev_data = \
|
||||
cinder.volume_snapshot_list_paged(
|
||||
self.request, paginate=True, marker=marker,
|
||||
sort_dir=sort_dir, search_opts={'all_tenants': True})
|
||||
volumes = cinder.volume_list(
|
||||
self.request,
|
||||
search_opts={'all_tenants': True})
|
||||
volumes = dict((v.id, v) for v in volumes)
|
||||
except Exception:
|
||||
snapshots = []
|
||||
volumes = {}
|
||||
exceptions.handle(self.request, _("Unable to retrieve "
|
||||
"volume snapshots."))
|
||||
|
||||
# Gather our tenants to correlate against volume IDs
|
||||
try:
|
||||
tenants, has_more = keystone.tenant_list(self.request)
|
||||
except Exception:
|
||||
tenants = []
|
||||
msg = _('Unable to retrieve volume project information.')
|
||||
exceptions.handle(self.request, msg)
|
||||
|
||||
tenant_dict = dict([(t.id, t) for t in tenants])
|
||||
for snapshot in snapshots:
|
||||
volume = volumes.get(snapshot.volume_id)
|
||||
tenant_id = getattr(volume,
|
||||
'os-vol-tenant-attr:tenant_id', None)
|
||||
tenant = tenant_dict.get(tenant_id, None)
|
||||
snapshot._volume = volume
|
||||
snapshot.tenant_name = getattr(tenant, "name", None)
|
||||
snapshot.host_name = getattr(
|
||||
volume, 'os-vol-host-attr:host', None)
|
||||
|
||||
else:
|
||||
snapshots = []
|
||||
return sorted(snapshots,
|
||||
key=lambda snapshot: snapshot.tenant_name or '')
|
||||
|
||||
|
||||
class VolumesGroupTabs(tabs.TabGroup):
|
||||
slug = "volumes_group_tabs"
|
||||
tabs = (VolumeTab, VolumeTypesTab, SnapshotTab)
|
||||
tabs = (VolumeTab, VolumeTypesTab)
|
||||
sticky = True
|
||||
|
@ -24,8 +24,6 @@ from mox3.mox import IsA # noqa
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.api import keystone
|
||||
from openstack_dashboard.dashboards.project.snapshots \
|
||||
import tables as snapshot_tables
|
||||
from openstack_dashboard.dashboards.project.volumes \
|
||||
import tables as volume_tables
|
||||
from openstack_dashboard.test import helpers as test
|
||||
@ -217,116 +215,6 @@ class VolumeTests(test.BaseAdminViewTests):
|
||||
qos_specs = res.context['qos_specs_table'].data
|
||||
self.assertItemsEqual(qos_specs, self.cinder_qos_specs.list())
|
||||
|
||||
@test.create_stubs({cinder: ('volume_list',
|
||||
'volume_snapshot_list_paged',),
|
||||
keystone: ('tenant_list',)})
|
||||
def test_snapshots_tab(self):
|
||||
cinder.volume_snapshot_list_paged(
|
||||
IsA(http.HttpRequest), paginate=True, marker=None, sort_dir='desc',
|
||||
search_opts={'all_tenants': True},).AndReturn(
|
||||
[self.cinder_volume_snapshots.list(), False, False])
|
||||
cinder.volume_list(IsA(http.HttpRequest), search_opts={
|
||||
'all_tenants': True}).\
|
||||
AndReturn(self.cinder_volumes.list())
|
||||
keystone.tenant_list(IsA(http.HttpRequest)). \
|
||||
AndReturn([self.tenants.list(), False])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
url = reverse('horizon:admin:volumes:snapshots_tab')
|
||||
res = self.client.get(urlunquote(url))
|
||||
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertTemplateUsed(res, 'admin/volumes/index.html')
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, self.cinder_volume_snapshots.list())
|
||||
|
||||
@test.create_stubs({cinder: ('volume_list',
|
||||
'volume_snapshot_list_paged',),
|
||||
keystone: ('tenant_list',)})
|
||||
def _test_snapshots_index_paginated(self, marker, sort_dir, snapshots, url,
|
||||
has_more, has_prev):
|
||||
cinder.volume_snapshot_list_paged(
|
||||
IsA(http.HttpRequest), paginate=True, marker=marker,
|
||||
sort_dir=sort_dir, search_opts={'all_tenants': True}) \
|
||||
.AndReturn([snapshots, has_more, has_prev])
|
||||
cinder.volume_list(IsA(http.HttpRequest), search_opts={
|
||||
'all_tenants': True}).\
|
||||
AndReturn(self.cinder_volumes.list())
|
||||
keystone.tenant_list(IsA(http.HttpRequest)) \
|
||||
.AndReturn([self.tenants.list(), False])
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
res = self.client.get(urlunquote(url))
|
||||
|
||||
self.assertTemplateUsed(res, 'admin/volumes/index.html')
|
||||
self.assertEqual(res.status_code, 200)
|
||||
|
||||
self.mox.UnsetStubs()
|
||||
return res
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=1)
|
||||
def test_snapshots_index_paginated(self):
|
||||
size = settings.API_RESULT_PAGE_SIZE
|
||||
mox_snapshots = self.cinder_volume_snapshots.list()
|
||||
base_url = reverse('horizon:admin:volumes:snapshots_tab')
|
||||
next = snapshot_tables.VolumeSnapshotsTable._meta.pagination_param
|
||||
|
||||
# get first page
|
||||
expected_snapshots = mox_snapshots[:size]
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=None, sort_dir="desc", snapshots=expected_snapshots,
|
||||
url=base_url, has_more=True, has_prev=False)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
# get second page
|
||||
expected_snapshots = mox_snapshots[size:2 * size]
|
||||
marker = expected_snapshots[0].id
|
||||
url = "&".join([base_url, "=".join([next, marker])])
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="desc", snapshots=expected_snapshots,
|
||||
url=url, has_more=True, has_prev=True)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
# get last page
|
||||
expected_snapshots = mox_snapshots[-size:]
|
||||
marker = expected_snapshots[0].id
|
||||
url = "&".join([base_url, "=".join([next, marker])])
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="desc", snapshots=expected_snapshots,
|
||||
url=url, has_more=False, has_prev=True)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
@override_settings(API_RESULT_PAGE_SIZE=1)
|
||||
def test_snapshots_index_paginated_prev(self):
|
||||
size = settings.API_RESULT_PAGE_SIZE
|
||||
max_snapshots = self.cinder_volume_snapshots.list()
|
||||
base_url = reverse('horizon:admin:volumes:snapshots_tab')
|
||||
prev = snapshot_tables.VolumeSnapshotsTable._meta.prev_pagination_param
|
||||
|
||||
# prev from some page
|
||||
expected_snapshots = max_snapshots[size:2 * size]
|
||||
marker = max_snapshots[0].id
|
||||
url = "&".join([base_url, "=".join([prev, marker])])
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="asc", snapshots=expected_snapshots,
|
||||
url=url, has_more=False, has_prev=True)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
# back to first page
|
||||
expected_snapshots = max_snapshots[:size]
|
||||
marker = max_snapshots[0].id
|
||||
url = "&".join([base_url, "=".join([prev, marker])])
|
||||
res = self._test_snapshots_index_paginated(
|
||||
marker=marker, sort_dir="asc", snapshots=expected_snapshots,
|
||||
url=url, has_more=True, has_prev=False)
|
||||
snapshots = res.context['volume_snapshots_table'].data
|
||||
self.assertItemsEqual(snapshots, expected_snapshots)
|
||||
|
||||
@override_settings(FILTER_DATA_FIRST={'admin.volumes': True})
|
||||
def test_volumes_tab_with_admin_filter_first(self):
|
||||
res = self.client.get(INDEX_URL)
|
||||
|
@ -13,8 +13,6 @@
|
||||
from django.conf.urls import include
|
||||
from django.conf.urls import url
|
||||
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots \
|
||||
import urls as snapshot_urls
|
||||
from openstack_dashboard.dashboards.admin.volumes import views
|
||||
from openstack_dashboard.dashboards.admin.volumes.volume_types \
|
||||
import urls as volume_types_urls
|
||||
@ -25,9 +23,6 @@ urlpatterns = [
|
||||
url(r'^$',
|
||||
views.IndexView.as_view(),
|
||||
name='index'),
|
||||
url(r'^\?tab=volumes_group_tabs__snapshots_tab$',
|
||||
views.IndexView.as_view(),
|
||||
name='snapshots_tab'),
|
||||
url(r'^\?tab=volumes_group_tabs__volumes_tab$',
|
||||
views.IndexView.as_view(),
|
||||
name='volumes_tab'),
|
||||
@ -38,6 +33,4 @@ urlpatterns = [
|
||||
include(volumes_urls, namespace='volumes')),
|
||||
url(r'volume_types/',
|
||||
include(volume_types_urls, namespace='volume_types')),
|
||||
url(r'snapshots/',
|
||||
include(snapshot_urls, namespace='snapshots')),
|
||||
]
|
||||
|
@ -25,7 +25,7 @@ from horizon import messages
|
||||
from horizon.utils import validators as utils_validators
|
||||
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots.forms \
|
||||
from openstack_dashboard.dashboards.admin.snapshots.forms \
|
||||
import populate_status_choices
|
||||
from openstack_dashboard.dashboards.project.volumes \
|
||||
import forms as project_forms
|
||||
|
@ -18,7 +18,7 @@ from mox3.mox import IsA # noqa
|
||||
from openstack_dashboard.api import cinder
|
||||
from openstack_dashboard.test import helpers as test
|
||||
|
||||
from openstack_dashboard.dashboards.admin.volumes.snapshots import forms
|
||||
from openstack_dashboard.dashboards.admin.snapshots import forms
|
||||
|
||||
INDEX_URL = reverse('horizon:admin:volumes:volumes_tab')
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
# The slug of the panel to be added to HORIZON_CONFIG. Required.
|
||||
PANEL = 'snapshots'
|
||||
# The slug of the dashboard the PANEL associated with. Required.
|
||||
PANEL_DASHBOARD = 'admin'
|
||||
# The slug of the panel group the PANEL is associated with.
|
||||
PANEL_GROUP = 'admin'
|
||||
|
||||
# Python panel class of the PANEL to be added.
|
||||
ADD_PANEL = 'openstack_dashboard.dashboards.admin.snapshots.panel.Snapshots'
|
Loading…
x
Reference in New Issue
Block a user