diff options
| author | Ilya Shakhat <ishakhat@mirantis.com> | 2012-12-19 17:40:00 +0400 |
|---|---|---|
| committer | Ilya Shakhat <ishakhat@mirantis.com> | 2013-01-28 12:44:02 +0400 |
| commit | 2bca8ee4407aee03a83592395d3191f097c459a5 (patch) | |
| tree | ce09848de54bfb384145e756e1a885f818731c5f /quantumclient/tests | |
| parent | 9f1858d0f158487baa9022c08bbb2bc44a9a8ecc (diff) | |
| download | python-neutronclient-2bca8ee4407aee03a83592395d3191f097c459a5.tar.gz | |
The change implements LBaaS CLI commands.
Implements: blueprint lbaas-cli
New commands:
* Vip: lb-vip-create, lb-vip-list, lb-vip-show, lb-vip-update,
lb-vip-delete
* Pool: lb-pool-create, lb-pool-list, lb-pool-show, lb-pool-update,
lb-pool-delete, lb-pool-stats
* Member: lb-member-create, lb-member-list, lb-member-show,
lb-member-update, lb-member-delete
* Health Monitor: lb-healthmonitor-create, lb-healthmonitor-list,
lb-healthmonitor-show, lb-healthmonitor-update, lb-healthmonitor-delete,
lb-healthmonitor-associate, lb-healthmonitor-disassociate
Change-Id: Idaa569024c24955886a836e3dfedd009fed87007
Diffstat (limited to 'quantumclient/tests')
| -rw-r--r-- | quantumclient/tests/unit/lb/__init__.py | 16 | ||||
| -rw-r--r-- | quantumclient/tests/unit/lb/test_cli20_healthmonitor.py | 189 | ||||
| -rw-r--r-- | quantumclient/tests/unit/lb/test_cli20_member.py | 104 | ||||
| -rw-r--r-- | quantumclient/tests/unit/lb/test_cli20_pool.py | 145 | ||||
| -rw-r--r-- | quantumclient/tests/unit/lb/test_cli20_vip.py | 185 | ||||
| -rw-r--r-- | quantumclient/tests/unit/test_casual_args.py | 16 | ||||
| -rw-r--r-- | quantumclient/tests/unit/test_cli20.py | 5 |
7 files changed, 659 insertions, 1 deletions
diff --git a/quantumclient/tests/unit/lb/__init__.py b/quantumclient/tests/unit/lb/__init__.py new file mode 100644 index 0000000..1668497 --- /dev/null +++ b/quantumclient/tests/unit/lb/__init__.py @@ -0,0 +1,16 @@ +# Copyright 2013 OpenStack LLC. +# 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 diff --git a/quantumclient/tests/unit/lb/test_cli20_healthmonitor.py b/quantumclient/tests/unit/lb/test_cli20_healthmonitor.py new file mode 100644 index 0000000..657b24e --- /dev/null +++ b/quantumclient/tests/unit/lb/test_cli20_healthmonitor.py @@ -0,0 +1,189 @@ +# Copyright 2013 Mirantis 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. +# +# @author: Ilya Shakhat, Mirantis Inc. +# +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +import sys + +from mox import ContainsKeyValue + +from quantumclient.quantum.v2_0.lb import healthmonitor +from quantumclient.tests.unit import test_cli20 + + +class CLITestV20LbHealthmonitor(test_cli20.CLITestV20Base): + def test_create_healthmonitor_with_all_params(self): + """lb-healthmonitor-create with mandatory params only""" + resource = 'health_monitor' + cmd = healthmonitor.CreateHealthMonitor(test_cli20.MyApp(sys.stdout), + None) + delay = '60' + max_retries = '2' + timeout = '10' + type = 'tcp' + tenant_id = 'my-tenant' + my_id = 'my-id' + args = ['--admin-state-down', + '--delay', delay, + '--max-retries', max_retries, + '--timeout', timeout, + '--type', type, + '--tenant-id', tenant_id] + position_names = ['admin_state_up', 'delay', 'max_retries', 'timeout', + 'type', 'tenant_id'] + position_values = [True, delay, max_retries, timeout, type, + tenant_id] + self._test_create_resource(resource, cmd, '', my_id, args, + position_names, position_values) + + def test_create_healthmonitor_with_all_params(self): + """lb-healthmonitor-create with all params set""" + resource = 'health_monitor' + cmd = healthmonitor.CreateHealthMonitor(test_cli20.MyApp(sys.stdout), + None) + admin_state_up = False + delay = '60' + expected_codes = '200-202,204' + http_method = 'HEAD' + max_retries = '2' + timeout = '10' + type = 'tcp' + tenant_id = 'my-tenant' + url_path = '/health' + my_id = 'my-id' + args = ['--admin-state-down', + '--delay', delay, + '--expected-codes', expected_codes, + '--http-method', http_method, + '--max-retries', max_retries, + '--timeout', timeout, + '--type', type, + '--tenant-id', tenant_id, + '--url-path', url_path] + position_names = ['admin_state_up', 'delay', + 'expected_codes', 'http_method', + 'max_retries', 'timeout', + 'type', 'tenant_id', 'url_path'] + position_values = [admin_state_up, delay, + expected_codes, http_method, + max_retries, timeout, + type, tenant_id, url_path] + self._test_create_resource(resource, cmd, '', my_id, args, + position_names, position_values) + + def test_list_healthmonitors(self): + """lb-healthmonitor-list""" + resources = "health_monitors" + cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout), + None) + self._test_list_resources(resources, cmd, True) + + def test_show_healthmonitor_id(self): + """lb-healthmonitor-show test_id""" + resource = 'health_monitor' + cmd = healthmonitor.ShowHealthMonitor(test_cli20.MyApp(sys.stdout), + None) + args = ['--fields', 'id', self.test_id] + self._test_show_resource(resource, cmd, self.test_id, args, ['id']) + + def test_show_healthmonitor_id_name(self): + """lb-healthmonitor-show""" + resource = 'health_monitor' + cmd = healthmonitor.ShowHealthMonitor(test_cli20.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_update_health_monitor(self): + """lb-healthmonitor-update myid --name myname --tags a b.""" + resource = 'health_monitor' + cmd = healthmonitor.UpdateHealthMonitor(test_cli20.MyApp(sys.stdout), + None) + self._test_update_resource(resource, cmd, 'myid', + ['myid', '--timeout', '5'], + {'timeout': '5', }) + + def test_delete_healthmonitor(self): + """lb-healthmonitor-delete my-id""" + resource = 'health_monitor' + cmd = healthmonitor.DeleteHealthMonitor(test_cli20.MyApp(sys.stdout), + None) + my_id = 'my-id' + args = [my_id] + self._test_delete_resource(resource, cmd, my_id, args) + + def test_associate_healthmonitor(self): + cmd = healthmonitor.AssociateHealthMonitor( + test_cli20.MyApp(sys.stdout), + None) + resource = 'health_monitor' + health_monitor_id = 'hm-id' + pool_id = 'p_id' + args = [health_monitor_id, pool_id] + + self.mox.StubOutWithMock(cmd, "get_client") + self.mox.StubOutWithMock(self.client.httpclient, "request") + cmd.get_client().MultipleTimes().AndReturn(self.client) + + body = {resource: {'id': health_monitor_id}} + result = {resource: {'id': health_monitor_id}, } + result_str = self.client.serialize(result) + + path = getattr(self.client, + "associate_pool_health_monitors_path") % pool_id + return_tup = (test_cli20.MyResp(200), result_str) + self.client.httpclient.request( + test_cli20.end_url(path), 'POST', + body=test_cli20.MyComparator(body, self.client), + headers=ContainsKeyValue('X-Auth-Token', + test_cli20.TOKEN)).AndReturn(return_tup) + self.mox.ReplayAll() + cmd_parser = cmd.get_parser('test_' + resource) + parsed_args = cmd_parser.parse_args(args) + cmd.run(parsed_args) + self.mox.VerifyAll() + self.mox.UnsetStubs() + + def test_disassociate_healthmonitor(self): + cmd = healthmonitor.DisassociateHealthMonitor( + test_cli20.MyApp(sys.stdout), + None) + resource = 'health_monitor' + health_monitor_id = 'hm-id' + pool_id = 'p_id' + args = [health_monitor_id, pool_id] + + self.mox.StubOutWithMock(cmd, "get_client") + self.mox.StubOutWithMock(self.client.httpclient, "request") + cmd.get_client().MultipleTimes().AndReturn(self.client) + + path = getattr(self.client, + "disassociate_pool_health_monitors_path") % \ + {'pool': pool_id, 'health_monitor': health_monitor_id} + return_tup = (test_cli20.MyResp(204), None) + self.client.httpclient.request( + test_cli20.end_url(path), 'DELETE', + body=None, + headers=ContainsKeyValue('X-Auth-Token', + test_cli20.TOKEN)).AndReturn(return_tup) + self.mox.ReplayAll() + cmd_parser = cmd.get_parser('test_' + resource) + parsed_args = cmd_parser.parse_args(args) + cmd.run(parsed_args) + self.mox.VerifyAll() + self.mox.UnsetStubs() diff --git a/quantumclient/tests/unit/lb/test_cli20_member.py b/quantumclient/tests/unit/lb/test_cli20_member.py new file mode 100644 index 0000000..7155073 --- /dev/null +++ b/quantumclient/tests/unit/lb/test_cli20_member.py @@ -0,0 +1,104 @@ +# Copyright 2013 Mirantis 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. +# +# @author: Ilya Shakhat, Mirantis Inc. +# +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +import sys + +from quantumclient.quantum.v2_0.lb import member +from quantumclient.tests.unit import test_cli20 + + +class CLITestV20LbMember(test_cli20.CLITestV20Base): + def test_create_member(self): + """lb-member-create with mandatory params only""" + resource = 'member' + cmd = member.CreateMember(test_cli20.MyApp(sys.stdout), None) + address = '10.0.0.1' + port = '8080' + tenant_id = 'my-tenant' + my_id = 'my-id' + pool_id = 'pool-id' + args = ['--address', address, '--port', port, + '--tenant-id', tenant_id, pool_id] + position_names = ['address', 'port', 'tenant_id', 'pool_id', + 'admin_state_up'] + position_values = [address, port, tenant_id, pool_id, + True] + self._test_create_resource(resource, cmd, None, my_id, args, + position_names, position_values, + admin_state_up=None) + + def test_create_member_all_params(self): + """lb-member-create with all available params""" + resource = 'member' + cmd = member.CreateMember(test_cli20.MyApp(sys.stdout), None) + address = '10.0.0.1' + admin_state_up = False + port = '8080' + weight = '1' + tenant_id = 'my-tenant' + my_id = 'my-id' + pool_id = 'pool-id' + args = ['--address', address, '--admin-state-down', + '--port', port, '--weight', weight, + '--tenant-id', tenant_id, pool_id] + position_names = ['address', 'admin_state_up', 'port', 'weight', + 'tenant_id', 'pool_id'] + position_values = [address, admin_state_up, port, weight, + tenant_id, pool_id] + self._test_create_resource(resource, cmd, None, my_id, args, + position_names, position_values, + admin_state_up=None) + + def test_list_members(self): + """lb-member-list""" + resources = "members" + cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None) + self._test_list_resources(resources, cmd, True) + + def test_show_member_id(self): + """lb-member-show test_id""" + resource = 'member' + cmd = member.ShowMember(test_cli20.MyApp(sys.stdout), None) + args = ['--fields', 'id', self.test_id] + self._test_show_resource(resource, cmd, self.test_id, args, ['id']) + + def test_show_member_id_name(self): + """lb-member-show""" + resource = 'member' + cmd = member.ShowMember(test_cli20.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_update_member(self): + """lb-member-update myid --name myname --tags a b.""" + resource = 'member' + cmd = member.UpdateMember(test_cli20.MyApp(sys.stdout), None) + self._test_update_resource(resource, cmd, 'myid', + ['myid', '--name', 'myname', + '--tags', 'a', 'b'], + {'name': 'myname', 'tags': ['a', 'b'], }) + + def test_delete_member(self): + """lb-member-delete my-id""" + resource = 'member' + cmd = member.DeleteMember(test_cli20.MyApp(sys.stdout), None) + my_id = 'my-id' + args = [my_id] + self._test_delete_resource(resource, cmd, my_id, args) diff --git a/quantumclient/tests/unit/lb/test_cli20_pool.py b/quantumclient/tests/unit/lb/test_cli20_pool.py new file mode 100644 index 0000000..ee2f4e3 --- /dev/null +++ b/quantumclient/tests/unit/lb/test_cli20_pool.py @@ -0,0 +1,145 @@ +# Copyright 2013 Mirantis 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. +# +# @author: Ilya Shakhat, Mirantis Inc. +# +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +import sys + +from mox import ContainsKeyValue + +from quantumclient.quantum.v2_0.lb import pool +from quantumclient.tests.unit import test_cli20 + + +class CLITestV20LbPool(test_cli20.CLITestV20Base): + + def test_create_pool_with_mandatory_params(self): + """lb-pool-create with mandatory params only""" + resource = 'pool' + cmd = pool.CreatePool(test_cli20.MyApp(sys.stdout), None) + name = 'my-name' + lb_method = 'round-robin' + protocol = 'http' + subnet_id = 'subnet-id' + tenant_id = 'my-tenant' + my_id = 'my-id' + args = ['--lb-method', lb_method, + '--name', name, + '--protocol', protocol, + '--subnet-id', subnet_id, + '--tenant-id', tenant_id] + position_names = ['admin_state_up', 'lb_method', 'name', + 'protocol', 'subnet_id', 'tenant_id'] + position_values = [True, lb_method, name, + protocol, subnet_id, tenant_id] + self._test_create_resource(resource, cmd, name, my_id, args, + position_names, position_values) + + def test_create_pool_with_all_params(self): + """lb-pool-create with all params set""" + resource = 'pool' + cmd = pool.CreatePool(test_cli20.MyApp(sys.stdout), None) + name = 'my-name' + description = 'my-desc' + lb_method = 'round-robin' + protocol = 'http' + subnet_id = 'subnet-id' + tenant_id = 'my-tenant' + my_id = 'my-id' + args = ['--admin-state-down', + '--description', description, + '--lb-method', lb_method, + '--name', name, + '--protocol', protocol, + '--subnet-id', subnet_id, + '--tenant-id', tenant_id] + position_names = ['admin_state_up', 'description', 'lb_method', 'name', + 'protocol', 'subnet_id', 'tenant_id'] + position_values = [False, description, lb_method, name, + protocol, subnet_id, tenant_id] + self._test_create_resource(resource, cmd, name, my_id, args, + position_names, position_values) + + def test_list_pools(self): + """lb-pool-list""" + resources = "pools" + cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None) + self._test_list_resources(resources, cmd, True) + + def test_show_pool_id(self): + """lb-pool-show test_id""" + resource = 'pool' + cmd = pool.ShowPool(test_cli20.MyApp(sys.stdout), None) + args = ['--fields', 'id', self.test_id] + self._test_show_resource(resource, cmd, self.test_id, args, ['id']) + + def test_show_pool_id_name(self): + """lb-pool-show""" + resource = 'pool' + cmd = pool.ShowPool(test_cli20.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_update_pool(self): + """lb-pool-update myid --name newname --tags a b.""" + resource = 'pool' + cmd = pool.UpdatePool(test_cli20.MyApp(sys.stdout), None) + self._test_update_resource(resource, cmd, 'myid', + ['myid', '--name', 'newname'], + {'name': 'newname', }) + + def test_delete_pool(self): + """lb-pool-delete my-id""" + resource = 'pool' + cmd = pool.DeletePool(test_cli20.MyApp(sys.stdout), None) + my_id = 'my-id' + args = [my_id] + self._test_delete_resource(resource, cmd, my_id, args) + + def test_retrieve_pool_stats(self): + """lb-pool-stats test_id""" + resource = 'pool' + cmd = pool.RetrievePoolStats(test_cli20.MyApp(sys.stdout), None) + my_id = self.test_id + fields = ['bytes_in', 'bytes_out'] + args = ['--fields', 'bytes_in', '--fields', 'bytes_out', my_id] + + self.mox.StubOutWithMock(cmd, "get_client") + self.mox.StubOutWithMock(self.client.httpclient, "request") + cmd.get_client().MultipleTimes().AndReturn(self.client) + query = "&".join(["fields=%s" % field for field in fields]) + expected_res = {'stats': {'bytes_in': '1234', 'bytes_out': '4321'}} + resstr = self.client.serialize(expected_res) + path = getattr(self.client, "pool_path_stats") + return_tup = (test_cli20.MyResp(200), resstr) + self.client.httpclient.request( + test_cli20.end_url(path % my_id, query), 'GET', + body=None, + headers=ContainsKeyValue('X-Auth-Token', + test_cli20.TOKEN)).AndReturn(return_tup) + self.mox.ReplayAll() + + cmd_parser = cmd.get_parser("test_" + 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('bytes_in' in _str) + self.assertTrue('bytes_out' in _str) diff --git a/quantumclient/tests/unit/lb/test_cli20_vip.py b/quantumclient/tests/unit/lb/test_cli20_vip.py new file mode 100644 index 0000000..8b7d176 --- /dev/null +++ b/quantumclient/tests/unit/lb/test_cli20_vip.py @@ -0,0 +1,185 @@ +# Copyright 2013 Mirantis 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. +# +# @author: Ilya Shakhat, Mirantis Inc. +# +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +import sys + +from quantumclient.quantum.v2_0.lb import vip +from quantumclient.tests.unit import test_cli20 + + +class CLITestV20LbVip(test_cli20.CLITestV20Base): + def test_create_vip_with_mandatory_params(self): + """lb-vip-create with all mandatory params""" + resource = 'vip' + cmd = vip.CreateVip(test_cli20.MyApp(sys.stdout), None) + pool_id = 'my-pool-id' + name = 'my-name' + subnet_id = 'subnet-id' + port = '1000' + protocol = 'tcp' + tenant_id = 'my-tenant' + my_id = 'my-id' + args = ['--name', name, + '--port', port, + '--protocol', protocol, + '--subnet-id', subnet_id, + '--tenant-id', tenant_id, + pool_id] + position_names = ['pool_id', 'name', 'port', 'protocol', + 'subnet_id', 'tenant_id'] + position_values = [pool_id, name, port, protocol, + subnet_id, tenant_id] + self._test_create_resource(resource, cmd, name, my_id, args, + position_names, position_values, + admin_state_up=True) + + def test_create_vip_with_all_params(self): + """lb-vip-create with all params""" + resource = 'vip' + cmd = vip.CreateVip(test_cli20.MyApp(sys.stdout), None) + pool_id = 'my-pool-id' + name = 'my-name' + description = 'my-desc' + address = '10.0.0.2' + admin_state = False + connection_limit = '1000' + subnet_id = 'subnet-id' + port = '80' + protocol = 'tcp' + tenant_id = 'my-tenant' + my_id = 'my-id' + args = ['--name', name, + '--description', description, + '--address', address, + '--admin-state-down', + '--connection-limit', connection_limit, + '--port', port, + '--protocol', protocol, + '--subnet-id', subnet_id, + '--tenant-id', tenant_id, + pool_id] + position_names = ['pool_id', 'name', 'description', 'address', + 'admin_state_up', 'connection_limit', 'port', + 'protocol', 'subnet_id', + 'tenant_id'] + position_values = [pool_id, name, description, address, + admin_state, connection_limit, port, + protocol, subnet_id, + tenant_id] + self._test_create_resource(resource, cmd, name, my_id, args, + position_names, position_values) + + def test_create_vip_with_session_persistence_params(self): + """lb-vip-create with mandatory and session-persistence params""" + resource = 'vip' + cmd = vip.CreateVip(test_cli20.MyApp(sys.stdout), None) + pool_id = 'my-pool-id' + name = 'my-name' + subnet_id = 'subnet-id' + port = '1000' + protocol = 'tcp' + tenant_id = 'my-tenant' + my_id = 'my-id' + args = ['--name', name, + '--port', port, + '--protocol', protocol, + '--subnet-id', subnet_id, + '--tenant-id', tenant_id, + pool_id, + '--session-persistence', 'type=dict', + 'type=cookie,cookie_name=pie', + '--optional-param', 'any'] + position_names = ['pool_id', 'name', 'port', 'protocol', + 'subnet_id', 'tenant_id', 'optional_param'] + position_values = [pool_id, name, port, protocol, + subnet_id, tenant_id, 'any'] + extra_body = { + 'session_persistence': { + 'type': 'cookie', + 'cookie_name': 'pie', + }, + } + self._test_create_resource(resource, cmd, name, my_id, args, + position_names, position_values, + admin_state_up=True, extra_body=extra_body) + + def test_list_vips(self): + """lb-vip-list""" + resources = "vips" + cmd = vip.ListVip(test_cli20.MyApp(sys.stdout), None) + self._test_list_resources(resources, cmd, True) + + def test_show_vip_id(self): + """lb-vip-show test_id""" + resource = 'vip' + cmd = vip.ShowVip(test_cli20.MyApp(sys.stdout), None) + args = ['--fields', 'id', self.test_id] + self._test_show_resource(resource, cmd, self.test_id, args, ['id']) + + def test_show_vip_id_name(self): + """lb-vip-show""" + resource = 'vip' + cmd = vip.ShowVip(test_cli20.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_update_vip(self): + """lb-vip-update myid --name myname --tags a b.""" + resource = 'vip' + cmd = vip.UpdateVip(test_cli20.MyApp(sys.stdout), None) + self._test_update_resource(resource, cmd, 'myid', + ['myid', '--name', 'myname', + '--tags', 'a', 'b'], + {'name': 'myname', 'tags': ['a', 'b'], }) + + def test_update_vip_with_session_persistence(self): + resource = 'vip' + cmd = vip.UpdateVip(test_cli20.MyApp(sys.stdout), None) + body = { + 'session_persistence': { + 'type': 'source', + }, + } + args = ['myid', '--session-persistence', 'type=dict', + 'type=source'] + self._test_update_resource(resource, cmd, 'myid', args, body) + + def test_update_vip_with_session_persistence_and_name(self): + resource = 'vip' + cmd = vip.UpdateVip(test_cli20.MyApp(sys.stdout), None) + body = { + 'name': 'newname', + 'session_persistence': { + 'type': 'cookie', + 'cookie_name': 'pie', + }, + } + args = ['myid', '--name', 'newname', + '--session-persistence', 'type=dict', + 'type=cookie,cookie_name=pie'] + self._test_update_resource(resource, cmd, 'myid', args, body) + + def test_delete_vip(self): + """lb-vip-delete my-id""" + resource = 'vip' + cmd = vip.DeleteVip(test_cli20.MyApp(sys.stdout), None) + my_id = 'my-id' + args = [my_id] + self._test_delete_resource(resource, cmd, my_id, args) diff --git a/quantumclient/tests/unit/test_casual_args.py b/quantumclient/tests/unit/test_casual_args.py index c827e0e..150edec 100644 --- a/quantumclient/tests/unit/test_casual_args.py +++ b/quantumclient/tests/unit/test_casual_args.py @@ -53,6 +53,16 @@ class CLITestArgs(testtools.TestCase): self.assertRaises(exceptions.CommandError, quantumV20.parse_args_to_dict, _specs) + def test_badarg_duplicate(self): + _specs = ['--tag=t', '--arg1', 'value1', '--arg1', 'value1'] + self.assertRaises(exceptions.CommandError, + quantumV20.parse_args_to_dict, _specs) + + def test_badarg_early_type_specification(self): + _specs = ['type=dict', 'key=value'] + self.assertRaises(exceptions.CommandError, + quantumV20.parse_args_to_dict, _specs) + def test_arg(self): _specs = ['--tag=t', '--arg1', 'value1'] self.assertEqual('value1', @@ -64,6 +74,12 @@ class CLITestArgs(testtools.TestCase): self.assertEqual('value1', arg1['key1']) self.assertEqual('value2', arg1['key2']) + def test_dict_arg_with_attribute_named_type(self): + _specs = ['--tag=t', '--arg1', 'type=dict', 'type=value1,key2=value2'] + arg1 = quantumV20.parse_args_to_dict(_specs)['arg1'] + self.assertEqual('value1', arg1['type']) + self.assertEqual('value2', arg1['key2']) + def test_list_of_dict_arg(self): _specs = ['--tag=t', '--arg1', 'type=dict', 'list=true', 'key1=value1,key2=value2'] diff --git a/quantumclient/tests/unit/test_cli20.py b/quantumclient/tests/unit/test_cli20.py index 0c9e6a0..1a97eb1 100644 --- a/quantumclient/tests/unit/test_cli20.py +++ b/quantumclient/tests/unit/test_cli20.py @@ -135,7 +135,8 @@ class CLITestV20Base(testtools.TestCase): def _test_create_resource(self, resource, cmd, name, myid, args, position_names, position_values, tenant_id=None, - tags=None, admin_state_up=True, shared=False): + tags=None, admin_state_up=True, shared=False, + extra_body=None): self.mox.StubOutWithMock(cmd, "get_client") self.mox.StubOutWithMock(self.client.httpclient, "request") cmd.get_client().MultipleTimes().AndReturn(self.client) @@ -151,6 +152,8 @@ class CLITestV20Base(testtools.TestCase): body[resource].update({'tags': tags}) if shared: body[resource].update({'shared': shared}) + if extra_body: + body[resource].update(extra_body) for i in xrange(len(position_names)): body[resource].update({position_names[i]: position_values[i]}) |
