Skip to content

Commit

Permalink
[sunbeam][tests] Add product tests for sunbeam
Browse files Browse the repository at this point in the history
* Move the juju tests now to sunbeam, now that we deploy using juju here
* Start testing kubernetes as well, initial tests for microk8s, more to follow

Related: #3622

Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali committed Nov 15, 2024
1 parent 20fc35f commit 0a746f3
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 265 deletions.
23 changes: 23 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ env:
curl --fail --location -O
--url https://api.cirrus-ci.com/v1/artifact/build/${CIRRUS_BUILD_ID}
SUNBEAM_VER: "2024.1/beta"

# Default task timeout
timeout_in: 30m

Expand Down Expand Up @@ -343,3 +345,24 @@ report_foreman_task:
on_failure:
fail_script: *faillogs
log_artifacts: *logs

report_sunbeam_task:
skip: "!changesInclude('.cirrus.yml', '**/{__init__,sunbeam,sunbeam_hypervisor,kubernetes,microk8s,k8s,ovn_host}.py', '**/sunbeam_setup.sh')"
timeout_in: 90m
alias: "sunbeam_integration"
name: "Integration Test - Sunbeam ${SUNBEAM_VER} - ${BUILD_NAME}"
depends_on: stageone_report
gce_instance: &xbigvm
<<: *standardvm
type: e2-standard-4
disk: 50
environment:
SUNBEAM_VER: ${SUNBEAM_VER}
matrix:
- env: *ubuntuprior
setup_script: *setup
sunbeam_setup_script: ./tests/test_data/sunbeam_setup.sh
main_script: PYTHONPATH=tests/ avocado run -p TESTLOCAL=true --max-parallel-tasks=1 -t sunbeam tests/product_tests/sunbeam/
on_failure:
fail_script: *faillogs
log_artifacts: *logs
Empty file.
88 changes: 88 additions & 0 deletions tests/product_tests/sunbeam/juju_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.

from sos_tests import StageOneReportTest


class JujuBasicTest(StageOneReportTest):
"""Ensure that a basic execution runs as expected with simple deployment.
:avocado: tags=sunbeam
"""

sos_cmd = '-v -o juju'
arch = ['x86_64']

ubuntu_only = True

def test_unit_agent_conf_collected(self):
self.assertFileCollected('/var/lib/juju/agents/machine-0/agent.conf')
self.assertFileCollected('/var/log/juju/machine-0.log')

# def test_unit_commands_collected(self):
# cmds_to_check = [
# 'juju_engine_report',
# 'juju_goroutines',
# 'juju_heap_profile',
# 'juju_leases',
# 'juju_metrics',
# 'juju_pubsub_report',
# 'juju_presence_report',
# 'juju_statepool_report',
# 'juju_statetracker_report',
# 'juju_unit_status',
# ]
#
# for the_cmd in cmds_to_check:
# self.assertFileCollected(f'sos_commands/juju/{the_cmd}')

def test_unit_agent_conf_cert_scrubbed(self):
file = '/var/lib/juju/agents/machine-0/agent.conf'

check_cert_scrub = [
"cacert",
"controllercert",
]
for cert in check_cert_scrub:
self.assertFileHasContent(
file, f'{cert}: |\n -----SCRUBBED CERTIFICATE-----')

def test_unit_agent_conf_private_cert_scrubbed(self):
file = '/var/lib/juju/agents/machine-0/agent.conf'
check_priv_key = [
"controllerkey",
"caprivatekey",
]
for priv in check_priv_key:
self.assertFileHasContent(
file, f'{priv}: |\n -----SCRUBBED PRIVATE KEY-----')

def test_unit_agent_conf_private_cert_rsa_scrubbed(self):
file = '/var/lib/juju/agents/machine-0/agent.conf'
check_priv_rsa_key = [
"systemidentity",
]

for priv_rsa in check_priv_rsa_key:
self.assertFileHasContent(
file, f'{priv_rsa}: |\n -----SCRUBBED RSA PRIVATE KEY-----')

def test_unit_agent_conf_secrets_scrubbed(self):
file = '/var/lib/juju/agents/machine-0/agent.conf'

check_key_scrub = [
"sharedsecret",
"apipassword",
"oldpassword",
"statepassword",
]

for key in check_key_scrub:
self.assertFileHasContent(file, rf'{key}: \*\*\*\*\*\*\*\*\*')

# vim: et ts=4 sw=4
42 changes: 42 additions & 0 deletions tests/product_tests/sunbeam/kubernetes_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.

from sos_tests import StageOneReportTest


class K8sBasicTest(StageOneReportTest):
"""Ensure that a basic execution runs as expected with simple deployment.
:avocado: tags=sunbeam
"""

sos_cmd = '-v -o microk8s,kubernetes'
arch = ['x86_64']

ubuntu_only = True

microk8s_cmd = "microk8s"

