From 6b729ca1d341534ba297e699fabd4ed58532391d Mon Sep 17 00:00:00 2001 From: jamepark4 Date: Tue, 27 Aug 2024 14:11:13 -0400 Subject: [PATCH] Verify vTPM creation after svc restart Ensure that vTPM creation is still possible after restarting the nova libvirt service. Also added a new client service for virtqemud that can start/stop the service. Updated the nova waiter to allow for checking status for either nova_compute or virtqemud. Originally the nova waiter would rely on just looking at results of compute services, specifically the state field to determine if nova_compute is up or down. Extend the nova waiter to check either the state field or the status field based on the service that is calling. Change-Id: I5895602b33c78698beec363fbc00bca876b3cefa --- .../api/compute/test_vtpm.py | 10 ++++++ whitebox_tempest_plugin/common/waiters.py | 4 +-- whitebox_tempest_plugin/services/clients.py | 34 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/whitebox_tempest_plugin/api/compute/test_vtpm.py b/whitebox_tempest_plugin/api/compute/test_vtpm.py index 659d066d..c2e517f8 100644 --- a/whitebox_tempest_plugin/api/compute/test_vtpm.py +++ b/whitebox_tempest_plugin/api/compute/test_vtpm.py @@ -18,6 +18,7 @@ from tempest.exceptions import BuildErrorException from tempest.lib.services import clients from whitebox_tempest_plugin.api.compute import base +from whitebox_tempest_plugin.services import clients as wb_clients CONF = config.CONF @@ -124,3 +125,12 @@ class VTPMTest(base.BaseWhiteboxComputeTest): self.create_test_server, flavor=vtpm_flavor['id'], wait_until='ACTIVE') + + def test_vtpm_creation_after_virtqemud_restart(self): + # Test validates vTPM instance creation after libvirt service restart + hosts = self.list_compute_hosts() + for host in hosts: + host_svc = wb_clients.VirtQEMUdManager( + host, 'libvirt', self.os_admin.services_client) + host_svc.restart() + self._vptm_server_creation_check('tpm-crb', '2.0') diff --git a/whitebox_tempest_plugin/common/waiters.py b/whitebox_tempest_plugin/common/waiters.py index 017ea787..5dde6a62 100644 --- a/whitebox_tempest_plugin/common/waiters.py +++ b/whitebox_tempest_plugin/common/waiters.py @@ -19,14 +19,14 @@ from tempest.lib import exceptions as lib_exc from whitebox_tempest_plugin.exceptions import MigrationException -def wait_for_nova_service_state(client, host, binary, state): +def wait_for_nova_service_state(client, host, binary, status_field, state): timeout = client.build_timeout start_time = int(time.time()) # NOTE(artom) Assumes that the (host, binary) combination will yield a # unique service. There is no service in Nova that can run multiple copies # on the same host. service = client.list_services(host=host, binary=binary)['services'][0] - while service['state'] != state: + while service[status_field] != state: time.sleep(client.build_interval) timed_out = int(time.time()) - start_time >= timeout if timed_out: diff --git a/whitebox_tempest_plugin/services/clients.py b/whitebox_tempest_plugin/services/clients.py index a414815f..10f94ef6 100644 --- a/whitebox_tempest_plugin/services/clients.py +++ b/whitebox_tempest_plugin/services/clients.py @@ -232,12 +232,14 @@ class NovaServiceManager(ServiceManager): super(NovaServiceManager, self).__init__(host, service) self.services_client = services_client self.host = host + self.status_field = 'state' def start(self): result = self.execute(self.start_command, sudo=True) waiters.wait_for_nova_service_state(self.services_client, self.host, self.service, + self.status_field, 'up') return result @@ -246,6 +248,7 @@ class NovaServiceManager(ServiceManager): waiters.wait_for_nova_service_state(self.services_client, self.host, self.service, + self.status_field, 'down') return result @@ -264,6 +267,37 @@ class NovaServiceManager(ServiceManager): return hardware.parse_cpu_spec(dedicated_set) +class VirtQEMUdManager(ServiceManager): + """A services manager for Nova services that uses Nova's service API to be + smarter about stopping and restarting services. + """ + + def __init__(self, host, service, services_client): + super(VirtQEMUdManager, self).__init__(host, service) + self.services_client = services_client + self.binary = 'nova-compute' + self.host = host + self.status_field = 'status' + + def start(self): + result = self.execute(self.start_command, sudo=True) + waiters.wait_for_nova_service_state(self.services_client, + self.host, + self.binary, + self.status_field, + 'enabled') + return result + + def stop(self): + result = self.execute(self.stop_command, sudo=True) + waiters.wait_for_nova_service_state(self.services_client, + self.host, + self.binary, + self.status_field, + 'disabled') + return result + + class NUMAClient(SSHClient): """A client to get host NUMA information. `numactl` needs to be installed in the environment or container(s).