Browse Source

Merge "FWaaS delete actions refactoring"

Jenkins 3 years ago
parent
commit
7f9580170b

+ 23
- 3
openstack_dashboard/dashboards/project/firewalls/tables.py View File

@@ -57,6 +57,7 @@ class AddFirewallLink(tables.LinkAction):
57 57
 
58 58
 class DeleteRuleLink(policy.PolicyTargetMixin, tables.DeleteAction):
59 59
     name = "deleterule"
60
+    policy_rules = (("network", "delete_firewall_rule"),)
60 61
 
61 62
     @staticmethod
62 63
     def action_present(count):
@@ -74,11 +75,21 @@ class DeleteRuleLink(policy.PolicyTargetMixin, tables.DeleteAction):
74 75
             count
75 76
         )
76 77
 
77
-    policy_rules = (("network", "delete_firewall_rule"),)
78
+    def allowed(self, request, datum=None):
79
+        if datum and datum.policy:
80
+            return False
81
+        return True
82
+
83
+    def delete(self, request, obj_id):
84
+        try:
85
+            api.fwaas.rule_delete(request, obj_id)
86
+        except Exception as e:
87
+            exceptions.handle(request, _('Unable to delete rule. %s') % e)
78 88
 
79 89
 
80 90
 class DeletePolicyLink(policy.PolicyTargetMixin, tables.DeleteAction):
81 91
     name = "deletepolicy"
92
+    policy_rules = (("network", "delete_firewall_policy"),)
82 93
 
83 94
     @staticmethod
84 95
     def action_present(count):
@@ -96,12 +107,17 @@ class DeletePolicyLink(policy.PolicyTargetMixin, tables.DeleteAction):
96 107
             count
97 108
         )
98 109
 
99
-    policy_rules = (("network", "delete_firewall_policy"),)
110
+    def delete(self, request, obj_id):
111
+        try:
112
+            api.fwaas.policy_delete(request, obj_id)
113
+        except Exception as e:
114
+            exceptions.handle(request, _('Unable to delete policy. %s') % e)
100 115
 
101 116
 
102 117
 class DeleteFirewallLink(policy.PolicyTargetMixin,
103 118
                          tables.DeleteAction):
104 119
     name = "deletefirewall"
120
+    policy_rules = (("network", "delete_firewall"),)
105 121
 
106 122
     @staticmethod
107 123
     def action_present(count):
@@ -119,7 +135,11 @@ class DeleteFirewallLink(policy.PolicyTargetMixin,
119 135
             count
120 136
         )
121 137
 
122
-    policy_rules = (("network", "delete_firewall"),)
138
+    def delete(self, request, obj_id):
139
+        try:
140
+            api.fwaas.firewall_delete(request, obj_id)
141
+        except Exception as e:
142
+            exceptions.handle(request, _('Unable to delete firewall. %s') % e)
123 143
 
124 144
 
125 145
 class UpdateRuleLink(policy.PolicyTargetMixin, tables.LinkAction):

+ 28
- 20
openstack_dashboard/dashboards/project/firewalls/tests.py View File

@@ -744,16 +744,17 @@ class FirewallTests(test.TestCase):
744 744
         self.assertNoFormErrors(res)
745 745
         self.assertRedirectsNoFollow(res, str(self.INDEX_URL))
746 746
 
747
-    @test.create_stubs({api.fwaas: ('firewall_list_for_tenant',
748
-                                    'policy_list_for_tenant',
749
-                                    'rule_list_for_tenant',
750
-                                    'firewall_unassociated_routers_list',
747
+    @test.create_stubs({api.fwaas: ('rule_list_for_tenant',
751 748
                                     'rule_delete'),
752
-                        api.neutron: ('is_extension_supported',
753
-                                      'router_list',), })
749
+                        api.neutron: ('is_extension_supported',)})
754 750
     def test_delete_rule(self):
755
-        self.set_up_expect()
756
-        rule = self.fw_rules.first()
751
+        api.neutron.is_extension_supported(
752
+            IsA(http.HttpRequest), 'fwaasrouterinsertion').AndReturn(True)
753
+
754
+        rule = self.fw_rules.list()[2]
755
+        api.fwaas.rule_list_for_tenant(
756
+            IsA(http.HttpRequest),
757
+            self.tenant.id).AndReturn(self.fw_rules.list())
757 758
         api.fwaas.rule_delete(IsA(http.HttpRequest), rule.id)
758 759
         self.mox.ReplayAll()
759 760
 
@@ -762,16 +763,17 @@ class FirewallTests(test.TestCase):
762 763
 
763 764
         self.assertNoFormErrors(res)
764 765
 
765
-    @test.create_stubs({api.fwaas: ('firewall_list_for_tenant',
766
-                                    'policy_list_for_tenant',
767
-                                    'rule_list_for_tenant',
768
-                                    'firewall_unassociated_routers_list',
766
+    @test.create_stubs({api.fwaas: ('policy_list_for_tenant',
769 767
                                     'policy_delete'),
770
-                        api.neutron: ('is_extension_supported',
771
-                                      'router_list',), })
768
+                        api.neutron: ('is_extension_supported',)})
772 769
     def test_delete_policy(self):
773
-        self.set_up_expect()
770
+        api.neutron.is_extension_supported(
771
+            IsA(http.HttpRequest), 'fwaasrouterinsertion').AndReturn(True)
772
+
774 773
         policy = self.fw_policies.first()
774
+        api.fwaas.policy_list_for_tenant(
775
+            IsA(http.HttpRequest),
776
+            self.tenant.id).AndReturn(self.fw_policies.list())
775 777
         api.fwaas.policy_delete(IsA(http.HttpRequest), policy.id)
776 778
         self.mox.ReplayAll()
777 779
 
@@ -781,15 +783,21 @@ class FirewallTests(test.TestCase):
781 783
         self.assertNoFormErrors(res)
782 784
 
783 785
     @test.create_stubs({api.fwaas: ('firewall_list_for_tenant',
784
-                                    'policy_list_for_tenant',
785
-                                    'rule_list_for_tenant',
786
-                                    'firewall_unassociated_routers_list',
787 786
                                     'firewall_delete'),
788 787
                         api.neutron: ('is_extension_supported',
789
-                                      'router_list',), })
788
+                                      'router_list',)})
790 789
     def test_delete_firewall(self):
