Skip to content

Commit fb2e0ce

Browse files
committed
tests: Explicitly specify port fields for output
Rather than excluding the few fields we don't want, explicitly indicate the ones we do want. We were already in-effect doing this in our tests, so this is simply moving the definition from tests to the main code. Note that this is a problem in the tests for virtually all commands that will be seen as the SDK continues to evolve and new fields are added to existing resources. This is a problem that be solved over time though, rather than in a big bang commit. Change-Id: Iaa64e97450f5c73cab2e2c3b0c741aec1495b4f1 Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 08faf81 commit fb2e0ce

2 files changed

Lines changed: 59 additions & 29 deletions

File tree

openstackclient/network/v2/port.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,48 @@ def human_readable(self):
5555

5656

5757
def _get_columns(item):
58-
column_map = {
59-
'binding:host_id': 'binding_host_id',
60-
'binding:profile': 'binding_profile',
61-
'binding:vif_details': 'binding_vif_details',
62-
'binding:vif_type': 'binding_vif_type',
63-
'binding:vnic_type': 'binding_vnic_type',
64-
'is_admin_state_up': 'admin_state_up',
65-
'is_port_security_enabled': 'port_security_enabled',
58+
column_data_mapping = {
59+
'admin_state_up': 'is_admin_state_up',
60+
'allowed_address_pairs': 'allowed_address_pairs',
61+
'binding_host_id': 'binding_host_id',
62+
'binding_profile': 'binding_profile',
63+
'binding_vif_details': 'binding_vif_details',
64+
'binding_vif_type': 'binding_vif_type',
65+
'binding_vnic_type': 'binding_vnic_type',
66+
'created_at': 'created_at',
67+
'data_plane_status': 'data_plane_status',
68+
'description': 'description',
69+
'device_id': 'device_id',
70+
'device_owner': 'device_owner',
71+
'device_profile': 'device_profile',
72+
'dns_assignment': 'dns_assignment',
73+
'dns_domain': 'dns_domain',
74+
'dns_name': 'dns_name',
75+
'extra_dhcp_opts': 'extra_dhcp_opts',
76+
'fixed_ips': 'fixed_ips',
77+
'hints': 'hints',
78+
'id': 'id',
79+
'ip_allocation': 'ip_allocation',
80+
'mac_address': 'mac_address',
81+
'name': 'name',
82+
'network_id': 'network_id',
83+
'numa_affinity_policy': 'numa_affinity_policy',
84+
'port_security_enabled': 'is_port_security_enabled',
85+
'project_id': 'project_id',
86+
'propagate_uplink_status': 'propagate_uplink_status',
87+
'resource_request': 'resource_request',
88+
'revision_number': 'revision_number',
89+
'qos_network_policy_id': 'qos_network_policy_id',
90+
'qos_policy_id': 'qos_policy_id',
91+
'security_group_ids': 'security_group_ids',
92+
'status': 'status',
93+
'tags': 'tags',
94+
'trunk_details': 'trunk_details',
95+
'updated_at': 'updated_at',
6696
}
67-
hidden_columns = ['location', 'tenant_id']
68-
return utils.get_osc_show_columns_for_sdk_resource(
69-
item, column_map, hidden_columns
97+
return (
98+
tuple(column_data_mapping.keys()),
99+
tuple(column_data_mapping.values()),
70100
)
71101

72102

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

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_create_default_options(self):
172172
)
173173
self.assertFalse(self.network_client.set_tags.called)
174174

175-
self.assertEqual(set(self.columns), set(columns))
175+
self.assertCountEqual(self.columns, columns)
176176
self.assertCountEqual(self.data, data)
177177

178178
def test_create_full_options(self):
@@ -245,7 +245,7 @@ def test_create_full_options(self):
245245
}
246246
)
247247

248-
self.assertEqual(set(self.columns), set(columns))
248+
self.assertCountEqual(self.columns, columns)
249249
self.assertCountEqual(self.data, data)
250250

251251
def test_create_invalid_json_binding_profile(self):
@@ -309,7 +309,7 @@ def test_create_json_binding_profile(self):
309309
}
310310
)
311311

312-
self.assertEqual(set(self.columns), set(columns))
312+
self.assertCountEqual(self.columns, columns)
313313
self.assertCountEqual(self.data, data)
314314

315315
def test_create_with_security_group(self):
@@ -347,7 +347,7 @@ def test_create_with_security_group(self):
347347
}
348348
)
349349

350-
self.assertEqual(set(self.columns), set(columns))
350+
self.assertCountEqual(self.columns, columns)
351351
self.assertCountEqual(self.data, data)
352352

353353
def test_create_port_with_dns_name(self):
@@ -380,7 +380,7 @@ def test_create_port_with_dns_name(self):
380380
}
381381
)
382382

383-
self.assertEqual(set(self.columns), set(columns))
383+
self.assertCountEqual(self.columns, columns)
384384
self.assertCountEqual(self.data, data)
385385

