Avoid running local dnsmasq when testing IMS 96/67896/2
authorCédric Ollivier <cedric.ollivier@orange.com>
Mon, 20 May 2019 15:49:38 +0000 (17:49 +0200)
committerCédric Ollivier <ollivier.cedric@gmail.com>
Tue, 21 May 2019 20:03:46 +0000 (22:03 +0200)
It may be unsafe and it's useless for testing IMS if BONO_IP is set.

Change-Id: I8b0f010956defbfa1fd22b5aa5cbea70bd2968a4
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
(cherry picked from commit a82827bd4f93c318f0bc2554928ab2213d1ee766)

docker/vnf/Dockerfile
functest/opnfv_tests/vnf/ims/clearwater.py
functest/opnfv_tests/vnf/ims/cloudify_ims.py
functest/opnfv_tests/vnf/ims/heat_ims.py
functest/tests/unit/vnf/ims/test_clearwater.py

index 6494138..ad6bd84 100644 (file)
@@ -20,7 +20,7 @@ ENV PATH $GOBIN:$PATH
 
 COPY clearwater-heat-singlenet-deps.patch /tmp/clearwater-heat-singlenet-deps.patch
 RUN apk --no-cache add --update \
-        ruby ruby-bundler ruby-irb ruby-rdoc dnsmasq \
+        ruby ruby-bundler ruby-irb ruby-rdoc \
         procps libxslt libxml2 zlib libffi python3 go musl-dev && \
     apk --no-cache add --virtual .build-deps --update \
         ruby-dev g++ make libxslt-dev libxml2-dev zlib-dev libffi-dev g++ make && \
index b05f8e7..64f0428 100644 (file)
@@ -12,9 +12,6 @@
 import logging
 import os
 import re
-import shlex
-import shutil
-import subprocess
 import time
 
 import pkg_resources
@@ -30,7 +27,7 @@ __author__ = ("Valentin Boucher <valentin.boucher@orange.com>, "
 class ClearwaterTesting(object):
     """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,6 +42,7 @@ class ClearwaterTesting(object):
             os.makedirs(self.result_dir)
 
         self.ellis_ip = ellis_ip
+        self.bono_ip = bono_ip
 
     def availability_check(self, signup_code='secret', two_numbers=False):
         """Create one or two numbers"""
@@ -143,9 +141,7 @@ class ClearwaterTesting(object):
                 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
@@ -157,23 +153,14 @@ 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,
+        script = ('cd {0};'
+                  'rake test[{1}] SIGNUP_CODE={2}'
+                  .format(self.test_dir,
                           public_domain,
                           signup_code))
-        if bono_ip and ellis_ip:
-            subscript = ' PROXY={0} ELLIS={1}'.format(bono_ip, ellis_ip)
+        if self.bono_ip and self.ellis_ip:
+            subscript = ' PROXY={0} ELLIS={1}'.format(
+                self.bono_ip, self.ellis_ip)
             script = '{0}{1}'.format(script, subscript)
         script = ('{0}{1}'.format(script, ' --trace'))
         cmd = "/bin/bash -c '{0}'".format(script)
@@ -182,11 +169,6 @@ class ClearwaterTesting(object):
         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:
             result = ofile.read()
index 8e3ec3e..288e031 100644 (file)
@@ -224,8 +224,10 @@ class CloudifyIms(cloudify.Cloudify):
 
         ellis_ip = self.cfy_client.deployments.outputs.get(
             self.vnf['descriptor'].get('name'))['outputs']['ellis_ip']
-        self.clearwater = clearwater.ClearwaterTesting(self.case_name,
-                                                       ellis_ip)
+        bono_ip = self.cfy_client.deployments.outputs.get(
+            self.vnf['descriptor'].get('name'))['outputs']['bono_ip']
+        self.clearwater = clearwater.ClearwaterTesting(
+            self.case_name, bono_ip, ellis_ip)
         self.clearwater.availability_check()
 
         self.details['vnf'].update(status='PASS',
@@ -241,7 +243,7 @@ class CloudifyIms(cloudify.Cloudify):
         if not dns_ip:
             return False
         short_result, vnf_test_rate = self.clearwater.run_clearwater_live_test(
-            dns_ip=dns_ip, public_domain=self.vnf['inputs']["public_domain"])
+            public_domain=self.vnf['inputs']["public_domain"])
         duration = time.time() - start_time
         self.__logger.info(short_result)
         self.details['test_vnf'].update(result=short_result, duration=duration)
index cce1a33..9ea9c56 100644 (file)
@@ -194,12 +194,16 @@ class HeatIms(singlevm.VmReady2):
                     server.name, regex='Cloud-init .* finished at ', loop=1):
                 return False
             if 'ellis' in server.name:
-                self.__logger.debug("server: %s", server)
+                self.__logger.debug("ellis: %s", server)
                 ellis_ip = server.public_v4
+            elif 'bono' in server.name:
+                self.__logger.debug("bono: %s", server)
+                bono_ip = server.public_v4
 
         assert ellis_ip
-        self.clearwater = clearwater.ClearwaterTesting(self.case_name,
-                                                       ellis_ip)
+        assert bono_ip
+        self.clearwater = clearwater.ClearwaterTesting(
+            self.case_name, bono_ip, ellis_ip)
         # This call can take time and many retry because Heat is
         # an infrastructure orchestrator so when Heat say "stack created"
         # it means that all OpenStack ressources are created but not that
@@ -222,7 +226,7 @@ class HeatIms(singlevm.VmReady2):
         if not dns_ip:
             return False
         short_result, vnf_test_rate = self.clearwater.run_clearwater_live_test(
-            dns_ip=dns_ip, public_domain=self.vnf['parameters']["zone"])
+            public_domain=self.vnf['parameters']["zone"])
         duration = time.time() - start_time
         self.__logger.info(short_result)
         self.details['test_vnf'] = dict(result=short_result, duration=duration)
index 93f8ffe..435b172 100644 (file)
@@ -20,7 +20,8 @@ class ClearwaterTesting(unittest.TestCase):
     def setUp(self):
         with mock.patch('functest.opnfv_tests.vnf.ims.cloudify_ims.'
                         'os.makedirs'):
-            self.ims_vnf = clearwater.ClearwaterTesting("foo", "0.0.0.0")
+            self.ims_vnf = clearwater.ClearwaterTesting(
+                "foo", "0.0.0.0", "0.0.0.0")
 
         self.mock_post = mock.Mock()
         attrs = {'status_code': 201,