Skip to content

Commit 2e7a008

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "functional: Remove 'api' parameter"
2 parents 66ffed4 + 7ae1a10 commit 2e7a008

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+449
-519
lines changed

nova/tests/functional/api_sample_tests/test_instance_actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def setUp(self):
3434
response_data = api_samples_test_base.pretty_data(response.content)
3535
actions = api_samples_test_base.objectify(response_data)
3636
self.action_stop = actions['instanceActions'][0]
37-
self._wait_for_state_change(self.api, {'id': self.uuid}, 'SHUTOFF')
37+
self._wait_for_state_change({'id': self.uuid}, 'SHUTOFF')
3838

3939
def _get_subs(self):
4040
return {

nova/tests/functional/api_sample_tests/test_multinic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ def setUp(self):
3232

3333
def _boot_a_server(self, expected_status='ACTIVE', extra_params=None):
3434
server = self._build_minimal_create_server_request(
35-
self.api, 'MultinicSampleJsonTestServer')
35+
'MultinicSampleJsonTestServer')
3636
if extra_params:
3737
server.update(extra_params)
3838

3939
created_server = self.api.post_server({'server': server})
4040

4141
# Wait for it to finish being created
42-
found_server = self._wait_for_state_change(self.api, created_server,
42+
found_server = self._wait_for_state_change(created_server,
4343
expected_status)
4444
return found_server
4545

nova/tests/functional/compute/test_init_host.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def test_migrate_disk_and_power_off_crash_finish_revert_migration(self):
4040
# Create a server, it does not matter on which host it lands.
4141
name = 'test_migrate_disk_and_power_off_crash_finish_revert_migration'
4242
server = self._build_minimal_create_server_request(
43-
self.api, name, image_uuid=fake_image.get_valid_image_id(),
43+
name, image_uuid=fake_image.get_valid_image_id(),
4444
networks='auto')
4545
server = self.api.post_server({'server': server})
46-
server = self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
46+
server = self._wait_for_state_change(server, 'ACTIVE')
4747
# Save the source hostname for assertions later.
4848
source_host = server['OS-EXT-SRV-ATTR:host']
4949

@@ -66,8 +66,7 @@ def fake_migrate_disk_and_power_off(*args, **kwargs):
6666
self.admin_api.post_server_action(server['id'], {'migrate': None})
6767
# Now wait for the task_state to be reset to None during
6868
# _init_instance.
69-
server = self._wait_for_server_parameter(
70-
self.admin_api, server, {
69+
server = self._wait_for_server_parameter(server, {
7170
'status': 'ACTIVE',
7271
'OS-EXT-STS:task_state': None,
7372
'OS-EXT-SRV-ATTR:host': source_host
@@ -158,7 +157,7 @@ def test_restart_compute_while_instance_waiting_for_resource_claim(self):
158157
# instance_claim() to stop it. This is less realistic but it works in
159158
# the test env.
160159
server_req = self._build_minimal_create_server_request(
161-
self.api, 'interrupted-server', flavor_id=self.flavor1['id'],
160+
'interrupted-server', flavor_id=self.flavor1['id'],
162161
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
163162
networks='none')
164163

@@ -170,7 +169,7 @@ def sleep_forever(*args, **kwargs):
170169
mock_instance_claim.side_effect = sleep_forever
171170

172171
server = self.api.post_server({'server': server_req})
173-
self._wait_for_state_change(self.admin_api, server, 'BUILD')
172+
self._wait_for_state_change(server, 'BUILD')
174173

175174
# the instance.create.start is the closest thing to the
176175
# instance_claim call we can wait for in the test
@@ -182,7 +181,7 @@ def sleep_forever(*args, **kwargs):
182181

183182
# We expect that the instance is pushed to ERROR state during the
184183
# compute restart.
185-
self._wait_for_state_change(self.admin_api, server, 'ERROR')
184+
self._wait_for_state_change(server, 'ERROR')
186185
mock_log.assert_called_with(
187186
'Instance spawn was interrupted before instance_claim, setting '
188187
'instance to ERROR state',

nova/tests/functional/compute/test_live_migration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_live_migrate_attachment_delete_fails(self):
6969
'uuid': uuids.working_volume,
7070
'source_type': 'volume',
7171
'destination_type': 'volume'}]}})
72-
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
72+
server = self._wait_for_state_change(server, 'ACTIVE')
7373

7474
source = server['OS-EXT-SRV-ATTR:host']
7575
if source == self.compute.host:
@@ -87,7 +87,7 @@ def test_live_migrate_attachment_delete_fails(self):
8787
self.stub_out('nova.volume.cinder.API.attachment_delete',
8888
stub_attachment_delete)
8989
self.api.post_server_action(server['id'], post)
90-
self._wait_for_server_parameter(self.api, server,
90+
self._wait_for_server_parameter(server,
9191
{'OS-EXT-SRV-ATTR:host': dest,
9292
'status': 'ACTIVE'})
9393
self.assertEqual(2, stub_attachment_delete.call_count)

nova/tests/functional/integrated_helpers.py

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,14 @@ def generate_new_element(items, prefix, numeric=False):
7373

7474

7575
class InstanceHelperMixin(object):
76-
def _wait_for_server_parameter(self, admin_api, server, expected_params,
77-
max_retries=10):
76+
77+
def _wait_for_server_parameter(
78+
self, server, expected_params, max_retries=10, api=None):
79+
api = api or getattr(self, 'admin_api', self.api)
80+
7881
retry_count = 0
7982
while True:
80-
server = admin_api.get_server(server['id'])
83+
server = api.get_server(server['id'])
8184
if all([server[attr] == expected_params[attr]
8285
for attr in expected_params]):
8386
break
@@ -90,22 +93,21 @@ def _wait_for_server_parameter(self, admin_api, server, expected_params,
9093

9194
return server
9295

93-
def _wait_for_state_change(self, admin_api, server, expected_status,
94-
max_retries=10):
96+
def _wait_for_state_change(self, server, expected_status, max_retries=10):
9597
return self._wait_for_server_parameter(
96-
admin_api, server, {'status': expected_status}, max_retries)
98+
server, {'status': expected_status}, max_retries)
99+
100+
def _build_minimal_create_server_request(
101+
self, name=None, image_uuid=None, flavor_id=None, networks=None,
102+
az=None, host=None):
97103

98-
def _build_minimal_create_server_request(self, api, name=None,
99-
image_uuid=None, flavor_id=None,
100-
networks=None, az=None,
101-
host=None):
102104
server = {}
103105

104106
if not image_uuid:
105107
# NOTE(takashin): In API version 2.36, image APIs were deprecated.
106108
# In API version 2.36 or greater, self.api.get_images() returns
107109
# a 404 error. In that case, 'image_uuid' should be specified.
108-
image_uuid = api.get_images()[0]['id']
110+
image_uuid = self.api.get_images()[0]['id']
109111
server['imageRef'] = image_uuid
110112

111113
if not name:
@@ -115,7 +117,7 @@ def _build_minimal_create_server_request(self, api, name=None,
115117

116118
if not flavor_id:
117119
# Set a valid flavorId
118-
flavor_id = api.get_flavors()[0]['id']
120+
flavor_id = self.api.get_flavors()[0]['id']
119121
server['flavorRef'] = 'http://fake.server/%s' % flavor_id
120122

121123
if networks is not None:
@@ -142,40 +144,43 @@ def _wait_until_deleted(self, server):
142144
return
143145

144146
def _wait_for_action_fail_completion(
145-
self, server, expected_action, event_name, api=None):
147+
self, server, expected_action, event_name):
146148
"""Polls instance action events for the given instance, action and
147149
action event name until it finds the action event with an error
148150
result.
149151
"""
150-
if api is None:
151-
api = self.api
152152
return self._wait_for_instance_action_event(
153-
api, server, expected_action, event_name, event_result='error')
153+
server, expected_action, event_name, event_result='error')
154154

155155
def _wait_for_instance_action_event(
156-
self, api, server, action_name, event_name, event_result):
156+
self, server, action_name, event_name, event_result):
157157
"""Polls the instance action events for the given instance, action,
158158
event, and event result until it finds the event.
159159
"""
160+
api = getattr(self, 'admin_api', self.api)
161+
160162
actions = []
161163
events = []
162164
for attempt in range(10):
163165
actions = api.get_instance_actions(server['id'])
164166
# The API returns the newest event first
165167
for action in actions:
166-
if action['action'] == action_name:
167-
events = (
168-
api.api_get(
169-
'/servers/%s/os-instance-actions/%s' %
170-
(server['id'], action['request_id'])
171-
).body['instanceAction']['events'])
172-
# Look for the action event being in error state.
173-
for event in events:
174-
result = event['result']
175-
if (event['event'] == event_name and
176-
result is not None and
177-
result.lower() == event_result.lower()):
178-
return event
168+
if action['action'] != action_name:
169+
continue
170+
171+
events = api.api_get(
172+
'/servers/%s/os-instance-actions/%s' % (
173+
server['id'], action['request_id'])
174+
).body['instanceAction']['events']
175+
176+
# Look for the action event being in error state.
177+
for event in events:
178+
result = event['result']
179+
if (event['event'] == event_name and
180+
result is not None and
181+
result.lower() == event_result.lower()):
182+
return event
183+
179184
# We didn't find the completion event yet, so wait a bit.
180185
time.sleep(0.5)
181186

