Browse Source

functional: Make '_wait_for_state_change' behave consistently

Both 'ServersTestBase' and 'InstanceHelperMixin' provide implementations
of '_wait_for_state_change' but they behave differently. The former
waits for an instance to transition *from* the provided state, while the
latter, somewhat more sanely, waits for the transition *to* the provided
state. Switch to using the latter everywhere and make the necessary
changes. Due to class hierarchies, we end up with two nearly identical
implementations but these will be merged in a future change.

Change-Id: I80cdc0a33ec27b1389130c22f9c3a8ff69f6b1a0
Signed-off-by: Stephen Finucane <sfinucan@redhat.com>
changes/80/689180/6
Stephen Finucane 3 weeks ago
parent
commit
431237d2ee
11 changed files with 114 additions and 202 deletions
  1. +1
    -3
      nova/tests/functional/db/test_archive.py
  2. +16
    -44
      nova/tests/functional/libvirt/test_numa_servers.py
  3. +2
    -3
      nova/tests/functional/libvirt/test_pci_sriov_servers.py
  4. +0
    -10
      nova/tests/functional/libvirt/test_reshape.py
  5. +1
    -3
      nova/tests/functional/libvirt/test_rt_servers.py
  6. +24
    -46
      nova/tests/functional/test_aggregates.py
  7. +4
    -8
      nova/tests/functional/test_images.py
  8. +1
    -4
      nova/tests/functional/test_instance_actions.py
  9. +1
    -1
      nova/tests/functional/test_legacy_v2_compatible_wrapper.py
  10. +62
    -76
      nova/tests/functional/test_servers.py
  11. +2
    -4
      nova/tests/functional/wsgi/test_interfaces.py

+ 1
- 3
nova/tests/functional/db/test_archive.py View File

@@ -68,9 +68,7 @@ class TestDatabaseArchive(test_servers.ServersTestBase):
found_server = self.api.get_server(created_server_id)
self.assertEqual(created_server_id, found_server['id'])

found_server = self._wait_for_state_change(found_server, 'BUILD')
# It should be available...
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
return found_server

def test_archive_deleted_rows(self):

+ 16
- 44
nova/tests/functional/libvirt/test_numa_servers.py View File

@@ -103,7 +103,7 @@ class NUMAServersTest(NUMAServersTestBase):
else:
self.assertFalse(self.mock_filter.called)

found_server = self._wait_for_state_change(found_server, 'BUILD')
found_server = self._wait_for_state_change(found_server, end_status)

if expected_usage:
compute_usage = self.placement_api.get(
@@ -111,8 +111,6 @@ class NUMAServersTest(NUMAServersTestBase):
'usages']
self.assertEqual(expected_usage, compute_usage)

self.assertEqual(end_status, found_server['status'])

self.addCleanup(self._delete_server, found_server)
return created_server

@@ -382,9 +380,7 @@ class NUMAServersTest(NUMAServersTestBase):
post = {'server': good_server}

created_server = self.api.post_server(post)
server = self._wait_for_state_change(created_server, 'BUILD')

self.assertEqual('ACTIVE', server['status'])
server = self._wait_for_state_change(created_server, 'ACTIVE')

original_host = server['OS-EXT-SRV-ATTR:host']

@@ -540,14 +536,10 @@ class ReshapeForPCPUsTest(NUMAServersTestBase):
server_req['networks'] = 'auto'

created_server1 = self.api.post_server({'server': server_req})
# _wait_for_state_change waits for the status to go from BUILD which
# should then be ACTIVE.
server1 = self._wait_for_state_change(created_server1, 'BUILD')
self.assertEqual('ACTIVE', server1['status'])
server1 = self._wait_for_state_change(created_server1, 'ACTIVE')

created_server2 = self.api.post_server({'server': server_req})
server2 = self._wait_for_state_change(created_server2, 'BUILD')
self.assertEqual('ACTIVE', server2['status'])
server2 = self._wait_for_state_change(created_server2, 'ACTIVE')

# sanity check usages

@@ -573,21 +565,12 @@ class ReshapeForPCPUsTest(NUMAServersTestBase):

# now initiate the migration process for one of the servers

# FIXME(stephenfin): This is a hack due to the poor behavior of the
# '_wait_for_state_change' implementation here, which doesn't actually
# wait for a transition _to_ a state. I'll be fixing this real soon.
import time
time.sleep(0.5)

with mock.patch('nova.virt.libvirt.driver.LibvirtDriver'
'.migrate_disk_and_power_off', return_value='{}'):
post = {'migrate': None}
self.api.post_server_action(server2['id'], post)

