summaryrefslogtreecommitdiff
path: root/neutronclient/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'neutronclient/tests/unit')
-rw-r--r--neutronclient/tests/unit/bgp/__init__.py0
-rw-r--r--neutronclient/tests/unit/bgp/test_cli20_dragentscheduler.py66
-rw-r--r--neutronclient/tests/unit/bgp/test_cli20_peer.py224
-rw-r--r--neutronclient/tests/unit/bgp/test_cli20_speaker.py273
-rw-r--r--neutronclient/tests/unit/flavor/__init__.py0
-rw-r--r--neutronclient/tests/unit/flavor/test_cli20_flavor.py154
-rw-r--r--neutronclient/tests/unit/flavor/test_cli20_flavor_profile.py122
-rw-r--r--neutronclient/tests/unit/fw/__init__.py0
-rw-r--r--neutronclient/tests/unit/fw/test_cli20_firewall.py170
-rw-r--r--neutronclient/tests/unit/fw/test_cli20_firewallpolicy.py228
-rw-r--r--neutronclient/tests/unit/fw/test_cli20_firewallrule.py251
-rw-r--r--neutronclient/tests/unit/lb/__init__.py0
-rw-r--r--neutronclient/tests/unit/lb/test_cli20_healthmonitor.py202
-rw-r--r--neutronclient/tests/unit/lb/test_cli20_member.py118
-rw-r--r--neutronclient/tests/unit/lb/test_cli20_pool.py166
-rw-r--r--neutronclient/tests/unit/lb/test_cli20_vip.py206
-rw-r--r--neutronclient/tests/unit/lb/v2/__init__.py0
-rw-r--r--neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py175
-rw-r--r--neutronclient/tests/unit/lb/v2/test_cli20_l7policy.py260
-rw-r--r--neutronclient/tests/unit/lb/v2/test_cli20_l7rule.py210
-rw-r--r--neutronclient/tests/unit/lb/v2/test_cli20_listener.py194
-rw-r--r--neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py213
-rw-r--r--neutronclient/tests/unit/lb/v2/test_cli20_member.py171
-rw-r--r--neutronclient/tests/unit/lb/v2/test_cli20_pool.py202
-rw-r--r--neutronclient/tests/unit/qos/__init__.py0
-rw-r--r--neutronclient/tests/unit/qos/test_cli20_bandwidth_limit_rule.py137
-rw-r--r--neutronclient/tests/unit/qos/test_cli20_dscp_marking_rule.py91
-rw-r--r--neutronclient/tests/unit/qos/test_cli20_minimum_bandwidth_rule.py143
-rw-r--r--neutronclient/tests/unit/qos/test_cli20_policy.py192
-rw-r--r--neutronclient/tests/unit/qos/test_cli20_rule.py44
-rw-r--r--neutronclient/tests/unit/test_auto_allocated_topology.py76
-rw-r--r--neutronclient/tests/unit/test_cli20.py1215
-rw-r--r--neutronclient/tests/unit/test_cli20_address_scope.py175
-rw-r--r--neutronclient/tests/unit/test_cli20_agents.py97
-rw-r--r--neutronclient/tests/unit/test_cli20_agentschedulers.py209
-rw-r--r--neutronclient/tests/unit/test_cli20_az.py31
-rw-r--r--neutronclient/tests/unit/test_cli20_extensions.py45
-rw-r--r--neutronclient/tests/unit/test_cli20_floatingips.py193
-rw-r--r--neutronclient/tests/unit/test_cli20_metering.py99
-rw-r--r--neutronclient/tests/unit/test_cli20_network.py698
-rw-r--r--neutronclient/tests/unit/test_cli20_network_ip_availability.py54
-rw-r--r--neutronclient/tests/unit/test_cli20_port.py794
-rw-r--r--neutronclient/tests/unit/test_cli20_purge.py100
-rw-r--r--neutronclient/tests/unit/test_cli20_rbac.py134
-rw-r--r--neutronclient/tests/unit/test_cli20_router.py434
-rw-r--r--neutronclient/tests/unit/test_cli20_securitygroup.py657
-rw-r--r--neutronclient/tests/unit/test_cli20_servicetype.py55
-rw-r--r--neutronclient/tests/unit/test_cli20_subnet.py687
-rw-r--r--neutronclient/tests/unit/test_cli20_subnetpool.py208
-rw-r--r--neutronclient/tests/unit/test_cli20_tag.py131
-rw-r--r--neutronclient/tests/unit/test_client_extension.py221
-rw-r--r--neutronclient/tests/unit/test_name_or_id.py244
-rw-r--r--neutronclient/tests/unit/test_quota.py99
-rw-r--r--neutronclient/tests/unit/test_shell.py366
-rw-r--r--neutronclient/tests/unit/vpn/__init__.py0
-rw-r--r--neutronclient/tests/unit/vpn/test_cli20_endpoint_group.py145
-rw-r--r--neutronclient/tests/unit/vpn/test_cli20_ikepolicy.py241
-rw-r--r--neutronclient/tests/unit/vpn/test_cli20_ipsec_site_connection.py342
-rw-r--r--neutronclient/tests/unit/vpn/test_cli20_ipsecpolicy.py249
-rw-r--r--neutronclient/tests/unit/vpn/test_cli20_vpnservice.py157
-rw-r--r--neutronclient/tests/unit/vpn/test_utils.py130
61 files changed, 0 insertions, 12498 deletions
diff --git a/neutronclient/tests/unit/bgp/__init__.py b/neutronclient/tests/unit/bgp/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/neutronclient/tests/unit/bgp/__init__.py
+++ /dev/null
diff --git a/neutronclient/tests/unit/bgp/test_cli20_dragentscheduler.py b/neutronclient/tests/unit/bgp/test_cli20_dragentscheduler.py
deleted file mode 100644
index cbe85d9..0000000
--- a/neutronclient/tests/unit/bgp/test_cli20_dragentscheduler.py
+++ /dev/null
@@ -1,66 +0,0 @@
-# Copyright 2016 Huawei Technologies India Pvt. Ltd.
-# 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 neutronclient.neutron.v2_0.bgp import dragentscheduler as bgp_drsched
-from neutronclient.tests.unit import test_cli20
-from neutronclient.tests.unit import test_cli20_agentschedulers as test_as
-
-
-BGP_DRAGENT_ID = 'bgp_dragent_id1'
-BGP_SPEAKER = 'bgp_speaker_id1'
-
-
-class CLITestV20DRAgentScheduler(test_as.CLITestV20AgentScheduler):
-
- def test_add_bgp_speaker_to_dragent(self):
- resource = 'agent'
- cmd = bgp_drsched.AddBGPSpeakerToDRAgent(
- test_cli20.MyApp(sys.stdout), None)
- args = (BGP_DRAGENT_ID, BGP_SPEAKER)
- body = {'bgp_speaker_id': BGP_SPEAKER}
- result = {'bgp_speaker_id': 'bgp_speaker_id', }
- self._test_add_to_agent(resource, cmd, args,
- self.client.BGP_DRINSTANCES,
- body, result)
-
- def test_remove_bgp_speaker_from_dragent(self):
- resource = 'agent'
- cmd = bgp_drsched.RemoveBGPSpeakerFromDRAgent(
- test_cli20.MyApp(sys.stdout), None)
- args = (BGP_DRAGENT_ID, BGP_SPEAKER)
- self._test_remove_from_agent(resource, cmd, args,
- self.client.BGP_DRINSTANCES)
-
- def test_list_bgp_speakers_on_dragent(self):
- resources = 'bgp_speakers'
- cmd = bgp_drsched.ListBGPSpeakersOnDRAgent(
- test_cli20.MyApp(sys.stdout), None)
- path = ((self.client.agent_path + self.client.BGP_DRINSTANCES) %
- BGP_DRAGENT_ID)
- self._test_list_resources(resources, cmd, base_args=[BGP_DRAGENT_ID],
- path=path)
-
- def test_list_dragents_hosting_bgp_speaker(self):
- resources = 'agent'
- cmd = bgp_drsched.ListDRAgentsHostingBGPSpeaker(
- test_cli20.MyApp(sys.stdout), None)
- path = ((self.client.bgp_speaker_path + self.client.BGP_DRAGENTS) %
- BGP_DRAGENT_ID)
- contents = {self.id_field: 'myid1', 'alive': True}
- self._test_list_resources(resources, cmd, base_args=[BGP_DRAGENT_ID],
- path=path, response_contents=contents)
diff --git a/neutronclient/tests/unit/bgp/test_cli20_peer.py b/neutronclient/tests/unit/bgp/test_cli20_peer.py
deleted file mode 100644
index 998b0d5..0000000
--- a/neutronclient/tests/unit/bgp/test_cli20_peer.py
+++ /dev/null
@@ -1,224 +0,0 @@
-# Copyright 2016 Huawei Technologies India Pvt. Ltd.
-# 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 neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.bgp import peer as bgp_peer
-from neutronclient.neutron.v2_0.bgp import speaker as bgp_speaker
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20BGPPeerJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['bgp_peer']
-
- def test_create_bgp_peer_with_mandatory_params(self):
- # Create BGP peer with mandatory params.
- resource = 'bgp_peer'
- cmd = bgp_peer.CreatePeer(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- peerip = '1.1.1.1'
- remote_asnum = '1'
- args = [name,
- '--peer-ip', peerip,
- '--remote-as', remote_asnum, ]
- position_names = ['name', 'peer_ip', 'remote_as',
- 'auth_type']
- position_values = [name, peerip, remote_asnum, 'none']
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_bgp_peer_with_all_params(self):
- # Create BGP peer with all params.
- resource = 'bgp_peer'
- cmd = bgp_peer.CreatePeer(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- peerip = '1.1.1.1'
- remote_asnum = '65535'
- authType = 'md5'
- password = 'abc'
- args = [name,
- '--peer-ip', peerip,
- '--remote-as', remote_asnum,
- '--auth-type', authType,
- '--password', password]
- position_names = ['name', 'peer_ip', 'remote_as',
- 'auth_type', 'password']
- position_values = [name, peerip, remote_asnum, authType, password]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_bgp_peer_with_invalid_min_remote_asnum(self):
- # Create BGP peer with invalid minimum remote-asnum.
- resource = 'bgp_peer'
- cmd = bgp_peer.CreatePeer(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- peerip = '1.1.1.1'
- remote_asnum = '0'
- args = [name,
- '--peer-ip', peerip,
- '--remote-as', remote_asnum, ]
- position_names = ['name', 'peer_ip', 'remote_as', ]
- position_values = [name, peerip, remote_asnum, ]
- exc = self.assertRaises(exceptions.CommandError,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
- self.assertEqual('remote-as "0" should be an integer [%s:%s].' %
- (bgp_speaker.MIN_AS_NUM, bgp_speaker.MAX_AS_NUM),
- str(exc))
-
- def test_create_bgp_peer_with_invalid_max_remote_asnum(self):
- # Create BGP peer with invalid maximum remote-asnum.
- resource = 'bgp_peer'
- cmd = bgp_peer.CreatePeer(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- peerip = '1.1.1.1'
- remote_asnum = '4294967296'
- args = [name,
- '--peer-ip', peerip,
- '--remote-as', remote_asnum, ]
- position_names = ['name', 'peer_ip', 'remote_as',
- 'auth_type', 'password']
- position_values = [name, peerip, remote_asnum, 'none', '']
- exc = self.assertRaises(exceptions.CommandError,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
- self.assertEqual('remote-as "4294967296" should be an '
- 'integer [%s:%s].' %
- (bgp_speaker.MIN_AS_NUM, bgp_speaker.MAX_AS_NUM),
- str(exc))
-
- def test_create_authenticated_bgp_peer_without_authtype(self):
- # Create authenticated BGP peer without auth-type.
- resource = 'bgp_peer'
- cmd = bgp_peer.CreatePeer(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- peerip = '1.1.1.1'
- remote_asnum = '2048'
- password = 'abc'
- args = [name,
- '--peer-ip', peerip,
- '--remote-as', remote_asnum,
- '--password', password]
- position_names = ['name', 'peer_ip', 'remote_as', 'password']
- position_values = [name, peerip, remote_asnum, password]
- exc = self.assertRaises(exceptions.CommandError,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
- self.assertEqual('Must provide auth-type if password is specified.',
- str(exc))
-
- def test_create_authenticated_bgp_peer_without_password(self):
- # Create authenticated BGP peer without password.
- resource = 'bgp_peer'
- cmd = bgp_peer.CreatePeer(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- peerip = '1.1.1.1'
- remote_asnum = '2048'
- authType = 'md5'
- args = [name,
- '--peer-ip', peerip,
- '--remote-as', remote_asnum,
- '--auth-type', authType]
- position_names = ['name', 'peer_ip', 'remote_as', 'auth_type']
- position_values = [name, peerip, remote_asnum, authType]
- exc = self.assertRaises(exceptions.CommandError,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
- self.assertEqual('Must provide password if auth-type is specified.',
- str(exc))
-
- def test_update_bgp_peer(self):
- # Update BGP peer:
- # myid --advertise-tenant-networks True
- # --advertise-floating-ip-host-routes False
- resource = 'bgp_peer'
- cmd = bgp_peer.UpdatePeer(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'new-name',
- '--password', 'abc'],
- {'name': 'new-name', 'password': 'abc'})
-
- def test_update_bgp_peer_exception(self):
- # Update BGP peer: myid.
- resource = 'bgp_peer'
- cmd = bgp_peer.UpdatePeer(test_cli20.MyApp(sys.stdout),
- None)
- self.assertRaises(exceptions.CommandError,
- self._test_update_resource,
- resource, cmd, 'myid', ['myid'], {})
-
- def test_list_bgp_peer(self):
- # List all BGP peers.
- resources = "bgp_peers"
- cmd = bgp_peer.ListPeers(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True)
-
- # TODO(Vikram): Add test_list_bgp_peer_pagination
-
- def test_list_bgp_peer_sort(self):
- # sorted list: bgp-peer-list --sort-key name --sort-key id
- # --sort-key asc --sort-key desc
- resources = "bgp_peers"
- cmd = bgp_peer.ListPeers(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_bgp_peer_limit(self):
- # size (1000) limited list: bgp-peer-list -P.
- resources = "bgp_peers"
- cmd = bgp_peer.ListPeers(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_bgp_peer(self):
- # Show BGP peer: --fields id --fields name myid.
- resource = 'bgp_peer'
- cmd = bgp_peer.ShowPeer(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_delete_bgp_peer(self):
- # Delete BGP peer: bgp_peer_id.
- resource = 'bgp_peer'
- cmd = bgp_peer.DeletePeer(test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
diff --git a/neutronclient/tests/unit/bgp/test_cli20_speaker.py b/neutronclient/tests/unit/bgp/test_cli20_speaker.py
deleted file mode 100644
index 5621576..0000000
--- a/neutronclient/tests/unit/bgp/test_cli20_speaker.py
+++ /dev/null
@@ -1,273 +0,0 @@
-# Copyright 2016 Huawei Technologies India Pvt. Ltd.
-# 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 unittest import mock
-
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.bgp import speaker as bgp_speaker
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20BGPSpeakerJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['bgp_speaker']
-
- def test_create_bgp_speaker_with_minimal_options(self):
- # Create BGP Speaker with mandatory params.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.CreateSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- local_asnum = '1'
- args = [name, '--local-as', local_asnum, ]
- position_names = ['name', 'local_as', 'ip_version']
- position_values = [name, local_asnum, 4]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_ipv4_bgp_speaker_with_all_params(self):
- # Create BGP Speaker with all params.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.CreateSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- local_asnum = '1'
- args = [name,
- '--local-as', local_asnum,
- '--ip-version', '4',
- '--advertise-floating-ip-host-routes', 'True',
- '--advertise-tenant-networks', 'True']
- position_names = ['name', 'local_as', 'ip_version',
- 'advertise_floating_ip_host_routes',
- 'advertise_tenant_networks']
- position_values = [name, local_asnum, 4, 'True', 'True']
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_ipv6_bgp_speaker_with_all_params(self):
- # Create BGP Speaker with all params.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.CreateSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- local_asnum = '65535'
- args = [name,
- '--local-as', local_asnum,
- '--ip-version', '6',
- '--advertise-floating-ip-host-routes', 'True',
- '--advertise-tenant-networks', 'True']
- position_names = ['name', 'local_as', 'ip_version',
- 'advertise_floating_ip_host_routes',
- 'advertise_tenant_networks']
- position_values = [name, local_asnum, 6, 'True', 'True']
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_bgp_speaker_with_invalid_min_local_asnum(self):
- # Create BGP Speaker with invalid minimum local-asnum.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.CreateSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- local_asnum = '0'
- args = [name,
- '--local-as', local_asnum]
- position_names = ['name', 'local_as']
- position_values = [name, local_asnum]
- exc = self.assertRaises(exceptions.CommandError,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
- self.assertEqual('local-as "0" should be an integer [%s:%s].' %
- (bgp_speaker.MIN_AS_NUM, bgp_speaker.MAX_AS_NUM),
- str(exc))
-
- def test_create_bgp_speaker_with_invalid_max_local_asnum(self):
- # Create BGP Speaker with invalid maximum local-asnum.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.CreateSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- my_id = 'my-id'
- local_asnum = '4294967296'
- args = [name,
- '--local-as', local_asnum]
- position_names = ['name', 'local_as', ]
- position_values = [name, local_asnum, ]
- exc = self.assertRaises(exceptions.CommandError,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
- self.assertEqual('local-as "4294967296" should be an '
- 'integer [%s:%s].' %
- (bgp_speaker.MIN_AS_NUM, bgp_speaker.MAX_AS_NUM),
- str(exc))
-
- def test_update_bgp_speaker(self):
- # Update BGP Speaker:
- # myid --advertise-tenant-networks True
- # --advertise-floating-ip-host-routes False
- resource = 'bgp_speaker'
- cmd = bgp_speaker.UpdateSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid',
- '--name', 'new-name',
- '--advertise-tenant-networks', 'True',
- '--advertise-floating-ip-host-routes',
- 'False'],
- {'name': 'new-name',
- 'advertise_tenant_networks': 'True',
- 'advertise_floating_ip_host_routes':
- 'False'})
-
- def test_update_bgp_speaker_exception(self):
- # Update BGP Speaker: myid.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.UpdateSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- self.assertRaises(exceptions.CommandError,
- self._test_update_resource,
- resource, cmd, 'myid', ['myid'], {})
-
- def test_list_bgp_speaker(self):
- # List all BGP Speakers.
- resources = "bgp_speakers"
- cmd = bgp_speaker.ListSpeakers(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True)
-
- @mock.patch.object(bgp_speaker.ListSpeakers, "extend_list")
- def test_list_bgp_speaker_pagination(self, mock_extend_list):
- # List all BGP Speakers with pagination support.
- cmd = bgp_speaker.ListSpeakers(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination("bgp_speakers",
- cmd)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_list_bgp_speaker_sort(self):
- # sorted list: bgp-speaker-list --sort-key name --sort-key id
- # --sort-key asc --sort-key desc
- resources = "bgp_speakers"
- cmd = bgp_speaker.ListSpeakers(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_bgp_speaker_limit(self):
- # size (1000) limited list: bgp-speaker-list -P.
- resources = "bgp_speakers"
- cmd = bgp_speaker.ListSpeakers(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_bgp_speaker(self):
- # Show BGP Speaker: --fields id --fields name myid.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.ShowSpeaker(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_delete_bgp_speaker(self):
- # Delete BGP Speaker: bgp_speaker_id.
- resource = 'bgp_speaker'
- cmd = bgp_speaker.DeleteSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
-
- def _test_add_remove_peer(self, action, cmd, args):
- """Add or Remove BGP Peer to/from a BGP Speaker."""
- resource = 'bgp_speaker'
- subcmd = '%s_bgp_peer' % action
- body = {'bgp_peer_id': 'peerid'}
- if action == 'add':
- retval = {'bgp_peer': 'peerid'}
- retval = self.client.serialize(retval)
- expected_code = 200
- else:
- retval = None
- expected_code = 204
- self._test_update_resource_action(resource, cmd, 'myid',
- subcmd, args, body, expected_code,
- retval)
-
- def test_add_peer_to_bgp_speaker(self):
- # Add peer to BGP speaker: myid peer_id=peerid
- cmd = bgp_speaker.AddPeerToSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- args = ['myid', 'peerid']
- self._test_add_remove_peer('add', cmd, args)
-
- def test_remove_peer_from_bgp_speaker(self):
- # Remove peer from BGP speaker: myid peer_id=peerid
- cmd = bgp_speaker.RemovePeerFromSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- args = ['myid', 'peerid']
- self._test_add_remove_peer('remove', cmd, args)
-
- def _test_add_remove_network(self, action, cmd, args):
- # Add or Remove network to/from a BGP Speaker.
- resource = 'bgp_speaker'
- subcmd = '%s_gateway_network' % action
- body = {'network_id': 'netid'}
- if action == 'add':
- retval = {'network': 'netid'}
- retval = self.client.serialize(retval)
- expected_code = 200
- else:
- retval = None
- expected_code = 204
- self._test_update_resource_action(resource, cmd, 'myid',
- subcmd, args, body, expected_code,
- retval)
-
- def test_add_network_to_bgp_speaker(self):
- # Add peer to BGP speaker: myid network_id=netid
- cmd = bgp_speaker.AddNetworkToSpeaker(test_cli20.MyApp(sys.stdout),
- None)
- args = ['myid', 'netid']
- self._test_add_remove_network('add', cmd, args)
-
- def test_remove_network_from_bgp_speaker(self):
- # Remove network from BGP speaker: myid network_id=netid
- cmd = bgp_speaker.RemoveNetworkFromSpeaker(
- test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'netid']
- self._test_add_remove_network('remove', cmd, args)
-
- def test_list_routes_advertised_by_a_bgp_speaker(self):
- # Retrieve advertised route list
- resources = 'advertised_routes'
- cmd = bgp_speaker.ListRoutesAdvertisedBySpeaker(
- test_cli20.MyApp(sys.stdout), None)
- bs_id = 'bgp_speaker_id1'
- path = ((self.client.bgp_speaker_path + '/get_advertised_routes') %
- bs_id)
- self._test_list_resources(resources, cmd, base_args=[bs_id],
- path=path)
diff --git a/neutronclient/tests/unit/flavor/__init__.py b/neutronclient/tests/unit/flavor/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/neutronclient/tests/unit/flavor/__init__.py
+++ /dev/null
diff --git a/neutronclient/tests/unit/flavor/test_cli20_flavor.py b/neutronclient/tests/unit/flavor/test_cli20_flavor.py
deleted file mode 100644
index 22bd8bb..0000000
--- a/neutronclient/tests/unit/flavor/test_cli20_flavor.py
+++ /dev/null
@@ -1,154 +0,0 @@
-# Copyright 2015 Hewlett-Packard Development Company, L.P.
-# 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 neutronclient.neutron.v2_0.flavor import flavor
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20FlavorJSON(test_cli20.CLITestV20Base):
-
- def setUp(self):
- """Prepare test environment."""
- super(CLITestV20FlavorJSON, self).setUp(plurals={'flavors': 'flavor'})
- self.register_non_admin_status_resource('flavor')
- self.register_non_admin_status_resource('service_profile')
-
- def test_create_flavor_with_missing_params(self):
- """Create test flavor with missing parameters."""
- resource = 'flavor'
- cmd = flavor.CreateFlavor(
- test_cli20.MyApp(sys.stdout), None)
- name = 'Test flavor'
- myid = 'myid'
- position_names = []
- position_values = []
- args = []
- self.assertRaises(
- SystemExit, self._test_create_resource,
- resource, cmd, name, myid, args, position_names, position_values)
-
- def test_create_flavor_with_mandatory_params(self):
- """Create test flavor with minimal parameters."""
- resource = 'flavor'
- cmd = flavor.CreateFlavor(
- test_cli20.MyApp(sys.stdout), None)
- name = 'Test flavor'
- myid = 'myid'
- service_type = 'DUMMY'
- # Defaults are returned in body
- position_names = ['name', 'service_type']
- position_values = [name, service_type]
- args = [name, service_type]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_flavor_with_optional_params(self):
- """Create test flavor including optional parameters."""
- resource = 'flavor'
- cmd = flavor.CreateFlavor(
- test_cli20.MyApp(sys.stdout), None)
- name = 'Test flavor'
- myid = 'myid'
- service_type = 'DUMMY'
- description = 'Test description'
- position_names = ['name', 'service_type', 'description', 'enabled']
- position_values = [name, service_type, description, 'False']
- args = [name, service_type,
- '--description', description,
- '--enabled=False']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_delete_flavor(self):
- """Delete flavor."""
- resource = 'flavor'
- cmd = flavor.DeleteFlavor(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args)
-
- def test_list_flavors(self):
- """List flavors test."""
- resources = 'flavors'
- cmd = flavor.ListFlavor(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_flavors_with_pagination(self):
- """List flavors test with pagination."""
- resources = 'flavors'
- cmd = flavor.ListFlavor(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_flavors_with_sort(self):
- """List flavors test with sorting by name and id."""
- resources = 'flavors'
- cmd = flavor.ListFlavor(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_show_flavor(self):
- """Show flavor test."""
- resource = 'flavor'
- cmd = flavor.ShowFlavor(
- 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_update_flavor_with_name(self):
- """Update flavor test."""
- resource = 'flavor'
- cmd = flavor.UpdateFlavor(
- test_cli20.MyApp(sys.stdout), None)
- newname = 'Test New Name'
- newdescription = 'New Description'
- args = ['--name', newname,
- '--description', newdescription,
- '--enabled', 'False', self.test_id]
- self._test_update_resource(resource, cmd, self.test_id, args,
- {'name': newname,
- 'description': newdescription,
- 'enabled': 'False'})
-
- def test_associate_flavor(self):
- """Associate flavor test."""
- resource = 'service_profile'
- cmd = flavor.AssociateFlavor(test_cli20.MyApp(sys.stdout), None)
- flavor_id = 'flavor-id'
- profile_id = 'profile-id'
- name = ''
- args = [flavor_id, profile_id]
- position_names = ['id']
- position_values = [profile_id]
- self._test_create_resource(resource, cmd, name, profile_id, args,
- position_names, position_values,
- cmd_resource='flavor_profile_binding',
- parent_id=flavor_id)
-
- def test_disassociate_flavor(self):
- """Disassociate flavor test."""
- resource = 'flavor_profile_binding'
- cmd = flavor.DisassociateFlavor(test_cli20.MyApp(sys.stdout), None)
- flavor_id = 'flavor-id'
- profile_id = 'profile-id'
- args = [flavor_id, profile_id]
- self._test_delete_resource(resource, cmd, profile_id, args,
- parent_id=flavor_id)
diff --git a/neutronclient/tests/unit/flavor/test_cli20_flavor_profile.py b/neutronclient/tests/unit/flavor/test_cli20_flavor_profile.py
deleted file mode 100644
index d130902..0000000
--- a/neutronclient/tests/unit/flavor/test_cli20_flavor_profile.py
+++ /dev/null
@@ -1,122 +0,0 @@
-# Copyright 2015 Hewlett-Packard Development Company, L.P.
-# 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 neutronclient.neutron.v2_0.flavor import flavor_profile
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20FlavorProfileJSON(test_cli20.CLITestV20Base):
-
- def setUp(self):
- """Prepare test environment."""
- super(CLITestV20FlavorProfileJSON, self).setUp(
- plurals={'service_profiles': 'service_profile'})
- self.register_non_admin_status_resource('service_profile')
-
- def test_create_flavor_profile_with_mandatory_params(self):
- """Create test flavor profile test."""
- resource = 'service_profile'
- cmd = flavor_profile.CreateFlavorProfile(
- test_cli20.MyApp(sys.stdout), None)
- name = ''
- description = 'Test flavor profile'
- myid = 'myid'
- metainfo = "{'a':'b'}"
- # Defaults are returned in body
- position_names = ['description', 'metainfo']
- position_values = [description, metainfo]
- args = ['--description', description, '--metainfo', metainfo]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_flavor_profile_with_optional_params(self):
- """Create test flavor profile disabled test."""
- resource = 'service_profile'
- cmd = flavor_profile.CreateFlavorProfile(
- test_cli20.MyApp(sys.stdout), None)
- name = ''
- description = 'Test flavor profile - disabled'
- myid = 'myid'
- driver = 'mydriver'
- metainfo = "{'a':'b'}"
- position_names = ['description', 'driver', 'metainfo', 'enabled']
- position_values = [description, driver, metainfo, 'False']
- args = ['--description', description, '--driver', driver,
- '--metainfo', metainfo, '--enabled=False']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_list_flavor_profiles(self):
- """List flavor profiles test."""
- resources = 'service_profiles'
- cmd = flavor_profile.ListFlavorProfile(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_flavor_profiles_with_pagination(self):
- """List flavor profiles test with pagination."""
- resources = 'service_profiles'
- cmd = flavor_profile.ListFlavorProfile(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_flavor_profiles_with_sort(self):
- """List flavor profiles test with sort by description."""
- resources = 'service_profiles'
- cmd = flavor_profile.ListFlavorProfile(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["description"],
- sort_dir=["asc"])
-
- def test_show_flavor_profile(self):
- """Show flavor profile test."""
- resource = 'service_profile'
- cmd = flavor_profile.ShowFlavorProfile(
- 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_update_flavor_profile(self):
- """Update flavor profile test."""
- resource = 'service_profile'
- cmd = flavor_profile.UpdateFlavorProfile(
- test_cli20.MyApp(sys.stdout), None)
- newdescription = 'Test new description'
- newdriver = 'NewDriver'
- newmetainfo = "{'c':'d'}"
- newenabled = "False"
- args = ['--description', newdescription,
- '--driver', newdriver,
- '--metainfo', newmetainfo,
- '--enabled', newenabled,
- self.test_id]
- self._test_update_resource(resource, cmd, self.test_id, args,
- {'description': newdescription,
- 'driver': newdriver,
- 'metainfo': newmetainfo,
- 'enabled': newenabled})
-
- def test_delete_flavor_profile(self):
- """Delete flavor profile."""
- resource = 'service_profile'
- cmd = flavor_profile.DeleteFlavorProfile(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/neutronclient/tests/unit/fw/__init__.py b/neutronclient/tests/unit/fw/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/neutronclient/tests/unit/fw/__init__.py
+++ /dev/null
diff --git a/neutronclient/tests/unit/fw/test_cli20_firewall.py b/neutronclient/tests/unit/fw/test_cli20_firewall.py
deleted file mode 100644
index f9a2dee..0000000
--- a/neutronclient/tests/unit/fw/test_cli20_firewall.py
+++ /dev/null
@@ -1,170 +0,0 @@
-# Copyright 2013 Big Switch Networks 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0.fw import firewall
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20FirewallJSON(test_cli20.CLITestV20Base):
-
- def test_create_firewall_with_mandatory_params(self):
- # firewall-create with mandatory (none) params.
- resource = 'firewall'
- cmd = firewall.CreateFirewall(test_cli20.MyApp(sys.stdout), None)
- name = ''
- tenant_id = 'my-tenant'
- my_id = 'my-id'
- policy_id = 'my-policy-id'
- args = ['--tenant-id', tenant_id, policy_id, ]
- position_names = ['firewall_policy_id', ]
- position_values = [policy_id, ]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- admin_state_up=True, tenant_id=tenant_id)
-
- def test_create_firewall_with_all_params(self):
- # firewall-create with all params set.
- resource = 'firewall'
- cmd = firewall.CreateFirewall(test_cli20.MyApp(sys.stdout), None)
- name = 'my-name'
- description = 'my-desc'
- policy_id = 'my-policy-id'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
- args = ['--description', description,
- '--admin-state-down',
- '--tenant-id', tenant_id,
- policy_id]
- position_names = ['firewall_policy_id', ]
- position_values = [policy_id, ]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- description=description,
- admin_state_up=False,
- tenant_id=tenant_id)
-
- def test_create_firewall_with_routers(self):
- resource = 'firewall'
- cmd = firewall.CreateFirewall(test_cli20.MyApp(sys.stdout), None)
- name = 'my-name'
- policy_id = 'my-policy-id'
- my_id = 'my-id'
- args = ['--router', 'fake-id', '--router', 'fake-name', policy_id]
- router_ids = ['fake-id', 'fake-name']
- position_names = ['firewall_policy_id', 'router_ids']
- position_values = [policy_id, router_ids]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_list_firewalls(self):
- # firewall-list.
- resources = "firewalls"
- cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_firewalls_pagination(self):
- # firewall-list with pagination.
- resources = "firewalls"
- cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_firewalls_sort(self):
- # sorted list: firewall-list --sort-key name --sort-key id
- # --sort-key asc --sort-key desc
- resources = "firewalls"
- cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_firewalls_limit(self):
- # size (1000) limited list: firewall-list -P.
- resources = "firewalls"
- cmd = firewall.ListFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_firewall_id(self):
- # firewall-show test_id.
- resource = 'firewall'
- cmd = firewall.ShowFirewall(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_firewall_id_name(self):
- # firewall-show.
- resource = 'firewall'
- cmd = firewall.ShowFirewall(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_firewall(self):
- # firewall-update myid --name newname --tags a b.
- resource = 'firewall'
- cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname'],
- {'name': 'newname', })
-
- def test_update_firewall_using_policy_name(self):
- # firewall-update myid --policy newpolicy.
- resource = 'firewall'
- cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--policy', 'newpolicy'],
- {'firewall_policy_id': 'newpolicy'})
-
- def test_update_firewall_with_routers(self):
- resource = 'firewall'
- cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(
- resource, cmd, 'myid',
- ['myid', '--router', 'fake-id', '--router', 'fake-name'],
- {'router_ids': ['fake-id', 'fake-name']})
-
- def test_update_firewall_with_no_routers(self):
- resource = 'firewall'
- cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(
- resource, cmd, 'myid',
- ['myid', '--no-routers'], {'router_ids': []})
-
- def test_update_firewall_with_bad_router_options(self):
- resource = 'firewall'
- cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
- self.assertRaises(
- SystemExit,
- self._test_update_resource,
- resource, cmd, 'myid',
- ['myid', '--no-routers', '--router', 'fake-id'], {})
-
- def test_delete_firewall(self):
- # firewall-delete my-id.
- resource = 'firewall'
- cmd = firewall.DeleteFirewall(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args)
-
- def test_update_firewall_admin_state(self):
- # firewall-update myid --admin-state-up True.
- resource = 'firewall'
- cmd = firewall.UpdateFirewall(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--admin-state-up', 'True'],
- {'admin_state_up': 'True'})
diff --git a/neutronclient/tests/unit/fw/test_cli20_firewallpolicy.py b/neutronclient/tests/unit/fw/test_cli20_firewallpolicy.py
deleted file mode 100644
index 4cadfb2..0000000
--- a/neutronclient/tests/unit/fw/test_cli20_firewallpolicy.py
+++ /dev/null
@@ -1,228 +0,0 @@
-# Copyright 2013 Big Switch Networks 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.
-#
-
-import sys
-from unittest import mock
-
-
-from neutronclient.neutron.v2_0.fw import firewallpolicy
-from neutronclient import shell
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20FirewallPolicyJSON(test_cli20.CLITestV20Base):
- def setUp(self):
- super(CLITestV20FirewallPolicyJSON, self).setUp()
-
- def test_create_firewall_policy_with_mandatory_params(self):
- # firewall-policy-create with mandatory (none) params only.
- resource = 'firewall_policy'
- cmd = firewallpolicy.CreateFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- tenant_id = 'my-tenant'
- name = 'my-name'
- my_id = 'myid'
- args = ['--tenant-id', tenant_id,
- '--admin-state_up',
- name, ]
- position_names = ['name', ]
- position_values = [name, ]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- admin_state_up=True, tenant_id=tenant_id)
-
- def test_create_firewall_policy_with_all_params(self):
- # firewall-policy-create with rule param of misc format.
- resource = 'firewall_policy'
- cmd = firewallpolicy.CreateFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- description = 'my-desc'
- firewall_rules_res = ['rule_id1', 'rule_id2']
- tenant_id = 'my-tenant'
- my_id = 'myid'
- position_names = ['name', ]
- position_values = [name, ]
-
- # check for both str and unicode format firewall_rules_arg
- for firewall_rules_arg in ['rule_id1 rule_id2', u'rule_id1 rule_id2']:
- args = ['--description', description,
- '--shared',
- '--firewall-rules', firewall_rules_arg,
- '--audited',
- '--tenant-id', tenant_id,
- '--admin-state_up',
- name]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- description=description, shared=True,
- firewall_rules=firewall_rules_res,
- audited=True, admin_state_up=True,
- tenant_id=tenant_id)
-
- def test_list_firewall_policies(self):
- # firewall-policy-list.
- resources = "firewall_policies"
- cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_firewall_policies_pagination(self):
- # firewall-policy-list."""
- resources = "firewall_policies"
- cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_firewall_policies_sort(self):
- # sorted list: firewall-policy-list --sort-key name --sort-key id
- # --sort-key asc --sort-key desc
- resources = "firewall_policies"
- cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_firewall_policies_limit(self):
- # size (1000) limited list: firewall-policy-list -P.
- resources = "firewall_policies"
- cmd = firewallpolicy.ListFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_firewall_policy_id(self):
- # firewall-policy-show test_id.
- resource = 'firewall_policy'
- cmd = firewallpolicy.ShowFirewallPolicy(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_firewall_policy_id_name(self):
- # firewall-policy-show.
- resource = 'firewall_policy'
- cmd = firewallpolicy.ShowFirewallPolicy(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_firewall_policy(self):
- # firewall-policy-update myid --name newname.
- resource = 'firewall_policy'
- cmd = firewallpolicy.UpdateFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname'],
- {'name': 'newname', })
-
- def test_update_firewall_policy_with_rules(self):
- # firewall-policy-update myid --firewall-rules "rule1 rule2".
- resource = 'firewall_policy'
- cmd = firewallpolicy.UpdateFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- firewall_rules_arg = u'rule_id3 rule_id4'
- firewall_rules_res = ['rule_id3', 'rule_id4']
- self._test_update_resource(
- resource, cmd, 'myid',
- ['myid', '--firewall-rules', firewall_rules_arg],
- {'firewall_rules': firewall_rules_res, })
-
- def test_delete_firewall_policy(self):
- # firewall-policy-delete my-id.
- resource = 'firewall_policy'
- cmd = firewallpolicy.DeleteFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'myid1'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args)
-
- def test_insert_firewall_rule(self):
- # firewall-policy-insert-rule myid newruleid --insert-before ruleAid
- # --insert-after ruleBid
- resource = 'firewall_policy'
- cmd = firewallpolicy.FirewallPolicyInsertRule(
- test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- args = ['myid', 'newrule',
- '--insert-before', 'rule2',
- '--insert-after', 'rule1']
- extrafields = {'firewall_rule_id': 'newrule',
- 'insert_before': 'rule2',
- 'insert_after': 'rule1'}
-
- body = extrafields
- path = getattr(self.client, resource + "_insert_path")
- cmd_parser = cmd.get_parser(resource + "_insert_rule")
- resp = (test_cli20.MyResp(204), None)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- shell.run_command(cmd, cmd_parser, args)
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), 4)
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path % myid),
- self.client),
- 'PUT', body=test_cli20.MyComparator(body, self.client),
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- def test_remove_firewall_rule(self):
- # firewall-policy-remove-rule myid ruleid
- resource = 'firewall_policy'
- cmd = firewallpolicy.FirewallPolicyRemoveRule(
- test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- args = ['myid', 'removerule']
- extrafields = {'firewall_rule_id': 'removerule', }
-
- body = extrafields
- path = getattr(self.client, resource + "_remove_path")
- cmd_parser = cmd.get_parser(resource + "_remove_rule")
- resp = (test_cli20.MyResp(204), None)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- shell.run_command(cmd, cmd_parser, args)
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), 2)
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path % myid),
- self.client),
- 'PUT', body=test_cli20.MyComparator(body, self.client),
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- def test_update_firewall_policy_name_shared_audited(self):
- # firewall-policy-update myid --name newname2 --shared --audited
- resource = 'firewall_policy'
- cmd = firewallpolicy.UpdateFirewallPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname2',
- '--shared', 'True', '--audited', 'True'],
- {'name': 'newname2',
- 'shared': 'True', 'audited': 'True'})
diff --git a/neutronclient/tests/unit/fw/test_cli20_firewallrule.py b/neutronclient/tests/unit/fw/test_cli20_firewallrule.py
deleted file mode 100644
index 50fabca..0000000
--- a/neutronclient/tests/unit/fw/test_cli20_firewallrule.py
+++ /dev/null
@@ -1,251 +0,0 @@
-# Copyright 2013 Big Switch Networks 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0.fw import firewallrule
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20FirewallRuleJSON(test_cli20.CLITestV20Base):
-
- def _test_create_firewall_rule_with_mandatory_params(self, enabled):
- # firewall-rule-create with mandatory (none) params only.
- resource = 'firewall_rule'
- cmd = firewallrule.CreateFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- tenant_id = 'my-tenant'
- name = ''
- my_id = 'myid'
- protocol = 'tcp'
- action = 'allow'
- ip_version = 4
- args = ['--tenant-id', tenant_id,
- '--admin-state-up',
- '--protocol', protocol,
- '--action', action,
- '--enabled', enabled]
- position_names = []
- position_values = []
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- protocol=protocol, action=action,
- enabled=enabled, tenant_id=tenant_id,
- ip_version=ip_version)
-
- def test_create_enabled_firewall_rule_with_mandatory_params_lcase(self):
- self._test_create_firewall_rule_with_mandatory_params(enabled='true')
-
- def test_create_disabled_firewall_rule_with_mandatory_params_lcase(self):
- self._test_create_firewall_rule_with_mandatory_params(enabled='false')
-
- def test_create_enabled_firewall_rule_with_mandatory_params(self):
- self._test_create_firewall_rule_with_mandatory_params(enabled='True')
-
- def test_create_disabled_firewall_rule_with_mandatory_params(self):
- self._test_create_firewall_rule_with_mandatory_params(enabled='False')
-
- def _setup_create_firewall_rule_with_all_params(
- self, protocol='tcp', protocol_cli=None,
- action='allow', action_cli=None, ip_version='4'):
- # firewall-rule-create with all params set.
- resource = 'firewall_rule'
- cmd = firewallrule.CreateFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- name = 'my-name'
- description = 'my-desc'
- source_ip = '192.168.1.0/24'
- destination_ip = '192.168.2.0/24'
- source_port = '0:65535'
- destination_port = '0:65535'
- tenant_id = 'my-tenant'
- my_id = 'myid'
- enabled = 'True'
- args = ['--description', description,
- '--shared',
- '--protocol', protocol_cli or protocol,
- '--ip-version', ip_version,
- '--source-ip-address', source_ip,
- '--destination-ip-address', destination_ip,
- '--source-port', source_port,
- '--destination-port', destination_port,
- '--action', action_cli or action,
- '--enabled', enabled,
- '--admin-state-up',
- '--tenant-id', tenant_id]
- position_names = []
- position_values = []
- if protocol == 'any':
- protocol = None
- if ip_version == '4' or ip_version == '6':
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- description=description, shared=True,
- protocol=protocol,
- ip_version=int(ip_version),
- source_ip_address=source_ip,
- destination_ip_address=destination_ip,
- source_port=source_port,
- destination_port=destination_port,
- action=action, enabled='True',
- tenant_id=tenant_id)
- else:
- self.assertRaises(SystemExit, self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values,
- ip_version=int(ip_version),
- source_ip_address=source_ip,
- destination_ip_address=destination_ip,
- source_port=source_port,
- destination_port=destination_port,
- action=action, enabled='True',
- tenant_id=tenant_id)
-
- def test_create_firewall_rule_with_all_params(self):
- self._setup_create_firewall_rule_with_all_params()
-
- def test_create_firewall_rule_with_proto_any(self):
- self._setup_create_firewall_rule_with_all_params(protocol='any')
-
- def test_create_firewall_rule_with_IP_version_6(self):
- self._setup_create_firewall_rule_with_all_params(ip_version='6')
-
- def test_create_firewall_rule_with_invalid_IP_version(self):
- self._setup_create_firewall_rule_with_all_params(ip_version='5')
-
- def test_create_firewall_rule_with_proto_action_upper_capitalized(self):
- for protocol in ('TCP', 'Tcp', 'ANY', 'AnY'):
- self._setup_create_firewall_rule_with_all_params(
- protocol=protocol.lower(),
- protocol_cli=protocol)
- for action in ('Allow', 'DENY', 'reject'):
- self._setup_create_firewall_rule_with_all_params(
- action=action.lower(),
- action_cli=action)
-
- def test_list_firewall_rules(self):
- # firewall-rule-list.
- resources = "firewall_rules"
- cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_firewall_rules_pagination(self):
- # firewall-rule-list.
- resources = "firewall_rules"
- cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_firewall_rules_sort(self):
- # firewall-rule-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "firewall_rules"
- cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_firewall_rules_limit(self):
- # firewall-rule-list -P."""
- resources = "firewall_rules"
- cmd = firewallrule.ListFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_firewall_rule_id(self):
- # firewall-rule-show test_id.
- resource = 'firewall_rule'
- cmd = firewallrule.ShowFirewallRule(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_firewall_rule_id_name(self):
- # firewall-rule-show.
- resource = 'firewall_rule'
- cmd = firewallrule.ShowFirewallRule(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_firewall_rule(self):
- # firewall-rule-update myid --name newname.
- resource = 'firewall_rule'
- cmd = firewallrule.UpdateFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname'],
- {'name': 'newname', })
-
- # firewall-rule-update myid --protocol any.
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--protocol', 'any'],
- {'protocol': None, })
-
- # firewall-rule-update myid --description any
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--description', 'any'],
- {'description': 'any', })
-
- # firewall-rule-update myid --source_ip_address 192.192.192.192
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--source_ip_address',
- '192.192.192.192'],
- {'source_ip_address': '192.192.192.192', })
-
- # firewall-rule-update myid --source_port 32767
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--source_port', '32767'],
- {'source_port': '32767', })
-
- # firewall-rule-update myid --destination_ip_address 0.1.0.1
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--destination_ip_address',
- '0.1.0.1'],
- {'destination_ip_address': '0.1.0.1', })
-
- # firewall-rule-update myid --destination_port 65432
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--destination_port',
- '65432'],
- {'destination_port': '65432', })
-
- # firewall-rule-update myid --enabled False
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--enabled', 'False'],
- {'enabled': 'False', })
-
- # firewall-rule-update myid --action reject
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--action', 'reject'],
- {'action': 'reject', })
-
- # firewall-rule-update myid --shared false
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--shared', 'false'],
- {'shared': 'false', })
-
- def test_delete_firewall_rule(self):
- # firewall-rule-delete my-id.
- resource = 'firewall_rule'
- cmd = firewallrule.DeleteFirewallRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'myid1'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args)
diff --git a/neutronclient/tests/unit/lb/__init__.py b/neutronclient/tests/unit/lb/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/neutronclient/tests/unit/lb/__init__.py
+++ /dev/null
diff --git a/neutronclient/tests/unit/lb/test_cli20_healthmonitor.py b/neutronclient/tests/unit/lb/test_cli20_healthmonitor.py
deleted file mode 100644
index 61cb1b1..0000000
--- a/neutronclient/tests/unit/lb/test_cli20_healthmonitor.py
+++ /dev/null
@@ -1,202 +0,0 @@
-# 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.
-#
-
-import sys
-from unittest import mock
-
-
-from neutronclient.neutron.v2_0.lb import healthmonitor
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbHealthmonitorJSON(test_cli20.CLITestV20Base):
- def test_create_healthmonitor_with_mandatory_params(self):
- # lb-healthmonitor-create with mandatory params only.
- resource = 'health_monitor'
- cmd = healthmonitor.CreateHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- admin_state_up = False
- 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 = [admin_state_up, 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_list_healthmonitors_pagination(self):
- # lb-healthmonitor-list.
- resources = "health_monitors"
- cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_healthmonitors_sort(self):
- # lb-healthmonitor-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "health_monitors"
- cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_healthmonitors_limit(self):
- # lb-healthmonitor-list -P.
- resources = "health_monitors"
- cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- 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_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]
-
- 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)
- cmd_parser = cmd.get_parser('test_' + resource)
- parsed_args = cmd_parser.parse_args(args)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=return_tup) as mock_request:
- cmd.run(parsed_args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.end_url(path), 'POST',
- body=test_cli20.MyComparator(body, self.client),
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- 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]
-
- path = (getattr(self.client,
- "disassociate_pool_health_monitors_path") %
- {'pool': pool_id, 'health_monitor': health_monitor_id})
- return_tup = (test_cli20.MyResp(204), None)
- cmd_parser = cmd.get_parser('test_' + resource)
- parsed_args = cmd_parser.parse_args(args)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=return_tup) as mock_request:
- cmd.run(parsed_args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.end_url(path), 'DELETE',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
diff --git a/neutronclient/tests/unit/lb/test_cli20_member.py b/neutronclient/tests/unit/lb/test_cli20_member.py
deleted file mode 100644
index 8ce2a0f..0000000
--- a/neutronclient/tests/unit/lb/test_cli20_member.py
+++ /dev/null
@@ -1,118 +0,0 @@
-# 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0.lb import member
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbMemberJSON(test_cli20.CLITestV20Base):
- def setUp(self):
- super(CLITestV20LbMemberJSON, self).setUp(plurals={'tags': 'tag'})
-
- 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, '--protocol-port', port,
- '--tenant-id', tenant_id, pool_id]
- position_names = ['address', 'protocol_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',
- '--protocol-port', port, '--weight', weight,
- '--tenant-id', tenant_id, pool_id]
- position_names = [
- 'address', 'admin_state_up', 'protocol_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_list_members_pagination(self):
- # lb-member-list.
- resources = "members"
- cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_members_sort(self):
- # lb-member-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "members"
- cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_members_limit(self):
- # lb-member-list -P.
- resources = "members"
- cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- 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_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/neutronclient/tests/unit/lb/test_cli20_pool.py b/neutronclient/tests/unit/lb/test_cli20_pool.py
deleted file mode 100644
index 79bf23d..0000000
--- a/neutronclient/tests/unit/lb/test_cli20_pool.py
+++ /dev/null
@@ -1,166 +0,0 @@
-# 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.
-#
-
-import sys
-from unittest import mock
-
-
-from neutronclient.neutron.v2_0.lb import pool
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbPoolJSON(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'
- provider = 'lbaas'
- args = ['--admin-state-down',
- '--description', description,
- '--lb-method', lb_method,
- '--name', name,
- '--protocol', protocol,
- '--subnet-id', subnet_id,
- '--tenant-id', tenant_id,
- '--provider', provider]
- position_names = ['admin_state_up', 'description', 'lb_method', 'name',
- 'protocol', 'subnet_id', 'tenant_id', 'provider']
- position_values = [False, description, lb_method, name,
- protocol, subnet_id, tenant_id, provider]
- 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_list_pools_pagination(self):
- # lb-pool-list.
- resources = "pools"
- cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_pools_sort(self):
- # lb-pool-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "pools"
- cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_pools_limit(self):
- # lb-pool-list -P.
- resources = "pools"
- cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- 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]
-
- 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)
-
- cmd_parser = cmd.get_parser("test_" + resource)
- parsed_args = cmd_parser.parse_args(args)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=return_tup) as mock_request:
- cmd.run(parsed_args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), 2)
- mock_request.assert_called_once_with(
- test_cli20.end_url(path % my_id, query), 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- _str = self.fake_stdout.make_string()
- self.assertIn('bytes_in', _str)
- self.assertIn('bytes_out', _str)
diff --git a/neutronclient/tests/unit/lb/test_cli20_vip.py b/neutronclient/tests/unit/lb/test_cli20_vip.py
deleted file mode 100644
index b08de44..0000000
--- a/neutronclient/tests/unit/lb/test_cli20_vip.py
+++ /dev/null
@@ -1,206 +0,0 @@
-# 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0.lb import vip
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbVipJSON(test_cli20.CLITestV20Base):
- def setUp(self):
- super(CLITestV20LbVipJSON, self).setUp(plurals={'tags': 'tag'})
-
- 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'
- protocol_port = '1000'
- protocol = 'TCP'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
- args = ['--name', name,
- '--protocol-port', protocol_port,
- '--protocol', protocol,
- '--subnet-id', subnet_id,
- '--tenant-id', tenant_id,
- pool_id]
- position_names = ['pool_id', 'name', 'protocol_port', 'protocol',
- 'subnet_id', 'tenant_id']
- position_values = [pool_id, name, protocol_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'
- protocol_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,
- '--protocol-port', protocol_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',
- 'protocol_port', 'protocol', 'subnet_id',
- 'tenant_id']
- position_values = [pool_id, name, description, address,
- admin_state, connection_limit, protocol_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'
- protocol_port = '1000'
- protocol = 'TCP'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
- args = ['--name', name,
- '--protocol-port', protocol_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', 'protocol_port', 'protocol',
- 'subnet_id', 'tenant_id', 'optional_param']
- position_values = [pool_id, name, protocol_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_list_vips_pagination(self):
- # lb-vip-list.
- resources = "vips"
- cmd = vip.ListVip(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_vips_sort(self):
- # lb-vip-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "vips"
- cmd = vip.ListVip(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_vips_limit(self):
- # lb-vip-list -P.
- resources = "vips"
- cmd = vip.ListVip(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- 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/neutronclient/tests/unit/lb/v2/__init__.py b/neutronclient/tests/unit/lb/v2/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/neutronclient/tests/unit/lb/v2/__init__.py
+++ /dev/null
diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py b/neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py
deleted file mode 100644
index 945ac18..0000000
--- a/neutronclient/tests/unit/lb/v2/test_cli20_healthmonitor.py
+++ /dev/null
@@ -1,175 +0,0 @@
-# Copyright 2014 Blue Box Group, 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0.lb.v2 import healthmonitor
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbHealthMonitorJSON(test_cli20.CLITestV20Base):
-
- def test_create_healthmonitor_with_mandatory_params(self):
- # lbaas-healthmonitor-create with mandatory params only.
- resource = 'healthmonitor'
- cmd_resource = 'lbaas_healthmonitor'
- cmd = healthmonitor.CreateHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- type = 'PING'
- max_retries = '3'
- delay = '10'
- timeout = '60'
- pool = 'pool1'
- args = ['--type', type, '--max-retries', max_retries,
- '--delay', delay, '--timeout', timeout, '--pool', pool]
- position_names = ['type', 'max_retries', 'delay', 'timeout', 'pool_id']
- position_values = [type, max_retries, delay, timeout, pool]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_create_healthmonitor_with_all_params(self):
- # lbaas-healthmonitor-create with all params set.
- resource = 'healthmonitor'
- cmd_resource = 'lbaas_healthmonitor'
- cmd = healthmonitor.CreateHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- type = 'PING'
- max_retries = '3'
- delay = '10'
- timeout = '60'
- http_method = 'GET'
- expected_codes = '201'
- url_path = '/somepath'
- pool = 'pool1'
- name = 'healthmonitor1'
- args = ['--admin-state-down', '--http-method', http_method,
- '--expected-codes', expected_codes, '--url-path', url_path,
- '--type', type, '--max-retries', max_retries,
- '--delay', delay, '--timeout', timeout, '--pool', pool,
- '--name', name]
- position_names = ['admin_state_up', 'http_method', 'expected_codes',
- 'url_path', 'type', 'max_retries', 'delay',
- 'timeout', 'pool_id', 'name']
- position_values = [False, http_method, expected_codes, url_path,
- type, max_retries, delay, timeout, pool, name]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_list_healthmonitors(self):
- # lbaas-healthmonitor-list.
- resources = 'healthmonitors'
- cmd_resources = 'lbaas_healthmonitors'
- cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_healthmonitors_pagination(self):
- # lbaas-healthmonitor-list with pagination.
- resources = 'healthmonitors'
- cmd_resources = 'lbaas_healthmonitors'
- cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination(resources, cmd,
- cmd_resources=cmd_resources)
-
- def test_list_healthmonitors_sort(self):
- # lbaas-healthmonitor-list --sort-key id --sort-key asc.
- resources = 'healthmonitors'
- cmd_resources = 'lbaas_healthmonitors'
- cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_healthmonitors_limit(self):
- # lbaas-healthmonitor-list -P.
- resources = 'healthmonitors'
- cmd_resources = 'lbaas_healthmonitors'
- cmd = healthmonitor.ListHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000,
- cmd_resources=cmd_resources)
-
- def test_show_healthmonitor_id(self):
- # lbaas-healthmonitor-show test_id.
- resource = 'healthmonitor'
- cmd_resource = 'lbaas_healthmonitor'
- 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'],
- cmd_resource=cmd_resource)
-
- def test_show_healthmonitor_id_name(self):
- # lbaas-healthmonitor-show.
- resource = 'healthmonitor'
- cmd_resource = 'lbaas_healthmonitor'
- 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'],
- cmd_resource=cmd_resource)
-
- def _test_update_hm(self, args, expected_values):
- resource = 'healthmonitor'
- cmd_resource = 'lbaas_healthmonitor'
- my_id = 'myid'
- cmd = healthmonitor.UpdateHealthMonitor(test_cli20.MyApp(sys.stdout),
- None)
- args.insert(0, my_id)
- self._test_update_resource(resource, cmd, my_id,
- args,
- expected_values,
- cmd_resource=cmd_resource)
-
- def test_update_healthmonitor(self):
- # lbaas-healthmonitor-update myid --name newname.
- self._test_update_hm(['--name', 'newname'], {'name': 'newname', })
- # lbaas-healthmonitor-update myid --delay 10.
- self._test_update_hm(['--delay', '10'], {'delay': '10'})
- # lbaas-healthmonitor-update myid --timeout 5.
- self._test_update_hm(['--timeout', '5'], {'timeout': '5', })
- # lbaas-healthmonitor-update myid --delay 10.
- self._test_update_hm(['--http-method', 'OPTIONS'],
- {'http_method': 'OPTIONS'})
- # lbaas-healthmonitor-update myid --url-path /test/string .
- self._test_update_hm(['--url-path', '/test/string'],
- {'url_path': '/test/string', })
- # lbaas-healthmonitor-update myid --max-retries 5
- self._test_update_hm(['--max-retries', '5'], {'max_retries': '5'})
- # lbaas-healthmonitor-update myid --expected-codes 201
- self._test_update_hm(['--expected-codes', '201'],
- {'expected_codes': '201'})
- # lbaas-healthmonitor-update myid --admin-state-up False
- self._test_update_hm(['--admin-state-up', 'False'],
- {'admin_state_up': 'False'})
-
- def test_delete_healthmonitor(self):
- # lbaas-healthmonitor-delete my-id.
- resource = 'healthmonitor'
- cmd_resource = 'lbaas_healthmonitor'
- 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,
- cmd_resource=cmd_resource)
diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_l7policy.py b/neutronclient/tests/unit/lb/v2/test_cli20_l7policy.py
deleted file mode 100644
index 7186931..0000000
--- a/neutronclient/tests/unit/lb/v2/test_cli20_l7policy.py
+++ /dev/null
@@ -1,260 +0,0 @@
-# Copyright 2016 Radware LTD.
-# 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 neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.lb.v2 import l7policy
-from neutronclient.tests.unit import test_cli20
-
-"""Structure for mapping cli and api arguments
-
-The structure maps cli arguments and a list of its
-api argument name, default cli value and default api value.
-It helps to make tests more general for different argument types.
-"""
-args_conf = {
- 'name': ['name', 'test_policy', 'test_policy'],
- 'description': ['description', 'test policy', 'test policy'],
- 'listener': ['listener_id', 'test_listener', 'test_listener'],
- 'admin-state-up': ['admin_state_up', True, True],
- 'admin-state-down': ['admin_state_up', None, False],
- 'action': ['action', 'REJECT', 'REJECT'],
- 'redirect-url': ['redirect_url', 'http://url', 'http://url'],
- 'redirect-pool': ['redirect_pool_id', 'test_pool', 'test_pool'],
- 'position': ['position', '1', 1]}
-
-
-class CLITestV20LbL7PolicyJSON(test_cli20.CLITestV20Base):
-
- def _get_test_args(self, *args, **kwargs):
- """Function for generically building testing arguments"""
- cli_args = []
- api_args = {}
- for arg in args:
- cli_args.append('--' + arg)
- if not args_conf[arg][1]:
- pass
- elif arg in kwargs:
- cli_args.append(str(kwargs[arg]))
- else:
- cli_args.append(args_conf[arg][1])
-
- if arg in kwargs:
- api_args[args_conf[arg][0]] = kwargs[arg]
- else:
- api_args[args_conf[arg][0]] = args_conf[arg][2]
-
- return cli_args, api_args
-
- def _test_create_policy(self, *args, **kwargs):
- resource = 'l7policy'
- cmd_resource = 'lbaas_l7policy'
- cmd = l7policy.CreateL7Policy(test_cli20.MyApp(sys.stdout), None)
- cli_args, api_args = self._get_test_args(*args, **kwargs)
- position_names = list(api_args.keys())
- position_values = list(api_args.values())
- self._test_create_resource(resource, cmd, None, 'test_id',
- cli_args, position_names, position_values,
- cmd_resource=cmd_resource)
-
- def _test_update_policy(self, *args, **kwargs):
- resource = 'l7policy'
- cmd_resource = 'lbaas_l7policy'
- cmd = l7policy.UpdateL7Policy(test_cli20.MyApp(sys.stdout), None)
- cli_args, api_args = self._get_test_args(*args, **kwargs)
- cli_args.append('test_id')
- self._test_update_resource(resource, cmd, 'test_id',
- cli_args, api_args,
- cmd_resource=cmd_resource)
-
- def test_create_policy_with_mandatory_params(self):
- # lbaas-l7policy-create with mandatory params only.
- self._test_create_policy('action', 'listener')
-
- def test_create_policy_with_all_params(self):
- # lbaas-l7policy-create REJECT policy.
- self._test_create_policy('name', 'description',
- 'action', 'listener',
- 'position')
-
- def test_create_disabled_policy(self):
- # lbaas-l7policy-create disabled REJECT policy.
- self._test_create_policy('action', 'listener', 'admin-state-down')
-
- def test_create_url_redirect_policy(self):
- # lbaas-l7policy-create REDIRECT_TO_URL policy.
- self._test_create_policy('name', 'description',
- 'action', 'listener',
- 'redirect-url',
- action='REDIRECT_TO_URL')
-
- def test_create_url_redirect_policy_no_url(self):
- # lbaas-l7policy-create REDIRECT_TO_URL policy without url argument.
- self.assertRaises(exceptions.CommandError,
- self._test_create_policy,
- 'name', 'description',
- 'action', 'listener',
- action='REDIRECT_TO_URL')
-
- def test_create_pool_redirect_policy(self):
- # lbaas-l7policy-create REDIRECT_TO_POOL policy.
- self._test_create_policy('name', 'description',
- 'action', 'listener',
- 'redirect-pool',
- action='REDIRECT_TO_POOL')
-
- def test_create_pool_redirect_policy_no_pool(self):
- # lbaas-l7policy-create REDIRECT_TO_POOL policy without pool argument.
- self.assertRaises(exceptions.CommandError,
- self._test_create_policy,
- 'name', 'description',
- 'action', 'listener',
- action='REDIRECT_TO_POOL')
-
- def test_create_reject_policy_with_url(self):
- # lbaas-l7policy-create REJECT policy while specifying url argument.
- self.assertRaises(exceptions.CommandError,
- self._test_create_policy,
- 'action', 'listener',
- 'redirect-url')
-
- def test_create_reject_policy_with_pool(self):
- # lbaas-l7policy-create REJECT policy while specifying pool argument.
- self.assertRaises(exceptions.CommandError,
- self._test_create_policy,
- 'action', 'listener',
- 'redirect-pool')
-
- def test_create_pool_redirect_policy_with_url(self):
- # lbaas-l7policy-create REDIRECT_TO_POOL policy with url argument.
- self.assertRaises(exceptions.CommandError,
- self._test_create_policy,
- 'action', 'listener',
- 'redirect-pool', 'redirect-url',
- action='REDIRECT_TO_POOL')
-
- def test_create_url_redirect_policy_with_pool(self):
- # lbaas-l7policy-create REDIRECT_TO_URL policy with pool argument.
- self.assertRaises(exceptions.CommandError,
- self._test_create_policy,
- 'action', 'listener',
- 'redirect-pool', 'redirect-url',
- action='REDIRECT_TO_URL')
-
- def test_list_policies(self):
- # lbaas-l7policy-list.
-
- resources = 'l7policies'
- cmd_resources = 'lbaas_l7policies'
- cmd = l7policy.ListL7Policy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_policies_pagination(self):
- # lbaas-l7policy-list with pagination.
-
- resources = 'l7policies'
- cmd_resources = 'lbaas_l7policies'
- cmd = l7policy.ListL7Policy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(
- resources, cmd, cmd_resources=cmd_resources)
-
- def test_list_policies_sort(self):
- # lbaas-l7policy-list --sort-key id --sort-key asc.
-
- resources = 'l7policies'
- cmd_resources = 'lbaas_l7policies'
- cmd = l7policy.ListL7Policy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(
- resources, cmd, True, cmd_resources=cmd_resources)
-
- def test_list_policies_limit(self):
- # lbaas-l7policy-list -P.
-
- resources = 'l7policies'
- cmd_resources = 'lbaas_l7policies'
- cmd = l7policy.ListL7Policy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(
- resources, cmd, page_size=1000, cmd_resources=cmd_resources)
-
- def test_show_policy_id(self):
- # lbaas-l7policy-show test_id.
-
- resource = 'l7policy'
- cmd_resource = 'lbaas_l7policy'
- cmd = l7policy.ShowL7Policy(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'test_id', self.test_id]
- self._test_show_resource(
- resource, cmd, self.test_id, args,
- ['test_id'], cmd_resource=cmd_resource)
-
- def test_show_policy_id_name(self):
- # lbaas-l7policy-show.
-
- resource = 'l7policy'
- cmd_resource = 'lbaas_l7policy'
- cmd = l7policy.ShowL7Policy(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'test_id', '--fields', 'name', self.test_id]
- self._test_show_resource(
- resource, cmd, self.test_id, args,
- ['test_id', 'name'], cmd_resource=cmd_resource)
-
- def test_disable_policy(self):
- # lbaas-l7policy-update test_id --admin-state-up False.
-
- self._test_update_policy('admin-state-up',
- **{'admin-state-up': 'False'})
-
- def test_update_policy_name_and_description(self):
- # lbaas-l7policy-update test_id --name other --description other_desc.
-
- self._test_update_policy('name', 'description',
- name='name',
- description='other desc')
-
- def test_update_pool_redirect_policy(self):
- # lbaas-l7policy-update test_id --action REDIRECT_TO_POOL
- # --redirect-pool id.
-
- self._test_update_policy('action', 'redirect-pool',
- **{'action': 'REDIRECT_TO_POOL',
- 'redirect-pool': 'id'})
-
- def test_update_url_redirect_policy(self):
- # lbaas-l7policy-update test_id --action REDIRECT_TO_URL
- # --redirect-url http://other_url.
-
- self._test_update_policy('action', 'redirect-url',
- **{'action': 'REDIRECT_TO_URL',
- 'redirect-url': 'http://other_url'})
-
- def test_update_policy_position(self):
- # lbaas-l7policy-update test_id --position 2.
-
- self._test_update_policy('position',
- position=2)
-
- def test_delete_policy(self):
- # lbaas-l7policy-delete test_id.
-
- resource = 'l7policy'
- cmd_resource = 'lbaas_l7policy'
- cmd = l7policy.DeleteL7Policy(test_cli20.MyApp(sys.stdout), None)
- test_id = 'test_id'
- args = [test_id]
- self._test_delete_resource(resource, cmd, test_id, args,
- cmd_resource=cmd_resource)
diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_l7rule.py b/neutronclient/tests/unit/lb/v2/test_cli20_l7rule.py
deleted file mode 100644
index 5483054..0000000
--- a/neutronclient/tests/unit/lb/v2/test_cli20_l7rule.py
+++ /dev/null
@@ -1,210 +0,0 @@
-# Copyright 2016 Radware LTD.
-# 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 neutronclient.neutron.v2_0.lb.v2 import l7rule
-from neutronclient.tests.unit import test_cli20
-
-
-"""Structure for mapping cli and api arguments
-
-The structure maps cli arguments and a list of its
-api argument name, default cli value and default api value.
-It helps to make tests more general for different argument types.
-"""
-args_conf = {
- 'admin-state-up': ['admin_state_up', True, True],
- 'admin-state-down': ['admin_state_up', None, False],
- 'type': ['type', 'HOST_NAME', 'HOST_NAME'],
- 'compare-type': ['compare_type', 'EQUAL_TO', 'EQUAL_TO'],
- 'invert-compare': ['invert', None, True],
- 'key': ['key', 'key', 'key'],
- 'value': ['value', 'value', 'value']}
-
-
-class CLITestV20LbL7RuleJSON(test_cli20.CLITestV20Base):
-
- def _get_test_args(self, *args, **kwargs):
- """Function for generically building testing arguments"""
- cli_args = []
- api_args = {}
- for arg in args:
- cli_args.append('--' + arg)
- if not args_conf[arg][1]:
- pass
- elif arg in kwargs:
- cli_args.append(str(kwargs[arg]))
- else:
- cli_args.append(args_conf[arg][1])
-
- if arg in kwargs:
- api_args[args_conf[arg][0]] = kwargs[arg]
- else:
- api_args[args_conf[arg][0]] = args_conf[arg][2]
-
- if 'invert' not in api_args:
- api_args['invert'] = False
- return cli_args, api_args
-
- def _test_create_rule(self, *args, **kwargs):
- resource = 'rule'
- cmd_resource = 'lbaas_l7rule'
- cmd = l7rule.CreateL7Rule(test_cli20.MyApp(sys.stdout), None)
- cli_args, api_args = self._get_test_args(*args, **kwargs)
- position_names = list(api_args.keys())
- position_values = list(api_args.values())
- cli_args.append('test_policy')
- self._test_create_resource(resource, cmd, None, 'test_id',
- cli_args, position_names, position_values,
- cmd_resource=cmd_resource,
- parent_id='test_policy')
-
- def _test_update_rule(self, *args, **kwargs):
- resource = 'rule'
- cmd_resource = 'lbaas_l7rule'
- cmd = l7rule.UpdateL7Rule(test_cli20.MyApp(sys.stdout), None)
- cli_args, api_args = self._get_test_args(*args, **kwargs)
- cli_args.append('test_id')
- cli_args.append('test_policy')
- self._test_update_resource(resource, cmd, 'test_id',
- cli_args, api_args,
- cmd_resource=cmd_resource,
- parent_id='test_policy')
-
- def test_create_rule_with_mandatory_params(self):
- # lbaas-l7rule-create with mandatory params only.
-
- self._test_create_rule('type', 'compare-type',
- 'value')
-
- def test_create_disabled_rule(self):
- # lbaas-l7rule-create disabled rule.
-
- self._test_create_rule('type', 'compare-type',
- 'value', 'admin-state-down')
-
- def test_create_rule_with_all_params(self):
- # lbaas-l7rule-create with all params set.
-
- self._test_create_rule('type', 'compare-type',
- 'invert-compare', 'key', 'value',
- type='HEADER', compare_type='CONTAINS',
- key='other_key', value='other_value')
-
- def test_create_rule_with_inverted_compare(self):
- # lbaas-l7rule-create with invertted compare type.
-
- self._test_create_rule('type', 'compare-type',
- 'invert-compare', 'value')
-
- def test_list_rules(self):
- # lbaas-l7rule-list.
-
- resources = 'rules'
- cmd_resources = 'lbaas_l7rules'
- cmd = l7rule.ListL7Rule(test_cli20.MyApp(sys.stdout), None)
-
- policy_id = 'policy_id'
- self._test_list_resources(resources, cmd, True,
- base_args=[policy_id],
- cmd_resources=cmd_resources,
- parent_id=policy_id,
- query="l7policy_id=%s" % policy_id)
-
- def test_list_rules_pagination(self):
- # lbaas-l7rule-list with pagination.
-
- resources = 'rules'
- cmd_resources = 'lbaas_l7rules'
- cmd = l7rule.ListL7Rule(test_cli20.MyApp(sys.stdout), None)
- policy_id = 'policy_id'
- self._test_list_resources_with_pagination(
- resources, cmd, base_args=[policy_id],
- cmd_resources=cmd_resources, parent_id=policy_id,
- query="l7policy_id=%s" % policy_id)
-
- def test_list_rules_sort(self):
- # lbaas-l7rule-list --sort-key id --sort-key asc.
-
- resources = 'rules'
- cmd_resources = 'lbaas_l7rules'
- cmd = l7rule.ListL7Rule(test_cli20.MyApp(sys.stdout), None)
- policy_id = 'policy_id'
- self._test_list_resources(
- resources, cmd, True, base_args=[policy_id],
- cmd_resources=cmd_resources, parent_id=policy_id,
- query="l7policy_id=%s" % policy_id)
-
- def test_list_rules_limit(self):
- # lbaas-l7rule-list -P.
-
- resources = 'rules'
- cmd_resources = 'lbaas_l7rules'
- cmd = l7rule.ListL7Rule(test_cli20.MyApp(sys.stdout), None)
- policy_id = 'policy_id'
- self._test_list_resources(resources, cmd, page_size=1000,
- base_args=[policy_id],
- cmd_resources=cmd_resources,
- parent_id=policy_id,
- query="l7policy_id=%s" % policy_id)
-
- def test_show_rule_id(self):
- # lbaas-l7rule-show test_id.
-
- resource = 'rule'
- cmd_resource = 'lbaas_l7rule'
- policy_id = 'policy_id'
- cmd = l7rule.ShowL7Rule(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', self.test_id, policy_id]
- self._test_show_resource(resource, cmd, self.test_id, args, ['id'],
- cmd_resource=cmd_resource,
- parent_id=policy_id)
-
- def test_update_rule_type(self):
- # lbaas-l7rule-update test_id --type HEADER test_policy
-
- self._test_update_rule('type', type='HEADER')
-
- def test_update_rule_compare_type(self):
- # lbaas-l7rule-update test_id --compare-type CONTAINS test_policy.
-
- self._test_update_rule('compare-type',
- **{'compare-type': 'CONTAINS'})
-
- def test_update_rule_inverted_compare_type(self):
- # lbaas-l7rule-update test_id --invert-compare test_policy.
-
- self._test_update_rule('invert-compare')
-
- def test_update_rule_key_value(self):
- # lbaas-l7rule-update test_id --key other --value other test_policy.
-
- self._test_update_rule('key', 'value',
- key='other', value='other')
-
- def test_delete_rule(self):
- # lbaas-l7rule-delete test_id policy_id.
-
- resource = 'rule'
- cmd_resource = 'lbaas_l7rule'
- policy_id = 'policy_id'
- test_id = 'test_id'
- cmd = l7rule.DeleteL7Rule(test_cli20.MyApp(sys.stdout), None)
- args = [test_id, policy_id]
- self._test_delete_resource(resource, cmd, test_id, args,
- cmd_resource=cmd_resource,
- parent_id=policy_id)
diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_listener.py b/neutronclient/tests/unit/lb/v2/test_cli20_listener.py
deleted file mode 100644
index 3993ea7..0000000
--- a/neutronclient/tests/unit/lb/v2/test_cli20_listener.py
+++ /dev/null
@@ -1,194 +0,0 @@
-# Copyright 2014 Blue Box Group, 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.
-#
-
-import sys
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.lb.v2 import listener
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbListenerJSON(test_cli20.CLITestV20Base):
-
- def test_create_listener_with_loadbalancer(self):
- # lbaas-listener-create with --loadbalancer
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- cmd = listener.CreateListener(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- loadbalancer_id = 'loadbalancer'
- protocol = 'TCP'
- protocol_port = '80'
- args = ['--protocol', protocol, '--protocol-port', protocol_port,
- '--loadbalancer', loadbalancer_id]
- position_names = ['protocol', 'protocol_port', 'loadbalancer_id']
- position_values = [protocol, protocol_port, loadbalancer_id,
- True]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_create_listener_with_default_pool(self):
- # lbaas-listener-create with --default-pool and no --loadbalancer.
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- cmd = listener.CreateListener(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- default_pool_id = 'default-pool'
- protocol = 'TCP'
- protocol_port = '80'
- args = ['--protocol', protocol, '--protocol-port', protocol_port,
- '--default-pool', default_pool_id]
- position_names = ['protocol', 'protocol_port', 'default_pool_id']
- position_values = [protocol, protocol_port, default_pool_id,
- True]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_create_listener_with_no_loadbalancer_or_default_pool(self):
- # lbaas-listener-create without --default-pool or --loadbalancer.
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- cmd = listener.CreateListener(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- protocol = 'TCP'
- protocol_port = '80'
- args = ['--protocol', protocol, '--protocol-port', protocol_port]
- position_names = ['protocol', 'protocol_port']
- position_values = [protocol, protocol_port, True]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource,
- no_api_call=True,
- expected_exception=exceptions.CommandError)
-
- def test_create_listener_with_all_params(self):
- # lbaas-listener-create with all params set.
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- cmd = listener.CreateListener(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- loadbalancer = 'loadbalancer'
- default_pool_id = 'default-pool'
- protocol = 'TCP'
- protocol_port = '80'
- connection_limit = 10
- def_tls_cont_ref = '11111'
- args = ['--admin-state-down',
- '--protocol', protocol, '--protocol-port', protocol_port,
- '--loadbalancer', loadbalancer,
- '--default-pool', default_pool_id,
- '--default-tls-container-ref', def_tls_cont_ref,
- '--sni-container-refs', '1111', '2222', '3333',
- '--connection-limit', '10']
- position_names = ['admin_state_up',
- 'protocol', 'protocol_port', 'loadbalancer_id',
- 'default_pool_id',
- 'default_tls_container_ref', 'sni_container_refs',
- 'connection_limit']
- position_values = [False, protocol, protocol_port, loadbalancer,
- default_pool_id,
- def_tls_cont_ref, ['1111', '2222', '3333'],
- connection_limit]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_list_listeners(self):
- # lbaas-listener-list.
- resources = 'listeners'
- cmd_resources = 'lbaas_listeners'
- cmd = listener.ListListener(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_listeners_pagination(self):
- # lbaas-listener-list with pagination.
- resources = 'listeners'
- cmd_resources = 'lbaas_listeners'
- cmd = listener.ListListener(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd,
- cmd_resources=cmd_resources)
-
- def test_list_listeners_sort(self):
- # lbaas-listener-list --sort-key id --sort-key asc.
- resources = 'listeners'
- cmd_resources = 'lbaas_listeners'
- cmd = listener.ListListener(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_listeners_limit(self):
- # lbaas-listener-list -P.
- resources = 'listeners'
- cmd_resources = 'lbaas_listeners'
- cmd = listener.ListListener(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000,
- cmd_resources=cmd_resources)
-
- def test_show_listener_id(self):
- # lbaas-listener-show test_id.
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- cmd = listener.ShowListener(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', self.test_id]
- self._test_show_resource(resource, cmd, self.test_id, args, ['id'],
- cmd_resource=cmd_resource)
-
- def test_show_listener_id_name(self):
- # lbaas-listener-show.
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- cmd = listener.ShowListener(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'],
- cmd_resource=cmd_resource)
-
- def _test_update_listener(self, args, expected_values):
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- my_id = 'myid'
- args.insert(0, my_id)
- cmd = listener.UpdateListener(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, my_id,
- args, expected_values,
- cmd_resource=cmd_resource)
-
- def test_update_listener(self):
- # lbaas-listener-update myid --name newname.
- self._test_update_listener(['--name', 'newname'],
- {'name': 'newname', })
- # lbaas-listener-update myid --description check.
- self._test_update_listener(['--description', 'check'],
- {'description': 'check', })
- # lbaas-listener-update myid --connection-limit -1
- self._test_update_listener(['--connection-limit', '-1'],
- {'connection_limit': -1, })
- # lbaas-listener-update myid --admin-state-up False.
- self._test_update_listener(['--admin-state-up', 'False'],
- {'admin_state_up': 'False', })
-
- def test_delete_listener(self):
- # lbaas-listener-delete my-id.
- resource = 'listener'
- cmd_resource = 'lbaas_listener'
- cmd = listener.DeleteListener(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args,
- cmd_resource=cmd_resource)
diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py b/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py
deleted file mode 100644
index 3a6010c..0000000
--- a/neutronclient/tests/unit/lb/v2/test_cli20_loadbalancer.py
+++ /dev/null
@@ -1,213 +0,0 @@
-# Copyright 2014 Blue Box Group, 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.
-#
-
-import sys
-from unittest import mock
-
-
-from neutronclient.neutron.v2_0.lb.v2 import loadbalancer as lb
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbLoadBalancerJSON(test_cli20.CLITestV20Base):
-
- def test_create_loadbalancer_with_mandatory_params(self):
- # lbaas-loadbalancer-create with mandatory params only.
- resource = 'loadbalancer'
- cmd_resource = 'lbaas_loadbalancer'
- cmd = lb.CreateLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- name = 'lbaas-loadbalancer-name'
- vip_subnet_id = 'vip-subnet'
- my_id = 'my-id'
- args = [vip_subnet_id]
- position_names = ['vip_subnet_id']
- position_values = [vip_subnet_id]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_create_loadbalancer_with_all_params(self):
- # lbaas-loadbalancer-create with all params set.
- resource = 'loadbalancer'
- cmd_resource = 'lbaas_loadbalancer'
- cmd = lb.CreateLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- name = 'lbaas-loadbalancer-name'
- description = 'lbaas-loadbalancer-desc'
- flavor_id = 'lbaas-loadbalancer-flavor'
- vip_subnet_id = 'vip-subnet'
- my_id = 'my-id'
- args = ['--admin-state-down', '--description', description,
- '--name', name, '--flavor', flavor_id, vip_subnet_id]
- position_names = ['admin_state_up', 'description', 'name',
- 'flavor_id', 'vip_subnet_id']
- position_values = [False, description, name, flavor_id, vip_subnet_id]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_list_loadbalancers(self):
- # lbaas-loadbalancer-list.
- resources = 'loadbalancers'
- cmd_resources = 'lbaas_loadbalancers'
- cmd = lb.ListLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_loadbalancers_pagination(self):
- # lbaas-loadbalancer-list with pagination.
- resources = 'loadbalancers'
- cmd_resources = 'lbaas_loadbalancers'
- cmd = lb.ListLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd,
- cmd_resources=cmd_resources)
-
- def test_list_loadbalancers_sort(self):
- # lbaas-loadbalancer-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = 'loadbalancers'
- cmd_resources = 'lbaas_loadbalancers'
- cmd = lb.ListLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"],
- cmd_resources=cmd_resources)
-
- def test_list_loadbalancers_limit(self):
- # lbaas-loadbalancer-list -P.
- resources = 'loadbalancers'
- cmd_resources = 'lbaas_loadbalancers'
- cmd = lb.ListLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000,
- cmd_resources=cmd_resources)
-
- def test_show_loadbalancer_id(self):
- # lbaas-loadbalancer-loadbalancer-show test_id.
- resource = 'loadbalancer'
- cmd_resource = 'lbaas_loadbalancer'
- cmd = lb.ShowLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', self.test_id]
- self._test_show_resource(resource, cmd, self.test_id, args, ['id'],
- cmd_resource=cmd_resource)
-
- def test_show_loadbalancer_id_name(self):
- # lbaas-loadbalancer-loadbalancer-show.
- resource = 'loadbalancer'
- cmd_resource = 'lbaas_loadbalancer'
- cmd = lb.ShowLoadBalancer(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'],
- cmd_resource=cmd_resource)
-
- def _test_update_lb(self, args, expected_values):
- resource = 'loadbalancer'
- cmd_resource = 'lbaas_loadbalancer'
- my_id = 'myid'
- args.insert(0, my_id)
- cmd = lb.UpdateLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, my_id,
- args, expected_values,
- cmd_resource=cmd_resource)
-
- def test_update_loadbalancer(self):
- # lbaas-loadbalancer-update myid --name newname.
- self._test_update_lb(['--name', 'newname'], {'name': 'newname', })
- # lbaas-loadbalancer-update myid --description check.
- self._test_update_lb(['--description', 'check'],
- {'description': 'check', })
- # lbaas-loadbalancer-update myid --admin-state-up False.
- self._test_update_lb(['--admin-state-up', 'False'],
- {'admin_state_up': 'False', })
-
- def test_delete_loadbalancer(self):
- # lbaas-loadbalancer-loadbalancer-delete my-id.
- resource = 'loadbalancer'
- cmd_resource = 'lbaas_loadbalancer'
- cmd = lb.DeleteLoadBalancer(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args,
- cmd_resource=cmd_resource)
-
- def test_retrieve_loadbalancer_stats(self):
- # lbaas-loadbalancer-stats test_id.
- resource = 'loadbalancer'
- cmd = lb.RetrieveLoadBalancerStats(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]
-
- 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, "lbaas_loadbalancer_path_stats")
- return_tup = (test_cli20.MyResp(200), resstr)
-
- cmd_parser = cmd.get_parser("test_" + resource)
- parsed_args = cmd_parser.parse_args(args)
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=return_tup) as mock_request:
- cmd.run(parsed_args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), 2)
- mock_request.assert_called_once_with(
- test_cli20.end_url(path % my_id, query), 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- _str = self.fake_stdout.make_string()
- self.assertIn('bytes_in', _str)
- self.assertIn('1234', _str)
- self.assertIn('bytes_out', _str)
- self.assertIn('4321', _str)
-
- def test_get_loadbalancer_statuses(self):
- # lbaas-loadbalancer-status test_id.
- resource = 'loadbalancer'
- cmd = lb.RetrieveLoadBalancerStatus(test_cli20.MyApp(sys.stdout), None)
- my_id = self.test_id
- args = [my_id]
-
- expected_res = {'statuses': {'operating_status': 'ONLINE',
- 'provisioning_status': 'ACTIVE'}}
-
- resstr = self.client.serialize(expected_res)
-
- path = getattr(self.client, "lbaas_loadbalancer_path_status")
- return_tup = (test_cli20.MyResp(200), resstr)
-
- cmd_parser = cmd.get_parser("test_" + resource)
- parsed_args = cmd_parser.parse_args(args)
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=return_tup) as mock_request:
- cmd.run(parsed_args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.end_url(path % my_id), 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- _str = self.fake_stdout.make_string()
- self.assertIn('operating_status', _str)
- self.assertIn('ONLINE', _str)
- self.assertIn('provisioning_status', _str)
- self.assertIn('ACTIVE', _str)
diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_member.py b/neutronclient/tests/unit/lb/v2/test_cli20_member.py
deleted file mode 100644
index 057da42..0000000
--- a/neutronclient/tests/unit/lb/v2/test_cli20_member.py
+++ /dev/null
@@ -1,171 +0,0 @@
-# Copyright 2014 Blue Box Group, 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0.lb.v2 import member
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbMemberJSON(test_cli20.CLITestV20Base):
-
- def test_create_member_with_mandatory_params(self):
- # lbaas-member-create with mandatory params only.
- resource = 'member'
- cmd_resource = 'lbaas_member'
- cmd = member.CreateMember(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- address = '10.1.1.1'
- protocol_port = '80'
- pool_id = 'pool-id'
- subnet_id = 'subnet-id'
- args = ['--address', address, '--protocol-port', protocol_port,
- '--subnet', subnet_id, pool_id]
- position_names = ['admin_state_up', 'address',
- 'protocol_port', 'subnet_id']
- position_values = [True, address, protocol_port, subnet_id]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource,
- parent_id=pool_id)
-
- def test_create_member_with_all_params(self):
- # lbaas-member-create with all params set.
- resource = 'member'
- cmd_resource = 'lbaas_member'
- cmd = member.CreateMember(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- address = '10.1.1.1'
- protocol_port = '80'
- pool_id = 'pool-id'
- subnet_id = 'subnet-id'
- weight = '100'
- name = 'member1'
- args = ['--address', address, '--protocol-port', protocol_port,
- '--subnet', subnet_id, pool_id, '--weight', weight,
- '--admin-state-down', '--name', name]
- position_names = ['admin_state_up', 'address', 'protocol_port',
- 'subnet_id', 'weight', 'name']
- position_values = [False, address, protocol_port,
- subnet_id, weight, name]
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource,
- parent_id=pool_id)
-
- def test_list_members(self):
- # lbaas-member-list.
- resources = 'members'
- cmd_resources = 'lbaas_members'
- pool_id = 'pool-id'
- cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True, base_args=[pool_id],
- cmd_resources=cmd_resources,
- parent_id=pool_id,
- query="pool_id=%s" % pool_id)
-
- def test_list_members_pagination(self):
- # lbaas-member-list with pagination.
- resources = 'members'
- cmd_resources = 'lbaas_members'
- pool_id = 'pool-id'
- cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd,
- base_args=[pool_id],
- cmd_resources=cmd_resources,
- parent_id=pool_id,
- query="pool_id=%s" % pool_id)
-
- def test_list_members_sort(self):
- # lbaas-member-list --sort-key id --sort-key asc.
- resources = 'members'
- cmd_resources = 'lbaas_members'
- pool_id = 'pool-id'
- cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True, base_args=[pool_id],
- cmd_resources=cmd_resources,
- parent_id=pool_id,
- query="pool_id=%s" % pool_id)
-
- def test_list_members_limit(self):
- # lbaas-member-list -P.
- resources = 'members'
- cmd_resources = 'lbaas_members'
- pool_id = 'pool-id'
- cmd = member.ListMember(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000,
- base_args=[pool_id],
- cmd_resources=cmd_resources,
- parent_id=pool_id,
- query="pool_id=%s" % pool_id)
-
- def test_show_member_id(self):
- # lbaas-member-show test_id.
- resource = 'member'
- cmd_resource = 'lbaas_member'
- pool_id = 'pool-id'
- cmd = member.ShowMember(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', self.test_id, pool_id]
- self._test_show_resource(resource, cmd, self.test_id, args, ['id'],
- cmd_resource=cmd_resource, parent_id=pool_id)
-
- def test_show_member_id_name(self):
- # lbaas-member-show.
- resource = 'member'
- cmd_resource = 'lbaas_member'
- pool_id = 'pool-id'
- cmd = member.ShowMember(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', '--fields', 'name', self.test_id, pool_id]
- self._test_show_resource(resource, cmd, self.test_id,
- args, ['id', 'name'],
- cmd_resource=cmd_resource, parent_id=pool_id)
-
- def test_update_member(self):
- # lbaas-member-update myid --name newname.
- resource = 'member'
- cmd_resource = 'lbaas_member'
- my_id = 'my-id'
- pool_id = 'pool-id'
- args = [my_id, pool_id, '--name', 'newname']
- cmd = member.UpdateMember(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, my_id, args,
- {'name': 'newname', },
- cmd_resource=cmd_resource,
- parent_id=pool_id)
- # lbaas-member-update myid --weight 100.
- args = [my_id, pool_id, '--weight', '100']
- self._test_update_resource(resource, cmd, my_id, args,
- {'weight': '100', },
- cmd_resource=cmd_resource,
- parent_id=pool_id)
- # lbaas-member-update myid --admin-state-up False
- args = [my_id, pool_id, '--admin-state-up', 'False']
- self._test_update_resource(resource, cmd, my_id, args,
- {'admin_state_up': 'False', },
- cmd_resource=cmd_resource,
- parent_id=pool_id)
-
- def test_delete_member(self):
- # lbaas-member-delete my-id.
- resource = 'member'
- cmd_resource = 'lbaas_member'
- cmd = member.DeleteMember(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- pool_id = 'pool-id'
- args = [my_id, pool_id]
- self._test_delete_resource(resource, cmd, my_id, args,
- cmd_resource=cmd_resource,
- parent_id=pool_id)
diff --git a/neutronclient/tests/unit/lb/v2/test_cli20_pool.py b/neutronclient/tests/unit/lb/v2/test_cli20_pool.py
deleted file mode 100644
index 8c1f428..0000000
--- a/neutronclient/tests/unit/lb/v2/test_cli20_pool.py
+++ /dev/null
@@ -1,202 +0,0 @@
-# Copyright 2014 Blue Box Group, 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.
-#
-
-import sys
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.lb.v2 import pool
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20LbPoolJSON(test_cli20.CLITestV20Base):
-
- def test_create_pool_with_listener(self):
- # lbaas-pool-create with listener
- resource = 'pool'
- cmd_resource = 'lbaas_pool'
- cmd = pool.CreatePool(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- lb_algorithm = 'ROUND_ROBIN'
- listener = 'listener'
- protocol = 'TCP'
- args = ['--lb-algorithm', lb_algorithm, '--protocol', protocol,
- '--listener', listener]
- position_names = ['admin_state_up', 'lb_algorithm', 'protocol',
- 'listener_id']
- position_values = [True, lb_algorithm, protocol, listener]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_create_pool_with_loadbalancer_no_listener(self):
- """lbaas-pool-create with loadbalancer, no listener."""
- resource = 'pool'
- cmd_resource = 'lbaas_pool'
- cmd = pool.CreatePool(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- lb_algorithm = 'ROUND_ROBIN'
- loadbalancer = 'loadbalancer'
- protocol = 'TCP'
- args = ['--lb-algorithm', lb_algorithm, '--protocol', protocol,
- '--loadbalancer', loadbalancer]
- position_names = ['admin_state_up', 'lb_algorithm', 'protocol',
- 'loadbalancer_id']
- position_values = [True, lb_algorithm, protocol, loadbalancer]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_create_pool_with_no_listener_or_loadbalancer(self):
- """lbaas-pool-create with no listener or loadbalancer."""
- resource = 'pool'
- cmd_resource = 'lbaas_pool'
- cmd = pool.CreatePool(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- lb_algorithm = 'ROUND_ROBIN'
- protocol = 'TCP'
- args = ['--lb-algorithm', lb_algorithm, '--protocol', protocol]
- position_names = ['admin_state_up', 'lb_algorithm', 'protocol']
- position_values = [True, lb_algorithm, protocol]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource,
- no_api_call=True,
- expected_exception=exceptions.CommandError)
-
- def test_create_pool_with_all_params(self):
- # lbaas-pool-create with all params set.
- resource = 'pool'
- cmd_resource = 'lbaas_pool'
- cmd = pool.CreatePool(test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- lb_algorithm = 'ROUND_ROBIN'
- listener = 'listener'
- loadbalancer = 'loadbalancer'
- protocol = 'TCP'
- description = 'description'
- session_persistence_str = 'type=APP_COOKIE,cookie_name=1234'
- session_persistence = {'type': 'APP_COOKIE',
- 'cookie_name': '1234'}
- name = 'my-pool'
- args = ['--lb-algorithm', lb_algorithm, '--protocol', protocol,
- '--description', description, '--session-persistence',
- session_persistence_str, '--admin-state-down', '--name', name,
- '--listener', listener, '--loadbalancer', loadbalancer]
- position_names = ['lb_algorithm', 'protocol', 'description',
- 'session_persistence', 'admin_state_up', 'name',
- 'listener_id', 'loadbalancer_id']
- position_values = [lb_algorithm, protocol, description,
- session_persistence, False, name, listener,
- loadbalancer]
- self._test_create_resource(resource, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=cmd_resource)
-
- def test_list_pools(self):
- # lbaas-pool-list.
- resources = 'pools'
- cmd_resources = 'lbaas_pools'
- cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_pools_pagination(self):
- # lbaas-pool-list with pagination.
- resources = 'pools'
- cmd_resources = 'lbaas_pools'
- cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd,
- cmd_resources=cmd_resources)
-
- def test_list_pools_sort(self):
- # lbaas-pool-list --sort-key id --sort-key asc.
- resources = 'pools'
- cmd_resources = 'lbaas_pools'
- cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True,
- cmd_resources=cmd_resources)
-
- def test_list_pools_limit(self):
- # lbaas-pool-list -P.
- resources = 'pools'
- cmd_resources = 'lbaas_pools'
- cmd = pool.ListPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000,
- cmd_resources=cmd_resources)
-
- def test_show_pool_id(self):
- # lbaas-pool-show test_id.
- resource = 'pool'
- cmd_resource = 'lbaas_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'],
- cmd_resource=cmd_resource)
-
- def test_show_pool_id_name(self):
- # lbaas-pool-show.
- resource = 'pool'
- cmd_resource = 'lbaas_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'],
- cmd_resource=cmd_resource)
-
- def test_update_pool(self):
- # lbaas-pool-update myid --name newname --description SuperPool
- # --lb-algorithm SOURCE_IP --admin-state-up
- # --session-persistence type=dict,type=HTTP_COOKIE,cookie_name=pie
-
- resource = 'pool'
- cmd_resource = 'lbaas_pool'
- cmd = pool.UpdatePool(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', '--name', 'newname',
- '--description', 'SuperPool', '--lb-algorithm', "SOURCE_IP",
- '--admin-state-up', 'True',
- '--session-persistence', 'type=dict,'
- 'type=HTTP_COOKIE,cookie_name=pie']
- body = {'name': 'newname',
- "description": "SuperPool",
- "lb_algorithm": "SOURCE_IP",
- "admin_state_up": 'True',
- 'session_persistence': {
- 'type': 'HTTP_COOKIE',
- 'cookie_name': 'pie',
- }, }
- self._test_update_resource(resource, cmd, 'myid', args, body,
- cmd_resource=cmd_resource)
- # lbaas-pool-update myid --name Name
- # --no-session-persistence
-
- resource = 'pool'
- cmd_resource = 'lbaas_pool'
- cmd = pool.UpdatePool(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', '--name', 'Name', '--no-session-persistence']
- body = {'name': "Name",
- "session_persistence": None, }
- self._test_update_resource(resource, cmd, 'myid', args, body,
- cmd_resource=cmd_resource)
-
- def test_delete_pool(self):
- # lbaas-pool-delete my-id.
- resource = 'pool'
- cmd_resource = 'lbaas_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,
- cmd_resource=cmd_resource)
diff --git a/neutronclient/tests/unit/qos/__init__.py b/neutronclient/tests/unit/qos/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/neutronclient/tests/unit/qos/__init__.py
+++ /dev/null
diff --git a/neutronclient/tests/unit/qos/test_cli20_bandwidth_limit_rule.py b/neutronclient/tests/unit/qos/test_cli20_bandwidth_limit_rule.py
deleted file mode 100644
index 8d4380a..0000000
--- a/neutronclient/tests/unit/qos/test_cli20_bandwidth_limit_rule.py
+++ /dev/null
@@ -1,137 +0,0 @@
-# Copyright 2015 Huawei Technologies India Pvt Ltd.
-# 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 neutronclient.neutron.v2_0.qos import bandwidth_limit_rule as bw_rule
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20QoSBandwidthLimitRuleJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['bandwidth_limit_rule']
-
- def setUp(self):
- super(CLITestV20QoSBandwidthLimitRuleJSON, self).setUp()
- self.res = 'bandwidth_limit_rule'
- self.cmd_res = 'qos_bandwidth_limit_rule'
- self.ress = self.res + 's'
- self.cmd_ress = self.cmd_res + 's'
-
- def test_create_bandwidth_limit_rule_with_max_kbps(self):
- cmd = bw_rule.CreateQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- max_kbps = '1337'
- policy_id = 'policy_id'
- args = ['--max-kbps', max_kbps, policy_id]
- position_names = ['max_kbps']
- position_values = [max_kbps]
- self._test_create_resource(self.res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_create_bandwidth_limit_rule_with_max_burst_kbps(self):
- cmd = bw_rule.CreateQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- max_burst_kbps = '1337'
- policy_id = 'policy_id'
- args = ['--max-burst-kbps', max_burst_kbps, policy_id]
- position_names = ['max_burst_kbps']
- position_values = [max_burst_kbps]
- self._test_create_resource(self.res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_create_bandwidth_limit_rule_with_all_params(self):
- cmd = bw_rule.CreateQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- max_kbps = '1337'
- max_burst_kbps = '1337'
- policy_id = 'policy_id'
- args = ['--max-kbps', max_kbps,
- '--max-burst-kbps', max_burst_kbps,
- policy_id]
- position_names = ['max_kbps', 'max_burst_kbps']
- position_values = [max_kbps, max_burst_kbps]
- self._test_create_resource(self.res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_update_bandwidth_limit_rule_with_max_kbps(self):
- cmd = bw_rule.UpdateQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- max_kbps = '1337'
- policy_id = 'policy_id'
- args = ['--max-kbps', max_kbps, my_id, policy_id]
- self._test_update_resource(self.res, cmd, my_id, args,
- {'max_kbps': max_kbps, },
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_update_bandwidth_limit_rule_with_max_burst_kbps(self):
- cmd = bw_rule.UpdateQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- max_burst_kbps = '1337'
- policy_id = 'policy_id'
- args = ['--max-burst-kbps', max_burst_kbps,
- my_id, policy_id]
- self._test_update_resource(self.res, cmd, my_id, args,
- {'max_burst_kbps': max_burst_kbps},
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_update_bandwidth_limit_rule_with_all_params(self):
- cmd = bw_rule.UpdateQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- max_kbps = '1337'
- max_burst_kbps = '1337'
- policy_id = 'policy_id'
- args = ['--max-kbps', max_kbps,
- '--max-burst-kbps', max_burst_kbps,
- my_id, policy_id]
- self._test_update_resource(self.res, cmd, my_id, args,
- {'max_kbps': max_kbps,
- 'max_burst_kbps': max_burst_kbps},
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_delete_bandwidth_limit_rule(self):
- cmd = bw_rule.DeleteQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- policy_id = 'policy_id'
- args = [my_id, policy_id]
- self._test_delete_resource(self.res, cmd, my_id, args,
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_show_bandwidth_limit_rule(self):
- cmd = bw_rule.ShowQoSBandwidthLimitRule(test_cli20.MyApp(sys.stdout),
- None)
- policy_id = 'policy_id'
- args = ['--fields', 'id', self.test_id, policy_id]
- self._test_show_resource(self.res, cmd, self.test_id, args,
- ['id'], cmd_resource=self.cmd_res,
- parent_id=policy_id)
diff --git a/neutronclient/tests/unit/qos/test_cli20_dscp_marking_rule.py b/neutronclient/tests/unit/qos/test_cli20_dscp_marking_rule.py
deleted file mode 100644
index 881b2f3..0000000
--- a/neutronclient/tests/unit/qos/test_cli20_dscp_marking_rule.py
+++ /dev/null
@@ -1,91 +0,0 @@
-# Copyright 2016 Comcast 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.
-#
-
-import sys
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.qos import dscp_marking_rule as dscp_rule
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20QoSDscpMarkingRuleJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['dscp_marking_rule']
-
- def setUp(self):
- super(CLITestV20QoSDscpMarkingRuleJSON, self).setUp()
- self.dscp_res = 'dscp_marking_rule'
- self.dscp_cmd_res = 'qos_dscp_marking_rule'
- self.dscp_ress = self.dscp_res + 's'
- self.dscp_cmd_ress = self.dscp_cmd_res + 's'
-
- def test_create_dscp_marking_rule_with_dscp_mark(self):
- cmd = dscp_rule.CreateQoSDscpMarkingRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- policy_id = 'policy_id'
- position_names = ['dscp_mark']
- valid_dscp_marks = ['0', '56']
- invalid_dscp_marks = ['-1', '19', '42', '44', '57', '58']
- for dscp_mark in valid_dscp_marks:
- args = ['--dscp-mark', dscp_mark, policy_id]
- position_values = [dscp_mark]
- self._test_create_resource(self.dscp_res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.dscp_cmd_res,
- parent_id=policy_id)
- for dscp_mark in invalid_dscp_marks:
- args = ['--dscp-mark', dscp_mark, policy_id]
- position_values = [dscp_mark]
- self._test_create_resource(
- self.dscp_res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.dscp_cmd_res,
- parent_id=policy_id,
- no_api_call=True,
- expected_exception=exceptions.CommandError)
-
- def test_update_dscp_marking_rule_with_dscp_mark(self):
- cmd = dscp_rule.UpdateQoSDscpMarkingRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- dscp_mark = '56'
- policy_id = 'policy_id'
- args = ['--dscp-mark', dscp_mark,
- my_id, policy_id]
- self._test_update_resource(self.dscp_res, cmd, my_id, args,
- {'dscp_mark': dscp_mark},
- cmd_resource=self.dscp_cmd_res,
- parent_id=policy_id)
-
- def test_delete_dscp_marking_rule(self):
- cmd = dscp_rule.DeleteQoSDscpMarkingRule(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'my-id'
- policy_id = 'policy_id'
- args = [my_id, policy_id]
- self._test_delete_resource(self.dscp_res, cmd, my_id, args,
- cmd_resource=self.dscp_cmd_res,
- parent_id=policy_id)
-
- def test_show_dscp_marking_rule(self):
- cmd = dscp_rule.ShowQoSDscpMarkingRule(test_cli20.MyApp(sys.stdout),
- None)
- policy_id = 'policy_id'
- args = ['--fields', 'id', self.test_id, policy_id]
- self._test_show_resource(self.dscp_res, cmd, self.test_id, args,
- ['id'], cmd_resource=self.dscp_cmd_res,
- parent_id=policy_id)
diff --git a/neutronclient/tests/unit/qos/test_cli20_minimum_bandwidth_rule.py b/neutronclient/tests/unit/qos/test_cli20_minimum_bandwidth_rule.py
deleted file mode 100644
index 39dccd6..0000000
--- a/neutronclient/tests/unit/qos/test_cli20_minimum_bandwidth_rule.py
+++ /dev/null
@@ -1,143 +0,0 @@
-# Copyright (c) 2016 Intel Corporation.
-# 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 neutronclient.neutron.v2_0.qos import minimum_bandwidth_rule as bw_rule
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20QoSMinimumBandwidthRuleJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['minimum_bandwidth_rule']
-
- def setUp(self):
- super(CLITestV20QoSMinimumBandwidthRuleJSON, self).setUp()
- self.res = 'minimum_bandwidth_rule'
- self.cmd_res = 'qos_minimum_bandwidth_rule'
- self.ress = self.res + 's'
- self.cmd_ress = self.cmd_res + 's'
-
- def test_create_minimum_bandwidth_rule_min_kbps_only(self):
- cmd = bw_rule.CreateQoSMinimumBandwidthRule(
- test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- min_kbps = '1500'
- policy_id = 'policy_id'
- args = ['--min-kbps', min_kbps,
- policy_id]
- position_names = ['min_kbps']
- position_values = [min_kbps]
- self.assertRaises(SystemExit, self._test_create_resource,
- self.res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.cmd_res,
- parent_id=policy_id,
- no_api_call=True)
-
- def test_create_minimum_bandwidth_rule_direction_only(self):
- cmd = bw_rule.CreateQoSMinimumBandwidthRule(
- test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- direction = 'egress'
- policy_id = 'policy_id'
- args = ['--direction', direction,
- policy_id]
- position_names = ['direction']
- position_values = [direction]
- self.assertRaises(SystemExit, self._test_create_resource,
- self.res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.cmd_res,
- parent_id=policy_id,
- no_api_call=True)
-
- def test_create_minimum_bandwidth_rule_none(self):
- cmd = bw_rule.CreateQoSMinimumBandwidthRule(
- test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- policy_id = 'policy_id'
- args = [policy_id]
- position_names = []
- position_values = []
- self.assertRaises(SystemExit, self._test_create_resource,
- self.res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.cmd_res,
- parent_id=policy_id,
- no_api_call=True)
-
- def test_create_minimum_bandwidth_rule_all(self):
- cmd = bw_rule.CreateQoSMinimumBandwidthRule(
- test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- min_kbps = '1500'
- direction = 'egress'
- policy_id = 'policy_id'
- args = ['--min-kbps', min_kbps,
- '--direction', direction,
- policy_id]
- position_names = ['direction', 'min_kbps']
- position_values = [direction, min_kbps]
- self._test_create_resource(self.res, cmd, '', my_id, args,
- position_names, position_values,
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_update_minimum_bandwidth_rule(self):
- cmd = bw_rule.UpdateQoSMinimumBandwidthRule(
- test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- min_kbps = '1200'
- direction = 'egress'
- policy_id = 'policy_id'
- args = ['--min-kbps', min_kbps,
- '--direction', direction,
- my_id, policy_id]
- self._test_update_resource(self.res, cmd, my_id, args,
- {'min_kbps': min_kbps,
- 'direction': direction},
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_delete_minimum_bandwidth_rule(self):
- cmd = bw_rule.DeleteQoSMinimumBandwidthRule(
- test_cli20.MyApp(sys.stdout), None)
- my_id = 'my-id'
- policy_id = 'policy_id'
- args = [my_id, policy_id]
- self._test_delete_resource(self.res, cmd, my_id, args,
- cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_show_minimum_bandwidth_rule(self):
- cmd = bw_rule.ShowQoSMinimumBandwidthRule(
- test_cli20.MyApp(sys.stdout), None)
- policy_id = 'policy_id'
- args = [self.test_id, policy_id]
- self._test_show_resource(self.res, cmd, self.test_id, args,
- [], cmd_resource=self.cmd_res,
- parent_id=policy_id)
-
- def test_list_minimum_bandwidth_rule(self):
- cmd = bw_rule.ListQoSMinimumBandwidthRules(
- test_cli20.MyApp(sys.stdout), None)
- policy_id = 'policy_id'
- args = [policy_id]
- contents = [{'name': 'rule1', 'min-kbps': 1000, 'direction': 'egress'}]
- self._test_list_resources(self.ress, cmd, parent_id=policy_id,
- cmd_resources=self.cmd_ress,
- base_args=args, response_contents=contents)
diff --git a/neutronclient/tests/unit/qos/test_cli20_policy.py b/neutronclient/tests/unit/qos/test_cli20_policy.py
deleted file mode 100644
index b1db866..0000000
--- a/neutronclient/tests/unit/qos/test_cli20_policy.py
+++ /dev/null
@@ -1,192 +0,0 @@
-# Copyright 2015 Huawei Technologies India Pvt Ltd.
-# 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 neutronclient.neutron.v2_0.qos import policy as policy
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20QoSPolicyJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['policy']
-
- def setUp(self):
- super(CLITestV20QoSPolicyJSON, self).setUp()
- self.res = 'policy'
- self.cmd_res = 'qos_policy'
- self.ress = "policies"
- self.cmd_ress = 'qos_policies'
-
- def test_create_policy_with_only_keyattributes(self):
- # Create qos policy abc.
- cmd = policy.CreateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- name = 'abc'
- args = [name]
- position_names = ['name']
- position_values = [name]
- self._test_create_resource(self.res, cmd, name, myid, args,
- position_names, position_values,
- cmd_resource=self.cmd_res)
-
- def test_create_policy_with_description(self):
- # Create qos policy xyz --description abc.
- cmd = policy.CreateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- name = 'abc'
- description = 'policy_abc'
- args = [name, '--description', description]
- position_names = ['name', 'description']
- position_values = [name, description]
- self._test_create_resource(self.res, cmd, name, myid, args,
- position_names, position_values,
- cmd_resource=self.cmd_res)
-
- def test_create_policy_with_shared(self):
- # Create qos policy abc shared across tenants
- cmd = policy.CreateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- name = 'abc'
- description = 'policy_abc'
- args = [name, '--description', description, '--shared']
- position_names = ['name', 'description', 'shared']
- position_values = [name, description, True]
- self._test_create_resource(self.res, cmd, name, myid, args,
- position_names, position_values,
- cmd_resource=self.cmd_res)
-
- def test_create_policy_with_unicode(self):
- # Create qos policy u'\u7f51\u7edc'.
- cmd = policy.CreateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- name = u'\u7f51\u7edc'
- description = u'\u7f51\u7edc'
- args = [name, '--description', description]
- position_names = ['name', 'description']
- position_values = [name, description]
- self._test_create_resource(self.res, cmd, name, myid, args,
- position_names, position_values,
- cmd_resource=self.cmd_res)
-
- def test_update_policy(self):
- # policy-update myid --name newname.
- cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(self.res, cmd, 'myid',
- ['myid', '--name', 'newname'],
- {'name': 'newname', },
- cmd_resource=self.cmd_res)
-
- def test_update_policy_description(self):
- # policy-update myid --name newname --description newdesc
- cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(self.res, cmd, 'myid',
- ['myid', '--description', 'newdesc'],
- {'description': 'newdesc', },
- cmd_resource=self.cmd_res)
-
- def test_update_policy_to_shared(self):
- # policy-update myid --shared
- cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(self.res, cmd, 'myid',
- ['myid', '--shared'],
- {'shared': True, },
- cmd_resource=self.cmd_res)
-
- def test_update_policy_to_no_shared(self):
- # policy-update myid --no-shared
- cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(self.res, cmd, 'myid',
- ['myid', '--no-shared'],
- {'shared': False, },
- cmd_resource=self.cmd_res)
-
- def test_update_policy_to_shared_no_shared_together(self):
- # policy-update myid --shared --no-shared
- cmd = policy.UpdateQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self.assertRaises(
- SystemExit,
- self._test_update_resource,
- self.res, cmd, 'myid',
- ['myid', '--shared', '--no-shared'], {},
- cmd_resource=self.cmd_res
- )
-
- def test_list_policies(self):
- # qos-policy-list.
- cmd = policy.ListQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(self.ress, cmd, True,
- cmd_resources=self.cmd_ress)
-
- def test_list_policies_pagination(self):
- # qos-policy-list for pagination.
- cmd = policy.ListQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination(self.ress, cmd,
- cmd_resources=self.cmd_ress)
-
- def test_list_policies_sort(self):
- # sorted list: qos-policy-list --sort-key name --sort-key id
- # --sort-key asc --sort-key desc
- cmd = policy.ListQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(self.ress, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"],
- cmd_resources=self.cmd_ress)
-
- def test_list_policies_limit(self):
- # size (1000) limited list: qos-policy-list -P.
- cmd = policy.ListQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(self.ress, cmd, page_size=1000,
- cmd_resources=self.cmd_ress)
-
- def test_show_policy_id(self):
- # qos-policy-show test_id.
- cmd = policy.ShowQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- args = ['--fields', 'id', self.test_id]
- self._test_show_resource(self.res, cmd, self.test_id, args,
- ['id'], cmd_resource=self.cmd_res)
-
- def test_show_policy_name(self):
- # qos-policy-show.
- cmd = policy.ShowQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- args = ['--fields', 'id', '--fields', 'name', self.test_id]
- self._test_show_resource(self.res, cmd, self.test_id,
- args, ['id', 'name'],
- cmd_resource=self.cmd_res)
-
- def test_delete_policy(self):
- # qos-policy-delete my-id.
- cmd = policy.DeleteQoSPolicy(test_cli20.MyApp(sys.stdout),
- None)
- my_id = 'myid1'
- args = [my_id]
- self._test_delete_resource(self.res, cmd, my_id, args,
- cmd_resource=self.cmd_res)
diff --git a/neutronclient/tests/unit/qos/test_cli20_rule.py b/neutronclient/tests/unit/qos/test_cli20_rule.py
deleted file mode 100644
index f77c3c4..0000000
--- a/neutronclient/tests/unit/qos/test_cli20_rule.py
+++ /dev/null
@@ -1,44 +0,0 @@
-# Copyright 2015 Huawei Technologies India Pvt Ltd.
-# 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 neutronclient.neutron.v2_0.qos import rule as qos_rule
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20QoSRuleJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['bandwidth_limit_rule',
- 'dscp_marking_rule',
- 'minimum_bandwidth_rule']
-
- def setUp(self):
- super(CLITestV20QoSRuleJSON, self).setUp()
-
- def test_list_qos_rule_types(self):
- # qos_rule_types.
- resources = 'rule_types'
- cmd_resources = 'qos_rule_types'
- response_contents = [{'type': 'bandwidth_limit'},
- {'type': 'dscp_marking'},
- {'type': 'minimum_bandwidth'}]
-
- cmd = qos_rule.ListQoSRuleTypes(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True,
- response_contents=response_contents,
- cmd_resources=cmd_resources)
diff --git a/neutronclient/tests/unit/test_auto_allocated_topology.py b/neutronclient/tests/unit/test_auto_allocated_topology.py
deleted file mode 100644
index e2f7e5b..0000000
--- a/neutronclient/tests/unit/test_auto_allocated_topology.py
+++ /dev/null
@@ -1,76 +0,0 @@
-# Copyright 2016 IBM
-# 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 neutronclient.neutron.v2_0 import auto_allocated_topology as aat
-from neutronclient.tests.unit import test_cli20
-
-
-class TestAutoAllocatedTopologyJSON(test_cli20.CLITestV20Base):
-
- def test_show_auto_allocated_topology_arg(self):
- resource = 'auto_allocated_topology'
- cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
- args = ['--tenant-id', self.test_id]
- self._test_show_resource(resource, cmd, self.test_id, args)
-
- def test_show_auto_allocated_topology_posarg(self):
- resource = 'auto_allocated_topology'
- cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
- args = ['some-tenant']
- self._test_show_resource(resource, cmd, "some-tenant", args)
-
- def test_show_auto_allocated_topology_no_arg(self):
- resource = 'auto_allocated_topology'
- cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
- args = []
- self._test_show_resource(resource, cmd, "None", args)
-
- def test_show_auto_allocated_topology_dry_run_as_tenant(self):
- resource = 'auto_allocated_topology'
- cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
- args = ['--dry-run']
- self._test_show_resource(resource, cmd, "None", args,
- fields=('dry-run',))
-
- def test_show_auto_allocated_topology_dry_run_as_admin(self):
- resource = 'auto_allocated_topology'
- cmd = aat.ShowAutoAllocatedTopology(test_cli20.MyApp(sys.stdout), None)
- args = ['--dry-run', 'some-tenant']
- self._test_show_resource(resource, cmd, "some-tenant", args,
- fields=('dry-run',))
-
- def test_delete_auto_allocated_topology_arg(self):
- resource = 'auto_allocated_topology'
- cmd = aat.DeleteAutoAllocatedTopology(test_cli20.MyApp(sys.stdout),
- None)
- args = ['--tenant-id', self.test_id]
- self._test_delete_resource(resource, cmd, self.test_id, args)
-
- def test_delete_auto_allocated_topology_posarg(self):
- resource = 'auto_allocated_topology'
- cmd = aat.DeleteAutoAllocatedTopology(test_cli20.MyApp(sys.stdout),
- None)
- args = ['some-tenant']
- self._test_delete_resource(resource, cmd, "some-tenant", args)
-
- def test_delete_auto_allocated_topology_no_arg(self):
- resource = 'auto_allocated_topology'
- cmd = aat.DeleteAutoAllocatedTopology(test_cli20.MyApp(sys.stdout),
- None)
- args = []
- self._test_delete_resource(resource, cmd, "None", args)
diff --git a/neutronclient/tests/unit/test_cli20.py b/neutronclient/tests/unit/test_cli20.py
deleted file mode 100644
index a067ee8..0000000
--- a/neutronclient/tests/unit/test_cli20.py
+++ /dev/null
@@ -1,1215 +0,0 @@
-# Copyright 2012 OpenStack Foundation.
-# 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 contextlib
-from io import StringIO
-import itertools
-import sys
-from unittest import mock
-import urllib.parse as urlparse
-
-from oslo_serialization import jsonutils
-from oslo_utils import encodeutils
-from oslotest import base
-import requests
-import yaml
-
-from neutronclient.common import constants
-from neutronclient.common import exceptions
-from neutronclient.common import utils
-from neutronclient.neutron import v2_0 as neutronV2_0
-from neutronclient.neutron.v2_0 import network
-from neutronclient import shell
-from neutronclient.v2_0 import client
-
-API_VERSION = "2.0"
-TOKEN = 'testtoken'
-ENDURL = 'localurl'
-REQUEST_ID = 'test_request_id'
-
-
-@contextlib.contextmanager
-def capture_std_streams():
- fake_stdout, fake_stderr = StringIO(), StringIO()
- stdout, stderr = sys.stdout, sys.stderr
- try:
- sys.stdout, sys.stderr = fake_stdout, fake_stderr
- yield fake_stdout, fake_stderr
- finally:
- sys.stdout, sys.stderr = stdout, stderr
-
-
-class FakeStdout(object):
-
- def __init__(self):
- self.content = []
-
- def write(self, text):
- self.content.append(text)
-
- def make_string(self):
- result = ''
- for line in self.content:
- result += encodeutils.safe_decode(line, 'utf-8')
- return result
-
-
-class MyRequest(requests.Request):
- def __init__(self, method=None):
- self.method = method
-
-
-class MyResp(requests.Response):
- def __init__(self, status_code, headers=None, reason=None,
- request=None, url=None):
- self.status_code = status_code
- self.headers = headers or {}
- self.reason = reason
- self.request = request or MyRequest()
- self.url = url
-
-
-class MyApp(object):
- def __init__(self, _stdout):
- self.stdout = _stdout
-
-
-def end_url(path, query=None):
- _url_str = ENDURL + "/v" + API_VERSION + path
- return query and _url_str + "?" + query or _url_str
-
-
-class MyUrlComparator(object):
- def __init__(self, lhs, client):
- self.lhs = lhs
- self.client = client
-
- def __eq__(self, rhs):
- lhsp = urlparse.urlparse(self.lhs)
- rhsp = urlparse.urlparse(rhs)
-
- lhs_qs = urlparse.parse_qsl(lhsp.query)
- rhs_qs = urlparse.parse_qsl(rhsp.query)
-
- return (lhsp.scheme == rhsp.scheme and
- lhsp.netloc == rhsp.netloc and
- lhsp.path == rhsp.path and
- len(lhs_qs) == len(rhs_qs) and
- set(lhs_qs) == set(rhs_qs))
-
- def __str__(self):
- return self.lhs
-
- def __repr__(self):
- return str(self)
-
-
-class MyComparator(object):
- def __init__(self, lhs, client):
- self.lhs = lhs
- self.client = client
-
- def _com_dict(self, lhs, rhs):
- if len(lhs) != len(rhs):
- return False
- for key, value in lhs.items():
- if key not in rhs:
- return False
- rhs_value = rhs[key]
- if not self._com(value, rhs_value):
- return False
- return True
-
- def _com_list(self, lhs, rhs):
- if len(lhs) != len(rhs):
- return False
- for lhs_value in lhs:
- if lhs_value not in rhs:
- return False
- return True
-
- def _com(self, lhs, rhs):
- if lhs is None:
- return rhs is None
- if isinstance(lhs, dict):
- if not isinstance(rhs, dict):
- return False
- return self._com_dict(lhs, rhs)
- if isinstance(lhs, list):
- if not isinstance(rhs, list):
- return False
- return self._com_list(lhs, rhs)
- if isinstance(lhs, tuple):
- if not isinstance(rhs, tuple):
- return False
- return self._com_list(lhs, rhs)
- return lhs == rhs
-
- def __eq__(self, rhs):
- if self.client:
- rhs = self.client.deserialize(rhs, 200)
- return self._com(self.lhs, rhs)
-
- def __repr__(self):
- if self.client:
- return self.client.serialize(self.lhs)
- return str(self.lhs)
-
-
-class ContainsKeyValue(object):
- """Checks whether key/value pair(s) are included in a dict parameter.
-
- This class just checks whether specifid key/value pairs passed in
- __init__() are included in a dict parameter. The comparison does not
- fail even if other key/value pair(s) exists in a target dict.
- """
-
- def __init__(self, expected):
- self._expected = expected
-
- def __eq__(self, other):
- if not isinstance(other, dict):
- return False
- for key, value in self._expected.items():
- if key not in other:
- return False
- if other[key] != value:
- return False
- return True
-
- def __repr__(self):
- return ('<%s (expected: %s)>' %
- (self.__class__.__name__, self._expected))
-
-
-class IsA(object):
- """Checks whether the parameter is of specific type."""
-
- def __init__(self, expected_type):
- self._expected_type = expected_type
-
- def __eq__(self, other):
- return isinstance(other, self._expected_type)
-
- def __repr__(self):
- return ('<%s (expected: %s)>' %
- (self.__class__.__name__, self._expected_type))
-
-
-class CLITestV20Base(base.BaseTestCase):
-
- test_id = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
- id_field = 'id'
-
- non_admin_status_resources = []
-
- def _find_resourceid(self, client, resource, name_or_id,
- cmd_resource=None, parent_id=None):
- return name_or_id
-
- def setUp(self, plurals=None):
- """Prepare the test environment."""
- super(CLITestV20Base, self).setUp()
- client.Client.EXTED_PLURALS.update(constants.PLURALS)
- if plurals is not None:
- client.Client.EXTED_PLURALS.update(plurals)
- self.metadata = {'plurals': client.Client.EXTED_PLURALS}
- self.endurl = ENDURL
- self.fake_stdout = FakeStdout()
-
- self.addCleanup(mock.patch.stopall)
- mock.patch('sys.stdout', new=self.fake_stdout).start()
- mock.patch('neutronclient.neutron.v2_0.find_resourceid_by_name_or_id',
- new=self._find_resourceid).start()
- mock.patch('neutronclient.neutron.v2_0.find_resourceid_by_id',
- new=self._find_resourceid).start()
-
- self.client = client.Client(token=TOKEN, endpoint_url=self.endurl)
-
- def register_non_admin_status_resource(self, resource_name):
- # TODO(amotoki):
- # It is recommended to define
- # "non_admin_status_resources in each test class rather than
- # using register_non_admin_status_resource method.
-
- # If we change self.non_admin_status_resources like this,
- # we need to ensure this should be an instance variable
- # to avoid changing the class variable.
- if (id(self.non_admin_status_resources) ==
- id(self.__class__.non_admin_status_resources)):
- self.non_admin_status_resources = (self.__class__.
- non_admin_status_resources[:])
- self.non_admin_status_resources.append(resource_name)
-
- def _test_create_resource(self, resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id=None, tags=None, admin_state_up=True,
- extra_body=None, cmd_resource=None,
- parent_id=None, no_api_call=False,
- expected_exception=None,
- **kwargs):
- if not cmd_resource:
- cmd_resource = resource
- if (resource in self.non_admin_status_resources):
- body = {resource: {}, }
- else:
- body = {resource: {'admin_state_up': admin_state_up, }, }
- if tenant_id:
- body[resource].update({'tenant_id': tenant_id})
- if tags:
- body[resource].update({'tags': tags})
- if extra_body:
- body[resource].update(extra_body)
- body[resource].update(kwargs)
-
- for i in range(len(position_names)):
- body[resource].update({position_names[i]: position_values[i]})
- ress = {resource:
- {self.id_field: myid}, }
- if name:
- ress[resource].update({'name': name})
- resstr = self.client.serialize(ress)
- # url method body
- resource_plural = self.client.get_resource_plural(cmd_resource)
- path = getattr(self.client, resource_plural + "_path")
- if parent_id:
- path = path % parent_id
- mock_body = MyComparator(body, self.client)
-
- cmd_parser = cmd.get_parser('create_' + resource)
- resp = (MyResp(200), resstr)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- if expected_exception:
- self.assertRaises(expected_exception,
- shell.run_command, cmd, cmd_parser, args)
- else:
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- if not no_api_call:
- mock_request.assert_called_once_with(
- end_url(path), 'POST',
- body=mock_body,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
- if not expected_exception:
- _str = self.fake_stdout.make_string()
- self.assertIn(myid, _str)
- if name:
- self.assertIn(name, _str)
-
- def _test_list_columns(self, cmd, resources,
- resources_out, args=('-f', 'json'),
- cmd_resources=None, parent_id=None):
- if not cmd_resources:
- cmd_resources = resources
-
- resstr = self.client.serialize(resources_out)
-
- path = getattr(self.client, cmd_resources + "_path")
- if parent_id:
- path = path % parent_id
- cmd_parser = cmd.get_parser("list_" + cmd_resources)
- resp = (MyResp(200), resstr)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- mock_request.assert_called_once_with(
- end_url(path), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
-
- def _test_list_resources(self, resources, cmd, detail=False, tags=(),
- fields_1=(), fields_2=(), page_size=None,
- sort_key=(), sort_dir=(), response_contents=None,
- base_args=None, path=None, cmd_resources=None,
- parent_id=None, output_format=None, query=""):
- if not cmd_resources:
- cmd_resources = resources
- if response_contents is None:
- contents = [{self.id_field: 'myid1', },
- {self.id_field: 'myid2', }, ]
- else:
- contents = response_contents
- reses = {resources: contents}
- resstr = self.client.serialize(reses)
- # url method body
- args = base_args if base_args is not None else []
- if detail:
- args.append('-D')
- if fields_1:
- for field in fields_1:
- args.append('--fields')
- args.append(field)
-
- if tags:
- args.append('--')
- args.append("--tag")
- for tag in tags:
- args.append(tag)
- tag_query = urlparse.urlencode(
- {'tag': encodeutils.safe_encode(tag)})
- if query:
- query += "&" + tag_query
- else:
- query = tag_query
- if (not tags) and fields_2:
- args.append('--')
- if fields_2:
- args.append("--fields")
- for field in fields_2:
- args.append(field)
- if detail:
- query = query and query + '&verbose=True' or 'verbose=True'
- for field in itertools.chain(fields_1, fields_2):
- if query:
- query += "&fields=" + field
- else:
- query = "fields=" + field
- if page_size:
- args.append("--page-size")
- args.append(str(page_size))
- if query:
- query += "&limit=%s" % page_size
- else:
- query = "limit=%s" % page_size
- if sort_key:
- for key in sort_key:
- args.append('--sort-key')
- args.append(key)
- if query:
- query += '&'
- query += 'sort_key=%s' % key
- if sort_dir:
- len_diff = len(sort_key) - len(sort_dir)
- if len_diff > 0:
- sort_dir = tuple(sort_dir) + ('asc',) * len_diff
- elif len_diff < 0:
- sort_dir = sort_dir[:len(sort_key)]
- for dir in sort_dir:
- args.append('--sort-dir')
- args.append(dir)
- if query:
- query += '&'
- query += 'sort_dir=%s' % dir
- if path is None:
- path = getattr(self.client, cmd_resources + "_path")
- if parent_id:
- path = path % parent_id
- if output_format:
- args.append('-f')
- args.append(output_format)
- cmd_parser = cmd.get_parser("list_" + cmd_resources)
- resp = (MyResp(200), resstr)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- mock_request.assert_called_once_with(
- MyUrlComparator(end_url(path, query), self.client),
- 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
- _str = self.fake_stdout.make_string()
- if response_contents is None:
- self.assertIn('myid1', _str)
- return _str
-
- def _test_list_resources_with_pagination(self, resources, cmd,
- base_args=None,
- cmd_resources=None,
- parent_id=None, query=""):
- if not cmd_resources:
- cmd_resources = resources
-
- path = getattr(self.client, cmd_resources + "_path")
- if parent_id:
- path = path % parent_id
- fake_query = "marker=myid2&limit=2"
- reses1 = {resources: [{'id': 'myid1', },
- {'id': 'myid2', }],
- '%s_links' % resources: [{'href': end_url(path, fake_query),
- 'rel': 'next'}]}
- reses2 = {resources: [{'id': 'myid3', },
- {'id': 'myid4', }]}
- resstr1 = self.client.serialize(reses1)
- resstr2 = self.client.serialize(reses2)
- cmd_parser = cmd.get_parser("list_" + cmd_resources)
- args = base_args if base_args is not None else []
- mock_request_calls = [
- mock.call(
- end_url(path, query), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN})),
- mock.call(
- MyUrlComparator(end_url(path, fake_query),
- self.client), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))]
- mock_request_resp = [(MyResp(200), resstr1), (MyResp(200), resstr2)]
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient,
- "request") as mock_request:
- mock_request.side_effect = mock_request_resp
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- self.assertEqual(2, mock_request.call_count)
- mock_request.assert_has_calls(mock_request_calls)
-
- def _test_update_resource(self, resource, cmd, myid, args, extrafields,
- cmd_resource=None, parent_id=None):
- if not cmd_resource:
- cmd_resource = resource
-
- body = {resource: extrafields}
- path = getattr(self.client, cmd_resource + "_path")
- if parent_id:
- path = path % (parent_id, myid)
- else:
- path = path % myid
- mock_body = MyComparator(body, self.client)
-
- cmd_parser = cmd.get_parser("update_" + cmd_resource)
- resp = (MyResp(204), None)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- mock_request.assert_called_once_with(
- MyUrlComparator(end_url(path), self.client),
- 'PUT',
- body=mock_body,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
- _str = self.fake_stdout.make_string()
- self.assertIn(myid, _str)
-
- def _test_show_resource(self, resource, cmd, myid, args, fields=(),
- cmd_resource=None, parent_id=None):
- if not cmd_resource:
- cmd_resource = resource
-
- query = "&".join(["fields=%s" % field for field in fields])
- expected_res = {resource:
- {self.id_field: myid,
- 'name': 'myname', }, }
- resstr = self.client.serialize(expected_res)
- path = getattr(self.client, cmd_resource + "_path")
- if parent_id:
- path = path % (parent_id, myid)
- else:
- path = path % myid
- cmd_parser = cmd.get_parser("show_" + cmd_resource)
- resp = (MyResp(200), resstr)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- mock_request.assert_called_once_with(
- end_url(path, query), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
- _str = self.fake_stdout.make_string()
- self.assertIn(myid, _str)
- self.assertIn('myname', _str)
-
- def _test_set_path_and_delete(self, path, parent_id, myid,
- mock_request_calls, mock_request_returns,
- delete_fail=False):
- return_val = 404 if delete_fail else 204
- if parent_id:
- path = path % (parent_id, myid)
- else:
- path = path % (myid)
- mock_request_returns.append((MyResp(return_val), None))
- mock_request_calls.append(mock.call(
- end_url(path), 'DELETE',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN})))
-
- def _test_delete_resource(self, resource, cmd, myid, args,
- cmd_resource=None, parent_id=None,
- extra_id=None, delete_fail=False):
- mock_request_calls = []
- mock_request_returns = []
- if not cmd_resource:
- cmd_resource = resource
- path = getattr(self.client, cmd_resource + "_path")
- self._test_set_path_and_delete(path, parent_id, myid,
- mock_request_calls,
- mock_request_returns)
- # extra_id is used to test for bulk_delete
- if extra_id:
- self._test_set_path_and_delete(path, parent_id, extra_id,
- mock_request_calls,
- mock_request_returns,
- delete_fail)
- cmd_parser = cmd.get_parser("delete_" + cmd_resource)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient,
- "request") as mock_request:
- mock_request.side_effect = mock_request_returns
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- mock_request.assert_has_calls(mock_request_calls)
- _str = self.fake_stdout.make_string()
- self.assertIn(myid, _str)
- if extra_id:
- self.assertIn(extra_id, _str)
-
- def _test_update_resource_action(self, resource, cmd, myid, action, args,
- body, expected_code=200, retval=None,
- cmd_resource=None):
- if not cmd_resource:
- cmd_resource = resource
- path = getattr(self.client, cmd_resource + "_path")
- path_action = '%s/%s' % (myid, action)
- cmd_parser = cmd.get_parser("update_" + cmd_resource)
- resp = (MyResp(expected_code), retval)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- mock_request.assert_called_once_with(
- end_url(path % path_action), 'PUT',
- body=MyComparator(body, self.client),
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))
- _str = self.fake_stdout.make_string()
- self.assertIn(myid, _str)
-
- def assert_mock_multiple_calls_with_same_arguments(
- self, mocked_method, expected_call, count):
- if count is None:
- self.assertLessEqual(1, mocked_method.call_count)
- else:
- self.assertEqual(count, mocked_method.call_count)
- mocked_method.assert_has_calls(
- [expected_call] * mocked_method.call_count)
-
-
-class TestListCommand(neutronV2_0.ListCommand):
- resource = 'test_resource'
- filter_attrs = [
- 'name',
- 'admin_state_up',
- {'name': 'foo', 'help': 'non-boolean attribute foo'},
- {'name': 'bar', 'help': 'boolean attribute bar',
- 'boolean': True},
- {'name': 'baz', 'help': 'integer attribute baz',
- 'argparse_kwargs': {'choices': ['baz1', 'baz2']}},
- ]
-
-
-class ListCommandTestCase(CLITestV20Base):
-
- def setUp(self):
- super(ListCommandTestCase, self).setUp()
- self.client.extend_list('test_resources', '/test_resources', None)
- setattr(self.client, 'test_resources_path', '/test_resources')
-
- def _test_list_resources_filter_params(self, base_args='', query=''):
- resources = 'test_resources'
- cmd = TestListCommand(MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- base_args=base_args.split(),
- query=query)
-
- def _test_list_resources_with_arg_error(self, base_args=''):
- resources = 'test_resources'
- cmd = TestListCommand(MyApp(sys.stdout), None)
- # argparse parse error leads to SystemExit
- self.assertRaises(SystemExit,
- self._test_list_resources,
- resources, cmd,
- base_args=base_args.split())
-
- def test_list_resources_without_filter(self):
- self._test_list_resources_filter_params()
-
- def test_list_resources_use_default_filter(self):
- self._test_list_resources_filter_params(
- base_args='--name val1 --admin-state-up False',
- query='name=val1&admin_state_up=False')
-
- def test_list_resources_use_custom_filter(self):
- self._test_list_resources_filter_params(
- base_args='--foo FOO --bar True',
- query='foo=FOO&bar=True')
-
- def test_list_resources_boolean_check_default_filter(self):
- self._test_list_resources_filter_params(
- base_args='--admin-state-up True', query='admin_state_up=True')
- self._test_list_resources_filter_params(
- base_args='--admin-state-up False', query='admin_state_up=False')
- self._test_list_resources_with_arg_error(
- base_args='--admin-state-up non-true-false')
-
- def test_list_resources_boolean_check_custom_filter(self):
- self._test_list_resources_filter_params(
- base_args='--bar True', query='bar=True')
- self._test_list_resources_filter_params(
- base_args='--bar False', query='bar=False')
- self._test_list_resources_with_arg_error(
- base_args='--bar non-true-false')
-
- def test_list_resources_argparse_kwargs(self):
- self._test_list_resources_filter_params(
- base_args='--baz baz1', query='baz=baz1')
- self._test_list_resources_filter_params(
- base_args='--baz baz2', query='baz=baz2')
- self._test_list_resources_with_arg_error(
- base_args='--bar non-choice')
-
-
-class ClientV2TestJson(CLITestV20Base):
- def test_do_request_unicode(self):
- unicode_text = u'\u7f51\u7edc'
- # url with unicode
- action = u'/test'
- expected_action = action
- # query string with unicode
- params = {'test': unicode_text}
- expect_query = urlparse.urlencode(utils.safe_encode_dict(params))
- # request body with unicode
- body = params
- expect_body = self.client.serialize(body)
- self.client.httpclient.auth_token = encodeutils.safe_encode(
- unicode_text)
- expected_auth_token = encodeutils.safe_encode(unicode_text)
- resp_headers = {'x-openstack-request-id': REQUEST_ID}
- resp = (MyResp(200, resp_headers), expect_body)
-
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- result = self.client.do_request('PUT', action, body=body,
- params=params)
-
- mock_request.assert_called_once_with(
- end_url(expected_action, query=expect_query),
- 'PUT', body=expect_body,
- headers=ContainsKeyValue({'X-Auth-Token': expected_auth_token}))
- # test response with unicode
- self.assertEqual(body, result)
-
- def test_do_request_error_without_response_body(self):
- params = {'test': 'value'}
- expect_query = urlparse.urlencode(params)
- self.client.httpclient.auth_token = 'token'
- resp_headers = {'x-openstack-request-id': REQUEST_ID}
- resp = (MyResp(400, headers=resp_headers, reason='An error'), '')
-
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- error = self.assertRaises(exceptions.NeutronClientException,
- self.client.do_request, 'PUT', '/test',
- body='', params=params)
-
- mock_request.assert_called_once_with(
- MyUrlComparator(end_url('/test', query=expect_query), self.client),
- 'PUT', body='',
- headers=ContainsKeyValue({'X-Auth-Token': 'token'}))
- expected_error = "An error\nNeutron server returns " \
- "request_ids: %s" % [REQUEST_ID]
- self.assertEqual(expected_error, str(error))
-
- def test_do_request_with_long_uri_exception(self):
- long_string = 'x' * 8200 # 8200 > MAX_URI_LEN:8192
- params = {'id': long_string}
- exception = self.assertRaises(exceptions.RequestURITooLong,
- self.client.do_request,
- 'GET', '/test', body='', params=params)
- self.assertNotEqual(0, exception.excess)
-
- def test_do_request_request_ids(self):
- params = {'test': 'value'}
- expect_query = urlparse.urlencode(params)
- self.client.httpclient.auth_token = 'token'
- body = params
- expect_body = self.client.serialize(body)
- resp_headers = {'x-openstack-request-id': REQUEST_ID}
- resp = (MyResp(200, resp_headers), expect_body)
-
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- result = self.client.do_request('PUT', '/test', body=body,
- params=params)
-
- mock_request.assert_called_once_with(
- MyUrlComparator(end_url('/test', query=expect_query), self.client),
- 'PUT', body=expect_body,
- headers=ContainsKeyValue({'X-Auth-Token': 'token'}))
-
- self.assertEqual(body, result)
- self.assertEqual([REQUEST_ID], result.request_ids)
-
- def test_list_request_ids_with_retrieve_all_true(self):
- path = '/test'
- resources = 'tests'
- fake_query = "marker=myid2&limit=2"
- reses1 = {resources: [{'id': 'myid1', },
- {'id': 'myid2', }],
- '%s_links' % resources: [{'href': end_url(path, fake_query),
- 'rel': 'next'}]}
- reses2 = {resources: [{'id': 'myid3', },
- {'id': 'myid4', }]}
- resstr1 = self.client.serialize(reses1)
- resstr2 = self.client.serialize(reses2)
- resp_headers = {'x-openstack-request-id': REQUEST_ID}
- resp = [(MyResp(200, resp_headers), resstr1),
- (MyResp(200, resp_headers), resstr2)]
- with mock.patch.object(self.client.httpclient, "request",
- side_effect=resp) as mock_request:
- result = self.client.list(resources, path)
-
- self.assertEqual(2, mock_request.call_count)
- mock_request.assert_has_calls([
- mock.call(
- end_url(path, ""), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN})),
- mock.call(
- MyUrlComparator(end_url(path, fake_query),
- self.client), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))])
-
- self.assertEqual([REQUEST_ID, REQUEST_ID], result.request_ids)
-
- def test_list_request_ids_with_retrieve_all_false(self):
- path = '/test'
- resources = 'tests'
- fake_query = "marker=myid2&limit=2"
- reses1 = {resources: [{'id': 'myid1', },
- {'id': 'myid2', }],
- '%s_links' % resources: [{'href': end_url(path, fake_query),
- 'rel': 'next'}]}
- reses2 = {resources: [{'id': 'myid3', },
- {'id': 'myid4', }]}
- resstr1 = self.client.serialize(reses1)
- resstr2 = self.client.serialize(reses2)
- resp_headers = {'x-openstack-request-id': REQUEST_ID}
- resp = [(MyResp(200, resp_headers), resstr1),
- (MyResp(200, resp_headers), resstr2)]
- with mock.patch.object(self.client.httpclient, "request",
- side_effect=resp) as mock_request:
- result = self.client.list(resources, path, retrieve_all=False)
- next(result)
- self.assertEqual([REQUEST_ID], result.request_ids)
- next(result)
- self.assertEqual([REQUEST_ID, REQUEST_ID], result.request_ids)
-
- self.assertEqual(2, mock_request.call_count)
- mock_request.assert_has_calls([
- mock.call(
- end_url(path, ""), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN})),
- mock.call(
- MyUrlComparator(end_url(path, fake_query), self.client), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': TOKEN}))])
-
- def test_deserialize_without_data(self):
- data = u''
- result = self.client.deserialize(data, 200)
- self.assertEqual(data, result)
-
- def test_update_resource(self):
- params = {'test': 'value'}
- expect_query = urlparse.urlencode(params)
- self.client.httpclient.auth_token = 'token'
- body = params
- expect_body = self.client.serialize(body)
- resp_headers = {'x-openstack-request-id': REQUEST_ID}
- resp = (MyResp(200, resp_headers), expect_body)
-
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- result = self.client._update_resource('/test', body=body,
- params=params)
-
- mock_request.assert_called_once_with(
- MyUrlComparator(end_url('/test', query=expect_query), self.client),
- 'PUT', body=expect_body,
- headers=ContainsKeyValue({'X-Auth-Token': 'token'}))
- self.assertNotIn('If-Match', mock_request.call_args[1]['headers'])
-
- self.assertEqual(body, result)
- self.assertEqual([REQUEST_ID], result.request_ids)
-
- def test_update_resource_with_revision_number(self):
- params = {'test': 'value'}
- expect_query = urlparse.urlencode(params)
- self.client.httpclient.auth_token = 'token'
- body = params
- expect_body = self.client.serialize(body)
- resp_headers = {'x-openstack-request-id': REQUEST_ID}
- resp = (MyResp(200, resp_headers), expect_body)
-
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- result = self.client._update_resource('/test', body=body,
- params=params,
- revision_number=1)
-
- mock_request.assert_called_once_with(
- MyUrlComparator(end_url('/test', query=expect_query), self.client),
- 'PUT', body=expect_body,
- headers=ContainsKeyValue(
- {'X-Auth-Token': 'token', 'If-Match': 'revision_number=1'}))
-
- self.assertEqual(body, result)
- self.assertEqual([REQUEST_ID], result.request_ids)
-
-
-class CLITestV20ExceptionHandler(CLITestV20Base):
-
- def _test_exception_handler_v20(
- self, expected_exception, status_code, expected_msg,
- error_type=None, error_msg=None, error_detail=None,
- request_id=None, error_content=None):
-
- resp = MyResp(status_code, {'x-openstack-request-id': request_id})
- if request_id is not None:
- expected_msg += "\nNeutron server returns " \
- "request_ids: %s" % [request_id]
- if error_content is None:
- error_content = {'NeutronError': {'type': error_type,
- 'message': error_msg,
- 'detail': error_detail}}
- expected_content = self.client._convert_into_with_meta(error_content,
- resp)
-
- e = self.assertRaises(expected_exception,
- client.exception_handler_v20,
- status_code, expected_content)
- self.assertEqual(status_code, e.status_code)
- self.assertEqual(expected_exception.__name__,
- e.__class__.__name__)
-
- if expected_msg is None:
- if error_detail:
- expected_msg = '\n'.join([error_msg, error_detail])
- else:
- expected_msg = error_msg
- self.assertEqual(expected_msg, e.message)
-
- def test_exception_handler_v20_ip_address_in_use(self):
- err_msg = ('Unable to complete operation for network '
- 'fake-network-uuid. The IP address fake-ip is in use.')
- self._test_exception_handler_v20(
- exceptions.IpAddressInUseClient, 409, err_msg,
- 'IpAddressInUse', err_msg, '', REQUEST_ID)
-
- def test_exception_handler_v20_neutron_known_error(self):
- known_error_map = [
- ('NetworkNotFound', exceptions.NetworkNotFoundClient, 404),
- ('PortNotFound', exceptions.PortNotFoundClient, 404),
- ('NetworkInUse', exceptions.NetworkInUseClient, 409),
- ('PortInUse', exceptions.PortInUseClient, 409),
- ('StateInvalid', exceptions.StateInvalidClient, 400),
- ('IpAddressInUse', exceptions.IpAddressInUseClient, 409),
- ('IpAddressGenerationFailure',
- exceptions.IpAddressGenerationFailureClient, 409),
- ('MacAddressInUse', exceptions.MacAddressInUseClient, 409),
- ('ExternalIpAddressExhausted',
- exceptions.ExternalIpAddressExhaustedClient, 400),
- ('OverQuota', exceptions.OverQuotaClient, 409),
- ('InvalidIpForNetwork', exceptions.InvalidIpForNetworkClient, 400),
- ('InvalidIpForSubnet', exceptions.InvalidIpForSubnetClient, 400),
- ('IpAddressAlreadyAllocated',
- exceptions.IpAddressAlreadyAllocatedClient, 400),
- ]
-
- error_msg = 'dummy exception message'
- error_detail = 'sample detail'
- for server_exc, client_exc, status_code in known_error_map:
- self._test_exception_handler_v20(
- client_exc, status_code,
- error_msg + '\n' + error_detail,
- server_exc, error_msg, error_detail, REQUEST_ID)
-
- def test_exception_handler_v20_neutron_known_error_without_detail(self):
- error_msg = 'Network not found'
- error_detail = ''
- self._test_exception_handler_v20(
- exceptions.NetworkNotFoundClient, 404,
- error_msg,
- 'NetworkNotFound', error_msg, error_detail, REQUEST_ID)
-
- def test_exception_handler_v20_unknown_error_to_per_code_exception(self):
- for status_code, client_exc in exceptions.HTTP_EXCEPTION_MAP.items():
- error_msg = 'Unknown error'
- error_detail = 'This is detail'
- self._test_exception_handler_v20(
- client_exc, status_code,
- error_msg + '\n' + error_detail,
- 'UnknownError', error_msg, error_detail, [REQUEST_ID])
-
- def test_exception_handler_v20_neutron_unknown_status_code(self):
- error_msg = 'Unknown error'
- error_detail = 'This is detail'
- self._test_exception_handler_v20(
- exceptions.NeutronClientException, 501,
- error_msg + '\n' + error_detail,
- 'UnknownError', error_msg, error_detail, REQUEST_ID)
-
- def test_exception_handler_v20_bad_neutron_error(self):
- for status_code, client_exc in exceptions.HTTP_EXCEPTION_MAP.items():
- error_content = {'NeutronError': {'unknown_key': 'UNKNOWN'}}
- self._test_exception_handler_v20(
- client_exc, status_code,
- expected_msg="{'unknown_key': 'UNKNOWN'}",
- error_content=error_content,
- request_id=REQUEST_ID)
-
- def test_exception_handler_v20_error_dict_contains_message(self):
- error_content = {'message': 'This is an error message'}
- for status_code, client_exc in exceptions.HTTP_EXCEPTION_MAP.items():
- self._test_exception_handler_v20(
- client_exc, status_code,
- expected_msg='This is an error message',
- error_content=error_content,
- request_id=REQUEST_ID)
-
- def test_exception_handler_v20_error_dict_not_contain_message(self):
- # 599 is not contained in HTTP_EXCEPTION_MAP.
- error_content = {'error': 'This is an error message'}
- expected_msg = '%s-%s' % (599, error_content)
- self._test_exception_handler_v20(
- exceptions.NeutronClientException, 599,
- expected_msg=expected_msg,
- request_id=None,
- error_content=error_content)
-
- def test_exception_handler_v20_default_fallback(self):
- # 599 is not contained in HTTP_EXCEPTION_MAP.
- error_content = 'This is an error message'
- expected_msg = '%s-%s' % (599, error_content)
- self._test_exception_handler_v20(
- exceptions.NeutronClientException, 599,
- expected_msg=expected_msg,
- request_id=None,
- error_content=error_content)
-
- def test_exception_status(self):
- e = exceptions.BadRequest()
- self.assertEqual(400, e.status_code)
-
- e = exceptions.BadRequest(status_code=499)
- self.assertEqual(499, e.status_code)
-
- # SslCertificateValidationError has no explicit status_code,
- # but should have a 'safe' defined fallback.
- e = exceptions.SslCertificateValidationError()
- self.assertIsNotNone(e.status_code)
-
- e = exceptions.SslCertificateValidationError(status_code=599)
- self.assertEqual(599, e.status_code)
-
- def test_connection_failed(self):
- self.client.httpclient.auth_token = 'token'
- excp = requests.exceptions.ConnectionError('Connection refused')
-
- with mock.patch.object(self.client.httpclient, "request",
- side_effect=excp) as mock_request:
- error = self.assertRaises(exceptions.ConnectionFailed,
- self.client.get, '/test')
-
- mock_request.assert_called_once_with(
- end_url('/test'), 'GET',
- body=None,
- headers=ContainsKeyValue({'X-Auth-Token': 'token'}))
- # NB: ConnectionFailed has no explicit status_code, so this
- # tests that there is a fallback defined.
- self.assertIsNotNone(error.status_code)
-
-
-class DictWithMetaTest(base.BaseTestCase):
-
- def test_dict_with_meta(self):
- body = {'test': 'value'}
- resp = MyResp(200, {'x-openstack-request-id': REQUEST_ID})
- obj = client._DictWithMeta(body, resp)
- self.assertEqual(body, obj)
-
- # Check request_ids attribute is added to obj
- self.assertTrue(hasattr(obj, 'request_ids'))
- self.assertEqual([REQUEST_ID], obj.request_ids)
-
-
-class TupleWithMetaTest(base.BaseTestCase):
-
- def test_tuple_with_meta(self):
- body = ('test', 'value')
- resp = MyResp(200, {'x-openstack-request-id': REQUEST_ID})
- obj = client._TupleWithMeta(body, resp)
- self.assertEqual(body, obj)
-
- # Check request_ids attribute is added to obj
- self.assertTrue(hasattr(obj, 'request_ids'))
- self.assertEqual([REQUEST_ID], obj.request_ids)
-
-
-class StrWithMetaTest(base.BaseTestCase):
-
- def test_str_with_meta(self):
- body = "test_string"
- resp = MyResp(200, {'x-openstack-request-id': REQUEST_ID})
- obj = client._StrWithMeta(body, resp)
- self.assertEqual(body, obj)
-
- # Check request_ids attribute is added to obj
- self.assertTrue(hasattr(obj, 'request_ids'))
- self.assertEqual([REQUEST_ID], obj.request_ids)
-
-
-class GeneratorWithMetaTest(base.BaseTestCase):
-
- body = {'test': 'value'}
- resp = MyResp(200, {'x-openstack-request-id': REQUEST_ID})
-
- def _pagination(self, collection, path, **params):
- obj = client._DictWithMeta(self.body, self.resp)
- yield obj
-
- def test_generator(self):
- obj = client._GeneratorWithMeta(self._pagination, 'test_collection',
- 'test_path', test_args='test_args')
- self.assertEqual(self.body, next(obj))
-
- self.assertTrue(hasattr(obj, 'request_ids'))
- self.assertEqual([REQUEST_ID], obj.request_ids)
-
-
-class CLITestV20OutputFormatter(CLITestV20Base):
-
- def _test_create_resource_with_formatter(self, fmt):
- resource = 'network'
- cmd = network.CreateNetwork(MyApp(sys.stdout), None)
- args = ['-f', fmt, 'myname']
- position_names = ['name']
- position_values = ['myname']
- self._test_create_resource(resource, cmd, 'myname', 'myid', args,
- position_names, position_values)
-
- def test_create_resource_table(self):
- self._test_create_resource_with_formatter('table')
- print(self.fake_stdout.content)
- # table data is contains in the third element.
- data = self.fake_stdout.content[2].split('\n')
- self.assertTrue(any(' id ' in d for d in data))
- self.assertTrue(any(' name ' in d for d in data))
-
- def test_create_resource_json(self):
- self._test_create_resource_with_formatter('json')
- data = jsonutils.loads(self.fake_stdout.make_string())
- self.assertEqual('myname', data['name'])
- self.assertEqual('myid', data['id'])
-
- def test_create_resource_yaml(self):
- self._test_create_resource_with_formatter('yaml')
- data = yaml.safe_load(self.fake_stdout.make_string())
- self.assertEqual('myname', data['name'])
- self.assertEqual('myid', data['id'])
-
- def _test_show_resource_with_formatter(self, fmt):
- resource = 'network'
- cmd = network.ShowNetwork(MyApp(sys.stdout), None)
- args = ['-f', fmt, '-F', 'id', '-F', 'name', 'myid']
- self._test_show_resource(resource, cmd, 'myid',
- args, ['id', 'name'])
-
- def test_show_resource_table(self):
- self._test_show_resource_with_formatter('table')
- data = self.fake_stdout.content[0].split('\n')
- self.assertTrue(any(' id ' in d for d in data))
- self.assertTrue(any(' name ' in d for d in data))
-
- def test_show_resource_json(self):
- self._test_show_resource_with_formatter('json')
- data = jsonutils.loads(''.join(self.fake_stdout.content))
- self.assertEqual('myname', data['name'])
- self.assertEqual('myid', data['id'])
-
- def test_show_resource_yaml(self):
- self._test_show_resource_with_formatter('yaml')
- data = yaml.safe_load(''.join(self.fake_stdout.content))
- self.assertEqual('myname', data['name'])
- self.assertEqual('myid', data['id'])
-
- @mock.patch.object(network.ListNetwork, "extend_list")
- def _test_list_resources_with_formatter(self, fmt, mock_extend_list):
- resources = 'networks'
- cmd = network.ListNetwork(MyApp(sys.stdout), None)
- # ListNetwork has its own extend_list, so we need to stub out it
- # to avoid an extra API call.
- self._test_list_resources(resources, cmd, output_format=fmt)
- mock_extend_list.assert_called_once_with(IsA(list), mock.ANY)
-
- def test_list_resources_table(self):
- self._test_list_resources_with_formatter('table')
- data = self.fake_stdout.content[0].split('\n')
- self.assertTrue(any(' id ' in d for d in data))
- self.assertTrue(any(' myid1 ' in d for d in data))
- self.assertTrue(any(' myid2 ' in d for d in data))
-
- def test_list_resources_json(self):
- self._test_list_resources_with_formatter('json')
- data = jsonutils.loads(''.join(self.fake_stdout.content))
- self.assertEqual(['myid1', 'myid2'], [d['id'] for d in data])
-
- def test_list_resources_yaml(self):
- self._test_list_resources_with_formatter('yaml')
- data = yaml.safe_load(''.join(self.fake_stdout.content))
- self.assertEqual(['myid1', 'myid2'], [d['id'] for d in data])
diff --git a/neutronclient/tests/unit/test_cli20_address_scope.py b/neutronclient/tests/unit/test_cli20_address_scope.py
deleted file mode 100644
index 902f7e6..0000000
--- a/neutronclient/tests/unit/test_cli20_address_scope.py
+++ /dev/null
@@ -1,175 +0,0 @@
-# Copyright 2015 Huawei Technologies India Pvt. Ltd.
-# 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 unittest import mock
-
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0 import address_scope
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20AddressScopeJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['address_scope']
-
- def setUp(self):
- super(CLITestV20AddressScopeJSON, self).setUp(plurals={'tags': 'tag'})
-
- def test_create_address_scope_with_minimum_option_ipv4(self):
- """Create address_scope: foo-address-scope with minimum option."""
- resource = 'address_scope'
- cmd = address_scope.CreateAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- name = 'foo-address-scope'
- myid = 'myid'
- args = [name, '4']
- position_names = ['name', 'ip_version']
- position_values = [name, 4]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_address_scope_with_minimum_option_ipv6(self):
- """Create address_scope: foo-address-scope with minimum option."""
- resource = 'address_scope'
- cmd = address_scope.CreateAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- name = 'foo-address-scope'
- myid = 'myid'
- args = [name, '6']
- position_names = ['name', 'ip_version']
- position_values = [name, 6]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_address_scope_with_minimum_option_bad_ip_version(self):
- """Create address_scope: foo-address-scope with minimum option."""
- resource = 'address_scope'
- cmd = address_scope.CreateAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- name = 'foo-address-scope'
- myid = 'myid'
- args = [name, '5']
- position_names = ['name', 'ip_version']
- position_values = [name, 5]
- self.assertRaises(SystemExit, self._test_create_resource,
- resource, cmd, name, myid, args, position_names,
- position_values)
-
- def test_create_address_scope_with_all_option(self):
- # Create address_scope: foo-address-scope with all options.
- resource = 'address_scope'
- cmd = address_scope.CreateAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- name = 'foo-address-scope'
- myid = 'myid'
- args = [name, '4', '--shared']
- position_names = ['name', 'ip_version', 'shared']
- position_values = [name, 4, True]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_address_scope_with_unicode(self):
- # Create address_scope: u'\u7f51\u7edc'.
- resource = 'address_scope'
- cmd = address_scope.CreateAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- name = u'\u7f51\u7edc'
- ip_version = u'4'
- myid = 'myid'
- args = [name, ip_version]
- position_names = ['name', 'ip_version']
- position_values = [name, 4]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_update_address_scope_exception(self):
- # Update address_scope (Negative) : myid.
- resource = 'address_scope'
- cmd = address_scope.UpdateAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- self.assertRaises(exceptions.CommandError, self._test_update_resource,
- resource, cmd, 'myid', ['myid'], {})
-
- def test_update_address_scope(self):
- # Update address_scope: myid --name newname-address-scope.
- resource = 'address_scope'
- cmd = address_scope.UpdateAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname-address-scope'],
- {'name': 'newname-address-scope'}
- )
- # Update address_scope: myid --shared
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--shared', 'True'],
- {'shared': "True"}
- )
-
- def test_list_address_scope(self):
- # address_scope-list.
- resources = "address_scopes"
- cmd = address_scope.ListAddressScope(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True)
-
- @mock.patch.object(address_scope.ListAddressScope, "extend_list")
- def test_list_address_scope_pagination(self, mock_extend_list):
- # address_scope-list.
- cmd = address_scope.ListAddressScope(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination("address_scopes",
- cmd)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_list_address_scope_sort(self):
- # sorted list:
- # address_scope-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "address_scopes"
- cmd = address_scope.ListAddressScope(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id", "ip_version"],
- sort_dir=["asc", "desc"])
-
- def test_list_address_scope_limit(self):
- # size (1000) limited list: address_scope-list -P.
- resources = "address_scopes"
- cmd = address_scope.ListAddressScope(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_address_scope(self):
- # Show address_scope: --fields id --fields name myid.
- resource = 'address_scope'
- cmd = address_scope.ShowAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', '--fields', 'name', self.test_id,
- '--fields', 'ip_version', '6']
- self._test_show_resource(resource, cmd, self.test_id, args,
- ['id', 'name', 'ip_version'])
-
- def test_delete_address_scope(self):
- # Delete address_scope: address_scope_id.
- resource = 'address_scope'
- cmd = address_scope.DeleteAddressScope(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
diff --git a/neutronclient/tests/unit/test_cli20_agents.py b/neutronclient/tests/unit/test_cli20_agents.py
deleted file mode 100644
index 7641d27..0000000
--- a/neutronclient/tests/unit/test_cli20_agents.py
+++ /dev/null
@@ -1,97 +0,0 @@
-# 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 oslo_serialization import jsonutils
-
-from neutronclient.neutron.v2_0 import agent
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20Agent(test_cli20.CLITestV20Base):
- def test_list_agents(self):
- contents = {'agents': [{'id': 'myname', 'agent_type': 'mytype',
- 'alive': True}]}
- args = ['-f', 'json']
- resources = "agents"
-
- cmd = agent.ListAgent(test_cli20.MyApp(sys.stdout), None)
- self._test_list_columns(cmd, resources, contents, args)
- _str = self.fake_stdout.make_string()
-
- returned_agents = jsonutils.loads(_str)
- self.assertEqual(1, len(returned_agents))
- ag = returned_agents[0]
- self.assertEqual(3, len(ag))
- self.assertIn("alive", ag.keys())
-
- def test_list_agents_field(self):
- contents = {'agents': [{'alive': True}]}
- args = ['-f', 'json']
- resources = "agents"
- smile = ':-)'
-
- cmd = agent.ListAgent(test_cli20.MyApp(sys.stdout), None)
- self._test_list_columns(cmd, resources, contents, args)
- _str = self.fake_stdout.make_string()
-
- returned_agents = jsonutils.loads(_str)
- self.assertEqual(1, len(returned_agents))
- ag = returned_agents[0]
- self.assertEqual(1, len(ag))
- self.assertIn("alive", ag.keys())
- self.assertIn(smile, ag.values())
-
- def test_list_agents_zone_field(self):
- contents = {'agents': [{'availability_zone': 'myzone'}]}
- args = ['-f', 'json']
- resources = "agents"
-
- cmd = agent.ListAgent(test_cli20.MyApp(sys.stdout), None)
- self._test_list_columns(cmd, resources, contents, args)
- _str = self.fake_stdout.make_string()
-
- returned_agents = jsonutils.loads(_str)
- self.assertEqual(1, len(returned_agents))
- ag = returned_agents[0]
- self.assertEqual(1, len(ag))
- self.assertIn("availability_zone", ag.keys())
- self.assertIn('myzone', ag.values())
-
- def test_update_agent(self):
- # agent-update myid --admin-state-down --description mydescr.
- resource = 'agent'
- cmd = agent.UpdateAgent(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(
- resource, cmd, 'myid',
- ['myid', '--admin-state-down', '--description', 'mydescr'],
- {'description': 'mydescr', 'admin_state_up': False}
- )
-
- def test_show_agent(self):
- # Show agent: --field id --field binary myid.
- resource = 'agent'
- cmd = agent.ShowAgent(test_cli20.MyApp(sys.stdout), None)
- args = ['--field', 'id', '--field', 'binary', self.test_id]
- self._test_show_resource(resource, cmd, self.test_id,
- args, ['id', 'binary'])
-
- def test_delete_agent(self):
- # Delete agent: myid.
- resource = 'agent'
- cmd = agent.DeleteAgent(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
diff --git a/neutronclient/tests/unit/test_cli20_agentschedulers.py b/neutronclient/tests/unit/test_cli20_agentschedulers.py
deleted file mode 100644
index 817909d..0000000
--- a/neutronclient/tests/unit/test_cli20_agentschedulers.py
+++ /dev/null
@@ -1,209 +0,0 @@
-# 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.
-#
-
-import sys
-from unittest import mock
-
-
-from neutronclient.neutron.v2_0 import agentscheduler
-from neutronclient.neutron.v2_0 import network
-from neutronclient.tests.unit import test_cli20
-
-
-AGENT_ID = 'agent_id1'
-NETWORK_ID = 'net_id1'
-ROUTER_ID = 'router_id1'
-
-
-class CLITestV20AgentScheduler(test_cli20.CLITestV20Base):
- def _test_add_to_agent(self, resource, cmd, cmd_args, destination,
- body, result):
- path = ((self.client.agent_path + destination) %
- cmd_args[0])
-
- result_str = self.client.serialize(result)
- return_tup = (test_cli20.MyResp(200), result_str)
-
- cmd_parser = cmd.get_parser('test_' + resource)
- parsed_args = cmd_parser.parse_args(cmd_args)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=return_tup) as mock_request:
- cmd.run(parsed_args)
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.end_url(path), 'POST',
- body=test_cli20.MyComparator(body, self.client),
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- def _test_remove_from_agent(self, resource, cmd, cmd_args, destination):
- path = ((self.client.agent_path + destination + '/%s') %
- cmd_args)
-
- return_tup = (test_cli20.MyResp(204), None)
- cmd_parser = cmd.get_parser('test_' + resource)
- parsed_args = cmd_parser.parse_args(cmd_args)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=return_tup) as mock_request:
- cmd.run(parsed_args)
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.end_url(path), 'DELETE',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
-
-class CLITestV20DHCPAgentScheduler(CLITestV20AgentScheduler):
-
- def test_add_network_to_agent(self):
- resource = 'agent'
- cmd = agentscheduler.AddNetworkToDhcpAgent(
- test_cli20.MyApp(sys.stdout), None)
- args = (AGENT_ID, NETWORK_ID)
- body = {'network_id': NETWORK_ID}
- result = {'network_id': 'net_id', }
- self._test_add_to_agent(resource, cmd, args, self.client.DHCP_NETS,
- body, result)
-
- def test_remove_network_from_agent(self):
- resource = 'agent'
- cmd = agentscheduler.RemoveNetworkFromDhcpAgent(
- test_cli20.MyApp(sys.stdout), None)
- args = (AGENT_ID, NETWORK_ID)
- self._test_remove_from_agent(resource, cmd, args,
- self.client.DHCP_NETS)
-
- @mock.patch.object(network.ListNetwork, "extend_list")
- def test_list_networks_on_agent(self, mock_extend_list):
- resources = 'networks'
- cmd = agentscheduler.ListNetworksOnDhcpAgent(
- test_cli20.MyApp(sys.stdout), None)
- agent_id = 'agent_id1'
- path = ((self.client.agent_path + self.client.DHCP_NETS) %
- agent_id)
- self._test_list_resources(resources, cmd, base_args=[agent_id],
- path=path)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_list_agents_hosting_network(self):
- resources = 'agent'
- cmd = agentscheduler.ListDhcpAgentsHostingNetwork(
- test_cli20.MyApp(sys.stdout), None)
- agent_id = 'agent_id1'
- path = ((self.client.network_path + self.client.DHCP_AGENTS) %
- agent_id)
- contents = {self.id_field: 'myid1', 'alive': True}
- self._test_list_resources(resources, cmd, base_args=[agent_id],
- path=path, response_contents=contents)
-
-
-class CLITestV20L3AgentScheduler(CLITestV20AgentScheduler):
-
- def test_add_router_to_agent(self):
- resource = 'agent'
- cmd = agentscheduler.AddRouterToL3Agent(
- test_cli20.MyApp(sys.stdout), None)
- args = (AGENT_ID, ROUTER_ID)
- body = {'router_id': ROUTER_ID}
- result = {'network_id': 'net_id', }
- self._test_add_to_agent(resource, cmd, args, self.client.L3_ROUTERS,
- body, result)
-
- def test_remove_router_from_agent(self):
- resource = 'agent'
- cmd = agentscheduler.RemoveRouterFromL3Agent(
- test_cli20.MyApp(sys.stdout), None)
- args = (AGENT_ID, ROUTER_ID)
- self._test_remove_from_agent(resource, cmd, args,
- self.client.L3_ROUTERS)
-
- def test_list_routers_on_agent(self):
- resources = 'router'
- cmd = agentscheduler.ListRoutersOnL3Agent(
- test_cli20.MyApp(sys.stdout), None)
- agent_id = 'agent_id1'
- path = ((self.client.agent_path + self.client.L3_ROUTERS) %
- agent_id)
- contents = {self.id_field: 'myid1', 'name': 'my_name'}
- self._test_list_resources(resources, cmd, base_args=[agent_id],
- path=path, response_contents=contents)
-
- def test_list_agents_hosting_router(self):
- resources = 'agent'
- cmd = agentscheduler.ListL3AgentsHostingRouter(
- test_cli20.MyApp(sys.stdout), None)
- agent_id = 'agent_id1'
- path = ((self.client.router_path + self.client.L3_AGENTS) %
- agent_id)
- contents = {self.id_field: 'myid1', 'alive': True}
- self._test_list_resources(resources, cmd, base_args=[agent_id],
- path=path, response_contents=contents)
-
-
-class CLITestV20LBaaSAgentScheduler(test_cli20.CLITestV20Base):
-
- def test_list_pools_on_agent(self):
- resources = 'pools'
- cmd = agentscheduler.ListPoolsOnLbaasAgent(
- test_cli20.MyApp(sys.stdout), None)
- agent_id = 'agent_id1'
- path = ((self.client.agent_path + self.client.LOADBALANCER_POOLS) %
- agent_id)
- self._test_list_resources(resources, cmd, base_args=[agent_id],
- path=path)
-
- def test_get_lbaas_agent_hosting_pool(self):
- resources = 'agent'
- cmd = agentscheduler.GetLbaasAgentHostingPool(
- test_cli20.MyApp(sys.stdout), None)
- pool_id = 'pool_id1'
- path = ((self.client.pool_path + self.client.LOADBALANCER_AGENT) %
- pool_id)
- contents = {self.id_field: 'myid1', 'alive': True}
- self._test_list_resources(resources, cmd, base_args=[pool_id],
- path=path, response_contents=contents)
-
-
-class CLITestV20LBaaSV2AgentScheduler(test_cli20.CLITestV20Base):
-
- def test_list_loadbalancers_on_agent(self):
- resources = 'loadbalancers'
- cmd = agentscheduler.ListLoadBalancersOnLbaasAgent(
- test_cli20.MyApp(sys.stdout), None)
- agent_id = 'agent_id1'
- path = ((self.client.agent_path + self.client.AGENT_LOADBALANCERS) %
- agent_id)
- self._test_list_resources(resources, cmd, base_args=[agent_id],
- path=path)
-
- def test_get_lbaas_agent_hosting_pool(self):
- resources = 'agent'
- cmd = agentscheduler.GetLbaasAgentHostingLoadBalancer(
- test_cli20.MyApp(sys.stdout), None)
- lb_id = 'lb_id1'
- path = ((self.client.lbaas_loadbalancer_path +
- self.client.LOADBALANCER_HOSTING_AGENT) % lb_id)
- contents = {self.id_field: 'myid1', 'alive': True}
- self._test_list_resources(resources, cmd, base_args=[lb_id],
- path=path, response_contents=contents)
diff --git a/neutronclient/tests/unit/test_cli20_az.py b/neutronclient/tests/unit/test_cli20_az.py
deleted file mode 100644
index cb127c5..0000000
--- a/neutronclient/tests/unit/test_cli20_az.py
+++ /dev/null
@@ -1,31 +0,0 @@
-# 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 neutronclient.neutron.v2_0 import availability_zone as az
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20Agent(test_cli20.CLITestV20Base):
- def test_list_agents(self):
- contents = {'availability_zones': [{'name': 'zone1',
- 'resource': 'network',
- 'state': 'available'},
- {'name': 'zone2',
- 'resource': 'router',
- 'state': 'unavailable'}]}
- args = ['-f', 'json']
- resources = "availability_zones"
-
- cmd = az.ListAvailabilityZone(test_cli20.MyApp(sys.stdout), None)
- self._test_list_columns(cmd, resources, contents, args)
diff --git a/neutronclient/tests/unit/test_cli20_extensions.py b/neutronclient/tests/unit/test_cli20_extensions.py
deleted file mode 100644
index cc29137..0000000
--- a/neutronclient/tests/unit/test_cli20_extensions.py
+++ /dev/null
@@ -1,45 +0,0 @@
-# Copyright 2013 NEC Corporation
-# 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 neutronclient.neutron.v2_0 import extension
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20Extension(test_cli20.CLITestV20Base):
- id_field = 'alias'
-
- def test_list_extensions(self):
- resources = 'extensions'
- cmd = extension.ListExt(test_cli20.MyApp(sys.stdout), None)
- contents = [{'alias': 'ext1', 'name': 'name1', 'other': 'other1'},
- {'alias': 'ext2', 'name': 'name2', 'other': 'other2'}]
- ret = self._test_list_resources(resources, cmd,
- response_contents=contents)
- ret_words = set(ret.split())
- # Check only the default columns are shown.
- self.assertIn('name', ret_words)
- self.assertIn('alias', ret_words)
- self.assertNotIn('other', ret_words)
-
- def test_show_extension(self):
- # -F option does not work for ext-show at the moment, so -F option
- # is not passed in the commandline args as other tests do.
- resource = 'extension'
- cmd = extension.ShowExt(test_cli20.MyApp(sys.stdout), None)
- args = [self.test_id]
- ext_alias = self.test_id
- self._test_show_resource(resource, cmd, ext_alias, args, fields=[])
diff --git a/neutronclient/tests/unit/test_cli20_floatingips.py b/neutronclient/tests/unit/test_cli20_floatingips.py
deleted file mode 100644
index d77bda6..0000000
--- a/neutronclient/tests/unit/test_cli20_floatingips.py
+++ /dev/null
@@ -1,193 +0,0 @@
-# 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 neutronclient.neutron.v2_0 import floatingip as fip
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20FloatingIpsJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['floatingip']
-
- def test_create_floatingip(self):
- # Create floatingip: fip1.
- resource = 'floatingip'
- cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
- name = 'fip1'
- myid = 'myid'
- args = [name, '--description', 'floats like a butterfly']
- position_names = ['floating_network_id']
- position_values = [name]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- description='floats like a butterfly')
-
- def test_create_floatingip_and_port(self):
- # Create floatingip: fip1.
- resource = 'floatingip'
- cmd = fip.CreateFloatingIP(test_cli20.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]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = [name, '--port-id', pid]
- position_names = ['floating_network_id', 'port_id']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_floatingip_and_port_and_address(self):
- # Create floatingip: fip1 with a given port and address.
- resource = 'floatingip'
- cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
- name = 'fip1'
- myid = 'myid'
- pid = 'mypid'
- addr = '10.0.0.99'
- args = [name, '--port_id', pid, '--fixed_ip_address', addr]
- position_names = ['floating_network_id', 'port_id', 'fixed_ip_address']
- position_values = [name, pid, addr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
- # Test dashed options
- args = [name, '--port-id', pid, '--fixed-ip-address', addr]
- position_names = ['floating_network_id', 'port_id', 'fixed_ip_address']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_floatingip_with_ip_address_of_floating_ip(self):
- # Create floatingip: fip1 with a given IP address of floating IP.
- resource = 'floatingip'
- cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
- name = 'fip1'
- myid = 'myid'
- addr = '10.0.0.99'
-
- args = [name, '--floating-ip-address', addr]
- position_values = [name, addr]
- position_names = ['floating_network_id', 'floating_ip_address']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_floatingip_with_subnet_id(self):
- # Create floatingip: fip1 on a given subnet id.
- resource = 'floatingip'
- cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
- name = 'fip1'
- myid = 'myid'
- subnet_id = 'mysubnetid'
-
- args = [name, '--subnet', subnet_id]
- position_values = [name, subnet_id]
- position_names = ['floating_network_id', 'subnet_id']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_floatingip_with_subnet_id_and_port(self):
- # Create floatingip: fip1 on a given subnet id and port.
- resource = 'floatingip'
- cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
- name = 'fip1'
- myid = 'myid'
- pid = 'mypid'
- subnet_id = 'mysubnetid'
-
- args = [name, '--subnet', subnet_id, '--port-id', pid]
- position_values = [name, subnet_id, pid]
- position_names = ['floating_network_id', 'subnet_id', 'port_id']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_floatingip_with_dns_name_and_dns_domain(self):
- # Create floatingip: fip1 with dns name and dns domain.
- resource = 'floatingip'
- cmd = fip.CreateFloatingIP(test_cli20.MyApp(sys.stdout), None)
- name = 'fip1'
- myid = 'myid'
- dns_name_name = 'my-floatingip'
- dns_domain_name = 'my-domain.org.'
- args = [name, '--dns-name', dns_name_name, '--dns-domain',
- dns_domain_name]
- position_names = ['floating_network_id', 'dns_name', 'dns_domain']
- position_values = [name, dns_name_name, dns_domain_name]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_list_floatingips(self):
- # list floatingips: -D.
- resources = 'floatingips'
- cmd = fip.ListFloatingIP(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_floatingips_pagination(self):
- resources = 'floatingips'
- cmd = fip.ListFloatingIP(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_floatingips_sort(self):
- # list floatingips:
- # --sort-key name --sort-key id --sort-key asc --sort-key desc
- resources = 'floatingips'
- cmd = fip.ListFloatingIP(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_floatingips_limit(self):
- # list floatingips: -P.
- resources = 'floatingips'
- cmd = fip.ListFloatingIP(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_delete_floatingip(self):
- # Delete floatingip: fip1.
- resource = 'floatingip'
- cmd = fip.DeleteFloatingIP(test_cli20.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 = fip.ShowFloatingIP(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_disassociate_ip(self):
- # Disassociate floating IP: myid.
- resource = 'floatingip'
- cmd = fip.DisassociateFloatingIP(test_cli20.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 = fip.AssociateFloatingIP(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'portid']
- self._test_update_resource(resource, cmd, 'myid',
- args, {"port_id": "portid"}
- )
diff --git a/neutronclient/tests/unit/test_cli20_metering.py b/neutronclient/tests/unit/test_cli20_metering.py
deleted file mode 100644
index 9ecf047..0000000
--- a/neutronclient/tests/unit/test_cli20_metering.py
+++ /dev/null
@@ -1,99 +0,0 @@
-# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
-#
-# 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 neutronclient.neutron.v2_0 import metering
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20MeteringJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['metering_label', 'metering_label_rule']
-
- def test_create_metering_label(self):
- # Create a metering label.
- resource = 'metering_label'
- cmd = metering.CreateMeteringLabel(
- test_cli20.MyApp(sys.stdout), None)
- name = 'my label'
- myid = 'myid'
- description = 'my description'
- args = [name, '--description', description, '--shared']
- position_names = ['name', 'description', 'shared']
- position_values = [name, description, True]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_list_metering_labels(self):
- resources = "metering_labels"
- cmd = metering.ListMeteringLabel(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd)
-
- def test_delete_metering_label(self):
- # Delete a metering label.
- resource = 'metering_label'
- cmd = metering.DeleteMeteringLabel(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
-
- def test_show_metering_label(self):
- resource = 'metering_label'
- cmd = metering.ShowMeteringLabel(
- 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_create_metering_label_rule(self):
- resource = 'metering_label_rule'
- cmd = metering.CreateMeteringLabelRule(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- metering_label_id = 'aaa'
- remote_ip_prefix = '10.0.0.0/24'
- direction = 'ingress'
- args = [metering_label_id, remote_ip_prefix, '--direction', direction,
- '--excluded']
- position_names = ['metering_label_id', 'remote_ip_prefix', 'direction',
- 'excluded']
- position_values = [metering_label_id, remote_ip_prefix,
- direction, True]
- self._test_create_resource(resource, cmd, metering_label_id,
- myid, args, position_names, position_values)
-
- def test_list_metering_label_rules(self):
- resources = "metering_label_rules"
- cmd = metering.ListMeteringLabelRule(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd)
-
- def test_delete_metering_label_rule(self):
- resource = 'metering_label_rule'
- cmd = metering.DeleteMeteringLabelRule(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
-
- def test_show_metering_label_rule(self):
- resource = 'metering_label_rule'
- cmd = metering.ShowMeteringLabelRule(
- test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', self.test_id]
- self._test_show_resource(resource, cmd, self.test_id,
- args, ['id'])
diff --git a/neutronclient/tests/unit/test_cli20_network.py b/neutronclient/tests/unit/test_cli20_network.py
deleted file mode 100644
index b1f69ac..0000000
--- a/neutronclient/tests/unit/test_cli20_network.py
+++ /dev/null
@@ -1,698 +0,0 @@
-# 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 itertools
-import sys
-from unittest import mock
-
-from oslo_serialization import jsonutils
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0 import network
-from neutronclient import shell
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20CreateNetworkJSON(test_cli20.CLITestV20Base):
- def setUp(self):
- super(CLITestV20CreateNetworkJSON, self).setUp(plurals={'tags': 'tag'})
-
- def _test_create_network(self, **kwargs):
- cmd = network.CreateNetwork(test_cli20.MyApp(sys.stdout), None)
- resource = kwargs.pop('resource', 'network')
-
- name = kwargs.pop('name', 'myname')
- myid = kwargs.pop('myid', 'myid')
- args = kwargs.pop('args', [name, ])
- position_names = kwargs.pop('position_names', ['name', ])
- position_values = kwargs.pop('position_values', [name, ])
-
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- **kwargs)
-
- def test_create_network(self):
- # Create net: myname.
- self._test_create_network()
-
- def test_create_network_with_unicode(self):
- # Create net: u'\u7f51\u7edc'.
- self._test_create_network(name=u'\u7f51\u7edc')
-
- def test_create_network_description(self):
- # Create net: --tenant_id tenantid myname.
- name = 'myname'
- args = ['--description', 'Nice network', name]
- self._test_create_network(name=name,
- args=args,
- description='Nice network')
-
- def test_create_network_tenant_underscore(self):
- # Create net: --tenant_id tenantid myname.
- name = 'myname'
- args = ['--tenant_id', 'tenantid', name]
- self._test_create_network(name=name, args=args, tenant_id="tenantid")
-
- def test_create_network_tenant_dash(self):
- # Test dashed options
- # Create net: --tenant_id tenantid myname.
- name = 'myname'
- args = ['--tenant-id', 'tenantid', name]
- self._test_create_network(name=name, args=args, tenant_id="tenantid")
-
- def test_create_network_provider_args(self):
- # Create net: with --provider arguments.
- # Test --provider attributes before network name
- name = 'myname'
- args = ['--provider:network_type', 'vlan',
- '--provider:physical_network', 'physnet1',
- '--provider:segmentation_id', '400', name]
- position_names = ['provider:network_type',
- 'provider:physical_network',
- 'provider:segmentation_id', 'name']
- position_values = ['vlan', 'physnet1', '400', name]
- self._test_create_network(name=name,
- args=args,
- position_names=position_names,
- position_values=position_values)
-
- def test_create_network_tags(self):
- # Create net: myname --tags a b.
- name = 'myname'
- args = [name, '--tags', 'a', 'b']
- self._test_create_network(name=name, args=args, tags=['a', 'b'])
-
- def test_create_network_state_underscore(self):
- # Create net: --admin_state_down myname.
- name = 'myname'
- args = ['--admin_state_down', name, ]
- self._test_create_network(name=name, args=args, admin_state_up=False)
-
- def test_create_network_state_dash(self):
- # Test dashed options
- name = 'myname'
- args = ['--admin-state-down', name, ]
- self._test_create_network(name=name, args=args, admin_state_up=False)
-
- def test_create_network_vlan_transparent(self):
- # Create net: myname --vlan-transparent True.
- name = 'myname'
- args = ['--vlan-transparent', 'True', name]
- self._test_create_network(name=name,
- args=args,
- vlan_transparent='True')
-
- def test_create_network_with_qos_policy(self):
- # Create net: --qos-policy mypolicy.
- name = 'myname'
- qos_policy_name = 'mypolicy'
- args = [name, '--qos-policy', qos_policy_name]
- position_names = ['name', 'qos_policy_id']
- position_values = [name, qos_policy_name]
- self._test_create_network(name=name,
- args=args,
- position_names=position_names,
- position_values=position_values)
-
- def test_create_network_with_az_hint(self):
- # Create net: --availability-zone-hint zone1
- # --availability-zone-hint zone2.
- name = 'myname'
- args = ['--availability-zone-hint', 'zone1',
- '--availability-zone-hint', 'zone2', name]
- position_names = ['availability_zone_hints', 'name']
- position_values = [['zone1', 'zone2'], name]
- self._test_create_network(name=name,
- args=args,
- position_names=position_names,
- position_values=position_values)
-
- def test_create_network_with_dns_domain(self):
- # Create net: --dns-domain my-domain.org.
- name = 'myname'
- dns_domain_name = 'my-domain.org.'
- args = [name, '--dns-domain', dns_domain_name]
- position_names = ['name', 'dns_domain']
- position_values = [name, dns_domain_name]
- self._test_create_network(name=name,
- args=args,
- position_names=position_names,
- position_values=position_values)
-
-
-class CLITestV20ListNetworkJSON(test_cli20.CLITestV20Base):
- def setUp(self):
- super(CLITestV20ListNetworkJSON, self).setUp(plurals={'tags': 'tag'})
-
- def test_list_nets_empty_with_column(self):
- resources = "networks"
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- reses = {resources: []}
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- # url method body
- query = "id=myfakeid"
- args = ['-c', 'id', '--', '--id', 'myfakeid']
- path = getattr(self.client, resources + "_path")
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request, \
- mock.patch.object(network.ListNetwork, "extend_list",
- return_value=None) as mock_extend_list:
- cmd_parser = cmd.get_parser("list_" + resources)
- shell.run_command(cmd, cmd_parser, args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(test_cli20.end_url(path, query),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
- _str = self.fake_stdout.make_string()
- self.assertEqual('\n', _str)
-
- def _test_list_networks(self, cmd, detail=False, tags=(),
- fields_1=(), fields_2=(), page_size=None,
- sort_key=(), sort_dir=(), base_args=None,
- query=''):
- resources = "networks"
- with mock.patch.object(network.ListNetwork, "extend_list",
- return_value=None) as mock_extend_list:
- self._test_list_resources(resources, cmd, detail, tags,
- fields_1, fields_2, page_size=page_size,
- sort_key=sort_key, sort_dir=sort_dir,
- base_args=base_args, query=query)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_list_nets_pagination(self):
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- with mock.patch.object(network.ListNetwork, "extend_list",
- return_value=None) as mock_extend_list:
- self._test_list_resources_with_pagination("networks", cmd)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_list_nets_sort(self):
- # list nets:
- # --sort-key name --sort-key id --sort-dir asc --sort-dir desc
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, sort_key=['name', 'id'],
- sort_dir=['asc', 'desc'])
-
- def test_list_nets_sort_with_keys_more_than_dirs(self):
- # list nets: --sort-key name --sort-key id --sort-dir desc
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, sort_key=['name', 'id'],
- sort_dir=['desc'])
-
- def test_list_nets_sort_with_dirs_more_than_keys(self):
- # list nets: --sort-key name --sort-dir desc --sort-dir asc
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, sort_key=['name'],
- sort_dir=['desc', 'asc'])
-
- def test_list_nets_limit(self):
- # list nets: -P.
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, page_size=1000)
-
- def test_list_nets_detail(self):
- # list nets: -D.
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, True)
-
- def test_list_nets_tags(self):
- # List nets: -- --tags a b.
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, tags=['a', 'b'])
-
- def test_list_nets_tags_with_unicode(self):
- # List nets: -- --tags u'\u7f51\u7edc'.
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, tags=[u'\u7f51\u7edc'])
-
- def test_list_nets_detail_tags(self):
- # List nets: -D -- --tags a b.
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, detail=True, tags=['a', 'b'])
-
- def _test_list_nets_extend_subnets(self, data, expected):
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- nets_path = getattr(self.client, 'networks_path')
- subnets_path = getattr(self.client, 'subnets_path')
- nets_query = ''
- filters = ''
- for n in data:
- for s in n['subnets']:
- filters = filters + "&id=%s" % s
- subnets_query = 'fields=id&fields=cidr' + filters
- with mock.patch.object(cmd, 'get_client',
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient,
- "request") as mock_request:
- resp1 = (test_cli20.MyResp(200),
- self.client.serialize({'networks': data}))
- resp2 = (test_cli20.MyResp(200),
- self.client.serialize({'subnets': [
- {'id': 'mysubid1', 'cidr': '192.168.1.0/24'},
- {'id': 'mysubid2', 'cidr': '172.16.0.0/24'},
- {'id': 'mysubid3', 'cidr': '10.1.1.0/24'}]}))
- mock_request.side_effect = [resp1, resp2]
- args = []
- cmd_parser = cmd.get_parser('list_networks')
- parsed_args = cmd_parser.parse_args(args)
- result = cmd.take_action(parsed_args)
-
- mock_get_client.assert_called_with()
- self.assertEqual(2, mock_request.call_count)
- mock_request.assert_has_calls([
- mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(nets_path, nets_query),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN})),
- mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(subnets_path, subnets_query),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))])
- _result = [x for x in result[1]]
- self.assertEqual(len(expected), len(_result))
- for res, exp in zip(_result, expected):
- self.assertEqual(len(exp), len(res))
- for obsrvd, expctd in zip(res, exp):
- self.assertEqual(expctd, obsrvd)
-
- def test_list_nets_extend_subnets(self):
- data = [{'id': 'netid1', 'name': 'net1', 'subnets': ['mysubid1']},
- {'id': 'netid2', 'name': 'net2', 'subnets': ['mysubid2',
- 'mysubid3']}]
- # id, name, subnets
- expected = [('netid1', 'net1', 'mysubid1 192.168.1.0/24'),
- ('netid2', 'net2',
- 'mysubid2 172.16.0.0/24\nmysubid3 10.1.1.0/24')]
- self._test_list_nets_extend_subnets(data, expected)
-
- def test_list_nets_extend_subnets_no_subnet(self):
- data = [{'id': 'netid1', 'name': 'net1', 'subnets': ['mysubid1']},
- {'id': 'netid2', 'name': 'net2', 'subnets': ['mysubid4']}]
- # id, name, subnets
- expected = [('netid1', 'net1', 'mysubid1 192.168.1.0/24'),
- ('netid2', 'net2', 'mysubid4 ')]
- self._test_list_nets_extend_subnets(data, expected)
-
- def test_list_nets_fields(self):
- # List nets: --fields a --fields b -- --fields c d.
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd,
- fields_1=['a', 'b'], fields_2=['c', 'd'])
-
- def _test_list_nets_columns(self, cmd, returned_body,
- args=('-f', 'json')):
- resources = 'networks'
- with mock.patch.object(network.ListNetwork, "extend_list",
- return_value=None) as mock_extend_list:
- self._test_list_columns(cmd, resources, returned_body, args=args)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_list_nets_defined_column(self):
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- returned_body = {"networks": [{"name": "buildname3",
- "id": "id3",
- "tenant_id": "tenant_3",
- "subnets": []}]}
- self._test_list_nets_columns(cmd, returned_body,
- args=['-f', 'json', '-c', 'id'])
- _str = self.fake_stdout.make_string()
- returned_networks = jsonutils.loads(_str)
- self.assertEqual(1, len(returned_networks))
- net = returned_networks[0]
- self.assertEqual(1, len(net))
- self.assertIn("id", net.keys())
-
- def test_list_nets_with_default_column(self):
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- returned_body = {"networks": [{"name": "buildname3",
- "id": "id3",
- "tenant_id": "tenant_3",
- "subnets": []}]}
- self._test_list_nets_columns(cmd, returned_body)
- _str = self.fake_stdout.make_string()
- returned_networks = jsonutils.loads(_str)
- self.assertEqual(1, len(returned_networks))
- net = returned_networks[0]
- self.assertEqual(3, len(net))
- self.assertEqual(0, len(set(net) ^ set(cmd.list_columns)))
-
- def test_list_external_nets_empty_with_column(self):
- resources = "networks"
- cmd = network.ListExternalNetwork(test_cli20.MyApp(sys.stdout), None)
- reses = {resources: []}
- resstr = self.client.serialize(reses)
- # url method body
- query = "router%3Aexternal=True&id=myfakeid"
- args = ['-c', 'id', '--', '--id', 'myfakeid']
- path = getattr(self.client, resources + "_path")
- resp = (test_cli20.MyResp(200), resstr)
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request, \
- mock.patch.object(network.ListNetwork, "extend_list",
- return_value=None) as mock_extend_list:
- cmd_parser = cmd.get_parser("list_" + resources)
- shell.run_command(cmd, cmd_parser, args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, query), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
- _str = self.fake_stdout.make_string()
- self.assertEqual('\n', _str)
-
- def _test_list_external_nets(self, resources, cmd,
- detail=False, tags=(),
- fields_1=(), fields_2=()):
- reses = {resources: [{'id': 'myid1', },
- {'id': 'myid2', }, ], }
-
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
-
- # url method body
- query = ""
- args = detail and ['-D', ] or []
- if fields_1:
- for field in fields_1:
- args.append('--fields')
- args.append(field)
- if tags:
- args.append('--')
- args.append("--tag")
- for tag in tags:
- args.append(tag)
- if (not tags) and fields_2:
- args.append('--')
- if fields_2:
- args.append("--fields")
- for field in fields_2:
- args.append(field)
- for field in itertools.chain(fields_1, fields_2):
- if query:
- query += "&fields=" + field
- else:
- query = "fields=" + field
- if query:
- query += '&router%3Aexternal=True'
- else:
- query += 'router%3Aexternal=True'
- for tag in tags:
- if query:
- query += "&tag=" + tag
- else:
- query = "tag=" + tag
- if detail:
- query = query and query + '&verbose=True' or 'verbose=True'
- path = getattr(self.client, resources + "_path")
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request, \
- mock.patch.object(network.ListNetwork, "extend_list",
- return_value=None) as mock_extend_list:
- cmd_parser = cmd.get_parser("list_" + resources)
- shell.run_command(cmd, cmd_parser, args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, query), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
- _str = self.fake_stdout.make_string()
-
- self.assertIn('myid1', _str)
-
- def test_list_external_nets_detail(self):
- # list external nets: -D.
- resources = "networks"
- cmd = network.ListExternalNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_external_nets(resources, cmd, True)
-
- def test_list_external_nets_tags(self):
- # List external nets: -- --tags a b.
- resources = "networks"
- cmd = network.ListExternalNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_external_nets(resources,
- cmd, tags=['a', 'b'])
-
- def test_list_external_nets_detail_tags(self):
- # List external nets: -D -- --tags a b.
- resources = "networks"
- cmd = network.ListExternalNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_external_nets(resources, cmd,
- detail=True, tags=['a', 'b'])
-
- def test_list_external_nets_fields(self):
- # List external nets: --fields a --fields b -- --fields c d.
- resources = "networks"
- cmd = network.ListExternalNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_external_nets(resources, cmd,
- fields_1=['a', 'b'],
- fields_2=['c', 'd'])
-
- def test_list_shared_networks(self):
- # list nets : --shared False
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_list_networks(cmd, base_args='--shared False'.split(),
- query='shared=False')
-
-
-class CLITestV20UpdateNetworkJSON(test_cli20.CLITestV20Base):
- def test_update_network_exception(self):
- # Update net: myid.
- resource = 'network'
- cmd = network.UpdateNetwork(test_cli20.MyApp(sys.stdout), None)
- self.assertRaises(exceptions.CommandError, self._test_update_resource,
- resource, cmd, 'myid', ['myid'], {})
-
- def test_update_network(self):
- # Update net: myid --name myname --tags a b.
- resource = 'network'
- cmd = network.UpdateNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'myname',
- '--tags', 'a', 'b', '--description',
- 'This network takes the scenic route'],
- {'name': 'myname', 'tags': ['a', 'b'],
- 'description': 'This network takes the '
- 'scenic route'})
-
- def test_update_network_with_unicode(self):
- # Update net: myid --name u'\u7f51\u7edc' --tags a b.
- resource = 'network'
- cmd = network.UpdateNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', u'\u7f51\u7edc',
- '--tags', 'a', 'b'],
- {'name': u'\u7f51\u7edc',
- 'tags': ['a', 'b'], }
- )
-
- def test_update_network_with_qos_policy(self):
- # Update net: myid --qos-policy mypolicy.
- resource = 'network'
- cmd = network.UpdateNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--qos-policy', 'mypolicy'],
- {'qos_policy_id': 'mypolicy', })
-
- def test_update_network_with_no_qos_policy(self):
- # Update net: myid --no-qos-policy.
- resource = 'network'
- cmd = network.UpdateNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--no-qos-policy'],
- {'qos_policy_id': None, })
-
- def test_update_network_with_dns_domain(self):
- # Update net: myid --dns-domain my-domain.org.
- resource = 'network'
- cmd = network.UpdateNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--dns-domain', 'my-domain.org.'],
- {'dns_domain': 'my-domain.org.', })
-
- def test_update_network_with_no_dns_domain(self):
- # Update net: myid --no-dns-domain
- resource = 'network'
- cmd = network.UpdateNetwork(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--no-dns-domain'],
- {'dns_domain': "", })
-
-
-class CLITestV20ShowNetworkJSON(test_cli20.CLITestV20Base):
- def test_show_network(self):
- # Show net: --fields id --fields name myid.
- resource = 'network'
- cmd = network.ShowNetwork(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'])
-
-
-class CLITestV20DeleteNetworkJSON(test_cli20.CLITestV20Base):
- def test_delete_network(self):
- # Delete net: myid.
- resource = 'network'
- cmd = network.DeleteNetwork(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
-
- def test_bulk_delete_network(self):
- # Delete net: myid1 myid2.
- resource = 'network'
- cmd = network.DeleteNetwork(test_cli20.MyApp(sys.stdout), None)
- myid1 = 'myid1'
- myid2 = 'myid2'
- args = [myid1, myid2]
- self._test_delete_resource(resource, cmd, myid1, args, extra_id=myid2)
-
- def test_bulk_delete_network_fail(self):
- # Delete net: myid1 myid2.
- resource = 'network'
- cmd = network.DeleteNetwork(test_cli20.MyApp(sys.stdout), None)
- myid1 = 'myid1'
- myid2 = 'myid2'
- args = [myid1, myid2]
- self.assertRaises(exceptions.NeutronCLIError,
- self._test_delete_resource,
- resource, cmd, myid1, args, extra_id=myid2,
- delete_fail=True)
-
-
-class CLITestV20ExtendListNetworkJSON(test_cli20.CLITestV20Base):
- def _build_test_data(self, data):
- subnet_ids = []
- response = []
- filters = ""
- for n in data:
- if 'subnets' in n:
- subnet_ids.extend(n['subnets'])
- for subnet_id in n['subnets']:
- filters = "%s&id=%s" % (filters, subnet_id)
- response.append({'id': subnet_id,
- 'cidr': '192.168.0.0/16'})
- resp_str = self.client.serialize({'subnets': response})
- resp = (test_cli20.MyResp(200), resp_str)
- return filters, resp
-
- def test_extend_list(self):
- data = [{'id': 'netid%d' % i, 'name': 'net%d' % i,
- 'subnets': ['mysubid%d' % i]}
- for i in range(10)]
- filters, response = self._build_test_data(data)
- path = getattr(self.client, 'subnets_path')
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=response) as mock_request:
- known_args, _vs = cmd.get_parser('create_subnets')\
- .parse_known_args()
- cmd.extend_list(data, known_args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(test_cli20.end_url(
- path, 'fields=id&fields=cidr' + filters), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- def test_extend_list_exceed_max_uri_len(self):
- data = [{'id': 'netid%d' % i, 'name': 'net%d' % i,
- 'subnets': ['mysubid%d' % i]}
- for i in range(10)]
- # Since in pagination we add &marker=<uuid> (44 symbols), total change
- # is 45 symbols. Single subnet takes 40 symbols (id=<uuid>&).
- # Because of it marker will take more space than single subnet filter,
- # and we expect neutron to send last 2 subnets in separate response.
- filters1, response1 = self._build_test_data(data[:len(data) - 2])
- filters2, response2 = self._build_test_data(data[len(data) - 2:])
- path = getattr(self.client, 'subnets_path')
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient,
- "request") as mock_request, \
- mock.patch.object(self.client.httpclient, "_check_uri_length",
- return_value=None) as mock_check_uri_length:
- # 1 char of extra URI len will cause a split in 2 requests
- mock_check_uri_length.side_effect = [
- exceptions.RequestURITooLong(excess=1), None, None]
- mock_request.side_effect = [response1, response2]
- known_args, _vs = cmd.get_parser('create_subnets')\
- .parse_known_args()
- cmd.extend_list(data, known_args)
-
- mock_get_client.assert_called_once_with()
- self.assertEqual(2, mock_request.call_count)
- mock_request.assert_has_calls([
- mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(
- path, 'fields=id&fields=cidr%s' % filters1),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN})),
- mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(
- path, 'fields=id&fields=cidr%s' % filters2),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))])
diff --git a/neutronclient/tests/unit/test_cli20_network_ip_availability.py b/neutronclient/tests/unit/test_cli20_network_ip_availability.py
deleted file mode 100644
index eb325a8..0000000
--- a/neutronclient/tests/unit/test_cli20_network_ip_availability.py
+++ /dev/null
@@ -1,54 +0,0 @@
-# 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 neutronclient.neutron.v2_0 import network_ip_availability
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20NetworkIPAvailability(test_cli20.CLITestV20Base):
-
- id_field = 'network_id'
-
- def _test_list_network_ip_availability(self, args, query):
- resources = "network_ip_availabilities"
- cmd = network_ip_availability.ListIpAvailability(test_cli20.MyApp
- (sys.stdout), None)
- self._test_list_resources(resources, cmd,
- base_args=args,
- query=query)
-
- def test_list_network_ip_availability(self):
- self._test_list_network_ip_availability(args=None,
- query='ip_version=4')
-
- def test_list_network_ip_availability_ipv6(self):
- self._test_list_network_ip_availability(
- args=['--ip-version', '6'], query='ip_version=6')
-
- def test_list_network_ip_availability_net_id_and_ipv4(self):
- self._test_list_network_ip_availability(
- args=['--ip-version', '4', '--network-id', 'myid'],
- query='ip_version=4&network_id=myid')
-
- def test_list_network_ip_availability_net_name_and_tenant_id(self):
- self._test_list_network_ip_availability(
- args=['--network-name', 'foo', '--tenant-id', 'mytenant'],
- query='network_name=foo&tenant_id=mytenant&ip_version=4')
-
- def test_show_network_ip_availability(self):
- resource = "network_ip_availability"
- cmd = network_ip_availability.ShowIpAvailability(
- test_cli20.MyApp(sys.stdout), None)
- self._test_show_resource(resource, cmd, self.test_id,
- args=[self.test_id])
diff --git a/neutronclient/tests/unit/test_cli20_port.py b/neutronclient/tests/unit/test_cli20_port.py
deleted file mode 100644
index ab7e956..0000000
--- a/neutronclient/tests/unit/test_cli20_port.py
+++ /dev/null
@@ -1,794 +0,0 @@
-# Copyright 2012 OpenStack Foundation.
-# 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 itertools
-import sys
-from unittest import mock
-
-
-from neutronclient.neutron.v2_0 import port
-from neutronclient import shell
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20PortJSON(test_cli20.CLITestV20Base):
- def setUp(self):
- super(CLITestV20PortJSON, self).setUp(plurals={'tags': 'tag'})
-
- def test_create_port(self):
- # Create port: netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = [netid, '--description', 'DESC']
- position_names = ['network_id']
- position_values = []
- position_values.extend([netid])
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- description='DESC')
-
- def test_create_port_extra_dhcp_opts_args(self):
- # Create port: netid --extra_dhcp_opt.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- extra_dhcp_opts = [{'opt_name': 'bootfile-name',
- 'opt_value': 'pxelinux.0'},
- {'opt_name': 'tftp-server',
- 'opt_value': '123.123.123.123'},
- {'opt_name': 'server-ip-address',
- 'opt_value': '123.123.123.45'}]
- args = [netid]
- for dhcp_opt in extra_dhcp_opts:
- args += ['--extra-dhcp-opt',
- ('opt_name=%(opt_name)s,opt_value=%(opt_value)s' %
- dhcp_opt)]
- position_names = ['network_id', 'extra_dhcp_opts']
- position_values = [netid, extra_dhcp_opts]
- position_values.extend([netid])
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_extra_dhcp_opts_args_ip_version(self):
- # Create port: netid --extra_dhcp_opt.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- extra_dhcp_opts = [{'opt_name': 'bootfile-name',
- 'opt_value': 'pxelinux.0',
- 'ip_version': "4"},
- {'opt_name': 'tftp-server',
- 'opt_value': '2001:192:168::1',
- 'ip_version': "6"},
- {'opt_name': 'server-ip-address',
- 'opt_value': '123.123.123.45',
- 'ip_version': "4"}]
- args = [netid]
- for dhcp_opt in extra_dhcp_opts:
- args += ['--extra-dhcp-opt',
- ('opt_name=%(opt_name)s,opt_value=%(opt_value)s,'
- 'ip_version=%(ip_version)s' %
- dhcp_opt)]
- position_names = ['network_id', 'extra_dhcp_opts']
- position_values = [netid, extra_dhcp_opts]
- position_values.extend([netid])
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_full(self):
- # Create port: --mac_address mac --device_id deviceid netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--mac_address', 'mac', '--device_id', 'deviceid', netid]
- position_names = ['network_id', 'mac_address', 'device_id']
- position_values = [netid, 'mac', 'deviceid']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--mac-address', 'mac', '--device-id', 'deviceid', netid]
- position_names = ['network_id', 'mac_address', 'device_id']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_vnic_type_normal(self):
- # Create port: --vnic_type normal netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--vnic_type', 'normal', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['normal', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--vnic-type', 'normal', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['normal', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_vnic_type_direct(self):
- # Create port: --vnic_type direct netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--vnic_type', 'direct', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['direct', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--vnic-type', 'direct', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['direct', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_vnic_type_direct_physical(self):
- # Create port: --vnic_type direct-physical netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--vnic_type', 'direct-physical', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['direct-physical', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--vnic-type', 'direct-physical', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['direct-physical', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_vnic_type_macvtap(self):
- # Create port: --vnic_type macvtap netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--vnic_type', 'macvtap', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['macvtap', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--vnic-type', 'macvtap', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['macvtap', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_vnic_type_baremetal(self):
- # Create port: --vnic_type baremetal netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--vnic_type', 'baremetal', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['baremetal', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--vnic-type', 'baremetal', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['baremetal', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_vnic_type_smart_nic(self):
- # Create port: --vnic_type smart-nic netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--vnic_type', 'smart-nic', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['smart-nic', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--vnic-type', 'smart-nic', netid]
- position_names = ['binding:vnic_type', 'network_id']
- position_values = ['smart-nic', netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_with_binding_profile(self):
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--binding_profile', '{"foo":"bar"}', netid]
- position_names = ['binding:profile', 'network_id']
- position_values = [{'foo': 'bar'}, netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- # Test dashed options
- args = ['--binding-profile', '{"foo":"bar"}', netid]
- position_names = ['binding:profile', 'network_id']
- position_values = [{'foo': 'bar'}, netid]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_tenant(self):
- # Create port: --tenant_id tenantid netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--tenant_id', 'tenantid', netid, ]
- position_names = ['network_id']
- position_values = []
- position_values.extend([netid])
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- # Test dashed options
- args = ['--tenant-id', 'tenantid', netid, ]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_port_tags(self):
- # Create port: netid mac_address device_id --tags a b.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = [netid, '--tags', 'a', 'b']
- position_names = ['network_id']
- position_values = []
- position_values.extend([netid])
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tags=['a', 'b'])
-
- def test_create_port_secgroup(self):
- # Create port: --security-group sg1_id netid.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--security-group', 'sg1_id', netid]
- position_names = ['network_id', 'security_groups']
- position_values = [netid, ['sg1_id']]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_secgroups(self):
- # Create port: <security_groups> netid
- # The <security_groups> are --security-group sg1_id
- # --security-group sg2_id
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--security-group', 'sg1_id',
- '--security-group', 'sg2_id',
- netid]
- position_names = ['network_id', 'security_groups']
- position_values = [netid, ['sg1_id', 'sg2_id']]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_secgroup_off(self):
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--no-security-groups', netid]
- position_names = ['network_id', 'security_groups']
- position_values = [netid, []]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_secgroups_list(self):
- # Create port: netid <security_groups>
- # The <security_groups> are --security-groups list=true sg_id1 sg_id2
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = [netid, '--security-groups', 'list=true', 'sg_id1', 'sg_id2']
- position_names = ['network_id', 'security_groups']
- position_values = [netid, ['sg_id1', 'sg_id2']]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_with_qos_policy(self):
- # Create port: --qos-policy mypolicy.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- qos_policy_name = 'mypolicy'
- args = [netid, '--qos-policy', qos_policy_name]
- position_names = ['network_id', 'qos_policy_id']
- position_values = [netid, qos_policy_name]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_with_dns_name(self):
- # Create port: --dns-name my-port.
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- dns_name_name = 'my-port'
- args = [netid, '--dns-name', dns_name_name]
- position_names = ['network_id', 'dns_name']
- position_values = [netid, dns_name_name]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_with_allowed_address_pair_ipaddr(self):
- # Create port:
- # --allowed-address-pair ip_address=addr0
- # --allowed-address-pair ip_address=addr1
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- pairs = [{'ip_address': '123.123.123.123'},
- {'ip_address': '123.123.123.45'}]
- args = [netid,
- '--allowed-address-pair',
- 'ip_address=123.123.123.123',
- '--allowed-address-pair',
- 'ip_address=123.123.123.45']
- position_names = ['network_id', 'allowed_address_pairs']
- position_values = [netid, pairs]
- position_values.extend([netid])
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_port_with_allowed_address_pair(self):
- # Create port:
- # --allowed-address-pair ip_address=addr0,mac_address=mac0
- # --allowed-address-pair ip_address=addr1,mac_address=mac1
- resource = 'port'
- cmd = port.CreatePort(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- pairs = [{'ip_address': '123.123.123.123',
- 'mac_address': '10:00:00:00:00:00'},
- {'ip_address': '123.123.123.45',
- 'mac_address': '10:00:00:00:00:01'}]
- args = [netid,
- '--allowed-address-pair',
- 'ip_address=123.123.123.123,mac_address=10:00:00:00:00:00',
- '--allowed-address-pair',
- 'ip_address=123.123.123.45,mac_address=10:00:00:00:00:01']
- position_names = ['network_id', 'allowed_address_pairs']
- position_values = [netid, pairs]
- position_values.extend([netid])
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_list_ports(self):
- # List ports: -D.
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_ports_pagination(self):
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_ports_sort(self):
- # list ports:
- # --sort-key name --sort-key id --sort-key asc --sort-key desc
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_ports_limit(self):
- # list ports: -P.
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_list_ports_tags(self):
- # List ports: -- --tags a b.
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, tags=['a', 'b'])
-
- def test_list_ports_detail_tags(self):
- # List ports: -D -- --tags a b.
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, detail=True, tags=['a', 'b'])
-
- def test_list_ports_fields(self):
- # List ports: --fields a --fields b -- --fields c d.
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- fields_1=['a', 'b'], fields_2=['c', 'd'])
-
- def test_list_ports_with_fixed_ips_in_csv(self):
- # List ports: -f csv.
- resources = "ports"
- cmd = port.ListPort(test_cli20.MyApp(sys.stdout), None)
- fixed_ips = [{"subnet_id": "30422057-d6df-4c90-8314-aefb5e326666",
- "ip_address": "10.0.0.12"},
- {"subnet_id": "30422057-d6df-4c90-8314-aefb5e326666",
- "ip_address": "10.0.0.4"}]
- contents = [{'name': 'name1', 'fixed_ips': fixed_ips}]
- self._test_list_resources(resources, cmd, True,
- response_contents=contents,
- output_format='csv')
-
- def _test_list_router_port(self, resources, cmd,
- myid, detail=False, tags=(),
- fields_1=(), fields_2=()):
- reses = {resources: [{'id': 'myid1', },
- {'id': 'myid2', }, ], }
-
- resstr = self.client.serialize(reses)
- # url method body
- query = ""
- args = detail and ['-D', ] or []
-
- if fields_1:
- for field in fields_1:
- args.append('--fields')
- args.append(field)
- args.append(myid)
- if tags:
- args.append('--')
- args.append("--tag")
- for tag in tags:
- args.append(tag)
- if (not tags) and fields_2:
- args.append('--')
- if fields_2:
- args.append("--fields")
- for field in fields_2:
- args.append(field)
- for field in itertools.chain(fields_1, fields_2):
- if query:
- query += "&fields=" + field
- else:
- query = "fields=" + field
-
- for tag in tags:
- if query:
- query += "&tag=" + tag
- else:
- query = "tag=" + tag
- if detail:
- query = query and query + '&verbose=True' or 'verbose=True'
- query = query and query + '&device_id=%s' or 'device_id=%s'
- path = getattr(self.client, resources + "_path")
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=(test_cli20.MyResp(200),
- resstr)) as mock_request:
- cmd_parser = cmd.get_parser("list_" + resources)
- shell.run_command(cmd, cmd_parser, args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), 2)
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, query % myid), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- _str = self.fake_stdout.make_string()
-
- self.assertIn('myid1', _str)
-
- def test_list_router_ports(self):
- # List router ports: -D.
- resources = "ports"
- cmd = port.ListRouterPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_router_port(resources, cmd,
- self.test_id, True)
-
- def test_list_router_ports_tags(self):
- # List router ports: -- --tags a b.
- resources = "ports"
- cmd = port.ListRouterPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_router_port(resources, cmd,
- self.test_id, tags=['a', 'b'])
-
- def test_list_router_ports_detail_tags(self):
- # List router ports: -D -- --tags a b.
- resources = "ports"
- cmd = port.ListRouterPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_router_port(resources, cmd, self.test_id,
- detail=True, tags=['a', 'b'])
-
- def test_list_router_ports_fields(self):
- # List ports: --fields a --fields b -- --fields c d.
- resources = "ports"
- cmd = port.ListRouterPort(test_cli20.MyApp(sys.stdout), None)
- self._test_list_router_port(resources, cmd, self.test_id,
- fields_1=['a', 'b'],
- fields_2=['c', 'd'])
-
- def test_update_port(self):
- # Update port: myid --name myname --admin-state-up False --tags a b.
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'myname',
- '--admin-state-up', 'False',
- '--description', 'garbage',
- '--tags', 'a', 'b'],
- {'name': 'myname',
- 'admin_state_up': 'False',
- 'description': 'garbage',
- 'tags': ['a', 'b'], })
-
- def test_update_port_secgroup(self):
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = ['--security-group', 'sg1_id', myid]
- updatefields = {'security_groups': ['sg1_id']}
- self._test_update_resource(resource, cmd, myid, args, updatefields)
-
- def test_update_port_secgroups(self):
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = ['--security-group', 'sg1_id',
- '--security-group', 'sg2_id',
- myid]
- updatefields = {'security_groups': ['sg1_id', 'sg2_id']}
- self._test_update_resource(resource, cmd, myid, args, updatefields)
-
- def test_update_port_extra_dhcp_opts(self):
- # Update port: myid --extra_dhcp_opt.
- resource = 'port'
- myid = 'myid'
- args = [myid,
- '--extra-dhcp-opt',
- "opt_name=bootfile-name,opt_value=pxelinux.0",
- '--extra-dhcp-opt',
- "opt_name=tftp-server,opt_value=123.123.123.123",
- '--extra-dhcp-opt',
- "opt_name=server-ip-address,opt_value=123.123.123.45"
- ]
- updatedfields = {'extra_dhcp_opts': [{'opt_name': 'bootfile-name',
- 'opt_value': 'pxelinux.0'},
- {'opt_name': 'tftp-server',
- 'opt_value': '123.123.123.123'},
- {'opt_name': 'server-ip-address',
- 'opt_value': '123.123.123.45'}]}
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, myid, args, updatedfields)
-
- def test_update_port_fixed_ip(self):
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- subnet_id = 'subnet_id'
- ip_addr = '123.123.123.123'
- args = [myid,
- '--fixed-ip',
- "subnet_id=%(subnet_id)s,ip_address=%(ip_addr)s" %
- {'subnet_id': subnet_id,
- 'ip_addr': ip_addr}]
- updated_fields = {"fixed_ips": [{'subnet_id': subnet_id,
- 'ip_address': ip_addr}]}
- self._test_update_resource(resource, cmd, myid, args, updated_fields)
-
- def test_update_port_device_id_device_owner(self):
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = ['--device-id', 'dev_id', '--device-owner', 'fake', myid]
- updatefields = {'device_id': 'dev_id',
- 'device_owner': 'fake'}
- self._test_update_resource(resource, cmd, myid, args, updatefields)
-
- def test_update_port_extra_dhcp_opts_ip_version(self):
- # Update port: myid --extra_dhcp_opt.
- resource = 'port'
- myid = 'myid'
- args = [myid,
- '--extra-dhcp-opt',
- "opt_name=bootfile-name,opt_value=pxelinux.0,ip_version=4",
- '--extra-dhcp-opt',
- "opt_name=tftp-server,opt_value=2001:192:168::1,ip_version=6",
- '--extra-dhcp-opt',
- "opt_name=server-ip-address,opt_value=null,ip_version=4"
- ]
- updatedfields = {'extra_dhcp_opts': [{'opt_name': 'bootfile-name',
- 'opt_value': 'pxelinux.0',
- 'ip_version': '4'},
- {'opt_name': 'tftp-server',
- 'opt_value': '2001:192:168::1',
- 'ip_version': '6'},
- {'opt_name': 'server-ip-address',
- 'opt_value': None,
- 'ip_version': '4'}]}
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, myid, args, updatedfields)
-
- def test_update_port_with_qos_policy(self):
- # Update port: myid --qos-policy mypolicy.
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--qos-policy', 'mypolicy'],
- {'qos_policy_id': 'mypolicy', })
-
- def test_update_port_with_no_qos_policy(self):
- # Update port: myid --no-qos-policy.
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--no-qos-policy'],
- {'qos_policy_id': None, })
-
- def test_update_port_with_dns_name(self):
- # Update port: myid --dns-name my-port.
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--dns-name', 'my-port'],
- {'dns_name': 'my-port', })
-
- def test_update_port_with_no_dns_name(self):
- # Update port: myid --no-dns-name
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--no-dns-name'],
- {'dns_name': "", })
-
- def test_delete_extra_dhcp_opts_from_port(self):
- resource = 'port'
- myid = 'myid'
- args = [myid,
- '--extra-dhcp-opt',
- "opt_name=bootfile-name,opt_value=null",
- '--extra-dhcp-opt',
- "opt_name=tftp-server,opt_value=123.123.123.123",
- '--extra-dhcp-opt',
- "opt_name=server-ip-address,opt_value=123.123.123.45"
- ]
- # the client code will change the null to None and send to server,
- # where its interpreted as delete the DHCP option on the port.
- updatedfields = {'extra_dhcp_opts': [{'opt_name': 'bootfile-name',
- 'opt_value': None},
- {'opt_name': 'tftp-server',
- 'opt_value': '123.123.123.123'},
- {'opt_name': 'server-ip-address',
- 'opt_value': '123.123.123.45'}]}
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, myid, args, updatedfields)
-
- def test_update_port_security_group_off(self):
- # Update port: --no-security-groups myid.
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['--no-security-groups', 'myid'],
- {'security_groups': []})
-
- def test_update_port_allowed_address_pair_ipaddr(self):
- # Update port(ip_address only):
- # --allowed-address-pairs ip_address=addr0
- # --allowed-address-pairs ip_address=addr1
- import sys
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- pairs = [{'ip_address': '123.123.123.123'},
- {'ip_address': '123.123.123.45'}]
- args = [myid,
- '--allowed-address-pair',
- 'ip_address=123.123.123.123',
- '--allowed-address-pair',
- 'ip_address=123.123.123.45']
- updatefields = {'allowed_address_pairs': pairs}
- self._test_update_resource(resource, cmd, myid, args, updatefields)
-
- def test_update_port_allowed_address_pair(self):
- # Update port:
- # --allowed-address-pair ip_address=addr0,mac_address=mac0
- # --allowed-address-pair ip_address_addr1,mac_address=mac1
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- pairs = [{'ip_address': '123.123.123.123',
- 'mac_address': '10:00:00:00:00:00'},
- {'ip_address': '123.123.123.45',
- 'mac_address': '10:00:00:00:00:01'}]
- args = [myid,
- '--allowed-address-pair',
- 'ip_address=123.123.123.123,mac_address=10:00:00:00:00:00',
- '--allowed-address-pair',
- 'ip_address=123.123.123.45,mac_address=10:00:00:00:00:01']
- updatefields = {'allowed_address_pairs': pairs}
- self._test_update_resource(resource, cmd, myid, args, updatefields)
-
- def test_update_port_allowed_address_pairs_off(self):
- # Update port: --no-allowed-address-pairs.
- resource = 'port'
- cmd = port.UpdatePort(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['--no-allowed-address-pairs', 'myid'],
- {'allowed_address_pairs': []})
-
- def test_show_port(self):
- # Show port: --fields id --fields name myid.
- resource = 'port'
- cmd = port.ShowPort(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_delete_port(self):
- # Delete port: myid.
- resource = 'port'
- cmd = port.DeletePort(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
diff --git a/neutronclient/tests/unit/test_cli20_purge.py b/neutronclient/tests/unit/test_cli20_purge.py
deleted file mode 100644
index 9bfd91c..0000000
--- a/neutronclient/tests/unit/test_cli20_purge.py
+++ /dev/null
@@ -1,100 +0,0 @@
-# Copyright 2016 Cisco Systems
-# 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 neutronclient.neutron.v2_0 import purge
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20Purge(test_cli20.CLITestV20Base):
-
- def setUp(self):
- super(CLITestV20Purge, self).setUp()
- self.resource_types = ['floatingip', 'port', 'router',
- 'network', 'security_group']
-
- def _generate_resources_dict(self, value=0):
- resources_dict = {}
- resources_dict['true'] = value
- for resource_type in self.resource_types:
- resources_dict[resource_type] = value
- return resources_dict
-
- def _verify_suffix(self, resources, message):
- for resource, value in resources.items():
- if value > 0:
- suffix = list('%(value)d %(resource)s' %
- {'value': value, 'resource': resource})
- if value != 1:
- suffix.append('s')
- suffix = ''.join(suffix)
- self.assertIn(suffix, message)
- else:
- self.assertNotIn(resource, message)
-
- def _verify_message(self, message, deleted, failed):
- message = message.split('.')
- success_prefix = "Deleted "
- failure_prefix = "The following resources could not be deleted: "
- if not deleted['true']:
- for msg in message:
- self.assertNotIn(success_prefix, msg)
- message = message[0]
- if not failed['true']:
- expected = 'Tenant has no supported resources'
- self.assertEqual(expected, message)
- else:
- self.assertIn(failure_prefix, message)
- self._verify_suffix(failed, message)
- else:
- resources_deleted = message[0]
- self.assertIn(success_prefix, resources_deleted)
- self._verify_suffix(deleted, resources_deleted)
- if failed['true']:
- resources_failed = message[1]
- self.assertIn(failure_prefix, resources_failed)
- self._verify_suffix(failed, resources_failed)
- else:
- for msg in message:
- self.assertNotIn(failure_prefix, msg)
-
- def _verify_result(self, my_purge, deleted, failed):
- message = my_purge._build_message(deleted, failed, failed['true'])
- self._verify_message(message, deleted, failed)
-
- def test_build_message(self):
- my_purge = purge.Purge(test_cli20.MyApp(sys.stdout), None)
-
- # Verify message when tenant has no supported resources
- deleted = self._generate_resources_dict()
- failed = self._generate_resources_dict()
- self._verify_result(my_purge, deleted, failed)
-
- # Verify message when tenant has supported resources,
- # and they are all deleteable
- deleted = self._generate_resources_dict(1)
- self._verify_result(my_purge, deleted, failed)
-
- # Verify message when tenant has supported resources,
- # and some are not deleteable
- failed = self._generate_resources_dict(1)
- self._verify_result(my_purge, deleted, failed)
-
- # Verify message when tenant has supported resources,
- # and all are not deleteable
- deleted = self._generate_resources_dict()
- self._verify_result(my_purge, deleted, failed)
diff --git a/neutronclient/tests/unit/test_cli20_rbac.py b/neutronclient/tests/unit/test_cli20_rbac.py
deleted file mode 100644
index ca89df6..0000000
--- a/neutronclient/tests/unit/test_cli20_rbac.py
+++ /dev/null
@@ -1,134 +0,0 @@
-# Copyright 2015 Huawei Technologies India Pvt Ltd.
-# 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
-
-import testscenarios
-
-from neutronclient.neutron.v2_0 import rbac
-from neutronclient.tests.unit import test_cli20
-
-load_tests = testscenarios.load_tests_apply_scenarios
-
-
-class CLITestV20RBACBaseJSON(test_cli20.CLITestV20Base):
- non_admin_status_resources = ['rbac_policy']
-
- scenarios = [
- ('network rbac objects',
- {'object_type_name': 'network', 'object_type_val': 'network'}),
- ('qos policy rbac objects',
- {'object_type_name': 'qos-policy', 'object_type_val': 'qos_policy'}),
- ]
-
- def test_create_rbac_policy_with_mandatory_params(self):
- # Create rbac: rbac_object --type <object_type_name> --action
- # access_as_shared
- resource = 'rbac_policy'
- cmd = rbac.CreateRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'rbac_object'
- myid = 'myid'
- args = [name, '--type', self.object_type_name,
- '--action', 'access_as_shared']
- position_names = ['object_id', 'object_type',
- 'target_tenant', 'action']
- position_values = [name, self.object_type_val, '*',
- 'access_as_shared']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_rbac_policy_with_all_params(self):
- # Create rbac: rbac_object --type <object_type_name>
- # --target-tenant tenant_id --action access_as_external
- resource = 'rbac_policy'
- cmd = rbac.CreateRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'rbac_object'
- myid = 'myid'
- args = [name, '--type', self.object_type_name,
- '--target-tenant', 'tenant_id',
- '--action', 'access_as_external']
- position_names = ['object_id', 'object_type',
- 'target_tenant', 'action']
- position_values = [name, self.object_type_val, 'tenant_id',
- 'access_as_external']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_rbac_policy_with_unicode(self):
- # Create rbac policy u'\u7f51\u7edc'.
- resource = 'rbac_policy'
- cmd = rbac.CreateRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- name = u'\u7f51\u7edc'
- myid = 'myid'
- args = [name, '--type', self.object_type_name,
- '--target-tenant', 'tenant_id',
- '--action', 'access_as_external']
- position_names = ['object_id', 'object_type',
- 'target_tenant', 'action']
- position_values = [name, self.object_type_val, 'tenant_id',
- 'access_as_external']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_update_rbac_policy(self):
- # rbac-update <rbac-uuid> --target-tenant <other-tenant-uuid>.
- resource = 'rbac_policy'
- cmd = rbac.UpdateRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--target-tenant', 'tenant_id'],
- {'target_tenant': 'tenant_id', })
-
- def test_delete_rbac_policy(self):
- # rbac-delete my-id.
- resource = 'rbac_policy'
- cmd = rbac.DeleteRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- my_id = 'myid1'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args)
-
- def test_list_rbac_policies(self):
- # rbac-list.
- resources = "rbac_policies"
- cmd = rbac.ListRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_rbac_policies_pagination(self):
- # rbac-list with pagination.
- resources = "rbac_policies"
- cmd = rbac.ListRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_rbac_policies_sort(self):
- # sorted list:
- # rbac-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "rbac_policies"
- cmd = rbac.ListRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_rbac_policies_limit(self):
- # size (1000) limited list: rbac-list -P.
- resources = "rbac_policies"
- cmd = rbac.ListRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_rbac_policy(self):
- # rbac-show test_id.
- resource = 'rbac_policy'
- cmd = rbac.ShowRBACPolicy(test_cli20.MyApp(sys.stdout), None)
- args = ['--fields', 'id', self.test_id]
- self._test_show_resource(resource, cmd, self.test_id, args, ['id'])
diff --git a/neutronclient/tests/unit/test_cli20_router.py b/neutronclient/tests/unit/test_cli20_router.py
deleted file mode 100644
index ba267f7..0000000
--- a/neutronclient/tests/unit/test_cli20_router.py
+++ /dev/null
@@ -1,434 +0,0 @@
-# Copyright 2012 VMware, 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.
-#
-
-import sys
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0 import router
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20RouterJSON(test_cli20.CLITestV20Base):
- def test_create_router(self):
- # Create router: router1.
- resource = 'router'
- cmd = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
- name = 'router1'
- myid = 'myid'
- args = [name, '--description', 'rooter']
- position_names = ['name', ]
- position_values = [name, ]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- description='rooter')
-
- def test_create_router_flavor(self):
- resource = 'router'
- cmd = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
- name = 'router1'
- myid = 'myid'
- flavor = 'router-flavor'
- args = [name, '--flavor', flavor]
- position_names = ['name', ]
- position_values = [name, flavor]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- flavor_id='router-flavor')
-
- def test_create_router_tenant(self):
- # Create router: --tenant_id tenantid myname.
- resource = 'router'
- cmd = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- args = ['--tenant_id', 'tenantid', name]
- position_names = ['name', ]
- position_values = [name, ]
- 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 = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- args = ['--admin_state_down', name, ]
- position_names = ['name', ]
- position_values = [name, ]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- admin_state_up=False)
-
- def _create_router_distributed_or_ha(self, distributed=None, ha=None):
- # Create router: --distributed distributed --ha ha myname.
- resource = 'router'
- cmd = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- args = []
- if distributed is not None:
- args += ['--distributed', str(distributed)]
- if ha is not None:
- args += ['--ha', str(ha)]
- args.append(name)
- position_names = ['name', ]
- position_values = [name, ]
- expected = {}
- if distributed is not None:
- expected['distributed'] = str(distributed)
- if ha is not None:
- expected['ha'] = str(ha)
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- **expected)
-
- def test_create_router_distributed_True(self):
- # Create router: --distributed=True.
- self._create_router_distributed_or_ha(distributed='True')
-
- def test_create_router_ha_with_True(self):
- self._create_router_distributed_or_ha(ha='True')
-
- def test_create_router_ha_with_true(self):
- self._create_router_distributed_or_ha(ha='true')
-
- def test_create_router_ha_with_False(self):
- self._create_router_distributed_or_ha(ha='False')
-
- def test_create_router_ha_with_false(self):
- self._create_router_distributed_or_ha(ha='false')
-
- def test_create_router_distributed_False(self):
- # Create router: --distributed=False.
- self._create_router_distributed_or_ha(distributed='False')
-
- def test_create_router_distributed_true(self):
- # Create router: --distributed=true.
- self._create_router_distributed_or_ha(distributed='true')
-
- def test_create_router_distributed_false(self):
- # Create router: --distributed=false.
- self._create_router_distributed_or_ha(distributed='false')
-
- def test_create_router_with_az_hint(self):
- # Create router: --availability-zone-hint zone1
- # --availability-zone-hint zone2.
- resource = 'router'
- cmd = router.CreateRouter(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- args = ['--availability-zone-hint', 'zone1',
- '--availability-zone-hint', 'zone2', name]
- position_names = ['availability_zone_hints', 'name']
- position_values = [['zone1', 'zone2'], name]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_list_routers_detail(self):
- # list routers: -D.
- resources = "routers"
- cmd = router.ListRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_routers_pagination(self):
- resources = "routers"
- cmd = router.ListRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_routers_sort(self):
- # list routers:
- # --sort-key name --sort-key id --sort-key asc --sort-key desc
- resources = "routers"
- cmd = router.ListRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_routers_limit(self):
- # list routers: -P.
- resources = "routers"
- cmd = router.ListRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_update_router_exception(self):
- # Update router: myid.
- resource = 'router'
- cmd = router.UpdateRouter(test_cli20.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 = router.UpdateRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'myname',
- '--description', ':D'],
- {'name': 'myname', 'description': ':D'})
-
- def test_update_router_admin_state(self):
- # Update router: myid --admin-state-up <True|False>.
- resource = 'router'
- cmd = router.UpdateRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--admin-state-up', 'True'],
- {'admin_state_up': 'True'}
- )
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--admin-state-up', 'true'],
- {'admin_state_up': 'true'}
- )
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--admin-state-up', 'False'],
- {'admin_state_up': 'False'}
- )
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--admin-state-up', 'false'],
- {'admin_state_up': 'false'}
- )
-
- def test_update_router_distributed(self):
- # Update router: myid --distributed <True|False>.
- resource = 'router'
- cmd = router.UpdateRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--distributed', 'True'],
- {'distributed': 'True'}
- )
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--distributed', 'true'],
- {'distributed': 'true'}
- )
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--distributed', 'False'],
- {'distributed': 'False'}
- )
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--distributed', 'false'],
- {'distributed': 'false'}
- )
-
- def test_update_router_no_routes(self):
- # Update router: myid --no-routes
- resource = 'router'
- cmd = router.UpdateRouter(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--no-routes'],
- {'routes': None})
-
- def test_update_router_add_route(self):
- # Update router: myid --route destination=10.0.3.0/24,nexthop=10.0.0.10
- resource = 'router'
- cmd = router.UpdateRouter(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid,
- '--route',
- 'destination=10.0.3.0/24,nexthop=10.0.0.10']
- routes = [{'destination': '10.0.3.0/24',
- 'nexthop': '10.0.0.10'}]
- updatefields = {'routes': routes}
- self._test_update_resource(resource, cmd, myid, args, updatefields)
-
- def test_update_router_add_routes(self):
- # Update router: myid --route destination=10.0.3.0/24,nexthop=10.0.0.10
- # --route destination=fd7a:1d63:2063::/64,
- # nexthop=fd7a:1d63:2063:0:f816:3eff:fe0e:a697
- resource = 'router'
- cmd = router.UpdateRouter(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid,
- '--route',
- 'destination=10.0.3.0/24,nexthop=10.0.0.10',
- '--route',
- 'destination=fd7a:1d63:2063::/64,'
- 'nexthop=fd7a:1d63:2063:0:f816:3eff:fe0e:a697']
- routes = [{'destination': '10.0.3.0/24',
- 'nexthop': '10.0.0.10'},
- {'destination': 'fd7a:1d63:2063::/64',
- 'nexthop': 'fd7a:1d63:2063:0:f816:3eff:fe0e:a697'}]
- updatefields = {'routes': routes}
- self._test_update_resource(resource, cmd, myid, args, updatefields)
-
- def test_update_router_no_routes_with_add_route(self):
- # Update router: --no-routes with --route
- resource = 'router'
- cmd = router.UpdateRouter(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid,
- '--no-routes',
- '--route',
- 'destination=10.0.3.0/24,nexthop=10.0.0.10']
- exception = self.assertRaises(SystemExit,
- self._test_update_resource,
- resource, cmd, myid, args, None)
- self.assertEqual(2, exception.code)
-
- def test_delete_router(self):
- # Delete router: myid.
- resource = 'router'
- cmd = router.DeleteRouter(test_cli20.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 = router.ShowRouter(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_add_remove_interface(self, action, mode, cmd, args):
- resource = 'router'
- subcmd = '%s_router_interface' % action
- if mode == 'port':
- body = {'port_id': 'portid'}
- else:
- body = {'subnet_id': 'subnetid'}
- if action == 'add':
- retval = {'subnet_id': 'subnetid', 'port_id': 'portid'}
- retval = self.client.serialize(retval)
- expected_code = 200
- else:
- retval = None
- expected_code = 204
- self._test_update_resource_action(resource, cmd, 'myid',
- subcmd, args,
- body, expected_code, retval)
-
- def test_add_interface_compat(self):
- # Add interface to router: myid subnetid.
- cmd = router.AddInterfaceRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'subnetid']
- self._test_add_remove_interface('add', 'subnet', cmd, args)
-
- def test_add_interface_by_subnet(self):
- # Add interface to router: myid subnet=subnetid.
- cmd = router.AddInterfaceRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'subnet=subnetid']
- self._test_add_remove_interface('add', 'subnet', cmd, args)
-
- def test_add_interface_by_port(self):
- # Add interface to router: myid port=portid.
- cmd = router.AddInterfaceRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'port=portid']
- self._test_add_remove_interface('add', 'port', cmd, args)
-
- def test_del_interface_compat(self):
- # Delete interface from router: myid subnetid.
- cmd = router.RemoveInterfaceRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'subnetid']
- self._test_add_remove_interface('remove', 'subnet', cmd, args)
-
- def test_del_interface_by_subnet(self):
- # Delete interface from router: myid subnet=subnetid.
- cmd = router.RemoveInterfaceRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'subnet=subnetid']
- self._test_add_remove_interface('remove', 'subnet', cmd, args)
-
- def test_del_interface_by_port(self):
- # Delete interface from router: myid port=portid.
- cmd = router.RemoveInterfaceRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'port=portid']
- self._test_add_remove_interface('remove', 'port', cmd, args)
-
- def test_set_gateway(self):
- # Set external gateway for router: myid externalid.
- resource = 'router'
- cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'externalid']
- self._test_update_resource(resource, cmd, 'myid',
- args,
- {"external_gateway_info":
- {"network_id": "externalid"}}
- )
-
- def test_set_gateway_enable_snat(self):
- # enable external gateway for router: myid externalid.
- resource = 'router'
- cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'externalid', '--enable-snat']
- self._test_update_resource(resource, cmd, 'myid',
- args,
- {"external_gateway_info":
- {"network_id": "externalid",
- "enable_snat": True}}
- )
-
- 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": False}}
- )
-
- def test_set_gateway_external_ip(self):
- # set external gateway for router: myid externalid --fixed-ip ...
- resource = 'router'
- cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'externalid', '--fixed-ip', 'ip_address=10.0.0.2']
- self._test_update_resource(resource, cmd, 'myid',
- args,
- {"external_gateway_info":
- {"network_id": "externalid",
- "external_fixed_ips": [
- {"ip_address": "10.0.0.2"}]}}
- )
-
- def test_set_gateway_external_subnet(self):
- # set external gateway for router: myid externalid --fixed-ip ...
- resource = 'router'
- cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'externalid', '--fixed-ip', 'subnet_id=mysubnet']
- self._test_update_resource(resource, cmd, 'myid',
- args,
- {"external_gateway_info":
- {"network_id": "externalid",
- "external_fixed_ips": [
- {"subnet_id": "mysubnet"}]}}
- )
-
- def test_set_gateway_external_ip_and_subnet(self):
- # set external gateway for router: myid externalid --fixed-ip ...
- resource = 'router'
- cmd = router.SetGatewayRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['myid', 'externalid', '--fixed-ip',
- 'ip_address=10.0.0.2,subnet_id=mysubnet']
- self._test_update_resource(resource, cmd, 'myid',
- args,
- {"external_gateway_info":
- {"network_id": "externalid",
- "external_fixed_ips": [
- {"subnet_id": "mysubnet",
- "ip_address": "10.0.0.2"}]}}
- )
-
- def test_remove_gateway(self):
- # Remove external gateway from router: externalid.
- resource = 'router'
- cmd = router.RemoveGatewayRouter(test_cli20.MyApp(sys.stdout), None)
- args = ['externalid']
- self._test_update_resource(resource, cmd, 'externalid',
- args, {"external_gateway_info": {}}
- )
diff --git a/neutronclient/tests/unit/test_cli20_securitygroup.py b/neutronclient/tests/unit/test_cli20_securitygroup.py
deleted file mode 100644
index 95a578f..0000000
--- a/neutronclient/tests/unit/test_cli20_securitygroup.py
+++ /dev/null
@@ -1,657 +0,0 @@
-# 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 unittest import mock
-import urllib.parse as urlparse
-
-from oslo_utils import uuidutils
-
-from neutronclient.common import exceptions
-from neutronclient.common import utils
-from neutronclient.neutron.v2_0 import securitygroup
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20SecurityGroupsJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['security_group', 'security_group_rule']
-
- def test_create_security_group(self):
- # Create security group: webservers.
- resource = 'security_group'
- cmd = securitygroup.CreateSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- name = 'webservers'
- myid = 'myid'
- args = [name, ]
- position_names = ['name']
- position_values = [name]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_security_group_tenant(self):
- # Create security group: webservers.
- resource = 'security_group'
- cmd = securitygroup.CreateSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- name = 'webservers'
- description = 'my webservers'
- myid = 'myid'
- args = ['--tenant_id', 'tenant_id', '--description', description, name]
- position_names = ['name', 'description']
- position_values = [name, description]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenant_id')
-
- def test_create_security_group_with_description(self):
- # Create security group: webservers.
- resource = 'security_group'
- cmd = securitygroup.CreateSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- name = 'webservers'
- description = 'my webservers'
- myid = 'myid'
- args = [name, '--description', description]
- position_names = ['name', 'description']
- position_values = [name, description]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_list_security_groups(self):
- resources = "security_groups"
- cmd = securitygroup.ListSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_security_groups_pagination(self):
- resources = "security_groups"
- cmd = securitygroup.ListSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_security_groups_sort(self):
- resources = "security_groups"
- cmd = securitygroup.ListSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_security_groups_limit(self):
- resources = "security_groups"
- cmd = securitygroup.ListSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_security_group_id(self):
- resource = 'security_group'
- cmd = securitygroup.ShowSecurityGroup(
- 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_security_group_id_name(self):
- resource = 'security_group'
- cmd = securitygroup.ShowSecurityGroup(
- 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_delete_security_group(self):
- # Delete security group: myid.
- resource = 'security_group'
- cmd = securitygroup.DeleteSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
-
- def test_update_security_group(self):
- # Update security group: myid --name myname --description desc.
- resource = 'security_group'
- cmd = securitygroup.UpdateSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'myname',
- '--description', 'mydescription'],
- {'name': 'myname',
- 'description': 'mydescription'}
- )
-
- def test_update_security_group_with_unicode(self):
- resource = 'security_group'
- cmd = securitygroup.UpdateSecurityGroup(
- test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', u'\u7f51\u7edc',
- '--description', u'\u7f51\u7edc'],
- {'name': u'\u7f51\u7edc',
- 'description': u'\u7f51\u7edc'}
- )
-
- def test_create_security_group_rule_full(self):
- # Create security group rule.
- resource = 'security_group_rule'
- cmd = securitygroup.CreateSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- direction = 'ingress'
- ethertype = 'IPv4'
- protocol = 'tcp'
- port_range_min = '22'
- port_range_max = '22'
- remote_ip_prefix = '10.0.0.0/24'
- security_group_id = '1'
- remote_group_id = '1'
- args = ['--remote_ip_prefix', remote_ip_prefix, '--direction',
- direction, '--ethertype', ethertype, '--protocol', protocol,
- '--port_range_min', port_range_min, '--port_range_max',
- port_range_max, '--remote_group_id', remote_group_id,
- security_group_id, '--description', 'PCI policy 1421912']
- position_names = ['remote_ip_prefix', 'direction', 'ethertype',
- 'protocol', 'port_range_min', 'port_range_max',
- 'remote_group_id', 'security_group_id']
- position_values = [remote_ip_prefix, direction, ethertype, protocol,
- port_range_min, port_range_max, remote_group_id,
- security_group_id]
- self._test_create_resource(resource, cmd, None, myid, args,
- position_names, position_values,
- description='PCI policy 1421912')
-
- def test_create_security_group_rule_with_integer_protocol_value(self):
- resource = 'security_group_rule'
- cmd = securitygroup.CreateSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- direction = 'ingress'
- ethertype = 'IPv4'
- protocol = '2'
- port_range_min = '22'
- port_range_max = '22'
- remote_ip_prefix = '10.0.0.0/24'
- security_group_id = '1'
- remote_group_id = '1'
- args = ['--remote_ip_prefix', remote_ip_prefix, '--direction',
- direction, '--ethertype', ethertype, '--protocol', protocol,
- '--port_range_min', port_range_min, '--port_range_max',
- port_range_max, '--remote_group_id', remote_group_id,
- security_group_id]
- position_names = ['remote_ip_prefix', 'direction', 'ethertype',
- 'protocol', 'port_range_min', 'port_range_max',
- 'remote_group_id', 'security_group_id']
- position_values = [remote_ip_prefix, direction, ethertype, protocol,
- port_range_min, port_range_max, remote_group_id,
- security_group_id]
- self._test_create_resource(resource, cmd, None, myid, args,
- position_names, position_values)
-
- def test_delete_security_group_rule(self):
- # Delete security group rule: myid.
- resource = 'security_group_rule'
- cmd = securitygroup.DeleteSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
-
- @mock.patch.object(securitygroup.ListSecurityGroupRule, "extend_list")
- def test_list_security_group_rules(self, mock_extend_list):
- resources = "security_group_rules"
- cmd = securitygroup.ListSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def _build_test_data(self, data, excess=0):
- # Length of a query filter on security group rule id
- # in these testcases, id='secgroupid%02d' (with len(id)=12)
- sec_group_id_filter_len = 12
-
- response = []
- replace_rules = {'security_group_id': 'security_group',
- 'remote_group_id': 'remote_group'}
-
- search_opts = {'fields': ['id', 'name']}
- sec_group_ids = set()
- for rule in data:
- for key in replace_rules:
- if rule.get(key):
- sec_group_ids.add(rule[key])
- response.append({'id': rule[key], 'name': 'default'})
- sec_group_ids = list(sec_group_ids)
-
- result = []
-
- sec_group_count = len(sec_group_ids)
- max_size = ((sec_group_id_filter_len * sec_group_count) - excess)
- chunk_size = max_size // sec_group_id_filter_len
-
- for i in range(0, sec_group_count, chunk_size):
- search_opts['id'] = sec_group_ids[i: i + chunk_size]
- params = utils.safe_encode_dict(search_opts)
- resp_str = self.client.serialize({'security_groups': response})
-
- result.append({
- 'filter': urlparse.urlencode(params, doseq=1),
- 'response': (test_cli20.MyResp(200), resp_str),
- })
-
- return result
-
- def test_extend_list(self):
- data = [{'name': 'default',
- 'remote_group_id': 'remgroupid%02d' % i}
- for i in range(10)]
- data.append({'name': 'default', 'remote_group_id': None})
- resources = "security_groups"
-
- cmd = securitygroup.ListSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
-
- path = getattr(self.client, resources + '_path')
- responses = self._build_test_data(data)
- known_args, _vs = cmd.get_parser(
- 'list' + resources).parse_known_args()
- resp = responses[0]['response']
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- cmd.extend_list(data, known_args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(test_cli20.end_url(
- path, responses[0]['filter']), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- def test_extend_list_exceed_max_uri_len(self):
- data = [{'name': 'default',
- 'security_group_id': 'secgroupid%02d' % i,
- 'remote_group_id': 'remgroupid%02d' % i}
- for i in range(10)]
- data.append({'name': 'default',
- 'security_group_id': 'secgroupid10',
- 'remote_group_id': None})
- resources = "security_groups"
-
- cmd = securitygroup.ListSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- path = getattr(self.client, resources + '_path')
- responses = self._build_test_data(data, excess=1)
-
- known_args, _vs = cmd.get_parser(
- 'list' + resources).parse_known_args()
- mock_request_side_effects = []
- mock_request_calls = []
- mock_check_uri_side_effects = [exceptions.RequestURITooLong(excess=1)]
- mock_check_uri_calls = [mock.call(mock.ANY)]
- for item in responses:
- mock_request_side_effects.append(item['response'])
- mock_request_calls.append(mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, item['filter']), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN})))
- mock_check_uri_side_effects.append(None)
- mock_check_uri_calls.append(mock.call(mock.ANY))
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient,
- "request") as mock_request, \
- mock.patch.object(self.client.httpclient,
- "_check_uri_length") as mock_check_uri:
- mock_request.side_effect = mock_request_side_effects
- mock_check_uri.side_effect = mock_check_uri_side_effects
- cmd.extend_list(data, known_args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_has_calls(mock_request_calls)
- mock_check_uri.assert_has_calls(mock_check_uri_calls)
- self.assertEqual(len(mock_request_calls), mock_request.call_count)
- self.assertEqual(len(mock_check_uri_calls), mock_check_uri.call_count)
-
- @mock.patch.object(securitygroup.ListSecurityGroupRule, "extend_list")
- def test_list_security_group_rules_pagination(self, mock_extend_list):
- resources = "security_group_rules"
- cmd = securitygroup.ListSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- @mock.patch.object(securitygroup.ListSecurityGroupRule, "extend_list")
- def test_list_security_group_rules_sort(self, mock_extend_list):
- resources = "security_group_rules"
- cmd = securitygroup.ListSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- @mock.patch.object(securitygroup.ListSecurityGroupRule, "extend_list")
- def test_list_security_group_rules_limit(self, mock_extend_list):
- resources = "security_group_rules"
- cmd = securitygroup.ListSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_show_security_group_rule(self):
- resource = 'security_group_rule'
- cmd = securitygroup.ShowSecurityGroupRule(
- 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_list_security_group_rules_extend(self, api_data, expected,
- args=(), conv=True,
- query_fields=None):
- def setup_list_stub(resources, data, query, mock_calls, mock_returns):
- reses = {resources: data}
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- path = getattr(self.client, resources + '_path')
- mock_calls.append(mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, query),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN})))
- mock_returns.append(resp)
-
- cmd = securitygroup.ListSecurityGroupRule(
- test_cli20.MyApp(sys.stdout), None)
- query = ''
- if query_fields:
- query = '&'.join(['fields=' + f for f in query_fields])
- mock_request_calls = []
- mock_request_returns = []
- setup_list_stub('security_group_rules', api_data, query,
- mock_request_calls, mock_request_returns)
- if conv:
- sec_ids = set()
- for n in api_data:
- sec_ids.add(n['security_group_id'])
- if n.get('remote_group_id'):
- sec_ids.add(n['remote_group_id'])
- filters = ''
- for id in sec_ids:
- filters = filters + "&id=%s" % id
- setup_list_stub('security_groups',
- [{'id': 'myid1', 'name': 'group1'},
- {'id': 'myid2', 'name': 'group2'},
- {'id': 'myid3', 'name': 'group3'}],
- 'fields=id&fields=name' + filters,
- mock_request_calls,
- mock_request_returns)
-
- cmd_parser = cmd.get_parser('list_security_group_rules')
- parsed_args = cmd_parser.parse_args(args)
-
- with mock.patch.object(cmd, "get_client",
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient,
- "request") as mock_request:
- mock_request.side_effect = mock_request_returns
- result = cmd.take_action(parsed_args)
-
- self.assert_mock_multiple_calls_with_same_arguments(
- mock_get_client, mock.call(), None)
- mock_request.assert_has_calls(mock_request_calls)
- self.assertEqual(len(mock_request_calls), mock_request.call_count)
- self.assertEqual(expected['cols'], result[0])
- # Check data
- _result = [x for x in result[1]]
- self.assertEqual(len(expected['data']), len(_result))
- for res, exp in zip(_result, expected['data']):
- self.assertEqual(len(exp), len(res))
- self.assertEqual(exp, res)
-
- def _test_list_security_group_rules_extend_sg_name(
- self, expected_mode=None, args=(), conv=True, query_field=False):
- if query_field:
- field_filters = ['id', 'security_group_id',
- 'remote_ip_prefix', 'remote_group_id']
- else:
- field_filters = None
-
- data = [self._prepare_rule(rule_id='ruleid1', sg_id='myid1',
- remote_group_id='myid1',
- filters=field_filters),
- self._prepare_rule(rule_id='ruleid2', sg_id='myid2',
- remote_group_id='myid3',
- filters=field_filters),
- self._prepare_rule(rule_id='ruleid3', sg_id='myid2',
- remote_group_id='myid2',
- filters=field_filters),
- ]
-
- if expected_mode == 'noconv':
- expected = {'cols': ['id', 'security_group_id', 'remote_group_id'],
- 'data': [('ruleid1', 'myid1', 'myid1'),
- ('ruleid2', 'myid2', 'myid3'),
- ('ruleid3', 'myid2', 'myid2')]}
- elif expected_mode == 'remote_group_id':
- expected = {'cols': ['id', 'security_group', 'remote_group'],
- 'data': [('ruleid1', 'group1', 'group1'),
- ('ruleid2', 'group2', 'group3'),
- ('ruleid3', 'group2', 'group2')]}
- else:
- expected = {'cols': ['id', 'security_group', 'remote'],
- 'data': [('ruleid1', 'group1', 'group1 (group)'),
- ('ruleid2', 'group2', 'group3 (group)'),
- ('ruleid3', 'group2', 'group2 (group)')]}
-
- self._test_list_security_group_rules_extend(
- data, expected, args=args, conv=conv, query_fields=field_filters)
-
- def test_list_security_group_rules_extend_remote_sg_name(self):
- args = '-c id -c security_group -c remote'.split()
- self._test_list_security_group_rules_extend_sg_name(args=args)
-
- def test_list_security_group_rules_extend_sg_name_noconv(self):
- args = '--no-nameconv -c id -c security_group_id -c remote_group_id'
- args = args.split()
- self._test_list_security_group_rules_extend_sg_name(
- expected_mode='noconv', args=args, conv=False)
-
- def test_list_security_group_rules_extend_sg_name_with_columns(self):
- args = '-c id -c security_group_id -c remote_group_id'.split()
- self._test_list_security_group_rules_extend_sg_name(
- expected_mode='remote_group_id', args=args)
-
- def test_list_security_group_rules_extend_sg_name_with_columns_no_id(self):
- args = '-c id -c security_group -c remote_group'.split()
- self._test_list_security_group_rules_extend_sg_name(
- expected_mode='remote_group_id', args=args)
-
- def test_list_security_group_rules_extend_sg_name_with_fields(self):
- # NOTE: remote_ip_prefix is required to show "remote" column
- args = ('-F id -F security_group_id '
- '-F remote_ip_prefix -F remote_group_id').split()
- self._test_list_security_group_rules_extend_sg_name(
- args=args, query_field=True)
-
- def test_list_security_group_rules_extend_sg_name_with_fields_no_id(self):
- # NOTE: remote_ip_prefix is required to show "remote" column
- args = ('-F id -F security_group '
- '-F remote_ip_prefix -F remote_group').split()
- self._test_list_security_group_rules_extend_sg_name(args=args,
- query_field=True)
-
- def test_list_security_group_rules_extend_remote(self):
- args = '-c id -c security_group -c remote'.split()
-
- data = [self._prepare_rule(rule_id='ruleid1', sg_id='myid1',
- remote_ip_prefix='172.16.18.0/24'),
- self._prepare_rule(rule_id='ruleid2', sg_id='myid2',
- remote_ip_prefix='172.16.20.0/24'),
- self._prepare_rule(rule_id='ruleid3', sg_id='myid2',
- remote_group_id='myid3')]
- expected = {'cols': ['id', 'security_group', 'remote'],
- 'data': [('ruleid1', 'group1', '172.16.18.0/24 (CIDR)'),
- ('ruleid2', 'group2', '172.16.20.0/24 (CIDR)'),
- ('ruleid3', 'group2', 'group3 (group)')]}
- self._test_list_security_group_rules_extend(data, expected, args)
-
- def test_list_security_group_rules_extend_proto_port(self):
- data = [self._prepare_rule(rule_id='ruleid1', sg_id='myid1',
- protocol='tcp',
- port_range_min=22, port_range_max=22),
- self._prepare_rule(rule_id='ruleid2', sg_id='myid2',
- direction='egress', ethertype='IPv6',
- protocol='udp',
- port_range_min=80, port_range_max=81),
- self._prepare_rule(rule_id='ruleid3', sg_id='myid2',
- protocol='icmp',
- remote_ip_prefix='10.2.0.0/16')]
- expected = {
- 'cols': ['id', 'security_group', 'direction', 'ethertype',
- 'port/protocol', 'remote'],
- 'data': [
- ('ruleid1', 'group1', 'ingress', 'IPv4', '22/tcp', 'any'),
- ('ruleid2', 'group2', 'egress', 'IPv6', '80-81/udp', 'any'),
- ('ruleid3', 'group2', 'ingress', 'IPv4', 'icmp',
- '10.2.0.0/16 (CIDR)')
- ]}
- self._test_list_security_group_rules_extend(data, expected)
-
- def _prepare_rule(self, rule_id=None, sg_id=None, tenant_id=None,
- direction=None, ethertype=None,
- protocol=None, port_range_min=None, port_range_max=None,
- remote_ip_prefix=None, remote_group_id=None,
- filters=None):
- rule = {'id': rule_id or uuidutils.generate_uuid(),
- 'tenant_id': tenant_id or uuidutils.generate_uuid(),
- 'security_group_id': sg_id or uuidutils.generate_uuid(),
- 'direction': direction or 'ingress',
- 'ethertype': ethertype or 'IPv4',
- 'protocol': protocol,
- 'port_range_min': port_range_min,
- 'port_range_max': port_range_max,
- 'remote_ip_prefix': remote_ip_prefix,
- 'remote_group_id': remote_group_id}
- if filters:
- return dict([(k, v) for k, v in rule.items() if k in filters])
- else:
- return rule
-
- def test__get_remote_both_unspecified(self):
- sg_rule = self._prepare_rule(remote_ip_prefix=None,
- remote_group_id=None)
- self.assertIsNone(securitygroup._get_remote(sg_rule))
-
- def test__get_remote_remote_ip_prefix_specified(self):
- sg_rule = self._prepare_rule(remote_ip_prefix='172.16.18.0/24')
- self.assertEqual('172.16.18.0/24 (CIDR)',
- securitygroup._get_remote(sg_rule))
-
- def test__get_remote_remote_group_specified(self):
- sg_rule = self._prepare_rule(remote_group_id='sg_id1')
- self.assertEqual('sg_id1 (group)', securitygroup._get_remote(sg_rule))
-
- def test__get_protocol_port_all_none(self):
- sg_rule = self._prepare_rule()
- self.assertIsNone(securitygroup._get_protocol_port(sg_rule))
-
- def test__get_protocol_port_tcp_all_port(self):
- sg_rule = self._prepare_rule(protocol='tcp')
- self.assertEqual('tcp', securitygroup._get_protocol_port(sg_rule))
-
- def test__get_protocol_port_tcp_one_port(self):
- sg_rule = self._prepare_rule(protocol='tcp',
- port_range_min=22, port_range_max=22)
- self.assertEqual('22/tcp', securitygroup._get_protocol_port(sg_rule))
-
- def test__get_protocol_port_tcp_port_range(self):
- sg_rule = self._prepare_rule(protocol='tcp',
- port_range_min=5000, port_range_max=5010)
- self.assertEqual('5000-5010/tcp',
- securitygroup._get_protocol_port(sg_rule))
-
- def test__get_protocol_port_udp_all_port(self):
- sg_rule = self._prepare_rule(protocol='udp')
- self.assertEqual('udp', securitygroup._get_protocol_port(sg_rule))
-
- def test__get_protocol_port_udp_one_port(self):
- sg_rule = self._prepare_rule(protocol='udp',
- port_range_min=22, port_range_max=22)
- self.assertEqual('22/udp', securitygroup._get_protocol_port(sg_rule))
-
- def test__get_protocol_port_udp_port_range(self):
- sg_rule = self._prepare_rule(protocol='udp',
- port_range_min=5000, port_range_max=5010)
- self.assertEqual('5000-5010/udp',
- securitygroup._get_protocol_port(sg_rule))
-
- def test__get_protocol_port_icmp_all(self):
- sg_rule = self._prepare_rule(protocol='icmp')
- self.assertEqual('icmp', securitygroup._get_protocol_port(sg_rule))
-
- def test_get_ethertype_for_protocol_icmpv6(self):
- self.assertEqual('IPv6',
- securitygroup.generate_default_ethertype('icmpv6'))
-
- def test_get_ethertype_for_protocol_icmp(self):
- self.assertEqual('IPv4',
- securitygroup.generate_default_ethertype('icmp'))
-
- def test__get_protocol_port_udp_code_type(self):
- sg_rule = self._prepare_rule(protocol='icmp',
- port_range_min=1, port_range_max=8)
- self.assertEqual('icmp (type:1, code:8)',
- securitygroup._get_protocol_port(sg_rule))
-
- def test__format_sg_rules(self):
- rules = [self._prepare_rule(),
- self._prepare_rule(protocol='tcp', port_range_min=80,
- port_range_max=80),
- self._prepare_rule(remote_ip_prefix='192.168.1.0/24'),
- self._prepare_rule(remote_group_id='group1'),
- self._prepare_rule(protocol='tcp',
- remote_ip_prefix='10.1.1.0/24'),
- self._prepare_rule(direction='egress'),
- self._prepare_rule(direction='egress', ethertype='IPv6'),
- ]
- sg = {'security_group_rules': rules}
- expected_data = ['ingress, IPv4',
- 'ingress, IPv4, 80/tcp',
- 'ingress, IPv4, remote_ip_prefix: 192.168.1.0/24',
- 'ingress, IPv4, remote_group_id: group1',
- 'ingress, IPv4, tcp, remote_ip_prefix: 10.1.1.0/24',
- 'egress, IPv4',
- 'egress, IPv6',
- ]
- expected = '\n'.join(sorted(expected_data))
- self.assertEqual(expected, securitygroup._format_sg_rules(sg))
diff --git a/neutronclient/tests/unit/test_cli20_servicetype.py b/neutronclient/tests/unit/test_cli20_servicetype.py
deleted file mode 100644
index ec9a663..0000000
--- a/neutronclient/tests/unit/test_cli20_servicetype.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0 import servicetype
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20ServiceProvidersJSON(test_cli20.CLITestV20Base):
- id_field = "name"
-
- def setUp(self):
- super(CLITestV20ServiceProvidersJSON, self).setUp(
- plurals={'tags': 'tag'}
- )
-
- def test_list_service_providers(self):
- resources = "service_providers"
- cmd = servicetype.ListServiceProvider(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_service_providers_pagination(self):
- resources = "service_providers"
- cmd = servicetype.ListServiceProvider(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_service_providers_sort(self):
- resources = "service_providers"
- cmd = servicetype.ListServiceProvider(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name"],
- sort_dir=["asc", "desc"])
-
- def test_list_service_providers_limit(self):
- resources = "service_providers"
- cmd = servicetype.ListServiceProvider(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
diff --git a/neutronclient/tests/unit/test_cli20_subnet.py b/neutronclient/tests/unit/test_cli20_subnet.py
deleted file mode 100644
index 97c2faf..0000000
--- a/neutronclient/tests/unit/test_cli20_subnet.py
+++ /dev/null
@@ -1,687 +0,0 @@
-# Copyright 2012 OpenStack Foundation.
-# 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 unittest import mock
-
-
-from neutronclient.common import exceptions
-from neutronclient.neutron import v2_0 as neutronV20
-from neutronclient.neutron.v2_0 import subnet
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20SubnetJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['subnet']
-
- def setUp(self):
- super(CLITestV20SubnetJSON, self).setUp(plurals={'tags': 'tag'})
-
- def test_create_subnet(self):
- # Create subnet: --gateway gateway netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = '10.10.10.0/24'
- gateway = 'gatewayvalue'
- args = ['--gateway', gateway, netid, cidr, '--description', 'cave']
- position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
- position_values = [4, netid, cidr, gateway]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- description='cave')
-
- def test_create_subnet_network_cidr_seperated(self):
- # For positional value, network_id and cidr can be separated.
- # Create subnet: --gateway gateway netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = '10.10.10.0/24'
- gateway = 'gatewayvalue'
- args = [netid, '--gateway', gateway, cidr]
- position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
- position_values = [4, netid, cidr, gateway]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_subnet_with_no_gateway(self):
- # Create subnet: --no-gateway netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'cidrvalue'
- args = ['--no-gateway', netid, cidr]
- position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
- position_values = [4, netid, cidr, None]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_subnet_with_segment(self):
- # Create subnet: --segment segment netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = '10.10.10.0/24'
- segment = 'segment'
- args = ['--segment', segment, netid, cidr,
- '--description', 'cave']
- position_names = ['ip_version', 'network_id', 'cidr', 'segment_id']
- position_values = [4, netid, cidr, segment]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- description='cave')
-
- def test_create_subnet_with_bad_gateway_option(self):
- # Create sbunet: --no-gateway netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'cidrvalue'
- gateway = 'gatewayvalue'
- args = ['--gateway', gateway, '--no-gateway', netid, cidr]
- position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
- position_values = [4, netid, cidr, None]
- self.assertRaises(
- SystemExit, self._test_create_resource,
- resource, cmd, name, myid, args, position_names, position_values)
-
- def _test_create_resource_and_catch_command_error(self, should_fail,
- *args):
- if should_fail:
- params = {'no_api_call': True,
- 'expected_exception': exceptions.CommandError}
- else:
- params = {}
- self._test_create_resource(*args, **params)
-
- def test_create_subnet_with_enable_and_disable_dhcp(self):
- # Create subnet: --enable-dhcp and --disable-dhcp.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'cidrvalue'
- position_names = ['ip_version', 'network_id', 'cidr', 'enable_dhcp']
- # enable_dhcp value is appended later inside the loop
- position_values = [4, netid, cidr]
- for enable_dhcp_arg, should_fail in (
- ('--enable-dhcp=False', False),
- ('--enable-dhcp=True', True),
- ('--enable-dhcp', True)
- ):
- tested_args = [enable_dhcp_arg, '--disable-dhcp']
- args = tested_args + [netid, cidr]
- pos_values = position_values + [should_fail]
- self._test_create_resource_and_catch_command_error(
- should_fail,
- resource, cmd, name, myid, args, position_names, pos_values)
-
- def test_create_subnet_with_multiple_enable_dhcp(self):
- # Create subnet with multiple --enable-dhcp arguments passed.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'cidrvalue'
- position_names = ['ip_version', 'network_id', 'cidr', 'enable_dhcp']
- # enable_dhcp value is appended later inside the loop
- position_values = [4, netid, cidr]
-
- _ = 'UNUSED_MARKER'
- for tested_args, should_fail, pos_value in (
- (['--enable-dhcp', '--enable-dhcp=True'], False, True),
- (['--enable-dhcp', '--enable-dhcp=False'], True, _),
- (['--enable-dhcp=False', '--enable-dhcp'], True, _),
- (['--enable-dhcp=True', '--enable-dhcp=False'], True, _),
- (['--enable-dhcp=False', '--enable-dhcp=True'], True, _)
- ):
- args = tested_args + [netid, cidr]
- pos_values = position_values + [pos_value]
- self._test_create_resource_and_catch_command_error(
- should_fail,
- resource, cmd, name, myid, args, position_names, pos_values)
-
- def test_create_subnet_tenant(self):
- # Create subnet: --tenant_id tenantid netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid', netid, cidr]
- position_names = ['ip_version', 'network_id', 'cidr']
- position_values = [4, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_tags(self):
- # Create subnet: netid cidr --tags a b.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = [netid, cidr, '--tags', 'a', 'b']
- position_names = ['ip_version', 'network_id', 'cidr']
- position_values = [4, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tags=['a', 'b'])
-
- def test_create_subnet_allocation_pool(self):
- # Create subnet: --tenant_id tenantid <pool> netid cidr.
- # The <pool> is --allocation_pool start=1.1.1.10,end=1.1.1.20
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--allocation_pool', 'start=1.1.1.10,end=1.1.1.20',
- netid, cidr]
- position_names = ['ip_version', 'allocation_pools', 'network_id',
- 'cidr']
- pool = [{'start': '1.1.1.10', 'end': '1.1.1.20'}]
- position_values = [4, pool, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_allocation_pools(self):
- # Create subnet: --tenant-id tenantid <pools> netid cidr.
- # The <pools> are --allocation_pool start=1.1.1.10,end=1.1.1.20 and
- # --allocation_pool start=1.1.1.30,end=1.1.1.40
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--allocation_pool', 'start=1.1.1.10,end=1.1.1.20',
- '--allocation_pool', 'start=1.1.1.30,end=1.1.1.40',
- netid, cidr]
- position_names = ['ip_version', 'allocation_pools', 'network_id',
- 'cidr']
- pools = [{'start': '1.1.1.10', 'end': '1.1.1.20'},
- {'start': '1.1.1.30', 'end': '1.1.1.40'}]
- position_values = [4, pools, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_host_route(self):
- # Create subnet: --tenant_id tenantid <host_route> netid cidr.
- # The <host_route> is
- # --host-route destination=172.16.1.0/24,nexthop=1.1.1.20
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--host-route', 'destination=172.16.1.0/24,nexthop=1.1.1.20',
- netid, cidr]
- position_names = ['ip_version', 'host_routes', 'network_id',
- 'cidr']
- route = [{'destination': '172.16.1.0/24', 'nexthop': '1.1.1.20'}]
- position_values = [4, route, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_host_routes(self):
- # Create subnet: --tenant-id tenantid <host_routes> netid cidr.
- # The <host_routes> are
- # --host-route destination=172.16.1.0/24,nexthop=1.1.1.20 and
- # --host-route destination=172.17.7.0/24,nexthop=1.1.1.40
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--host-route', 'destination=172.16.1.0/24,nexthop=1.1.1.20',
- '--host-route', 'destination=172.17.7.0/24,nexthop=1.1.1.40',
- netid, cidr]
- position_names = ['ip_version', 'host_routes', 'network_id',
- 'cidr']
- routes = [{'destination': '172.16.1.0/24', 'nexthop': '1.1.1.20'},
- {'destination': '172.17.7.0/24', 'nexthop': '1.1.1.40'}]
- position_values = [4, routes, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_dns_nameservers(self):
- # Create subnet: --tenant-id tenantid <dns-nameservers> netid cidr.
- # The <dns-nameservers> are
- # --dns-nameserver 1.1.1.20 and --dns-nameserver 1.1.1.40
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--dns-nameserver', '1.1.1.20',
- '--dns-nameserver', '1.1.1.40',
- netid, cidr]
- position_names = ['ip_version', 'dns_nameservers', 'network_id',
- 'cidr']
- nameservers = ['1.1.1.20', '1.1.1.40']
- position_values = [4, nameservers, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_with_use_default_subnetpool(self):
- # Create subnet: --tenant-id tenantid --use-default-subnetpool \
- # netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--use-default-subnetpool',
- netid, cidr]
- position_names = ['ip_version', 'use_default_subnetpool', 'network_id',
- 'cidr']
- position_values = [4, True, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_with_disable_dhcp(self):
- # Create subnet: --tenant-id tenantid --disable-dhcp netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--disable-dhcp',
- netid, cidr]
- position_names = ['ip_version', 'enable_dhcp', 'network_id',
- 'cidr']
- position_values = [4, False, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_merge_single_plurar(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--allocation-pool', 'start=1.1.1.10,end=1.1.1.20',
- netid, cidr,
- '--allocation-pools', 'list=true', 'type=dict',
- 'start=1.1.1.30,end=1.1.1.40']
- position_names = ['ip_version', 'allocation_pools', 'network_id',
- 'cidr']
- pools = [{'start': '1.1.1.10', 'end': '1.1.1.20'},
- {'start': '1.1.1.30', 'end': '1.1.1.40'}]
- position_values = [4, pools, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_merge_plurar(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- netid, cidr,
- '--allocation-pools', 'list=true', 'type=dict',
- 'start=1.1.1.30,end=1.1.1.40']
- position_names = ['ip_version', 'allocation_pools', 'network_id',
- 'cidr']
- pools = [{'start': '1.1.1.30', 'end': '1.1.1.40'}]
- position_values = [4, pools, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_merge_single_single(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--allocation-pool', 'start=1.1.1.10,end=1.1.1.20',
- netid, cidr,
- '--allocation-pool',
- 'start=1.1.1.30,end=1.1.1.40']
- position_names = ['ip_version', 'allocation_pools', 'network_id',
- 'cidr']
- pools = [{'start': '1.1.1.10', 'end': '1.1.1.20'},
- {'start': '1.1.1.30', 'end': '1.1.1.40'}]
- position_values = [4, pools, netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_max_v4_cidr(self):
- # Create subnet: --gateway gateway netid cidr.
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = '192.168.0.1/32'
- gateway = 'gatewayvalue'
- args = ['--gateway', gateway, netid, cidr]
- position_names = ['ip_version', 'network_id', 'cidr', 'gateway_ip']
- position_values = [4, netid, cidr, gateway]
- with mock.patch.object(cmd.log, 'warning') as mock_warning:
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
- mock_warning.assert_called_once_with(mock.ANY,
- {'ip': 4, 'cidr': '/32'})
-
- def test_create_subnet_with_ipv6_ra_mode(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '6',
- '--ipv6-ra-mode', 'dhcpv6-stateful',
- netid, cidr]
- position_names = ['ip_version', 'ipv6_ra_mode',
- 'network_id', 'cidr']
- position_values = [6, 'dhcpv6-stateful', netid, cidr]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_with_ipv6_address_mode(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '6',
- '--ipv6-address-mode', 'dhcpv6-stateful',
- netid, cidr]
- position_names = ['ip_version', 'ipv6_address_mode',
- 'network_id', 'cidr']
- position_values = [6, 'dhcpv6-stateful', netid, cidr]
-
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_with_ipv6_modes(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '6',
- '--ipv6-address-mode', 'slaac',
- '--ipv6-ra-mode', 'slaac',
- netid, cidr]
- position_names = ['ip_version', 'ipv6_address_mode',
- 'ipv6_ra_mode', 'network_id', 'cidr']
- position_values = [6, 'slaac', 'slaac', netid, cidr]
-
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- tenant_id='tenantid')
-
- def test_create_subnet_with_ipv6_ra_mode_ipv4(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '4',
- '--ipv6-ra-mode', 'slaac',
- netid, cidr]
- position_names = ['ip_version', 'ipv6_ra_mode',
- 'network_id', 'cidr']
- position_values = [4, None, netid, cidr]
- self._test_create_resource(
- resource, cmd, name, myid, args, position_names,
- position_values, tenant_id='tenantid',
- no_api_call=True, expected_exception=exceptions.CommandError)
-
- def test_create_subnet_with_ipv6_address_mode_ipv4(self):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'prefixvalue'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '4',
- '--ipv6-address-mode', 'slaac',
- netid, cidr]
- position_names = ['ip_version', 'ipv6_address_mode',
- 'network_id', 'cidr']
- position_values = [4, None, netid, cidr]
- self._test_create_resource(
- resource, cmd, name, myid, args, position_names,
- position_values, tenant_id='tenantid',
- no_api_call=True, expected_exception=exceptions.CommandError)
-
- @mock.patch.object(neutronV20, 'find_resource_by_name_or_id')
- def test_create_subnet_with_subnetpool_ipv6_and_ip_ver_ignored(
- self, mock_find_resource):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '4',
- '--subnetpool', 'subnetpool_id',
- netid]
- position_names = ['ip_version', 'network_id', 'subnetpool_id']
- position_values = [6, netid, 'subnetpool_id']
- mock_find_resource.return_value = {
- 'id': 'subnetpool_id', 'ip_version': 6}
- self._test_create_resource(
- resource, cmd, name, myid, args, position_names,
- position_values, tenant_id='tenantid')
- mock_find_resource.assert_called_once_with(
- self.client, 'subnetpool', 'subnetpool_id')
-
- @mock.patch.object(neutronV20, 'find_resource_by_name_or_id')
- def test_create_subnet_with_subnetpool_ipv4_with_cidr_wildcard(
- self, mock_find_resource):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- cidr = 'cidrwildcard'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '4',
- '--ipv6-address-mode', 'slaac',
- '--subnetpool', 'subnetpool_id',
- netid, cidr]
- position_names = ['ip_version', 'ipv6_address_mode',
- 'network_id', 'subnetpool_id', 'cidr']
- position_values = [4, None, netid, 'subnetpool_id', cidr]
- mock_find_resource.return_value = {'id': 'subnetpool_id',
- 'ip_version': 4}
- self._test_create_resource(
- resource, cmd, name, myid, args, position_names,
- position_values, tenant_id='tenantid',
- no_api_call=True, expected_exception=exceptions.CommandError)
- mock_find_resource.assert_called_once_with(
- self.client, 'subnetpool', 'subnetpool_id')
-
- @mock.patch.object(neutronV20, 'find_resource_by_name_or_id')
- def test_create_subnet_with_subnetpool_ipv4_with_prefixlen(
- self, mock_find_resource):
- resource = 'subnet'
- cmd = subnet.CreateSubnet(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- netid = 'netid'
- args = ['--tenant_id', 'tenantid',
- '--ip-version', '4',
- '--ipv6-address-mode', 'slaac',
- '--subnetpool', 'subnetpool_id',
- '--prefixlen', '31',
- netid]
- position_names = ['ip_version', 'ipv6_address_mode',
- 'network_id', 'subnetpool_id']
- position_values = [4, None, netid, 'subnetpool_id']
- mock_find_resource.return_value = {'id': 'subnetpool_id',
- 'ip_version': 4}
- self._test_create_resource(
- resource, cmd, name, myid, args, position_names,
- position_values, tenant_id='tenantid',
- no_api_call=True, expected_exception=exceptions.CommandError)
- mock_find_resource.assert_called_once_with(
- self.client, 'subnetpool', 'subnetpool_id')
-
- def test_list_subnets_detail(self):
- # List subnets: -D.
- resources = "subnets"
- cmd = subnet.ListSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_subnets_tags(self):
- # List subnets: -- --tags a b.
- resources = "subnets"
- cmd = subnet.ListSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, tags=['a', 'b'])
-
- def test_list_subnets_detail_tags(self):
- # List subnets: -D -- --tags a b.
- resources = "subnets"
- cmd = subnet.ListSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, detail=True, tags=['a', 'b'])
-
- def test_list_subnets_fields(self):
- # List subnets: --fields a --fields b -- --fields c d.
- resources = "subnets"
- cmd = subnet.ListSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- fields_1=['a', 'b'], fields_2=['c', 'd'])
-
- def test_list_subnets_pagination(self):
- resources = "subnets"
- cmd = subnet.ListSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_subnets_sort(self):
- # List subnets: --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "subnets"
- cmd = subnet.ListSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_subnets_limit(self):
- # List subnets: -P.
- resources = "subnets"
- cmd = subnet.ListSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_update_subnet(self):
- # Update subnet: myid --name myname --tags a b.
- resource = 'subnet'
- cmd = subnet.UpdateSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'myname',
- '--description', 'cavern',
- '--tags', 'a', 'b'],
- {'name': 'myname', 'tags': ['a', 'b'],
- 'description': 'cavern'})
-
- def test_update_subnet_allocation_pools(self):
- # Update subnet: myid --name myname --tags a b.
- resource = 'subnet'
- cmd = subnet.UpdateSubnet(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--allocation-pool',
- 'start=1.2.0.2,end=1.2.0.127'],
- {'allocation_pools': [{'start': '1.2.0.2',
- 'end': '1.2.0.127'}]}
- )
-
- def test_update_subnet_enable_disable_dhcp(self):
- # Update sbunet: --enable-dhcp and --disable-dhcp.
- resource = 'subnet'
- cmd = subnet.UpdateSubnet(test_cli20.MyApp(sys.stdout), None)
- self.assertRaises(exceptions.CommandError,
- self._test_update_resource,
- resource, cmd, 'myid',
- ['myid', '--name', 'myname', '--enable-dhcp',
- '--disable-dhcp'], {'name': 'myname', })
-
- def test_show_subnet(self):
- # Show subnet: --fields id --fields name myid.
- resource = 'subnet'
- cmd = subnet.ShowSubnet(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_delete_subnet(self):
- # Delete subnet: subnetid.
- resource = 'subnet'
- cmd = subnet.DeleteSubnet(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
diff --git a/neutronclient/tests/unit/test_cli20_subnetpool.py b/neutronclient/tests/unit/test_cli20_subnetpool.py
deleted file mode 100644
index fb20168..0000000
--- a/neutronclient/tests/unit/test_cli20_subnetpool.py
+++ /dev/null
@@ -1,208 +0,0 @@
-# Copyright 2015 OpenStack Foundation.
-# 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 unittest import mock
-
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0 import subnetpool
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20SubnetPoolJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['subnetpool']
-
- def setUp(self):
- super(CLITestV20SubnetPoolJSON, self).setUp(plurals={'tags': 'tag'})
-
- def test_create_subnetpool_with_options(self):
- # Create subnetpool: myname.
- resource = 'subnetpool'
- cmd = subnetpool.CreateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- min_prefixlen = 30
- prefix1 = '10.11.12.0/24'
- prefix2 = '12.11.13.0/24'
- args = [name, '--min-prefixlen', str(min_prefixlen),
- '--pool-prefix', prefix1, '--pool-prefix', prefix2,
- '--shared', '--description', 'public pool',
- '--tenant-id', 'tenantid']
- position_names = ['name', 'min_prefixlen', 'prefixes', 'shared',
- 'tenant_id']
- position_values = [name, min_prefixlen, [prefix1, prefix2], True,
- 'tenantid']
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values,
- description='public pool')
-
- def test_create_subnetpool_only_with_required_options(self):
- # Create subnetpool: myname.
- resource = 'subnetpool'
- cmd = subnetpool.CreateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- min_prefixlen = 30
- prefix1 = '10.11.12.0/24'
- prefix2 = '12.11.13.0/24'
- args = [name, '--min-prefixlen', str(min_prefixlen),
- '--pool-prefix', prefix1, '--pool-prefix', prefix2]
- position_names = ['name', 'min_prefixlen', 'prefixes']
- position_values = [name, min_prefixlen, [prefix1, prefix2]]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_subnetpool_with_is_default(self, default='false'):
- # Create subnetpool: myname.
- resource = 'subnetpool'
- cmd = subnetpool.CreateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- min_prefixlen = 30
- prefix1 = '10.11.12.0/24'
- prefix2 = '12.11.13.0/24'
- args = [name, '--min-prefixlen', str(min_prefixlen),
- '--pool-prefix', prefix1, '--pool-prefix', prefix2,
- '--is-default', default]
- position_names = ['name', 'min_prefixlen', 'prefixes', 'is_default']
- position_values = [name, min_prefixlen, [prefix1, prefix2], default]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_subnetpool_default(self):
- self.test_create_subnetpool_with_is_default(default='true')
-
- def test_create_subnetpool_with_unicode(self):
- # Create subnetpool: u'\u7f51\u7edc'.
- resource = 'subnetpool'
- cmd = subnetpool.CreateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- name = u'\u7f51\u7edc'
- myid = 'myid'
- min_prefixlen = 30
- prefixes = '10.11.12.0/24'
- args = [name, '--min-prefixlen', str(min_prefixlen),
- '--pool-prefix', prefixes]
- position_names = ['name', 'min_prefixlen', 'prefixes']
- position_values = [name, min_prefixlen, [prefixes]]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_subnetpool_with_addrscope(self):
- # Create subnetpool: myname in addrscope: foo-address-scope
- resource = 'subnetpool'
- cmd = subnetpool.CreateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- min_prefixlen = 30
- prefix1 = '11.11.11.0/24'
- prefix2 = '12.12.12.0/24'
- address_scope = 'foo-address-scope'
- args = [name, '--min-prefixlen', str(min_prefixlen),
- '--pool-prefix', prefix1, '--pool-prefix', prefix2,
- '--address-scope', address_scope]
- position_names = ['name', 'min_prefixlen', 'prefixes',
- 'address_scope_id']
- position_values = [name, min_prefixlen, [prefix1, prefix2],
- address_scope]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_create_subnetpool_no_poolprefix(self):
- # Should raise an error because --pool-prefix is required
- resource = 'subnetpool'
- cmd = subnetpool.CreateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- name = 'myname'
- myid = 'myid'
- args = [name]
- position_names = ['name']
- position_values = [name]
- self.assertRaises(SystemExit, self._test_create_resource, resource,
- cmd, name, myid, args, position_names,
- position_values)
-
- @mock.patch.object(subnetpool.ListSubnetPool, "extend_list")
- def test_list_subnetpool_pagination(self, mock_extend_list):
- cmd = subnetpool.ListSubnetPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination("subnetpools", cmd)
- mock_extend_list.assert_called_once_with(test_cli20.IsA(list),
- mock.ANY)
-
- def test_list_subnetpools_sort(self):
- # List subnetpools:
- # --sort-key name --sort-key id --sort-key asc --sort-key desc
- resources = "subnetpools"
- cmd = subnetpool.ListSubnetPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_subnetpools_limit(self):
- # List subnetpools: -P.
- resources = "subnetpools"
- cmd = subnetpool.ListSubnetPool(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_update_subnetpool_exception(self):
- # Update subnetpool: myid.
- resource = 'subnetpool'
- cmd = subnetpool.UpdateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- self.assertRaises(exceptions.CommandError, self._test_update_resource,
- resource, cmd, 'myid', ['myid'], {})
-
- def test_update_subnetpool(self):
- # Update subnetpool: myid --name myname.
- resource = 'subnetpool'
- cmd = subnetpool.UpdateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'myname',
- '--description', ':)'],
- {'name': 'myname', 'description': ':)'})
-
- def test_update_subnetpool_with_address_scope(self):
- # Update subnetpool: myid --address-scope newscope.
- resource = 'subnetpool'
- cmd = subnetpool.UpdateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--address-scope', 'newscope'],
- {'address_scope_id': 'newscope'}
- )
-
- def test_update_subnetpool_with_no_address_scope(self):
- # Update subnetpool: myid --no-address-scope.
- resource = 'subnetpool'
- cmd = subnetpool.UpdateSubnetPool(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--no-address-scope'],
- {'address_scope_id': None}
- )
-
- def test_show_subnetpool(self):
- # Show subnetpool: --fields id --fields name myid.
- resource = 'subnetpool'
- cmd = subnetpool.ShowSubnetPool(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_delete_subnetpool(self):
- # Delete subnetpool: subnetpoolid.
- resource = 'subnetpool'
- cmd = subnetpool.DeleteSubnetPool(test_cli20.MyApp(sys.stdout), None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
diff --git a/neutronclient/tests/unit/test_cli20_tag.py b/neutronclient/tests/unit/test_cli20_tag.py
deleted file mode 100644
index 2e23c9d..0000000
--- a/neutronclient/tests/unit/test_cli20_tag.py
+++ /dev/null
@@ -1,131 +0,0 @@
-# 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 unittest import mock
-
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0 import network
-from neutronclient.neutron.v2_0 import tag
-from neutronclient import shell
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20Tag(test_cli20.CLITestV20Base):
- def _test_tag_operation(self, cmd, path, method, args, prog_name,
- body=None):
- with mock.patch.object(cmd, 'get_client',
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, 'request',
- return_value=(test_cli20.MyResp(204), None)
- ) as mock_request:
- if body:
- body = test_cli20.MyComparator(body, self.client)
- cmd_parser = cmd.get_parser(prog_name)
- shell.run_command(cmd, cmd_parser, args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(test_cli20.end_url(path), self.client),
- method, body=body,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- def _test_tags_query(self, cmd, resources, args, query):
- path = getattr(self.client, resources + "_path")
- res = {resources: [{'id': 'myid'}]}
- resstr = self.client.serialize(res)
- with mock.patch.object(cmd, 'get_client',
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, 'request',
- return_value=(test_cli20.MyResp(200), resstr)
- ) as mock_request:
- cmd_parser = cmd.get_parser("list_networks")
- shell.run_command(cmd, cmd_parser, args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(test_cli20.end_url(path, query),
- self.client),
- 'GET', body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- _str = self.fake_stdout.make_string()
- self.assertIn('myid', _str)
-
- def _make_tag_path(self, resource, resource_id, tag):
- path = getattr(self.client, "tag_path")
- resource_plural = self.client.get_resource_plural(resource)
- return path % (resource_plural, resource_id, tag)
-
- def _make_tags_path(self, resource, resource_id):
- path = getattr(self.client, "tags_path")
- resource_plural = self.client.get_resource_plural(resource)
- return path % (resource_plural, resource_id)
-
- def test_add_tag(self):
- cmd = tag.AddTag(test_cli20.MyApp(sys.stdout), None)
- path = self._make_tag_path('network', 'myid', 'red')
- args = ['--resource-type', 'network', '--resource', 'myid',
- '--tag', 'red']
- self._test_tag_operation(cmd, path, 'PUT', args, "tag-add")
-
- def test_add_tag_empty_tag(self):
- cmd = tag.AddTag(test_cli20.MyApp(sys.stdout), None)
- path = self._make_tag_path('network', 'myid', '')
- args = ['--resource-type', 'network', '--resource', 'myid',
- '--tag', '']
- self.assertRaises(exceptions.CommandError, self._test_tag_operation,
- cmd, path, 'PUT', args, "tag-add")
-
- def test_replace_tag(self):
- cmd = tag.ReplaceTag(test_cli20.MyApp(sys.stdout), None)
- path = self._make_tags_path('network', 'myid')
- args = ['--resource-type', 'network', '--resource', 'myid',
- '--tag', 'red', '--tag', 'blue']
- body = {'tags': ['red', 'blue']}
- self._test_tag_operation(cmd, path, 'PUT', args, "tag-replace",
- body=body)
-
- def test_remove_tag(self):
- cmd = tag.RemoveTag(test_cli20.MyApp(sys.stdout), None)
- path = self._make_tag_path('network', 'myid', 'red')
- args = ['--resource-type', 'network', '--resource', 'myid',
- '--tag', 'red']
- self._test_tag_operation(cmd, path, 'DELETE', args, "tag-remove")
-
- def test_remove_tag_all(self):
- cmd = tag.RemoveTag(test_cli20.MyApp(sys.stdout), None)
- path = self._make_tags_path('network', 'myid')
- args = ['--resource-type', 'network', '--resource', 'myid',
- '--all']
- self._test_tag_operation(cmd, path, 'DELETE', args, "tag-remove")
-
- def test_no_tag_nor_all(self):
- cmd = tag.RemoveTag(test_cli20.MyApp(sys.stdout), None)
- path = self._make_tags_path('network', 'myid')
- args = ['--resource-type', 'network', '--resource', 'myid']
- self.assertRaises(exceptions.CommandError, self._test_tag_operation,
- cmd, path, 'DELETE', args, "tag-remove")
-
- def test_tags_query(self):
- # This test examines that '-' in the tag related filters
- # is not converted to '_'.
- resources = 'networks'
- cmd = network.ListNetwork(test_cli20.MyApp(sys.stdout), None)
- with mock.patch.object(network.ListNetwork, 'extend_list'):
- args = ['--not-tags', 'red,blue', '--tags-any', 'green',
- '--not-tags-any', 'black']
- query = "not-tags=red,blue&tags-any=green&not-tags-any=black"
- self._test_tags_query(cmd, resources, args, query)
diff --git a/neutronclient/tests/unit/test_client_extension.py b/neutronclient/tests/unit/test_client_extension.py
deleted file mode 100644
index 871e7a6..0000000
--- a/neutronclient/tests/unit/test_client_extension.py
+++ /dev/null
@@ -1,221 +0,0 @@
-# Copyright 2015 Rackspace Hosting 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.
-#
-
-import inspect
-import sys
-from unittest import mock
-
-
-from neutronclient.common import extension
-from neutronclient.neutron.v2_0.contrib import _fox_sockets as fox_sockets
-from neutronclient import shell
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20ExtensionJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['fox_socket']
-
- def setUp(self):
- # need to mock before super because extensions loaded on instantiation
- self._mock_extension_loading()
- super(CLITestV20ExtensionJSON, self).setUp(plurals={'tags': 'tag'})
-
- def _mock_extension_loading(self):
- ext_pkg = 'neutronclient.common.extension'
- contrib = mock.patch(ext_pkg + '._discover_via_entry_points').start()
- contrib.return_value = [("_fox_sockets", fox_sockets)]
- return contrib
-
- def test_ext_cmd_loaded(self):
- neutron_shell = shell.NeutronShell('2.0')
- ext_cmd = {'fox-sockets-list': fox_sockets.FoxInSocketsList,
- 'fox-sockets-create': fox_sockets.FoxInSocketsCreate,
- 'fox-sockets-update': fox_sockets.FoxInSocketsUpdate,
- 'fox-sockets-delete': fox_sockets.FoxInSocketsDelete,
- 'fox-sockets-show': fox_sockets.FoxInSocketsShow}
- for cmd_name, cmd_class in ext_cmd.items():
- found = neutron_shell.command_manager.find_command([cmd_name])
- self.assertEqual(cmd_class, found[0])
-
- def test_ext_cmd_help_doc_with_extension_name(self):
- neutron_shell = shell.NeutronShell('2.0')
- ext_cmd = {'fox-sockets-list': fox_sockets.FoxInSocketsList,
- 'fox-sockets-create': fox_sockets.FoxInSocketsCreate,
- 'fox-sockets-update': fox_sockets.FoxInSocketsUpdate,
- 'fox-sockets-delete': fox_sockets.FoxInSocketsDelete,
- 'fox-sockets-show': fox_sockets.FoxInSocketsShow}
- for cmd_name, cmd_class in ext_cmd.items():
- found = neutron_shell.command_manager.find_command([cmd_name])
- found_factory = found[0]
- self.assertEqual(cmd_class, found_factory)
- self.assertTrue(found_factory.__doc__.startswith("[_fox_sockets]"))
-
- def test_delete_fox_socket(self):
- # Delete fox socket: myid.
- resource = 'fox_socket'
- cmd = fox_sockets.FoxInSocketsDelete(test_cli20.MyApp(sys.stdout),
- None)
- myid = 'myid'
- args = [myid]
- self._test_delete_resource(resource, cmd, myid, args)
-
- def test_update_fox_socket(self):
- # Update fox_socket: myid --name myname.
- resource = 'fox_socket'
- cmd = fox_sockets.FoxInSocketsUpdate(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'myname'],
- {'name': 'myname'})
-
- def test_create_fox_socket(self):
- # Create fox_socket: myname.
- resource = 'fox_socket'
- cmd = fox_sockets.FoxInSocketsCreate(test_cli20.MyApp(sys.stdout),
- None)
- name = 'myname'
- myid = 'myid'
- args = [name, ]
- position_names = ['name', ]
- position_values = [name, ]
- self._test_create_resource(resource, cmd, name, myid, args,
- position_names, position_values)
-
- def test_list_fox_sockets(self):
- # List fox_sockets.
- resources = 'fox_sockets'
- cmd = fox_sockets.FoxInSocketsList(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_fox_pagination(self):
- resources = 'fox_sockets'
- cmd = fox_sockets.FoxInSocketsList(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_show_fox_socket(self):
- # Show fox_socket: --fields id --fields name myid.
- resource = 'fox_socket'
- cmd = fox_sockets.FoxInSocketsShow(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'])
-
-
-class CLITestV20ExtensionJSONAlternatePlurals(test_cli20.CLITestV20Base):
- class IPAddress(extension.NeutronClientExtension):
- resource = 'ip_address'
- resource_plural = '%ses' % resource
- object_path = '/%s' % resource_plural
- resource_path = '/%s/%%s' % resource_plural
- versions = ['2.0']
-
- class IPAddressesList(extension.ClientExtensionList, IPAddress):
- shell_command = 'ip-address-list'
-
- def setUp(self):
- # need to mock before super because extensions loaded on instantiation
- self._mock_extension_loading()
- super(CLITestV20ExtensionJSONAlternatePlurals, self).setUp()
-
- def _mock_extension_loading(self):
- ext_pkg = 'neutronclient.common.extension'
- contrib = mock.patch(ext_pkg + '._discover_via_entry_points').start()
- ip_address = mock.Mock()
- ip_address.IPAddress = self.IPAddress
- ip_address.IPAddressesList = self.IPAddressesList
- contrib.return_value = [("ip_address", ip_address)]
- return contrib
-
- def test_ext_cmd_loaded(self):
- neutron_shell = shell.NeutronShell('2.0')
- ext_cmd = {'ip-address-list': self.IPAddressesList}
- for cmd_name, cmd_class in ext_cmd.items():
- found = neutron_shell.command_manager.find_command([cmd_name])
- self.assertEqual(cmd_class, found[0])
-
- def test_list_ip_addresses(self):
- # List ip_addresses.
- resources = 'ip_addresses'
- cmd = self.IPAddressesList(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
-
-class CLITestV20ExtensionJSONChildResource(test_cli20.CLITestV20Base):
- class Child(extension.NeutronClientExtension):
- parent_resource = 'parents'
- child_resource = 'child'
- resource = '%s_%s' % (parent_resource, child_resource)
- resource_plural = '%sren' % resource
- child_resource_plural = '%ren' % child_resource
- object_path = '/%s/%%s/%s' % (parent_resource, child_resource_plural)
- resource_path = '/%s/%%s/%s/%%s' % (parent_resource,
- child_resource_plural)
- versions = ['2.0']
-
- class ChildrenList(extension.ClientExtensionList, Child):
- shell_command = 'parent-child-list'
-
- class ChildShow(extension.ClientExtensionShow, Child):
- shell_command = 'parent-child-show'
-
- class ChildUpdate(extension.ClientExtensionUpdate, Child):
- shell_command = 'parent-child-update'
-
- class ChildDelete(extension.ClientExtensionDelete, Child):
- shell_command = 'parent-child-delete'
-
- class ChildCreate(extension.ClientExtensionCreate, Child):
- shell_command = 'parent-child-create'
-
- def setUp(self):
- # need to mock before super because extensions loaded on instantiation
- self._mock_extension_loading()
- super(CLITestV20ExtensionJSONChildResource, self).setUp()
-
- def _mock_extension_loading(self):
- ext_pkg = 'neutronclient.common.extension'
- contrib = mock.patch(ext_pkg + '._discover_via_entry_points').start()
- child = mock.Mock()
- child.Child = self.Child
- child.ChildrenList = self.ChildrenList
- child.ChildShow = self.ChildShow
- child.ChildUpdate = self.ChildUpdate
- child.ChildDelete = self.ChildDelete
- child.ChildCreate = self.ChildCreate
- contrib.return_value = [("child", child)]
- return contrib
-
- def test_ext_cmd_loaded(self):
- neutron_shell = shell.NeutronShell('2.0')
- ext_cmd = {'parent-child-list': self.ChildrenList,
- 'parent-child-show': self.ChildShow,
- 'parent-child-update': self.ChildUpdate,
- 'parent-child-delete': self.ChildDelete,
- 'parent-child-create': self.ChildCreate}
- for cmd_name, cmd_class in ext_cmd.items():
- found = neutron_shell.command_manager.find_command([cmd_name])
- self.assertEqual(cmd_class, found[0])
-
- def test_client_methods_have_parent_id_arg(self):
- methods = (self.client.list_parents_children,
- self.client.show_parents_child,
- self.client.update_parents_child,
- self.client.delete_parents_child,
- self.client.create_parents_child)
- for method in methods:
- argspec = inspect.getfullargspec(method)
- self.assertIn("parent_id", argspec.args)
diff --git a/neutronclient/tests/unit/test_name_or_id.py b/neutronclient/tests/unit/test_name_or_id.py
deleted file mode 100644
index a6a7b92..0000000
--- a/neutronclient/tests/unit/test_name_or_id.py
+++ /dev/null
@@ -1,244 +0,0 @@
-# Copyright 2012 OpenStack Foundation.
-# 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.
-#
-
-from unittest import mock
-
-from oslo_utils import uuidutils
-import testtools
-
-from neutronclient.common import exceptions
-from neutronclient.neutron import v2_0 as neutronV20
-from neutronclient.tests.unit import test_cli20
-from neutronclient.v2_0 import client
-
-
-class CLITestNameorID(testtools.TestCase):
-
- def setUp(self):
- """Prepare the test environment."""
- super(CLITestNameorID, self).setUp()
- self.endurl = test_cli20.ENDURL
- self.client = client.Client(token=test_cli20.TOKEN,
- endpoint_url=self.endurl)
-
- def test_get_id_from_id(self):
- _id = uuidutils.generate_uuid()
- reses = {'networks': [{'id': _id, }, ], }
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- path = getattr(self.client, "networks_path")
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- returned_id = neutronV20.find_resourceid_by_name_or_id(
- self.client, 'network', _id)
-
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&id=" + _id),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- self.assertEqual(_id, returned_id)
-
- def test_get_id_from_id_then_name_empty(self):
- _id = uuidutils.generate_uuid()
- reses = {'networks': [{'id': _id, }, ], }
- resstr = self.client.serialize(reses)
- resstr1 = self.client.serialize({'networks': []})
- path = getattr(self.client, "networks_path")
- with mock.patch.object(self.client.httpclient,
- "request") as mock_request:
- mock_request.side_effect = [(test_cli20.MyResp(200), resstr1),
- (test_cli20.MyResp(200), resstr)]
- returned_id = neutronV20.find_resourceid_by_name_or_id(
- self.client, 'network', _id)
-
- self.assertEqual(2, mock_request.call_count)
- mock_request.assert_has_calls([
- mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&id=" + _id),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN})),
- mock.call(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&name=" + _id),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))])
- self.assertEqual(_id, returned_id)
-
- def test_get_id_from_name(self):
- name = 'myname'
- _id = uuidutils.generate_uuid()
- reses = {'networks': [{'id': _id, }, ], }
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- path = getattr(self.client, "networks_path")
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- returned_id = neutronV20.find_resourceid_by_name_or_id(
- self.client, 'network', name)
-
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&name=" + name),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- self.assertEqual(_id, returned_id)
-
- def test_get_id_from_name_multiple(self):
- name = 'myname'
- reses = {'networks': [{'id': uuidutils.generate_uuid()},
- {'id': uuidutils.generate_uuid()}]}
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- path = getattr(self.client, "networks_path")
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- exception = self.assertRaises(
- exceptions.NeutronClientNoUniqueMatch,
- neutronV20.find_resourceid_by_name_or_id,
- self.client, 'network', name)
-
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&name=" + name),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- self.assertIn('Multiple', exception.message)
-
- def test_get_id_from_name_notfound(self):
- name = 'myname'
- reses = {'networks': []}
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- path = getattr(self.client, "networks_path")
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- exception = self.assertRaises(
- exceptions.NotFound,
- neutronV20.find_resourceid_by_name_or_id,
- self.client, 'network', name)
-
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&name=" + name),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- self.assertIn('Unable to find', exception.message)
- self.assertEqual(404, exception.status_code)
-
- def test_get_id_from_name_multiple_with_project(self):
- name = 'web_server'
- project = uuidutils.generate_uuid()
- expect_id = uuidutils.generate_uuid()
- reses = {'security_groups':
- [{'id': expect_id, 'tenant_id': project}]}
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- path = getattr(self.client, "security_groups_path")
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- observed_id = neutronV20.find_resourceid_by_name_or_id(
- self.client, 'security_group', name, project)
-
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&name=%s&tenant_id=%s" %
- (name, project)), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- self.assertEqual(expect_id, observed_id)
-
- def test_get_id_from_name_multiple_with_project_not_found(self):
- name = 'web_server'
- project = uuidutils.generate_uuid()
- resstr_notfound = self.client.serialize({'security_groups': []})
- resp = (test_cli20.MyResp(200), resstr_notfound)
- path = getattr(self.client, "security_groups_path")
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- exc = self.assertRaises(exceptions.NotFound,
- neutronV20.find_resourceid_by_name_or_id,
- self.client, 'security_group', name,
- project)
-
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, "fields=id&name=%s&tenant_id=%s" %
- (name, project)), self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- self.assertIn('Unable to find', exc.message)
- self.assertEqual(404, exc.status_code)
-
- def _test_get_resource_by_id(self, id_only=False):
- _id = uuidutils.generate_uuid()
- net = {'id': _id, 'name': 'test'}
- reses = {'networks': [net], }
- resstr = self.client.serialize(reses)
- resp = (test_cli20.MyResp(200), resstr)
- path = getattr(self.client, "networks_path")
- if id_only:
- query_params = "fields=id&id=%s" % _id
- else:
- query_params = "id=%s" % _id
- with mock.patch.object(self.client.httpclient, "request",
- return_value=resp) as mock_request:
- if id_only:
- returned_id = neutronV20.find_resourceid_by_id(
- self.client, 'network', _id)
- self.assertEqual(_id, returned_id)
- else:
- result = neutronV20.find_resource_by_id(
- self.client, 'network', _id)
- self.assertEqual(net, result)
-
- mock_request.assert_called_once_with(
- test_cli20.MyUrlComparator(
- test_cli20.end_url(path, query_params),
- self.client),
- 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
-
- def test_get_resource_by_id(self):
- self._test_get_resource_by_id(id_only=False)
-
- def test_get_resourceid_by_id(self):
- self._test_get_resource_by_id(id_only=True)
diff --git a/neutronclient/tests/unit/test_quota.py b/neutronclient/tests/unit/test_quota.py
deleted file mode 100644
index 747621d..0000000
--- a/neutronclient/tests/unit/test_quota.py
+++ /dev/null
@@ -1,99 +0,0 @@
-# Copyright (C) 2013 Yahoo! 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.
-
-import sys
-from unittest import mock
-
-
-from neutronclient.common import exceptions
-from neutronclient.neutron.v2_0 import quota as test_quota
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20Quota(test_cli20.CLITestV20Base):
- def test_show_quota(self):
- resource = 'quota'
- cmd = test_quota.ShowQuota(
- test_cli20.MyApp(sys.stdout), None)
- args = ['--tenant-id', self.test_id]
- self._test_show_resource(resource, cmd, self.test_id, args)
-
- def test_update_quota(self):
- resource = 'quota'
- cmd = test_quota.UpdateQuota(
- test_cli20.MyApp(sys.stdout), None)
- args = ['--tenant-id', self.test_id, '--network', 'test']
- self.assertRaises(
- exceptions.CommandError, self._test_update_resource,
- resource, cmd, self.test_id, args=args,
- extrafields={'network': 'new'})
-
- def test_delete_quota_get_parser(self):
- cmd = test_cli20.MyApp(sys.stdout)
- test_quota.DeleteQuota(cmd, None).get_parser(cmd)
-
- def test_show_quota_positional(self):
- resource = 'quota'
- cmd = test_quota.ShowQuota(
- test_cli20.MyApp(sys.stdout), None)
- args = [self.test_id]
- self._test_show_resource(resource, cmd, self.test_id, args)
-
- def test_update_quota_positional(self):
- resource = 'quota'
- cmd = test_quota.UpdateQuota(
- test_cli20.MyApp(sys.stdout), None)
- args = [self.test_id, '--network', 'test']
- self.assertRaises(
- exceptions.CommandError, self._test_update_resource,
- resource, cmd, self.test_id, args=args,
- extrafields={'network': 'new'})
-
- def test_show_quota_default(self):
- resource = 'quota'
- cmd = test_quota.ShowQuotaDefault(
- test_cli20.MyApp(sys.stdout), None)
- args = ['--tenant-id', self.test_id]
- expected_res = {'quota': {'port': 50, 'network': 10, 'subnet': 10}}
- resstr = self.client.serialize(expected_res)
- path = getattr(self.client, "quota_default_path")
- return_tup = (test_cli20.MyResp(200), resstr)
- with mock.patch.object(cmd, 'get_client',
- return_value=self.client) as mock_get_client, \
- mock.patch.object(self.client.httpclient, 'request',
- return_value=return_tup) as mock_request:
- cmd_parser = cmd.get_parser("test_" + resource)
- parsed_args = cmd_parser.parse_args(args)
- cmd.run(parsed_args)
-
- mock_get_client.assert_called_once_with()
- mock_request.assert_called_once_with(
- test_cli20.end_url(path % self.test_id), 'GET',
- body=None,
- headers=test_cli20.ContainsKeyValue(
- {'X-Auth-Token': test_cli20.TOKEN}))
- _str = self.fake_stdout.make_string()
- self.assertIn('network', _str)
- self.assertIn('subnet', _str)
- self.assertIn('port', _str)
- self.assertNotIn('subnetpool', _str)
-
- def test_update_quota_noargs(self):
- resource = 'quota'
- cmd = test_quota.UpdateQuota(test_cli20.MyApp(sys.stdout), None)
- args = [self.test_id]
- self.assertRaises(exceptions.CommandError, self._test_update_resource,
- resource, cmd, self.test_id, args=args,
- extrafields=None)
diff --git a/neutronclient/tests/unit/test_shell.py b/neutronclient/tests/unit/test_shell.py
deleted file mode 100644
index 04e8140..0000000
--- a/neutronclient/tests/unit/test_shell.py
+++ /dev/null
@@ -1,366 +0,0 @@
-# Copyright (C) 2013 Yahoo! 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.
-
-import argparse
-from io import StringIO
-import logging
-import os
-import re
-import sys
-from unittest import mock
-
-import fixtures
-from keystoneauth1 import session
-import testtools
-from testtools import matchers
-
-from neutronclient.common import clientmanager
-from neutronclient.neutron.v2_0 import network
-from neutronclient import shell as openstack_shell
-
-
-DEFAULT_USERNAME = 'username'
-DEFAULT_PASSWORD = 'password'
-DEFAULT_TENANT_ID = 'tenant_id'
-DEFAULT_TENANT_NAME = 'tenant_name'
-DEFAULT_AUTH_URL = 'http://127.0.0.1:5000/v2.0/'
-DEFAULT_TOKEN = '3bcc3d3a03f44e3d8377f9247b0ad155'
-DEFAULT_URL = 'http://quantum.example.org:9696/'
-DEFAULT_REGION = 'regionOne'
-DEFAULT_ENDPOINT_TYPE = 'public'
-DEFAULT_API_VERSION = '2.0'
-DEFAULT_SERVICE_TYPE = 'network'
-DEFAULT_SERVICE_NAME = 'neutron'
-DEFAULT_RETRIES = 3
-DEFAULT_TIMEOUT = 3.0
-
-
-class ShellTest(testtools.TestCase):
-
- FAKE_ENV = {
- 'OS_USERNAME': DEFAULT_USERNAME,
- 'OS_PASSWORD': DEFAULT_PASSWORD,
- 'OS_TENANT_ID': DEFAULT_TENANT_ID,
- 'OS_TENANT_NAME': DEFAULT_TENANT_NAME,
- 'OS_AUTH_URL': DEFAULT_AUTH_URL,
- 'OS_REGION_NAME': None,
- 'HTTP_PROXY': None,
- 'http_proxy': None,
- }
-
- # Patch os.environ to avoid required auth info.
- def setUp(self):
- super(ShellTest, self).setUp()
- for var in self.FAKE_ENV:
- self.useFixture(
- fixtures.EnvironmentVariable(
- var, self.FAKE_ENV[var]))
-
- def shell(self, argstr, check=False, expected_val=0):
- # expected_val is the expected return value after executing
- # the command in NeutronShell
- orig = (sys.stdout, sys.stderr)
- clean_env = {}
- _old_env, os.environ = os.environ, clean_env.copy()
- try:
- sys.stdout = StringIO()
- sys.stderr = StringIO()
- _shell = openstack_shell.NeutronShell('2.0')
- _shell.run(argstr.split())
- except SystemExit:
- exc_type, exc_value, exc_traceback = sys.exc_info()
- self.assertEqual(expected_val, exc_value.code)
- finally:
- stdout = sys.stdout.getvalue()
- stderr = sys.stderr.getvalue()
- sys.stdout.close()
- sys.stderr.close()
- sys.stdout, sys.stderr = orig
- os.environ = _old_env
- return stdout, stderr
-
- def test_run_unknown_command(self):
- self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
- stdout, stderr = self.shell('fake', check=True)
- self.assertFalse(stdout)
- self.assertIn("Unknown command ['fake']", stderr.strip())
-
- def test_help(self):
- required = 'usage:'
- help_text, stderr = self.shell('help')
- self.assertThat(
- help_text,
- matchers.MatchesRegex(required))
-
- def test_bash_completion(self):
- required = '.*os_user_domain_id.*'
- bash_completion, stderr = self.shell('bash-completion')
- self.assertThat(
- bash_completion,
- matchers.MatchesRegex(required))
-
- def test_help_on_subcommand(self):
- required = [
- '.*?^usage: .* quota-list']
- stdout, stderr = self.shell('help quota-list')
- for r in required:
- self.assertThat(
- stdout,
- matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
-
- def test_help_command(self):
- required = 'usage:'
- help_text, stderr = self.shell('help network-create')
- self.assertThat(
- help_text,
- matchers.MatchesRegex(required))
-
- def test_bash_completion_in_outputs_of_help_command(self):
- help_text, stderr = self.shell('help')
- completion_cmd = "bash-completion"
- completion_help_str = ("Prints all of the commands and options "
- "for bash-completion.")
- self.assertIn(completion_cmd, help_text)
- self.assertIn(completion_help_str, help_text)
-
- def test_bash_completion_command(self):
- # just check we have some output
- required = [
- '.*--tenant_id',
- '.*help',
- '.*--dns-nameserver']
- help_text, stderr = self.shell('neutron bash-completion')
- for r in required:
- self.assertThat(help_text,
- matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))
-
- def test_build_option_parser(self):
- neutron_shell = openstack_shell.NeutronShell('2.0')
- result = neutron_shell.build_option_parser('descr', '2.0')
- self.assertIsInstance(result, argparse.ArgumentParser)
-
- @mock.patch.object(openstack_shell.NeutronShell, 'run')
- def test_main_with_unicode(self, fake_shell):
- unicode_text = u'\u7f51\u7edc'
- argv = ['net-list', unicode_text, unicode_text]
- fake_shell.return_value = 0
- ret = openstack_shell.main(argv=argv)
- fake_shell.assert_called_once_with([u'net-list', unicode_text,
- unicode_text])
- self.assertEqual(0, ret)
-
- def test_endpoint_option(self):
- shell = openstack_shell.NeutronShell('2.0')
- parser = shell.build_option_parser('descr', '2.0')
-
- # Neither $OS_ENDPOINT_TYPE nor --os-endpoint-type
- namespace = parser.parse_args([])
- self.assertEqual('public', namespace.os_endpoint_type)
-
- # --endpoint-type but not $OS_ENDPOINT_TYPE
- namespace = parser.parse_args(['--os-endpoint-type=admin'])
- self.assertEqual('admin', namespace.os_endpoint_type)
-
- def test_endpoint_environment_variable(self):
- fixture = fixtures.EnvironmentVariable("OS_ENDPOINT_TYPE",
- "public")
- self.useFixture(fixture)
-
- shell = openstack_shell.NeutronShell('2.0')
- parser = shell.build_option_parser('descr', '2.0')
-
- # $OS_ENDPOINT_TYPE but not --endpoint-type
- namespace = parser.parse_args([])
- self.assertEqual("public", namespace.os_endpoint_type)
-
- # --endpoint-type and $OS_ENDPOINT_TYPE
- namespace = parser.parse_args(['--endpoint-type=admin'])
- self.assertEqual('admin', namespace.endpoint_type)
-
- def test_timeout_option(self):
- shell = openstack_shell.NeutronShell('2.0')
- parser = shell.build_option_parser('descr', '2.0')
-
- # Neither $OS_ENDPOINT_TYPE nor --endpoint-type
- namespace = parser.parse_args([])
- self.assertIsNone(namespace.http_timeout)
-
- # --endpoint-type but not $OS_ENDPOINT_TYPE
- namespace = parser.parse_args(['--http-timeout=50'])
- self.assertEqual(50, namespace.http_timeout)
-
- def test_timeout_environment_variable(self):
- fixture = fixtures.EnvironmentVariable("OS_NETWORK_TIMEOUT",
- "50")
- self.useFixture(fixture)
-
- shell = openstack_shell.NeutronShell('2.0')
- parser = shell.build_option_parser('descr', '2.0')
-
- namespace = parser.parse_args([])
- self.assertEqual(50, namespace.http_timeout)
-
- def test_run_incomplete_command(self):
- self.useFixture(fixtures.FakeLogger(level=logging.DEBUG))
- cmd = (
- '--os-username test --os-password test --os-project-id test '
- '--os-auth-strategy keystone --os-auth-url '
- '%s port-create' %
- DEFAULT_AUTH_URL)
- stdout, stderr = self.shell(cmd, check=True, expected_val=2)
- search_str = "Try 'neutron help port-create' for more information"
- self.assertTrue(any(search_str in string for string
- in stderr.split('\n')))
-
- def _test_authenticate_user(self, expect_verify, expect_insecure,
- **options):
- base_options = {'os_cloud': None,
- 'http_timeout': DEFAULT_TIMEOUT,
- 'region_name': DEFAULT_REGION,
- 'network_service_name': DEFAULT_SERVICE_NAME,
- 'neutron_service_type': DEFAULT_SERVICE_TYPE}
-
- options.update(base_options)
- if options.get('os_token'):
- options.update({'auth_type': 'token'})
- options.update({'os_token': 'token', 'os_url': 'url'})
- else:
- options.update({'os_token': None, 'os_url': None})
-
- with mock.patch.object(openstack_shell.NeutronShell,
- 'run_subcommand'), \
- mock.patch.object(session, 'Session') as session_mock, \
- mock.patch.object(clientmanager, 'ClientManager') as cmgr_mock:
-
- shell = openstack_shell.NeutronShell(DEFAULT_API_VERSION)
- shell.options = mock.Mock(spec=options.keys())
- for k, v in options.items():
- setattr(shell.options, k, v)
- shell.options.os_endpoint_type = DEFAULT_ENDPOINT_TYPE
- shell.options.retries = DEFAULT_RETRIES
-
- if not (options.get('os_token') and options.get('os_url')):
- auth = mock.ANY
- auth_session = mock.sentinel.session
- session_mock.return_value = auth_session
- else:
- auth = None
- auth_session = None
-
- shell.authenticate_user()
-
- if not (options.get('os_token') and options.get('os_url')):
- session_mock.assert_called_once_with(
- auth=mock.ANY, verify=expect_verify,
- cert=options.get('cert'),
- timeout=DEFAULT_TIMEOUT)
- else:
- self.assertFalse(session_mock.called)
-
- cmgr_mock.assert_called_once_with(
- retries=DEFAULT_RETRIES,
- raise_errors=False,
- session=auth_session,
- url=options.get('os_url'),
- token=options.get('os_token'),
- region_name=DEFAULT_REGION,
- api_version=DEFAULT_API_VERSION,
- service_type=DEFAULT_SERVICE_TYPE,
- service_name=DEFAULT_SERVICE_NAME,
- endpoint_type=DEFAULT_ENDPOINT_TYPE,
- auth=auth,
- insecure=expect_insecure,
- log_credentials=True)
-
- def test_authenticate_secure_with_cacert_with_cert(self):
- self._test_authenticate_user(
- insecure=False, cacert='cacert', cert='cert',
- expect_verify='cacert', expect_insecure=False)
-
- def test_authenticate_secure_with_cacert_with_cert_with_token(self):
- self._test_authenticate_user(
- os_token='token',
- insecure=False, cacert='cacert', cert='cert',
- expect_verify='cacert', expect_insecure=False)
-
- def test_authenticate_insecure_with_cacert_with_cert(self):
- self._test_authenticate_user(
- insecure=True, cacert='cacert', cert='cert',
- expect_verify=False, expect_insecure=True)
-
- def test_authenticate_insecure_with_cacert_with_cert_with_token(self):
- self._test_authenticate_user(
- os_token='token',
- insecure=True, cacert='cacert', cert='cert',
- expect_verify=False, expect_insecure=True)
-
- def test_authenticate_secure_without_cacert_with_cert(self):
- self._test_authenticate_user(
- insecure=False, cert='cert',
- expect_verify=True, expect_insecure=False)
-
- def test_authenticate_secure_without_cacert_with_cert_with_token(self):
- self._test_authenticate_user(
- os_token='token',
- insecure=False, cert='cert',
- expect_verify=True, expect_insecure=False)
-
- def test_authenticate_insecure_without_cacert_with_cert(self):
- self._test_authenticate_user(
- insecure=True, cert='cert',
- expect_verify=False, expect_insecure=True)
-
- def test_authenticate_insecure_without_cacert_with_cert_with_token(self):
- self._test_authenticate_user(
- os_token='token',
- insecure=True, cert='cert',
- expect_verify=False, expect_insecure=True)
-
- def test_authenticate_secure_with_cacert_without_cert(self):
- self._test_authenticate_user(
- insecure=False, cacert='cacert',
- expect_verify='cacert', expect_insecure=False)
-
- def test_authenticate_secure_with_cacert_without_cert_with_token(self):
- self._test_authenticate_user(
- os_token='token',
- insecure=False, cacert='cacert',
- expect_verify='cacert', expect_insecure=False)
-
- def test_authenticate_insecure_with_cacert_without_cert(self):
- self._test_authenticate_user(
- insecure=True, cacert='cacert',
- expect_verify=False, expect_insecure=True)
-
- def test_authenticate_insecure_with_cacert_without_cert_with_token(self):
- self._test_authenticate_user(
- os_token='token',
- insecure=True, cacert='cacert',
- expect_verify=False, expect_insecure=True)
-
- def test_commands_dict_populated(self):
- # neutron.shell.COMMANDS is populated once NeutronShell is initialized.
- # To check COMMANDS during NeutronShell initialization,
- # reset COMMANDS to some dummy value before calling NeutronShell().
- self.useFixture(fixtures.MockPatchObject(openstack_shell,
- 'COMMANDS', None))
- openstack_shell.NeutronShell('2.0')
- self.assertLessEqual(
- {'net-create': network.CreateNetwork,
- 'net-delete': network.DeleteNetwork,
- 'net-list': network.ListNetwork,
- 'net-show': network.ShowNetwork,
- 'net-update': network.UpdateNetwork}.items(),
- openstack_shell.COMMANDS['2.0'].items())
diff --git a/neutronclient/tests/unit/vpn/__init__.py b/neutronclient/tests/unit/vpn/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/neutronclient/tests/unit/vpn/__init__.py
+++ /dev/null
diff --git a/neutronclient/tests/unit/vpn/test_cli20_endpoint_group.py b/neutronclient/tests/unit/vpn/test_cli20_endpoint_group.py
deleted file mode 100644
index f43da90..0000000
--- a/neutronclient/tests/unit/vpn/test_cli20_endpoint_group.py
+++ /dev/null
@@ -1,145 +0,0 @@
-# (c) Copyright 2015 Cisco Systems, 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.
-#
-
-import sys
-
-from neutronclient.neutron.v2_0.vpn import endpoint_group
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20VpnEndpointGroupJSON(test_cli20.CLITestV20Base):
-
- def setUp(self):
- super(CLITestV20VpnEndpointGroupJSON, self).setUp()
- self.register_non_admin_status_resource('endpoint_group')
-
- def test_create_endpoint_group_with_cidrs(self):
- # vpn-endpoint-group-create with CIDR endpoints."""
- resource = 'endpoint_group'
- cmd = endpoint_group.CreateEndpointGroup(test_cli20.MyApp(sys.stdout),
- None)
- tenant_id = 'mytenant-id'
- my_id = 'my-id'
- name = 'my-endpoint-group'
- description = 'my endpoint group'
- endpoint_type = 'cidr'
- endpoints = ['10.0.0.0/24', '20.0.0.0/24']
-
- args = ['--name', name,
- '--description', description,
- '--tenant-id', tenant_id,
- '--type', endpoint_type,
- '--value', '10.0.0.0/24',
- '--value', '20.0.0.0/24']
-
- position_names = ['name', 'description', 'tenant_id',
- 'type', 'endpoints']
-
- position_values = [name, description, tenant_id,
- endpoint_type, endpoints]
-
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_endpoint_group_with_subnets(self):
- # vpn-endpoint-group-create with subnet endpoints."""
- resource = 'endpoint_group'
- cmd = endpoint_group.CreateEndpointGroup(test_cli20.MyApp(sys.stdout),
- None)
- tenant_id = 'mytenant-id'
- my_id = 'my-id'
- endpoint_type = 'subnet'
- subnet = 'subnet-id'
- endpoints = [subnet]
-
- args = ['--type', endpoint_type,
- '--value', subnet,
- '--tenant-id', tenant_id]
-
- position_names = ['type', 'endpoints', 'tenant_id']
-
- position_values = [endpoint_type, endpoints, tenant_id]
-
- self._test_create_resource(resource, cmd, None, my_id, args,
- position_names, position_values)
-
- def test_list_endpoint_group(self):
- # vpn-endpoint-group-list.
- resources = "endpoint_groups"
- cmd = endpoint_group.ListEndpointGroup(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_endpoint_group_pagination(self):
- # vpn-endpoint-group-list.
- resources = "endpoint_groups"
- cmd = endpoint_group.ListEndpointGroup(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_endpoint_group_sort(self):
- # vpn-endpoint-group-list --sort-key name --sort-key id
- # --sort-key asc --sort-key desc
- resources = "endpoint_groups"
- cmd = endpoint_group.ListEndpointGroup(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_endpoint_group_limit(self):
- # vpn-endpoint-group-list -P.
- resources = "endpoint_groups"
- cmd = endpoint_group.ListEndpointGroup(test_cli20.MyApp(sys.stdout),
- None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_endpoint_group_id(self):
- # vpn-endpoint-group-show test_id.
- resource = 'endpoint_group'
- cmd = endpoint_group.ShowEndpointGroup(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_endpoint_group_id_name(self):
- # vpn-endpoint-group-show.
- resource = 'endpoint_group'
- cmd = endpoint_group.ShowEndpointGroup(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_endpoint_group(self):
- # vpn-endpoint-group-update myid --name newname --description newdesc.
- resource = 'endpoint_group'
- cmd = endpoint_group.UpdateEndpointGroup(test_cli20.MyApp(sys.stdout),
- None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname',
- '--description', 'newdesc'],
- {'name': 'newname',
- 'description': 'newdesc'})
-
- def test_delete_endpoint_group(self):
- # vpn-endpoint-group-delete my-id.
- resource = 'endpoint_group'
- cmd = endpoint_group.DeleteEndpointGroup(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/neutronclient/tests/unit/vpn/test_cli20_ikepolicy.py b/neutronclient/tests/unit/vpn/test_cli20_ikepolicy.py
deleted file mode 100644
index 33e326c..0000000
--- a/neutronclient/tests/unit/vpn/test_cli20_ikepolicy.py
+++ /dev/null
@@ -1,241 +0,0 @@
-# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
-# 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 neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.vpn import ikepolicy
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20VpnIkePolicyJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['ikepolicy']
-
- def _test_create_ikepolicy_all_params(self, auth='sha1',
- expected_exc=None):
- # vpn-ikepolicy-create all params.
- resource = 'ikepolicy'
- cmd = ikepolicy.CreateIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'ikepolicy1'
- description = 'my-ike-policy'
- auth_algorithm = auth
- encryption_algorithm = 'aes-256'
- ike_version = 'v1'
- phase1_negotiation_mode = 'main'
- pfs = 'group5'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
- lifetime = 'units=seconds,value=20000'
-
- args = [name,
- '--description', description,
- '--tenant-id', tenant_id,
- '--auth-algorithm', auth_algorithm,
- '--encryption-algorithm', encryption_algorithm,
- '--ike-version', ike_version,
- '--phase1-negotiation-mode', phase1_negotiation_mode,
- '--lifetime', lifetime,
- '--pfs', pfs]
-
- position_names = ['name', 'description',
- 'auth_algorithm', 'encryption_algorithm',
- 'phase1_negotiation_mode',
- 'ike_version', 'pfs',
- 'tenant_id']
-
- position_values = [name, description,
- auth_algorithm, encryption_algorithm,
- phase1_negotiation_mode, ike_version, pfs,
- tenant_id]
- extra_body = {
- 'lifetime': {
- 'units': 'seconds',
- 'value': 20000,
- },
- }
-
- if not expected_exc:
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- extra_body=extra_body)
- else:
- self.assertRaises(
- expected_exc,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values,
- extra_body=extra_body)
-
- def test_create_ikepolicy_all_params(self):
- self._test_create_ikepolicy_all_params()
-
- def test_create_ikepolicy_auth_sha256(self):
- self._test_create_ikepolicy_all_params(auth='sha256')
-
- def test_create_ikepolicy_auth_sha384(self):
- self._test_create_ikepolicy_all_params(auth='sha384')
-
- def test_create_ikepolicy_auth_sha512(self):
- self._test_create_ikepolicy_all_params(auth='sha512')
-
- def test_create_ikepolicy_invalid_auth(self):
- self._test_create_ikepolicy_all_params(auth='invalid',
- expected_exc=SystemExit)
-
- def test_create_ikepolicy_with_limited_params(self):
- # vpn-ikepolicy-create with limited params.
- resource = 'ikepolicy'
- cmd = ikepolicy.CreateIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'ikepolicy1'
- auth_algorithm = 'sha1'
- encryption_algorithm = 'aes-128'
- ike_version = 'v1'
- phase1_negotiation_mode = 'main'
- pfs = 'group5'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
-
- args = [name,
- '--tenant-id', tenant_id]
-
- position_names = ['name',
- 'auth_algorithm', 'encryption_algorithm',
- 'phase1_negotiation_mode',
- 'ike_version', 'pfs',
- 'tenant_id']
-
- position_values = [name,
- auth_algorithm, encryption_algorithm,
- phase1_negotiation_mode,
- ike_version, pfs,
- tenant_id]
-
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def _test_lifetime_values(self, lifetime, expected_exc=None):
- resource = 'ikepolicy'
- cmd = ikepolicy.CreateIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'ikepolicy1'
- description = 'my-ike-policy'
- auth_algorithm = 'sha1'
- encryption_algorithm = 'aes-256'
- ike_version = 'v1'
- phase1_negotiation_mode = 'main'
- pfs = 'group5'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
-
- args = [name,
- '--description', description,
- '--tenant-id', tenant_id,
- '--auth-algorithm', auth_algorithm,
- '--encryption-algorithm', encryption_algorithm,
- '--ike-version', ike_version,
- '--phase1-negotiation-mode', phase1_negotiation_mode,
- '--lifetime', lifetime,
- '--pfs', pfs]
-
- position_names = ['name', 'description',
- 'auth_algorithm', 'encryption_algorithm',
- 'phase1_negotiation_mode',
- 'ike_version', 'pfs',
- 'tenant_id']
-
- position_values = [name, description,
- auth_algorithm, encryption_algorithm,
- phase1_negotiation_mode, ike_version, pfs,
- tenant_id]
- if not expected_exc:
- expected_exc = exceptions.CommandError
- self.assertRaises(
- expected_exc,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_ikepolicy_with_invalid_lifetime_keys(self):
- lifetime = 'uts=seconds,val=20000'
- self._test_lifetime_values(lifetime, expected_exc=SystemExit)
-
- def test_create_ikepolicy_with_invalid_lifetime_value(self):
- lifetime = 'units=seconds,value=-1'
- self._test_lifetime_values(lifetime)
-
- def test_list_ikepolicy(self):
- # vpn-ikepolicy-list.
- resources = "ikepolicies"
- cmd = ikepolicy.ListIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_ikepolicy_pagination(self):
- # vpn-ikepolicy-list.
- resources = "ikepolicies"
- cmd = ikepolicy.ListIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_ikepolicy_sort(self):
- # vpn-ikepolicy-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "ikepolicies"
- cmd = ikepolicy.ListIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_ikepolicy_limit(self):
- # vpn-ikepolicy-list -P.
- resources = "ikepolicies"
- cmd = ikepolicy.ListIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_ikepolicy_id(self):
- # vpn-ikepolicy-show ikepolicy_id.
- resource = 'ikepolicy'
- cmd = ikepolicy.ShowIKEPolicy(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_ikepolicy_id_name(self):
- # vpn-ikepolicy-show.
- resource = 'ikepolicy'
- cmd = ikepolicy.ShowIKEPolicy(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_ikepolicy(self):
- # vpn-ikepolicy-update myid --name newname --tags a b.
- resource = 'ikepolicy'
- cmd = ikepolicy.UpdateIKEPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname'],
- {'name': 'newname', })
- # vpn-ikepolicy-update myid --pfs group2 --ike-version v2.
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--pfs', 'group2',
- '--ike-version', 'v2'],
- {'pfs': 'group2',
- 'ike_version': 'v2'})
-
- def test_delete_ikepolicy(self):
- # vpn-ikepolicy-delete my-id.
- resource = 'ikepolicy'
- cmd = ikepolicy.DeleteIKEPolicy(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/neutronclient/tests/unit/vpn/test_cli20_ipsec_site_connection.py b/neutronclient/tests/unit/vpn/test_cli20_ipsec_site_connection.py
deleted file mode 100644
index cbab15c..0000000
--- a/neutronclient/tests/unit/vpn/test_cli20_ipsec_site_connection.py
+++ /dev/null
@@ -1,342 +0,0 @@
-# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
-# 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 neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.vpn import ipsec_site_connection
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20IPsecSiteConnectionJSON(test_cli20.CLITestV20Base):
-
- # TODO(pcm): Remove, once peer-cidr is deprecated completely
- def test_create_ipsec_site_connection_all_params_using_peer_cidrs(self):
- # ipsecsite-connection-create all params using peer CIDRs.
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.CreateIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- tenant_id = 'mytenant_id'
- name = 'connection1'
- my_id = 'my_id'
- peer_address = '192.168.2.10'
- peer_id = '192.168.2.10'
- psk = 'abcd'
- mtu = '1500'
- initiator = 'bi-directional'
- vpnservice_id = 'vpnservice_id'
- ikepolicy_id = 'ikepolicy_id'
- ipsecpolicy_id = 'ipsecpolicy_id'
- peer_cidrs = ['192.168.3.0/24', '192.168.2.0/24']
- admin_state = True
- description = 'my-vpn-connection'
- dpd = 'action=restart,interval=30,timeout=120'
-
- args = ['--tenant-id', tenant_id,
- '--peer-address', peer_address, '--peer-id', peer_id,
- '--psk', psk, '--initiator', initiator,
- '--vpnservice-id', vpnservice_id,
- '--ikepolicy-id', ikepolicy_id, '--name', name,
- '--ipsecpolicy-id', ipsecpolicy_id, '--mtu', mtu,
- '--description', description,
- '--peer-cidr', '192.168.3.0/24',
- '--peer-cidr', '192.168.2.0/24',
- '--dpd', dpd]
-
- position_names = ['name', 'tenant_id', 'admin_state_up',
- 'peer_address', 'peer_id', 'peer_cidrs',
- 'psk', 'mtu', 'initiator', 'description',
- 'vpnservice_id', 'ikepolicy_id',
- 'ipsecpolicy_id']
-
- position_values = [name, tenant_id, admin_state, peer_address,
- peer_id, peer_cidrs, psk, mtu,
- initiator, description,
- vpnservice_id, ikepolicy_id, ipsecpolicy_id]
- extra_body = {
- 'dpd': {
- 'action': 'restart',
- 'interval': 30,
- 'timeout': 120,
- },
- }
-
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- extra_body=extra_body)
-
- def test_create_ipsec_site_conn_all_params(self):
- # ipsecsite-connection-create all params using endpoint groups.
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.CreateIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- tenant_id = 'mytenant_id'
- name = 'connection1'
- my_id = 'my_id'
- peer_address = '192.168.2.10'
- peer_id = '192.168.2.10'
- psk = 'abcd'
- mtu = '1500'
- initiator = 'bi-directional'
- vpnservice_id = 'vpnservice_id'
- ikepolicy_id = 'ikepolicy_id'
- ipsecpolicy_id = 'ipsecpolicy_id'
- local_ep_group = 'local-epg'
- peer_ep_group = 'peer-epg'
- admin_state = True
- description = 'my-vpn-connection'
- dpd = 'action=restart,interval=30,timeout=120'
-
- args = ['--tenant-id', tenant_id,
- '--peer-address', peer_address, '--peer-id', peer_id,
- '--psk', psk, '--initiator', initiator,
- '--vpnservice-id', vpnservice_id,
- '--ikepolicy-id', ikepolicy_id, '--name', name,
- '--ipsecpolicy-id', ipsecpolicy_id, '--mtu', mtu,
- '--description', description,
- '--local-ep-group', local_ep_group,
- '--peer-ep-group', peer_ep_group,
- '--dpd', dpd]
-
- position_names = ['name', 'tenant_id', 'admin_state_up',
- 'peer_address', 'peer_id', 'psk', 'mtu',
- 'local_ep_group_id', 'peer_ep_group_id',
- 'initiator', 'description',
- 'vpnservice_id', 'ikepolicy_id',
- 'ipsecpolicy_id']
-
- position_values = [name, tenant_id, admin_state, peer_address,
- peer_id, psk, mtu, local_ep_group,
- peer_ep_group, initiator, description,
- vpnservice_id, ikepolicy_id, ipsecpolicy_id]
- extra_body = {
- 'dpd': {
- 'action': 'restart',
- 'interval': 30,
- 'timeout': 120,
- },
- }
-
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- extra_body=extra_body)
-
- def test_create_ipsec_site_connection_with_limited_params(self):
- # ipsecsite-connection-create with limited params.
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.CreateIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- tenant_id = 'mytenant_id'
- my_id = 'my_id'
- peer_address = '192.168.2.10'
- peer_id = '192.168.2.10'
- psk = 'abcd'
- mtu = '1500'
- initiator = 'bi-directional'
- vpnservice_id = 'vpnservice_id'
- ikepolicy_id = 'ikepolicy_id'
- ipsecpolicy_id = 'ipsecpolicy_id'
- local_ep_group = 'local-epg'
- peer_ep_group = 'peer-epg'
- admin_state = True
-
- args = ['--tenant-id', tenant_id,
- '--peer-address', peer_address,
- '--peer-id', peer_id,
- '--psk', psk,
- '--vpnservice-id', vpnservice_id,
- '--ikepolicy-id', ikepolicy_id,
- '--ipsecpolicy-id', ipsecpolicy_id,
- '--local-ep-group', local_ep_group,
- '--peer-ep-group', peer_ep_group]
-
- position_names = ['tenant_id', 'admin_state_up',
- 'peer_address', 'peer_id',
- 'local_ep_group_id', 'peer_ep_group_id',
- 'psk', 'mtu', 'initiator',
- 'vpnservice_id', 'ikepolicy_id',
- 'ipsecpolicy_id']
-
- position_values = [tenant_id, admin_state, peer_address, peer_id,
- local_ep_group, peer_ep_group, psk, mtu, initiator,
- vpnservice_id, ikepolicy_id, ipsecpolicy_id]
-
- self._test_create_resource(resource, cmd, None, my_id, args,
- position_names, position_values)
-
- def _test_create_failure(self, additional_args=None, expected_exc=None):
- # Helper to test failure of IPSec site-to-site creation failure.
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.CreateIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- tenant_id = 'mytenant_id'
- my_id = 'my_id'
- peer_address = '192.168.2.10'
- peer_id = '192.168.2.10'
- psk = 'abcd'
- mtu = '1500'
- initiator = 'bi-directional'
- vpnservice_id = 'vpnservice_id'
- ikepolicy_id = 'ikepolicy_id'
- ipsecpolicy_id = 'ipsecpolicy_id'
- admin_state = True
-
- args = ['--tenant-id', tenant_id,
- '--peer-address', peer_address,
- '--peer-id', peer_id,
- '--psk', psk,
- '--vpnservice-id', vpnservice_id,
- '--ikepolicy-id', ikepolicy_id,
- '--ipsecpolicy-id', ipsecpolicy_id]
- if additional_args is not None:
- args += additional_args
- position_names = ['tenant_id', 'admin_state_up', 'peer_address',
- 'peer_id', 'psk', 'mtu', 'initiator',
- 'local_ep_group_id', 'peer_ep_group_id',
- 'vpnservice_id', 'ikepolicy_id', 'ipsecpolicy_id']
-
- position_values = [tenant_id, admin_state, peer_address, peer_id, psk,
- mtu, initiator, None, None, vpnservice_id,
- ikepolicy_id, ipsecpolicy_id]
- if not expected_exc:
- expected_exc = exceptions.CommandError
- self.assertRaises(expected_exc,
- self._test_create_resource,
- resource, cmd, None, my_id, args,
- position_names, position_values)
-
- def test_fail_create_with_invalid_mtu(self):
- # ipsecsite-connection-create with invalid dpd values.
- bad_mtu = ['--mtu', '67']
- self._test_create_failure(bad_mtu)
-
- def test_fail_create_with_invalid_dpd_keys(self):
- bad_dpd_key = ['--dpd', 'act=restart,interval=30,time=120']
- self._test_create_failure(bad_dpd_key, SystemExit)
-
- def test_fail_create_with_invalid_dpd_values(self):
- bad_dpd_values = ['--dpd', 'action=hold,interval=30,timeout=-1']
- self._test_create_failure(bad_dpd_values)
-
- def test_fail_create_missing_endpoint_groups_or_cidr(self):
- # Must provide either endpoint groups or peer cidrs.
- self._test_create_failure()
-
- def test_fail_create_missing_peer_endpoint_group(self):
- # Fails if dont have both endpoint groups - missing peer.
- self._test_create_failure(['--local-ep-group', 'local-epg'])
-
- def test_fail_create_missing_local_endpoint_group(self):
- # Fails if dont have both endpoint groups - missing local.
- self._test_create_failure(['--peer-ep-group', 'peer-epg'])
-
- def test_fail_create_when_both_endpoints_and_peer_cidr(self):
- # Cannot intermix endpoint groups and peer CIDRs for create.
- additional_args = ['--local-ep-group', 'local-epg',
- '--peer-ep-group', 'peer-epg',
- '--peer-cidr', '10.2.0.0/24']
- self._test_create_failure(additional_args)
-
- def test_list_ipsec_site_connection(self):
- # ipsecsite-connection-list.
- resources = "ipsec_site_connections"
- cmd = ipsec_site_connection.ListIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- self._test_list_resources(resources, cmd, True)
-
- def test_list_ipsec_site_connection_pagination(self):
- # ipsecsite-connection-list.
- resources = "ipsec_site_connections"
- cmd = ipsec_site_connection.ListIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_ipsec_site_connection_sort(self):
- # ipsecsite-connection-list.
- # --sort-key name --sort-key id --sort-key asc --sort-key desc
- resources = "ipsec_site_connections"
- cmd = ipsec_site_connection.ListIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_ipsec_site_connection_limit(self):
- # ipsecsite-connection-list -P.
- resources = "ipsec_site_connections"
- cmd = ipsec_site_connection.ListIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_delete_ipsec_site_connection(self):
- # ipsecsite-connection-delete my-id.
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.DeleteIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- my_id = 'my-id'
- args = [my_id]
- self._test_delete_resource(resource, cmd, my_id, args)
-
- def test_update_ipsec_site_connection(self):
- # ipsecsite-connection-update myid --name Branch-new --tags a b.
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.UpdateIPsecSiteConnection(
- test_cli20.MyApp(sys.stdout), None
- )
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'Branch-new',
- '--tags', 'a', 'b'],
- {'name': 'Branch-new',
- 'tags': ['a', 'b'], })
- # ipsecsite-connection-update myid --mtu 69 --initiator response-only
- # --peer-id '192.168.2.11' --peer-ep-group 'update-grp'
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--mtu', '69',
- '--initiator', 'response-only',
- '--peer-id', '192.168.2.11',
- '--peer-ep-group', 'update-grp'],
- {'mtu': '69',
- 'initiator': 'response-only',
- 'peer_id': '192.168.2.11',
- 'peer_ep_group_id': 'update-grp', },)
-
- def test_show_ipsec_site_connection_id(self):
- # ipsecsite-connection-show test_id."""
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.ShowIPsecSiteConnection(
- 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_ipsec_site_connection_id_name(self):
- # ipsecsite-connection-show."""
- resource = 'ipsec_site_connection'
- cmd = ipsec_site_connection.ShowIPsecSiteConnection(
- 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'])
diff --git a/neutronclient/tests/unit/vpn/test_cli20_ipsecpolicy.py b/neutronclient/tests/unit/vpn/test_cli20_ipsecpolicy.py
deleted file mode 100644
index 8c7df4a..0000000
--- a/neutronclient/tests/unit/vpn/test_cli20_ipsecpolicy.py
+++ /dev/null
@@ -1,249 +0,0 @@
-# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
-# 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 neutronclient.common import exceptions
-from neutronclient.neutron.v2_0.vpn import ipsecpolicy
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20VpnIpsecPolicyJSON(test_cli20.CLITestV20Base):
-
- non_admin_status_resources = ['ipsecpolicy']
-
- def _test_create_ipsecpolicy_all_params(self, auth='sha1',
- expected_exc=None):
- # vpn-ipsecpolicy-create all params with dashes.
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.CreateIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'ipsecpolicy1'
- description = 'first-ipsecpolicy1'
- auth_algorithm = auth
- encryption_algorithm = 'aes-256'
- encapsulation_mode = 'tunnel'
- pfs = 'group5'
- transform_protocol = 'ah'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
- lifetime = 'units=seconds,value=20000'
-
- args = [name,
- '--description', description,
- '--tenant-id', tenant_id,
- '--auth-algorithm', auth_algorithm,
- '--encryption-algorithm', encryption_algorithm,
- '--transform-protocol', transform_protocol,
- '--encapsulation-mode', encapsulation_mode,
- '--lifetime', lifetime,
- '--pfs', pfs]
-
- position_names = ['name', 'auth_algorithm', 'encryption_algorithm',
- 'encapsulation_mode', 'description',
- 'transform_protocol', 'pfs',
- 'tenant_id']
-
- position_values = [name, auth_algorithm, encryption_algorithm,
- encapsulation_mode, description,
- transform_protocol, pfs,
- tenant_id]
- extra_body = {
- 'lifetime': {
- 'units': 'seconds',
- 'value': 20000,
- },
- }
-
- if not expected_exc:
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values,
- extra_body=extra_body)
- else:
- self.assertRaises(
- expected_exc,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values,
- extra_body=extra_body)
-
- def test_create_ipsecpolicy_all_params(self):
- self._test_create_ipsecpolicy_all_params()
-
- def test_create_ipsecpolicy_auth_sha256(self):
- self._test_create_ipsecpolicy_all_params(auth='sha256')
-
- def test_create_ipsecpolicy_auth_sha384(self):
- self._test_create_ipsecpolicy_all_params(auth='sha384')
-
- def test_create_ipsecpolicy_auth_sha512(self):
- self._test_create_ipsecpolicy_all_params(auth='sha512')
-
- def test_create_ipsecpolicy_invalid_auth(self):
- self._test_create_ipsecpolicy_all_params(auth='invalid',
- expected_exc=SystemExit)
-
- def test_create_ipsecpolicy_with_limited_params(self):
- # vpn-ipsecpolicy-create with limited params.
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.CreateIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'ipsecpolicy1'
- auth_algorithm = 'sha1'
- encryption_algorithm = 'aes-128'
- encapsulation_mode = 'tunnel'
- pfs = 'group5'
- transform_protocol = 'esp'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
-
- args = [name,
- '--tenant-id', tenant_id]
-
- position_names = ['name', 'auth_algorithm', 'encryption_algorithm',
- 'encapsulation_mode',
- 'transform_protocol', 'pfs',
- 'tenant_id']
-
- position_values = [name, auth_algorithm, encryption_algorithm,
- encapsulation_mode,
- transform_protocol, pfs,
- tenant_id]
-
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def _test_lifetime_values(self, lifetime, expected_exc=None):
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.CreateIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- name = 'ipsecpolicy1'
- description = 'my-ipsec-policy'
- auth_algorithm = 'sha1'
- encryption_algorithm = 'aes-256'
- ike_version = 'v1'
- phase1_negotiation_mode = 'main'
- pfs = 'group5'
- tenant_id = 'my-tenant'
- my_id = 'my-id'
-
- args = [name,
- '--description', description,
- '--tenant-id', tenant_id,
- '--auth-algorithm', auth_algorithm,
- '--encryption-algorithm', encryption_algorithm,
- '--ike-version', ike_version,
- '--phase1-negotiation-mode', phase1_negotiation_mode,
- '--lifetime', lifetime,
- '--pfs', pfs]
-
- position_names = ['name', 'description',
- 'auth_algorithm', 'encryption_algorithm',
- 'phase1_negotiation_mode',
- 'ike_version', 'pfs',
- 'tenant_id']
-
- position_values = [name, description,
- auth_algorithm, encryption_algorithm,
- phase1_negotiation_mode, ike_version, pfs,
- tenant_id]
- if not expected_exc:
- expected_exc = exceptions.CommandError
- self.assertRaises(
- expected_exc,
- self._test_create_resource,
- resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_ipsecpolicy_with_invalid_lifetime_keys(self):
- lifetime = 'uts=seconds,val=20000'
- self._test_lifetime_values(lifetime, SystemExit)
-
- def test_create_ipsecpolicy_with_invalid_lifetime_units(self):
- lifetime = 'units=minutes,value=600'
- self._test_lifetime_values(lifetime)
-
- def test_create_ipsecpolicy_with_invalid_lifetime_value(self):
- lifetime = 'units=seconds,value=0'
- self._test_lifetime_values(lifetime)
-
- def test_list_ipsecpolicy(self):
- # vpn-ipsecpolicy-list.
- resources = "ipsecpolicies"
- cmd = ipsecpolicy.ListIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_ipsecpolicy_pagination(self):
- # vpn-ipsecpolicy-list.
- resources = "ipsecpolicies"
- cmd = ipsecpolicy.ListIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_ipsecpolicy_sort(self):
- # vpn-ipsecpolicy-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "ipsecpolicies"
- cmd = ipsecpolicy.ListIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_ipsecpolicy_limit(self):
- # vpn-ipsecpolicy-list -P.
- resources = "ipsecpolicies"
- cmd = ipsecpolicy.ListIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_ipsecpolicy_id(self):
- # vpn-ipsecpolicy-show ipsecpolicy_id.
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.ShowIPsecPolicy(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_ipsecpolicy_id_name(self):
- # vpn-ipsecpolicy-show.
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.ShowIPsecPolicy(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_ipsecpolicy_name(self):
- # vpn-ipsecpolicy-update myid --name newname --tags a b.
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.UpdateIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname'],
- {'name': 'newname', })
-
- def test_update_ipsecpolicy_other_params(self):
- # vpn-ipsecpolicy-update myid --transform-protocol esp
- # --pfs group14 --encapsulation-mode transport
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.UpdateIPsecPolicy(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--transform-protocol', 'esp',
- '--pfs', 'group14',
- '--encapsulation-mode', 'transport'],
- {'transform_protocol': 'esp',
- 'pfs': 'group14',
- 'encapsulation_mode': 'transport', })
-
- def test_delete_ipsecpolicy(self):
- # vpn-ipsecpolicy-delete my-id.
- resource = 'ipsecpolicy'
- cmd = ipsecpolicy.DeleteIPsecPolicy(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/neutronclient/tests/unit/vpn/test_cli20_vpnservice.py b/neutronclient/tests/unit/vpn/test_cli20_vpnservice.py
deleted file mode 100644
index 3c4def8..0000000
--- a/neutronclient/tests/unit/vpn/test_cli20_vpnservice.py
+++ /dev/null
@@ -1,157 +0,0 @@
-# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
-# 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 neutronclient.neutron.v2_0.vpn import vpnservice
-from neutronclient.tests.unit import test_cli20
-
-
-class CLITestV20VpnServiceJSON(test_cli20.CLITestV20Base):
-
- def test_create_vpnservice_all_params(self):
- # vpn-service-create all params.
- resource = 'vpnservice'
- cmd = vpnservice.CreateVPNService(test_cli20.MyApp(sys.stdout), None)
- subnet = 'mysubnet-id'
- router = 'myrouter-id'
- tenant_id = 'mytenant-id'
- my_id = 'my-id'
- name = 'myvpnservice'
- description = 'my-vpn-service'
- admin_state = True
-
- args = ['--name', name,
- '--description', description,
- router,
- subnet,
- '--tenant-id', tenant_id]
-
- position_names = ['admin_state_up', 'name', 'description',
- 'subnet_id', 'router_id',
- 'tenant_id']
-
- position_values = [admin_state, name, description,
- subnet, router, tenant_id]
-
- self._test_create_resource(resource, cmd, name, my_id, args,
- position_names, position_values)
-
- def test_create_vpnservice_with_limited_params(self):
- # vpn-service-create with limited params.
- resource = 'vpnservice'
- cmd = vpnservice.CreateVPNService(test_cli20.MyApp(sys.stdout), None)
- subnet = 'mysubnet-id'
- router = 'myrouter-id'
- tenant_id = 'mytenant-id'
- my_id = 'my-id'
- admin_state = True
-
- args = [router,
- subnet,
- '--tenant-id', tenant_id]
-
- position_names = ['admin_state_up',
- 'subnet_id', 'router_id',
- 'tenant_id']
-
- position_values = [admin_state, subnet, router, tenant_id]
-
- self._test_create_resource(resource, cmd, None, my_id, args,
- position_names, position_values)
-
- def test_create_vpnservice_without_subnet(self):
- # vpn-service-create with no subnet provided.
- resource = 'vpnservice'
- cmd = vpnservice.CreateVPNService(test_cli20.MyApp(sys.stdout), None)
- router = 'myrouter-id'
- tenant_id = 'mytenant-id'
- my_id = 'my-id'
- admin_state = True
-
- args = [router,
- '--tenant-id', tenant_id]
-
- position_names = ['admin_state_up',
- 'subnet_id', 'router_id',
- 'tenant_id']
-
- position_values = [admin_state, None, router, tenant_id]
-
- self._test_create_resource(resource, cmd, None, my_id, args,
- position_names, position_values)
-
- def test_list_vpnservice(self):
- # vpn-service-list.
- resources = "vpnservices"
- cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, True)
-
- def test_list_vpnservice_pagination(self):
- # vpn-service-list.
- resources = "vpnservices"
- cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources_with_pagination(resources, cmd)
-
- def test_list_vpnservice_sort(self):
- # vpn-service-list --sort-key name --sort-key id --sort-key asc
- # --sort-key desc
- resources = "vpnservices"
- cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd,
- sort_key=["name", "id"],
- sort_dir=["asc", "desc"])
-
- def test_list_vpnservice_limit(self):
- # vpn-service-list -P.
- resources = "vpnservices"
- cmd = vpnservice.ListVPNService(test_cli20.MyApp(sys.stdout), None)
- self._test_list_resources(resources, cmd, page_size=1000)
-
- def test_show_vpnservice_id(self):
- # vpn-service-show test_id.
- resource = 'vpnservice'
- cmd = vpnservice.ShowVPNService(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_vpnservice_id_name(self):
- # vpn-service-show."""
- resource = 'vpnservice'
- cmd = vpnservice.ShowVPNService(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_vpnservice(self):
- # vpn-service-update myid --name newname --tags a b.
- resource = 'vpnservice'
- cmd = vpnservice.UpdateVPNService(test_cli20.MyApp(sys.stdout), None)
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--name', 'newname'],
- {'name': 'newname', })
- # vpn-service-update myid --admin-state-up False
- self._test_update_resource(resource, cmd, 'myid',
- ['myid', '--admin-state-up', 'False'],
- {'admin_state_up': 'False', })
-
- def test_delete_vpnservice(self):
- # vpn-service-delete my-id.
- resource = 'vpnservice'
- cmd = vpnservice.DeleteVPNService(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/neutronclient/tests/unit/vpn/test_utils.py b/neutronclient/tests/unit/vpn/test_utils.py
deleted file mode 100644
index c39f7ce..0000000
--- a/neutronclient/tests/unit/vpn/test_utils.py
+++ /dev/null
@@ -1,130 +0,0 @@
-# (c) Copyright 2013 Hewlett-Packard Development Company, L.P.
-# 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 testtools
-
-from neutronclient.common import exceptions
-from neutronclient.common import utils
-from neutronclient.neutron.v2_0.vpn import utils as vpn_utils
-
-
-class TestVPNUtils(testtools.TestCase):
-
- def test_validate_lifetime_dictionary_seconds(self):
- input_str = utils.str2dict("units=seconds,value=3600")
- self.assertIsNone(vpn_utils.validate_lifetime_dict(input_str))
-
- def test_validate_dpd_dictionary_action_hold(self):
- input_str = utils.str2dict("action=hold,interval=30,timeout=120")
- self.assertIsNone(vpn_utils.validate_dpd_dict(input_str))
-
- def test_validate_dpd_dictionary_action_restart(self):
- input_str = utils.str2dict("action=restart,interval=30,timeout=120")
- self.assertIsNone(vpn_utils.validate_dpd_dict(input_str))
-
- def test_validate_dpd_dictionary_action_restart_by_peer(self):
- input_str = utils.str2dict(
- "action=restart-by-peer,interval=30,timeout=120"
- )
- self.assertIsNone(vpn_utils.validate_dpd_dict(input_str))
-
- def test_validate_dpd_dictionary_action_clear(self):
- input_str = utils.str2dict('action=clear,interval=30,timeout=120')
- self.assertIsNone(vpn_utils.validate_dpd_dict(input_str))
-
- def test_validate_dpd_dictionary_action_disabled(self):
- input_str = utils.str2dict('action=disabled,interval=30,timeout=120')
- self.assertIsNone(vpn_utils.validate_dpd_dict(input_str))
-
- def test_validate_lifetime_dictionary_invalid_unit_key(self):
- input_str = utils.str2dict('ut=seconds,value=3600')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_lifetime_dictionary_invalid_unit_key_value(self):
- input_str = utils.str2dict('units=seconds,val=3600')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_lifetime_dictionary_unsupported_units(self):
- input_str = utils.str2dict('units=minutes,value=3600')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_lifetime_dictionary_invalid_empty_unit(self):
- input_str = utils.str2dict('units=,value=3600')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_lifetime_dictionary_under_minimum_integer_value(self):
- input_str = utils.str2dict('units=seconds,value=59')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_lifetime_dictionary_negative_integer_value(self):
- input_str = utils.str2dict('units=seconds,value=-1')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_lifetime_dictionary_empty_value(self):
- input_str = utils.str2dict('units=seconds,value=')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_invalid_key_action(self):
- input_str = utils.str2dict('act=hold,interval=30,timeout=120')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_invalid_key_interval(self):
- input_str = utils.str2dict('action=hold,int=30,timeout=120')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_invalid_key_timeout(self):
- input_str = utils.str2dict('action=hold,interval=30,tiut=120')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_unsupported_action(self):
- input_str = utils.str2dict('action=bye-bye,interval=30,timeout=120')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_empty_action(self):
- input_str = utils.str2dict('action=,interval=30,timeout=120')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_empty_interval(self):
- input_str = utils.str2dict('action=hold,interval=,timeout=120')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_negative_interval_value(self):
- input_str = utils.str2dict('action=hold,interval=-1,timeout=120')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_zero_timeout(self):
- input_str = utils.str2dict('action=hold,interval=30,timeout=0')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_empty_timeout(self):
- input_str = utils.str2dict('action=hold,interval=30,timeout=')
- self._test_validate_dpd_negative_test_case(input_str)
-
- def test_validate_dpd_dictionary_negative_timeout_value(self):
- input_str = utils.str2dict('action=hold,interval=30,timeout=-1')
- self._test_validate_lifetime_negative_test_case(input_str)
-
- def _test_validate_lifetime_negative_test_case(self, input_str):
- """Generic handler for negative lifetime tests."""
- 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(exceptions.CommandError,
- vpn_utils.validate_lifetime_dict,
- (input_str))