| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
import sys |
| 7 |
import os |
| 8 |
import openscap_api as oscap |
| 9 |
|
| 10 |
|
| 11 |
''' |
| 12 |
Ensure that the openscap_api is really imported from the desired install dir |
| 13 |
Python doesn't directly use env(PYTHONPATH), but sys.path which aggregate |
| 14 |
potential paths. So we check that the import path is in PYTHONPATH. |
| 15 |
|
| 16 |
To learn more about sys.path: |
| 17 |
https://stackoverflow.com/questions/897792/where-is-pythons-sys-path-initialized-from/38403654#38403654 |
| 18 |
''' |
| 19 |
if os.path.dirname(oscap.__file__) not in os.getenv('PYTHONPATH'): |
| 20 |
raise Exception("openscap_api is loaded but from the local env " |
| 21 |
"instead of the tested environment.\n" |
| 22 |
"Loaded module path = {0}".format(oscap.__file__)) |
| 23 |
else: |
| 24 |
print("openscap_api loaded from "+oscap.__file__) |
| 25 |
pass |
| 26 |
|
| 27 |
|
| 28 |
''' |
| 29 |
Return the string corresponding to the oscap result (PASS, FAIL etc.) |
| 30 |
''' |
| 31 |
|
| 32 |
|
| 33 |
def result2str(result): |
| 34 |
if result == oscap.xccdf.XCCDF_RESULT_PASS: |
| 35 |
return "PASS" |
| 36 |
elif result == oscap.xccdf.XCCDF_RESULT_FAIL: |
| 37 |
return "FAIL" |
| 38 |
elif result == oscap.xccdf.XCCDF_RESULT_ERROR: |
| 39 |
return "ERROR" |
| 40 |
elif result == oscap.xccdf.XCCDF_RESULT_UNKNOWN: |
| 41 |
return "UNKNOWN" |
| 42 |
elif result == oscap.xccdf.XCCDF_RESULT_NOT_APPLICABLE: |
| 43 |
return "NOT_APPLICABLE" |
| 44 |
elif result == oscap.xccdf.XCCDF_RESULT_NOT_CHECKED: |
| 45 |
return "NOT_CHECKED" |
| 46 |
elif result == oscap.xccdf.XCCDF_RESULT_NOT_SELECTED: |
| 47 |
return "NOT_SELECTED" |
| 48 |
elif result == oscap.xccdf.XCCDF_RESULT_INFORMATIONAL: |
| 49 |
return "INFORMATIONAL" |
| 50 |
elif result == oscap.xccdf.XCCDF_RESULT_FIXED: |
| 51 |
return "FIXED" |
| 52 |
|
| 53 |
|
| 54 |
''' |
| 55 |
Return the absolute path of a relative path (located in this folder) |
| 56 |
Required because the tests are run from the build directory, |
| 57 |
so you need to use this functions for all relative paths. |
| 58 |
''' |
| 59 |
|
| 60 |
|
| 61 |
def get_path(path_str): |
| 62 |
return os.path.join(os.path.dirname(__file__), path_str) |