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 # pylint: disable=bad-continuation
65 with open(pkg_resources.resource_filename(
66 'functest_kubernetes', 'rally/all-in-one.yaml')) as tfile:
67 template = Template(tfile.read())
68 task = yaml.safe_load(template.render(
69 concurrency=kwargs.get("concurrency", self.concurrency),
70 times=kwargs.get("times", self.times),
71 namespaces_count=kwargs.get(
72 "namespaces_count", self.namespaces_count)))
73 rapi.task.validate(deployment='my-kubernetes', config=task)
74 task_instance = rapi.task.create(deployment='my-kubernetes')
76 deployment='my-kubernetes', config=task,
77 task=task_instance["uuid"])
78 self.details = rapi.task.get(task_instance["uuid"], detailed=False)
79 self.__logger.debug("details: %s", self.details)
80 if self.details['pass_sla']:
82 result = rapi.task.export(
83 [task_instance["uuid"]], "html",
84 output_dest=os.path.join(
85 self.res_dir, "{}.html".format(self.case_name)))
87 for path in result["files"]:
88 with open(path, "w+") as output:
89 output.write(result["files"][path])
90 result = rapi.task.export(
91 [task_instance["uuid"]], "junit-xml",
92 output_dest=os.path.join(
93 self.res_dir, "{}.xml".format(self.case_name)))
95 for path in result["files"]:
96 with open(path, "w+") as output:
97 output.write(result["files"][path])
98 self.stop_time = time.time()