@@ -192,19 +197,16 @@ def _assert_resize_migrate_action_fail(self, server, action, error_in_tb):
192197
:param action: Either "resize" or "migrate" instance action.
193198
:param error_in_tb: Some expected part of the error event traceback.
194199
"""
195-
api = self.admin_api if hasattr(self, 'admin_api') else self.api
196200
event = self._wait_for_action_fail_completion(
197-
server, action, 'conductor_migrate_server', api=api)
201+
server, action, 'conductor_migrate_server')
198202
self.assertIn(error_in_tb, event['traceback'])
199203

200204
def _wait_for_migration_status(self, server, expected_statuses):
201205
"""Waits for a migration record with the given statuses to be found
202206
for the given server, else the test fails. The migration record, if
203207
found, is returned.
204208
"""
205-
api = getattr(self, 'admin_api', None)
206-
if api is None:
207-
api = self.api
209+
api = getattr(self, 'admin_api', self.api)
208210

209211
statuses = [status.lower() for status in expected_statuses]
210212
for attempt in range(10):
@@ -297,10 +299,14 @@ def _setup_services(self):
297299
self.api = self.api_fixture.admin_api
298300
else:
299301
self.api = self.api_fixture.api
302+
self.admin_api = self.api_fixture.admin_api
300303

301304
if hasattr(self, 'microversion'):
302305
self.api.microversion = self.microversion
303306

307+
if not self.ADMIN_API:
308+
self.admin_api.microversion = self.microversion
309+
304310
def get_unused_server_name(self):
305311
servers = self.api.get_servers()
306312
server_names = [server['name'] for server in servers]
@@ -728,14 +734,13 @@ def _boot_and_check_allocations(
728734
:return: the API representation of the booted instance
729735
"""
730736
server_req = self._build_minimal_create_server_request(
731-
self.api, 'some-server', flavor_id=flavor['id'],
737+
'some-server', flavor_id=flavor['id'],
732738
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
733739
networks=networks)
734740
server_req['availability_zone'] = 'nova:%s' % source_hostname
735741
LOG.info('booting on %s', source_hostname)
736742
created_server = self.api.post_server({'server': server_req})
737-
server = self._wait_for_state_change(
738-
self.admin_api, created_server, 'ACTIVE')
743+
server = self._wait_for_state_change(created_server, 'ACTIVE')
739744

