def test_relational(tmp_path): """Test loading and using a queue with the filesystem database. """ from qme.main import Queue config_dir = os.path.join(str(tmp_path), ".qme") queue = Queue(config_dir=config_dir, database="sqlite") assert os.path.exists(config_dir) assert queue.config_dir == config_dir assert queue.config.configfile == os.path.join(queue.config_dir, "config.ini") assert queue.database == "sqlite" assert queue.db.database == "sqlite" # Test list, empty without anything assert not queue.list() # Run a task task = queue.run("ls") assert task.executor.name == "shell" assert task.taskid.startswith("shell") assert len(queue.list()) == 1 # Rerun the task, should still only have one rerun = queue.rerun() assert rerun.taskid == task.taskid assert len(queue.list()) == 1 # queue.get should return last task, given no id lasttask = queue.get() assert lasttask.taskid == task.taskid # Run a new task newtask = queue.run("whoami") assert len(queue.list()) == 2 exports = newtask.export() # Search for tasks assert len(queue.search("ls")) > 0 # Check exports for required in ["pwd", "output", "error", "cmd", "returncode"]: assert required in exports assert exports["pwd"] == os.getcwd() assert exports["cmd"] == ["whoami"] assert exports["returncode"] == 0 # Get a task id that isn't the last task notlast = queue.get(task.taskid) assert task.taskid == notlast.taskid # Clean up a specific task (no prompt) queue.clear(task.taskid, noprompt=True) assert len(queue.list()) == 1 queue.clear(noprompt=True) assert not queue.list()
def test_executors_sqlite(tmp_path): """test each executor type with an sqlite database """ from qme.main import Queue config_dir = os.path.join(str(tmp_path), ".qme") queue = Queue(config_dir=config_dir, database="sqlite") # The following commands should map to the following executors commands = ["ls"] executors = ["shell"] for i, command in enumerate(commands): # The executor name should be chosen based on the command name = executors[i] task = queue.run("ls") assert task.executor.name == name assert task.summary() # Task.load includes the file dump, the upper level keys should be same content = task.load() for key in ["executor", "uid", "data", "command"]: assert key in content # Task.export includes the executor specific data data = task.export() for key in ["pwd", "user", "timestamp"]: assert key in data
def run(args, extra): # Create a queue object, run the command to match to an executor queue = Queue(config_dir=args.config_dir) # Don't allow an empty command! if not args.cmd: sys.exit("Please provide a command for QueueMe to execute.") command = args.cmd # --help needs to be quoted, make sure if provided, gets parsed into command if any(["--help" in x for x in args.cmd]): command = [] for item in args.cmd: command += shlex.split(item) # Extra might include unparsed arguments queue.run(command=command + extra, message=args.message)
def test_executor_shell(tmp_path): """Test the shell executor. A shell executor should have added a returncode, output, and error to it's data export. """ from qme.main import Queue config_dir = os.path.join(str(tmp_path), ".qme") queue = Queue(config_dir=config_dir) task = queue.run("ls") assert task.executor.name == "shell" assert task.filename == os.path.join(queue.config_dir, "database", "shell", "%s.json" % task.taskid) assert task.summary() # Task.load includes the file dump, the upper level keys should be same content = task.load() for key in ["executor", "uid", "data"]: assert key in content # Task.export includes the executor specific data data = task.export() for key in ["cmd", "pwd", "output", "error", "returncode"]: assert key in data