def run(data, quiet=False): # do not edit this line """ Executes plugin :param quiet: be more silent on returned information :param data: data to process :return: returncode, out, err """ # By default it returns list, so get only one item sourceid = citellus.getids(include=['/core/system/clock-1-ntpd.sh'])[0] targetid = citellus.getids(include=['/core/system/clock-1-chrony.sh'])[0] mangle = False # Grab source data if sourceid in data: if data[sourceid]['result']['rc'] == citellus.RC_OKAY: mangle = True if mangle: # We now fake result as SKIPPED and copy to datahook dict the new data data[targetid]['datahook'] = {} data[targetid]['datahook']['prior'] = dict(data[targetid]['result']) data[targetid]['result']['rc'] = citellus.RC_SKIPPED data[targetid]['result'][ 'err'] = 'Marked as skipped by data hook %s' % os.path.basename( __file__).split(os.sep)[0] citellus.LOG.debug("Data mangled for plugin %s:" % data[targetid]['plugin']) return data
def init(): """ Initializes module :return: List of triggers for Plugin """ ids = citellus.getids(include=['/core/openstack/mysql/seqno.sh']) return ids
def runtest(testtype='False'): """ Actually run the test for UT :param testtype: argument to pass to setup script :return: returncode """ # testtype will be 'pass', 'fail', 'skipped' # We're iterating against the different UT tests defined in UT-tests folder tmpdir = tempfile.mkdtemp(prefix='citellus-tmp') # Setup test for 'testtype' subprocess.check_output([uttest, uttest, testtype, tmpdir], stderr=subprocess.STDOUT) # Run test against it res = citellus.docitellus(path=tmpdir, plugins=citplugs) plugid = citellus.getids(plugins=citplugs)[0] # Get Return code rc = res[plugid]['result']['rc'] # Remove tmp folder shutil.rmtree(tmpdir) # Check if it passed return rc
def init(): """ Initializes module :return: List of triggers for Plugin """ ids = citellus.getids(include=['/metadata/system/release.sh']) return ids
def test_runplugin_fail(self): plugins = citellus.findplugins(folders=[testplugins], include=['exit_failed.sh']) results = citellus.docitellus(plugins=plugins) plugid = citellus.getids(plugins=plugins)[0] assert results[plugid]['result']['rc'] == citellus.RC_FAILED assert results[plugid]['result']['out'].endswith('something on stdout\n') assert results[plugid]['result']['err'].endswith('something on stderr\n')
def init(): """ Initializes module :return: List of triggers for Plugin """ triggers = citellus.getids(include=['faraday/positive']) return triggers
def run(data, quiet=False): # do not edit this line """ Executes plugin :param quiet: be more silent on returned information :param data: data to process :return: returncode, out, err """ # prefill plugins we had used: plugins = [] for item in data: plugin = {'plugin': data[item]['plugin'], 'id': data[item]['id']} plugins.append(plugin) # Find available profile definitions profiles = citellus.findplugins(folders=[pluginsdir], executables=False, fileextension='.txt') for item in profiles: uid = citellus.getids(plugins=[item])[0] profile = item['plugin'] plugin = dict(item) # Precreate storage for this profile name = "Profiles: %s" % os.path.basename(os.path.splitext(profile.replace(pluginsdir, ''))[0]) subcategory = '' category = name data[uid] = {"category": category, "hash": item['hash'], "plugin": item['plugin'], "name": name, "result": {"rc": int(os.environ['RC_OKAY']), "err": "", "out": ""}, "time": 0, "backend": "profile", "id": uid, "subcategory": subcategory} metadata = {'description': citellus.regexpfile(filename=plugin['plugin'], regexp='\A# description:')[14:].strip(), 'long_name': citellus.regexpfile(filename=plugin['plugin'], regexp='\A# long_name:')[12:].strip(), 'bugzilla': citellus.regexpfile(filename=plugin['plugin'], regexp='\A# bugzilla:')[11:].strip(), 'priority': int(citellus.regexpfile(filename=plugin['plugin'], regexp='\A# priority:')[11:].strip() or 0)} data[uid].update(metadata) # Start asembling data for the plugins relevant for profile data[uid]['result']['err'] = '' ids = plugidsforprofile(profile=profile, plugins=plugins) for id in ids: data[uid]['result']['err'] = data[uid]['result']['err'] + "\n" + "%s" % {'plugin': data[id]['plugin'].replace(os.path.join(citellus.citellusdir, 'plugins'), ''), 'err': data[id]['result']['err'].strip(), 'rc': data[id]['result']['rc']} data[uid]['components'] = ids return data
def plugidsforprofile(profile, plugins): """ Gets plugin id's related with profile includes/excludes :param profile: profile file to open :param plugins: plugins in citellus exection :return: array of id's """ # Open Profile definition for read and fill filters for plugins include = [] exclude = [] with open(profile, 'r') as f: for line in f: if re.match('\A\+.*', line): include.append(line[1:].strip()) if re.match('\A\-.*', line): exclude.append(line[1:].strip()) ids = citellus.getids(plugins=plugins, include=include, exclude=exclude) return ids
def run(data, quiet=False): # do not edit this line """ Executes plugin :param quiet: be more silent on returned information :param data: data to process :return: returncode, out, err """ # prefill plugins we had used: plugins = [] for item in data: plugin = {"plugin": data[item]["plugin"], "id": data[item]["id"]} plugins.append(plugin) # Find available profile definitions profiles = citellus.findplugins(folders=[pluginsdir], executables=False, fileextension=".txt") for item in profiles: uid = citellus.getids(plugins=[item])[0] profile = item["plugin"] plugin = dict(item) # Precreate storage for this profile name = "Profiles: %s" % os.path.basename( os.path.splitext(profile.replace(pluginsdir, ""))[0]) subcategory = "" category = name data[uid] = { "category": category, "hash": item["hash"], "plugin": item["plugin"], "name": name, "result": { "rc": 0, "err": "", "out": "" }, "time": 0, "backend": "profile", "id": uid, "subcategory": subcategory, } metadata = { "description": citellus.regexpfile(filename=plugin["plugin"], regexp=r"\A# description:")[14:].strip(), "long_name": citellus.regexpfile(filename=plugin["plugin"], regexp=r"\A# long_name:")[12:].strip(), "bugzilla": citellus.regexpfile(filename=plugin["plugin"], regexp=r"\A# bugzilla:")[11:].strip(), "priority": int( citellus.regexpfile(filename=plugin["plugin"], regexp=r"\A# priority:")[11:].strip() or 0), } data[uid].update(metadata) # start with OK status okay = int(os.environ["RC_OKAY"]) failed = int(os.environ["RC_FAILED"]) skipped = int(os.environ["RC_SKIPPED"]) info = int(os.environ["RC_INFO"]) # Start asembling data for the plugins relevant for profile data[uid]["result"]["err"] = "" ids = plugidsforprofile(profile=profile, plugins=plugins) new_results = [] overallitems = [] for id in ids: if id in data: if "sysinfo" in name and data[id]["result"]["rc"] == skipped: # Do nothing as we don't want to show skipped in sysinfo pass else: new_results.append({ "plugin_id": id, "plugin": data[id]["plugin"].replace( os.path.join(citellus.citellusdir, "plugins"), ""), "err": data[id]["result"]["err"].strip(), "rc": data[id]["result"]["rc"], }) overallitems.append(data[id]["result"]["rc"]) if "sysinfo" in name: if okay in overallitems or failed in overallitems or info in overallitems: overall = info else: # No plugins matched, so skip it overall = skipped else: if failed in overallitems: overall = failed elif info in overallitems: overall = info elif skipped in overallitems: overall = skipped else: overall = okay data[uid]["result"]["err"] = json.dumps(new_results) data[uid]["components"] = ids data[uid]["result"]["rc"] = overall return data
def run(data, quiet=False): # do not edit this line """ Executes plugin :param quiet: be more silent on returned information :param data: data to process :return: returncode, out, err """ # Act on all faraday-exec plugins idstodel = [] datatoadd = [] # Loop over plugin id's in data faradayids = citellus.getids(include=['faraday/positive', 'faraday/negative']) for pluginid in data: if data[pluginid]['id'] in faradayids: # Make a copy of dict for working on it plugin = dict(data[pluginid]) # Add plugin ID to be removed for resulting data so magui doesn't compare the whole set of nics at the same time idstodel.append(str(pluginid)) err = str(plugin['result']['err']) rc = int(plugin['result']['rc']) plugpath = str(plugin['plugin']) id = str(plugin['id']) ln = str(plugin['long_name']) desc = str(plugin['description']) name = str(plugin['name']) # Iterate over NIC pairs for pair in err.split(";"): if pair != '': # For each value split and fake plugin entry newid = "%s-%s" % (id, citellus.calcid(string=pair.split(":")[0])) update = {'id': newid, 'description': '%s: %s' % (desc, pair.split(":")[0]), 'long_name': '%s: %s' % (ln, pair.split(":")[0]), 'plugin': '%s-%s' % (plugpath, pair.split(":")[0]), 'name': 'Faraday: %s' % name} resultupdate = {'result': {'err': pair, 'out': '', 'rc': rc}} update.update(resultupdate) # Update plugin dictionary with forged values plugin.update(dict(update)) plugin['result']['err'] = str(pair) # Append new modified plugin to dataset datatoadd.append({newid: dict(plugin)}) # Process id's to remove for id in idstodel: del data[id] # Process data to add for item in datatoadd: data.update(item) return data
def run(data, quiet=False): # do not edit this line """ Executes plugin :param quiet: be more silent on returned information :param data: data to process :return: returncode, out, err """ # Act on all faraday-exec plugins idstodel = [] datatoadd = [] # Loop over plugin id's in data faradayids = citellus.getids(include=["faraday/positive", "faraday/negative"]) for pluginid in data: if data[pluginid]["id"] in faradayids: # Make a copy of dict for working on it plugin = dict(data[pluginid]) # Add plugin ID to be removed for resulting data so magui doesn't compare the whole set of nics at the same time idstodel.append(str(pluginid)) err = str(plugin["result"]["err"]) rc = int(plugin["result"]["rc"]) plugpath = str(plugin["plugin"]) id = str(plugin["id"]) ln = str(plugin["long_name"]) desc = str(plugin["description"]) name = str(plugin["name"]) kb = str(plugin["kb"]) # Iterate over NIC pairs for pair in err.split(";"): if pair != "": # For each value split and fake plugin entry newid = "%s-%s" % (id, citellus.calcid(string=pair.split(":")[0])) update = { "id": newid, "description": "%s: %s" % (desc, pair.split(":")[0]), "long_name": "%s: %s" % (ln, pair.split(":")[0]), "plugin": "%s-%s" % (plugpath, pair.split(":")[0]), "name": "Faraday: %s" % name, "kb": kb, } resultupdate = {"result": {"err": pair, "out": "", "rc": rc}} update.update(resultupdate) # Update plugin dictionary with forged values plugin.update(dict(update)) plugin["result"]["err"] = str(pair) # Append new modified plugin to dataset datatoadd.append({newid: dict(plugin)}) # Process id's to remove for id in idstodel: del data[id] # Process data to add for item in datatoadd: data.update(item) return data