コード例 #1
0
def report(args):
    context = statemachine.Context()
    context = statemachine.Init().run(context)
    jwt = authorize.request(
        context.config.ServerURL,
        context.config.TenantToken,
        context.identity_data,
        context.private_key,
        context.config.ServerCertificate,
    )
    if not jwt:
        log.error("Failed to authorize with the Mender server")
        sys.exit(1)
    try:
        with open(settings.PATHS.lockfile_path) as f:
            deployment_id = f.read()
            if not deployment_id:
                log.error("No deployment ID found in the lockfile")
                sys.exit(1)
    except FileNotFoundError:
        log.error("No update in progress...")
        sys.exit(1)
    if args.success:
        log.info("Reporting a successful update to the Mender server")
        if not deployments.report(
                context.config.ServerURL,
                deployments.STATUS_SUCCESS,
                deployment_id,
                context.config.ServerCertificate,
                jwt,
                deployment_logger=None,
        ):
            log.error(
                "Failed to report the successful update status to the Mender server"
            )
            sys.exit(1)
    elif args.failure:
        log.info("Reporting a failed update to the Mender server")
        log.parent.deployment_log_handler.enable()
        if not deployments.report(
                context.config.ServerURL,
                deployments.STATUS_FAILURE,
                deployment_id,
                context.config.ServerCertificate,
                jwt,
                log.parent.deployment_log_handler,
        ):
            log.error(
                "Failed to report the failed update status to the Mender server"
            )
            sys.exit(1)
    else:
        log.error("No report status given")
        sys.exit(1)
コード例 #2
0
 def run(self, context):
     log.info("Running the ArtifactInstall state...")
     ret = installscriptrunner.run_sub_updater(context.deployment.ID)
     if ret == installscriptrunner.INSTALL_SCRIPT_OK:
         log.info(
             "The client has successfully spawned the install-script process. Exiting. Goodbye!"
         )
         sys.exit(0)
         # return ArtifactReboot()
     elif ret in (
             installscriptrunner.INSTALL_SCRIPT_NOT_FOUND_ERROR,
             installscriptrunner.INSTALL_SCRIPT_PERMISSION_ERROR,
     ):
         if not deployments.report(
                 context.config.ServerURL,
                 deployments.STATUS_FAILURE,
                 context.deployment.ID,
                 context.config.ServerCertificate,
                 context.JWT,
                 deployment_logger=log,
         ):
             log.error(
                 "Failed to report the deployment status 'FAILURE' to the Mender server"
             )
     else:
         log.error(
             "The daemon should never reach this point. Something is wrong with the setup of the client."
         )
     sys.exit(1)
コード例 #3
0
 def run(self, context):
     log.info("Running the Download state...")
     if deployments.download(
             context.deployment,
             artifact_path=os.path.join(settings.PATHS.artifact_download,
                                        "artifact.mender"),
             server_certificate=context.config.ServerCertificate,
     ):
         if not deployments.report(
                 context.config.ServerURL,
                 deployments.STATUS_DOWNLOADING,
                 context.deployment.ID,
                 context.config.ServerCertificate,
                 context.JWT,
                 deployment_logger=None,
         ):
             log.error(
                 "Failed to report the deployment status 'downloading' to the Mender server"
             )
         return ArtifactInstall()
     log.warning(
         "The Artifact has not been properly downloaded due to lack of Internet access or a server failure."
     )
     log.warning(
         "The next attempt of the update will happen after the UpdatePollIntervalSeconds config variable."
     )
     return ArtifactFailure()
コード例 #4
0
def report_no_install_script(context):

    jwt = authorize.request(
        context.config.ServerURL,
        context.config.TenantToken,
        context.identity_data,
        context.private_key,
        context.config.ServerCertificate,
    )

    return deployments.report(
            context.config.ServerURL,
            "failure",
            context.deployment_id,
            context.config.ServerCertificate,
            jwt
    )
    
コード例 #5
0
 def run(self, context):
     log.info("Running the Download state...")
     if deployments.download(
             context.deployment,
             artifact_path=os.path.join(settings.PATHS.artifact_download,
                                        "artifact.mender"),
             server_certificate=context.config.ServerCertificate,
     ):
         if not deployments.report(
                 context.config.ServerURL,
                 deployments.STATUS_DOWNLOADING,
                 context.deployment.ID,
                 context.config.ServerCertificate,
                 context.JWT,
         ):
             log.error(
                 "Failed to report the deployment status 'downloading' to the Mender server"
             )
         return ArtifactInstall()
     return ArtifactFailure()