# _wait_for_state_change waits for the status to go from ACTIVE which
# should then be VERIFY_RESIZE.
server2 = self._wait_for_state_change(server2, 'ACTIVE')
self.assertEqual('VERIFY_RESIZE', server2['status'])
server2 = self._wait_for_state_change(server2, 'VERIFY_RESIZE')

# verify that the inventory, usages and allocation are correct before
# the reshape. Note that the value of 8 VCPUs is derived from
@@ -718,8 +701,7 @@ class ReshapeForPCPUsTest(NUMAServersTestBase):
# reshaped tree which should result in PCPU allocations

created_server = self.api.post_server({'server': server_req})
server3 = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', server3['status'])
server3 = self._wait_for_state_change(created_server, 'ACTIVE')

compute_rp_uuid = self.compute_rp_uuids['test_compute0']

@@ -766,7 +748,8 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):
# fixture already stubbed.
self.neutron = self.useFixture(base.LibvirtNeutronFixture(self))

def _test_create_server_with_networks(self, flavor_id, networks):
def _test_create_server_with_networks(self, flavor_id, networks,
end_status='ACTIVE'):
host_info = fakelibvirt.HostInfo(cpu_nodes=2, cpu_sockets=1,
cpu_cores=2, cpu_threads=2,
kB_mem=15740000)
@@ -785,7 +768,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):

found_server = self.api.get_server(created_server['id'])

return self._wait_for_state_change(found_server, 'BUILD')
return self._wait_for_state_change(found_server, end_status)

def test_create_server_with_single_physnet(self):
extra_spec = {'hw:numa_nodes': '1'}
@@ -794,11 +777,9 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):
{'uuid': base.LibvirtNeutronFixture.network_1['id']},
]

status = self._test_create_server_with_networks(
flavor_id, networks)['status']
self._test_create_server_with_networks(flavor_id, networks)

self.assertTrue(self.mock_filter.called)
self.assertEqual('ACTIVE', status)

def test_create_server_with_multiple_physnets(self):
"""Test multiple networks split across host NUMA nodes.
@@ -814,11 +795,9 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):
{'uuid': base.LibvirtNeutronFixture.network_2['id']},
]

status = self._test_create_server_with_networks(
flavor_id, networks)['status']
self._test_create_server_with_networks(flavor_id, networks)

self.assertTrue(self.mock_filter.called)
self.assertEqual('ACTIVE', status)

def test_create_server_with_multiple_physnets_fail(self):
"""Test multiple networks split across host NUMA nodes.
@@ -833,11 +812,10 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):
{'uuid': base.LibvirtNeutronFixture.network_2['id']},
]

status = self._test_create_server_with_networks(
flavor_id, networks)['status']
self._test_create_server_with_networks(flavor_id, networks,
end_status='ERROR')

self.assertTrue(self.mock_filter.called)
self.assertEqual('ERROR', status)

