From dc80bc1fd82b9cac568d8af0ff24be6cf205e82a Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Thu, 10 Oct 2013 13:10:58 +0400 Subject: [PATCH] Fix access to lifetime dict in update_ipsecpolicy method Also add corresponding unit test. Change-Id: Ie1141b5034415ccf3039a71dfedc47cfb2ca7a88 Closes-Bug: #1237912 --- neutron/db/vpn/vpn_db.py | 2 +- neutron/tests/unit/db/vpn/test_db_vpnaas.py | 33 ++++++++++++++++++--- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/neutron/db/vpn/vpn_db.py b/neutron/db/vpn/vpn_db.py index 175dd0bc6e..8052c18de2 100644 --- a/neutron/db/vpn/vpn_db.py +++ b/neutron/db/vpn/vpn_db.py @@ -504,7 +504,7 @@ class VPNPluginDb(VPNPluginBase, base_db.CommonDbMixin): if lifetime_info: if lifetime_info.get('units'): ipsecp['lifetime_units'] = lifetime_info['units'] - if lifetime_info('value'): + if lifetime_info.get('value'): ipsecp['lifetime_value'] = lifetime_info['value'] ipsecp_db.update(ipsecp) return self._make_ipsecpolicy_dict(ipsecp_db) diff --git a/neutron/tests/unit/db/vpn/test_db_vpnaas.py b/neutron/tests/unit/db/vpn/test_db_vpnaas.py index 9296e9b941..23c4fcd193 100644 --- a/neutron/tests/unit/db/vpn/test_db_vpnaas.py +++ b/neutron/tests/unit/db/vpn/test_db_vpnaas.py @@ -515,9 +515,13 @@ class TestVpnaas(VPNPluginDbTestCase): ('phase1_negotiation_mode', 'main'), ('ike_version', 'v1'), ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] + ('tenant_id', self._tenant_id), + ('lifetime', {'units': 'seconds', + 'value': 60})] with self.ikepolicy(name=name) as ikepolicy: - data = {'ikepolicy': {'name': name}} + data = {'ikepolicy': {'name': name, + 'lifetime': {'units': 'seconds', + 'value': 60}}} req = self.new_update_request("ikepolicies", data, ikepolicy['ikepolicy']['id']) @@ -699,9 +703,13 @@ class TestVpnaas(VPNPluginDbTestCase): ('encapsulation_mode', 'tunnel'), ('transform_protocol', 'esp'), ('pfs', 'group5'), - ('tenant_id', self._tenant_id)] + ('tenant_id', self._tenant_id), + ('lifetime', {'units': 'seconds', + 'value': 60})] with self.ipsecpolicy(name=name) as ipsecpolicy: - data = {'ipsecpolicy': {'name': name}} + data = {'ipsecpolicy': {'name': name, + 'lifetime': {'units': 'seconds', + 'value': 60}}} req = self.new_update_request("ipsecpolicies", data, ipsecpolicy['ipsecpolicy']['id']) @@ -709,6 +717,23 @@ class TestVpnaas(VPNPluginDbTestCase): for k, v in keys: self.assertEqual(res['ipsecpolicy'][k], v) + def test_update_ipsecpolicy_lifetime(self): + with self.ipsecpolicy() as ipsecpolicy: + data = {'ipsecpolicy': {'lifetime': {'units': 'seconds'}}} + req = self.new_update_request("ipsecpolicies", + data, + ipsecpolicy['ipsecpolicy']['id']) + res = self.deserialize(self.fmt, req.get_response(self.ext_api)) + self.assertEqual(res['ipsecpolicy']['lifetime']['units'], + 'seconds') + + data = {'ipsecpolicy': {'lifetime': {'value': 60}}} + req = self.new_update_request("ipsecpolicies", + data, + ipsecpolicy['ipsecpolicy']['id']) + res = self.deserialize(self.fmt, req.get_response(self.ext_api)) + self.assertEqual(res['ipsecpolicy']['lifetime']['value'], 60) + def test_create_ipsecpolicy_with_invalid_values(self): """Test case to test invalid values.""" name = 'ipsecpolicy1'