Skip to content

Commit 3b409e4

Browse files
author
Eric Fried
committed
Refactor AggregateTests
While investigating the referenced story/bug I noticed that wait_for_status in openstackclient.tests.functional.compute.v2.test_aggregate.AggregateTests was doing a lot more than it should ever need to (it probably got copied in from somewhere). The two places calling it only need to a) check the output of `openstack aggregate show`, and b) try once -- since they just got done creating the aggregate synchronously, there should never be a need to delay/retry. So this commit removes the helper method and just inlines the check. At the same time, the addCleanup(aggregate delete) directives are moved above their respective creates. This is a defensive best practice which makes sure cleanup happens even if something fails very soon after the actual back-end create (as was in fact the case with the referenced bug/story). It is unknown whether this will impact the referenced bug. Change-Id: I0d7432f13642fbccd5ca79da9c76adfcbabb5fa9 Story: 2006811 Related-Bug: #1851391
1 parent d17a1c8 commit 3b409e4

1 file changed

Lines changed: 19 additions & 41 deletions

File tree

openstackclient/tests/functional/compute/v2/test_aggregate.py

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# under the License.
1212

1313
import json
14-
import time
1514
import uuid
1615

1716
from openstackclient.tests.functional import base
@@ -20,34 +19,14 @@
2019
class AggregateTests(base.TestCase):
2120
"""Functional tests for aggregate"""
2221

23-
def wait_for_status(self, check_type, check_name, desired_status,
24-
wait=120, interval=5, failures=None):
25-
current_status = "notset"
26-
if failures is None:
27-
failures = ['error']
28-
total_sleep = 0
29-
while total_sleep < wait:
30-
output = json.loads(self.openstack(
31-
check_type + ' show -f json ' + check_name))
32-
current_status = output['name']
33-
if (current_status == desired_status):
34-
print('{} {} now has status {}'
35-
.format(check_type, check_name, current_status))
36-
return
37-
print('Checking {} {} Waiting for {} current status: {}'
38-
.format(check_type, check_name,
39-
desired_status, current_status))
40-
if current_status in failures:
41-
raise Exception(
42-
'Current status {} of {} {} is one of failures {}'
43-
.format(current_status, check_type, check_name, failures))
44-
time.sleep(interval)
45-
total_sleep += interval
46-
self.assertOutput(desired_status, current_status)
47-
4822
def test_aggregate_crud(self):
4923
"""Test create, delete multiple"""
5024
name1 = uuid.uuid4().hex
25+
self.addCleanup(
26+
self.openstack,
27+
'aggregate delete ' + name1,
28+
fail_ok=True,
29+
)
5130
cmd_output = json.loads(self.openstack(
5231
'aggregate create -f json ' +
5332
'--zone nova ' +
@@ -66,14 +45,16 @@ def test_aggregate_crud(self):
6645
'a',
6746
cmd_output['properties']
6847
)
69-
self.wait_for_status('aggregate', name1, name1)
48+
cmd_output = json.loads(self.openstack(
49+
'aggregate show -f json ' + name1))
50+
self.assertEqual(name1, cmd_output['name'])
51+
52+
name2 = uuid.uuid4().hex
7053
self.addCleanup(
7154
self.openstack,
72-
'aggregate delete ' + name1,
55+
'aggregate delete ' + name2,
7356
fail_ok=True,
7457
)
75-
76-
name2 = uuid.uuid4().hex
7758
cmd_output = json.loads(self.openstack(
7859
'aggregate create -f json ' +
7960
'--zone external ' +
@@ -87,15 +68,17 @@ def test_aggregate_crud(self):
8768
'external',
8869
cmd_output['availability_zone']
8970
)
90-
self.wait_for_status('aggregate', name2, name2)
71+
cmd_output = json.loads(self.openstack(
72+
'aggregate show -f json ' + name2))
73+
self.assertEqual(name2, cmd_output['name'])
74+
75+
# Test aggregate set
76+
name3 = uuid.uuid4().hex
9177
self.addCleanup(
9278
self.openstack,
93-
'aggregate delete ' + name2,
79+
'aggregate delete ' + name3,
9480
fail_ok=True,
9581
)
96-
97-
# Test aggregate set
98-
name3 = uuid.uuid4().hex
9982
raw_output = self.openstack(
10083
'aggregate set ' +
10184
'--name ' + name3 + ' ' +
@@ -105,11 +88,6 @@ def test_aggregate_crud(self):
10588
name1
10689
)
10790
self.assertOutput('', raw_output)
108-
self.addCleanup(
109-
self.openstack,
110-
'aggregate delete ' + name3,
111-
fail_ok=True,
112-
)
11391

11492
cmd_output = json.loads(self.openstack(
11593
'aggregate show -f json ' +
@@ -196,11 +174,11 @@ def test_aggregate_add_and_remove_host(self):
196174
self.skipTest("Skip aggregates in a Nova cells v1 configuration")
197175

198176
name = uuid.uuid4().hex
177+
self.addCleanup(self.openstack, 'aggregate delete ' + name)
199178
self.openstack(
200179
'aggregate create ' +
201180
name
202181
)
203-
self.addCleanup(self.openstack, 'aggregate delete ' + name)
204182

205183
# Test add host
206184
cmd_output = json.loads(self.openstack(

0 commit comments

Comments
 (0)