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, no
  need to mock the configuration files.
* Include plugins that are associated here
  - kubernetes
  - ovn_host
  - juju

Related: #3622

Signed-off-by: Arif Ali <[email protected]>
  • Loading branch information
arif-ali committed Dec 5, 2024
1 parent 77a2a55 commit 1b82d01
Show file tree
Hide file tree
Showing 10 changed files with 387 additions and 265 deletions.
23 changes: 23 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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 @@ -340,3 +342,24 @@ report_foreman_task:
on_failure:
fail_script: *faillogs
log_artifacts: *logs

report_sunbeam_task:
skip: "!changesInclude('.cirrus.yml', '**/{__init__,sunbeam,sunbeam_hypervisor,juju,kubernetes,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-8
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.
90 changes: 90 additions & 0 deletions tests/product_tests/sunbeam/juju_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright (C) 2024 Canonical Ltd., Arif Ali <[email protected]>

# 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
93 changes: 93 additions & 0 deletions tests/product_tests/sunbeam/kubernetes_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Copyright (C) 2024 Canonical Ltd., Arif Ali <[email protected]>

# 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 kubernetes'
arch = ['x86_64']

ubuntu_only = True

k8s_cmd = "k8s"

def test_k8s_config_collected(self):
k8s_common = "/var/snap/k8s/common"

k8s_files = [
f"{k8s_common}/args",
f"{k8s_common}/var/lib/k8s-dqlite/info.yaml",
f"{k8s_common}/var/lib/k8s-dqlite/cluster.yaml",
f"{k8s_common}/var/lib/k8sd/state/truststore/k8s.yaml",
f"{k8s_common}/var/lib/k8sd/state/database/info.yaml",
f"{k8s_common}/var/lib/k8sd/state/database/cluster.yaml",
f"{k8s_common}/var/lib/k8sd/state/daemon.yaml",
]

for file in k8s_files:
self.assertFileCollected(file)

def test_k8s_cmd_ran(self):
ran_cmds = [
"status",
"get",
]
for cmd_run in ran_cmds:
self.assertFileCollected(
f'sos_commands/kubernetes/{self.k8s_cmd}_{cmd_run}')

def test_kubectl_cmd_ran(self):
kube_cmd = f"{self.k8s_cmd}_kubectl"

ran_cmds = [
'config_view',
'get_--all-namespaces_true_clusterrolebindings',
'get_--all-namespaces_true_clusterroles',
'get_--all-namespaces_true_configmaps',
'get_--all-namespaces_true_cronjobs',
'get_--all-namespaces_true_daemonsets',
'get_--all-namespaces_true_deployments',
'get_--all-namespaces_true_endpoints',
'get_--all-namespaces_true_events',
'get_--all-namespaces_true_ingresses',
'get_--all-namespaces_true_jobs',
'get_--all-namespaces_true_limitranges',
'get_--all-namespaces_true_pods',
'get_--all-namespaces_true_pvc',
'get_--all-namespaces_true_replicasets',
'get_--all-namespaces_true_resourcequotas',
'get_--all-namespaces_true_secrets',
'get_--all-namespaces_true_serviceaccounts',
'get_--all-namespaces_true_services',
'get_--all-namespaces_true_statefulsets',
'get_--raw_.metrics',
'get_-o_json_nodes',
'get_namespaces',
'get_nodes',
'get_pv',
'get_rolebindings',
'get_roles',
'get_sc',
'version',
]

for cmd_run in ran_cmds:
self.assertFileCollected(
'sos_commands/kubernetes/cluster-info/'
f'{kube_cmd}_{cmd_run}')


# vim: et ts=4 sw=4
34 changes: 34 additions & 0 deletions tests/product_tests/sunbeam/ovn_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2024 Canonical Ltd., Arif Ali <[email protected]>

# 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 OvnBasicTest(StageOneReportTest):
"""Ensure that a basic execution runs as expected with simple deployment.
:avocado: tags=sunbeam
"""

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

ubuntu_only = True

def test_ovn_cmds_collected(self):
ran_cmds = [
'openstack-hypervisor.ovs-vsctl_list_Open_vSwitch',
'openstack-hypervisor.ovs-ofctl_-O_OpenFlow13_dump-flows_br-int',
'openstack-hypervisor.ovs-vsctl_list-br',
]
for cmd in ran_cmds:
self.assertFileCollected(f'sos_commands/ovn_host/{cmd}')

# vim: et ts=4 sw=4
126 changes: 126 additions & 0 deletions tests/product_tests/sunbeam/sunbeam_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# Copyright (C) 2024 Canonical Ltd., Arif Ali <[email protected]>

# 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/{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)

def test_sunbeam_masakarimonitors_conf_collected_and_obfuscated(self):
masakari_conf = (f'{self.hypervisor_common}/etc/masakarimonitors/'
'masakarimonitors.conf')
self.assertFileCollected(masakari_conf)

self.assertFileHasContent(
masakari_conf, r"password = \*\*\*\*\*\*\*\*\*")

# vim: et ts=4 sw=4
Loading

0 comments on commit 1b82d01

Please sign in to comment.