diff options
| author | Tang Chen <tangchen@cn.fujitsu.com> | 2015-12-14 16:33:49 +0800 |
|---|---|---|
| committer | Tang Chen <tangchen@cn.fujitsu.com> | 2015-12-15 09:42:41 +0800 |
| commit | 6158ebb0e02ca2b796df973e71c6a7d5e829c959 (patch) | |
| tree | ea27dae63fa9d41ca1a46ae3b0394f9f00cf1cdf /openstackclient/tests/network | |
| parent | 1ee5191cec53df588d51a7cee31cfe9cf3a57a1b (diff) | |
| download | python-openstackclient-6158ebb0e02ca2b796df973e71c6a7d5e829c959.tar.gz | |
Router: Add "router create" command using SDK
This patch adds "router create" command to osc using sdk.
NOTE: Test for --project needs support for fake identity client v2 and v3.
These tests will be added in other patches.
NOTE: external_gateway_info and routes are not supported to be passed to
create command now. They will be supported in another tow patches.
NOTE: Creating a ha router is not supported for now. Will support it in
another patch.
Change-Id: I7642295d27c27dd498331ae1da1c293706d8f6af
Implements: blueprint neutron-client
Partial-bug: #1519503
Diffstat (limited to 'openstackclient/tests/network')
| -rw-r--r-- | openstackclient/tests/network/v2/fakes.py | 5 | ||||
| -rw-r--r-- | openstackclient/tests/network/v2/test_router.py | 62 |
2 files changed, 66 insertions, 1 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py index 284a40b7..b45c5412 100644 --- a/openstackclient/tests/network/v2/fakes.py +++ b/openstackclient/tests/network/v2/fakes.py @@ -174,7 +174,10 @@ class FakeRouter(object): router_attrs.update(attrs) # Set default methods. - router_methods = {} + router_methods = { + 'keys': ['id', 'name', 'admin_state_up', 'distributed', 'ha', + 'tenant_id'], + } # Overwrite default methods. router_methods.update(methods) diff --git a/openstackclient/tests/network/v2/test_router.py b/openstackclient/tests/network/v2/test_router.py index d91daceb..5170826c 100644 --- a/openstackclient/tests/network/v2/test_router.py +++ b/openstackclient/tests/network/v2/test_router.py @@ -15,6 +15,7 @@ import mock from openstackclient.network.v2 import router from openstackclient.tests.network.v2 import fakes as network_fakes +from openstackclient.tests import utils as tests_utils class TestRouter(network_fakes.TestNetworkV2): @@ -26,6 +27,67 @@ class TestRouter(network_fakes.TestNetworkV2): self.network = self.app.client_manager.network +class TestCreateRouter(TestRouter): + + # The new router created. + new_router = network_fakes.FakeRouter.create_one_router() + + columns = ( + 'admin_state_up', + 'distributed', + 'ha', + 'id', + 'name', + 'project_id', + ) + data = ( + router._format_admin_state(new_router.admin_state_up), + new_router.distributed, + new_router.ha, + new_router.id, + new_router.name, + new_router.tenant_id, + ) + + def setUp(self): + super(TestCreateRouter, self).setUp() + + self.network.create_router = mock.Mock(return_value=self.new_router) + + # Get the command object to test + self.cmd = router.CreateRouter(self.app, self.namespace) + + def test_create_no_options(self): + arglist = [] + verifylist = [] + + try: + self.check_parser(self.cmd, arglist, verifylist) + except tests_utils.ParserException: + pass + + def test_create_default_options(self): + arglist = [ + self.new_router.name, + ] + verifylist = [ + ('name', self.new_router.name), + ('admin_state_up', True), + ('distributed', False), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + columns, data = (self.cmd.take_action(parsed_args)) + + self.network.create_router.assert_called_with(**{ + 'admin_state_up': True, + 'name': self.new_router.name, + 'distributed': False, + }) + self.assertEqual(self.columns, columns) + self.assertEqual(self.data, data) + + class TestListRouter(TestRouter): # The routers going to be listed up. |
