def test_exec_interactive(self): """ Test for the task `exec()` sub-command, using `--interactive`. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() tasks = running_tasks(master) if not tasks: raise CLIException("Unable to find running tasks on master" " '{master}'".format(master=master.addr)) with open(LOREM_IPSUM) as text: returncode, stdout, stderr = exec_command( ["mesos", "task", "exec", "-i", tasks[0]["id"], "cat"], stdin=text) self.assertEqual(returncode, 0) with open(LOREM_IPSUM) as text: self.assertEqual(stdout, text.read()) self.assertEqual(stderr, "") # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_exec(self): """ Basic test for the task `exec()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() with open(LOREM_IPSUM) as text: content = text.read() command = "printf '{data}' > a.txt && sleep 1000".format(data=content) task = Task({"command": command}) task.launch() tasks = running_tasks(master) if not tasks: raise CLIException("Unable to find running tasks on master" " '{master}'".format(master=master.addr)) returncode, stdout, stderr = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "cat", "a.txt"]) self.assertEqual(returncode, 0) self.assertEqual(stdout, content) self.assertEqual(stderr, "") # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_exec_exit_status(self): """ Basic test for the task `exec()` sub-command exit status. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() tasks = running_tasks(master) if not tasks: raise CLIException("Unable to find running tasks on master" " '{master}'".format(master=master.addr)) returncode, _, _ = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "true"]) self.assertEqual(returncode, 0) returncode, _, _ = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "bash", "-c", "exit 10"]) self.assertEqual(returncode, 10) # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_list(self): """ Basic test for the task `list()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() try: wait_for_task(master, task.name, "TASK_RUNNING") except Exception as exception: raise CLIException("Error waiting for task '{name}' to" " reach state '{state}': {error}".format( name=task.name, state="TASK_RUNNING", error=exception)) try: tasks = http.get_json(master.addr, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}". format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) # Invoke the task plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = TaskPlugin(None, test_config) output = capture_output(plugin.list, {"--all": False}) table = Table.parse(output) # Verify there are two rows in the table # and that they are formatted as expected, # with the proper task info in them. self.assertEqual(table.dimensions()[0], 2) self.assertEqual(table.dimensions()[1], 4) self.assertEqual("ID", table[0][0]) self.assertEqual("State", table[0][1]) self.assertEqual("Framework ID", table[0][2]) self.assertEqual("Executor ID", table[0][3]) self.assertEqual(tasks[0]["id"], table[1][0]) self.assertEqual(tasks[0]["statuses"][-1]["state"], table[1][1]) self.assertEqual(tasks[0]["framework_id"], table[1][2]) self.assertEqual(tasks[0]["executor_id"], table[1][3]) # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_list(self): """ Basic test for the task `list()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() try: wait_for_task(master, task.name, "TASK_RUNNING") except Exception as exception: raise CLIException( "Error waiting for task '{name}' to" " reach state '{state}': {error}" .format(name=task.name, state="TASK_RUNNING", error=exception)) try: tasks = http.get_json(master.addr, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}" .format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) # Invoke the task plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = TaskPlugin(None, test_config) output = capture_output(plugin.list, {"--all": False}) table = Table.parse(output) # Verify there are two rows in the table # and that they are formatted as expected, # with the proper task info in them. self.assertEqual(table.dimensions()[0], 2) self.assertEqual(table.dimensions()[1], 4) self.assertEqual("ID", table[0][0]) self.assertEqual("State", table[0][1]) self.assertEqual("Framework ID", table[0][2]) self.assertEqual("Executor ID", table[0][3]) self.assertEqual(tasks[0]["id"], table[1][0]) self.assertEqual(tasks[0]["statuses"][-1]["state"], table[1][1]) self.assertEqual(tasks[0]["framework_id"], table[1][2]) self.assertEqual(tasks[0]["executor_id"], table[1][3]) # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_exec(self): """ Basic test for the task `exec()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() with open(LOREM_IPSUM) as text: content = text.read() command = "printf '{data}' > a.txt && sleep 1000".format(data=content) task = Task({"command": command}) task.launch() try: wait_for_task(master, task.name, "TASK_RUNNING") except Exception as exception: raise CLIException("Error waiting for task '{name}' to" " reach state '{state}': {error}".format( name=task.name, state="TASK_RUNNING", error=exception)) try: tasks = http.get_json(master.addr, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}". format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) returncode, stdout, stderr = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "cat", "a.txt"]) self.assertEqual(returncode, 0) self.assertEqual(stdout, content) self.assertEqual(stderr, "") # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_launch_binaries(self): """ Tests the launching and killing of a mesos master, agent, and task. """ master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() task.kill() agent.kill() master.kill()
def test_launch_binaries(self): """ Tests the launching and killing of a mesos master, agent, and task. """ master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() task.kill() agent.kill() master.kill()
def test_exec(self): """ Basic test for the task `exec()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() with open(LOREM_IPSUM) as text: content = text.read() command = "printf '{data}' > a.txt && sleep 1000".format(data=content) task = Task({"command": command}) task.launch() try: wait_for_task(master, task.name, "TASK_RUNNING") except Exception as exception: raise CLIException( "Error waiting for task '{name}' to" " reach state '{state}': {error}" .format(name=task.name, state="TASK_RUNNING", error=exception)) try: tasks = http.get_json(master.addr, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}" .format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) returncode, stdout, stderr = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "cat", "a.txt"]) self.assertEqual(returncode, 0) self.assertEqual(stdout, content) self.assertEqual(stderr, "") # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_exec_exit_status(self): """ Basic test for the task `exec()` sub-command exit status. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() try: wait_for_task(master, task.name, "TASK_RUNNING") except Exception as exception: raise CLIException("Error waiting for task '{name}' to" " reach state '{state}': {error}".format( name=task.name, state="TASK_RUNNING", error=exception)) try: tasks = http.get_json(master.addr, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}". format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) returncode, _, _ = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "true"]) self.assertEqual(returncode, 0) returncode, _, _ = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "bash", "-c", "exit 10"]) self.assertEqual(returncode, 10) # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_exec_exit_status(self): """ Basic test for the task `exec()` sub-command exit status. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() try: wait_for_task(master, task.name, "TASK_RUNNING") except Exception as exception: raise CLIException( "Error waiting for task '{name}' to" " reach state '{state}': {error}" .format(name=task.name, state="TASK_RUNNING", error=exception)) try: tasks = http.get_json(master.addr, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}" .format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) returncode, _, _ = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "true"]) self.assertEqual(returncode, 0) returncode, _, _ = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "bash", "-c", "exit 10"]) self.assertEqual(returncode, 10) # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_list(self): """ Basic test for the task `list()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() # Open the master's `/tasks` endpoint and read the # task information ourselves. tasks = http.get_json(master.addr, 'tasks')["tasks"] self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) # Invoke the task plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = TaskPlugin(None, test_config) output = capture_output(plugin.list, {}) table = Table.parse(output) # Verify there are two rows in the table # and that they are formatted as expected, # with the proper task info in them. self.assertEqual(table.dimensions()[0], 2) self.assertEqual(table.dimensions()[1], 3) self.assertEqual("Task ID", table[0][0]) self.assertEqual("Framework ID", table[0][1]) self.assertEqual("Executor ID", table[0][2]) self.assertEqual(tasks[0]["id"], table[1][0]) self.assertEqual(tasks[0]["framework_id"], table[1][1]) self.assertEqual(tasks[0]["executor_id"], table[1][2]) # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_list(self): """ Basic test for the task `list()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() task = Task({"command": "sleep 1000"}) task.launch() # Open the master's `/tasks` endpoint and read the # task information ourselves. tasks = http.get_json(master.addr, 'tasks')["tasks"] self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 1) # Invoke the task plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = TaskPlugin(None, test_config) output = capture_output(plugin.list, {}) table = Table.parse(output) # Verify there are two rows in the table # and that they are formatted as expected, # with the proper task info in them. self.assertEqual(table.dimensions()[0], 2) self.assertEqual(table.dimensions()[1], 3) self.assertEqual("Task ID", table[0][0]) self.assertEqual("Framework ID", table[0][1]) self.assertEqual("Executor ID", table[0][2]) self.assertEqual(tasks[0]["id"], table[1][0]) self.assertEqual(tasks[0]["framework_id"], table[1][1]) self.assertEqual(tasks[0]["executor_id"], table[1][2]) # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_list(self): """ Basic test for the agent `list()` sub-command. """ # Launch a master and agent. master = Master() master.launch() agent = Agent() agent.launch() # Open the master's `/slaves` endpoint and read the # agents' information ourselves. agents = http.get_json(master.addr, 'slaves', config.Config(None))["slaves"] self.assertEqual(type(agents), list) self.assertEqual(len(agents), 1) # Invoke the agent plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = AgentPlugin(None, test_config) output = capture_output(plugin.list, {}) table = Table.parse(output) # Verify there are two rows in the table # and that they are formatted as expected, # with the proper agent info in them. self.assertEqual(table.dimensions()[0], 2) self.assertEqual(table.dimensions()[1], 3) self.assertEqual("Agent ID", table[0][0]) self.assertEqual("Hostname", table[0][1]) self.assertEqual("Active", table[0][2]) self.assertEqual(agents[0]["id"], table[1][0]) self.assertEqual(agents[0]["hostname"], table[1][1]) self.assertEqual(str(agents[0]["active"]), table[1][2]) # Kill the agent and master. agent.kill() master.kill()
def test_exec(self): """ Basic test for the task `exec()` sub-command. """ # Launch a master, agent, and task. master = Master() master.launch() agent = Agent() agent.launch() with open(LOREM_IPSUM) as text: content = text.read() command = "echo '{data}' > a.txt && sleep 1000".format(data=content) task = Task({"command": command}) task.launch() # We wait (max 1 second) for the task to be in a running state. @retry(stop=stop_after_delay(1)) def updated_tasks(): # Open the master's `/tasks` endpoint and # read the task information ourselves. tasks = http.get_json(master.addr, "tasks")["tasks"] if tasks[0]["state"] == "TASK_RUNNING": return tasks raise CLIException("Unable to find running task in master state" " '{master}'".format(master=master)) tasks = updated_tasks() returncode, stdout, stderr = exec_command( ["mesos", "task", "exec", tasks[0]["id"], "cat", "a.txt"]) self.assertEqual(returncode, 0) self.assertEqual(stdout.strip(), content.strip()) self.assertEqual(stderr, "") # Kill the task, agent, and master. task.kill() agent.kill() master.kill()
def test_list(self): """ Basic test for the agent `list()` sub-command. """ # Launch a master and agent. master = Master() master.launch() agent = Agent() agent.launch() # Open the master's `/slaves` endpoint and read the # agents' information ourselves. agents = http.get_json(master.addr, 'slaves')["slaves"] self.assertEqual(type(agents), list) self.assertEqual(len(agents), 1) # Invoke the agent plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = AgentPlugin(None, test_config) output = capture_output(plugin.list, {}) table = Table.parse(output) # Verify there are two rows in the table # and that they are formatted as expected, # with the proper agent info in them. self.assertEqual(table.dimensions()[0], 2) self.assertEqual(table.dimensions()[1], 3) self.assertEqual("Agent ID", table[0][0]) self.assertEqual("Hostname", table[0][1]) self.assertEqual("Active", table[0][2]) self.assertEqual(agents[0]["id"], table[1][0]) self.assertEqual(agents[0]["hostname"], table[1][1]) self.assertEqual(str(agents[0]["active"]), table[1][2]) # Kill the agent and master. agent.kill() master.kill()
def test_list_all(self): """ Basic test for the task `list()` sub-command with flag `--all`. """ # Launch a master, agent, and two tasks. master = Master() master.launch() agent = Agent() agent.launch() task1 = Task({"command": "true"}) task1.launch() task1_state = "TASK_FINISHED" try: wait_for_task(master, task1.name, task1_state) except Exception as exception: raise CLIException( "Error waiting for task '{name}' to" " reach state '{state}': {error}" .format(name=task1.name, state=task1_state, error=exception)) task2 = Task({"command": "sleep 1000"}) task2.launch() task2_state = "TASK_RUNNING" try: wait_for_task(master, task2.name, task2_state) except Exception as exception: raise CLIException( "Error waiting for task '{name}' to" " reach state '{state}': {error}" .format(name=task2.name, state=task2_state, error=exception)) try: tasks = http.get_json(master.addr, None, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}" .format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 2) # Invoke the task plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = TaskPlugin(None, test_config) output = capture_output(plugin.list, {"--all": True}) table = Table.parse(output) # Verify that there are two rows in the table, one for the running task # and one for the finished task. We do verify the information in the # table as this is already covered in the test `test_list`. self.assertEqual(table.dimensions()[0], 3) self.assertEqual(table.dimensions()[1], 4) # Kill the task1, task2, agent, and master. task1.kill() task2.kill() agent.kill() master.kill()
def test_list_all(self): """ Basic test for the task `list()` sub-command with flag `--all`. """ # Launch a master, agent, and two tasks. master = Master() master.launch() agent = Agent() agent.launch() task1 = Task({"command": "true"}) task1.launch() task1_state = "TASK_FINISHED" try: wait_for_task(master, task1.name, task1_state) except Exception as exception: raise CLIException( "Error waiting for task '{name}' to" " reach state '{state}': {error}" .format(name=task1.name, state=task1_state, error=exception)) task2 = Task({"command": "sleep 1000"}) task2.launch() task2_state = "TASK_RUNNING" try: wait_for_task(master, task2.name, task2_state) except Exception as exception: raise CLIException( "Error waiting for task '{name}' to" " reach state '{state}': {error}" .format(name=task2.name, state=task2_state, error=exception)) try: tasks = http.get_json(master.addr, "tasks")["tasks"] except Exception as exception: raise CLIException( "Could not get tasks from '/{endpoint}' on master: {error}" .format(endpoint="tasks", error=exception)) self.assertEqual(type(tasks), list) self.assertEqual(len(tasks), 2) # Invoke the task plugin `list()` command # and parse its output as a table. test_config = config.Config(None) plugin = TaskPlugin(None, test_config) output = capture_output(plugin.list, {"--all": True}) table = Table.parse(output) # Verify that there are two rows in the table, one for the running task # and one for the finished task. We do verify the information in the # table as this is already covered in the test `test_list`. self.assertEqual(table.dimensions()[0], 3) self.assertEqual(table.dimensions()[1], 4) # Kill the task1, task2, agent, and master. task1.kill() task2.kill() agent.kill() master.kill()