summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2016-09-20 06:40:48 +0000
committerGerrit Code Review <review@openstack.org>2016-09-20 06:40:48 +0000
commita83f3c8a71de1686b8b9140cadf21225897b5cbd (patch)
tree122eb61cbf311e3454cd5f0aa6f0ca4c9b82b95f /openstackclient/tests
parenta51406da5a84ea5f721771d2eb60f05d4c129152 (diff)
parent4265002e599af332f2e6288814dcaefa0dcb1be0 (diff)
downloadpython-openstackclient-a83f3c8a71de1686b8b9140cadf21225897b5cbd.tar.gz
Merge "Add 'description' option to os subnet (pool) create/set cmd"
Diffstat (limited to 'openstackclient/tests')
-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 4cc3512e..d4cef0a3 100644
--- a/openstackclient/tests/unit/network/v2/fakes.py
+++ b/openstackclient/tests/unit/network/v2/fakes.py
@@ -892,6 +892,7 @@ class FakeSubnet(object):
'segment_id': None,
'service_types': [],
'subnetpool_id': None,
+ 'description': 'subnet-description-' + uuid.uuid4().hex,
}
# Overwrite default attributes.
@@ -1047,6 +1048,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 f09fe4fa..58506391 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):
@@ -876,6 +914,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
@@ -884,6 +946,7 @@ class TestShowSubnet(TestSubnet):
columns = (
'allocation_pools',
'cidr',
+ 'description',
'dns_nameservers',
'enable_dhcp',
'gateway_ip',
@@ -903,6 +966,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 251323d9..fa6ffff3 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):
@@ -749,6 +774,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):
@@ -759,6 +804,7 @@ class TestShowSubnetPool(TestSubnetPool):
'address_scope_id',
'default_prefixlen',
'default_quota',
+ 'description',
'id',
'ip_version',
'is_default',
@@ -774,6 +820,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,