Skip to content

Commit

Permalink
Fix H202 hacking check in VPN client
Browse files Browse the repository at this point in the history
Closes-Bug: #1217840

H202 was added recently in hacking 0.7.0.

Change-Id: Icaa73bb3483844a8d50e8fa1bf01495375c49dc9
  • Loading branch information
amotoki committed Aug 28, 2013
1 parent ad59ba6 commit 081b55b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
11 changes: 6 additions & 5 deletions neutronclient/neutron/v2_0/vpn/utils.py
Expand Up @@ -22,6 +22,7 @@
"""VPN Utilities and helper functions."""


from neutronclient.common import exceptions
from neutronclient.openstack.common.gettextutils import _

dpd_supported_actions = ['hold', 'clear', 'restart',
Expand All @@ -40,23 +41,23 @@ def validate_dpd_dict(dpd_dict):
"Reason-Invalid DPD key : "
"'%(key)s' not in %(supported_key)s ") % {
'key': key, 'supported_key': dpd_supported_keys}
raise KeyError(message)
raise exceptions.CommandError(message)
if key == 'action' and value not in dpd_supported_actions:
message = _(
"DPD Dictionary ValueError: "
"Reason-Invalid DPD action : "
"'%(key_value)s' not in %(supported_action)s ") % {
'key_value': value,
'supported_action': dpd_supported_actions}
raise ValueError(message)
raise exceptions.CommandError(message)
if key in ('interval', 'timeout'):
if int(value) <= 0:
message = _(
"DPD Dictionary ValueError: "
"Reason-Invalid positive integer value: "
"'%(key)s' = %(value)i ") % {
'key': key, 'value': int(value)}
raise ValueError(message)
raise exceptions.CommandError(message)
else:
dpd_dict[key] = int(value)
return
Expand All @@ -78,15 +79,15 @@ def validate_lifetime_dict(lifetime_dict):
"Reason-Invalid units : "
"'%(key_value)s' not in %(supported_units)s ") % {
'key_value': key, 'supported_units': lifetime_units}
raise ValueError(message)
raise exceptions.CommandError(message)
if key == 'value':
if int(value) < 60:
message = _(
"Lifetime Dictionary ValueError: "
"Reason-Invalid value should be at least 60:"
"'%(key_value)s' = %(value)i ") % {
'key_value': key, 'value': int(value)}
raise ValueError(str(message))
raise exceptions.CommandError(str(message))
else:
lifetime_dict['value'] = int(value)
return
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/vpn/test_cli20_ipsec_site_connection.py
Expand Up @@ -19,6 +19,7 @@

import sys

from neutronclient.common import exceptions
from neutronclient.neutron.v2_0.vpn import ipsec_site_connection
from tests.unit import test_cli20

Expand Down Expand Up @@ -166,7 +167,7 @@ def _test_dpd_values(self, dpd):
initiator, description,
vpnservice_id, ikepolicy_id, ipsecpolicy_id]
self.assertRaises(
Exception,
exceptions.CommandError,
self._test_create_resource,
resource, cmd, name, my_id, args,
position_names, position_values)
Expand Down Expand Up @@ -213,7 +214,7 @@ def test_invalid_mtu(self):
initiator, description,
vpnservice_id, ikepolicy_id, ipsecpolicy_id]
self.assertRaises(
Exception,
exceptions.CommandError,
self._test_create_resource,
resource, cmd, name, my_id, args,
position_names, position_values)
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/vpn/test_utils.py
Expand Up @@ -19,6 +19,7 @@

import testtools

from neutronclient.common import exceptions
from neutronclient.common import utils
from neutronclient.neutron.v2_0.vpn import utils as vpn_utils

Expand Down Expand Up @@ -121,12 +122,12 @@ def test_validate_dpd_dictionary_negative_timeout_value(self):

def _test_validate_lifetime_negative_test_case(self, input_str):
"""Generic handler for negative lifetime tests."""
self.assertRaises(Exception,
self.assertRaises(exceptions.CommandError,
vpn_utils.validate_lifetime_dict,
(input_str))

def _test_validate_dpd_negative_test_case(self, input_str):
"""Generic handler for negative lifetime tests."""
self.assertRaises(Exception,
self.assertRaises(exceptions.CommandError,
vpn_utils.validate_lifetime_dict,
(input_str))

0 comments on commit 081b55b

Please sign in to comment.