740745
# Verify that our source host is what the server ended up on
741746
self.assertEqual(source_hostname, server['OS-EXT-SRV-ATTR:host'])
@@ -849,7 +854,7 @@ class redefined this function to force a specific order.
849854
def _move_and_check_allocations(self, server, request, old_flavor,
850855
new_flavor, source_rp_uuid, dest_rp_uuid):
851856
self.api.post_server_action(server['id'], request)
852-
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
857+
self._wait_for_state_change(server, 'VERIFY_RESIZE')
853858

854859
def _check_allocation():
855860
self.assertFlavorMatchesUsage(source_rp_uuid, old_flavor)
@@ -911,7 +916,7 @@ def _resize_to_same_host_and_check_allocations(self, server, old_flavor,
911916
}
912917
}
913918
self.api.post_server_action(server['id'], resize_req)
914-
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
919+
self._wait_for_state_change(server, 'VERIFY_RESIZE')
915920

916921
self.assertFlavorMatchesUsage(rp_uuid, old_flavor, new_flavor)
917922

@@ -981,15 +986,15 @@ def assert_hypervisor_usage(self, compute_node_uuid, flavor,
981986

982987
def _confirm_resize(self, server):
983988
self.api.post_server_action(server['id'], {'confirmResize': None})
984-
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
989+
server = self._wait_for_state_change(server, 'ACTIVE')
985990
self._wait_for_instance_action_event(
986-
self.api, server, instance_actions.CONFIRM_RESIZE,
991+
server, instance_actions.CONFIRM_RESIZE,
987992
'compute_confirm_resize', 'success')
988993
return server
989994

990995
def _revert_resize(self, server):
991996
self.api.post_server_action(server['id'], {'revertResize': None})
992-
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
997+
server = self._wait_for_state_change(server, 'ACTIVE')
993998
self._wait_for_migration_status(server, ['reverted'])
994999
# Note that the migration status is changed to "reverted" in the
9951000
# dest host revert_resize method but the allocations are cleaned up

nova/tests/functional/libvirt/test_shared_resource_provider.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def test_shared_storage_rp_configuration_with_cn_rp(self):
7777
}
7878
# create server
7979
server = self.api.post_server(server_req_body)
80-
self._wait_for_state_change(self.api, server, 'ACTIVE')
80+
self._wait_for_state_change(server, 'ACTIVE')
8181

