summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Ma <stephen.ma@hp.com>2013-08-07 13:29:43 -0700
committerStephen Ma <stephen.ma@hp.com>2013-08-26 17:37:36 -0700
commit5ae7b02385f085e117c074b4e16aaa3f06e86cb3 (patch)
tree348bcc862ed94f3c231d2e843e43c00ff0fad879
parentad59ba60979ff9506972024d5a7d4a227e685568 (diff)
downloadpython-neutronclient-5ae7b02385f085e117c074b4e16aaa3f06e86cb3.tar.gz
neutron router-gateway-set failed for non-admin users
Fixed the neutron router-gateway-set command regression: "neutron router-gateway-set <router> <public-net>" is failing for non-admin users. Changed the behavior to pass the enable_snat attribute to the server only when the --disable-snat option is specified. bug 1209027 Change-Id: Iec55a17ed7966ee15bf05982d98540fe6884fa20
-rw-r--r--neutronclient/neutron/v2_0/router.py10
-rw-r--r--neutronclient/tests/unit/test_cli20_router.py13
2 files changed, 17 insertions, 6 deletions
diff --git a/neutronclient/neutron/v2_0/router.py b/neutronclient/neutron/v2_0/router.py
index 54b8117..197c6df 100644
--- a/neutronclient/neutron/v2_0/router.py
+++ b/neutronclient/neutron/v2_0/router.py
@@ -185,7 +185,7 @@ class SetGatewayRouter(neutronV20.NeutronCommand):
'external_network_id', metavar='external-network-id',
help='ID of the external network for the gateway')
parser.add_argument(
- '--disable-snat', action='store_false', dest='enable_snat',
+ '--disable-snat', action='store_true',
help='Disable Source NAT on the router gateway')
return parser
@@ -197,10 +197,10 @@ class SetGatewayRouter(neutronV20.NeutronCommand):
neutron_client, self.resource, parsed_args.router_id)
_ext_net_id = neutronV20.find_resourceid_by_name_or_id(
neutron_client, 'network', parsed_args.external_network_id)
- neutron_client.add_gateway_router(
- _router_id,
- {'network_id': _ext_net_id,
- 'enable_snat': parsed_args.enable_snat})
+ router_dict = {'network_id': _ext_net_id}
+ if parsed_args.disable_snat:
+ router_dict['enable_snat'] = False
+ neutron_client.add_gateway_router(_router_id, router_dict)
print >>self.app.stdout, (
_('Set gateway for router %s') % parsed_args.router_id)
diff --git a/neutronclient/tests/unit/test_cli20_router.py b/neutronclient/tests/unit/test_cli20_router.py
index f7b6111..5d61e57 100644
--- a/neutronclient/tests/unit/test_cli20_router.py
+++ b/neutronclient/tests/unit/test_cli20_router.py
@@ -179,8 +179,19 @@ class CLITestV20RouterJSON(test_cli20.CLITestV20Base):
self._test_update_resource(resource, cmd, 'myid',
args,
{"external_gateway_info":
+ {"network_id": "externalid"}}
+ )
+
+ def test_set_gateway_disable_snat(self):
+ """set external gateway for router: myid externalid."""
+ resource = 'router'
+ cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
+ args = ['myid', 'externalid', '--disable-snat']
+ self._test_update_resource(resource, cmd, 'myid',
+ args,
+ {"external_gateway_info":
{"network_id": "externalid",
- "enable_snat": True}}
+ "enable_snat": False}}
)
def test_remove_gateway(self):