Beispiel #1
0
    def run(self, kwargs):
        job_log.debug(
            "Unconfigure stratagem timer step kwargs: {}".format(kwargs))

        config = kwargs["config"]

        if runningInDocker():
            api_key = os.getenv("API_KEY")
            api_user = os.getenv("API_USER")
            s = get_api_session_request(api_user, api_key)
            result = s.delete("{}/timer/unconfigure/{}".format(
                SERVER_HTTP_URL, config.id),
                              verify=False)

            if not result.ok:
                raise RuntimeError(result.reason)
        else:
            self.try_shell([
                "systemctl", "disable", "--now",
                "{}.timer".format(unit_name(config.id))
            ])

            os.unlink(timer_file(config.id))
            os.unlink(service_file(config.id))
            self.try_shell(["systemctl", "daemon-reload"])
Beispiel #2
0
    def test_send_action(self, post, socket_post, uuid):
        invoke_rust_agent("mds1.local", "ls")

        if runningInDocker():
            post.assert_called_once_with(
                "http://127.0.0.1:8009",
                json={
                    "REMOTE": ("mds1.local", {
                        "action": "ls",
                        "args": {},
                        "type": "ACTION_START",
                        "id": "1-2-3-4"
                    })
                },
            )
        else:
            socket_post.assert_called_once_with(
                "http+unix://%2Fvar%2Frun%2Fiml-action-runner.sock/",
                json={
                    "REMOTE": ("mds1.local", {
                        "action": "ls",
                        "args": {},
                        "type": "ACTION_START",
                        "id": "1-2-3-4"
                    })
                },
            )
Beispiel #3
0
    def test_error_raises(self, post, socket_post, uuid):
        if runningInDocker():
            post.side_effect = Exception("ruh-roh")
        else:
            socket_post.side_effect = Exception("ruh-roh")

        with self.assertRaises(Exception):
            invoke_rust_agent("mds1.local", "ls")
Beispiel #4
0
    def test_get_data(self, post, socket_post, uuid):
        if runningInDocker():
            post.return_value.content = "{}"
        else:
            socket_post.return_value.content = "{}"

        r = invoke_rust_agent("mds1.local", "ls")

        self.assertEqual(r, "{}")
Beispiel #5
0
    def run(self, kwargs):
        job_log.debug(
            "Configure stratagem timer step kwargs: {}".format(kwargs))
        # Create systemd timer

        config = kwargs["config"]

        iml_cmd = self.get_run_stratagem_command("/usr/bin/iml stratagem scan",
                                                 config)

        interval_in_seconds = config.interval / 1000
        # Create timer file
        timer_config = """# This file is part of IML
# This file will be overwritten automatically

[Unit]
Description=Start Stratagem run on {}

[Timer]
OnActiveSec={}
OnUnitActiveSec={}
AccuracySec=1us
Persistent=true

[Install]
WantedBy=timers.target
""".format(config.filesystem.id, interval_in_seconds, interval_in_seconds)

        service_config = """# This file is part of IML
# This file will be overwritten automatically

[Unit]
Description=Start Stratagem run on {}
{}

[Service]
Type=oneshot
EnvironmentFile=/var/lib/chroma/iml-settings.conf
ExecStart={}
""".format(config.filesystem.id,
           "After=iml-manager.target" if not runningInDocker() else "",
           iml_cmd)

        post_data = {
            "config_id": str(config.id),
            "file_prefix": "iml-stratagem",
            "timer_config": timer_config,
            "service_config": service_config,
        }

        result = requests.put("{}/configure/".format(TIMER_PROXY_PASS),
                              json=post_data)

        if not result.ok:
            raise RuntimeError(result.reason)
Beispiel #6
0
    def run(self, kwargs):
        job_log.debug(
            "Unconfigure stratagem timer step kwargs: {}".format(kwargs))

        config = kwargs["config"]

        if runningInDocker():
            result = requests.delete("{}/unconfigure/iml-stratagem/{}".format(
                TIMER_PROXY_PASS, config.id))

            if not result.ok:
                raise RuntimeError(result.reason)
        else:
            self.try_shell([
                "systemctl", "disable", "--now",
                "{}.timer".format(unit_name(config.id))
            ])

            os.unlink(timer_file(config.id))
            os.unlink(service_file(config.id))
            self.try_shell(["systemctl", "daemon-reload"])
    def run(self, kwargs):
        job_log.debug("Configure stratagem timer step kwargs: {}".format(kwargs))
        # Create systemd timer

        config = kwargs["config"]
        interval_in_seconds = config.interval / 1000

        if runningInDocker():
            iml_cmd = self.get_run_stratagem_command("/usr/bin/start-stratagem-scan", config, None)

            # Create timer file
            timer_config = """# This file is part of IML
# This file will be overwritten automatically

[Unit]
Description=Start Stratagem run on {}

[Timer]
OnActiveSec={}
OnUnitActiveSec={}
AccuracySec=1us
Persistent=true

[Install]
WantedBy=timers.target
""".format(
                config.filesystem.id, interval_in_seconds, interval_in_seconds
            )

            service_config = """# This file is part of IML
# This file will be overwritten automatically

[Unit]
Description=Start Stratagem run on {}

[Service]
Type=oneshot
EnvironmentFile=/var/lib/chroma/iml-settings.conf
ExecStart={}
""".format(
                config.filesystem.id, iml_cmd
            )

            post_data = {"config_id": str(config.id), "timer_config": timer_config, "service_config": service_config}

            api_key = os.getenv("API_KEY")
            api_user = os.getenv("API_USER")
            s = get_api_session_request(api_user, api_key)
            result = s.put("{}/timer/configure/".format(SERVER_HTTP_URL), json=post_data, verify=False)

            if not result.ok:
                raise RuntimeError(result.reason)
        else:
            iml_cmd = self.get_run_stratagem_command("/usr/bin/iml stratagem scan", config, "s")

            with open(timer_file(config.id), "w") as fn:
                fn.write(
                    """#  This file is part of IML
#  This file will be overwritten automatically
[Unit]
Description=Start Stratagem run on {}

[Timer]
OnActiveSec={}
OnUnitActiveSec={}
Persistent=true

[Install]
WantedBy=timers.target
""".format(
                        config.filesystem.id, interval_in_seconds, interval_in_seconds
                    )
                )

            with open(service_file(config.id), "w") as fn:
                fn.write(
                    """#  This file is part of IML
#  This file will be overwritten automatically
[Unit]
Description=Start Stratagem run on {}
After=iml-manager.target

[Service]
Type=oneshot
ExecStart={}
""".format(
                        config.filesystem.id, iml_cmd
                    )
                )
            self.try_shell(["systemctl", "daemon-reload"])
            self.try_shell(["systemctl", "enable", "--now", "{}.timer".format(unit_name(config.id))])