def test_client_config_collected(self):
self.assertFileCollected(
'/var/snap/microk8s/current/credentials/client.config')

def test_microk8s_cmd_ran(self):
ran_cmds = [
f"{self.microk8s_cmd}_addons_repo_list",
f"{self.microk8s_cmd}_config",
f"{self.microk8s_cmd}_ctr_plugins_ls",
f"{self.microk8s_cmd}_ctr_plugins_ls_-d",
f"{self.microk8s_cmd}_status",
f"{self.microk8s_cmd}_version",
]
for cmd_run in ran_cmds:
self.assertFileCollected(f'sos_commands/microk8s/{cmd_run}')


# vim: et ts=4 sw=4
116 changes: 116 additions & 0 deletions tests/product_tests/sunbeam/sunbeam_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# This file is part of the sos project: https://github.com/sosreport/sos
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# version 2 of the GNU General Public License.
#
# See the LICENSE file in the source distribution for further information.

from sos_tests import StageOneReportTest


class SunbeamBasicTest(StageOneReportTest):
"""Ensure that a basic execution runs as expected with simple deployment.
:avocado: tags=sunbeam
"""

sos_cmd = '-v'
arch = ['x86_64']

ubuntu_only = True
sos_timeout = 1200

sunbeam_common = "/var/snap/openstack/common"
sunbeam_current = "/var/snap/openstack/current"

hypervisor_common = "/var/snap/openstack-hypervisor/common"

check_obfuscate = [
r"transport_url = \*\*\*\*\*\*\*\*\*",
r"password = \*\*\*\*\*\*\*\*\*",
]

def test_plugins_ran(self):
self.assertPluginIncluded([
'juju',
'libvirt',
'kubernetes',
'ovn_host',
'sunbeam',
'sunbeam_hypervisor',
])

def test_sunbeam_keys_skipped(self):
self.assertFileGlobNotInArchive(
f"{self.hypervisor_common}/etc/pki/**/*.pem")
self.assertFileGlobNotInArchive(
f"{self.hypervisor_common}/etc/ssl/**/*.pem")

def test_sunbeam_installer_dirs_collected(self):
self.assertFileGlobInArchive("/etc/sunbeam-installer/*")
self.assertFileGlobInArchive("/var/log/sunbeam-installer/*")

def test_sunbeam_openstack_config_files_collected(self):
files_collected = [
f'{self.sunbeam_common}/state/daemon.yaml',
f'{self.sunbeam_common}/state/database/info.yaml',
f'{self.sunbeam_common}/state/database/cluster.yaml',
f'{self.sunbeam_current}/config.yaml',
]
for file in files_collected:
self.assertFileCollected(file)

def test_sunbeam_nova_log_collected(self):
self.assertFileCollected(
f'{self.hypervisor_common}/var/log/nova/nova.log')

def test_sunbeam_neutron_log_collected(self):
self.assertFileCollected(
f'{self.hypervisor_common}/var/log/neutron/neutron.log')

def test_sunbeam_ovn_controller_log_collected(self):
self.assertFileCollected(
f'{self.hypervisor_common}/var/log/ovn/ovn-controller.log')

def test_sunbeam_openvswitch_log_collected(self):
self.assertFileCollected(
f'{self.hypervisor_common}/var/log/openvswitch/ovs-vswitchd.log')
self.assertFileCollected(
f'{self.hypervisor_common}/var/log/openvswitch/ovsdb-server.log')

def test_sunbeam_cluster_list_collected_(self):
self.assertFileCollected('sos_commands/sunbeam/sunbeam_cluster_list')

def test_sunbeam_juju_configs_controller_collected(self):
files_collected = [
'juju_status_-m_sunbeam-controller_admin.controller',
'juju_model-config_-m_sunbeam-controller_admin.controller',
]

for file in files_collected:
self.assertFileCollected(f'sos_commands/sunbeam/sunbeam/{file}')

def test_sunbeam_nova_conf_collected_and_obfuscated(self):
nova_conf = f'{self.hypervisor_common}/etc/nova/nova.conf'
self.assertFileCollected(nova_conf)

for check in self.check_obfuscate:
self.assertFileHasContent(nova_conf, check)

def test_sunbeam_neutron_conf_collected_and_obfuscated(self):
neutron_conf = f'{self.hypervisor_common}/etc/neutron/neutron.conf'
self.assertFileCollected(neutron_conf)

for check in self.check_obfuscate:
self.assertFileHasContent(neutron_conf, check)

def test_sunbeam_ceilometer_conf_collected_and_obfuscated(self):
ceilometer_conf = (f'{self.hypervisor_common}/etc/ceilometer/'
'ceilometer.conf')
self.assertFileCollected(ceilometer_conf)

for check in self.check_obfuscate:
self.assertFileHasContent(ceilometer_conf, check)

# vim: et ts=4 sw=4
Loading

0 comments on commit 0a746f3

Please sign in to comment.