From 5c8add8e51f3cbc5f6949e890f13785502005576 Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Wed, 18 Jul 2018 16:39:17 +0100 Subject: Accept strings and lists as container "args" and "commands" Accept strings and list of strings as "args" and "commands" in a Kubernetes container. JIRA: YARDSTICK-1329 Change-Id: I56470741072fb7f9a62d695c51fcb0cc3f3ff1b9 Signed-off-by: Rodolfo Alonso Hernandez --- yardstick/orchestrator/kubernetes.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'yardstick/orchestrator') diff --git a/yardstick/orchestrator/kubernetes.py b/yardstick/orchestrator/kubernetes.py index bee4d4a78..3e2572fcc 100644 --- a/yardstick/orchestrator/kubernetes.py +++ b/yardstick/orchestrator/kubernetes.py @@ -11,6 +11,7 @@ import copy import re from oslo_serialization import jsonutils +import six from yardstick.common import constants from yardstick.common import exceptions @@ -22,7 +23,7 @@ class ContainerObject(object): SSH_MOUNT_PATH = '/tmp/.ssh/' IMAGE_DEFAULT = 'openretriever/yardstick' - COMMAND_DEFAULT = '/bin/bash' + COMMAND_DEFAULT = ['/bin/bash', '-c'] RESOURCES = ('requests', 'limits') PORT_OPTIONS = ('containerPort', 'hostIP', 'hostPort', 'name', 'protocol') IMAGE_PULL_POLICY = ('Always', 'IfNotPresent', 'Never') @@ -31,8 +32,9 @@ class ContainerObject(object): self._name = name self._ssh_key = ssh_key self._image = kwargs.get('image', self.IMAGE_DEFAULT) - self._command = [kwargs.get('command', self.COMMAND_DEFAULT)] - self._args = kwargs.get('args', []) + self._command = self._parse_commands( + kwargs.get('command', self.COMMAND_DEFAULT)) + self._args = self._parse_commands(kwargs.get('args', [])) self._volume_mounts = kwargs.get('volumeMounts', []) self._security_context = kwargs.get('securityContext') self._env = kwargs.get('env', []) @@ -40,6 +42,14 @@ class ContainerObject(object): self._ports = kwargs.get('ports', []) self._image_pull_policy = kwargs.get('imagePullPolicy') + @staticmethod + def _parse_commands(command): + if isinstance(command, six.string_types): + return [command] + elif isinstance(command, list): + return command + raise exceptions.KubernetesContainerCommandType() + def _create_volume_mounts(self): """Return all "volumeMounts" items per container""" volume_mounts_items = [self._create_volume_mounts_item(vol) -- cgit 1.2.3-korg