summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorBrad Behle <behle@us.ibm.com>2016-02-04 17:19:37 -0600
committerBrad Behle <behle@us.ibm.com>2016-02-22 13:04:25 -0600
commit112d7b0e0966599aa940de4c0598cea759780785 (patch)
treefab9ae2e815c303d41451fb3f258925bb309e1b0 /openstackclient/tests
parentba08683d90277e3cc6f943a2a994ccf08589cb1a (diff)
downloadpython-openstackclient-112d7b0e0966599aa940de4c0598cea759780785.tar.gz
Add "os subnet show" command using SDK
Implement the openstack client subnet show command using SDK calls. This shows the details of a specific subnet. Co-Authored-By: Terry Howe <terrylhowe@gmail.com> Partially implements: blueprint neutron-client Closes-Bug: #1542359 Change-Id: Iaf18b9e44af35ca0cd61033b468e0c60cd3b05d6
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/network/v2/fakes.py11
-rw-r--r--openstackclient/tests/network/v2/test_subnet.py74
2 files changed, 83 insertions, 2 deletions
diff --git a/openstackclient/tests/network/v2/fakes.py b/openstackclient/tests/network/v2/fakes.py
index 680e9cbf..c24410e1 100644
--- a/openstackclient/tests/network/v2/fakes.py
+++ b/openstackclient/tests/network/v2/fakes.py
@@ -550,18 +550,22 @@ class FakeSubnet(object):
A FakeResource object faking the subnet
"""
# Set default attributes.
+ project_id = 'project-id-' + uuid.uuid4().hex
subnet_attrs = {
'id': 'subnet-id-' + uuid.uuid4().hex,
'name': 'subnet-name-' + uuid.uuid4().hex,
'network_id': 'network-id-' + uuid.uuid4().hex,
'cidr': '10.10.10.0/24',
- 'tenant_id': 'project-id-' + uuid.uuid4().hex,
+ 'tenant_id': project_id,
'enable_dhcp': True,
'dns_nameservers': [],
'allocation_pools': [],
'host_routes': [],
'ip_version': '4',
'gateway_ip': '10.10.10.1',
+ 'ipv6_address_mode': 'None',
+ 'ipv6_ra_mode': 'None',
+ 'subnetpool_id': 'None',
}
# Overwrite default attributes.
@@ -571,7 +575,8 @@ class FakeSubnet(object):
subnet_methods = {
'keys': ['id', 'name', 'network_id', 'cidr', 'enable_dhcp',
'allocation_pools', 'dns_nameservers', 'gateway_ip',
- 'host_routes', 'ip_version', 'tenant_id']
+ 'host_routes', 'ip_version', 'tenant_id',
+ 'ipv6_address_mode', 'ipv6_ra_mode', 'subnetpool_id']
}
# Overwrite default methods.
@@ -580,6 +585,8 @@ class FakeSubnet(object):
subnet = fakes.FakeResource(info=copy.deepcopy(subnet_attrs),
methods=copy.deepcopy(subnet_methods),
loaded=True)
+ # Set attributes with special mappings in OpenStack SDK.
+ subnet.project_id = subnet_attrs['tenant_id']
return subnet
diff --git a/openstackclient/tests/network/v2/test_subnet.py b/openstackclient/tests/network/v2/test_subnet.py
index 5fca5edd..c02dc407 100644
--- a/openstackclient/tests/network/v2/test_subnet.py
+++ b/openstackclient/tests/network/v2/test_subnet.py
@@ -16,6 +16,7 @@ import mock
from openstackclient.common import utils
from openstackclient.network.v2 import subnet as subnet_v2
from openstackclient.tests.network.v2 import fakes as network_fakes
+from openstackclient.tests import utils as tests_utils
class TestSubnet(network_fakes.TestNetworkV2):
@@ -106,3 +107,76 @@ class TestListSubnet(TestSubnet):
self.network.subnets.assert_called_with()
self.assertEqual(self.columns_long, columns)
self.assertEqual(self.data_long, list(data))
+
+
+class TestShowSubnet(TestSubnet):
+ # The subnets to be shown
+ _subnet = network_fakes.FakeSubnet.create_one_subnet()
+
+ columns = (
+ 'allocation_pools',
+ 'cidr',
+ 'dns_nameservers',
+ 'enable_dhcp',
+ 'gateway_ip',
+ 'host_routes',
+ 'id',
+ 'ip_version',
+ 'ipv6_address_mode',
+ 'ipv6_ra_mode',
+ 'name',
+ 'network_id',
+ 'project_id',
+ 'subnetpool_id',
+ )
+
+ data = (
+ subnet_v2._format_allocation_pools(_subnet.allocation_pools),
+ _subnet.cidr,
+ utils.format_list(_subnet.dns_nameservers),
+ _subnet.enable_dhcp,
+ _subnet.gateway_ip,
+ utils.format_list(_subnet.host_routes),
+ _subnet.id,
+ _subnet.ip_version,
+ _subnet.ipv6_address_mode,
+ _subnet.ipv6_ra_mode,
+ _subnet.name,
+ _subnet.network_id,
+ _subnet.tenant_id,
+ _subnet.subnetpool_id,
+ )
+
+ def setUp(self):
+ super(TestShowSubnet, self).setUp()
+
+ # Get the command object to test
+ self.cmd = subnet_v2.ShowSubnet(self.app, self.namespace)
+
+ self.network.find_subnet = mock.Mock(return_value=self._subnet)
+
+ def test_show_no_options(self):
+ arglist = []
+ verifylist = []
+
+ # Testing that a call without the required argument will fail and
+ # throw a "ParserExecption"
+ self.assertRaises(tests_utils.ParserException,
+ self.check_parser, self.cmd, arglist, verifylist)
+
+ def test_show_all_options(self):
+ arglist = [
+ self._subnet.name,
+ ]
+ verifylist = [
+ ('subnet', self._subnet.name),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.find_subnet.assert_called_with(self._subnet.name,
+ ignore_missing=False)
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(list(self.data), list(data))