summaryrefslogtreecommitdiffstats
path: root/vnftest/onap
diff options
context:
space:
mode:
authorMoshe <moshehoa@amdocs.com>2018-06-20 10:23:28 +0300
committerMoshe <moshehoa@amdocs.com>2018-06-20 12:13:36 +0300
commitc7c4cc227ed9447b4fdceeceece35384404bd7ec (patch)
tree5a7900dfa5ce66c1821e2ab0719741e9cccfb126 /vnftest/onap
parente65155cab8d6d74989f1dd0bd1a493e1c91a30d9 (diff)
Add validation abilities to test cases
Change-Id: I76b28e6170d6e91836b195d58c0b882168c11a67 Issue-ID: VNFSDK-275 Signed-off-by: Moshe <moshehoa@amdocs.com> Add unit tests Issue-ID: VNFSDK-275 Change-Id: I34bc9a11e16e4092fdad3b4a1733c7219e624f5f Signed-off-by: Moshe <moshehoa@amdocs.com> add unit tests Issue-ID: VNFSDK-275 Change-Id: Ib99c3521438b002e0d8aaff9870224673e34899f Signed-off-by: Moshe <moshehoa@amdocs.com> add unit tests Issue-ID: VNFSDK-275 Change-Id: I1ac560dfb40df5f346b0db8f40b8c52a2fb6b350 Signed-off-by: Moshe <moshehoa@amdocs.com>
Diffstat (limited to 'vnftest/onap')
-rw-r--r--vnftest/onap/__init__.py7
-rw-r--r--vnftest/onap/lifecycle/__init__.py0
-rw-r--r--vnftest/onap/lifecycle/create_vf_module.yaml6
-rw-r--r--vnftest/onap/onap_api_call.py52
-rw-r--r--vnftest/onap/steps/__init__.py0
-rw-r--r--vnftest/onap/steps/validation/__init__.py0
-rw-r--r--vnftest/onap/steps/validation/aai_get_vf_module.yaml25
-rw-r--r--vnftest/onap/steps/validation/vf_module_validator.py63
8 files changed, 105 insertions, 48 deletions
diff --git a/vnftest/onap/__init__.py b/vnftest/onap/__init__.py
index 7382128..293d41b 100644
--- a/vnftest/onap/__init__.py
+++ b/vnftest/onap/__init__.py
@@ -11,10 +11,3 @@
# See the License for the specific language governing permissions and limitations under
# the License
##############################################################################
-
-from __future__ import absolute_import
-import vnftest.common.utils as utils
-
-utils.import_modules_from_package("vnftest.benchmark.contexts")
-utils.import_modules_from_package("vnftest.benchmark.runners")
-utils.import_modules_from_package("vnftest.benchmark.steps")
diff --git a/vnftest/onap/lifecycle/__init__.py b/vnftest/onap/lifecycle/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vnftest/onap/lifecycle/__init__.py
diff --git a/vnftest/onap/lifecycle/create_vf_module.yaml b/vnftest/onap/lifecycle/create_vf_module.yaml
index 1728a07..5499ee7 100644
--- a/vnftest/onap/lifecycle/create_vf_module.yaml
+++ b/vnftest/onap/lifecycle/create_vf_module.yaml
@@ -40,6 +40,12 @@ body:
requestParameters:
usePreload: true
+ userParams:
+ {% for user_parameter in user_parameters %}
+ -
+ name: {{user_parameter.name}}
+ value: {{user_parameter.value}}
+ {% endfor %}
cloudConfiguration:
lcpCloudRegionId: RegionOne
diff --git a/vnftest/onap/onap_api_call.py b/vnftest/onap/onap_api_call.py
index 417e259..9ab95e7 100644
--- a/vnftest/onap/onap_api_call.py
+++ b/vnftest/onap/onap_api_call.py
@@ -12,7 +12,6 @@
# the License
##############################################################################
from __future__ import absolute_import
-
import copy
import logging
import time
@@ -20,7 +19,7 @@ import time
import os
import yaml
-from vnftest.common import constants as consts
+from vnftest.common import constants as consts, utils
from vnftest.common import rest_client
from vnftest.common.utils import dotdict
from vnftest.common.exceptions import MandatoryKeyException, InputParameterMissing
@@ -44,10 +43,10 @@ class OnapApiCall(base.Step):
self.input_params = input_params
self.input_cfg = None
self.output_cfg = None
+
self.rest_def_file = None
self.delay = None
self.setup_done = False
- self.curr_path = os.path.dirname(os.path.abspath(__file__))
def setup(self):
options = self.step_cfg['options']
@@ -68,7 +67,7 @@ class OnapApiCall(base.Step):
value = None
if 'value' in input_parameter:
value_def = input_parameter['value']
- value = self.format_string(value_def, self.input_params)
+ value = utils.format(value_def, self.input_params)
if value is None or value == "":
raise InputParameterMissing(param_name=param_name, source="task configuration")
params[param_name] = value
@@ -92,23 +91,12 @@ class OnapApiCall(base.Step):
def run_impl(self, result):
if not self.setup_done:
self.setup()
- output = {}
params = copy.deepcopy(consts.component_constants)
self.eval_input(params)
execution_result = self.execute_operation(params)
result_body = execution_result['body']
- for output_parameter in self.output_cfg:
- param_name = output_parameter['parameter_name']
- param_value = output_parameter.get('value', "[]")
- if param_value.find("[") > -1:
- crawler_type = output_parameter.get('type', 'default')
- crawler_class = Crawler.get_cls(crawler_type)
- crawler = crawler_class()
- param_value = crawler.crawl(result_body, param_value)
- if param_value is None:
- raise MandatoryKeyException(key_name='param_path', class_name=str(result_body))
- result[param_name] = param_value
- output[param_name] = param_value
+ output = Crawler.crawl(result_body, self.output_cfg)
+ result.update(output)
return output
def execute_operation(self, params, attempt=0):
@@ -129,10 +117,8 @@ class OnapApiCall(base.Step):
def execute_operation_impl(self, params):
operation = self.load_file(params)
url = operation['url']
- headers = operation['headers']
- body = {}
- if 'body' in operation:
- body = operation['body']
+ headers = operation.get('headers', {}) or {}
+ body = operation.get('body', {}) or {}
LOG.info(url)
LOG.info(headers)
LOG.info(body)
@@ -153,30 +139,14 @@ class OnapApiCall(base.Step):
LOG.info("Results: " + str(result))
return result
- @staticmethod
- def format_string(st, params):
- if not isinstance(st, basestring):
- return st
- try:
- return st.format(**params)
- except Exception as e:
- s = str(e)
- s = s.replace("'", "")
- LOG.info(s)
- params[s] = ""
- LOG.info("param" + params[s])
- return st.format(**params)
-
def handle_sla(self, output):
if self.sla_cfg.get('action', "") == 'assert' and 'equals' in self.sla_cfg:
value_def = self.sla_cfg['value']
- value = self.format_string(value_def, output)
+ value = utils.format(value_def, output)
expected_value = self.sla_cfg['equals']
assert value == expected_value
def load_file(self, params):
- yaml_path = os.path.join(self.curr_path, self.rest_def_file)
- with open(yaml_path) as f:
- operation_template = f.read()
- operation = jinja2.Template(operation_template).render(**params)
- return yaml.load(operation)
+ operation_template = utils.resource_as_string(self.rest_def_file)
+ operation = jinja2.Template(operation_template).render(**params)
+ return yaml.load(operation)
diff --git a/vnftest/onap/steps/__init__.py b/vnftest/onap/steps/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vnftest/onap/steps/__init__.py
diff --git a/vnftest/onap/steps/validation/__init__.py b/vnftest/onap/steps/validation/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/vnftest/onap/steps/validation/__init__.py
diff --git a/vnftest/onap/steps/validation/aai_get_vf_module.yaml b/vnftest/onap/steps/validation/aai_get_vf_module.yaml
new file mode 100644
index 0000000..e57ba15
--- /dev/null
+++ b/vnftest/onap/steps/validation/aai_get_vf_module.yaml
@@ -0,0 +1,25 @@
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.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
+#
+# 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
+##############################################################################
+
+---
+method: GET
+
+url: http://{{aai_ip}}:30232/aai/v11/network/generic-vnfs/generic-vnf/{{vnf_instance_id}}/vf-modules/vf-module/{{vf_module_instance_id}}
+headers:
+ Content-Type: application/json
+ Accept: application/json
+ Authorization: Basic QUFJOkFBSQ==
+ X-FromAppId: AAI
+
+body:
diff --git a/vnftest/onap/steps/validation/vf_module_validator.py b/vnftest/onap/steps/validation/vf_module_validator.py
new file mode 100644
index 0000000..63caf58
--- /dev/null
+++ b/vnftest/onap/steps/validation/vf_module_validator.py
@@ -0,0 +1,63 @@
+##############################################################################
+# Copyright 2018 EuropeanSoftwareMarketingLtd.
+# ===================================================================
+# Licensed under the ApacheLicense, Version2.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
+#
+# 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
+##############################################################################
+
+from __future__ import absolute_import
+
+from vnftest.common import openstack_utils, utils
+
+from vnftest.onap.onap_api_call import OnapApiCall
+import logging
+
+from vnftest.steps import base
+
+LOG = logging.getLogger(__name__)
+
+
+class VfModuleValidator(base.Step):
+ __step_type__ = "VfModuleValidator"
+
+ def __init__(self, step_cfg, context, input_params):
+ self.validation_cfg = step_cfg
+ self.context = context
+ self.input_params = input_params
+ self.vnf_instance_id = None
+ self.vf_module_instance_id = None
+
+ def setup(self):
+ options = self.validation_cfg['options']
+ vnf_instance_id_def = options.get("vnf_instance_id")
+ self.vnf_instance_id = utils.format(vnf_instance_id_def, self.input_params)
+ vf_module_instance_id_def = options.get("vf_module_instance_id")
+ self.vf_module_instance_id = utils.format(vf_module_instance_id_def, self.input_params)
+
+ def run(self, result):
+ heat_stack_id = self.get_heat_stack_id()
+ vm_resources = openstack_utils.get_stack_vms(heat_stack_id)
+ for resource in vm_resources:
+ assert resource.resource_status == 'CREATE_COMPLETE', "Unexpected VM status: " + str(resource.resource_status)
+
+ # Get the heat stack id from AAI
+ def get_heat_stack_id(self):
+ step_conf = {}
+ step_conf['file'] = "aai_get_vf_module.yaml"
+ step_conf['input'] = [{'parameter_name': 'vnf_instance_id',
+ 'value': self.vnf_instance_id},
+ {'parameter_name': 'vf_module_instance_id',
+ 'value': self.vf_module_instance_id}
+ ]
+ step_conf['output'] = {'heat_stack_id': '[heat-stack-id]'}
+ onap_api_call = OnapApiCall(step_conf, self.context, self.input_params)
+ output = onap_api_call.run({})
+ return output['heat_stack_id']
+