3 """Run workloads via Rally against Kubernetes platform
5 xrally/kubernetes_ provides xRally plugins for Kubernetes platform.
7 .. _xrally/kubernetes: https://github.com/xrally/xrally-kubernetes/
14 from jinja2 import Template
17 from rally import exceptions
18 from rally.common import yamlutils as yaml
19 import rally.common.logging
20 from rally.env import env_mgr
22 from xtesting.core import testcase
25 class RallyKubernetes(testcase.TestCase):
26 # pylint: disable=too-many-instance-attributes
27 """Run tasks for checking basic functionality of Kubernetes cluster"""
29 __logger = logging.getLogger(__name__)
35 def __init__(self, **kwargs):
36 super(RallyKubernetes, self).__init__(**kwargs)
37 self.dir_results = "/home/opnfv/functest/results"
38 self.res_dir = os.path.join(self.dir_results, self.case_name)
39 self.output_log_name = 'functest-kubernetes.log'
40 self.output_debug_log_name = 'functest-kubernetes.debug.log'
42 def run(self, **kwargs):
43 self.start_time = time.time()
44 if not os.path.exists(self.res_dir):
45 os.makedirs(self.res_dir)
47 api.CONF.set_default("use_stderr", False)
48 api.CONF.set_default('log_dir', self.res_dir)
49 api.CONF.set_default('log_file', 'rally.log')
50 rally.common.logging.setup("rally")
51 spec = env_mgr.EnvManager.create_spec_from_sys_environ()["spec"]
53 env_mgr.EnvManager.get('my-kubernetes').delete(force=True)
54 except exceptions.DBRecordNotFound:
56 env = env_mgr.EnvManager.create('my-kubernetes', spec)
57 result = env.check_health()
58 self.__logger.debug("check health %s: %s", 'my-kubernetes', result)
59 if not result['existing@kubernetes']['available']:
61 "Cannot check env heath: %s",
62 result['existing@kubernetes']['message'])
64 with open(pkg_resources.resource_filename(
65 'functest_kubernetes', 'rally/all-in-one.yaml')) as file:
66 template = Template(file.read())
67 task = yaml.safe_load(template.render(
68 concurrency=kwargs.get("concurrency", self.concurrency),
69 times=kwargs.get("times", self.times),
70 namespaces_count=kwargs.get(
71 "namespaces_count", self.namespaces_count)))
72 rapi.task.validate(deployment='my-kubernetes', config=task)
73 task_instance = rapi.task.create(deployment='my-kubernetes')
75 deployment='my-kubernetes', config=task,
76 task=task_instance["uuid"])
77 self.details = rapi.task.get(task_instance["uuid"], detailed=True)
78 self.__logger.debug("details: %s", self.details)
79 if self.details['pass_sla']:
81 result = rapi.task.export(
82 [task_instance["uuid"]], "html",
83 output_dest=os.path.join(
84 self.res_dir, "{}.html".format(self.case_name)))
86 for path in result["files"]:
87 with open(path, "w+") as output:
88 output.write(result["files"][path])
89 result = rapi.task.export(
90 [task_instance["uuid"]], "junit-xml",
91 output_dest=os.path.join(
92 self.res_dir, "{}.xml".format(self.case_name)))
94 for path in result["files"]:
95 with open(path, "w+") as output:
96 output.write(result["files"][path])
97 self.stop_time = time.time()