Merge "FWaaS delete actions refactoring"

changes/13/179513/17 8.0.0.0rc1
Jenkins 7 years ago committed by Gerrit Code Review
commit 7f9580170b
  1. 26
      openstack_dashboard/dashboards/project/firewalls/tables.py
  2. 48
      openstack_dashboard/dashboards/project/firewalls/tests.py
  3. 40
      openstack_dashboard/dashboards/project/firewalls/views.py

@ -57,6 +57,7 @@ class AddFirewallLink(tables.LinkAction):
class DeleteRuleLink(policy.PolicyTargetMixin, tables.DeleteAction):
name = "deleterule"
policy_rules = (("network", "delete_firewall_rule"),)
@staticmethod
def action_present(count):
@ -74,11 +75,21 @@ class DeleteRuleLink(policy.PolicyTargetMixin, tables.DeleteAction):
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):
name = "deletepolicy"
policy_rules = (("network", "delete_firewall_policy"),)
@staticmethod
def action_present(count):
@ -96,12 +107,17 @@ class DeletePolicyLink(policy.PolicyTargetMixin, tables.DeleteAction):
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,
tables.DeleteAction):
name = "deletefirewall"
policy_rules = (("network", "delete_firewall"),)
@staticmethod
def action_present(count):
@ -119,7 +135,11 @@ class DeleteFirewallLink(policy.PolicyTargetMixin,
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):

@ -744,16 +744,17 @@ class FirewallTests(test.TestCase):
self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
@test.create_stubs({api.fwaas: ('firewall_list_for_tenant',
'policy_list_for_tenant',
'rule_list_for_tenant',
'firewall_unassociated_routers_list',
@test.create_stubs({api.fwaas: ('rule_list_for_tenant',
'rule_delete'),
api.neutron: ('is_extension_supported',
'router_list',), })
api.neutron: ('is_extension_supported',)})
def test_delete_rule(self):
self.set_up_expect()
rule = self.fw_rules.first()
api.neutron.is_extension_supported(
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)
self.mox.ReplayAll()
@ -762,16 +763,17 @@ class FirewallTests(test.TestCase):
self.assertNoFormErrors(res)
@test.create_stubs({api.fwaas: ('firewall_list_for_tenant',
'policy_list_for_tenant',
'rule_list_for_tenant',
'firewall_unassociated_routers_list',
@test.create_stubs({api.fwaas: ('policy_list_for_tenant',
'policy_delete'),
api.neutron: ('is_extension_supported',
'router_list',), })
api.neutron: ('is_extension_supported',)})
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()
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)
self.mox.ReplayAll()
@ -781,15 +783,21 @@ class FirewallTests(test.TestCase):
self.assertNoFormErrors(res)
@test.create_stubs({api.fwaas: ('firewall_list_for_tenant',
'policy_list_for_tenant',
'rule_list_for_tenant',
'firewall_unassociated_routers_list',
'firewall_delete'),
api.neutron: ('is_extension_supported',
'router_list',), })
'router_list',)})
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()
api.fwaas.firewall_list_for_tenant(
IsA(http.HttpRequest), self.tenant.id).AndReturn([fwl])
api.fwaas.firewall_delete(IsA(http.HttpRequest), fwl.id)
self.mox.ReplayAll()

@ -12,15 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
import re
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
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
@ -51,44 +48,11 @@ AddPolicy = fw_workflows.AddPolicy
AddRule = fw_workflows.AddRule
class IndexView(tabs.TabView):
tab_group_class = (FirewallTabs)
class IndexView(tabs.TabbedTableView):
tab_group_class = FirewallTabs
template_name = 'project/firewalls/details_tabs.html'
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):
workflow_class = AddRule

Loading…
Cancel
Save