Merge "improve scenario test"
This commit is contained in:
commit
888d3f467d
5 files changed
+103
-356
No files matched your search
@@ -68,6 +68,64 @@ class BaseInfraOptimScenarioTest(manager.ScenarioTest):
|
||||
"""Ensure that all created objects get destroyed."""
|
||||
super(BaseInfraOptimScenarioTest, cls).resource_cleanup()
|
||||
|
||||
@classmethod
|
||||
def get_hypervisors_setup(cls):
|
||||
hypervisors_client = cls.mgr.hypervisor_client
|
||||
hypervisors = hypervisors_client.list_hypervisors(
|
||||
detail=True)['hypervisors']
|
||||
return hypervisors
|
||||
|
||||
@classmethod
|
||||
def get_compute_nodes_setup(cls):
|
||||
services_client = cls.mgr.services_client
|
||||
available_services = services_client.list_services()['services']
|
||||
|
||||
return [srv for srv in available_services
|
||||
if srv.get('binary') == 'nova-compute']
|
||||
|
||||
@classmethod
|
||||
def wait_for_compute_node_setup(cls):
|
||||
|
||||
def _are_compute_nodes_setup():
|
||||
try:
|
||||
hypervisors = cls.get_hypervisors_setup()
|
||||
available_hypervisors = set(
|
||||
hyp['hypervisor_hostname'] for hyp in hypervisors
|
||||
if hyp['state'] == 'up')
|
||||
available_services = set(
|
||||
service['host']
|
||||
for service in cls.get_compute_nodes_setup()
|
||||
if service['state'] == 'up')
|
||||
return (
|
||||
len(available_hypervisors) == len(available_services) and
|
||||
len(hypervisors) >= 2)
|
||||
except Exception as exc:
|
||||
LOG.exception(exc)
|
||||
return False
|
||||
|
||||
assert test_utils.call_until_true(
|
||||
func=_are_compute_nodes_setup,
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def rollback_compute_nodes_status(cls):
|
||||
current_compute_nodes_setup = cls.get_compute_nodes_setup()
|
||||
for cn_setup in current_compute_nodes_setup:
|
||||
cn_hostname = cn_setup.get('host')
|
||||
matching_cns = [
|
||||
cns for cns in cls.initial_compute_nodes_setup
|
||||
if cns.get('host') == cn_hostname
|
||||
]
|
||||
initial_cn_setup = matching_cns[0] # Should return a single result
|
||||
if cn_setup.get('status') != initial_cn_setup.get('status'):
|
||||
if initial_cn_setup.get('status') == 'enabled':
|
||||
rollback_func = cls.mgr.services_client.enable_service
|
||||
else:
|
||||
rollback_func = cls.mgr.services_client.disable_service
|
||||
rollback_func(binary='nova-compute', host=cn_hostname)
|
||||
|
||||
@classmethod
|
||||
def wait_for(cls, condition, timeout=30):
|
||||
start_time = time.time()
|
||||
@@ -96,6 +154,51 @@ class BaseInfraOptimScenarioTest(manager.ScenarioTest):
|
||||
sleep_for=5
|
||||
)
|
||||
|
||||
def _migrate_server_to(self, server_id, dest_host, volume_backed=False):
|
||||
kwargs = dict()
|
||||
kwargs['disk_over_commit'] = False
|
||||
block_migration = (CONF.compute_feature_enabled.
|
||||
block_migration_for_live_migration and
|
||||
not volume_backed)
|
||||
body = self.mgr.servers_client.live_migrate_server(
|
||||
server_id, host=dest_host, block_migration=block_migration,
|
||||
**kwargs)
|
||||
return body
|
||||
|
||||
def _create_one_instance_per_host(self):
|
||||
"""Create 1 instance per compute node
|
||||
|
||||
This goes up to the min_compute_nodes threshold so that things don't
|
||||
get crazy if you have 1000 compute nodes but set min to 3.
|
||||
"""
|
||||
host_client = self.mgr.hosts_client
|
||||
all_hosts = host_client.list_hosts()['hosts']
|
||||
compute_nodes = [x for x in all_hosts if x['service'] == 'compute']
|
||||
|
||||
created_instances = []
|
||||
for _ in compute_nodes[:CONF.compute.min_compute_nodes]:
|
||||
# by getting to active state here, this means this has
|
||||
# landed on the host in question.
|
||||
instance = self.create_server(image_id=CONF.compute.image_ref,
|
||||
wait_until='ACTIVE',
|
||||
clients=self.os_primary)
|
||||
# get instance object again as admin
|
||||
instance = self.mgr.servers_client.show_server(
|
||||
instance['id'])['server']
|
||||
created_instances.append(instance)
|
||||
self.make_instance_statistic(instance)
|
||||
|
||||
return created_instances
|
||||
|
||||
def _pack_all_created_instances_on_one_host(self, instances):
|
||||
hypervisors = [
|
||||
hyp['hypervisor_hostname'] for hyp in self.get_hypervisors_setup()
|
||||
if hyp['state'] == 'up']
|
||||
node = hypervisors[0]
|
||||
for instance in instances:
|
||||
if instance.get('OS-EXT-SRV-ATTR:hypervisor_hostname') != node:
|
||||
self._migrate_server_to(instance['id'], node)
|
||||
|
||||
# ### GNOCCHI ### #
|
||||
|
||||
def create_resource(self, **kwargs):
|
||||
|
||||
@@ -78,82 +78,6 @@ class TestExecuteActionsViaActuator(base.BaseInfraOptimScenarioTest):
|
||||
"Less than 2 compute nodes are enabled, "
|
||||
"skipping multinode tests.")
|
||||
|
||||
@classmethod
|
||||
def get_compute_nodes_setup(cls):
|
||||
services_client = cls.mgr.services_client
|
||||
available_services = services_client.list_services()['services']
|
||||
|
||||
return [srv for srv in available_services
|
||||
if srv.get('binary') == 'nova-compute']
|
||||
|
||||
@classmethod
|
||||
def wait_for_compute_node_setup(cls):
|
||||
|
||||
def _are_compute_nodes_setup():
|
||||
try:
|
||||
hypervisors_client = cls.mgr.hypervisor_client
|
||||
hypervisors = hypervisors_client.list_hypervisors(
|
||||
detail=True)['hypervisors']
|
||||
available_hypervisors = set(
|
||||
hyp['hypervisor_hostname'] for hyp in hypervisors)
|
||||
available_services = set(
|
||||
service['host']
|
||||
for service in cls.get_compute_nodes_setup())
|
||||
|
||||
return (
|
||||
available_hypervisors == available_services and
|
||||
len(hypervisors) >= 2)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
assert test_utils.call_until_true(
|
||||
func=_are_compute_nodes_setup,
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def rollback_compute_nodes_status(cls):
|
||||
current_compute_nodes_setup = cls.get_compute_nodes_setup()
|
||||
for cn_setup in current_compute_nodes_setup:
|
||||
cn_hostname = cn_setup.get('host')
|
||||
matching_cns = [
|
||||
cns for cns in cls.initial_compute_nodes_setup
|
||||
if cns.get('host') == cn_hostname
|
||||
]
|
||||
initial_cn_setup = matching_cns[0] # Should return a single result
|
||||
if cn_setup.get('status') != initial_cn_setup.get('status'):
|
||||
if initial_cn_setup.get('status') == 'enabled':
|
||||
rollback_func = cls.mgr.services_client.enable_service
|
||||
else:
|
||||
rollback_func = cls.mgr.services_client.disable_service
|
||||
rollback_func(binary='nova-compute', host=cn_hostname)
|
||||
|
||||
def _create_one_instance_per_host(self):
|
||||
"""Create 1 instance per compute node
|
||||
|
||||
This goes up to the min_compute_nodes threshold so that things don't
|
||||
get crazy if you have 1000 compute nodes but set min to 3.
|
||||
"""
|
||||
host_client = self.mgr.hosts_client
|
||||
all_hosts = host_client.list_hosts()['hosts']
|
||||
compute_nodes = [x for x in all_hosts if x['service'] == 'compute']
|
||||
|
||||
created_servers = []
|
||||
for _ in compute_nodes[:CONF.compute.min_compute_nodes]:
|
||||
# by getting to active state here, this means this has
|
||||
# landed on the host in question.
|
||||
instance = self.create_server(image_id=CONF.compute.image_ref,
|
||||
wait_until='ACTIVE',
|
||||
clients=self.os_primary)
|
||||
# get instance object again as admin
|
||||
instance = self.mgr.servers_client.show_server(
|
||||
instance['id'])['server']
|
||||
created_servers.append(instance)
|
||||
self.make_instance_statistic(instance)
|
||||
|
||||
return created_servers
|
||||
|
||||
def _get_flavors(self):
|
||||
return self.mgr.flavors_client.list_flavors()['flavors']
|
||||
|
||||
|
||||
@@ -56,81 +56,6 @@ class TestExecuteBasicStrategy(base.BaseInfraOptimScenarioTest):
|
||||
"Less than 2 compute nodes are enabled, "
|
||||
"skipping multinode tests.")
|
||||
|
||||
@classmethod
|
||||
def get_compute_nodes_setup(cls):
|
||||
services_client = cls.mgr.services_client
|
||||
available_services = services_client.list_services()['services']
|
||||
|
||||
return [srv for srv in available_services
|
||||
if srv.get('binary') == 'nova-compute']
|
||||
|
||||
@classmethod
|
||||
def wait_for_compute_node_setup(cls):
|
||||
|
||||
def _are_compute_nodes_setup():
|
||||
try:
|
||||
hypervisors_client = cls.mgr.hypervisor_client
|
||||
hypervisors = hypervisors_client.list_hypervisors(
|
||||
detail=True)['hypervisors']
|
||||
available_hypervisors = set(
|
||||
hyp['hypervisor_hostname'] for hyp in hypervisors)
|
||||
available_services = set(
|
||||
service['host']
|
||||
for service in cls.get_compute_nodes_setup())
|
||||
|
||||
return (
|
||||
available_hypervisors == available_services and
|
||||
len(hypervisors) >= 2)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
assert test_utils.call_until_true(
|
||||
func=_are_compute_nodes_setup,
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def rollback_compute_nodes_status(cls):
|
||||
current_compute_nodes_setup = cls.get_compute_nodes_setup()
|
||||
for cn_setup in current_compute_nodes_setup:
|
||||
cn_hostname = cn_setup.get('host')
|
||||
matching_cns = [
|
||||
cns for cns in cls.initial_compute_nodes_setup
|
||||
if cns.get('host') == cn_hostname
|
||||
]
|
||||
initial_cn_setup = matching_cns[0] # Should return a single result
|
||||
if cn_setup.get('status') != initial_cn_setup.get('status'):
|
||||
if initial_cn_setup.get('status') == 'enabled':
|
||||
rollback_func = cls.mgr.services_client.enable_service
|
||||
else:
|
||||
rollback_func = cls.mgr.services_client.disable_service
|
||||
rollback_func(binary='nova-compute', host=cn_hostname)
|
||||
|
||||
def _create_one_instance_per_host(self):
|
||||
"""Create 1 instance per compute node
|
||||
|
||||
This goes up to the min_compute_nodes threshold so that things don't
|
||||
get crazy if you have 1000 compute nodes but set min to 3.
|
||||
"""
|
||||
host_client = self.mgr.hosts_client
|
||||
all_hosts = host_client.list_hosts()['hosts']
|
||||
compute_nodes = [x for x in all_hosts if x['service'] == 'compute']
|
||||
|
||||
for idx, _ in enumerate(
|
||||
compute_nodes[:CONF.compute.min_compute_nodes], start=1):
|
||||
# by getting to active state here, this means this has
|
||||
# landed on the host in question.
|
||||
instance = self.create_server(
|
||||
name="instance-%d" % idx,
|
||||
image_id=CONF.compute.image_ref,
|
||||
wait_until='ACTIVE',
|
||||
clients=self.os_primary)
|
||||
# get instance object again as admin
|
||||
instance = self.mgr.servers_client.show_server(
|
||||
instance['id'])['server']
|
||||
self.make_instance_statistic(instance)
|
||||
|
||||
def test_execute_basic_action_plan(self):
|
||||
"""Execute an action plan based on the BASIC strategy
|
||||
|
||||
|
||||
@@ -58,109 +58,6 @@ class TestExecuteWorkloadBalancingStrategy(base.BaseInfraOptimScenarioTest):
|
||||
"Less than 2 compute nodes are enabled, "
|
||||
"skipping multinode tests.")
|
||||
|
||||
@classmethod
|
||||
def get_hypervisors_setup(cls):
|
||||
hypervisors_client = cls.mgr.hypervisor_client
|
||||
hypervisors = hypervisors_client.list_hypervisors(
|
||||
detail=True)['hypervisors']
|
||||
return hypervisors
|
||||
|
||||
@classmethod
|
||||
def get_compute_nodes_setup(cls):
|
||||
services_client = cls.mgr.services_client
|
||||
available_services = services_client.list_services()['services']
|
||||
|
||||
return [srv for srv in available_services
|
||||
if srv.get('binary') == 'nova-compute']
|
||||
|
||||
def _migrate_server_to(self, server_id, dest_host, volume_backed=False):
|
||||
kwargs = dict()
|
||||
kwargs['disk_over_commit'] = False
|
||||
block_migration = (CONF.compute_feature_enabled.
|
||||
block_migration_for_live_migration and
|
||||
not volume_backed)
|
||||
body = self.mgr.servers_client.live_migrate_server(
|
||||
server_id, host=dest_host, block_migration=block_migration,
|
||||
**kwargs)
|
||||
return body
|
||||
|
||||
@classmethod
|
||||
def wait_for_compute_node_setup(cls):
|
||||
|
||||
def _are_compute_nodes_setup():
|
||||
try:
|
||||
hypervisors = cls.get_hypervisors_setup()
|
||||
available_hypervisors = set(
|
||||
hyp['hypervisor_hostname'] for hyp in hypervisors
|
||||
if hyp['state'] == 'up')
|
||||
available_services = set(
|
||||
service['host']
|
||||
for service in cls.get_compute_nodes_setup()
|
||||
if service['state'] == 'up')
|
||||
return (
|
||||
len(available_hypervisors) == len(available_services) and
|
||||
len(hypervisors) >= 2)
|
||||
except Exception as exc:
|
||||
LOG.exception(exc)
|
||||
return False
|
||||
|
||||
assert test_utils.call_until_true(
|
||||
func=_are_compute_nodes_setup,
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def rollback_compute_nodes_status(cls):
|
||||
current_compute_nodes_setup = cls.get_compute_nodes_setup()
|
||||
for cn_setup in current_compute_nodes_setup:
|
||||
cn_hostname = cn_setup.get('host')
|
||||
matching_cns = [
|
||||
cns for cns in cls.initial_compute_nodes_setup
|
||||
if cns.get('host') == cn_hostname
|
||||
]
|
||||
initial_cn_setup = matching_cns[0] # Should return a single result
|
||||
if cn_setup.get('status') != initial_cn_setup.get('status'):
|
||||
if initial_cn_setup.get('status') == 'enabled':
|
||||
rollback_func = cls.mgr.services_client.enable_service
|
||||
else:
|
||||
rollback_func = cls.mgr.services_client.disable_service
|
||||
rollback_func(binary='nova-compute', host=cn_hostname)
|
||||
|
||||
def _create_one_instance_per_host(self):
|
||||
"""Create 1 instance per compute node
|
||||
|
||||
This goes up to the min_compute_nodes threshold so that things don't
|
||||
get crazy if you have 1000 compute nodes but set min to 3.
|
||||
"""
|
||||
host_client = self.mgr.hosts_client
|
||||
all_hosts = host_client.list_hosts()['hosts']
|
||||
compute_nodes = [x for x in all_hosts if x['service'] == 'compute']
|
||||
|
||||
created_instances = []
|
||||
for _ in compute_nodes[:CONF.compute.min_compute_nodes]:
|
||||
# by getting to active state here, this means this has
|
||||
# landed on the host in question.
|
||||
instance = self.create_server(image_id=CONF.compute.image_ref,
|
||||
wait_until='ACTIVE',
|
||||
clients=self.os_primary)
|
||||
# get instance object again as admin
|
||||
instance = self.mgr.servers_client.show_server(
|
||||
instance['id'])['server']
|
||||
created_instances.append(instance)
|
||||
self.make_instance_statistic(instance)
|
||||
|
||||
return created_instances
|
||||
|
||||
def _pack_all_created_instances_on_one_host(self, instances):
|
||||
hypervisors = [
|
||||
hyp['hypervisor_hostname'] for hyp in self.get_hypervisors_setup()
|
||||
if hyp['state'] == 'up']
|
||||
node = hypervisors[0]
|
||||
for instance in instances:
|
||||
if instance.get('OS-EXT-SRV-ATTR:hypervisor_hostname') != node:
|
||||
self._migrate_server_to(instance['id'], node)
|
||||
|
||||
def test_execute_workload_stabilization(self):
|
||||
"""Execute an action plan using the workload_stabilization strategy"""
|
||||
self.addCleanup(self.rollback_compute_nodes_status)
|
||||
|
||||
@@ -54,108 +54,6 @@ class TestExecuteZoneMigrationStrategy(base.BaseInfraOptimScenarioTest):
|
||||
"Less than 2 compute nodes are enabled, "
|
||||
"skipping multinode tests.")
|
||||
|
||||
@classmethod
|
||||
def get_hypervisors_setup(cls):
|
||||
hypervisors_client = cls.mgr.hypervisor_client
|
||||
hypervisors = hypervisors_client.list_hypervisors(
|
||||
detail=True)['hypervisors']
|
||||
return hypervisors
|
||||
|
||||
@classmethod
|
||||
def get_compute_nodes_setup(cls):
|
||||
services_client = cls.mgr.services_client
|
||||
available_services = services_client.list_services()['services']
|
||||
|
||||
return [srv for srv in available_services
|
||||
if srv.get('binary') == 'nova-compute']
|
||||
|
||||
def _migrate_server_to(self, server_id, dest_host, volume_backed=False):
|
||||
kwargs = dict()
|
||||
kwargs['disk_over_commit'] = False
|
||||
block_migration = (CONF.compute_feature_enabled.
|
||||
block_migration_for_live_migration and
|
||||
not volume_backed)
|
||||
body = self.mgr.servers_client.live_migrate_server(
|
||||
server_id, host=dest_host, block_migration=block_migration,
|
||||
**kwargs)
|
||||
return body
|
||||
|
||||
@classmethod
|
||||
def wait_for_compute_node_setup(cls):
|
||||
|
||||
def _are_compute_nodes_setup():
|
||||
try:
|
||||
hypervisors = cls.get_hypervisors_setup()
|
||||
available_hypervisors = set(
|
||||
hyp['hypervisor_hostname'] for hyp in hypervisors
|
||||
if hyp['state'] == 'up')
|
||||
available_services = set(
|
||||
service['host']
|
||||
for service in cls.get_compute_nodes_setup()
|
||||
if service['state'] == 'up')
|
||||
return (
|
||||
len(available_hypervisors) == len(available_services) and
|
||||
len(hypervisors) >= 2)
|
||||
except Exception as exc:
|
||||
LOG.exception(exc)
|
||||
return False
|
||||
|
||||
assert test_utils.call_until_true(
|
||||
func=_are_compute_nodes_setup,
|
||||
duration=600,
|
||||
sleep_for=2
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def rollback_compute_nodes_status(cls):
|
||||
current_compute_nodes_setup = cls.get_compute_nodes_setup()
|
||||
for cn_setup in current_compute_nodes_setup:
|
||||
cn_hostname = cn_setup.get('host')
|
||||
matching_cns = [
|
||||
cns for cns in cls.initial_compute_nodes_setup
|
||||
if cns.get('host') == cn_hostname
|
||||
]
|
||||
initial_cn_setup = matching_cns[0] # Should return a single result
|
||||
if cn_setup.get('status') != initial_cn_setup.get('status'):
|
||||
if initial_cn_setup.get('status') == 'enabled':
|
||||
rollback_func = cls.mgr.services_client.enable_service
|
||||
else:
|
||||
rollback_func = cls.mgr.services_client.disable_service
|
||||
rollback_func(binary='nova-compute', host=cn_hostname)
|
||||
|
||||
def _create_one_instance_per_host(self):
|
||||
"""Create 1 instance per compute node
|
||||
|
||||
This goes up to the min_compute_nodes threshold so that things don't
|
||||
get crazy if you have 1000 compute nodes but set min to 3.
|
||||
"""
|
||||
host_client = self.mgr.hosts_client
|
||||
all_hosts = host_client.list_hosts()['hosts']
|
||||
compute_nodes = [x for x in all_hosts if x['service'] == 'compute']
|
||||
|
||||
created_instances = []
|
||||
for _ in compute_nodes[:CONF.compute.min_compute_nodes]:
|
||||
# by getting to active state here, this means this has
|
||||
# landed on the host in question.
|
||||
instance = self.create_server(image_id=CONF.compute.image_ref,
|
||||
wait_until='ACTIVE',
|
||||
clients=self.os_primary)
|
||||
instance = self.mgr.servers_client.show_server(
|
||||
instance['id'])['server']
|
||||
created_instances.append(instance)
|
||||
|
||||
return created_instances
|
||||
|
||||
def _pack_all_created_instances_on_one_host(self, instances):
|
||||
hypervisors = [
|
||||
hyp['hypervisor_hostname'] for hyp in self.get_hypervisors_setup()
|
||||
if hyp['state'] == 'up']
|
||||
node = hypervisors[0]
|
||||
for instance in instances:
|
||||
if instance.get('OS-EXT-SRV-ATTR:hypervisor_hostname') != node:
|
||||
self._migrate_server_to(instance['id'], node)
|
||||
return node
|
||||
|
||||
def test_execute_zone_migration_live_migration(self):
|
||||
"""Execute an action plan using the zone migration strategy"""
|
||||
self.addCleanup(self.rollback_compute_nodes_status)
|
||||
|
||||
Reference in new issue
Block a user