コード例 #1
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)
コード例 #2
0
def test_no_install_script(caplog, monkeypatch, tmpdir):
    d = tmpdir.mkdir("test_install_script")
    lockfile = os.path.join(d, "lockfile.test")
    install_script = os.path.join(d, "install")
    with monkeypatch.context() as m:
        m.setattr(settings.PATHS, "lockfile_path", lockfile)
        m.setattr(settings.PATHS, "install_script", install_script)
        assert not runner.run_sub_updater("deploymentid-2")
        assert "No install script found" in caplog.text
コード例 #3
0
def test_run_sub_updater(monkeypatch, tmpdir):
    d = tmpdir.mkdir("test_lockfile")
    lockfile = os.path.join(d, "lockfile.test")
    install_script = d.join("install")
    install_script.write("#!/bin/sh echo foo")
    os.chmod(install_script, stat.S_IRWXU | stat.S_IRWXO | stat.S_IRWXG)
    with monkeypatch.context() as m:
        m.setattr(settings.PATHS, "lockfile_path", lockfile)
        m.setattr(settings.PATHS, "install_script", install_script)
        assert runner.run_sub_updater("deploymentid-2") == runner.INSTALL_SCRIPT_OK
        assert os.path.exists(lockfile)
コード例 #4
0
 def run(self, context):
     log.info("Running the ArtifactInstall state...")
     if installscriptrunner.run_sub_updater(context.deployment.ID):
         log.info(
             "The client has successfully spawned the install-script process. Exiting. Goodbye!"
         )
         sys.exit(0)
         # return ArtifactReboot()
     log.error(
         "The daemon should never reach this point. Something is wrong with the setup of the client."
     )
     sys.exit(1)
コード例 #5
0
def test_install_script_permissions(caplog, monkeypatch, tmpdir):
    d = tmpdir.mkdir("test_install_script")
    lockfile = os.path.join(d, "lockfile.test")
    install_script = d.join("install")
    install_script.write("jibberish")
    with monkeypatch.context() as m:
        m.setattr(settings.PATHS, "lockfile_path", lockfile)
        m.setattr(settings.PATHS, "install_script", install_script)
        assert not runner.run_sub_updater("deploymentid-2")
        assert (
            f"The install script '{settings.PATHS.install_script}' has the wrong permissions"
            in caplog.text
        )
コード例 #6
0
 def run(self, context):
     log.info("Running the ArtifactInstall state...")
     if installscriptrunner.run_sub_updater(context.deployment.ID):
         return ArtifactReboot()
     return ArtifactFailure()