Merge "Create Share Snapshot modal form refactoring"
This commit is contained in:
commit
e42b82d63f
|
@ -66,23 +66,27 @@ class SnapshotDetailView(tabs.TabView):
|
|||
|
||||
class CreateSnapshotView(forms.ModalFormView):
|
||||
form_class = snapshot_forms.CreateSnapshotForm
|
||||
form_id = "create_share_snapshot"
|
||||
template_name = 'project/shares/snapshots/create_snapshot.html'
|
||||
success_url = reverse_lazy("horizon:project:shares:index")
|
||||
modal_header = _("Create Share Snapshot")
|
||||
modal_id = "create_share_snapshot_modal"
|
||||
submit_url = "horizon:project:shares:create_snapshot"
|
||||
success_url = reverse_lazy('horizon:project:shares:snapshots_tab')
|
||||
page_title = _('Create Share Snapshot')
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(CreateSnapshotView, self).get_context_data(**kwargs)
|
||||
context['share_id'] = self.kwargs['share_id']
|
||||
args = (context['share_id'],)
|
||||
context['submit_url'] = reverse(self.submit_url, args=args)
|
||||
try:
|
||||
share = manila.share_get(self.request, context['share_id'])
|
||||
if (share.status == 'in-use'):
|
||||
context['attached'] = True
|
||||
context['form'].set_warning(_("This share is currently "
|
||||
"attached to an instance. "
|
||||
"In some cases, creating a "
|
||||
"snapshot from an attached "
|
||||
"share can result in a "
|
||||
"corrupted snapshot."))
|
||||
context['form'].set_warning(
|
||||
_("This share is currently attached to an instance. "
|
||||
"In some cases, creating a snapshot from an attached "
|
||||
"share can result in a corrupted snapshot."))
|
||||
context['usages'] = quotas.tenant_limit_usages(self.request)
|
||||
except Exception:
|
||||
exceptions.handle(self.request,
|
||||
|
|
|
@ -1,29 +1,16 @@
|
|||
{% extends "horizon/common/_modal_form.html" %}
|
||||
{% load i18n %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block form_id %}{% endblock %}
|
||||
{% block form_action %}{% url 'horizon:project:shares:create_snapshot' share_id %}{% endblock %}
|
||||
|
||||
{% block modal_id %}create_share_snapshot_modal{% endblock %}
|
||||
{% block modal-header %}{% trans "Create Share Snapshot" %}{% endblock %}
|
||||
|
||||
{% block modal-body %}
|
||||
<div class="left">
|
||||
<fieldset>
|
||||
{% include "horizon/common/_form_fields.html" %}
|
||||
</fieldset>
|
||||
</div>
|
||||
<div class="right quota-dynamic">
|
||||
{% block modal-body-right %}
|
||||
<div class="quota-dynamic">
|
||||
{% include "project/shares/snapshots/_limits_snapshots.html" with usages=usages snapshot_quota=True %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block modal-footer %}
|
||||
<a href="{% url 'horizon:project:shares:index' %}" class="btn btn-default cancel">{% trans "Cancel" %}</a>
|
||||
{% if attached %}
|
||||
<input class="btn btn-primary btn-warning pull-right" type="submit" value="{% trans "Create Share Snapshot (Force)" %}" />
|
||||
<input class="btn btn-warning" type="submit" value="{% trans "Create Share Snapshot (Force)" %}" />
|
||||
{% else %}
|
||||
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Create Share Snapshot" %}" />
|
||||
<input class="btn btn-primary" type="submit" value="{% trans "Create Share Snapshot" %}" />
|
||||
{% endif %}
|
||||
<a href="{% url 'horizon:project:shares:index' %}" class="btn secondary cancel close">{% trans "Cancel" %}</a>
|
||||
{% endblock %}
|
||||
|
|
|
@ -31,6 +31,9 @@ from manila_ui.dashboards.project.shares import views
|
|||
urlpatterns = patterns(
|
||||
'openstack_dashboard.dashboards.project.shares.views',
|
||||
url(r'^$', views.IndexView.as_view(), name='index'),
|
||||
url(r'^\?tab=share_tabs__snapshots_tab$',
|
||||
views.IndexView.as_view(),
|
||||
name='snapshots_tab'),
|
||||
url(r'^create/$', shares_views.CreateView.as_view(), name='create'),
|
||||
url(r'^create_security_service$',
|
||||
security_services_views.CreateView.as_view(),
|
||||
|
|
|
@ -20,13 +20,37 @@ from manila_ui.tests.dashboards.project.shares import test_data
|
|||
from manila_ui.tests import helpers as test
|
||||
|
||||
from openstack_dashboard.api import neutron
|
||||
from openstack_dashboard.usage import quotas
|
||||
|
||||
SHARE_INDEX_URL = reverse('horizon:project:shares:index')
|
||||
SHARE_SNAPSHOTS_TAB_URL = reverse('horizon:project:shares:snapshots_tab')
|
||||
|
||||
|
||||
class SnapshotSnapshotViewTests(test.TestCase):
|
||||
|
||||
def test_create_snapshot(self):
|
||||
def test_create_snapshot_get(self):
|
||||
share = test_data.share
|
||||
usage_limit = {
|
||||
'maxTotalShareGigabytes': 250,
|
||||
'totalShareGigabytesUsed': 20,
|
||||
}
|
||||
url = reverse('horizon:project:shares:create_snapshot',
|
||||
args=[share.id])
|
||||
self.mock_object(
|
||||
quotas, "tenant_limit_usages", mock.Mock(return_value=usage_limit))
|
||||
self.mock_object(
|
||||
api_manila, "share_get", mock.Mock(return_value=share))
|
||||
self.mock_object(
|
||||
neutron, "is_service_enabled", mock.Mock(return_value=[True]))
|
||||
|
||||
res = self.client.get(url)
|
||||
|
||||
api_manila.share_get.assert_called_once_with(mock.ANY, share.id)
|
||||
self.assertNoMessages()
|
||||
self.assertTemplateUsed(
|
||||
res, 'project/shares/snapshots/create_snapshot.html')
|
||||
|
||||
def test_create_snapshot_post(self):
|
||||
share = test_data.share
|
||||
url = reverse('horizon:project:shares:create_snapshot',
|
||||
args=[share.id])
|
||||
|
@ -44,7 +68,7 @@ class SnapshotSnapshotViewTests(test.TestCase):
|
|||
|
||||
api_manila.share_snapshot_create.assert_called_once_with(
|
||||
mock.ANY, share.id, formData['name'], formData['description'])
|
||||
self.assertRedirectsNoFollow(res, SHARE_INDEX_URL)
|
||||
self.assertRedirectsNoFollow(res, SHARE_SNAPSHOTS_TAB_URL)
|
||||
|
||||
def test_delete_snapshot(self):
|
||||
share = test_data.share
|
||||
|
|
Loading…
Reference in New Issue