def test__setup_sudo_access(self): """ registration.setup_sudo_access: installs a sudo-based `run_root` method onto the provided plugin. """ plugin = MockPlugin() registration.setup_sudo_access(plugin) # check if method was injected method = getattr(plugin, 'run_root', None) self.assertIsNotNone(method) self.assertTrue(callable(method))
def _handle_command(self, command, env, args): """ Handles calling appropriate command plugin based on the arguments provided. `command` Command string. `env` Runtime ``Environment`` instance. `args` List of argument strings passed. Returns ``False`` if nothing handled. * Raises ``HelpBanner`` exception if mismatched command arguments. """ # get command plugin registered for command # note, we're guaranteed to have a command string by this point plugin_obj = registration.get_command_hook(command, env.task.active) # check if plugin is task-specific or has option hooks implying # task-specific behavior if plugin_obj and not env.task.active: if plugin_obj.task_only or plugin_obj.options: plugin_obj = None if plugin_obj: # plugin needs root, setup root access via sudo if plugin_obj.needs_root: registration.setup_sudo_access(plugin_obj) # parse arguments parser = self._get_plugin_parser(plugin_obj) parsed_args = parser.parse_args(args) # run plugin plugin_obj.execute(env, parsed_args) return True return False