8282
# get shared_rp and cn_rp usages
8383
shared_rp_usages = self._get_provider_usages(shared_RP['uuid'])
@@ -135,7 +135,7 @@ def test_rebuild_instance_with_image_traits_on_shared_rp(self):
135135
}
136136
# create server
137137
server = self.api.post_server(server_req_body)
138-
self._wait_for_state_change(self.api, server, 'ACTIVE')
138+
self._wait_for_state_change(server, 'ACTIVE')
139139

140140
rebuild_image_ref = (
141141
nova.tests.unit.image.fake.AUTO_DISK_CONFIG_ENABLED_IMAGE_UUID)
@@ -152,7 +152,7 @@ def test_rebuild_instance_with_image_traits_on_shared_rp(self):
152152
self.api.api_post('/servers/%s/action' % server['id'],
153153
rebuild_req_body)
154154
self._wait_for_server_parameter(
155-
self.api, server, {'OS-EXT-STS:task_state': None})
155+
server, {'OS-EXT-STS:task_state': None})
156156

157157
# get shared_rp and cn_rp usages
158158
shared_rp_usages = self._get_provider_usages(shared_rp_uuid)
@@ -198,7 +198,7 @@ def test_rebuild_instance_with_image_traits_on_shared_rp_no_valid_host(
198198
}
199199
# create server
200200
server = self.api.post_server(server_req_body)
201-
self._wait_for_state_change(self.api, server, 'ACTIVE')
201+
self._wait_for_state_change(server, 'ACTIVE')
202202

203203
rebuild_image_ref = (
204204
nova.tests.unit.image.fake.AUTO_DISK_CONFIG_ENABLED_IMAGE_UUID)
@@ -216,7 +216,7 @@ def test_rebuild_instance_with_image_traits_on_shared_rp_no_valid_host(
216216
rebuild_req_body)
217217
# Look for the failed rebuild action.
218218
self._wait_for_action_fail_completion(
219-
server, instance_actions.REBUILD, 'rebuild_server', self.admin_api)
219+
server, instance_actions.REBUILD, 'rebuild_server')
220220
# Assert the server image_ref was rolled back on failure.
221221
server = self.api.get_server(server['id'])
222222
self.assertEqual(org_image_id, server['image']['id'])

0 commit comments

Comments
 (0)