From bf3750175a9f600d8a8f32612f1fdb3f9000be1a Mon Sep 17 00:00:00 2001 From: Shivakumar M Date: Tue, 22 Jul 2014 06:22:01 -0700 Subject: [PATCH] Audited attribute for policy update not changing Updating firewall policy with shared, name or description is not changing the audited attribute to false. Modified firewall policy update to make audited to false. Change-Id: Ic3f3e08190dcdaa8f4ecda729bdb2fdf1bdadc52 Closes-bug: 1327063 --- neutron/db/firewall/firewall_db.py | 2 ++ .../unit/db/firewall/test_db_firewall.py | 23 ++++++++++++++++--- .../unit/vmware/vshield/test_fwaas_plugin.py | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/neutron/db/firewall/firewall_db.py b/neutron/db/firewall/firewall_db.py index 46042df84b..47046139ed 100644 --- a/neutron/db/firewall/firewall_db.py +++ b/neutron/db/firewall/firewall_db.py @@ -312,6 +312,8 @@ class Firewall_db_mixin(firewall.FirewallPluginBase, base_db.CommonDbMixin): self._set_rules_for_policy(context, fwp_db, fwp['firewall_rules']) del fwp['firewall_rules'] + if 'audited' not in fwp or fwp['audited']: + fwp['audited'] = False fwp_db.update(fwp) return self._make_firewall_policy_dict(fwp_db) diff --git a/neutron/tests/unit/db/firewall/test_db_firewall.py b/neutron/tests/unit/db/firewall/test_db_firewall.py index 1c1483d1dc..0abd354646 100644 --- a/neutron/tests/unit/db/firewall/test_db_firewall.py +++ b/neutron/tests/unit/db/firewall/test_db_firewall.py @@ -131,13 +131,14 @@ class FirewallPluginDbTestCase(test_db_plugin.NeutronDbPluginV2TestCase): 'enabled': ENABLED} return attrs - def _get_test_firewall_policy_attrs(self, name='firewall_policy1'): + def _get_test_firewall_policy_attrs(self, name='firewall_policy1', + audited=AUDITED): attrs = {'name': name, 'description': DESCRIPTION, 'tenant_id': self._tenant_id, 'shared': SHARED, 'firewall_rules': [], - 'audited': AUDITED} + 'audited': audited} return attrs def _get_test_firewall_attrs(self, name='firewall_1'): @@ -373,7 +374,7 @@ class TestFirewallDBPlugin(FirewallPluginDbTestCase): def test_update_firewall_policy(self): name = "new_firewall_policy1" - attrs = self._get_test_firewall_policy_attrs(name) + attrs = self._get_test_firewall_policy_attrs(name, audited=False) with self.firewall_policy(shared=SHARED, firewall_rules=None, @@ -385,6 +386,22 @@ class TestFirewallDBPlugin(FirewallPluginDbTestCase): for k, v in attrs.iteritems(): self.assertEqual(res['firewall_policy'][k], v) + def test_update_firewall_policy_set_audited_false(self): + attrs = self._get_test_firewall_policy_attrs(audited=False) + + with self.firewall_policy(name='firewall_policy1', + description='fwp', + audited=AUDITED) as fwp: + data = {'firewall_policy': + {'description': 'fw_p1'}} + req = self.new_update_request('firewall_policies', data, + fwp['firewall_policy']['id']) + res = self.deserialize(self.fmt, + req.get_response(self.ext_api)) + attrs['description'] = 'fw_p1' + for k, v in attrs.iteritems(): + self.assertEqual(res['firewall_policy'][k], v) + def test_update_firewall_policy_with_rules(self): attrs = self._get_test_firewall_policy_attrs() diff --git a/neutron/tests/unit/vmware/vshield/test_fwaas_plugin.py b/neutron/tests/unit/vmware/vshield/test_fwaas_plugin.py index b96844c034..04c24172e2 100644 --- a/neutron/tests/unit/vmware/vshield/test_fwaas_plugin.py +++ b/neutron/tests/unit/vmware/vshield/test_fwaas_plugin.py @@ -291,7 +291,7 @@ class FirewallPluginTestCase(test_db_firewall.FirewallPluginDbTestCase, def test_update_firewall_policy_with_no_firewall(self): name = "new_firewall_policy1" - attrs = self._get_test_firewall_policy_attrs(name) + attrs = self._get_test_firewall_policy_attrs(name, audited=False) with self.firewall_policy(shared=test_db_firewall.SHARED, firewall_rules=None, @@ -305,7 +305,7 @@ class FirewallPluginTestCase(test_db_firewall.FirewallPluginDbTestCase, def test_update_firewall_policy_with_firewall(self): name = "new_firewall_policy1" - attrs = self._get_test_firewall_policy_attrs(name) + attrs = self._get_test_firewall_policy_attrs(name, audited=False) with self.firewall_policy(shared=test_db_firewall.SHARED, firewall_rules=None,