386386
def test_create_with_security_groups(self):
@@ -420,7 +420,7 @@ def test_create_with_security_groups(self):
420420
}
421421
)
422422

423-
self.assertEqual(set(self.columns), set(columns))
423+
self.assertCountEqual(self.columns, columns)
424424
self.assertCountEqual(self.data, data)
425425

426426
def test_create_with_no_security_groups(self):
@@ -449,7 +449,7 @@ def test_create_with_no_security_groups(self):
449449
}
450450
)
451451

452-
self.assertEqual(set(self.columns), set(columns))
452+
self.assertCountEqual(self.columns, columns)
453453
self.assertCountEqual(self.data, data)
454454

455455
def test_create_with_no_fixed_ips(self):
@@ -478,7 +478,7 @@ def test_create_with_no_fixed_ips(self):
478478
}
479479
)
480480

481-
self.assertEqual(set(self.columns), set(columns))
481+
self.assertCountEqual(self.columns, columns)
482482
self.assertCountEqual(self.data, data)
483483

484484
def test_create_port_with_allowed_address_pair_ipaddr(self):
@@ -520,7 +520,7 @@ def test_create_port_with_allowed_address_pair_ipaddr(self):
520520
}
521521
)
522522

523-
self.assertEqual(set(self.columns), set(columns))
523+
self.assertCountEqual(self.columns, columns)
524524
self.assertCountEqual(self.data, data)
525525

526526
def test_create_port_with_allowed_address_pair(self):
@@ -571,7 +571,7 @@ def test_create_port_with_allowed_address_pair(self):
571571
}
572572
)
573573

574-
self.assertEqual(set(self.columns), set(columns))
574+
self.assertCountEqual(self.columns, columns)
575575
self.assertCountEqual(self.data, data)
576576

577577
def test_create_port_with_qos(self):
@@ -608,7 +608,7 @@ def test_create_port_with_qos(self):
608608
}
609609
)
610610

611-
self.assertEqual(set(self.columns), set(columns))
611+
self.assertCountEqual(self.columns, columns)
612612
self.assertCountEqual(self.data, data)
613613

614614
def test_create_port_security_enabled(self):
@@ -738,7 +738,7 @@ def _test_create_with_tag(self, add_tags=True, add_tags_in_post=True):
738738
else:
739739
self.assertFalse(self.network_client.set_tags.called)
740740

741-
self.assertEqual(set(self.columns), set(columns))
741+
self.assertCountEqual(self.columns, columns)
742742
self.assertCountEqual(self.data, data)
743743

744744
def test_create_with_tags(self):
@@ -787,7 +787,7 @@ def _test_create_with_uplink_status_propagation(self, enable=True):
787787
}
788788
)
789789

790-
self.assertEqual(set(self.columns), set(columns))
790+
self.assertCountEqual(self.columns, columns)
791791
self.assertCountEqual(self.data, data)
792792

793793
def test_create_with_uplink_status_propagation_enabled(self):
@@ -893,7 +893,7 @@ def _test_create_with_numa_affinity_policy(self, policy=None):
893893
create_args['numa_affinity_policy'] = numa_affinity_policy
894894
self.network_client.create_port.assert_called_once_with(**create_args)
895895

896-
self.assertEqual(set(self.columns), set(columns))
896+
self.assertCountEqual(self.columns, columns)
897897
self.assertCountEqual(self.data, data)
898898

899899
def test_create_with_numa_affinity_policy_required(self):
@@ -940,7 +940,7 @@ def test_create_with_device_profile(self):
940940
'device_profile': 'cyborg_device_profile_1',
941941
}
942942
self.network_client.create_port.assert_called_once_with(**create_args)
943-
self.assertEqual(set(self.columns), set(columns))
943+
self.assertCountEqual(self.columns, columns)
944944
self.assertCountEqual(self.data, data)
945945

946946
def test_create_hints_invalid_json(self):
@@ -1032,7 +1032,7 @@ def test_create_hints_valid_alias_value(self):
10321032
}
10331033
)
10341034

1035-
self.assertEqual(set(self.columns), set(columns))
1035+
self.assertCountEqual(self.columns, columns)
10361036
self.assertCountEqual(self.data, data)
10371037

10381038
def test_create_hints_valid_json(self):
@@ -1067,7 +1067,7 @@ def test_create_hints_valid_json(self):
10671067
}
10681068
)
10691069

1070-
self.assertEqual(set(self.columns), set(columns))
1070+
self.assertCountEqual(self.columns, columns)
10711071
self.assertCountEqual(self.data, data)
10721072

10731073

@@ -2496,7 +2496,7 @@ def test_show_all_options(self):
24962496
self._port.name, ignore_missing=False
24972497
)
24982498

2499-
self.assertEqual(set(self.columns), set(columns))
2499+
self.assertCountEqual(self.columns, columns)
25002500
self.assertCountEqual(self.data, data)
25012501

25022502

0 commit comments

Comments
 (0)