Merge "functional: Remove 'api' parameter"

This commit is contained in:
Zuul 2019-12-12 13:37:05 +00:00 committed by Gerrit Code Review
commit 2e7a0088c2
65 changed files with 449 additions and 519 deletions

View File

@ -34,7 +34,7 @@ class ServerActionsSampleJsonTest(test_servers.ServersSampleBase,
response_data = api_samples_test_base.pretty_data(response.content)
actions = api_samples_test_base.objectify(response_data)
self.action_stop = actions['instanceActions'][0]
self._wait_for_state_change(self.api, {'id': self.uuid}, 'SHUTOFF')
self._wait_for_state_change({'id': self.uuid}, 'SHUTOFF')
def _get_subs(self):
return {

View File

@ -32,14 +32,14 @@ class MultinicSampleJsonTest(integrated_helpers.InstanceHelperMixin,
def _boot_a_server(self, expected_status='ACTIVE', extra_params=None):
server = self._build_minimal_create_server_request(
self.api, 'MultinicSampleJsonTestServer')
'MultinicSampleJsonTestServer')
if extra_params:
server.update(extra_params)
created_server = self.api.post_server({'server': server})
# Wait for it to finish being created
found_server = self._wait_for_state_change(self.api, created_server,
found_server = self._wait_for_state_change(created_server,
expected_status)
return found_server

View File

@ -40,10 +40,10 @@ class ComputeManagerInitHostTestCase(
# Create a server, it does not matter on which host it lands.
name = 'test_migrate_disk_and_power_off_crash_finish_revert_migration'
server = self._build_minimal_create_server_request(
self.api, name, image_uuid=fake_image.get_valid_image_id(),
name, image_uuid=fake_image.get_valid_image_id(),
networks='auto')
server = self.api.post_server({'server': server})
server = self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
# Save the source hostname for assertions later.
source_host = server['OS-EXT-SRV-ATTR:host']
@ -66,8 +66,7 @@ class ComputeManagerInitHostTestCase(
self.admin_api.post_server_action(server['id'], {'migrate': None})
# Now wait for the task_state to be reset to None during
# _init_instance.
server = self._wait_for_server_parameter(
self.admin_api, server, {
server = self._wait_for_server_parameter(server, {
'status': 'ACTIVE',
'OS-EXT-STS:task_state': None,
'OS-EXT-SRV-ATTR:host': source_host
@ -158,7 +157,7 @@ class TestComputeRestartInstanceStuckInBuild(
# instance_claim() to stop it. This is less realistic but it works in
# the test env.
server_req = self._build_minimal_create_server_request(
self.api, 'interrupted-server', flavor_id=self.flavor1['id'],
'interrupted-server', flavor_id=self.flavor1['id'],
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks='none')
@ -170,7 +169,7 @@ class TestComputeRestartInstanceStuckInBuild(
mock_instance_claim.side_effect = sleep_forever
server = self.api.post_server({'server': server_req})
self._wait_for_state_change(self.admin_api, server, 'BUILD')
self._wait_for_state_change(server, 'BUILD')
# the instance.create.start is the closest thing to the
# instance_claim call we can wait for in the test
@ -182,7 +181,7 @@ class TestComputeRestartInstanceStuckInBuild(
# We expect that the instance is pushed to ERROR state during the
# compute restart.
self._wait_for_state_change(self.admin_api, server, 'ERROR')
self._wait_for_state_change(server, 'ERROR')
mock_log.assert_called_with(
'Instance spawn was interrupted before instance_claim, setting '
'instance to ERROR state',

View File

@ -69,7 +69,7 @@ class LiveMigrationCinderFailure(integrated_helpers._IntegratedTestBase,
'uuid': uuids.working_volume,
'source_type': 'volume',
'destination_type': 'volume'}]}})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
source = server['OS-EXT-SRV-ATTR:host']
if source == self.compute.host:
@ -87,7 +87,7 @@ class LiveMigrationCinderFailure(integrated_helpers._IntegratedTestBase,
self.stub_out('nova.volume.cinder.API.attachment_delete',
stub_attachment_delete)
self.api.post_server_action(server['id'], post)
self._wait_for_server_parameter(self.api, server,
self._wait_for_server_parameter(server,
{'OS-EXT-SRV-ATTR:host': dest,
'status': 'ACTIVE'})
self.assertEqual(2, stub_attachment_delete.call_count)

View File

@ -73,11 +73,14 @@ def generate_new_element(items, prefix, numeric=False):
class InstanceHelperMixin(object):
def _wait_for_server_parameter(self, admin_api, server, expected_params,
max_retries=10):
def _wait_for_server_parameter(
self, server, expected_params, max_retries=10, api=None):
api = api or getattr(self, 'admin_api', self.api)
retry_count = 0
while True:
server = admin_api.get_server(server['id'])
server = api.get_server(server['id'])
if all([server[attr] == expected_params[attr]
for attr in expected_params]):
break
@ -90,22 +93,21 @@ class InstanceHelperMixin(object):
return server
def _wait_for_state_change(self, admin_api, server, expected_status,
max_retries=10):
def _wait_for_state_change(self, server, expected_status, max_retries=10):
return self._wait_for_server_parameter(
admin_api, server, {'status': expected_status}, max_retries)
server, {'status': expected_status}, max_retries)
def _build_minimal_create_server_request(
self, name=None, image_uuid=None, flavor_id=None, networks=None,
az=None, host=None):
def _build_minimal_create_server_request(self, api, name=None,
image_uuid=None, flavor_id=None,
networks=None, az=None,
host=None):
server = {}
if not image_uuid:
# NOTE(takashin): In API version 2.36, image APIs were deprecated.
# In API version 2.36 or greater, self.api.get_images() returns
# a 404 error. In that case, 'image_uuid' should be specified.
image_uuid = api.get_images()[0]['id']
image_uuid = self.api.get_images()[0]['id']
server['imageRef'] = image_uuid
if not name:
@ -115,7 +117,7 @@ class InstanceHelperMixin(object):
if not flavor_id:
# Set a valid flavorId
flavor_id = api.get_flavors()[0]['id']
flavor_id = self.api.get_flavors()[0]['id']
server['flavorRef'] = 'http://fake.server/%s' % flavor_id
if networks is not None:
@ -142,40 +144,43 @@ class InstanceHelperMixin(object):
return
def _wait_for_action_fail_completion(
self, server, expected_action, event_name, api=None):
self, server, expected_action, event_name):
"""Polls instance action events for the given instance, action and
action event name until it finds the action event with an error
result.
"""
if api is None:
api = self.api
return self._wait_for_instance_action_event(
api, server, expected_action, event_name, event_result='error')
server, expected_action, event_name, event_result='error')
def _wait_for_instance_action_event(
self, api, server, action_name, event_name, event_result):
self, server, action_name, event_name, event_result):
"""Polls the instance action events for the given instance, action,
event, and event result until it finds the event.
"""
api = getattr(self, 'admin_api', self.api)
actions = []
events = []
for attempt in range(10):
actions = api.get_instance_actions(server['id'])
# The API returns the newest event first
for action in actions:
if action['action'] == action_name:
events = (
api.api_get(
'/servers/%s/os-instance-actions/%s' %
(server['id'], action['request_id'])
).body['instanceAction']['events'])
# Look for the action event being in error state.
for event in events:
result = event['result']
if (event['event'] == event_name and
result is not None and
result.lower() == event_result.lower()):
return event
if action['action'] != action_name:
continue
events = api.api_get(
'/servers/%s/os-instance-actions/%s' % (
server['id'], action['request_id'])
).body['instanceAction']['events']
# Look for the action event being in error state.
for event in events:
result = event['result']
if (event['event'] == event_name and
result is not None and
result.lower() == event_result.lower()):
return event
# We didn't find the completion event yet, so wait a bit.
time.sleep(0.5)
@ -192,9 +197,8 @@ class InstanceHelperMixin(object):
:param action: Either "resize" or "migrate" instance action.
:param error_in_tb: Some expected part of the error event traceback.
"""
api = self.admin_api if hasattr(self, 'admin_api') else self.api
event = self._wait_for_action_fail_completion(
server, action, 'conductor_migrate_server', api=api)
server, action, 'conductor_migrate_server')
self.assertIn(error_in_tb, event['traceback'])
def _wait_for_migration_status(self, server, expected_statuses):
@ -202,9 +206,7 @@ class InstanceHelperMixin(object):
for the given server, else the test fails. The migration record, if
found, is returned.
"""
api = getattr(self, 'admin_api', None)
if api is None:
api = self.api
api = getattr(self, 'admin_api', self.api)
statuses = [status.lower() for status in expected_statuses]
for attempt in range(10):
@ -297,10 +299,14 @@ class _IntegratedTestBase(test.TestCase):
self.api = self.api_fixture.admin_api
else:
self.api = self.api_fixture.api
self.admin_api = self.api_fixture.admin_api
if hasattr(self, 'microversion'):
self.api.microversion = self.microversion
if not self.ADMIN_API:
self.admin_api.microversion = self.microversion
def get_unused_server_name(self):
servers = self.api.get_servers()
server_names = [server['name'] for server in servers]
@ -728,14 +734,13 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
:return: the API representation of the booted instance
"""
server_req = self._build_minimal_create_server_request(
self.api, 'some-server', flavor_id=flavor['id'],
'some-server', flavor_id=flavor['id'],
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks=networks)
server_req['availability_zone'] = 'nova:%s' % source_hostname
LOG.info('booting on %s', source_hostname)
created_server = self.api.post_server({'server': server_req})
server = self._wait_for_state_change(
self.admin_api, created_server, 'ACTIVE')
server = self._wait_for_state_change(created_server, 'ACTIVE')
# Verify that our source host is what the server ended up on
self.assertEqual(source_hostname, server['OS-EXT-SRV-ATTR:host'])
@ -849,7 +854,7 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
def _move_and_check_allocations(self, server, request, old_flavor,
new_flavor, source_rp_uuid, dest_rp_uuid):
self.api.post_server_action(server['id'], request)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
def _check_allocation():
self.assertFlavorMatchesUsage(source_rp_uuid, old_flavor)
@ -911,7 +916,7 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
}
}
self.api.post_server_action(server['id'], resize_req)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
self.assertFlavorMatchesUsage(rp_uuid, old_flavor, new_flavor)
@ -981,15 +986,15 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
def _confirm_resize(self, server):
self.api.post_server_action(server['id'], {'confirmResize': None})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
self._wait_for_instance_action_event(
self.api, server, instance_actions.CONFIRM_RESIZE,
server, instance_actions.CONFIRM_RESIZE,
'compute_confirm_resize', 'success')
return server
def _revert_resize(self, server):
self.api.post_server_action(server['id'], {'revertResize': None})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
self._wait_for_migration_status(server, ['reverted'])
# Note that the migration status is changed to "reverted" in the
# dest host revert_resize method but the allocations are cleaned up

View File

@ -77,7 +77,7 @@ class SharedStorageProviderUsageTestCase(
}
# create server
server = self.api.post_server(server_req_body)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
# get shared_rp and cn_rp usages
shared_rp_usages = self._get_provider_usages(shared_RP['uuid'])
@ -135,7 +135,7 @@ class SharedStorageProviderUsageTestCase(
}
# create server
server = self.api.post_server(server_req_body)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
rebuild_image_ref = (
nova.tests.unit.image.fake.AUTO_DISK_CONFIG_ENABLED_IMAGE_UUID)
@ -152,7 +152,7 @@ class SharedStorageProviderUsageTestCase(
self.api.api_post('/servers/%s/action' % server['id'],
rebuild_req_body)
self._wait_for_server_parameter(
self.api, server, {'OS-EXT-STS:task_state': None})
server, {'OS-EXT-STS:task_state': None})
# get shared_rp and cn_rp usages
shared_rp_usages = self._get_provider_usages(shared_rp_uuid)
@ -198,7 +198,7 @@ class SharedStorageProviderUsageTestCase(
}
# create server
server = self.api.post_server(server_req_body)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
rebuild_image_ref = (
nova.tests.unit.image.fake.AUTO_DISK_CONFIG_ENABLED_IMAGE_UUID)
@ -216,7 +216,7 @@ class SharedStorageProviderUsageTestCase(
rebuild_req_body)
# Look for the failed rebuild action.
self._wait_for_action_fail_completion(
server, instance_actions.REBUILD, 'rebuild_server', self.admin_api)
server, instance_actions.REBUILD, 'rebuild_server')
# Assert the server image_ref was rolled back on failure.
server = self.api.get_server(server['id'])
self.assertEqual(org_image_id, server['image']['id'])

View File

@ -126,7 +126,7 @@ class VPMEMTestBase(integrated_helpers.LibvirtProviderUsageBaseTestCase):
def _create_server(self, flavor_id, hostname):
server_req = self._build_minimal_create_server_request(
self.api, 'some-server', flavor_id=flavor_id,
'some-server', flavor_id=flavor_id,
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks='none')
server_req['availability_zone'] = 'nova:%s' % hostname
@ -173,22 +173,22 @@ class VPMEMTests(VPMEMTestBase):
# Boot two servers with pmem
server1 = self._create_server(self.flavor, self.compute1.host)
self._wait_for_state_change(self.api, server1, 'ACTIVE')
self._wait_for_state_change(server1, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server1['id'], cn1_uuid)
server2 = self._create_server(self.flavor, self.compute1.host)
self._wait_for_state_change(self.api, server2, 'ACTIVE')
self._wait_for_state_change(server2, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server2['id'], cn1_uuid)
# 'SMALL' VPMEM resource has used up
server3 = self._create_server(self.flavor, self.compute1.host)
self._wait_for_state_change(self.api, server3, 'ERROR')
self._wait_for_state_change(server3, 'ERROR')
# Delete server2, one 'SMALL' VPMEM will be released
self._delete_server(server2)
server3 = self._create_server(self.flavor, self.compute1.host)
self._wait_for_state_change(self.api, server3, 'ACTIVE')
self._wait_for_state_change(server3, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server3['id'], cn1_uuid)
@ -237,29 +237,29 @@ class VPMEMResizeTests(VPMEMTestBase):
# Boot one server with pmem, then resize the server
server = self._create_server(self.flavor1, self.compute1.host)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn1_uuid)
# Revert resize
self._resize_server(server, self.flavor2)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_4GB': 1,
'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn2_uuid)
self._revert_resize(server)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn1_uuid)
# Confirm resize
self._resize_server(server, self.flavor2)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_4GB': 1,
'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn2_uuid)
self._confirm_resize(server)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_4GB': 1,
'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn2_uuid)
@ -272,29 +272,29 @@ class VPMEMResizeTests(VPMEMTestBase):
# Boot one server with pmem, then resize the server
server = self._create_server(self.flavor1, self.compute1.host)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn1_uuid)
# Revert resize
self._resize_server(server, self.flavor2)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_4GB': 1,
'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn1_uuid)
self._revert_resize(server)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn1_uuid)
# Confirm resize
self._resize_server(server, self.flavor2)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_4GB': 1,
'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn1_uuid)
self._confirm_resize(server)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._check_vpmem_allocations({'CUSTOM_PMEM_NAMESPACE_4GB': 1,
'CUSTOM_PMEM_NAMESPACE_SMALL': 1},
server['id'], cn1_uuid)

View File

@ -220,7 +220,7 @@ class NotificationSampleTestBase(test.TestCase,
actual=fake_notifier.VERSIONED_NOTIFICATIONS.pop(0))
server = self._build_minimal_create_server_request(
self.api, 'some-server',
'some-server',
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
flavor_id=flavor_id)
@ -246,7 +246,7 @@ class NotificationSampleTestBase(test.TestCase,
self.assertTrue(created_server['id'])
# Wait for it to finish being created
found_server = self._wait_for_state_change(self.api, created_server,
found_server = self._wait_for_state_change(created_server,
expected_status)
found_server['reservation_id'] = reservation_id

View File

@ -59,7 +59,7 @@ class TestInstanceNotificationSampleWithMultipleCompute(
fake_notifier.reset()
action(server)
# Ensure that instance is in active state after an action
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
@mock.patch('nova.compute.manager.ComputeManager.'
'_live_migration_cleanup_flags', return_value=[True, False])
@ -188,13 +188,13 @@ class TestInstanceNotificationSampleWithMultipleCompute(
}
self.admin_api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, 'MIGRATING')
self._wait_for_state_change(server, 'MIGRATING')
migrations = self._wait_and_get_migrations(server)
self.admin_api.delete_migration(server['id'], migrations[0]['id'])
self._wait_for_notification('instance.live_migration_abort.start')
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
# NOTE(gibi): the intance.live_migration_rollback notification emitted
# after the instance.live_migration_abort notification so we have to
# wait for the rollback to ensure we can assert both notifications
@ -261,10 +261,8 @@ class TestInstanceNotificationSampleWithMultipleCompute(
}
self.admin_api.post_server_action(server['id'], evacuate)
self._wait_for_state_change(self.api, server,
expected_status='REBUILD')
self._wait_for_state_change(self.api, server,
expected_status='ACTIVE')
self._wait_for_state_change(server, expected_status='REBUILD')
self._wait_for_state_change(server, expected_status='ACTIVE')
notifications = self._get_notifications('instance.evacuate')
self.assertEqual(1, len(notifications),
@ -286,7 +284,7 @@ class TestInstanceNotificationSampleWithMultipleCompute(
}
self.admin_api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, 'MIGRATING')
self._wait_for_state_change(server, 'MIGRATING')
migrations = self._wait_and_get_migrations(server)
migration_id = migrations[0]['id']
@ -390,7 +388,7 @@ class TestInstanceNotificationSample(
fake_notifier.reset()
action(server)
# Ensure that instance is in active state after an action
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
# if the test step did not raised then we consider the step as
# succeeded. We drop the logs to avoid causing subunit parser
@ -520,10 +518,8 @@ class TestInstanceNotificationSample(
}
}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server,
expected_status='REBUILD')
self._wait_for_state_change(self.api, server,
expected_status='ACTIVE')
self._wait_for_state_change(server, expected_status='REBUILD')
self._wait_for_state_change(server, expected_status='ACTIVE')
notifications = self._get_notifications('instance.exists')
self._verify_notification(
@ -751,11 +747,9 @@ class TestInstanceNotificationSample(
def _test_power_off_on_server(self, server):
self.api.post_server_action(server['id'], {'os-stop': {}})
self._wait_for_state_change(self.api, server,
expected_status='SHUTOFF')
self._wait_for_state_change(server, expected_status='SHUTOFF')
self.api.post_server_action(server['id'], {'os-start': {}})
self._wait_for_state_change(self.api, server,
expected_status='ACTIVE')
self._wait_for_state_change(server, expected_status='ACTIVE')
self.assertEqual(4, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -788,8 +782,7 @@ class TestInstanceNotificationSample(
def _test_shelve_and_shelve_offload_server(self, server):
self.flags(shelved_offload_time=-1)
self.api.post_server_action(server['id'], {'shelve': {}})
self._wait_for_state_change(self.api, server,
expected_status='SHELVED')
self._wait_for_state_change(server, expected_status='SHELVED')
self.assertEqual(3, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -812,7 +805,7 @@ class TestInstanceNotificationSample(
# we can unshelve to make sure that the unshelve.start notification
# payload is stable as the compute manager first sets the instance
# state then a bit later sets the instance.host to None.
self._wait_for_server_parameter(self.api, server,
self._wait_for_server_parameter(server,
{'status': 'SHELVED_OFFLOADED',
'OS-EXT-SRV-ATTR:host': None})
@ -832,7 +825,7 @@ class TestInstanceNotificationSample(
actual=fake_notifier.VERSIONED_NOTIFICATIONS[1])
self.api.post_server_action(server['id'], {'unshelve': None})
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._wait_for_notification('instance.unshelve.end')
def _test_unshelve_server(self, server):
@ -844,13 +837,13 @@ class TestInstanceNotificationSample(
# we can unshelve to make sure that the unshelve.start notification
# payload is stable as the compute manager first sets the instance
# state then a bit later sets the instance.host to None.
self._wait_for_server_parameter(self.api, server,
self._wait_for_server_parameter(server,
{'status': 'SHELVED_OFFLOADED',
'OS-EXT-SRV-ATTR:host': None})
post = {'unshelve': None}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self._wait_for_notification('instance.unshelve.end')
self.assertEqual(9, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -870,11 +863,11 @@ class TestInstanceNotificationSample(
def _test_suspend_resume_server(self, server):
post = {'suspend': {}}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.admin_api, server, 'SUSPENDED')
self._wait_for_state_change(server, 'SUSPENDED')
post = {'resume': None}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
# Four versioned notification are generated.
# 0. instance-suspend-start
@ -913,10 +906,10 @@ class TestInstanceNotificationSample(
def _test_pause_unpause_server(self, server):
self.api.post_server_action(server['id'], {'pause': {}})
self._wait_for_state_change(self.api, server, 'PAUSED')
self._wait_for_state_change(server, 'PAUSED')
self.api.post_server_action(server['id'], {'unpause': {}})
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
# Four versioned notifications are generated
# 0. instance-pause-start
@ -997,7 +990,7 @@ class TestInstanceNotificationSample(
}
}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
self._pop_and_verify_dest_select_notification(server['id'],
replacements={
@ -1034,7 +1027,7 @@ class TestInstanceNotificationSample(
# the following is the revert server request
post = {'revertResize': None}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self.assertEqual(3, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -1170,7 +1163,7 @@ class TestInstanceNotificationSample(
self.addCleanup(patcher.stop)
patcher.start()
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, expected_status='ERROR')
self._wait_for_state_change(server, expected_status='ERROR')
self._wait_for_notification('compute.exception')
# There should be the following notifications after scheduler's
# select_destination notifications:
@ -1248,10 +1241,8 @@ class TestInstanceNotificationSample(
self.api.post_server_action(server['id'], post)
# Before going back to ACTIVE state
# server state need to be changed to REBUILD state
self._wait_for_state_change(self.api, server,
expected_status='REBUILD')
self._wait_for_state_change(self.api, server,
expected_status='ACTIVE')
self._wait_for_state_change(server, expected_status='REBUILD')
self._wait_for_state_change(server, expected_status='ACTIVE')
self._pop_and_verify_dest_select_notification(server['id'],
replacements={
@ -1345,10 +1336,8 @@ class TestInstanceNotificationSample(
self.api.post_server_action(server['id'], post)
# Before going back to ACTIVE state
# server state need to be changed to REBUILD state
self._wait_for_state_change(self.api, server,
expected_status='REBUILD')
self._wait_for_state_change(self.api, server,
expected_status='ACTIVE')
self._wait_for_state_change(server, expected_status='REBUILD')
self._wait_for_state_change(server, expected_status='ACTIVE')
self._pop_and_verify_dest_select_notification(server['id'],
replacements={
@ -1434,7 +1423,7 @@ class TestInstanceNotificationSample(
}
self.api.post_server_action(server['id'], post)
mock_rebuild.side_effect = _virtual_interface_create_failed
self._wait_for_state_change(self.api, server, expected_status='ERROR')
self._wait_for_state_change(server, expected_status='ERROR')
notification = self._get_notifications('instance.rebuild.error')
self.assertEqual(1, len(notification),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -1455,11 +1444,11 @@ class TestInstanceNotificationSample(
def _test_restore_server(self, server):
self.flags(reclaim_instance_interval=30)
self.api.delete_server(server['id'])
self._wait_for_state_change(self.api, server, 'SOFT_DELETED')
self._wait_for_state_change(server, 'SOFT_DELETED')
# we don't want to test soft_delete here
fake_notifier.reset()
self.api.post_server_action(server['id'], {'restore': {}})
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -1641,12 +1630,12 @@ class TestInstanceNotificationSample(
self.flags(allow_resize_to_same_host=True)
post = {'resize': {'flavorRef': '2'}}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
self._wait_for_state_change(server, 'VERIFY_RESIZE')
fake_notifier.reset()
post = {'confirmResize': None}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -1733,7 +1722,7 @@ class TestInstanceNotificationSample(
}
}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.admin_api, server, 'RESCUE')
self._wait_for_state_change(server, 'RESCUE')
# 0. instance.rescue.start
# 1. instance.exists
@ -1759,7 +1748,7 @@ class TestInstanceNotificationSample(
'unrescue': None
}
self.api.post_server_action(server['id'], post)
self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -1779,7 +1768,7 @@ class TestInstanceNotificationSample(
def _test_soft_delete_server(self, server):
self.flags(reclaim_instance_interval=30)
self.api.delete_server(server['id'])
self._wait_for_state_change(self.api, server, 'SOFT_DELETED')
self._wait_for_state_change(server, 'SOFT_DELETED')
self.assertEqual(2, len(fake_notifier.VERSIONED_NOTIFICATIONS),
fake_notifier.VERSIONED_NOTIFICATIONS)
@ -1948,9 +1937,9 @@ class TestInstanceNotificationSample(
def _test_lock_unlock_instance(self, server):
self.api.post_server_action(server['id'], {'lock': {}})
self._wait_for_server_parameter(self.api, server, {'locked': True})
self._wait_for_server_parameter(server, {'locked': True})
self.api.post_server_action(server['id'], {'unlock': {}})
self._wait_for_server_parameter(self.api, server, {'locked': False})
self._wait_for_server_parameter(server, {'locked': False})
# Two versioned notifications are generated
# 0. instance-lock
# 1. instance-unlock
@ -1973,9 +1962,9 @@ class TestInstanceNotificationSample(
def _test_lock_unlock_instance_with_reason(self, server):
self.api.post_server_action(
server['id'], {'lock': {"locked_reason": "global warming"}})
self._wait_for_server_parameter(self.api, server, {'locked': True})
self._wait_for_server_parameter(server, {'locked': True})
self.api.post_server_action(server['id'], {'unlock': {}})
self._wait_for_server_parameter(self.api, server, {'locked': False})
self._wait_for_server_parameter(server, {'locked': False})
# Two versioned notifications are generated
# 0. instance-lock
# 1. instance-unlock

View File

@ -55,7 +55,7 @@ class DeleteWithReservedVolumes(integrated_helpers._IntegratedTestBase,
]
}
})
return self._wait_for_state_change(self.api, server, 'ERROR')
return self._wait_for_state_change(server, 'ERROR')
def test_delete_with_reserved_volumes_new(self):
self.cinder = self.useFixture(

View File

@ -42,7 +42,7 @@ class ResizeEvacuateTestCase(integrated_helpers._IntegratedTestBase,
flavor1 = flavors[0]['id']
server = self._build_server(flavor1)
server = self.api.post_server({'server': server})
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
# Start up another compute service so we can resize.
host2 = self.start_service('compute', host='host2')
@ -51,10 +51,10 @@ class ResizeEvacuateTestCase(integrated_helpers._IntegratedTestBase,
flavor2 = flavors[1]['id']
req = {'resize': {'flavorRef': flavor2}}
self.api.post_server_action(server['id'], req)
server = self._wait_for_state_change(self.api, server, 'VERIFY_RESIZE')
server = self._wait_for_state_change(server, 'VERIFY_RESIZE')
self.assertEqual('host2', server['OS-EXT-SRV-ATTR:host'])
self.api.post_server_action(server['id'], {'confirmResize': None})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
# Disable the host on which the server is now running (host2).
host2.stop()
@ -62,7 +62,7 @@ class ResizeEvacuateTestCase(integrated_helpers._IntegratedTestBase,
# Now try to evacuate the server back to the original source compute.
req = {'evacuate': {'onSharedStorage': False}}
self.api.post_server_action(server['id'], req)
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
# The evacuate flow in the compute manager is annoying in that it
# sets the instance status to ACTIVE before updating the host, so we
# have to wait for the migration record to be 'done' to avoid a race.

View File

@ -81,10 +81,10 @@ class TestLocalDeleteAllocations(test.TestCase,
self.assertEqual(0, usage)
# Create a server.
server = self._build_minimal_create_server_request(self.api,
server = self._build_minimal_create_server_request(
'local-delete-test', self.image_id, self.flavor_id, 'none')
server = self.admin_api.post_server({'server': server})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
# Assert usages are non zero now.
usages_during = self._get_usages(placement_api, rp_uuid)
@ -136,10 +136,10 @@ class TestLocalDeleteAllocations(test.TestCase,
self.assertEqual(0, usage)
# Create a server.
server = self._build_minimal_create_server_request(self.api,
server = self._build_minimal_create_server_request(
'local-delete-test', self.image_id, self.flavor_id, 'none')
server = self.admin_api.post_server({'server': server})
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
# Assert usages are non zero now.
usages_during = self._get_usages(placement_api, rp_uuid)

View File

@ -59,10 +59,10 @@ class ServerTagsFilteringTest(test.TestCase,
for x in range(2):
server = self.api.post_server(
dict(server=self._build_minimal_create_server_request(
self.api, 'test-list-server-tag-filters%i' % x, image_id,
'test-list-server-tag-filters%i' % x, image_id,
networks='none')))
self.addCleanup(self.api.delete_server, server['id'])
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
self.servers.append(server)
# now apply two tags to the first server

View File

@ -66,10 +66,10 @@ class ServerListLimitMarkerCell0Test(test.TestCase,
for x in range(3):
server = self.api.post_server(
dict(server=self._build_minimal_create_server_request(
self.api, 'test-list-server-limit%i' % x, self.image_id,
'test-list-server-limit%i' % x, self.image_id,
networks='none')))
self.addCleanup(self.api.delete_server, server['id'])
self._wait_for_state_change(self.api, server, 'ERROR')
self._wait_for_state_change(server, 'ERROR')
servers = self.api.get_servers()
self.assertEqual(3, len(servers))

View File

@ -95,11 +95,11 @@ class SchedulerOnlyChecksTargetTest(test.TestCase,
# We first create the instance
server = self.admin_api.post_server(
dict(server=self._build_minimal_create_server_request(
self.api, 'my-pretty-instance-to-evacuate', self.image_id,
'my-pretty-instance-to-evacuate', self.image_id,
networks='none')))
server_id = server['id']
self.addCleanup(self.api.delete_server, server_id)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
# We need to get instance details for knowing its host
server = self.admin_api.get_server(server_id)
@ -125,7 +125,7 @@ class SchedulerOnlyChecksTargetTest(test.TestCase,
}
self.admin_api.post_server_action(server['id'], evacuate)
self._wait_for_state_change(self.api, server, 'ACTIVE')
self._wait_for_state_change(server, 'ACTIVE')
server = self.admin_api.get_server(server_id)
# Yeepee, that works!

View File

@ -84,13 +84,12 @@ class FailedEvacuateStateTests(test.TestCase,
def _boot_a_server(self):
server_req = self._build_minimal_create_server_request(
self.api, 'some-server', flavor_id=self.flavor1['id'],
'some-server', flavor_id=self.flavor1['id'],
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks='none')
LOG.info('booting on %s', self.hostname)
created_server = self.api.post_server({'server': server_req})
return self._wait_for_state_change(
self.api, created_server, 'ACTIVE')
return self._wait_for_state_change(created_server, 'ACTIVE')
def test_evacuate_no_valid_host(self):
# Boot a server
@ -110,7 +109,7 @@ class FailedEvacuateStateTests(test.TestCase,
self._wait_for_notification_event_type('compute_task.rebuild_server')
server = self._wait_for_state_change(self.api, server, 'ERROR')
server = self._wait_for_state_change(server, 'ERROR')
self.assertEqual(self.hostname, server['OS-EXT-SRV-ATTR:host'])
# Check migrations

View File

@ -70,7 +70,7 @@ class TestLiveMigrateOneOfConcurrentlyCreatedInstances(
def _boot_servers(self, num_servers=1):
server_req = self._build_minimal_create_server_request(
self.api, 'some-server', flavor_id=self.flavor1['id'],
'some-server', flavor_id=self.flavor1['id'],
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks='none')
server_req.update({'min_count': str(num_servers),
@ -81,7 +81,7 @@ class TestLiveMigrateOneOfConcurrentlyCreatedInstances(
servers = self.api.get_servers(detail=True,
search_opts={'reservation_id': reservation_id})
for idx, server in enumerate(servers):
servers[idx] = self._wait_for_state_change(self.api, server,
servers[idx] = self._wait_for_state_change(server,
'ACTIVE')
return servers

View File

@ -103,9 +103,9 @@ class TestRequestSpecRetryReschedule(test.TestCase,
# create the instance which should go to host1
server = self.admin_api.post_server(
dict(server=self._build_minimal_create_server_request(
self.api, 'test_resize_with_reschedule_then_live_migrate',
'test_resize_with_reschedule_then_live_migrate',
self.image_id, flavor_id=flavor1['id'], networks='none')))
server = self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
self.assertEqual('host1', server['OS-EXT-SRV-ATTR:host'])
# Stub out the resize to fail on host2, which will trigger a reschedule
@ -116,17 +116,17 @@ class TestRequestSpecRetryReschedule(test.TestCase,
# on host3.
data = {'resize': {'flavorRef': flavor2['id']}}
self.api.post_server_action(server['id'], data)
server = self._wait_for_state_change(self.admin_api, server,
server = self._wait_for_state_change(server,
'VERIFY_RESIZE')
self.assertEqual('host3', server['OS-EXT-SRV-ATTR:host'])
self.api.post_server_action(server['id'], {'confirmResize': None})
server = self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
# Now live migrate the server to host2 specifically, which previously
# failed the resize attempt but here it should pass.
data = {'os-migrateLive': {'host': 'host2', 'block_migration': 'auto'}}
self.admin_api.post_server_action(server['id'], data)
server = self._wait_for_state_change(self.admin_api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
self.assertEqual('host2', server['OS-EXT-SRV-ATTR:host'])
# NOTE(mriedem): The instance status effectively goes to ACTIVE before
# the migration status is changed to "completed" since

View File

@ -104,8 +104,7 @@ class TestRescheduleWithServerGroup(test.TestCase,
hints = {'group': created_group['id']}
created_server = self.api.post_server({'server': server,
'os:scheduler_hints': hints})
found_server = self._wait_for_state_change(self.admin_api,
created_server, 'ACTIVE')
found_server = self._wait_for_state_change(created_server, 'ACTIVE')
# Assert that the host is not the failed host.
self.assertNotEqual(self.failed_host,
found_server['OS-EXT-SRV-ATTR:host'])

View File

@ -64,7 +64,7 @@ class RebuildVolumeBackedSameImage(integrated_helpers._IntegratedTestBase,
}
}
server = self.api.post_server(server_req_body)
server = self._wait_for_state_change(self.api, server, 'ACTIVE')
server = self._wait_for_state_change(server, 'ACTIVE')
# For a volume-backed server, the image ref will be an empty string
# in the server response.
self.assertEqual('', server['image'])

View File

@ -99,13 +99,11 @@ class TestParallelEvacuationWithServerGroup(
hints = {'group': group['id']}
created_server1 = self.api.post_server({'server': server,
'os:scheduler_hints': hints})
server1 = self._wait_for_state_change(self.api,
created_server1, 'ACTIVE')
server1 = self._wait_for_state_change(created_server1, 'ACTIVE')
created_server2 = self.api.post_server({'server': server,
'os:scheduler_hints': hints})
server2 = self._wait_for_state_change(self.api,
created_server2, 'ACTIVE')
server2 = self._wait_for_state_change(created_server2, 'ACTIVE')
# assert that the anti-affinity policy is enforced during the boot
self.assertNotEqual(server1['OS-EXT-SRV-ATTR:host'],
@ -134,9 +132,9 @@ class TestParallelEvacuationWithServerGroup(
fake_notifier.wait_for_versioned_notifications(
'instance.rebuild.start', n_events=1)
server1 = self._wait_for_server_parameter(
self.api, server1, {'OS-EXT-STS:task_state': None})
server1, {'OS-EXT-STS:task_state': None})
server2 = self._wait_for_server_parameter(
self.api, server2, {'OS-EXT-STS:task_state': None})
server2, {'OS-EXT-STS:task_state': None})
# NOTE(gibi): The instance.host set _after_ the instance state and
# tast_state is set back to normal so it is not enough to wait for

View File

@ -48,13 +48,13 @@ class TestServerResizeReschedule(integrated_helpers.ProviderUsageBaseTestCase):
supplied host_list, and does not call the scheduler.
"""
server_req = self._build_minimal_create_server_request(
self.api, 'some-server', flavor_id=self.flavor1['id'],
'some-server', flavor_id=self.flavor1['id'],
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
networks='none')
self.first_attempt = True
created_server = self.api.post_server({'server': server_req})
server = self._wait_for_state_change(self.api, created_server,
server = self._wait_for_state_change(created_server,
'ACTIVE')
actual_prep_resize = compute_manager.ComputeManager._prep_resize
@ -74,7 +74,7 @@ class TestServerResizeReschedule(integrated_helpers.ProviderUsageBaseTestCase):
data = {"resize": {"flavorRef": self.flavor2['id']}}
self.api.post_server_action(server_uuid, data)
server = self._wait_for_state_change(self.api, created_server,
server = self._wait_for_state_change(created_server,
'VERIFY_RESIZE')
self.assertEqual(self.flavor2['name'],
server['flavor']['original_name'])