summaryrefslogtreecommitdiff
path: root/openstackclient/tests/unit
diff options
context:
space:
mode:
authorCao Xuan Hoang <hoangcx@vn.fujitsu.com>2016-08-18 16:50:52 +0700
committerCao Xuan Hoang <hoangcx@vn.fujitsu.com>2016-09-20 10:12:42 +0700
commit4265002e599af332f2e6288814dcaefa0dcb1be0 (patch)
treeef94ff6bd258aaf9585f6a3178e908b01e90e840 /openstackclient/tests/unit
parent7e990ba1e2ae0ecb804287212797ebad84d7b56b (diff)
downloadpython-openstackclient-4265002e599af332f2e6288814dcaefa0dcb1be0.tar.gz
Add 'description' option to os subnet (pool) create/set cmd
This patch adds '--description' option to the commands. Change-Id: Ifc2828670c3c48a87a0493d98686a5babf9b2ae7 Closes-Bug: #1614458 Closes-Bug: #1614823 Partially-Implements: blueprint network-commands-options
Diffstat (limited to 'openstackclient/tests/unit')
-rw-r--r--openstackclient/tests/unit/network/v2/fakes.py2
-rw-r--r--openstackclient/tests/unit/network/v2/test_subnet.py64
-rw-r--r--openstackclient/tests/unit/network/v2/test_subnet_pool.py47
3 files changed, 113 insertions, 0 deletions
diff --git a/openstackclient/tests/unit/network/v2/fakes.py b/openstackclient/tests/unit/network/v2/fakes.py
index e3adb435..7559811c 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -891,6 +891,7 @@ class FakeSubnet(object):
'segment_id': None,
'service_types': [],
'subnetpool_id': None,
+ 'description': 'subnet-description-' + uuid.uuid4().hex,
}
# Overwrite default attributes.
@@ -1046,6 +1047,7 @@ class FakeSubnetPool(object):
'min_prefixlen': '8',
'default_quota': None,
'ip_version': '4',
+ 'description': 'subnet-pool-description-' + uuid.uuid4().hex,
}
# Overwrite default attributes.
diff --git a/openstackclient/tests/unit/network/v2/test_subnet.py b/openstackclient/tests/unit/network/v2/test_subnet.py
index 6d762344..38613c00 100644
--- a/openstackclient/tests/unit/network/v2/test_subnet.py
+++ b/openstackclient/tests/unit/network/v2/test_subnet.py
@@ -110,6 +110,7 @@ class TestCreateSubnet(TestSubnet):
columns = (
'allocation_pools',
'cidr',
+ 'description',
'dns_nameservers',
'enable_dhcp',
'gateway_ip',
@@ -129,6 +130,7 @@ class TestCreateSubnet(TestSubnet):
data = (
subnet_v2._format_allocation_pools(_subnet.allocation_pools),
_subnet.cidr,
+ _subnet.description,
utils.format_list(_subnet.dns_nameservers),
_subnet.enable_dhcp,
_subnet.gateway_ip,
@@ -148,6 +150,7 @@ class TestCreateSubnet(TestSubnet):
data_subnet_pool = (
subnet_v2._format_allocation_pools(_subnet_from_pool.allocation_pools),
_subnet_from_pool.cidr,
+ _subnet_from_pool.description,
utils.format_list(_subnet_from_pool.dns_nameservers),
_subnet_from_pool.enable_dhcp,
_subnet_from_pool.gateway_ip,
@@ -167,6 +170,7 @@ class TestCreateSubnet(TestSubnet):
data_ipv6 = (
subnet_v2._format_allocation_pools(_subnet_ipv6.allocation_pools),
_subnet_ipv6.cidr,
+ _subnet_ipv6.description,
utils.format_list(_subnet_ipv6.dns_nameservers),
_subnet_ipv6.enable_dhcp,
_subnet_ipv6.gateway_ip,
@@ -427,6 +431,40 @@ class TestCreateSubnet(TestSubnet):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
+ def test_create_with_description(self):
+ # Mock SDK calls for this test.
+ self.network.create_subnet = mock.Mock(return_value=self._subnet)
+ self._network.id = self._subnet.network_id
+
+ arglist = [
+ "--subnet-range", self._subnet.cidr,
+ "--network", self._subnet.network_id,
+ "--description", self._subnet.description,
+ self._subnet.name,
+ ]
+ verifylist = [
+ ('name', self._subnet.name),
+ ('description', self._subnet.description),
+ ('subnet_range', self._subnet.cidr),
+ ('network', self._subnet.network_id),
+ ('ip_version', self._subnet.ip_version),
+ ('gateway', 'auto'),
+
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ columns, data = self.cmd.take_action(parsed_args)
+
+ self.network.create_subnet.assert_called_once_with(**{
+ 'cidr': self._subnet.cidr,
+ 'ip_version': self._subnet.ip_version,
+ 'name': self._subnet.name,
+ 'network_id': self._subnet.network_id,
+ 'description': self._subnet.description,
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
class TestDeleteSubnet(TestSubnet):
@@ -768,6 +806,30 @@ class TestSetSubnet(TestSubnet):
_testsubnet, **attrs)
self.assertIsNone(result)
+ def test_set_non_append_options(self):
+ arglist = [
+ "--description", "new_description",
+ "--dhcp",
+ "--gateway", self._subnet.gateway_ip,
+ self._subnet.name,
+ ]
+ verifylist = [
+ ('description', "new_description"),
+ ('dhcp', True),
+ ('gateway', self._subnet.gateway_ip),
+ ('subnet', self._subnet.name),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ result = self.cmd.take_action(parsed_args)
+ attrs = {
+ 'enable_dhcp': True,
+ 'gateway_ip': self._subnet.gateway_ip,
+ 'description': "new_description",
+ }
+ self.network.update_subnet.assert_called_with(self._subnet, **attrs)
+ self.assertIsNone(result)
+
class TestShowSubnet(TestSubnet):
# The subnets to be shown
@@ -776,6 +838,7 @@ class TestShowSubnet(TestSubnet):
columns = (
'allocation_pools',
'cidr',
+ 'description',
'dns_nameservers',
'enable_dhcp',
'gateway_ip',
@@ -795,6 +858,7 @@ class TestShowSubnet(TestSubnet):
data = (
subnet_v2._format_allocation_pools(_subnet.allocation_pools),
_subnet.cidr,
+ _subnet.description,
utils.format_list(_subnet.dns_nameservers),
_subnet.enable_dhcp,
_subnet.gateway_ip,
diff --git a/openstackclient/tests/unit/network/v2/test_subnet_pool.py b/openstackclient/tests/unit/network/v2/test_subnet_pool.py
index e0e1969b..c78dc6fb 100644
--- a/openstackclient/tests/unit/network/v2/test_subnet_pool.py
+++ b/openstackclient/tests/unit/network/v2/test_subnet_pool.py
@@ -50,6 +50,7 @@ class TestCreateSubnetPool(TestSubnetPool):
'address_scope_id',
'default_prefixlen',
'default_quota',
+ 'description',
'id',
'ip_version',
'is_default',
@@ -64,6 +65,7 @@ class TestCreateSubnetPool(TestSubnetPool):
_subnet_pool.address_scope_id,
_subnet_pool.default_prefixlen,
_subnet_pool.default_quota,
+ _subnet_pool.description,
_subnet_pool.id,
_subnet_pool.ip_version,
_subnet_pool.is_default,
@@ -245,6 +247,29 @@ class TestCreateSubnetPool(TestSubnetPool):
self.assertEqual(self.columns, columns)
self.assertEqual(self.data, data)
+ def test_create_with_description(self):
+ arglist = [
+ '--pool-prefix', '10.0.10.0/24',
+ '--description', self._subnet_pool.description,
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('prefixes', ['10.0.10.0/24']),
+ ('description', self._subnet_pool.description),
+ ('name', self._subnet_pool.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ columns, data = (self.cmd.take_action(parsed_args))
+
+ self.network.create_subnet_pool.assert_called_once_with(**{
+ 'name': self._subnet_pool.name,
+ 'prefixes': ['10.0.10.0/24'],
+ 'description': self._subnet_pool.description,
+ })
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.data, data)
+
class TestDeleteSubnetPool(TestSubnetPool):
@@ -611,6 +636,26 @@ class TestSetSubnetPool(TestSubnetPool):
self.assertRaises(tests_utils.ParserException, self.check_parser,
self.cmd, arglist, verifylist)
+ def test_set_description(self):
+ arglist = [
+ '--description', 'new_description',
+ self._subnet_pool.name,
+ ]
+ verifylist = [
+ ('description', "new_description"),
+ ('subnet_pool', self._subnet_pool.name),
+ ]
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ result = self.cmd.take_action(parsed_args)
+
+ attrs = {
+ 'description': "new_description",
+ }
+ self.network.update_subnet_pool.assert_called_once_with(
+ self._subnet_pool, **attrs)
+ self.assertIsNone(result)
+
class TestShowSubnetPool(TestSubnetPool):
@@ -621,6 +666,7 @@ class TestShowSubnetPool(TestSubnetPool):
'address_scope_id',
'default_prefixlen',
'default_quota',
+ 'description',
'id',
'ip_version',
'is_default',
@@ -636,6 +682,7 @@ class TestShowSubnetPool(TestSubnetPool):
_subnet_pool.address_scope_id,
_subnet_pool.default_prefixlen,
_subnet_pool.default_quota,
+ _subnet_pool.description,
_subnet_pool.id,
_subnet_pool.ip_version,
_subnet_pool.is_default,