예제 #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
예제 #2
0
 def test_idle(self, monkeypatch):
     context = statemachine.Context()
     context.retry_timer = 1
     monkeypatch.setattr(timeutil, "sleep", time.sleep)
     time_1 = time.time()
     statemachine.Idle().run(context)
     time_2 = time.time()
     assert abs(time_2 - time_1) < 2
예제 #3
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)
예제 #4
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
예제 #5
0
def fixture_ctx():
    settings.PATHS.deployment_log = os.getcwd()
    context = statemachine.Context()
    context.JWT = "foobar"
    context.config = config.Config({}, {})
    context.update_timer = timeutil.IsItTime
    context.deployment_log_handler = DeploymentLogHandler()
    context.deployment = deployments.DeploymentInfo(
        {
            "id": "bugsbunny",
            "artifact": {
                "artifact_name": "release-1",
                "source": {"uri": "https://docker.mender.io",},
            },
        }
    )
    return context
예제 #6
0
def fixture_ctx():
    settings.PATHS.deployment_log = os.getcwd()
    context = statemachine.Context()
    context.JWT = "foobar"
    return context