Deduplicate get_opts methods · reulan/python-openstackclient@259b4a1 · GitHub
Skip to content

Commit 259b4a1

Browse files
kromanenkostevemar
authored andcommitted
Deduplicate get_opts methods
One get_opts method can work instead of get_list_opts and get_show_opts both. Remove mutable default value. Change-Id: I9c5683d416f0f3ed4989abab6f152b0341e30a4f
1 parent 44d4188 commit 259b4a1

29 files changed

Lines changed: 117 additions & 122 deletions

functional/common/test.py

Lines changed: 2 additions & 6 deletions

functional/tests/common/test_availability_zone.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ class AvailabilityZoneTests(test.TestCase):
2020
DEFAULT_AZ_NAME = 'nova'
2121

2222
def test_availability_zone_list(self):
23-
opts = self.get_list_opts(self.HEADERS)
23+
opts = self.get_opts(self.HEADERS)
2424
raw_output = self.openstack('availability zone list' + opts)
2525
self.assertIn(self.DEFAULT_AZ_NAME, raw_output)

functional/tests/common/test_quota.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def setUpClass(cls):
2727
def test_quota_set(self):
2828
self.openstack('quota set --instances 11 --volumes 11 --networks 11 '
2929
+ self.PROJECT_NAME)
30-
opts = self.get_show_opts(self.EXPECTED_FIELDS)
30+
opts = self.get_opts(self.EXPECTED_FIELDS)
3131
raw_output = self.openstack('quota show ' + self.PROJECT_NAME + opts)
3232
self.assertEqual("11\n11\n11\n", raw_output)
3333

functional/tests/compute/v2/test_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ComputeAgentTests(test.TestCase):
3131

