Browse Source

Merge "Replace time.sleep(10) with service forced_down in tests" into stable/rocky

changes/53/696353/2
Zuul 2 months ago
parent
commit
a96ae9a0a3
2 changed files with 27 additions and 49 deletions
  1. +6
    -0
      nova/tests/functional/api/client.py
  2. +21
    -49
      nova/tests/functional/test_server_group.py

+ 6
- 0
nova/tests/functional/api/client.py View File

@@ -514,3 +514,9 @@ class TestOpenStackClient(object):
def get_hypervisor_stats(self):
return self.api_get(
'/os-hypervisors/statistics').body['hypervisor_statistics']

def put_service_force_down(self, service_id, forced_down):
req = {
'forced_down': forced_down
}
return self.api_put('os-services/%s' % service_id, req).body['service']

+ 21
- 49
nova/tests/functional/test_server_group.py View File

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

import time

import mock
from oslo_config import cfg

@@ -26,6 +24,7 @@ from nova.tests import fixtures as nova_fixtures
from nova.tests.functional.api import client
from nova.tests.functional import integrated_helpers
from nova.tests.unit import policy_fixture
from nova import utils
from nova.virt import fake

import nova.scheduler.utils
@@ -48,10 +47,6 @@ class ServerGroupTestBase(test.TestCase,
+ ['ServerGroupAntiAffinityFilter',
'ServerGroupAffinityFilter'])

# Override servicegroup parameters to make the tests run faster
_service_down_time = 10
_report_interval = 1

anti_affinity = {'name': 'fake-name-1', 'policies': ['anti-affinity']}
affinity = {'name': 'fake-name-2', 'policies': ['affinity']}

