Example #1
0
 def test_init_no_configuration_files(self, monkeypatch, caplog):
     with monkeypatch.context() as m:
         m.setattr(settings.PATHS, "local_conf", "/foobar/")
         m.setattr(settings.PATHS, "global_conf", "/foobar/")
         context = statemachine.Context()
         context = statemachine.Init().run(context)
         assert "No configuration files found for the device" in caplog.text
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)
Example #3
0
 def test_init(self, monkeypatch, caplog):
     with monkeypatch.context() as m:
         m.setattr(identity, "aggregate", lambda *args, **kwargs: {"foo", "bar"})
         m.setattr(
             settings.PATHS,
             "local_conf",
             os.path.join(os.getcwd(), "tests/unit/data/configs/local_mender.conf"),
         )
         m.setattr(
             settings.PATHS,
             "global_conf",
             os.path.join(os.getcwd(), "tests/unit/data/configs/global_mender.conf"),
         )
         context = statemachine.Context()
         context = statemachine.Init().run(context)
         assert "Loaded configuration" in caplog.text