def test_create_server_with_physnet_and_tunneled_net(self):
"""Test combination of physnet and tunneled network.
@@ -852,11 +830,9 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):
{'uuid': base.LibvirtNeutronFixture.network_3['id']},
]

status = self._test_create_server_with_networks(
flavor_id, networks)['status']
self._test_create_server_with_networks(flavor_id, networks)

self.assertTrue(self.mock_filter.called)
self.assertEqual('ACTIVE', status)

def test_rebuild_server_with_network_affinity(self):
extra_spec = {'hw:numa_nodes': '1'}
@@ -867,8 +843,6 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):

server = self._test_create_server_with_networks(flavor_id, networks)

self.assertEqual('ACTIVE', server['status'])

# attach an interface from the **same** network
post = {
'interfaceAttachment': {
@@ -884,8 +858,7 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):
# This should succeed since we haven't changed the NUMA affinity
# requirements
self.api.post_server_action(server['id'], post)
found_server = self._wait_for_state_change(server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
self._wait_for_state_change(server, 'ACTIVE')

# attach an interface from a **different** network
post = {
@@ -924,9 +897,8 @@ class NUMAServersWithNetworksTest(NUMAServersTestBase):
post = {'server': good_server}

created_server = self.api.post_server(post)
server = self._wait_for_state_change(created_server, 'BUILD')
server = self._wait_for_state_change(created_server, 'ACTIVE')

self.assertEqual('ACTIVE', server['status'])
original_host = server['OS-EXT-SRV-ATTR:host']

# We reset mock_filter because we want to ensure it's called as part of

+ 2
- 3
nova/tests/functional/libvirt/test_pci_sriov_servers.py View File

@@ -77,9 +77,8 @@ class _PCIServersTestBase(base.ServersTestBase):
# Validate that PciPassthroughFilter has been called
self.assertTrue(self.mock_filter.called)

found_server = self._wait_for_state_change(found_server, 'BUILD')
found_server = self._wait_for_state_change(found_server, end_status)

self.assertEqual(end_status, found_server['status'])
self.addCleanup(self._delete_server, found_server)
return created_server

@@ -246,7 +245,7 @@ class GetServerDiagnosticsServerWithVfTestV21(_PCIServersTestBase):

post = {'server': good_server}
created_server = self.api.post_server(post)
self._wait_for_state_change(created_server, 'BUILD')
self._wait_for_state_change(created_server, 'ACTIVE')

diagnostics = self.api.get_server_diagnostics(created_server['id'])


+ 0
- 10
nova/tests/functional/libvirt/test_reshape.py View File

@@ -13,7 +13,6 @@

import io
import mock
import time

from oslo_config import cfg
from oslo_log import log as logging
@@ -33,15 +32,6 @@ class VGPUReshapeTests(base.ServersTestBase):
# the minimum libvirt version needed for vgpu
MIN_LIBVIRT_MDEV_SUPPORT = 3004000

def _wait_for_state_change(self, server, expected_status):
for i in range(0, 50):
server = self.api.get_server(server['id'])
if server['status'] == expected_status:
return server
time.sleep(.1)
self.assertEqual(expected_status, server['status'])
return server

@mock.patch('nova.virt.libvirt.LibvirtDriver._get_local_gb_info',
return_value={'total': 128,
'used': 44,

+ 1
- 3
nova/tests/functional/libvirt/test_rt_servers.py View File

@@ -63,8 +63,6 @@ class RealTimeServersTest(base.ServersTestBase):
server = self._build_server(flavor)
created = self.api.post_server({'server': server})

instance = self.api.get_server(created['id'])
instance = self._wait_for_state_change(instance, 'BUILD')
instance = self._wait_for_state_change(created, 'ACTIVE')

self.assertEqual('ACTIVE', instance['status'])
self._delete_server(instance)

+ 24
- 46
nova/tests/functional/test_aggregates.py View File

@@ -10,8 +10,6 @@
# License for the specific language governing permissions and limitations
# under the License.

import time

from oslo_utils.fixture import uuidsentinel as uuids

import nova.conf
@@ -212,16 +210,8 @@ class AggregateRequestFiltersTest(
agg = self.aggregates[agg]
self.admin_api.add_host_to_aggregate(agg['id'], host)

def _wait_for_state_change(self, server, from_status):
for i in range(0, 50):
server = self.api.get_server(server['id'])
if server['status'] != from_status:
break
time.sleep(.1)

return server

def _boot_server(self, az=None, flavor_id=None, image_id=None):
def _boot_server(self, az=None, flavor_id=None, image_id=None,
end_status='ACTIVE'):
flavor_id = flavor_id or self.flavors[0]['id']
image_uuid = image_id or '155d900f-4e14-4e4c-a73d-069cbf4541e6'
server_req = self._build_minimal_create_server_request(
@@ -230,7 +220,8 @@ class AggregateRequestFiltersTest(
networks='none', az=az)

created_server = self.api.post_server({'server': server_req})
server = self._wait_for_state_change(created_server, 'BUILD')
server = self._wait_for_state_change(
self.admin_api, created_server, end_status)

return server

@@ -339,8 +330,8 @@ class AggregatePostTest(AggregateRequestFiltersTest):
# Configure for the SOFT_DELETED scenario.
self.flags(reclaim_instance_interval=300)
self.api.delete_server(server['id'])
server = self._wait_for_state_change(server, from_status='ACTIVE')
self.assertEqual('SOFT_DELETED', server['status'])
server = self._wait_for_state_change(
self.admin_api, server, 'SOFT_DELETED')
self.assertRaisesRegex(
client.OpenStackApiException,
'One or more hosts contain instances in this zone.',
@@ -397,18 +388,16 @@ class TenantAggregateFilterTest(AggregateRequestFiltersTest):
group='scheduler')

def test_tenant_id_required_fails_if_no_aggregate(self):
server = self._boot_server()
# Without granting our tenant permission to an aggregate, instance
# creates should fail since aggregates are required
self.assertEqual('ERROR', server['status'])
self._boot_server(end_status='ERROR')

def test_tenant_id_not_required_succeeds_if_no_aggregate(self):
self.flags(placement_aggregate_required_for_tenants=False,
group='scheduler')
server = self._boot_server()
# Without granting our tenant permission to an aggregate, instance
# creates should still succeed since aggregates are not required
self.assertEqual('ACTIVE', server['status'])
self._boot_server(end_status='ACTIVE')

def test_filter_honors_tenant_id(self):
tenant = self.api.project_id
@@ -417,10 +406,8 @@ class TenantAggregateFilterTest(AggregateRequestFiltersTest):
# and boot some servers. They should all stack up on host1.
self._grant_tenant_aggregate('only-host1',
['foo', tenant, 'bar'])
server1 = self._boot_server()
server2 = self._boot_server()
self.assertEqual('ACTIVE', server1['status'])
self.assertEqual('ACTIVE', server2['status'])
server1 = self._boot_server(end_status='ACTIVE')
server2 = self._boot_server(end_status='ACTIVE')

# Grant our tenant access to the aggregate with only host2 in it
# and boot some servers. They should all stack up on host2.
@@ -428,10 +415,8 @@ class TenantAggregateFilterTest(AggregateRequestFiltersTest):
['foo', 'bar'])
self._grant_tenant_aggregate('only-host2',
['foo', tenant, 'bar'])
server3 = self._boot_server()
server4 = self._boot_server()
self.assertEqual('ACTIVE', server3['status'])
self.assertEqual('ACTIVE', server4['status'])
server3 = self._boot_server(end_status='ACTIVE')
server4 = self._boot_server(end_status='ACTIVE')

# Make sure the servers landed on the hosts we had access to at
# the time we booted them.
@@ -446,8 +431,7 @@ class TenantAggregateFilterTest(AggregateRequestFiltersTest):
# Grant our tenant access to the aggregate with no hosts in it
self._grant_tenant_aggregate('no-hosts',
['foo', tenant, 'bar'])
server = self._boot_server()
self.assertEqual('ERROR', server['status'])
self._boot_server(end_status='ERROR')

def test_filter_with_multiple_aggregates_for_tenant(self):
tenant = self.api.project_id
@@ -462,8 +446,7 @@ class TenantAggregateFilterTest(AggregateRequestFiltersTest):
# Boot several servers and make sure they all land on the
# only host we have access to.
for i in range(0, 4):
server = self._boot_server()
self.assertEqual('ACTIVE', server['status'])
server = self._boot_server(end_status='ACTIVE')
self.assertEqual('host2', self._get_instance_host(server))


@@ -549,10 +532,9 @@ class IsolateAggregateFilterTest(AggregateRequestFiltersTest):

server = self._boot_server(
flavor_id=self.flavor_without_trait['id'],
image_id=self.image_id_without_trait)
image_id=self.image_id_without_trait,
end_status='ERROR')
self.assertIsNone(self._get_instance_host(server))
server = self.api.get_server(server['id'])
self.assertEqual('ERROR', server['status'])
self.assertIn('No valid host', server['fault']['message'])

def test_filter_without_trait(self):
@@ -680,11 +662,10 @@ class IsolateAggregateFilterTest(AggregateRequestFiltersTest):
'trait:HW_CPU_X86_VMX': 'required'}})
server = self._boot_server(
flavor_id=self.flavor_with_trait_sgx['id'],
image_id=image_id_with_trait)
image_id=image_id_with_trait,
end_status='ERROR')

self.assertIsNone(self._get_instance_host(server))
server = self.api.get_server(server['id'])
self.assertEqual('ERROR', server['status'])
self.assertIn('No valid host', server['fault']['message'])

def test_filter_with_traits_image_flavor_disjoint_of_aggregates(self):
@@ -715,11 +696,10 @@ class IsolateAggregateFilterTest(AggregateRequestFiltersTest):
'trait:HW_CPU_X86_VMX': 'required'}})
server = self._boot_server(
flavor_id=self.flavor_with_trait_sgx['id'],
image_id=image_id_with_trait)
image_id=image_id_with_trait,
end_status='ERROR')

self.assertIsNone(self._get_instance_host(server))
server = self.api.get_server(server['id'])
self.assertEqual('ERROR', server['status'])
self.assertIn('No valid host', server['fault']['message'])


@@ -820,10 +800,8 @@ class TestAggregateFiltersTogether(AggregateRequestFiltersTest):
self._set_az_aggregate('only-host2', 'myaz')

# Boot the server into that az and make sure we fail
server = self._boot_server(az='myaz')
server = self._boot_server(az='myaz', end_status='ERROR')
self.assertIsNone(self._get_instance_host(server))
server = self.api.get_server(server['id'])
self.assertEqual('ERROR', server['status'])

def test_tenant_with_az_and_traits_match(self):
# Grant our tenant access to the aggregate with host2
@@ -854,10 +832,10 @@ class TestAggregateFiltersTogether(AggregateRequestFiltersTest):
self._set_traits_on_aggregate('only-host2', ['HW_CPU_X86_VMX'])
# Boot the server into that az and make sure we fail
server = self._boot_server(
flavor_id=self.flavor_with_trait_dxva['id'], az='myaz')
flavor_id=self.flavor_with_trait_dxva['id'],
az='myaz',
end_status='ERROR')
self.assertIsNone(self._get_instance_host(server))
server = self.api.get_server(server['id'])
self.assertEqual('ERROR', server['status'])
self.assertIn('No valid host', server['fault']['message'])



+ 4
- 8
nova/tests/functional/test_images.py View File

@@ -24,14 +24,13 @@ class ImagesTest(test_servers.ServersTestBase):
server = self._build_minimal_create_server_request()
created_server = self.api.post_server({"server": server})
server_id = created_server['id']
found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Create image
name = 'Snapshot 1'
self.api.post_server_action(
server_id, {'createImage': {'name': name}})
self.assertEqual('ACTIVE', found_server['status'])
# Confirm that the image was created
images = self.api.get_images(detail=False)
image_map = {image['name']: image for image in images}
@@ -41,8 +40,7 @@ class ImagesTest(test_servers.ServersTestBase):
# Change server status from ACTIVE to SHELVED for negative test
self.flags(shelved_offload_time = -1)
self.api.post_server_action(server_id, {'shelve': {}})
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SHELVED', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'SHELVED')

# Create image in SHELVED (not ACTIVE, etc.)
name = 'Snapshot 2'
@@ -51,7 +49,6 @@ class ImagesTest(test_servers.ServersTestBase):
server_id,
{'createImage': {'name': name}})
self.assertEqual(409, ex.response.status_code)
self.assertEqual('SHELVED', found_server['status'])

# Confirm that the image was not created
images = self.api.get_images(detail=False)
@@ -71,8 +68,7 @@ class ImagesTest(test_servers.ServersTestBase):
# Create a server using the tenant user project.
server = self._build_minimal_create_server_request()
server = self.api.post_server({"server": server})
server = self._wait_for_state_change(server, 'BUILD')
self.assertEqual('ACTIVE', server['status'])
server = self._wait_for_state_change(server, 'ACTIVE')

# Create an admin API fixture with a unique project ID.
admin_api = self.useFixture(

+ 1
- 4
nova/tests/functional/test_instance_actions.py View File

@@ -38,10 +38,7 @@ class InstanceActionsTestV2(test_servers.ServersTestBase):
found_server = self.api.get_server(created_server_id)
self.assertEqual(created_server_id, found_server['id'])

found_server = self._wait_for_state_change(found_server, 'BUILD')
# It should be available...
self.assertEqual('ACTIVE', found_server['status'])
return found_server
return self._wait_for_state_change(found_server, 'ACTIVE')

def test_get_instance_actions(self):
server = self._create_server()

+ 1
- 1
nova/tests/functional/test_legacy_v2_compatible_wrapper.py View File

@@ -52,7 +52,7 @@ class LegacyV2CompatibleTestBase(test_servers.ServersTestBase):
server = self._build_minimal_create_server_request()
post = {'server': server}
created_server = self.api.post_server(post)
self._wait_for_state_change(created_server, 'BUILD')
self._wait_for_state_change(created_server, 'ACTIVE')
response = self.api.post_server_metadata(created_server['id'],
{'a': 'b'})
self.assertEqual(response, {'a': 'b'})

+ 62
- 76
nova/tests/functional/test_servers.py View File

@@ -73,15 +73,27 @@ class ServersTestBase(integrated_helpers._IntegratedTestBase):
self.computes = {}
super(ServersTestBase, self).setUp()

def _wait_for_state_change(self, server, from_status):
for i in range(0, 50):
server = self.api.get_server(server['id'])
if server['status'] != from_status:
def _wait_for_server_parameter(self, admin_api, server, expected_params,
max_retries=10):
retry_count = 0
while True:
server = admin_api.get_server(server['id'])
if all([server[attr] == expected_params[attr]
for attr in expected_params]):
break
time.sleep(.1)
retry_count += 1
if retry_count == max_retries:
self.fail('Wait for state change failed, '
'expected_params=%s, server=%s' % (
expected_params, server))
time.sleep(0.5)

return server

def _wait_for_state_change(self, server, expected_status, max_retries=10):
return self._wait_for_server_parameter(
self.api, server, {'status': expected_status}, max_retries)

def _wait_for_deletion(self, server_id):
# Wait (briefly) for deletion
for _retries in range(50):
@@ -165,9 +177,9 @@ class ServersTest(ServersTestBase):
found_server = self.api.get_server(created_server_id)
self.assertEqual(created_server_id, found_server['id'])

found_server = self._wait_for_state_change(found_server, 'BUILD')
found_server = self._wait_for_state_change(found_server, 'ERROR')

self.assertEqual('ERROR', found_server['status'])
# Delete the server
self._delete_server(created_server)

# We should have no (persisted) build failures until we update
@@ -187,16 +199,17 @@ class ServersTest(ServersTestBase):
image_uuid=vhd_image)
server = self.api.post_server({'server': server})
server = self.api.get_server(server['id'])
errored_server = self._wait_for_state_change(server, server['status'])
self.assertEqual('ERROR', errored_server['status'])
errored_server = self._wait_for_state_change(server, 'ERROR')
self.assertIn('No valid host', errored_server['fault']['message'])

server = self._build_minimal_create_server_request(
image_uuid=raw_image)
server = self.api.post_server({'server': server})
server = self.api.get_server(server['id'])
created_server = self._wait_for_state_change(server, server['status'])
self.assertEqual('ACTIVE', created_server['status'])
created_server = self._wait_for_state_change(server, 'ACTIVE')

# Delete the server
self._delete_server(created_server)

def _test_create_server_with_error_with_retries(self):
# Create a server which will enter error state.
@@ -219,9 +232,9 @@ class ServersTest(ServersTestBase):
found_server = self.api.get_server(created_server_id)
self.assertEqual(created_server_id, found_server['id'])

found_server = self._wait_for_state_change(found_server, 'BUILD')
found_server = self._wait_for_state_change(found_server, 'ERROR')

self.assertEqual('ERROR', found_server['status'])
# Delete the server
self._delete_server(created_server)

return len(fails)
@@ -297,15 +310,14 @@ class ServersTest(ServersTestBase):
server_ids = [s['id'] for s in servers]
self.assertIn(created_server_id, server_ids)

found_server = self._wait_for_state_change(found_server, 'BUILD')
# It should be available...
# TODO(justinsb): Mock doesn't yet do this...
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'ACTIVE')

servers = self.api.get_servers(detail=True)
for server in servers:
self.assertIn("image", server)
self.assertIn("flavor", server)

# Delete the server
self._delete_server(found_server)

def _force_reclaim(self):
@@ -330,10 +342,7 @@ class ServersTest(ServersTestBase):
created_server_id = created_server['id']

# Wait for it to finish being created
found_server = self._wait_for_state_change(created_server, 'BUILD')

# It should be available...
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Cannot restore unless instance is deleted
self.assertRaises(client.OpenStackApiException,
@@ -344,8 +353,8 @@ class ServersTest(ServersTestBase):
self.api.delete_server(created_server_id)

# Wait for queued deletion
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SOFT_DELETED', found_server['status'])
found_server = self._wait_for_state_change(found_server,
'SOFT_DELETED')

self._force_reclaim()

@@ -365,24 +374,20 @@ class ServersTest(ServersTestBase):
created_server_id = created_server['id']

# Wait for it to finish being created
found_server = self._wait_for_state_change(created_server, 'BUILD')

# It should be available...
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Delete the server
self.api.delete_server(created_server_id)

# Wait for queued deletion
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SOFT_DELETED', found_server['status'])
found_server = self._wait_for_state_change(found_server,
'SOFT_DELETED')

# Restore server
self.api.post_server_action(created_server_id, {'restore': {}})

# Wait for server to become active again
found_server = self._wait_for_state_change(found_server, 'DELETED')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'ACTIVE')

def test_deferred_delete_restore_overquota(self):
# Test that a restore that would put the user over quota fails
@@ -399,17 +404,14 @@ class ServersTest(ServersTestBase):
created_server_id1 = created_server1['id']

# Wait for it to finish being created
found_server1 = self._wait_for_state_change(created_server1, 'BUILD')

# It should be available...
self.assertEqual('ACTIVE', found_server1['status'])
found_server1 = self._wait_for_state_change(created_server1, 'ACTIVE')

# Delete the server
self.api.delete_server(created_server_id1)

# Wait for queued deletion
found_server1 = self._wait_for_state_change(found_server1, 'ACTIVE')
self.assertEqual('SOFT_DELETED', found_server1['status'])
found_server1 = self._wait_for_state_change(found_server1,
'SOFT_DELETED')

# Create a second server
server = self._build_minimal_create_server_request()
@@ -419,10 +421,7 @@ class ServersTest(ServersTestBase):
self.assertTrue(created_server2['id'])

# Wait for it to finish being created
found_server2 = self._wait_for_state_change(created_server2, 'BUILD')

# It should be available...
self.assertEqual('ACTIVE', found_server2['status'])
self._wait_for_state_change(created_server2, 'ACTIVE')

# Try to restore the first server, it should fail
ex = self.assertRaises(client.OpenStackApiException,
@@ -444,17 +443,14 @@ class ServersTest(ServersTestBase):
created_server_id = created_server['id']

# Wait for it to finish being created
found_server = self._wait_for_state_change(created_server, 'BUILD')

# It should be available...
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Delete the server
self.api.delete_server(created_server_id)

# Wait for queued deletion
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SOFT_DELETED', found_server['status'])
found_server = self._wait_for_state_change(found_server,
'SOFT_DELETED')

# Force delete server
self.api.post_server_action(created_server_id,
@@ -515,16 +511,14 @@ class ServersTest(ServersTestBase):
post = {'server': server}
created_server = self.api.post_server(post)

found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')
self.assertEqual(metadata, found_server.get('metadata'))
server_id = found_server['id']

# Change status from ACTIVE to SHELVED for negative test
self.flags(shelved_offload_time = -1)
self.api.post_server_action(server_id, {'shelve': {}})
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SHELVED', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'SHELVED')

metadata = {'key_2': 'value_2'}

@@ -563,7 +557,7 @@ class ServersTest(ServersTestBase):
self.assertTrue(created_server['id'])
created_server_id = created_server['id']

created_server = self._wait_for_state_change(created_server, 'BUILD')
created_server = self._wait_for_state_change(created_server, 'ACTIVE')

# rebuild the server with metadata and other server attributes
post = {}
@@ -701,8 +695,7 @@ class ServersTest(ServersTestBase):
found_server = self.api.get_server(created_server_id)
self.assertEqual(created_server_id, found_server['id'])

found_server = self._wait_for_state_change(found_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'ACTIVE')

# Cleanup
self._delete_server(found_server)
@@ -713,8 +706,7 @@ class ServersTest(ServersTestBase):
created_server = self.api.post_server({"server": server})
created_server_id = created_server['id']

found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Start server in ACTIVE
# NOTE(mkoshiya): When os-start API runs, the server status
@@ -731,8 +723,7 @@ class ServersTest(ServersTestBase):
# Stop server
post = {'os-stop': {}}
self.api.post_server_action(created_server_id, post)
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SHUTOFF', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'SHUTOFF')

# Stop server in SHUTOFF
# NOTE(mkoshiya): When os-stop API runs, the server status
@@ -754,8 +745,7 @@ class ServersTest(ServersTestBase):
server = self._build_minimal_create_server_request()
created_server = self.api.post_server({"server": server})
created_server_id = created_server['id']
found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Revert resized server in ACTIVE
# NOTE(yatsumi): When revert resized server API runs,
@@ -780,14 +770,13 @@ class ServersTest(ServersTestBase):
server = self._build_minimal_create_server_request()
created_server = self.api.post_server({"server": server})
created_server_id = created_server['id']
found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Resize server(flavorRef: 1 -> 2)
post = {'resize': {"flavorRef": "2", "OS-DCF:diskConfig": "AUTO"}}
self.api.post_server_action(created_server_id, post)
found_server = self._wait_for_state_change(found_server, 'RESIZE')
self.assertEqual('VERIFY_RESIZE', found_server['status'])
found_server = self._wait_for_state_change(found_server,
'VERIFY_RESIZE')

# Resize server in VERIFY_RESIZE(flavorRef: 2 -> 1)
# NOTE(yatsumi): When resize API runs, the server status
@@ -809,8 +798,7 @@ class ServersTest(ServersTestBase):
server = self._build_minimal_create_server_request()
created_server = self.api.post_server({"server": server})
created_server_id = created_server['id']
found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

# Confirm resized server in ACTIVE
# NOTE(yatsumi): When confirm resized server API runs,
@@ -835,8 +823,7 @@ class ServersTest(ServersTestBase):
created_server = self.api.post_server({"server": server})
created_server_id = created_server['id']

found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
self._wait_for_state_change(created_server, 'ACTIVE')

# Try to resize to flavorid 2, 1 core, 2048 ram
post = {'resize': {'flavorRef': '2'}}
@@ -851,7 +838,7 @@ class ServersTest(ServersTestBase):
server = self._build_minimal_create_server_request()
created_server = self.api.post_server({"server": server})
server_id = created_server['id']
self._wait_for_state_change(created_server, 'BUILD')
self._wait_for_state_change(created_server, 'ACTIVE')

volume_id = '9a695496-44aa-4404-b2cc-ccab2501f87e'
LOG.info('Attaching volume %s to server %s', volume_id, server_id)
@@ -1012,7 +999,7 @@ class ServersTestV219(ServersTestBase):
# Create a server with an initial description
server = self._create_server(True, 'test desc 1')[1]
server_id = server['id']
self._wait_for_state_change(server, 'BUILD')
self._wait_for_state_change(server, 'ACTIVE')

# Rebuild and get the server with a description
self._rebuild_server_and_verify(server_id, True, 'updated desc')
@@ -1097,9 +1084,9 @@ class ServerTestV220(ServersTestBase):
def _shelve_server(self):
server = self._create_server()[1]
server_id = server['id']
self._wait_for_state_change(server, 'BUILD')
self._wait_for_state_change(server, 'ACTIVE')
self.api.post_server_action(server_id, {'shelve': None})
return self._wait_for_state_change(server, 'ACTIVE')
return self._wait_for_state_change(server, 'SHELVED_OFFLOADED')

def _get_fake_bdms(self, ctxt):
return block_device_obj.block_device_make_list(self.ctxt,
@@ -1112,7 +1099,6 @@ class ServerTestV220(ServersTestBase):
def test_attach_detach_vol_to_shelved_offloaded_server_new_flow(self):
self.flags(shelved_offload_time=0)
found_server = self._shelve_server()
self.assertEqual('SHELVED_OFFLOADED', found_server['status'])
server_id = found_server['id']
fake_bdms = self._get_fake_bdms(self.ctxt)

@@ -4566,7 +4552,7 @@ class ServerTestV256MultiCellTestCase(ServerTestV256Common):
# We target host1 specifically so that we have a predictable target for
# the cold migration in cell2.
server = self._create_server(target_host='host1')
server = self._wait_for_state_change(server, 'BUILD')
server = self._wait_for_state_change(server, 'ACTIVE')

self.assertEqual('host1', server['OS-EXT-SRV-ATTR:host'])
ex = self.assertRaises(client.OpenStackApiException,
@@ -4588,7 +4574,7 @@ class ServerTestV256SingleCellMultiHostTestCase(ServerTestV256Common):
"""
def test_migrate_server_to_host_in_same_cell(self):
server = self._create_server()
server = self._wait_for_state_change(server, 'BUILD')
server = self._wait_for_state_change(server, 'ACTIVE')
source_host = server['OS-EXT-SRV-ATTR:host']
target_host = self._get_target_and_other_hosts(source_host)[0]
self.api.post_server_action(server['id'],
@@ -4605,7 +4591,7 @@ class ServerTestV256RescheduleTestCase(ServerTestV256Common):
reason='Test Exception'))
def test_migrate_server_not_reschedule(self, mock_prep_resize):
server = self._create_server()
found_server = self._wait_for_state_change(server, 'BUILD')
found_server = self._wait_for_state_change(server, 'ACTIVE')

