diff options
author | helenyao <yaohelan@huawei.com> | 2016-11-21 06:50:06 -0500 |
---|---|---|
committer | jose.lausuch <jose.lausuch@ericsson.com> | 2016-11-24 15:14:45 +0100 |
commit | 3e3c96b2aa15d7757f281ce00518a67e2a1225a9 (patch) | |
tree | 9b15e0ceab33a9301ca7cde1a0a36e05f2347584 /functest/opnfv_tests/security_scan/security_scan.py | |
parent | 7a776398ef8b17bd9af5367d712707a903c1c86a (diff) |
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 <yaohelan@huawei.com>
Diffstat (limited to 'functest/opnfv_tests/security_scan/security_scan.py')
-rwxr-xr-x | functest/opnfv_tests/security_scan/security_scan.py | 39 |
1 files changed, 22 insertions, 17 deletions
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() |