aboutsummaryrefslogtreecommitdiffstats
path: root/yardstick/network_services/vnf_generic/vnfdgen.py
diff options
context:
space:
mode:
authorDeepak S <deepak.s@linux.intel.com>2016-12-30 09:21:22 -0800
committerDeepak S <deepak.s@linux.intel.com>2017-01-19 08:27:31 +0530
commita8075ff20b2046f847b91085aa27f2b336823337 (patch)
tree035dbed36ffb23ac4ced52bd06394c4fb159db03 /yardstick/network_services/vnf_generic/vnfdgen.py
parent6f8fbe8acb94448ef2eb188193e9bea534021e89 (diff)
Introducing Generic framework to do pre-deployment VNF & Network service testing
This patch introduces the framework which is aligned with ETSI-TST001 This patch adds: 1. NetworkServiceTestCase introduces following functions --> setup --> Verify if infrastructure mapping can meet topology --> Load VNF models --> Fill traffic profile with information from topology --> Provision VNFs --> Run experiment (traffic) --> run -> Yardstick calls run() at intervals defined in the yaml and produces timestamped samples --> teardown --> Stop VNFs 2. TrafficProfile is a generic class to get traffic profile for a given testcase and select the traffic generator for testcase. 3. QueueFileWrapper is a class to send/recive cmds to vnf 4. GenericVNF is a generic class to instantiate VNF 5. GenericTrafficGen is a generic class to run/listen/verify traffic. JIRA: YARDSTICK-483 Change-Id: Ic453c917d34dcb508a7f3afb459011da85f6402e Signed-off-by: Deepak S <deepak.s@linux.intel.com>
Diffstat (limited to 'yardstick/network_services/vnf_generic/vnfdgen.py')
-rw-r--r--yardstick/network_services/vnf_generic/vnfdgen.py71
1 files changed, 71 insertions, 0 deletions
diff --git a/yardstick/network_services/vnf_generic/vnfdgen.py b/yardstick/network_services/vnf_generic/vnfdgen.py
new file mode 100644
index 000000000..9a02050a2
--- /dev/null
+++ b/yardstick/network_services/vnf_generic/vnfdgen.py
@@ -0,0 +1,71 @@
+# Copyright (c) 2016-2017 Intel Corporation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+""" Generic file to map and build vnf discriptor """
+
+from __future__ import absolute_import
+import collections
+import yaml
+import six
+
+from yardstick.common.task_template import TaskTemplate
+
+
+def generate_vnfd(vnf_model, node):
+ """
+
+ :param vnf_model: VNF definition template, e.g. tg_ping_tpl.yaml
+ :param node: node configuration taken from pod.yaml
+ :return: Complete VNF Descriptor that will be taken
+ as input for GenericVNF.__init__
+ """
+ node["get"] = get
+ rendered_vnfd = TaskTemplate.render(vnf_model, **node)
+ # This is done to get rid of issues with serializing node
+ del node["get"]
+ filled_vnfd = yaml.load(rendered_vnfd)
+ return filled_vnfd
+
+
+def dict_key_flatten(data):
+ """ Convert nested dict structure to dotted key
+ (e.g. {"a":{"b":1}} -> {"a.b":1}
+
+ :param data: nested dictionary
+ :return: flat dicrionary
+ """
+ next_data = {}
+
+ if not any((isinstance(v, collections.Iterable) and not isinstance(v, str))
+ for v in data.values()):
+ return data
+
+ for key, val in six.iteritems(data):
+ if isinstance(val, collections.Mapping):
+ for n_k, n_v in six.iteritems(val):
+ next_data["%s.%s" % (key, n_k)] = n_v
+ elif isinstance(val, collections.Iterable) and not isinstance(val,
+ str):
+ for index, item in enumerate(val):
+ next_data["%s%d" % (key, index)] = item
+ else:
+ next_data[key] = val
+
+ return dict_key_flatten(next_data)
+
+
+def get(obj, key, *args):
+ """ Get template key from dictionary, get default value or raise an exception
+ """
+ data = dict_key_flatten(obj)
+ return data.get(key, *args)