Merge "FWaaS delete actions refactoring"

This commit is contained in:
Jenkins 2015-09-25 14:58:13 +00:00 committed by Gerrit Code Review
commit 7f9580170b
3 changed files with 53 additions and 61 deletions

View File

@ -57,6 +57,7 @@ class AddFirewallLink(tables.LinkAction):
class DeleteRuleLink(policy.PolicyTargetMixin, tables.DeleteAction): class DeleteRuleLink(policy.PolicyTargetMixin, tables.DeleteAction):
name = "deleterule" name = "deleterule"
policy_rules = (("network", "delete_firewall_rule"),)
@staticmethod @staticmethod
def action_present(count): def action_present(count):
@ -74,11 +75,21 @@ class DeleteRuleLink(policy.PolicyTargetMixin, tables.DeleteAction):
count count
) )
policy_rules = (("network", "delete_firewall_rule"),) def allowed(self, request, datum=None):
if datum and datum.policy:
return False
return True
def delete(self, request, obj_id):
try:
api.fwaas.rule_delete(request, obj_id)
except Exception as e:
exceptions.handle(request, _('Unable to delete rule. %s') % e)
class DeletePolicyLink(policy.PolicyTargetMixin, tables.DeleteAction): class DeletePolicyLink(policy.PolicyTargetMixin, tables.DeleteAction):
name = "deletepolicy" name = "deletepolicy"
policy_rules = (("network", "delete_firewall_policy"),)
@staticmethod @staticmethod
def action_present(count): def action_present(count):
@ -96,12 +107,17 @@ class DeletePolicyLink(policy.PolicyTargetMixin, tables.DeleteAction):
count count
) )
policy_rules = (("network", "delete_firewall_policy"),) def delete(self, request, obj_id):
try:
api.fwaas.policy_delete(request, obj_id)
except Exception as e:
exceptions.handle(request, _('Unable to delete policy. %s') % e)
class DeleteFirewallLink(policy.PolicyTargetMixin, class DeleteFirewallLink(policy.PolicyTargetMixin,
tables.DeleteAction): tables.DeleteAction):
name = "deletefirewall" name = "deletefirewall"
policy_rules = (("network", "delete_firewall"),)
@staticmethod @staticmethod
def action_present(count): def action_present(count):
@ -119,7 +135,11 @@ class DeleteFirewallLink(policy.PolicyTargetMixin,
count count
) )
policy_rules = (("network", "delete_firewall"),) def delete(self, request, obj_id):
try:
api.fwaas.firewall_delete(request, obj_id)
except Exception as e:
exceptions.handle(request, _('Unable to delete firewall. %s') % e)
class UpdateRuleLink(policy.PolicyTargetMixin, tables.LinkAction): class UpdateRuleLink(policy.PolicyTargetMixin, tables.LinkAction):

View File

