Skip to content

Commit 54bb747

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Do not sort subnet dns_nameservers field"
2 parents e9aa6f5 + 75ed315 commit 54bb747

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

openstackclient/network/v2/subnet.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ def human_readable(self):
6060
)
6161

6262

63+
class UnsortedListColumn(cliff_columns.FormattableColumn):
64+
# format_columns.ListColumn sorts the output, but for things like
65+
# DNS server addresses the order matters
66+
def human_readable(self):
67+
return ', '.join(self._value)
68+
69+
6370
_formatters = {
6471
'allocation_pools': AllocationPoolsColumn,
65-
'dns_nameservers': format_columns.ListColumn,
72+
'dns_nameservers': UnsortedListColumn,
6673
'host_routes': HostRoutesColumn,
6774
'service_types': format_columns.ListColumn,
6875
'tags': format_columns.ListColumn,

openstackclient/tests/unit/network/v2/test_subnet.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def _init_subnet_variables(self):
167167
subnet_v2.AllocationPoolsColumn(self._subnet.allocation_pools),
168168
self._subnet.cidr,
169169
self._subnet.description,
170-
format_columns.ListColumn(self._subnet.dns_nameservers),
170+
subnet_v2.UnsortedListColumn(self._subnet.dns_nameservers),
171171
self._subnet.enable_dhcp,
172172
self._subnet.gateway_ip,
173173
subnet_v2.HostRoutesColumn(self._subnet.host_routes),
@@ -190,7 +190,9 @@ def _init_subnet_variables(self):
190190
),
191191
self._subnet_from_pool.cidr,
192192
self._subnet_from_pool.description,
193-
format_columns.ListColumn(self._subnet_from_pool.dns_nameservers),
193+
subnet_v2.UnsortedListColumn(
194+
self._subnet_from_pool.dns_nameservers
195+
),
194196
self._subnet_from_pool.enable_dhcp,
195197
self._subnet_from_pool.gateway_ip,
196198
subnet_v2.HostRoutesColumn(self._subnet_from_pool.host_routes),
@@ -213,7 +215,7 @@ def _init_subnet_variables(self):
213215
),
214216
self._subnet_ipv6.cidr,
215217
self._subnet_ipv6.description,
216-
format_columns.ListColumn(self._subnet_ipv6.dns_nameservers),
218+
subnet_v2.UnsortedListColumn(self._subnet_ipv6.dns_nameservers),
217219
self._subnet_ipv6.enable_dhcp,
218220
self._subnet_ipv6.gateway_ip,
219221
subnet_v2.HostRoutesColumn(self._subnet_ipv6.host_routes),
@@ -236,7 +238,7 @@ def _init_subnet_variables(self):
236238
),
237239
self._subnet_ipv6_pd.cidr,
238240
self._subnet_ipv6_pd.description,
239-
format_columns.ListColumn(self._subnet_ipv6_pd.dns_nameservers),
241+
subnet_v2.UnsortedListColumn(self._subnet_ipv6_pd.dns_nameservers),
240242
self._subnet_ipv6_pd.enable_dhcp,
241243
self._subnet_ipv6_pd.gateway_ip,
242244
subnet_v2.HostRoutesColumn(self._subnet_ipv6_pd.host_routes),
@@ -837,7 +839,7 @@ class TestListSubnet(TestSubnet):
837839
subnet.cidr,
838840
subnet.project_id,
839841
subnet.enable_dhcp,
840-
format_columns.ListColumn(subnet.dns_nameservers),
842+
subnet_v2.UnsortedListColumn(subnet.dns_nameservers),
841843
subnet_v2.AllocationPoolsColumn(subnet.allocation_pools),
842844
subnet_v2.HostRoutesColumn(subnet.host_routes),
843845
subnet.ip_version,
@@ -1489,7 +1491,7 @@ class TestShowSubnet(TestSubnet):
14891491
subnet_v2.AllocationPoolsColumn(_subnet.allocation_pools),
14901492
_subnet.cidr,
14911493
_subnet.description,
1492-
format_columns.ListColumn(_subnet.dns_nameservers),
1494+
subnet_v2.UnsortedListColumn(_subnet.dns_nameservers),
14931495
_subnet.enable_dhcp,
14941496
_subnet.gateway_ip,
14951497
subnet_v2.HostRoutesColumn(_subnet.host_routes),
@@ -1550,9 +1552,10 @@ def test_show_all_options(self):
15501552
class TestUnsetSubnet(TestSubnet):
15511553
def setUp(self):
15521554
super(TestUnsetSubnet, self).setUp()
1555+
# Add three dns_nameserver entries so we can verify ordering
15531556
self._testsubnet = network_fakes.FakeSubnet.create_one_subnet(
15541557
{
1555-
'dns_nameservers': ['8.8.8.8', '8.8.8.4'],
1558+
'dns_nameservers': ['8.8.8.8', '8.8.8.4', '8.8.4.4'],
15561559
'host_routes': [
15571560
{'destination': '10.20.20.0/24', 'nexthop': '10.20.20.1'},
15581561
{'destination': '10.30.30.30/24', 'nexthop': '10.30.30.1'},
@@ -1578,9 +1581,10 @@ def setUp(self):
15781581
self.cmd = subnet_v2.UnsetSubnet(self.app, None)
15791582

15801583
def test_unset_subnet_params(self):
1584+
# Remove just the middle dns_nameserver entry, verify still in order
15811585
arglist = [
15821586
'--dns-nameserver',
1583-
'8.8.8.8',
1587+
'8.8.8.4',
15841588
'--host-route',
15851589
'destination=10.30.30.30/24,gateway=10.30.30.1',
15861590
'--allocation-pool',
@@ -1591,7 +1595,7 @@ def test_unset_subnet_params(self):
15911595
self._testsubnet.name,
15921596
]
15931597
verifylist = [
1594-
('dns_nameservers', ['8.8.8.8']),
1598+
('dns_nameservers', ['8.8.8.4']),
15951599
(
15961600
'host_routes',
15971601
[{"destination": "10.30.30.30/24", "gateway": "10.30.30.1"}],
@@ -1605,7 +1609,7 @@ def test_unset_subnet_params(self):
16051609
result = self.cmd.take_action(parsed_args)
16061610

16071611
attrs = {
1608-
'dns_nameservers': ['8.8.8.4'],
1612+
'dns_nameservers': ['8.8.8.8', '8.8.4.4'],
16091613
'host_routes': [
16101614
{"destination": "10.20.20.0/24", "nexthop": "10.20.20.1"}
16111615
],

0 commit comments

Comments
 (0)