in Providers/Scripts/2.6x-2.7x/Scripts/nxOMSPlugin.py [0:0]
def Test(Plugins):
"""
For each IP plugin inside the plugin module directory, test for the
existence of plugin(s) and conf files in the directory that omsagent
uses to run (PLUGIN_PATH and CONF_PATH)
"""
for plugin in Plugins:
# test for the existence of plugin and conf subfolders in the current plugin
plugin_dir = os.path.join(PLUGIN_MODULE_PATH, plugin['PluginName'], 'plugin')
plugin_arch_dir = os.path.join(PLUGIN_ARCH_MODULE_PATH, plugin['PluginName'], 'plugin')
conf_dir = os.path.join(PLUGIN_MODULE_PATH, plugin['PluginName'], 'conf')
# 4 cases here:
# Case 1: The IP has both plugin and conf directories
# Case 2: The IP has only plugin(s)
# Case 3: The IP has only conf
# Case 4: The IP has neither plugin nor conf directory, which is invalid if the MOF has "ensure: present"
if os.path.isdir(plugin_dir) and os.path.isdir(conf_dir):
if plugin['Ensure'] == 'Present':
# check all files exist under conf and dir
if (not check_all_files(plugin_dir, PLUGIN_PATH, False)
or not check_all_files(conf_dir, CONF_PATH, False)):
return [-1]
elif plugin['Ensure'] == 'Absent':
# check all conf files do NOT exist under conf directory
if check_all_files(conf_dir, CONF_PATH, False):
return [-1];
else:
# log error Ensure value not expected
LG().Log('ERROR', 'Ensure value: ' + plugin['Ensure'] + ' not expected')
return [-1]
elif os.path.isdir(plugin_dir):
if plugin['Ensure'] == 'Present':
# check all files exist under conf and dir
if not check_all_files(plugin_dir, PLUGIN_PATH, False):
return [-1]
elif plugin['Ensure'] == 'Absent':
# NO-OP as we do *NOT* test for the absence of common plugins
pass
else:
# log error Ensure value not expected
LG().Log('ERROR', 'Ensure value: ' + plugin['Ensure'] + ' not expected')
return [-1]
elif os.path.isdir(conf_dir):
if plugin['Ensure'] == 'Present':
# check all files exist under conf and dir
if not check_all_files(conf_dir, PLUGIN_PATH, False):
return [-1]
elif plugin['Ensure'] == 'Absent':
# check all conf files do NOT exist under conf directory
if check_all_files(conf_dir, CONF_PATH, False):
return [-1];
else:
# log error Ensure value not expected
LG().Log('ERROR', 'Ensure value: ' + plugin['Ensure'] + ' not expected')
return [-1]
else:
if plugin['Ensure'] == 'Present':
# log error - neither conf nor plugin directory was found in IP to set
LG().Log('ERROR', plugin['PluginName'] + ' contains neither plugin nor conf')
return [-1]
elif plugin['Ensure'] == 'Absent':
# log warning - this scenario is unexpected but should not cause plugin test to fail
LG().Log('WARN', plugin['PluginName'] + ' contains neither plugin nor conf, but was not to be installed anyways')
else:
# log error Ensure value not expected
LG().Log('ERROR', 'Ensure value: ' + plugin['Ensure'] + ' not expected')
return [-1]
# Some Plugins (e.g. Security Baseline) have arch specific files
if os.path.isdir(plugin_arch_dir):
if plugin['Ensure'] == 'Present':
# check all files exist under conf and dir
if not check_all_files(plugin_arch_dir, PLUGIN_PATH, True):
return [-1]
elif plugin['Ensure'] == 'Absent':
# NO-OP as we do *NOT* test for the absence of common plugins
pass
else:
# log error Ensure value not expected
LG().Log('ERROR', 'Ensure value: ' + plugin['Ensure'] + ' not expected')
return [-1]
# files are all present and hash matches
return [0]