aboutsummaryrefslogtreecommitdiffstats
path: root/functest/opnfv_tests/vnf/ims/clearwater.py
diff options
context:
space:
mode:
Diffstat (limited to 'functest/opnfv_tests/vnf/ims/clearwater.py')
-rw-r--r--functest/opnfv_tests/vnf/ims/clearwater.py91
1 files changed, 34 insertions, 57 deletions
diff --git a/functest/opnfv_tests/vnf/ims/clearwater.py b/functest/opnfv_tests/vnf/ims/clearwater.py
index 57857b563..4c143fd70 100644
--- a/functest/opnfv_tests/vnf/ims/clearwater.py
+++ b/functest/opnfv_tests/vnf/ims/clearwater.py
@@ -12,9 +12,6 @@
import logging
import os
import re
-import shlex
-import shutil
-import subprocess
import time
import pkg_resources
@@ -27,10 +24,10 @@ __author__ = ("Valentin Boucher <valentin.boucher@orange.com>, "
"Helen Yao <helanyao@gmail.com>")
-class ClearwaterTesting(object):
+class ClearwaterTesting():
"""vIMS clearwater base usable by several orchestrators"""
- def __init__(self, case_name, ellis_ip):
+ def __init__(self, case_name, bono_ip, ellis_ip):
self.logger = logging.getLogger(__name__)
self.case_dir = pkg_resources.resource_filename(
'functest', 'opnfv_tests/vnf/ims')
@@ -45,16 +42,15 @@ class ClearwaterTesting(object):
os.makedirs(self.result_dir)
self.ellis_ip = ellis_ip
+ self.bono_ip = bono_ip
- def availability_check_by_creating_numbers(self,
- signup_code='secret',
- two_numbers=False):
+ def availability_check(self, signup_code='secret', two_numbers=False):
"""Create one or two numbers"""
assert self.ellis_ip
output_dict = {}
self.logger.debug('Ellis IP: %s', self.ellis_ip)
output_dict['ellis_ip'] = self.ellis_ip
- account_url = 'http://{0}/accounts'.format(self.ellis_ip)
+ account_url = f'http://{self.ellis_ip}/accounts'
params = {"password": "functest",
"full_name": "opnfv functest user",
"email": "functest@opnfv.org",
@@ -64,7 +60,7 @@ class ClearwaterTesting(object):
number_res = self._create_ellis_account(account_url, params)
output_dict['number'] = number_res
- session_url = 'http://{0}/session'.format(self.ellis_ip)
+ session_url = f'http://{self.ellis_ip}/session'
session_data = {
'username': params['email'],
'password': params['password'],
@@ -72,8 +68,8 @@ class ClearwaterTesting(object):
}
cookies = self._get_ellis_session_cookies(session_url, session_data)
- number_url = 'http://{0}/accounts/{1}/numbers'.format(
- self.ellis_ip, params['email'])
+ number_url = (
+ f"http://{self.ellis_ip}/accounts/{params['email']}/numbers")
self.logger.debug('Create 1st calling number on Ellis')
number_res = self._create_ellis_number(number_url, cookies)
@@ -85,7 +81,7 @@ class ClearwaterTesting(object):
return output_dict
def _create_ellis_account(self, account_url, params):
- i = 50
+ i = 80
for iloop in range(i):
try:
req = requests.post(account_url, data=params)
@@ -95,15 +91,13 @@ class ClearwaterTesting(object):
'Account %s is created on Ellis\n%s',
params.get('full_name'), account_res)
return account_res
- else:
- raise Exception("Cannot create ellis account")
+ raise Exception("Cannot create ellis account")
except Exception: # pylint: disable=broad-except
self.logger.info(
"try %s: cannot create ellis account", iloop + 1)
- time.sleep(25)
+ time.sleep(30)
raise Exception(
- "Unable to create an account {}".format(
- params.get('full_name')))
+ f"Unable to create an account {params.get('full_name')}")
def _get_ellis_session_cookies(self, session_url, params):
i = 15
@@ -114,8 +108,7 @@ class ClearwaterTesting(object):
cookies = req.cookies
self.logger.debug('cookies: %s', cookies)
return cookies
- else:
- raise Exception('Failed to get cookies for Ellis')
+ raise Exception('Failed to get cookies for Ellis')
except Exception: # pylint: disable=broad-except
self.logger.info(
"try %s: cannot get cookies for Ellis", iloop + 1)
@@ -132,22 +125,19 @@ class ClearwaterTesting(object):
self.logger.info(
'Calling number is created: %s', number_res)
return number_res
+ if req and req.json():
+ reason = req.json()['reason']
else:
- if req and req.json():
- reason = req.json()['reason']
- else:
- reason = req
- self.logger.info("cannot create a number: %s", reason)
- raise Exception('Failed to create a number')
+ reason = req
+ self.logger.info("cannot create a number: %s", reason)
+ raise Exception('Failed to create a number')
except Exception: # pylint: disable=broad-except
self.logger.info(
"try %s: cannot create a number", iloop + 1)
time.sleep(25)
raise Exception('Failed to create a number')
- def run_clearwater_live_test(self, dns_ip, public_domain,
- bono_ip=None, ellis_ip=None,
- signup_code='secret'):
+ def run_clearwater_live_test(self, public_domain, signup_code='secret'):
"""Run the Clearwater live tests
It first runs dnsmasq to reach clearwater services by FQDN and then the
@@ -159,38 +149,20 @@ class ClearwaterTesting(object):
"""
# pylint: disable=too-many-locals,too-many-arguments
self.logger.info('Run Clearwater live test')
- dns_file = '/etc/resolv.conf'
- dns_file_bak = '/etc/resolv.conf.bak'
- self.logger.debug('Backup %s -> %s', dns_file, dns_file_bak)
- shutil.copy(dns_file, dns_file_bak)
- cmd = ("dnsmasq -d -u root --server=/clearwater.opnfv/{0} "
- "-r /etc/resolv.conf.bak".format(dns_ip))
- dnsmasq_process = subprocess.Popen(shlex.split(cmd))
- script = ('echo -e "nameserver {0}" > {1};'
- 'cd {2};'
- 'rake test[{3}] SIGNUP_CODE={4}'
- .format('127.0.0.1',
- dns_file,
- self.test_dir,
- public_domain,
- signup_code))
- if bono_ip and ellis_ip:
- subscript = ' PROXY={0} ELLIS={1}'.format(bono_ip, ellis_ip)
- script = '{0}{1}'.format(script, subscript)
- script = ('{0}{1}'.format(script, ' --trace'))
- cmd = "/bin/bash -c '{0}'".format(script)
+ script = (f'cd {self.test_dir};'
+ f'rake test[{public_domain}] SIGNUP_CODE={signup_code}')
+ if self.bono_ip and self.ellis_ip:
+ subscript = f' PROXY={self.bono_ip} ELLIS={self.ellis_ip}'
+ script = f'{script}{subscript}'
+ script = f'{script} --trace'
+ cmd = f"/bin/sh -c '{script}'"
self.logger.debug('Live test cmd: %s', cmd)
output_file = os.path.join(self.result_dir, "ims_test_output.txt")
ft_utils.execute_command(cmd,
error_msg='Clearwater live test failed',
output_file=output_file)
- dnsmasq_process.kill()
- with open(dns_file_bak, 'r') as bak_file:
- result = bak_file.read()
- with open(dns_file, 'w') as dfile:
- dfile.write(result)
- with open(output_file, 'r') as ofile:
+ with open(output_file, 'r', encoding='utf-8') as ofile:
result = ofile.read()
if result != "":
@@ -207,7 +179,12 @@ class ClearwaterTesting(object):
vims_test_result["skipped"] = int(grp.group(3))
vims_test_result['passed'] = (
int(grp.group(2)) - int(grp.group(3)) - int(grp.group(1)))
+ if vims_test_result['total'] - vims_test_result['skipped'] > 0:
+ vnf_test_rate = vims_test_result['passed'] / (
+ vims_test_result['total'] - vims_test_result['skipped'])
+ else:
+ vnf_test_rate = 0
except Exception: # pylint: disable=broad-except
self.logger.exception("Cannot parse live tests results")
- return None
- return vims_test_result
+ return None, 0
+ return vims_test_result, vnf_test_rate