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):
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:
self._add_node_selector()
self._add_volumes()
self._add_security_context()
+ self._add_networks()
def get_template(self):
return self.template
'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):
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):