@@ -67,8 +62,6 @@ class ServerGroupTestBase(test.TestCase,
self.flags(disk_allocation_ratio=9999.0)
self.flags(weight_classes=self._get_weight_classes(),
group='filter_scheduler')
self.flags(service_down_time=self._service_down_time)
self.flags(report_interval=self._report_interval)

self.useFixture(policy_fixture.RealPolicyFixture())
self.useFixture(nova_fixtures.NeutronFixture(self))
@@ -411,16 +404,20 @@ class ServerGroupTestV21(ServerGroupTestBase):

return host

def _set_forced_down(self, service, forced_down):
# Use microversion 2.53 for PUT /os-services/{service_id} force down.
with utils.temporary_mutation(self.admin_api, microversion='2.53'):
self.admin_api.put_service_force_down(service.service_ref.uuid,
forced_down)

def test_evacuate_with_anti_affinity(self):
created_group = self.api.post_server_groups(self.anti_affinity)
servers = self._boot_servers_to_group(created_group)

host = self._get_compute_service_by_host_name(
servers[1]['OS-EXT-SRV-ATTR:host'])
host.stop()
# Need to wait service_down_time amount of seconds to ensure
# nova considers the host down
time.sleep(self._service_down_time)
# Set forced_down on the host to ensure nova considers the host down.
self._set_forced_down(host, True)

# Start additional host to test evacuation
fake.set_nodes(['host3'])
@@ -439,18 +436,14 @@ class ServerGroupTestV21(ServerGroupTestBase):
self.assertNotEqual(evacuated_server['OS-EXT-SRV-ATTR:host'],
servers[0]['OS-EXT-SRV-ATTR:host'])

host.start()

def test_evacuate_with_anti_affinity_no_valid_host(self):
created_group = self.api.post_server_groups(self.anti_affinity)
servers = self._boot_servers_to_group(created_group)

host = self._get_compute_service_by_host_name(
servers[1]['OS-EXT-SRV-ATTR:host'])
host.stop()
# Need to wait service_down_time amount of seconds to ensure
# nova considers the host down
time.sleep(self._service_down_time)
# Set forced_down on the host to ensure nova considers the host down.
self._set_forced_down(host, True)

post = {'evacuate': {'onSharedStorage': False}}
self.admin_api.post_server_action(servers[1]['id'], post)
@@ -463,18 +456,14 @@ class ServerGroupTestV21(ServerGroupTestBase):
self.assertEqual(server_after_failed_evac['OS-EXT-SRV-ATTR:host'],
servers[1]['OS-EXT-SRV-ATTR:host'])

host.start()

def test_evacuate_with_affinity_no_valid_host(self):
created_group = self.api.post_server_groups(self.affinity)
servers = self._boot_servers_to_group(created_group)

host = self._get_compute_service_by_host_name(
servers[1]['OS-EXT-SRV-ATTR:host'])
host.stop()
# Need to wait service_down_time amount of seconds to ensure
# nova considers the host down
time.sleep(self._service_down_time)
# Set forced_down on the host to ensure nova considers the host down.
self._set_forced_down(host, True)

post = {'evacuate': {'onSharedStorage': False}}
self.admin_api.post_server_action(servers[1]['id'], post)
@@ -487,8 +476,6 @@ class ServerGroupTestV21(ServerGroupTestBase):
self.assertEqual(server_after_failed_evac['OS-EXT-SRV-ATTR:host'],
servers[1]['OS-EXT-SRV-ATTR:host'])

host.start()

def test_soft_affinity_not_supported(self):
ex = self.assertRaises(client.OpenStackApiException,
self.api.post_server_groups,
@@ -614,10 +601,8 @@ class ServerGroupTestV215(ServerGroupTestV21):

host = self._get_compute_service_by_host_name(
servers[1]['OS-EXT-SRV-ATTR:host'])
host.stop()
# Need to wait service_down_time amount of seconds to ensure
# nova considers the host down
time.sleep(self._service_down_time)
# Set forced_down on the host to ensure nova considers the host down.
self._set_forced_down(host, True)

# Start additional host to test evacuation
fake.set_nodes(['host3'])
@@ -637,7 +622,6 @@ class ServerGroupTestV215(ServerGroupTestV21):
servers[0]['OS-EXT-SRV-ATTR:host'])

compute3.kill()
host.start()

def test_evacuate_with_anti_affinity_no_valid_host(self):
created_group = self.api.post_server_groups(self.anti_affinity)
@@ -645,10 +629,8 @@ class ServerGroupTestV215(ServerGroupTestV21):

host = self._get_compute_service_by_host_name(
servers[1]['OS-EXT-SRV-ATTR:host'])
host.stop()
# Need to wait service_down_time amount of seconds to ensure
# nova considers the host down
time.sleep(self._service_down_time)
# Set forced_down on the host to ensure nova considers the host down.
self._set_forced_down(host, True)

post = {'evacuate': {}}
self.admin_api.post_server_action(servers[1]['id'], post)
@@ -661,18 +643,14 @@ class ServerGroupTestV215(ServerGroupTestV21):
self.assertEqual(server_after_failed_evac['OS-EXT-SRV-ATTR:host'],
servers[1]['OS-EXT-SRV-ATTR:host'])

host.start()

def test_evacuate_with_affinity_no_valid_host(self):
created_group = self.api.post_server_groups(self.affinity)
servers = self._boot_servers_to_group(created_group)

host = self._get_compute_service_by_host_name(
servers[1]['OS-EXT-SRV-ATTR:host'])
host.stop()
# Need to wait service_down_time amount of seconds to ensure
# nova considers the host down
time.sleep(self._service_down_time)
# Set forced_down on the host to ensure nova considers the host down.
self._set_forced_down(host, True)

post = {'evacuate': {}}
self.admin_api.post_server_action(servers[1]['id'], post)
@@ -685,8 +663,6 @@ class ServerGroupTestV215(ServerGroupTestV21):
self.assertEqual(server_after_failed_evac['OS-EXT-SRV-ATTR:host'],
servers[1]['OS-EXT-SRV-ATTR:host'])

host.start()

def _check_group_format(self, group, created_group):
self.assertEqual(group['policies'], created_group['policies'])
self.assertEqual({}, created_group['metadata'])
@@ -815,10 +791,8 @@ class ServerGroupTestV215(ServerGroupTestV21):

host = self._get_compute_service_by_host_name(
servers[1]['OS-EXT-SRV-ATTR:host'])
host.stop()
# Need to wait service_down_time amount of seconds to ensure
# nova considers the host down
time.sleep(self._service_down_time)
# Set forced_down on the host to ensure nova considers the host down.
self._set_forced_down(host, True)

post = {'evacuate': {}}
self.admin_api.post_server_action(servers[1]['id'], post)
@@ -831,8 +805,6 @@ class ServerGroupTestV215(ServerGroupTestV21):
# new host later
evacuated_server = self.admin_api.get_server(evacuated_server['id'])

host.start()

return [evacuated_server['OS-EXT-SRV-ATTR:host'],
servers[0]['OS-EXT-SRV-ATTR:host']]


Loading…
Cancel
Save