def main(args=None): CoreServices.setup() # inject existing libraries. # because of that all the ansible modules should be imported after that CoreServices.dependency_manager().inject_libraries() specs_manager = api.SpecManager() # Init Managers specs_manager.register_spec( WorkspaceManagerSpec('workspace', description="Workspace manager. " "Allows to create and use an " "isolated environment for plugins " "execution.")) specs_manager.register_spec( PluginManagerSpec('plugin', description="Plugin management")) specs_manager.register_spec( SSHSpec('ssh', description="Interactive ssh session to node from inventory.")) # register all plugins for plugin in CoreServices.plugins_manager().PLUGINS_DICT.values(): specs_manager.register_spec(api.InfraredPluginsSpec(plugin)) argcomplete.autocomplete(specs_manager.parser) return specs_manager.run_specs(args) or 0
def main(args=None): CoreServices.setup() # inject existing libraries. # because of that all the ansible modules should be imported after that CoreServices.dependency_manager().inject_libraries() specs_manager = api.SpecManager() # Init Managers specs_manager.register_spec( WorkspaceManagerSpec('workspace', description="Workspace manager. " "Allows to create and use an " "isolated environment for plugins " "execution.")) specs_manager.register_spec( PluginManagerSpec('plugin', description="Plugin management")) specs_manager.register_spec( SSHSpec( 'ssh', description="Interactive ssh session to node from inventory.")) # register all plugins for plugin in CoreServices.plugins_manager().PLUGINS_DICT.values(): specs_manager.register_spec(api.InfraredPluginsSpec(plugin)) argcomplete.autocomplete(specs_manager.parser) return specs_manager.run_specs(args) or 0
def test_install_dependencies_already_exist(plugin_manager_fixture): """ Test that skipping existing plugins and not trying to install them again :param plugin_manager_fixture: Fixture object which yields InfraredPluginManger object """ plugin_manager = plugin_manager_fixture() plugin_dir = "plugin_with_dependencies" plugin_dict = get_plugin_spec_flatten_dict( os.path.join(SAMPLE_PLUGINS_DIR, plugin_dir)) # set the expected dictionary of installed plugins expected_installed_plugins = { plugin_dict["name"]: { "src": plugin_dict["dir"] } } # validates that the plugin is not in configuration file at the beginning validate_plugins_presence_in_conf(plugin_manager, expected_installed_plugins, present=False) # add the plugin with its dependencies plugin_manager.add_plugin(plugin_source=plugin_dict["dir"]) # add the same dependency one more time assert CoreServices.dependency_manager()._install_local_dependency( PluginDependency(plugin_dict['dependencies'][0])) is False
def plugin_manager_helper(plugins_conf_dict=None): if plugins_conf_dict is None: plugins_conf_dict = {} plugins_conf_dict.update(SUPPORTED_TYPES_DICT) with lp_file.open(mode='w') as fp: config = ConfigParser.ConfigParser() for section, section_data in plugins_conf_dict.items(): config.add_section(section) for option, value in section_data.items(): config.set(section, option, value) config.write(fp) # replace core service with or test service # dependency manager will live in the temp folder # so we can keep it unmocked. CoreServices.register_service( ServiceName.DEPENDENCY_MANAGER, PluginDependencyManager(os.path.join(lp_file.dirname, ".library"))) CoreServices.register_service( ServiceName.PLUGINS_MANAGER, InfraredPluginManager(lp_file.strpath, CoreServices.dependency_manager(), os.path.join(lp_file.dirname, "plugins"))) return CoreServices.plugins_manager()
def test_install_dependencies_already_exist(plugin_manager_fixture): """ Test that skipping existing plugins and not trying to install them again :param plugin_manager_fixture: Fixture object which yields InfraredPluginManger object """ plugin_manager = plugin_manager_fixture() plugin_dir = "plugin_with_dependencies" plugin_dict = get_plugin_spec_flatten_dict( os.path.join(SAMPLE_PLUGINS_DIR, plugin_dir)) # set the expected dictionary of installed plugins expected_installed_plugins = { plugin_dict["name"]: { "src": plugin_dict["dir"] } } # validates that the plugin is not in configuration file at the beginning validate_plugins_presence_in_conf( plugin_manager, expected_installed_plugins, present=False) # add the plugin with its dependencies plugin_manager.add_plugin(plugin_source=plugin_dict["dir"]) # add the same dependency one more time assert CoreServices.dependency_manager()._install_local_dependency( PluginDependency(plugin_dict['dependencies'][0])) is False
def plugin_manager_helper(plugins_conf_dict=None): if plugins_conf_dict is None: plugins_conf_dict = {} plugins_conf_dict.update(SUPPORTED_TYPES_DICT) with lp_file.open(mode='w') as fp: config = ConfigParser.ConfigParser() for section, section_data in plugins_conf_dict.items(): config.add_section(section) for option, value in section_data.items(): config.set(section, option, value) config.write(fp) # replace core service with or test service # dependency manager will live in the temp folder # so we can keep it unmocked. CoreServices.register_service( ServiceName.DEPENDENCY_MANAGER, PluginDependencyManager( os.path.join(lp_file.dirname, ".library"))) CoreServices.register_service( ServiceName.PLUGINS_MANAGER, InfraredPluginManager( lp_file.strpath, CoreServices.dependency_manager(), os.path.join(lp_file.dirname, "plugins"))) return CoreServices.plugins_manager()
def test_install_dependencies(plugin_manager_fixture): """ Test installing plugin dependencies Validate that the plugin's dependencies were installed :param plugin_manager_fixture: Fixture object which yields InfraredPluginManger object """ plugin_manager = plugin_manager_fixture() plugin_dir = "plugin_with_dependencies" plugin_dict = get_plugin_spec_flatten_dict( os.path.join(SAMPLE_PLUGINS_DIR, plugin_dir)) # set the expected dictionary of installed plugins expected_installed_plugins = { plugin_dict["name"]: { "src": plugin_dict["dir"] } } # validates that the plugin is not in configuration file at the beginning validate_plugins_presence_in_conf(plugin_manager, expected_installed_plugins, present=False) # add the plugin with its dependencies plugin_manager.add_plugin(plugin_source=plugin_dict["dir"]) # validates that the plugin is in config file after adding plugin validate_plugins_presence_in_conf(plugin_manager, expected_installed_plugins, present=True) # check that copytree tried to copy the dependency to the library folder expected_dependency_dir = os.path.join( CoreServices.dependency_manager().library_root_dir, os.path.basename(plugin_dict["dependencies"][0]["source"])) assert os.path.isdir(expected_dependency_dir) assert os.path.isdir( os.path.join(expected_dependency_dir, 'callback_plugins')) assert os.path.isdir( os.path.join(expected_dependency_dir, 'filter_plugins')) assert os.path.isdir(os.path.join(expected_dependency_dir, 'library')) assert os.path.isdir(os.path.join(expected_dependency_dir, 'roles'))
def test_install_dependencies(plugin_manager_fixture): """ Test installing plugin dependencies Validate that the plugin's dependencies were installed :param plugin_manager_fixture: Fixture object which yields InfraredPluginManger object """ plugin_manager = plugin_manager_fixture() plugin_dir = "plugin_with_dependencies" plugin_dict = get_plugin_spec_flatten_dict( os.path.join(SAMPLE_PLUGINS_DIR, plugin_dir)) # set the expected dictionary of installed plugins expected_installed_plugins = { plugin_dict["name"]: { "src": plugin_dict["dir"] } } # validates that the plugin is not in configuration file at the beginning validate_plugins_presence_in_conf( plugin_manager, expected_installed_plugins, present=False) # add the plugin with its dependencies plugin_manager.add_plugin(plugin_source=plugin_dict["dir"]) # validates that the plugin is in config file after adding plugin validate_plugins_presence_in_conf( plugin_manager, expected_installed_plugins, present=True) # check that copytree tried to copy the dependency to the library folder expected_dependency_dir = os.path.join( CoreServices.dependency_manager().library_root_dir, os.path.basename(plugin_dict["dependencies"][0]["source"])) assert os.path.isdir(expected_dependency_dir) assert os.path.isdir(os.path.join( expected_dependency_dir, 'callback_plugins')) assert os.path.isdir(os.path.join( expected_dependency_dir, 'filter_plugins')) assert os.path.isdir(os.path.join( expected_dependency_dir, 'library')) assert os.path.isdir(os.path.join( expected_dependency_dir, 'roles'))