3232
@classmethod
3333
def setUpClass(cls):
34-
opts = cls.get_show_opts(cls.HEADERS)
34+
opts = cls.get_opts(cls.HEADERS)
3535
raw_output = cls.openstack('compute agent create ' +
3636
cls.OS + ' ' + cls.ARCH + ' ' +
3737
cls.VER + ' ' + cls.URL + ' ' +

functional/tests/compute/v2/test_aggregate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AggregateTests(test.TestCase):
2424

2525
@classmethod
2626
def setUpClass(cls):
27-
opts = cls.get_show_opts(cls.FIELDS)
27+
opts = cls.get_opts(cls.FIELDS)
2828
# Use the default 'nova' availability zone for the aggregate.
2929
raw_output = cls.openstack(
3030
'aggregate create --zone nova ' + cls.NAME + opts
@@ -38,17 +38,17 @@ def tearDownClass(cls):
3838
cls.assertOutput('', raw_output)
3939

4040
def test_aggregate_list(self):
41-
opts = self.get_list_opts(self.HEADERS)
41+
opts = self.get_opts(self.HEADERS)
4242
raw_output = self.openstack('aggregate list' + opts)
4343
self.assertIn(self.NAME, raw_output)
4444

4545
def test_aggregate_show(self):
46-
opts = self.get_show_opts(self.FIELDS)
46+
opts = self.get_opts(self.FIELDS)
4747
raw_output = self.openstack('aggregate show ' + self.NAME + opts)
4848
self.assertEqual(self.NAME + "\n", raw_output)
4949

5050
def test_aggregate_properties(self):
51-
opts = self.get_show_opts(['properties'])
51+
opts = self.get_opts(['properties'])
5252

5353
raw_output = self.openstack(
5454
'aggregate set --property a=b --property c=d ' + self.NAME

functional/tests/compute/v2/test_flavor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class FlavorTests(test.TestCase):
2424

2525
@classmethod
2626
def setUpClass(cls):
27-
opts = cls.get_show_opts(cls.FIELDS)
27+
opts = cls.get_opts(cls.FIELDS)
2828
raw_output = cls.openstack(
2929
'flavor create --property a=b --property c=d ' + cls.NAME + opts)
3030
expected = cls.NAME + '\n'
@@ -36,18 +36,18 @@ def tearDownClass(cls):
3636
cls.assertOutput('', raw_output)
3737

3838
def test_flavor_list(self):
39-
opts = self.get_list_opts(self.HEADERS)
39+
opts = self.get_opts(self.HEADERS)
4040
raw_output = self.openstack('flavor list' + opts)
4141
self.assertIn("small", raw_output)
4242
self.assertIn(self.NAME, raw_output)
4343

4444
def test_flavor_show(self):
45-
opts = self.get_show_opts(self.FIELDS)
45+
opts = self.get_opts(self.FIELDS)
4646
raw_output = self.openstack('flavor show ' + self.NAME + opts)
4747
self.assertEqual(self.NAME + "\n", raw_output)
4848

4949
def test_flavor_properties(self):
50-
opts = self.get_show_opts(['properties'])
50+
opts = self.get_opts(['properties'])
5151
# check the properties we added in create command.
5252
raw_output = self.openstack('flavor show ' + self.NAME + opts)
5353
self.assertEqual("a='b', c='d'\n", raw_output)

functional/tests/compute/v2/test_server.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def get_network(cls):
5858
def server_create(self, name=None):
5959
"""Create server. Add cleanup."""
6060
name = name or data_utils.rand_uuid()
61-
opts = self.get_show_opts(self.FIELDS)
61+
opts = self.get_opts(self.FIELDS)
6262
flavor = self.get_flavor()
6363
image = self.get_image()
6464
network = self.get_network()
@@ -72,7 +72,7 @@ def server_create(self, name=None):
7272

7373
def server_list(self, params=[]):
7474
"""List servers."""
75-
opts = self.get_list_opts(params)
75+
opts = self.get_opts(params)
7676
return self.openstack('server list' + opts)
7777

7878
def server_delete(self, name):
@@ -114,7 +114,7 @@ def test_server_list(self):
114114
2) List servers
115115
3) Check output
116116
"""
117-
opts = self.get_list_opts(self.HEADERS)
117+
opts = self.get_opts(self.HEADERS)
118118
raw_output = self.openstack('server list' + opts)
119119
self.assertIn(self.NAME, raw_output)
120120

@@ -126,7 +126,7 @@ def test_server_show(self):
126126
2) Show server
127127
3) Check output
128128
"""
129-
opts = self.get_show_opts(self.FIELDS)
129+
opts = self.get_opts(self.FIELDS)
130130
raw_output = self.openstack('server show ' + self.NAME + opts)
131131
self.assertEqual(self.NAME + "\n", raw_output)
132132

@@ -144,13 +144,13 @@ def test_server_metadata(self):
144144
# metadata
145145
raw_output = self.openstack(
146146
'server set --property a=b --property c=d ' + self.NAME)
147-
opts = self.get_show_opts(["name", "properties"])
147+
opts = self.get_opts(["name", "properties"])
148148
raw_output = self.openstack('server show ' + self.NAME + opts)
149149
self.assertEqual(self.NAME + "\na='b', c='d'\n", raw_output)
150150

151151
raw_output = self.openstack(
152152
'server unset --property a ' + self.NAME)
153-
opts = self.get_show_opts(["name", "properties"])
153+
opts = self.get_opts(["name", "properties"])
154154
raw_output = self.openstack('server show ' + self.NAME + opts)
155155
self.assertEqual(self.NAME + "\nc='d'\n", raw_output)
156156

@@ -224,7 +224,7 @@ def test_server_rescue_unrescue(self):
224224
"""
225225
self.wait_for_status("ACTIVE")
226226
# rescue
227-
opts = self.get_show_opts(["adminPass"])
227+
opts = self.get_opts(["adminPass"])
228228
raw_output = self.openstack('server rescue ' + self.NAME + opts)
229229
self.assertNotEqual("", raw_output)
230230
self.wait_for_status("RESCUE")
@@ -248,7 +248,7 @@ def test_server_attach_detach_floating_ip(self):
248248
"""
249249
self.wait_for_status("ACTIVE")
250250
# attach ip
251-
opts = self.get_show_opts(["id", "floating_ip_address"])
251+
opts = self.get_opts(["id", "floating_ip_address"])
252252
raw_output = self.openstack('ip floating create ' +
253253
self.IP_POOL +
254254
opts)
@@ -288,7 +288,7 @@ def wait_for_status(self, expected_status='ACTIVE', wait=900, interval=30):
288288
# TODO(thowe): Add a server wait command to osc
289289
failures = ['ERROR']
290290
total_sleep = 0
291-
opts = self.get_show_opts(['status'])
291+
opts = self.get_opts(['status'])
292292
while total_sleep < wait:
293293
status = self.openstack('server show ' + self.NAME + opts)
294294
status = status.rstrip()

functional/tests/compute/v2/test_server_group.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ServerGroupTests(test.TestCase):
2424

2525
@classmethod
2626
def setUpClass(cls):
27-
opts = cls.get_show_opts(cls.FIELDS)
27+
opts = cls.get_opts(cls.FIELDS)
2828
raw_output = cls.openstack('server group create --policy affinity ' +
2929
cls.NAME + opts)
3030
expected = cls.NAME + '\n'
@@ -36,11 +36,11 @@ def tearDownClass(cls):
3636
cls.assertOutput('', raw_output)
3737

3838
def test_server_group_list(self):
39-
opts = self.get_list_opts(self.HEADERS)
39+
opts = self.get_opts(self.HEADERS)
4040
raw_output = self.openstack('server group list' + opts)
4141
self.assertIn(self.NAME, raw_output)
4242

4343
def test_server_group_show(self):
44-
opts = self.get_show_opts(self.FIELDS)
44+
opts = self.get_opts(self.FIELDS)
4545
raw_output = self.openstack('server group show ' + self.NAME + opts)
4646
self.assertEqual(self.NAME + "\n", raw_output)

functional/tests/image/v1/test_image.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ImageTests(test.TestCase):
2727
@classmethod
2828
def setUpClass(cls):
2929
os.environ['OS_IMAGE_API_VERSION'] = '1'
30-
opts = cls.get_show_opts(cls.FIELDS)
30+
opts = cls.get_opts(cls.FIELDS)
3131
raw_output = cls.openstack('image create ' + cls.NAME + opts)
3232
expected = cls.NAME + '\n'
3333
cls.assertOutput(expected, raw_output)
@@ -43,25 +43,25 @@ def tearDownClass(cls):
4343
cls.assertOutput('', raw_output)
4444

4545
def test_image_list(self):
46-
opts = self.get_list_opts(self.HEADERS)
46+
opts = self.get_opts(self.HEADERS)
4747
raw_output = self.openstack('image list' + opts)
4848
self.assertIn(self.NAME, raw_output)
4949

5050
def test_image_show(self):
51-
opts = self.get_show_opts(self.FIELDS)
51+
opts = self.get_opts(self.FIELDS)
5252
raw_output = self.openstack('image show ' + self.NAME + opts)
5353
self.assertEqual(self.NAME + "\n", raw_output)
5454

5555
def test_image_set(self):
56-
opts = self.get_show_opts([
56+
opts = self.get_opts([
5757
"disk_format", "is_public", "min_disk", "min_ram", "name"])
5858
self.openstack('image set --min-disk 4 --min-ram 5 ' +
5959
'--disk-format qcow2 --public ' + self.NAME)
6060
raw_output = self.openstack('image show ' + self.NAME + opts)
6161
self.assertEqual("qcow2\nTrue\n4\n5\n" + self.NAME + '\n', raw_output)
6262

6363
def test_image_metadata(self):
64-
opts = self.get_show_opts(["name", "properties"])
64+
opts = self.get_opts(["name", "properties"])
6565
self.openstack('image set --property a=b --property c=d ' + self.NAME)
6666
raw_output = self.openstack('image show ' + self.NAME + opts)
6767
self.assertEqual(self.NAME + "\na='b', c='d'\n", raw_output)

functional/tests/image/v2/test_image.py

Lines changed: 6 additions & 6 deletions

0 commit comments

Comments
 (0)