aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yardstick/orchestrator/kubernetes.py19
-rw-r--r--yardstick/tests/unit/orchestrator/test_kubernetes.py10
2 files changed, 28 insertions, 1 deletions
diff --git a/yardstick/orchestrator/kubernetes.py b/yardstick/orchestrator/kubernetes.py
index 44a333e4b..231a03b13 100644
--- a/yardstick/orchestrator/kubernetes.py
+++ b/yardstick/orchestrator/kubernetes.py
@@ -9,10 +9,12 @@
import copy
+from oslo_serialization import jsonutils
+
from yardstick.common import constants
from yardstick.common import exceptions
-from yardstick.common import utils
from yardstick.common import kubernetes_utils as k8s_utils
+from yardstick.common import utils
class ContainerObject(object):
@@ -71,6 +73,7 @@ class KubernetesObject(object):
self.ssh_key = parameters.pop('ssh_key', self.SSHKEY_DEFAULT)
self._volumes = parameters.pop('volumes', [])
self._security_context = parameters.pop('securityContext', None)
+ self._networks = parameters.pop('networks', [])
containers = parameters.pop('containers', None)
if containers:
@@ -107,6 +110,7 @@ class KubernetesObject(object):
self._add_node_selector()
self._add_volumes()
self._add_security_context()
+ self._add_networks()
def get_template(self):
return self.template
@@ -164,6 +168,19 @@ class KubernetesObject(object):
'spec.template.spec.securityContext',
self._security_context)
+ def _add_networks(self):
+ networks = []
+ for net in self._networks:
+ networks.append({'name': net})
+
+ if not networks:
+ return
+
+ annotations = {'networks': jsonutils.dumps(networks)}
+ utils.set_dict_value(self.template,
+ 'spec.template.metadata.annotations',
+ annotations)
+
class ServiceObject(object):
diff --git a/yardstick/tests/unit/orchestrator/test_kubernetes.py b/yardstick/tests/unit/orchestrator/test_kubernetes.py
index e45545d6a..fe9e2fd2b 100644
--- a/yardstick/tests/unit/orchestrator/test_kubernetes.py
+++ b/yardstick/tests/unit/orchestrator/test_kubernetes.py
@@ -208,6 +208,16 @@ class KubernetesObjectTestCase(base.BaseUnitTestCase):
self.assertEqual({'key%s' % i: 'value%s' % i},
container['securityContext'])
+ def test__add_networks(self):
+ k8s_obj = kubernetes.KubernetesObject(
+ 'name', networks=['network1', 'network2', 'network3'])
+ k8s_obj._add_networks()
+ networks = k8s_obj.\
+ template['spec']['template']['metadata']['annotations']['networks']
+ expected = ('[{"name": "network1"}, {"name": "network2"}, '
+ '{"name": "network3"}]')
+ self.assertEqual(expected, networks)
+
class ContainerObjectTestCase(base.BaseUnitTestCase):