791
-        self.set_up_expect()
790
+        api.neutron.is_extension_supported(
791
+            IsA(http.HttpRequest), 'fwaasrouterinsertion'
792
+        ).MultipleTimes().AndReturn(True)
793
+
794
+        routers = self.routers.list()
795
+        api.neutron.router_list(
796
+            IsA(http.HttpRequest), tenant_id=self.tenant.id).AndReturn(routers)
797
+
792 798
         fwl = self.firewalls.first()
799
+        api.fwaas.firewall_list_for_tenant(
800
+            IsA(http.HttpRequest), self.tenant.id).AndReturn([fwl])
793 801
         api.fwaas.firewall_delete(IsA(http.HttpRequest), fwl.id)
794 802
         self.mox.ReplayAll()
795 803
 

+ 2
- 38
openstack_dashboard/dashboards/project/firewalls/views.py View File

@@ -12,15 +12,12 @@
12 12
 #    License for the specific language governing permissions and limitations
13 13
 #    under the License.
14 14
 
15
-import re
16
-
17 15
 from django.core.urlresolvers import reverse
18 16
 from django.core.urlresolvers import reverse_lazy
19 17
 from django.utils.translation import ugettext_lazy as _
20 18
 
21 19
 from horizon import exceptions
22 20
 from horizon import forms
23
-from horizon import messages
24 21
 from horizon import tabs
25 22
 from horizon.utils import memoized
26 23
 from horizon import workflows
@@ -51,44 +48,11 @@ AddPolicy = fw_workflows.AddPolicy
51 48
 AddRule = fw_workflows.AddRule
52 49
 
53 50
 
54
-class IndexView(tabs.TabView):
55
-    tab_group_class = (FirewallTabs)
51
+class IndexView(tabs.TabbedTableView):
52
+    tab_group_class = FirewallTabs
56 53
     template_name = 'project/firewalls/details_tabs.html'
57 54
     page_title = _("Firewalls")
58 55
 
59
-    def post(self, request, *args, **kwargs):
60
-        obj_ids = request.POST.getlist('object_ids')
61
-        action = request.POST['action']
62
-        obj_type = re.search('.delete([a-z]+)', action).group(1)
63
-        if not obj_ids:
64
-            obj_ids.append(re.search('([0-9a-z-]+)$', action).group(1))
65
-        if obj_type == 'rule':
66
-            for obj_id in obj_ids:
67
-                try:
68
-                    api.fwaas.rule_delete(request, obj_id)
69
-                    messages.success(request, _('Deleted rule %s') % obj_id)
70
-                except Exception as e:
71
-                    exceptions.handle(request,
72
-                                      _('Unable to delete rule. %s') % e)
73
-        if obj_type == 'policy':
74
-            for obj_id in obj_ids:
75
-                try:
76
-                    api.fwaas.policy_delete(request, obj_id)
77
-                    messages.success(request, _('Deleted policy %s') % obj_id)
78
-                except Exception as e:
79
-                    exceptions.handle(request,
80
-                                      _('Unable to delete policy. %s') % e)
81
-        if obj_type == 'firewall':
82
-            for obj_id in obj_ids:
83
-                try:
84
-                    api.fwaas.firewall_delete(request, obj_id)
85
-                    messages.success(request,
86
-                                     _('Deleted firewall %s') % obj_id)
87
-                except Exception as e:
88
-                    exceptions.handle(request,
89
-                                      _('Unable to delete firewall. %s') % e)
90
-        return self.get(request, *args, **kwargs)
91
-
92 56
 
93 57
 class AddRuleView(workflows.WorkflowView):
94 58
     workflow_class = AddRule

Loading…
Cancel
Save