target_host, other_host = self._get_target_and_other_hosts(
found_server['OS-EXT-SRV-ATTR:host'])

+ 2
- 4
nova/tests/functional/wsgi/test_interfaces.py View File

@@ -117,8 +117,7 @@ class InterfaceFullstackWithNeutron(test_servers.ServersTestBase):
"networks": [{"uuid": "3cb9bc59-5699-4588-a4b1-b87f96708bc6"}]}}
created_server = self.api.post_server(post)
created_server_id = created_server['id']
found_server = self._wait_for_state_change(created_server, 'BUILD')
self.assertEqual('ACTIVE', found_server['status'])
found_server = self._wait_for_state_change(created_server, 'ACTIVE')

post = {
'interfaceAttachment': {
@@ -133,8 +132,7 @@ class InterfaceFullstackWithNeutron(test_servers.ServersTestBase):
# Change status from ACTIVE to SUSPENDED for negative test
post = {'suspend': {}}
self.api.post_server_action(created_server_id, post)
found_server = self._wait_for_state_change(found_server, 'ACTIVE')
self.assertEqual('SUSPENDED', found_server['status'])
found_server = self._wait_for_state_change(found_server, 'SUSPENDED')

# Detach port interface in SUSPENDED (not ACTIVE, etc.)
ex = self.assertRaises(client.OpenStackApiException,

Loading…
Cancel
Save