Fix H202 hacking check in VPN client

Closes-Bug: #1217840

H202 was added recently in hacking 0.7.0.

Change-Id: Icaa73bb3483844a8d50e8fa1bf01495375c49dc9
This commit is contained in:
Akihiro MOTOKI
2013-08-28 20:23:02 +09:00
parent ad59ba6097
commit 081b55b7ae
3 changed files with 12 additions and 9 deletions

View File

@@ -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',
@@ -40,7 +41,7 @@ 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: "
@@ -48,7 +49,7 @@ def validate_dpd_dict(dpd_dict):
"'%(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 = _(
@@ -56,7 +57,7 @@ def validate_dpd_dict(dpd_dict):
"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
@@ -78,7 +79,7 @@ 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 = _(
@@ -86,7 +87,7 @@ def validate_lifetime_dict(lifetime_dict):
"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

View File

@@ -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
@@ -166,7 +167,7 @@ class CLITestV20IPsecSiteConnectionJSON(test_cli20.CLITestV20Base):
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)
@@ -213,7 +214,7 @@ class CLITestV20IPsecSiteConnectionJSON(test_cli20.CLITestV20Base):
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)

View File

@@ -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
@@ -121,12 +122,12 @@ class TestVPNUtils(testtools.TestCase):
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))