summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-07-06 12:13:48 +0100
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>2018-07-06 13:20:31 +0100
commit87b32f4366fbe25f48711a42ffd4e2d8215ce1ca (patch)
tree7e337a1296ff28f947c895a764b862ad0adfd8a1
parentab8629071966fb46a4eeac473cda3352424fa350 (diff)
Add network elements as a dict in Kubernetes context
Like in Heat context, network elements should be defined in a dictionary, using the network name as the entry key. Previous implementation: context: networks: - name: ... plugin: ... args: ... New implementation: context: networks: net_name_1: plugin: ... args: ... net_name_2: ... JIRA: YARDSTICK-1160 Change-Id: I786b06555af509440604305e2c3c2c9fe521bef8 Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
-rw-r--r--yardstick/orchestrator/kubernetes.py11
-rw-r--r--yardstick/tests/unit/orchestrator/test_kubernetes.py7
2 files changed, 8 insertions, 10 deletions
diff --git a/yardstick/orchestrator/kubernetes.py b/yardstick/orchestrator/kubernetes.py
index f690ab3e9..643b09c25 100644
--- a/yardstick/orchestrator/kubernetes.py
+++ b/yardstick/orchestrator/kubernetes.py
@@ -276,10 +276,10 @@ class CustomResourceDefinitionObject(object):
class NetworkObject(object):
- MANDATORY_PARAMETERS = {'name', 'plugin', 'args'}
+ MANDATORY_PARAMETERS = {'plugin', 'args'}
KIND = 'Network'
- def __init__(self, **kwargs):
+ def __init__(self, name, **kwargs):
if not self.MANDATORY_PARAMETERS.issubset(kwargs):
missing_parameters = ', '.join(
str(param) for param in
@@ -287,7 +287,7 @@ class NetworkObject(object):
raise exceptions.KubernetesNetworkObjectDefinitionError(
missing_parameters=missing_parameters)
- self._name = kwargs['name']
+ self._name = name
self._plugin = kwargs['plugin']
self._args = kwargs['args']
self._crd = None
@@ -377,7 +377,7 @@ class KubernetesTemplate(object):
context_cfg = copy.deepcopy(context_cfg)
servers_cfg = context_cfg.pop('servers', {})
crd_cfg = context_cfg.pop('custom_resources', [])
- networks_cfg = context_cfg.pop('networks', [])
+ networks_cfg = context_cfg.pop('networks', {})
self.name = name
self.ssh_key = '{}-key'.format(name)
@@ -389,7 +389,8 @@ class KubernetesTemplate(object):
for rc, cfg in self.rcs.items()]
self.crd = [CustomResourceDefinitionObject(self.name, **crd)
for crd in crd_cfg]
- self.network_objs = [NetworkObject(**nobj) for nobj in networks_cfg]
+ self.network_objs = [NetworkObject(net_name, **net_data)
+ for net_name, net_data in networks_cfg.items()]
self.pods = []
def _get_rc_name(self, rc_name):
diff --git a/yardstick/tests/unit/orchestrator/test_kubernetes.py b/yardstick/tests/unit/orchestrator/test_kubernetes.py
index 5eba1a02a..8e64c8fe1 100644
--- a/yardstick/tests/unit/orchestrator/test_kubernetes.py
+++ b/yardstick/tests/unit/orchestrator/test_kubernetes.py
@@ -340,13 +340,10 @@ class NetworkObjectTestCase(base.BaseUnitTestCase):
def test__init_missing_parameter(self):
with self.assertRaises(
exceptions.KubernetesNetworkObjectDefinitionError):
- kubernetes.NetworkObject(name='name', plugin='plugin')
+ kubernetes.NetworkObject('network_name', plugin='plugin')
with self.assertRaises(
exceptions.KubernetesNetworkObjectDefinitionError):
- kubernetes.NetworkObject(name='name', args='args')
- with self.assertRaises(
- exceptions.KubernetesNetworkObjectDefinitionError):
- kubernetes.NetworkObject(args='args', plugin='plugin')
+ kubernetes.NetworkObject('network_name', args='args')
@mock.patch.object(kubernetes_utils, 'get_custom_resource_definition')
def test_crd(self, mock_get_crd):