VPNaaS delete actions refactoring
VPNaaS delete actions are implemented in an unusual way and have a lot of unnecessary code. This change makes some clean up. Partial-Bug: #1492281 Change-Id: Ic5efbace813b22ae8b79edbba2ae88de1f41e119
This commit is contained in:
parent
1d1b683f51
commit
8be6822985
@ -18,8 +18,12 @@ from django.utils.translation import pgettext_lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ungettext_lazy
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import tables
|
||||
|
||||
from openstack_dashboard import api
|
||||
from openstack_dashboard import policy
|
||||
|
||||
|
||||
forbid_updates = set(["PENDING_CREATE", "PENDING_UPDATE", "PENDING_DELETE"])
|
||||
|
||||
@ -60,7 +64,7 @@ class AddIPSecSiteConnectionLink(tables.LinkAction):
|
||||
policy_rules = (("network", "create_ipsec_site_connection"),)
|
||||
|
||||
|
||||
class DeleteVPNServiceLink(tables.DeleteAction):
|
||||
class DeleteVPNServiceLink(policy.PolicyTargetMixin, tables.DeleteAction):
|
||||
name = "deletevpnservice"
|
||||
policy_rules = (("network", "delete_vpnservice"),)
|
||||
|
||||
@ -85,8 +89,15 @@ class DeleteVPNServiceLink(tables.DeleteAction):
|
||||
return False
|
||||
return True
|
||||
|
||||
def delete(self, request, obj_id):
|
||||
try:
|
||||
api.vpn.vpnservice_delete(request, obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(
|
||||
request, _('Unable to delete VPN Service. %s') % e)
|
||||
|
||||
class DeleteIKEPolicyLink(tables.DeleteAction):
|
||||
|
||||
class DeleteIKEPolicyLink(policy.PolicyTargetMixin, tables.DeleteAction):
|
||||
name = "deleteikepolicy"
|
||||
policy_rules = (("network", "delete_ikepolicy"),)
|
||||
|
||||
@ -111,8 +122,15 @@ class DeleteIKEPolicyLink(tables.DeleteAction):
|
||||
return False
|
||||
return True
|
||||
|
||||
def delete(self, request, obj_id):
|
||||
try:
|
||||
api.vpn.ikepolicy_delete(request, obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(
|
||||
request, _('Unable to delete IKE Policy. %s') % e)
|
||||
|
||||
class DeleteIPSecPolicyLink(tables.DeleteAction):
|
||||
|
||||
class DeleteIPSecPolicyLink(policy.PolicyTargetMixin, tables.DeleteAction):
|
||||
name = "deleteipsecpolicy"
|
||||
policy_rules = (("network", "delete_ipsecpolicy"),)
|
||||
|
||||
@ -137,8 +155,16 @@ class DeleteIPSecPolicyLink(tables.DeleteAction):
|
||||
return False
|
||||
return True
|
||||
|
||||
def delete(self, request, obj_id):
|
||||
try:
|
||||
api.vpn.ipsecpolicy_delete(request, obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(
|
||||
request, _('Unable to delete IPSec Policy. %s') % e)
|
||||
|
||||
class DeleteIPSecSiteConnectionLink(tables.DeleteAction):
|
||||
|
||||
class DeleteIPSecSiteConnectionLink(policy.PolicyTargetMixin,
|
||||
tables.DeleteAction):
|
||||
name = "deleteipsecsiteconnection"
|
||||
policy_rules = (("network", "delete_ipsec_site_connection"),)
|
||||
|
||||
@ -158,6 +184,13 @@ class DeleteIPSecSiteConnectionLink(tables.DeleteAction):
|
||||
count
|
||||
)
|
||||
|
||||
def delete(self, request, obj_id):
|
||||
try:
|
||||
api.vpn.ipsecsiteconnection_delete(request, obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(
|
||||
request, _('Unable to delete IPSec Site Connection. %s') % e)
|
||||
|
||||
|
||||
class UpdateVPNServiceLink(tables.LinkAction):
|
||||
name = "update_vpnservice"
|
||||
|
@ -749,85 +749,66 @@ class VPNTests(test.TestCase):
|
||||
self.assertNoFormErrors(res)
|
||||
self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
|
||||
|
||||
@test.create_stubs({api.vpn: ('ikepolicy_list', 'ipsecpolicy_list',
|
||||
'vpnservice_list',
|
||||
'ipsecsiteconnection_list',
|
||||
'vpnservice_delete',)})
|
||||
@test.create_stubs({api.vpn: ('vpnservice_list', 'vpnservice_delete',)})
|
||||
def test_delete_vpnservice(self):
|
||||
self.set_up_expect()
|
||||
|
||||
vpnservice = self.vpnservices.first()
|
||||
|
||||
vpnservice = self.vpnservices.list()[1]
|
||||
api.vpn.vpnservice_list(
|
||||
IsA(http.HttpRequest), tenant_id=self.tenant.id) \
|
||||
.AndReturn(self.vpnservices.list())
|
||||
api.vpn.vpnservice_delete(IsA(http.HttpRequest), vpnservice.id)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
form_data = {"action":
|
||||
"vpnservicestable__deletevpnservice__%s" % vpnservice.id}
|
||||
|
||||
res = self.client.post(self.INDEX_URL, form_data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
|
||||
@test.create_stubs({api.vpn: ('ikepolicy_list', 'ipsecpolicy_list',
|
||||
'vpnservice_list',
|
||||
'ipsecsiteconnection_list',
|
||||
'ikepolicy_delete',)})
|
||||
@test.create_stubs({api.vpn: ('ikepolicy_list', 'ikepolicy_delete',)})
|
||||
def test_delete_ikepolicy(self):
|
||||
self.set_up_expect()
|
||||
|
||||
ikepolicy = self.ikepolicies.first()
|
||||
|
||||
ikepolicy = self.ikepolicies.list()[1]
|
||||
api.vpn.ikepolicy_list(
|
||||
IsA(http.HttpRequest), tenant_id=self.tenant.id) \
|
||||
.AndReturn(self.ikepolicies.list())
|
||||
api.vpn.ikepolicy_delete(IsA(http.HttpRequest), ikepolicy.id)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
form_data = {"action":
|
||||
"ikepoliciestable__deleteikepolicy__%s" % ikepolicy.id}
|
||||
|
||||
res = self.client.post(self.INDEX_URL, form_data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
|
||||
@test.create_stubs({api.vpn: ('ikepolicy_list', 'ipsecpolicy_list',
|
||||
'vpnservice_list',
|
||||
'ipsecsiteconnection_list',
|
||||
'ipsecpolicy_delete',)})
|
||||
@test.create_stubs({api.vpn: ('ipsecpolicy_list', 'ipsecpolicy_delete',)})
|
||||
def test_delete_ipsecpolicy(self):
|
||||
self.set_up_expect()
|
||||
|
||||
ipsecpolicy = self.ipsecpolicies.first()
|
||||
|
||||
ipsecpolicy = self.ipsecpolicies.list()[1]
|
||||
api.vpn.ipsecpolicy_list(
|
||||
IsA(http.HttpRequest), tenant_id=self.tenant.id) \
|
||||
.AndReturn(self.ipsecpolicies.list())
|
||||
api.vpn.ipsecpolicy_delete(IsA(http.HttpRequest), ipsecpolicy.id)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
form_data = {"action":
|
||||
"ipsecpoliciestable__deleteipsecpolicy__%s"
|
||||
% ipsecpolicy.id}
|
||||
|
||||
res = self.client.post(self.INDEX_URL, form_data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
|
||||
@test.create_stubs({api.vpn: ('ikepolicy_list', 'ipsecpolicy_list',
|
||||
'vpnservice_list',
|
||||
'ipsecsiteconnection_list',
|
||||
@test.create_stubs({api.vpn: ('ipsecsiteconnection_list',
|
||||
'ipsecsiteconnection_delete',)})
|
||||
def test_delete_ipsecsiteconnection(self):
|
||||
self.set_up_expect()
|
||||
|
||||
ipsecsiteconnection = self.ipsecsiteconnections.first()
|
||||
|
||||
api.vpn.ipsecsiteconnection_list(
|
||||
IsA(http.HttpRequest), tenant_id=self.tenant.id) \
|
||||
.AndReturn(self.ipsecsiteconnections.list())
|
||||
api.vpn.ipsecsiteconnection_delete(
|
||||
IsA(http.HttpRequest), ipsecsiteconnection.id)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
form_data = {"action":
|
||||
"ipsecsiteconnectionstable__deleteipsecsiteconnection__%s"
|
||||
% ipsecsiteconnection.id}
|
||||
|
||||
res = self.client.post(self.INDEX_URL, form_data)
|
||||
|
||||
self.assertNoFormErrors(res)
|
||||
|
@ -18,7 +18,6 @@ from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon import exceptions
|
||||
from horizon import forms
|
||||
from horizon import messages
|
||||
from horizon import tabs
|
||||
from horizon.utils import memoized
|
||||
from horizon import workflows
|
||||
@ -32,95 +31,28 @@ from openstack_dashboard.dashboards.project.vpn import tabs as vpn_tabs
|
||||
from openstack_dashboard.dashboards.project.vpn \
|
||||
import workflows as vpn_workflows
|
||||
|
||||
import re
|
||||
|
||||
|
||||
class IndexView(tabs.TabView):
|
||||
class IndexView(tabs.TabbedTableView):
|
||||
tab_group_class = vpn_tabs.VPNTabs
|
||||
template_name = 'project/vpn/index.html'
|
||||
page_title = _("Virtual Private Network")
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
obj_ids = request.POST.getlist('object_ids')
|
||||
action = request.POST['action']
|
||||
m = re.search('.delete([a-z]+)', action).group(1)
|
||||
if obj_ids == []:
|
||||
obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
|
||||
if m == 'vpnservice':
|
||||
for obj_id in obj_ids:
|
||||
try:
|
||||
api.vpn.vpnservice_delete(request, obj_id)
|
||||
messages.success(request,
|
||||
_('Deleted VPN Service %s') % obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(request,
|
||||
_('Unable to delete VPN Service: %s')
|
||||
% e)
|
||||
elif m == 'ikepolicy':
|
||||
for obj_id in obj_ids:
|
||||
try:
|
||||
api.vpn.ikepolicy_delete(request, obj_id)
|
||||
messages.success(request,
|
||||
_('Deleted IKE Policy %s') % obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(request,
|
||||
_('Unable to delete IKE Policy: %s') % e)
|
||||
elif m == 'ipsecpolicy':
|
||||
for obj_id in obj_ids:
|
||||
try:
|
||||
api.vpn.ipsecpolicy_delete(request, obj_id)
|
||||
messages.success(request,
|
||||
_('Deleted IPSec Policy %s') % obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(request,
|
||||
_('Unable to delete IPSec Policy: %s')
|
||||
% e)
|
||||
elif m == 'ipsecsiteconnection':
|
||||
for obj_id in obj_ids:
|
||||
try:
|
||||
api.vpn.ipsecsiteconnection_delete(request, obj_id)
|
||||
messages.success(request,
|
||||
_('Deleted IPSec Site Connection %s')
|
||||
% obj_id)
|
||||
except Exception as e:
|
||||
exceptions.handle(
|
||||
request,
|
||||
_('Unable to delete IPSec Site Connection: %s') % e)
|
||||
|
||||
return self.get(request, *args, **kwargs)
|
||||
|
||||
|
||||
class AddVPNServiceView(workflows.WorkflowView):
|
||||
workflow_class = vpn_workflows.AddVPNService
|
||||
|
||||
def get_initial(self):
|
||||
initial = super(AddVPNServiceView, self).get_initial()
|
||||
return initial
|
||||
|
||||
|
||||
class AddIPSecSiteConnectionView(workflows.WorkflowView):
|
||||
workflow_class = vpn_workflows.AddIPSecSiteConnection
|
||||
|
||||
def get_initial(self):
|
||||
initial = super(AddIPSecSiteConnectionView, self).get_initial()
|
||||
return initial
|
||||
|
||||
|
||||
class AddIKEPolicyView(workflows.WorkflowView):
|
||||
workflow_class = vpn_workflows.AddIKEPolicy
|
||||
|
||||
def get_initial(self):
|
||||
initial = super(AddIKEPolicyView, self).get_initial()
|
||||
return initial
|
||||
|
||||
|
||||
class AddIPSecPolicyView(workflows.WorkflowView):
|
||||
workflow_class = vpn_workflows.AddIPSecPolicy
|
||||
|
||||
def get_initial(self):
|
||||
initial = super(AddIPSecPolicyView, self).get_initial()
|
||||
return initial
|
||||
|
||||
|
||||
class IKEPolicyDetailsView(tabs.TabView):
|
||||
tab_group_class = vpn_tabs.IKEPolicyDetailsTabs
|
||||
|
Loading…
x
Reference in New Issue
Block a user