Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cert inheritance tests to match new xapi behavior #93

Merged
merged 3 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import logging
import pytest
import tempfile

from packaging import version

import lib.config as global_config

from lib.common import wait_for, vm_image, is_uuid
from lib.common import setup_formatted_and_mounted_disk, teardown_formatted_and_mounted_disk
from lib.pool import Pool
Expand Down Expand Up @@ -78,38 +82,27 @@ def pytest_configure(config):
global_config.ignore_ssh_banner = config.getoption('--ignore-ssh-banner')
global_config.ssh_output_max_lines = int(config.getoption('--ssh-output-max-lines'))

def host_data(hostname_or_ip):
# read from data.py
from data import HOST_DEFAULT_USER, HOST_DEFAULT_PASSWORD, HOSTS
if hostname_or_ip in HOSTS:
h_data = HOSTS[hostname_or_ip]
return h_data
else:
return {'user': HOST_DEFAULT_USER, 'password': HOST_DEFAULT_PASSWORD}

def setup_host(hostname_or_ip):
logging.info(">>> Connect host %s" % hostname_or_ip)
pool = Pool(hostname_or_ip)
h = pool.master
# XO connection
h_data = host_data(hostname_or_ip)
skip_xo_config = h_data.get('skip_xo_config', False)
if not skip_xo_config:
h.xo_server_add(h_data['user'], h_data['password'])
if not h.skip_xo_config:
h.xo_server_add(h.user, h.password)
else:
h.xo_get_server_id(store=True)
wait_for(h.xo_server_connected, timeout_secs=10)
return h, skip_xo_config
return h

@pytest.fixture(scope='session')
def hosts(request):
# a list of master hosts, each from a different pool
hostname_list = request.param.split(',')
host_list = [setup_host(hostname_or_ip) for hostname_or_ip in hostname_list]
yield [tup[0] for tup in host_list]
yield host_list
# teardown
for h, skip_xo_config in host_list:
if not skip_xo_config:
for h in host_list:
if not h.skip_xo_config:
logging.info("<<< Disconnect host %s" % h)
h.xo_server_remove()

Expand Down Expand Up @@ -140,6 +133,18 @@ def hostB1(hosts):
logging.info(">>> hostB1 present: %s" % _hostB1)
yield _hostB1

@pytest.fixture(scope='session')
def host_at_least_8_3(host):
version_str = "8.3"
if not host.xcp_version >= version.parse(version_str):
pytest.skip(f"This test requires an XCP-ng >= {version_str} host")

@pytest.fixture(scope='session')
def host_less_than_8_3(host):
version_str = "8.3"
if not host.xcp_version < version.parse(version_str):
pytest.skip(f"This test requires an XCP-ng < {version_str} host")

@pytest.fixture(scope='session')
def local_sr_on_hostA1(hostA1):
""" A local SR on the pool's master. """
Expand Down
40 changes: 37 additions & 3 deletions lib/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,42 @@
import shlex
import tempfile

from packaging import version

import lib.commands as commands

from lib.common import safe_split, to_xapi_bool, wait_for, wait_for_not
from lib.sr import SR
from lib.vm import VM
from lib.xo import xo_cli, xo_object_exists

def host_data(hostname_or_ip):
# read from data.py
from data import HOST_DEFAULT_USER, HOST_DEFAULT_PASSWORD, HOSTS
if hostname_or_ip in HOSTS:
h_data = HOSTS[hostname_or_ip]
return h_data
else:
return {'user': HOST_DEFAULT_USER, 'password': HOST_DEFAULT_PASSWORD}

class Host:
def __init__(self, pool, hostname_or_ip):
self.pool = pool
self.hostname_or_ip = hostname_or_ip
self.inventory = None
self.uuid = None
self.xo_srv_id = None
self.user = None
self.password = None

h_data = host_data(self.hostname_or_ip)
self.user = h_data['user']
self.password = h_data['password']
self.skip_xo_config = h_data.get('skip_xo_config', False)

self.saved_packages_list = None
self.saved_rollback_id = None
self.inventory = self._get_xensource_inventory()
self.uuid = self.inventory['INSTALLATION_UUID']
self.xcp_version = version.parse(self.inventory['PRODUCT_VERSION'])

def __str__(self):
return self.hostname_or_ip
Expand Down Expand Up @@ -173,7 +189,7 @@ def install_updates(self):

def restart_toolstack(self, verify=False):
logging.info("Restart toolstack on host %s" % self)
return self.ssh(['xe-toolstack-restart'])
self.ssh(['xe-toolstack-restart'])
if verify:
wait_for(self.is_enabled, "Wait for host enabled")

Expand Down Expand Up @@ -342,3 +358,21 @@ def call_plugin(self, plugin_name, function, args=None):
for k, v in args.items():
params['args:%s' % k] = v
return self.xe('host-call-plugin', params)

def join_pool(self, pool):
master = pool.master
self.xe('pool-join', {
'master-address': master.hostname_or_ip,
'master-username': master.user,
'master-password': master.password
})
wait_for(
lambda: self.uuid in pool.hosts_uuids(),
f"Wait for joining host {self} to appear in joined pool {master}."
)
pool.hosts.append(Host(pool, pool.host_ip(self.uuid)))
# Do not use `self.is_enabled` since it'd ask the XAPi of hostB1 before the join...
wait_for(
lambda: master.xe('host-param-get', {'uuid': self.uuid, 'param-name': 'enabled'}),
f"Wait for pool {master} to see joined host {self} as enabled."
)
9 changes: 8 additions & 1 deletion lib/pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lib.commands as commands

from lib.common import safe_split
from lib.common import safe_split, wait_for, wait_for_not
from lib.host import Host
from lib.sr import SR

Expand Down Expand Up @@ -136,3 +136,10 @@ def install_custom_uefi_certs(self, auths):
host.ssh(['secureboot-certs', 'install'] + params)
finally:
host.ssh(['rm', '-f'] + list(auths_dict.values()))

def eject_host(self, host):
master = self.master
master.xe('pool-eject', {'host-uuid': host.uuid, 'force': True})
wait_for_not(lambda: host.uuid in self.hosts_uuids(), "Wait for host {host} to be ejected of pool {master}.")
benjamreis marked this conversation as resolved.
Show resolved Hide resolved
self.hosts = [h for h in self.hosts if h.uuid != host.uuid]
wait_for(host.is_enabled, f"Wait for host {host} to restart in its own pool.", timeout_secs=600)
Loading