Merge "Refactor TestEvacuateDeleteServerRestartOriginalCompute"
This commit is contained in:
@@ -787,3 +787,11 @@ class ProviderUsageBaseTestCase(test.TestCase, InstanceHelperMixin):
|
|||||||
# The migration should hold an old_flavor allocation
|
# The migration should hold an old_flavor allocation
|
||||||
self.assertFlavorMatchesAllocation(old_flavor, migration_uuid,
|
self.assertFlavorMatchesAllocation(old_flavor, migration_uuid,
|
||||||
rp_uuid)
|
rp_uuid)
|
||||||
|
|
||||||
|
def _check_allocation_during_evacuate(
|
||||||
|
self, flavor, server_uuid, source_root_rp_uuid, dest_root_rp_uuid):
|
||||||
|
|
||||||
|
allocations = self._get_allocations_by_server_uuid(server_uuid)
|
||||||
|
self.assertEqual(2, len(allocations))
|
||||||
|
self.assertFlavorMatchesUsage(source_root_rp_uuid, flavor)
|
||||||
|
self.assertFlavorMatchesUsage(dest_root_rp_uuid, flavor)
|
||||||
|
@@ -10,12 +10,8 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
from oslo_log import log as logging
|
|
||||||
|
|
||||||
from nova.tests.functional import integrated_helpers
|
from nova.tests.functional import integrated_helpers
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class TestEvacuateDeleteServerRestartOriginalCompute(
|
class TestEvacuateDeleteServerRestartOriginalCompute(
|
||||||
integrated_helpers.ProviderUsageBaseTestCase):
|
integrated_helpers.ProviderUsageBaseTestCase):
|
||||||
@@ -30,95 +26,6 @@ class TestEvacuateDeleteServerRestartOriginalCompute(
|
|||||||
flavors = self.api.get_flavors()
|
flavors = self.api.get_flavors()
|
||||||
self.flavor1 = flavors[0]
|
self.flavor1 = flavors[0]
|
||||||
|
|
||||||
# NOTE(mriedem): This is here for backports and should be removed later
|
|
||||||
# on master (Stein).
|
|
||||||
def assertFlavorMatchesAllocation(self, flavor, allocation):
|
|
||||||
self.assertEqual(flavor['vcpus'], allocation['VCPU'])
|
|
||||||
self.assertEqual(flavor['ram'], allocation['MEMORY_MB'])
|
|
||||||
self.assertEqual(flavor['disk'], allocation['DISK_GB'])
|
|
||||||
|
|
||||||
# NOTE(mriedem): This is here for backports and should be removed later
|
|
||||||
# on master (Stein).
|
|
||||||
def _boot_and_check_allocations(self, flavor, source_hostname):
|
|
||||||
"""Boot an instance and check that the resource allocation is correct
|
|
||||||
After booting an instance on the given host with a given flavor it
|
|
||||||
asserts that both the providers usages and resource allocations match
|
|
||||||
with the resources requested in the flavor. It also asserts that
|
|
||||||
running the periodic update_available_resource call does not change the
|
|
||||||
resource state.
|
|
||||||
:param flavor: the flavor the instance will be booted with
|
|
||||||
:param source_hostname: the name of the host the instance will be
|
|
||||||
booted on
|
|
||||||
:return: the API representation of the booted instance
|
|
||||||
"""
|
|
||||||
server_req = self._build_minimal_create_server_request(
|
|
||||||
self.api, 'some-server', flavor_id=flavor['id'],
|
|
||||||
image_uuid='155d900f-4e14-4e4c-a73d-069cbf4541e6',
|
|
||||||
networks='none')
|
|
||||||
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')
|
|
||||||
|
|
||||||
# Verify that our source host is what the server ended up on
|
|
||||||
self.assertEqual(source_hostname, server['OS-EXT-SRV-ATTR:host'])
|
|
||||||
|
|
||||||
source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
|
|
||||||
|
|
||||||
# Before we run periodics, make sure that we have allocations/usages
|
|
||||||
# only on the source host
|
|
||||||
source_usages = self._get_provider_usages(source_rp_uuid)
|
|
||||||
self.assertFlavorMatchesAllocation(flavor, source_usages)
|
|
||||||
|
|
||||||
# Check that the other providers has no usage
|
|
||||||
for rp_uuid in [self._get_provider_uuid_by_host(hostname)
|
|
||||||
for hostname in self.computes.keys()
|
|
||||||
if hostname != source_hostname]:
|
|
||||||
usages = self._get_provider_usages(rp_uuid)
|
|
||||||
self.assertEqual({'VCPU': 0,
|
|
||||||
'MEMORY_MB': 0,
|
|
||||||
'DISK_GB': 0}, usages)
|
|
||||||
|
|
||||||
# Check that the server only allocates resource from the host it is
|
|
||||||
# booted on
|
|
||||||
allocations = self._get_allocations_by_server_uuid(server['id'])
|
|
||||||
self.assertEqual(1, len(allocations),
|
|
||||||
'No allocation for the server on the host it '
|
|
||||||
'is booted on')
|
|
||||||
allocation = allocations[source_rp_uuid]['resources']
|
|
||||||
self.assertFlavorMatchesAllocation(flavor, allocation)
|
|
||||||
|
|
||||||
self._run_periodics()
|
|
||||||
|
|
||||||
# After running the periodics but before we start any other operation,
|
|
||||||
# we should have exactly the same allocation/usage information as
|
|
||||||
# before running the periodics
|
|
||||||
|
|
||||||
# Check usages on the selected host after boot
|
|
||||||
source_usages = self._get_provider_usages(source_rp_uuid)
|
|
||||||
self.assertFlavorMatchesAllocation(flavor, source_usages)
|
|
||||||
|
|
||||||
# Check that the server only allocates resource from the host it is
|
|
||||||
# booted on
|
|
||||||
allocations = self._get_allocations_by_server_uuid(server['id'])
|
|
||||||
self.assertEqual(1, len(allocations),
|
|
||||||
'No allocation for the server on the host it '
|
|
||||||
'is booted on')
|
|
||||||
allocation = allocations[source_rp_uuid]['resources']
|
|
||||||
self.assertFlavorMatchesAllocation(flavor, allocation)
|
|
||||||
|
|
||||||
# Check that the other providers has no usage
|
|
||||||
for rp_uuid in [self._get_provider_uuid_by_host(hostname)
|
|
||||||
for hostname in self.computes.keys()
|
|
||||||
if hostname != source_hostname]:
|
|
||||||
usages = self._get_provider_usages(rp_uuid)
|
|
||||||
self.assertEqual({'VCPU': 0,
|
|
||||||
'MEMORY_MB': 0,
|
|
||||||
'DISK_GB': 0}, usages)
|
|
||||||
|
|
||||||
return server
|
|
||||||
|
|
||||||
def test_evacuate_delete_server_restart_original_compute(self):
|
def test_evacuate_delete_server_restart_original_compute(self):
|
||||||
"""Regression test for bug 1794996 where a server is successfully
|
"""Regression test for bug 1794996 where a server is successfully
|
||||||
evacuated from a down host and then deleted. Then the source compute
|
evacuated from a down host and then deleted. Then the source compute
|
||||||
@@ -158,18 +65,13 @@ class TestEvacuateDeleteServerRestartOriginalCompute(
|
|||||||
source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
|
source_rp_uuid = self._get_provider_uuid_by_host(source_hostname)
|
||||||
dest_rp_uuid = self._get_provider_uuid_by_host(dest_hostname)
|
dest_rp_uuid = self._get_provider_uuid_by_host(dest_hostname)
|
||||||
|
|
||||||
source_usages = self._get_provider_usages(source_rp_uuid)
|
self.assertFlavorMatchesUsage(source_rp_uuid, self.flavor1)
|
||||||
self.assertFlavorMatchesAllocation(self.flavor1, source_usages)
|
self.assertFlavorMatchesUsage(dest_rp_uuid, self.flavor1)
|
||||||
|
|
||||||
dest_usages = self._get_provider_usages(dest_rp_uuid)
|
|
||||||
self.assertFlavorMatchesAllocation(self.flavor1, dest_usages)
|
|
||||||
|
|
||||||
allocations = self._get_allocations_by_server_uuid(server['id'])
|
allocations = self._get_allocations_by_server_uuid(server['id'])
|
||||||
self.assertEqual(2, len(allocations))
|
self.assertEqual(2, len(allocations))
|
||||||
source_allocation = allocations[source_rp_uuid]['resources']
|
self._check_allocation_during_evacuate(
|
||||||
self.assertFlavorMatchesAllocation(self.flavor1, source_allocation)
|
self.flavor1, server['id'], source_rp_uuid, dest_rp_uuid)
|
||||||
dest_allocation = allocations[dest_rp_uuid]['resources']
|
|
||||||
self.assertFlavorMatchesAllocation(self.flavor1, dest_allocation)
|
|
||||||
|
|
||||||
# Delete the evacuated server. The allocations should be gone from
|
# Delete the evacuated server. The allocations should be gone from
|
||||||
# both the original evacuated-from host and the evacuated-to host.
|
# both the original evacuated-from host and the evacuated-to host.
|
||||||
|
@@ -2363,14 +2363,6 @@ class ServerMovingTests(integrated_helpers.ProviderUsageBaseTestCase):
|
|||||||
|
|
||||||
self._delete_and_check_allocations(server)
|
self._delete_and_check_allocations(server)
|
||||||
|
|
||||||
def _check_allocation_during_evacuate(
|
|
||||||
self, flavor, server_uuid, source_root_rp_uuid, dest_root_rp_uuid):
|
|
||||||
|
|
||||||
allocations = self._get_allocations_by_server_uuid(server_uuid)
|
|
||||||
self.assertEqual(2, len(allocations))
|
|
||||||
self.assertFlavorMatchesUsage(source_root_rp_uuid, flavor)
|
|
||||||
self.assertFlavorMatchesUsage(dest_root_rp_uuid, flavor)
|
|
||||||
|
|
||||||
def test_evacuate(self):
|
def test_evacuate(self):
|
||||||
source_hostname = self.compute1.host
|
source_hostname = self.compute1.host
|
||||||
dest_hostname = self.compute2.host
|
dest_hostname = self.compute2.host
|
||||||
|
Reference in New Issue
Block a user