def post(self): taskname = self.get_argument("taskname") repo_uri = self.get_argument("repo_uri") entry_point = self.get_argument("entry_point") hosts = json.loads(self.get_argument("hosts")) username = self.get_secure_cookie("username") user_id = UserMeta.query.filter_by(username=username).first().id deploy_item = DeployMeta(taskname=taskname, user_id=user_id, repo_uri=repo_uri, entry_point=entry_point, hosts=hosts) session.add(deploy_item) session.commit() session.close() do_deploy(deploy_id=deploy_item.id, entry_point=entry_point, user="******", hosts=hosts, repo_uri=repo_uri) self.write({ deploy_item.id: { "Taskname": deploy_item.taskname, "Status": deploy_item.status, "Created": created2str(created=deploy_item.created) } })
def test_do_deploy(self, _HostMeta, _Process, _deploy): _process_item = mock.Mock() _Process.return_value = _process_item _HostMeta.get_all_hosts_status.return_value = { 1: {"IP": "123.45.67.89"} } do_deploy(1, "sample_entry_point", "root", [1], "uri") _HostMeta.get_all_hosts_status.assert_called_once_with() _Process.assert_called_once_with( target=_deploy, kwargs={ "deploy_id": 1, "user": "******", "entry_point": "sample_entry_point", "hosts_ip": ["123.45.67.89"], "repo_uri": "uri" } ) _process_item.start.assert_called_once_with()