Exemple #1
0
    def get_varnish_status(self, request, env_name, deploy_stage):
        if deploy_stage == NgappDeployStep.PRE_DEPLOY:
            page = 'ngapp2/ngapp2_pre_deploy.html'
            status_file = settings.NGAPP_PRE_DEPLOY_STATUS_NODE
        elif deploy_stage == NgappDeployStep.POST_DEPLOY:
            page = 'ngapp2/ngapp2_post_deploy.html'
            status_file = settings.NGAPP_POST_DEPLOY_STATUS_NODE
        else:
            page = 'ngapp2/ngapp2_rollback.html'
            status_file = settings.NGAPP_ROLLBACK_STATUS_NODE

        recorder = Recorder(status_file)
        state, total, correct = recorder.read_varish_info()
        total = int(total)
        correct = int(correct)
        progress = correct * 100 / total
        if deploy_stage in self.ENDING_STATE and state == "DONE":
            Ngapp2DeployUtils().set_status_to_zk("SERVING_BUILD")

        return state, render(request, page, {
            "current_status": state,
            "correct_node": correct,
            "total_node": total,
            "progress": progress,
            "env_name": env_name
        })
Exemple #2
0
    def get_varnish_status(self, request, env_name, deploy_stage):
        if deploy_stage == NgappDeployStep.PRE_DEPLOY:
            page = 'ngapp2/ngapp2_pre_deploy.html'
            status_file = settings.NGAPP_PRE_DEPLOY_STATUS_NODE
        elif deploy_stage == NgappDeployStep.POST_DEPLOY:
            page = 'ngapp2/ngapp2_post_deploy.html'
            status_file = settings.NGAPP_POST_DEPLOY_STATUS_NODE
        else:
            page = 'ngapp2/ngapp2_rollback.html'
            status_file = settings.NGAPP_ROLLBACK_STATUS_NODE

        recorder = Recorder(status_file)
        state, total, correct = recorder.read_varish_info()
        total = int(total)
        correct = int(correct)
        progress = correct * 100 / total
        if deploy_stage in self.ENDING_STATE and state == "DONE":
            Ngapp2DeployUtils().set_status_to_zk("SERVING_BUILD")

        return state, render(
            request, page, {
                "current_status": state,
                "correct_node": correct,
                "total_node": total,
                "progress": progress,
                "env_name": env_name
            })
Exemple #3
0
 def start_post_deploy(self, request):
     Recorder(settings.NGAPP_POST_DEPLOY_STATUS_NODE).init_info()
     if is_prod():
         virtual_env = os.path.join(os.environ.get("VIRTUAL_ENV","/usr/local"), "bin")
         cmd = [os.path.join(virtual_env, "python"),
                os.path.join(virtual_env, "ngapp-post-deploy")]
     else:
         cmd = [os.path.join(os.environ.get("BASE_DIR"), "../integ_test/ngapp2/post_deploy")]
     result = execute(cmd=cmd)
     if result < 0:
         raise
Exemple #4
0
    def start_pre_deploy(self, request):
        Recorder(settings.NGAPP_PRE_DEPLOY_STATUS_NODE).init_info()
        if is_prod():
            virtual_env = os.path.join(os.environ.get("VIRTUAL_ENV", "/usr/local"), "bin")
            cmd = [os.path.join(virtual_env, "python"),
                   os.path.join(virtual_env, "ngapp-pre-deploy")]
        else:
            cmd = [os.path.join(os.environ.get("BASE_DIR"), "../integ_test/ngapp2/pre_deploy")]

        result = execute(cmd=cmd)
        if result < 0:
            raise
        # also disable health check for webapp
        disable_health_check(request)
Exemple #5
0
 def start_roll_back(self):
     Recorder(settings.NGAPP_ROLLBACK_STATUS_NODE).init_info()
     if is_prod():
         virtual_env = os.path.join(os.environ.get("VIRTUAL_ENV"), "bin")
         cmd = [
             os.path.join(virtual_env, "python"),
             os.path.join(virtual_env, "ngapp-rollback")
         ]
     else:
         cmd = [
             os.path.join(os.environ.get("BASE_DIR"),
                          "integ_test/ngapp2/rollback")
         ]
     result = execute(cmd)
     if result < 0:
         raise
Exemple #6
0
    def start_roll_back(self, request):
        Recorder(settings.NGAPP_ROLLBACK_STATUS_NODE).init_info()

        params = request.POST
        reason = params.get("description")
        build_sha = params.get("build")
        operator = request.teletraan_user_id.name

        if is_prod():
            virtual_env = os.path.join(os.environ.get("VIRTUAL_ENV"), "bin")
            cmd = [
                os.path.join(virtual_env, "python"),
                os.path.join(virtual_env, "ngapp-rollback")
            ]
        else:
            cmd = [
                os.path.join(os.environ.get("BASE_DIR"),
                             "../integ_test/ngapp2/rollback")
            ]

        result = execute(cmd)
        if result < 0:
            raise

        # record history
        timestamp = time.time() * 1000
        deploy = {
            "startDate": timestamp,
            "type": "ROLLBACK",
            "state": "SUCCEEDED",
            "acceptanceStatus": "ACCEPTED",
            "operator": operator,
            "successTotal": 1,
            "total": 1,
            "reason": reason
        }
        build = {"commitShort": build_sha}
        history = {"deploy": deploy, "build": build}

        s3 = s3_helper.S3Helper(bucket_name=S3_INTERNAL_TOOLS_BUCKET_NAME)
        history_key = get_rollback_history_key()
        s3.upload_string("%s/%d" % (history_key, timestamp),
                         json.dumps(history))