Run sonobuoy on tests

Supported modes by sonobuoy are:
certified-conformance conformance-lite non-disruptive-conformance quick

Default to quick

Change-Id: I75cef50d022b3145719bb4271969297b5fd1beba
This commit is contained in:
Michal Nasiadka 2024-02-05 10:46:11 +00:00
parent b3c601735b
commit 41a4875323
4 changed files with 72 additions and 1 deletions

View File

@ -14,6 +14,7 @@ import logging
import os import os
import subprocess import subprocess
from pathlib import Path
from tempest import config from tempest import config
from tempest import test from tempest import test
@ -121,3 +122,47 @@ class BaseMagnumTest(test.BaseTestCase):
except Exception as e: except Exception as e:
cls.LOG.exception(e) cls.LOG.exception(e)
raise raise
@classmethod
def run_sonobuoy(cls, sonobuoy_mode="quick"):
"""Run sonobuoy
This method will run sonobuoy tests,
expects a kube.config file under /tmp/magnum-nodes/
"""
try:
cls.LOG.debug("running sonobuoy")
subprocess.check_call(["/opt/stack/bin/sonobuoy",
"run",
"--mode",
sonobuoy_mode,
"--wait",
"--kubeconfig",
"/tmp/magnum-nodes/kube.conf"])
except Exception as e:
cls.LOG.exception(e)
raise
if sonobuoy_mode != "quick":
try:
cls.LOG.debug("retrieving sonobuoy logs")
Path("/tmp/magnum-nodes/sonobuoy").mkdir(parents=True,
exist_ok=True)
subprocess.check_call(["/opt/stack/bin/sonobuoy",
"retrieve",
"--extract",
"--retrieve-path",
"/tmp/magnum-nodes/sonobuoy",
"--kubeconfig",
"/tmp/magnum-nodes/kube.conf"])
except Exception as e:
cls.LOG.exception(e)
cls.LOG.debug("Getting aggregator logs")
aggregator = subprocess.check_call(["/opt/stack/bin/kubectl",
"logs",
"sonobuoy",
"-nsonobuoy"])
with open("/tmp/magnum-nodes/sonobuoy_logs.txt") as outfile:
outfile.write(aggregator)
raise

View File

@ -161,6 +161,14 @@ class Config(object):
def set_labels(cls, config): def set_labels(cls, config):
cls.labels = ast.literal_eval(CONF.magnum.labels) cls.labels = ast.literal_eval(CONF.magnum.labels)
@classmethod
def set_run_sonobuoy(cls, config):
cls.run_sonobuoy = CONF.magnum.run_sonobuoy
@classmethod
def set_sonobuoy_mode(cls, config):
cls.sonobuoy_mode = CONF.magnum.sonobuoy_mode
@classmethod @classmethod
def setUp(cls): def setUp(cls):
cls.set_admin_creds(config) cls.set_admin_creds(config)
@ -185,3 +193,5 @@ class Config(object):
cls.set_cluster_template_id(config) cls.set_cluster_template_id(config)
cls.set_cluster_creation_timeout(config) cls.set_cluster_creation_timeout(config)
cls.set_labels(config) cls.set_labels(config)
cls.set_run_sonobuoy(config)
cls.set_sonobuoy_mode(config)

View File

@ -79,6 +79,9 @@ class ClusterTestTemplate(base.BaseTempestTest):
# NOTE (dimtruck) by default tempest sets timeout to 20 mins. # NOTE (dimtruck) by default tempest sets timeout to 20 mins.
# We need more time. # We need more time.
if config.Config.run_sonobuoy:
test_timeout = 7200
else:
test_timeout = 3600 test_timeout = 3600
self.useFixture(fixtures.Timeout(test_timeout, gentle=True)) self.useFixture(fixtures.Timeout(test_timeout, gentle=True))
@ -256,6 +259,12 @@ users:
except Exception as e: except Exception as e:
self.LOG.debug("kubectl exception: %s\n" % e) self.LOG.debug("kubectl exception: %s\n" % e)
raise raise
if config.Config.run_sonobuoy:
try:
self.run_sonobuoy(config.Config.sonobuoy_mode)
except Exception as e:
self.LOG.debug("sonobuoy exception: %s\n" % e)
raise
# test cluster delete # test cluster delete
self._delete_cluster(cluster_model.uuid) self._delete_cluster(cluster_model.uuid)

View File

@ -86,4 +86,11 @@ MagnumGroup = [
cfg.StrOpt("labels", cfg.StrOpt("labels",
default={}, default={},
help="A dict of labels to be defined in cluster template"), help="A dict of labels to be defined in cluster template"),
cfg.BoolOpt("run_sonobuoy",
default=True,
help="Specify whether to run sonobuoy in cluster creation "
"test"),
cfg.StrOpt("sonobuoy_mode",
default="conformance-lite",
help="Sonobuoy mode, default is quick"),
] ]