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
This commit is contained in:
jamepark4 2024-08-27 14:11:13 -04:00
parent 2a09062deb
commit 6b729ca1d3
3 changed files with 46 additions and 2 deletions

View File

@ -18,6 +18,7 @@ from tempest.exceptions import BuildErrorException
from tempest.lib.services import clients from tempest.lib.services import clients
from whitebox_tempest_plugin.api.compute import base from whitebox_tempest_plugin.api.compute import base
from whitebox_tempest_plugin.services import clients as wb_clients
CONF = config.CONF CONF = config.CONF
@ -124,3 +125,12 @@ class VTPMTest(base.BaseWhiteboxComputeTest):
self.create_test_server, self.create_test_server,
flavor=vtpm_flavor['id'], flavor=vtpm_flavor['id'],
wait_until='ACTIVE') 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')

View File

@ -19,14 +19,14 @@ from tempest.lib import exceptions as lib_exc
from whitebox_tempest_plugin.exceptions import MigrationException 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 timeout = client.build_timeout
start_time = int(time.time()) start_time = int(time.time())
# NOTE(artom) Assumes that the (host, binary) combination will yield a # NOTE(artom) Assumes that the (host, binary) combination will yield a
# unique service. There is no service in Nova that can run multiple copies # unique service. There is no service in Nova that can run multiple copies
# on the same host. # on the same host.
service = client.list_services(host=host, binary=binary)['services'][0] service = client.list_services(host=host, binary=binary)['services'][0]
while service['state'] != state: while service[status_field] != state:
time.sleep(client.build_interval) time.sleep(client.build_interval)
timed_out = int(time.time()) - start_time >= timeout timed_out = int(time.time()) - start_time >= timeout
if timed_out: if timed_out:

View File

@ -232,12 +232,14 @@ class NovaServiceManager(ServiceManager):
super(NovaServiceManager, self).__init__(host, service) super(NovaServiceManager, self).__init__(host, service)
self.services_client = services_client self.services_client = services_client
self.host = host self.host = host
self.status_field = 'state'
def start(self): def start(self):
result = self.execute(self.start_command, sudo=True) result = self.execute(self.start_command, sudo=True)
waiters.wait_for_nova_service_state(self.services_client, waiters.wait_for_nova_service_state(self.services_client,
self.host, self.host,
self.service, self.service,
self.status_field,
'up') 'up')
return result return result
@ -246,6 +248,7 @@ class NovaServiceManager(ServiceManager):
waiters.wait_for_nova_service_state(self.services_client, waiters.wait_for_nova_service_state(self.services_client,
self.host, self.host,
self.service, self.service,
self.status_field,
'down') 'down')
return result return result
@ -264,6 +267,37 @@ class NovaServiceManager(ServiceManager):
return hardware.parse_cpu_spec(dedicated_set) 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): class NUMAClient(SSHClient):
"""A client to get host NUMA information. `numactl` needs to be installed """A client to get host NUMA information. `numactl` needs to be installed
in the environment or container(s). in the environment or container(s).