예제 #1
0
    def test_update_deploy_meta(self, session, _session):
        _commit = mock.Mock()
        _session.commit = _commit
        _insert_data = DeployMeta(
            taskname="sample_task",
            user_id=42,
            repo_uri="[email protected]:user/repo.git",
            entry_point="sample",
            hosts=[1, 2]
        )
        session.add(_insert_data)

        with mock.patch.object(
            DeployMeta, "query", session.query_property()
        ) as _query:
            _id = session.query(DeployMeta).first().id
            DeployMeta.update_deploy_meta(deploy_id=_id,
                                          status=1,
                                          msg=u"placeholder")
            _query_data = session.query(DeployMeta).filter_by(
                id=_id
            ).first()
            self.assertEqual(_query_data.status, 1)
            self.assertEqual(_query_data.msg, u"placeholder")
            _commit.assert_called_once_with()
예제 #2
0
파일: deploy.py 프로젝트: TheSophon/sophon
 def get(self):
     result = DeployMeta.get_all_deploy_summary()
     for key in result.keys():
         result[key]["Created"] = created2str(
             result[key]["Created"]
         )
     self.write(result)
예제 #3
0
파일: deploy.py 프로젝트: TheSophon/sophon
def deploy(deploy_id, entry_point, user, hosts_ip, repo_uri):
    deploy_playbook = DEPLOY_TEMPLATE_PART_VARS.format(
        hosts_ip_arg=",".join(hosts_ip),
        user_arg=user,
        app_name_arg=entry_point,
        repo_uri_arg=repo_uri
    ) + DEPLOY_TEMPLATE_PART_TASK
    with tempfile.NamedTemporaryFile(suffix=".yml") as tmp_playbook:
        tmp_playbook.write(deploy_playbook)
        tmp_playbook.flush()
        msg = subprocess.Popen(
            "ansible-playbook " + tmp_playbook.name,
            shell=True,
            stdout=subprocess.PIPE
        ).stdout.read()
        status = 2 if "FAILED!" in msg.upper() else 1
        DeployMeta.update_deploy_meta(deploy_id=deploy_id,
                                      status=status, msg=msg)
예제 #4
0
    def test_get_all_deploy_summary(self, session, _session):
        _insert_data = DeployMeta(
            taskname="sample_task",
            repo_uri="[email protected]:user/repo.git",
            user_id=42,
            entry_point="sample",
            hosts=[1, 2]
        )
        session.add(_insert_data)

        with mock.patch.object(
            DeployMeta, "query", session.query_property()
        ) as _query:
            summary = DeployMeta.get_all_deploy_summary()
            _id = summary.keys()[0]
            self.assertEqual(summary[_id]["Taskname"], "sample_task")
            self.assertEqual(summary[_id]["Status"], 0)
예제 #5
0
    def test_get_deploy_item_by_id(self, session):
        _insert_data = DeployMeta(
            taskname="sample_task",
            user_id=42,
            repo_uri="[email protected]:user/repo.git",
            entry_point="sample",
            hosts=[1, 2]
        )
        session.add(_insert_data)
        _id = session.query(DeployMeta).all()[-1].id

        with mock.patch.object(
            DeployMeta, "query", session.query_property()
        ) as _query:
            deploy_item = DeployMeta.get_deploy_item_by_id(deploy_id=_id)
            self.assertEqual(deploy_item["Taskname"], "sample_task")
            self.assertEqual(deploy_item["Status"], 0)
            self.assertEqual(deploy_item["Repo URI"],
                             "[email protected]:user/repo.git")
            self.assertEqual(deploy_item["Entry Point"], "sample")
            self.assertEqual(deploy_item["Hosts"], [1, 2])
            self.assertEqual(deploy_item["Msg"], "")
예제 #6
0
파일: deploy.py 프로젝트: TheSophon/sophon
 def get(self, deploy_id):
     result = DeployMeta.get_deploy_item_by_id(deploy_id=int(deploy_id))
     result.update({
         "Created": created2str(created=result["Created"])
     })
     self.write(result)