@ -744,16 +744,17 @@ class FirewallTests(test.TestCase):
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, str(self.INDEX_URL)) self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
@test.create_stubs({api.fwaas: ('firewall_list_for_tenant', @test.create_stubs({api.fwaas: ('rule_list_for_tenant',
'policy_list_for_tenant',
'rule_list_for_tenant',
'firewall_unassociated_routers_list',
'rule_delete'), 'rule_delete'),
api.neutron: ('is_extension_supported', api.neutron: ('is_extension_supported',)})
'router_list',), })
def test_delete_rule(self): def test_delete_rule(self):
self.set_up_expect() api.neutron.is_extension_supported(
rule = self.fw_rules.first() IsA(http.HttpRequest), 'fwaasrouterinsertion').AndReturn(True)
rule = self.fw_rules.list()[2]
api.fwaas.rule_list_for_tenant(
IsA(http.HttpRequest),
self.tenant.id).AndReturn(self.fw_rules.list())
api.fwaas.rule_delete(IsA(http.HttpRequest), rule.id) api.fwaas.rule_delete(IsA(http.HttpRequest), rule.id)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -762,16 +763,17 @@ class FirewallTests(test.TestCase):
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
@test.create_stubs({api.fwaas: ('firewall_list_for_tenant', @test.create_stubs({api.fwaas: ('policy_list_for_tenant',
'policy_list_for_tenant',
'rule_list_for_tenant',
'firewall_unassociated_routers_list',
'policy_delete'), 'policy_delete'),
api.neutron: ('is_extension_supported', api.neutron: ('is_extension_supported',)})
'router_list',), })
def test_delete_policy(self): def test_delete_policy(self):
self.set_up_expect() api.neutron.is_extension_supported(
IsA(http.HttpRequest), 'fwaasrouterinsertion').AndReturn(True)
policy = self.fw_policies.first() policy = self.fw_policies.first()
api.fwaas.policy_list_for_tenant(
IsA(http.HttpRequest),
self.tenant.id).AndReturn(self.fw_policies.list())
api.fwaas.policy_delete(IsA(http.HttpRequest), policy.id) api.fwaas.policy_delete(IsA(http.HttpRequest), policy.id)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -781,15 +783,21 @@ class FirewallTests(test.TestCase):
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
@test.create_stubs({api.fwaas: ('firewall_list_for_tenant', @test.create_stubs({api.fwaas: ('firewall_list_for_tenant',
'policy_list_for_tenant',
'rule_list_for_tenant',
'firewall_unassociated_routers_list',
'firewall_delete'), 'firewall_delete'),
api.neutron: ('is_extension_supported', api.neutron: ('is_extension_supported',
'router_list',), }) 'router_list',)})
def test_delete_firewall(self): def test_delete_firewall(self):
self.set_up_expect() api.neutron.is_extension_supported(
IsA(http.HttpRequest), 'fwaasrouterinsertion'
).MultipleTimes().AndReturn(True)
routers = self.routers.list()
api.neutron.router_list(
IsA(http.HttpRequest), tenant_id=self.tenant.id).AndReturn(routers)
fwl = self.firewalls.first() fwl = self.firewalls.first()
api.fwaas.firewall_list_for_tenant(
IsA(http.HttpRequest), self.tenant.id).AndReturn([fwl])
api.fwaas.firewall_delete(IsA(http.HttpRequest), fwl.id) api.fwaas.firewall_delete(IsA(http.HttpRequest), fwl.id)
self.mox.ReplayAll() self.mox.ReplayAll()

View File

@ -12,15 +12,12 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import re
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy from django.core.urlresolvers import reverse_lazy
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from horizon import exceptions from horizon import exceptions
from horizon import forms from horizon import forms
from horizon import messages
from horizon import tabs from horizon import tabs
from horizon.utils import memoized from horizon.utils import memoized
from horizon import workflows from horizon import workflows
@ -51,44 +48,11 @@ AddPolicy = fw_workflows.AddPolicy
AddRule = fw_workflows.AddRule AddRule = fw_workflows.AddRule
class IndexView(tabs.TabView): class IndexView(tabs.TabbedTableView):
tab_group_class = (FirewallTabs) tab_group_class = FirewallTabs
template_name = 'project/firewalls/details_tabs.html' template_name = 'project/firewalls/details_tabs.html'
page_title = _("Firewalls") page_title = _("Firewalls")
def post(self, request, *args, **kwargs):
obj_ids = request.POST.getlist('object_ids')
action = request.POST['action']
obj_type = re.search('.delete([a-z]+)', action).group(1)
if not obj_ids:
obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
if obj_type == 'rule':
for obj_id in obj_ids:
try:
api.fwaas.rule_delete(request, obj_id)
messages.success(request, _('Deleted rule %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete rule. %s') % e)
if obj_type == 'policy':
for obj_id in obj_ids:
try:
api.fwaas.policy_delete(request, obj_id)
messages.success(request, _('Deleted policy %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete policy. %s') % e)
if obj_type == 'firewall':
for obj_id in obj_ids:
try:
api.fwaas.firewall_delete(request, obj_id)
messages.success(request,
_('Deleted firewall %s') % obj_id)
except Exception as e:
exceptions.handle(request,
_('Unable to delete firewall. %s') % e)
return self.get(request, *args, **kwargs)
class AddRuleView(workflows.WorkflowView): class AddRuleView(workflows.WorkflowView):
workflow_class = AddRule workflow_class = AddRule