From 3e3c96b2aa15d7757f281ce00518a67e2a1225a9 Mon Sep 17 00:00:00 2001 From: helenyao Date: Mon, 21 Nov 2016 06:50:06 -0500 Subject: Extracted all global parameters into functest_constants.py JIRA: FUNCTEST-533 1. Extracted all global variables into functest_constants.py and updated all affected areas accordingly 2. Used os.path.join to replace '/' to come up with the path for better cross-platform support and improve the path accuracy 3. Removed unused variables 4. Updated the hardcoded path in Dockerfile by using variable reference 5. Removed "/" ending from all path variables 6. Updated the unit test Change-Id: Ib30a81d1f0c83fbaef042d63c187c27bd18301bb Signed-off-by: helenyao --- functest/opnfv_tests/security_scan/connect.py | 3 +- .../security_scan/scripts/internet_check.py | 2 ++ .../opnfv_tests/security_scan/security_scan.py | 39 ++++++++++++---------- 3 files changed, 26 insertions(+), 18 deletions(-) (limited to 'functest/opnfv_tests/security_scan') diff --git a/functest/opnfv_tests/security_scan/connect.py b/functest/opnfv_tests/security_scan/connect.py index 18ca96d8..3d5456c5 100644 --- a/functest/opnfv_tests/security_scan/connect.py +++ b/functest/opnfv_tests/security_scan/connect.py @@ -15,9 +15,10 @@ import socket import paramiko import functest.utils.functest_logger as ft_logger +import functest.utils.functest_constants as ft_constants # add installer IP from env -INSTALLER_IP = os.getenv('INSTALLER_IP') +INSTALLER_IP = ft_constants.CI_INSTALLER_IP # Set up loggers logger = ft_logger.Logger("security_scan").getLogger() diff --git a/functest/opnfv_tests/security_scan/scripts/internet_check.py b/functest/opnfv_tests/security_scan/scripts/internet_check.py index 1bed50a7..d417d174 100644 --- a/functest/opnfv_tests/security_scan/scripts/internet_check.py +++ b/functest/opnfv_tests/security_scan/scripts/internet_check.py @@ -22,4 +22,6 @@ def is_connected(): return True except: return False + + print is_connected() diff --git a/functest/opnfv_tests/security_scan/security_scan.py b/functest/opnfv_tests/security_scan/security_scan.py index 4e0407fb..f0673924 100755 --- a/functest/opnfv_tests/security_scan/security_scan.py +++ b/functest/opnfv_tests/security_scan/security_scan.py @@ -24,23 +24,23 @@ from keystoneclient.auth.identity import v2 from novaclient import client import connect -import functest.utils.functest_utils as ft_utils +import functest.utils.functest_constants as ft_constants __version__ = 0.1 __author__ = 'Luke Hinds (lhinds@redhat.com)' __url__ = 'https://wiki.opnfv.org/display/functest/Functest+Security' # Global vars -INSTALLER_IP = os.getenv('INSTALLER_IP') +INSTALLER_IP = ft_constants.CI_INSTALLER_IP oscapbin = 'sudo /bin/oscap' -functest_dir = '%s/opnfv_tests/security_scan/' % ft_utils.FUNCTEST_REPO +functest_dir = '%s/security_scan/' % ft_constants.FUNCTEST_TEST_DIR # Apex Spefic var needed to query Undercloud -if os.getenv('OS_AUTH_URL') is None: +if ft_constants.OS_AUTH_URL is None: connect.logger.error(" Enviroment variable OS_AUTH_URL is not set") sys.exit(0) else: - OS_AUTH_URL = os.getenv('OS_AUTH_URL') + OS_AUTH_URL = ft_constants.OS_AUTH_URL # args parser = argparse.ArgumentParser(description='OPNFV OpenSCAP Scanner') @@ -71,6 +71,10 @@ sess = session.Session(auth=auth) nova = client.Client(2, session=sess) +class GlobalVariables: + tmpdir = "" + + def run_tests(host, nodetype): user = cfgparse.get(nodetype, 'user') port = cfgparse.get(nodetype, 'port') @@ -133,13 +137,12 @@ def internet_check(host, nodetype): def createfiles(host, port, user, localkey): import connect - global tmpdir localpath = functest_dir + 'scripts/createfiles.py' remotepath = '/tmp/createfiles.py' com = 'python /tmp/createfiles.py' connect = connect.ConnectionManager(host, port, user, localkey, localpath, remotepath, com) - tmpdir = connect.remotescript() + GlobalVariables.tmpdir = connect.remotescript() def install_pkg(host, port, user, localkey): @@ -160,18 +163,20 @@ def run_scanner(host, port, user, localkey, nodetype): if scantype == 'xccdf': cpe = cfgparse.get(nodetype, 'cpe') com = '{0} xccdf eval --profile {1} --results {2}/{3}' \ - ' --report {2}/{4} --cpe {5} {6}'.format(oscapbin, - profile, - tmpdir.rstrip(), - results, - report, - cpe, - secpolicy) + ' --report {2}/{4}' \ + ' --cpe {5} {6}'.format(oscapbin, + profile, + GlobalVariables.tmpdir.rstrip(), + results, + report, + cpe, + secpolicy) connect = connect.ConnectionManager(host, port, user, localkey, com) connect.remotecmd() elif scantype == 'oval': com = '{0} oval eval --results {1}/{2} ' - '--report {1}/{3} {4}'.format(oscapbin, tmpdir.rstrip(), + '--report {1}/{3} {4}'.format(oscapbin, + GlobalVariables.tmpdir.rstrip(), results, report, secpolicy) connect = connect.ConnectionManager(host, port, user, localkey, com) connect.remotecmd() @@ -191,7 +196,7 @@ def post_tasks(host, port, user, localkey, nodetype): os.makedirs(dl_folder, 0755) report = cfgparse.get(nodetype, 'report') results = cfgparse.get(nodetype, 'results') - reportfile = '{0}/{1}'.format(tmpdir.rstrip(), report) + reportfile = '{0}/{1}'.format(GlobalVariables.tmpdir.rstrip(), report) connect = connect.ConnectionManager(host, port, user, localkey, dl_folder, reportfile, report, results) connect.download_reports() @@ -206,7 +211,7 @@ def removepkg(host, port, user, localkey, nodetype): def cleandir(host, port, user, localkey, nodetype): import connect - com = 'sudo rm -r {0}'.format(tmpdir.rstrip()) + com = 'sudo rm -r {0}'.format(GlobalVariables.tmpdir.rstrip()) connect = connect.ConnectionManager(host, port, user, localkey, com) connect.remotecmd() -- cgit 1.2.3-korg