diff options
| author | Dan Wendlandt <dan@nicira.com> | 2012-08-21 01:54:17 -0700 |
|---|---|---|
| committer | Gary Kotton <gkotton@redhat.com> | 2012-08-22 06:14:51 -0400 |
| commit | 38abece8a6a82c722b00d8ea46997aacecb463a5 (patch) | |
| tree | 8e8a8ecda33fa32346dac9ccd4f55e0b74a16ae2 /quantumclient/tests | |
| parent | f574f77731ed3ee2123c2b8f8572c50e30810c43 (diff) | |
| download | python-neutronclient-38abece8a6a82c722b00d8ea46997aacecb463a5.tar.gz | |
initial client + CLI support for routers + floating ips
bp quantum-client-l3-floating-ip
The task also does the following:
1. Fixes alignment of the --help output
2. Ensures that a show command prints a dictionary correctly
Change-Id: Ib61b3e8748a7bd476ec008ab6ce20ab852e92f58
Diffstat (limited to 'quantumclient/tests')
| -rw-r--r-- | quantumclient/tests/unit/test_cli20.py | 24 | ||||
| -rw-r--r-- | quantumclient/tests/unit/test_cli20_floatingips.py | 96 | ||||
| -rw-r--r-- | quantumclient/tests/unit/test_cli20_router.py | 151 |
3 files changed, 270 insertions, 1 deletions
diff --git a/quantumclient/tests/unit/test_cli20.py b/quantumclient/tests/unit/test_cli20.py index 3737061..6ed0afc 100644 --- a/quantumclient/tests/unit/test_cli20.py +++ b/quantumclient/tests/unit/test_cli20.py @@ -140,7 +140,7 @@ class CLITestV20Base(unittest.TestCase): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) - if resource == 'subnet': + if (resource == 'subnet' or resource == 'floatingip'): body = {resource: {}, } else: body = {resource: {'admin_state_up': admin_state_up, }, } @@ -293,3 +293,25 @@ class CLITestV20Base(unittest.TestCase): self.mox.UnsetStubs() _str = self.fake_stdout.make_string() self.assertTrue(myid in _str) + + def _test_update_resource_action(self, resource, cmd, myid, action, args, + body): + self.mox.StubOutWithMock(cmd, "get_client") + self.mox.StubOutWithMock(self.client.httpclient, "request") + cmd.get_client().MultipleTimes().AndReturn(self.client) + path = getattr(self.client, resource + "_path") + path_action = '%s/%s' % (myid, action) + self.client.httpclient.request( + end_url(path % path_action), 'PUT', + body=MyComparator(body, self.client), + headers=ContainsKeyValue('X-Auth-Token', + TOKEN)).AndReturn((MyResp(204), None)) + self.mox.ReplayAll() + cmd_parser = cmd.get_parser("update_" + resource) + + parsed_args = cmd_parser.parse_args(args) + cmd.run(parsed_args) + self.mox.VerifyAll() + self.mox.UnsetStubs() + _str = self.fake_stdout.make_string() + self.assertTrue(myid in _str) diff --git a/quantumclient/tests/unit/test_cli20_floatingips.py b/quantumclient/tests/unit/test_cli20_floatingips.py new file mode 100644 index 0000000..f9b63df --- /dev/null +++ b/quantumclient/tests/unit/test_cli20_floatingips.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 Red Hat +# All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import sys + +from quantumclient.common import exceptions +from quantumclient.quantum.v2_0.floatingip import AssociateFloatingIP +from quantumclient.quantum.v2_0.floatingip import CreateFloatingIP +from quantumclient.quantum.v2_0.floatingip import DeleteFloatingIP +from quantumclient.quantum.v2_0.floatingip import DisassociateFloatingIP +from quantumclient.quantum.v2_0.floatingip import ListFloatingIP +from quantumclient.quantum.v2_0.floatingip import ShowFloatingIP +from quantumclient.tests.unit.test_cli20 import CLITestV20Base +from quantumclient.tests.unit.test_cli20 import MyApp + + +class CLITestV20FloatingIps(CLITestV20Base): + def test_create_floatingip(self): + """Create floatingip: fip1.""" + resource = 'floatingip' + cmd = CreateFloatingIP(MyApp(sys.stdout), None) + name = 'fip1' + myid = 'myid' + args = [name] + position_names = ['floating_network_id'] + position_values = [name] + _str = self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values) + + def test_create_floatingip_and_port(self): + """Create floatingip: fip1.""" + resource = 'floatingip' + cmd = CreateFloatingIP(MyApp(sys.stdout), None) + name = 'fip1' + myid = 'myid' + pid = 'mypid' + args = [name, '--port_id', pid] + position_names = ['floating_network_id', 'port_id'] + position_values = [name, pid] + _str = self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values) + + def test_list_floatingips(self): + """list floatingips: -D.""" + resources = 'floatingips' + cmd = ListFloatingIP(MyApp(sys.stdout), None) + self._test_list_resources(resources, cmd, True) + + def test_delete_floatingip(self): + """Delete floatingip: fip1""" + resource = 'floatingip' + cmd = DeleteFloatingIP(MyApp(sys.stdout), None) + myid = 'myid' + args = [myid] + self._test_delete_resource(resource, cmd, myid, args) + + def test_show_floatingip(self): + """Show floatingip: --fields id.""" + resource = 'floatingip' + cmd = ShowFloatingIP(MyApp(sys.stdout), None) + args = ['--fields', 'id', self.test_id] + self._test_show_resource(resource, cmd, self.test_id, + args, ['id']) + + def test_disassociate_ip(self): + """Disassociate floating IP: myid""" + resource = 'floatingip' + cmd = DisassociateFloatingIP(MyApp(sys.stdout), None) + args = ['myid'] + self._test_update_resource(resource, cmd, 'myid', + args, {"port_id": None} + ) + + def test_associate_ip(self): + """Associate floating IP: myid portid""" + resource = 'floatingip' + cmd = AssociateFloatingIP(MyApp(sys.stdout), None) + args = ['myid', 'portid'] + self._test_update_resource(resource, cmd, 'myid', + args, {"port_id": "portid"} + ) diff --git a/quantumclient/tests/unit/test_cli20_router.py b/quantumclient/tests/unit/test_cli20_router.py new file mode 100644 index 0000000..502365d --- /dev/null +++ b/quantumclient/tests/unit/test_cli20_router.py @@ -0,0 +1,151 @@ +# Copyright 2012 Nicira, Inc +# All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +import sys + +from quantumclient.common import exceptions +from quantumclient.quantum.v2_0.router import AddInterfaceRouter +from quantumclient.quantum.v2_0.router import CreateRouter +from quantumclient.quantum.v2_0.router import DeleteRouter +from quantumclient.quantum.v2_0.router import ListRouter +from quantumclient.quantum.v2_0.router import RemoveGatewayRouter +from quantumclient.quantum.v2_0.router import RemoveInterfaceRouter +from quantumclient.quantum.v2_0.router import SetGatewayRouter +from quantumclient.quantum.v2_0.router import ShowRouter +from quantumclient.quantum.v2_0.router import UpdateRouter +from quantumclient.tests.unit.test_cli20 import CLITestV20Base +from quantumclient.tests.unit.test_cli20 import MyApp + + +class CLITestV20Router(CLITestV20Base): + def test_create_router(self): + """Create router: router1.""" + resource = 'router' + cmd = CreateRouter(MyApp(sys.stdout), None) + name = 'router1' + myid = 'myid' + args = [name, ] + position_names = ['name', ] + position_values = [name, ] + _str = self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values) + + def test_create_router_tenant(self): + """Create router: --tenant_id tenantid myname.""" + resource = 'router' + cmd = CreateRouter(MyApp(sys.stdout), None) + name = 'myname' + myid = 'myid' + args = ['--tenant_id', 'tenantid', name] + position_names = ['name', ] + position_values = [name, ] + _str = self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values, + tenant_id='tenantid') + + def test_create_router_admin_state(self): + """Create router: --admin_state_down myname.""" + resource = 'router' + cmd = CreateRouter(MyApp(sys.stdout), None) + name = 'myname' + myid = 'myid' + args = ['--admin_state_down', name, ] + position_names = ['name', ] + position_values = [name, ] + _str = self._test_create_resource(resource, cmd, name, myid, args, + position_names, position_values, + admin_state_up=False) + + def test_list_routers_detail(self): + """list routers: -D.""" + resources = "routers" + cmd = ListRouter(MyApp(sys.stdout), None) + self._test_list_resources(resources, cmd, True) + + def test_update_router_exception(self): + """Update router: myid.""" + resource = 'router' + cmd = UpdateRouter(MyApp(sys.stdout), None) + self.assertRaises(exceptions.CommandError, self._test_update_resource, + resource, cmd, 'myid', ['myid'], {}) + + def test_update_router(self): + """Update router: myid --name myname --tags a b.""" + resource = 'router' + cmd = UpdateRouter(MyApp(sys.stdout), None) + self._test_update_resource(resource, cmd, 'myid', + ['myid', '--name', 'myname'], + {'name': 'myname'} + ) + + def test_delete_router(self): + """Delete router: myid.""" + resource = 'router' + cmd = DeleteRouter(MyApp(sys.stdout), None) + myid = 'myid' + args = [myid] + self._test_delete_resource(resource, cmd, myid, args) + + def test_show_router(self): + """Show router: myid.""" + resource = 'router' + cmd = ShowRouter(MyApp(sys.stdout), None) + args = ['--fields', 'id', '--fields', 'name', self.test_id] + self._test_show_resource(resource, cmd, self.test_id, args, + ['id', 'name']) + + def test_add_interface(self): + """Add interface to router: myid subnetid""" + resource = 'router' + cmd = AddInterfaceRouter(MyApp(sys.stdout), None) + args = ['myid', 'subnetid'] + self._test_update_resource_action(resource, cmd, 'myid', + 'add_router_interface', + args, + {'subnet_id': 'subnetid'} + ) + + def test_del_interface(self): + """Delete interface from router: myid subnetid""" + resource = 'router' + cmd = RemoveInterfaceRouter(MyApp(sys.stdout), None) + args = ['myid', 'subnetid'] + self._test_update_resource_action(resource, cmd, 'myid', + 'remove_router_interface', + args, + {'subnet_id': 'subnetid'} + ) + + def test_set_gateway(self): + """Set external gateway for router: myid externalid""" + resource = 'router' + cmd = SetGatewayRouter(MyApp(sys.stdout), None) + args = ['myid', 'externalid'] + self._test_update_resource(resource, cmd, 'myid', + args, + {"external_gateway_info": + {"network_id": "externalid"}} + ) + + def test_remove_gateway(self): + """Remove external gateway from router: externalid""" + resource = 'router' + cmd = RemoveGatewayRouter(MyApp(sys.stdout), None) + args = ['externalid'] + self._test_update_resource(resource, cmd, 'externalid', + args, {"external_gateway_info": {}} + ) |
