Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
# Base path to find files
CITELLUS_ROOT = os.environ["CITELLUS_ROOT"]
if runninglive():
# Running on LIVE environment
# For example, next condition might be an existing file like:
# os.path.exists(os.join.path(CITELLUS_ROOT,'/etc/nova/nova.conf'))
if True:
# Example: File does exist, check file contents or other checks
if True:
# Plugin tests passed
exitcitellus(code=citellus.RC_OKAY)
else:
# Error with plugin tests
# Provide messages on STDERR
exitcitellus(
code=citellus.RC_FAILED, msg="There was an error because of 'xxx'"
)
else:
# Plugin script skipped per conditions
# Provide reason for skipping:
exitcitellus(code=citellus.RC_SKIPPED, msg="Required file 'xxx' not found")
elif not runninglive():
# Running on snapshot/sosreport environment
# Provide messages on STDERR
exitcitellus(
code=citellus.RC_FAILED, msg="There was an error because of 'xxx'"
)
else:
# Plugin script skipped per conditions
# Provide reason for skipping:
exitcitellus(code=citellus.RC_SKIPPED, msg="Required file 'xxx' not found")
elif not runninglive():
# Running on snapshot/sosreport environment
if True:
if True:
# Plugin tests passed
exitcitellus(code=citellus.RC_OKAY)
else:
# Error with plugin tests
# Provide messages on STDERR
exitcitellus(
code=citellus.RC_FAILED, msg="There was an error because of 'xxx'"
)
else:
# Plugin script skipped per conditions
# Provide reason for skipping:
exitcitellus(code=citellus.RC_SKIPPED, msg="Required file 'xxx' not found")
commands = []
ansible = which("ansible-playbook")
for playbook in playbooks:
commands.append("%s -i localhost --connection=local, %s" % (ansible, playbook))
# Actually run the tests
results = citellus.docitellus(live=options.live, path=None, plugins=commands, lang='en_US')
# Do formatting of results to remove ansible-playbook -i localhost, and adjust return codes to citellus standards
for result in results:
# Convert RC codes to what citellus expects
if result['result']['rc'] == 2:
result['result']['rc'] = citellus.RC_FAILED
elif result['result']['rc'] == 0:
result['result']['rc'] = citellus.RC_OKAY
# Convert stdout to stderr for citellus handling
result['result']['err'] = result['result']['out']
result['result']['out'] = ''
# Remove ansible-playbook command and just leave yml file
result['plugin'] = result['plugin'].replace(which('ansible-playbook'), '').replace(' -i localhost --connection=local, ', '')
# Now, fake 'skipped' for all the plugins which were tied to the mode we're not running in:
for playbook in playbookskipped:
dictionary = {'plugin': playbook,
'result': {'rc': citellus.RC_SKIPPED, 'err': 'Skipped for incompatible operating mode', 'out': ''}}
results.append(dictionary)
return results