def setUp(self): class Inventory(): cache = dict() class PopenResult(): returncode = 0 stdout = b"" stderr = b"" def communicate(self): return (self.stdout, self.stderr) self.popen_result = PopenResult() self.inventory = Inventory() self.loader = mock.MagicMock() self.loader.load = mock.MagicMock() inv_loader = PluginLoader('InventoryModule', 'ansible.plugins.inventory', C.DEFAULT_INVENTORY_PLUGIN_PATH, 'inventory_plugins') self.inventory_module = inv_loader.get('script') self.inventory_module.set_options() def register_patch(name): patcher = mock.patch(name) self.addCleanup(patcher.stop) return patcher.start() self.popen = register_patch('subprocess.Popen') self.popen.return_value = self.popen_result self.BaseInventoryPlugin = register_patch('ansible.plugins.inventory.BaseInventoryPlugin') self.BaseInventoryPlugin.get_cache_prefix.return_value = 'abc123'
def _setup_inventory_plugins(self): ''' sets up loaded inventory plugins for usage ''' inventory_loader = PluginLoader('InventoryModule', 'ansible.plugins.inventory', C.DEFAULT_INVENTORY_PLUGIN_PATH, 'inventory_plugins') display.vvvv('setting up inventory plugins') for name in C.INVENTORY_ENABLED: plugin = inventory_loader.get(name) if plugin: self._inventory_plugins.append(plugin) else: display.warning('Failed to load inventory plugin, skipping %s' % name) if not self._inventory_plugins: raise AnsibleError("No inventory plugins available to generate inventory, make sure you have at least one whitelisted.")
def _setup_inventory_plugins(self): ''' sets up loaded inventory plugins for usage ''' inventory_loader = PluginLoader('InventoryModule', 'ansible.plugins.inventory', 'inventory_plugins', 'inventory_plugins') display.vvvv('setting up inventory plugins') for name in C.INVENTORY_ENABLED: plugin = inventory_loader.get(name) if plugin: self._inventory_plugins.append(plugin) else: display.warning('Failed to load inventory plugin, skipping %s' % name) if not self._inventory_plugins: raise AnsibleError("No inventory plugins available to generate inventory, make sure you have at least one whitelisted.")