def test_command_with_no_user_input(self):
        expected_command = ["cmd", "--arg"]
        command = ReactorCommand(cmd=expected_command)

        self.assertEqual(
            expected_command,
            command.resolve(ctx=test_context(mode=Mode.INTERACTIVE)))
Beispiel #2
0
    def react(self, data: ValidationResult, ctx: Context):

        commands = []
        if data.status == Status.NOT_FOUND:
            ctx.logger.info(
                "Going to configure missing gcloud authentication...")

            if data.input_data is None or not data.input_data.docker_ok:
                commands.append(
                    ReactorCommand(
                        cmd=["gcloud", "auth", "configure-docker", "--quiet"]))

            if data.input_data is None or not data.input_data.auth_ok:
                email_input = UserInput(
                    key="gcloud_email",
                    prompt="\nPlease enter your GCloud email address: ")
                commands.append(
                    ReactorCommand(
                        cmd=["gcloud", "auth", "login", email_input]))
                commands.append(
                    ReactorCommand(
                        cmd=["gcloud", "auth", "application-default", "login"
                             ]))

        else:
            ctx.logger.info("Gcloud authentication already configured")

        return commands
Beispiel #3
0
    def react(self, data: ValidationResult, ctx: Context):

        commands = []
        if data.status == Status.NOT_FOUND:
            commands = download_and_install_commands_for(
                ctx.config["installer"]["python"]["macos_package_url"])
            commands.append(
                ReactorCommand(
                    ["/Applications/Python 3.6/Install Certificates.command"]))
            commands.append(
                ReactorCommand(
                    ["/Applications/Python 3.6/Update Shell Profile.command"]))
        else:
            ctx.logger.info(
                "Python 3 already installed! Detected version: {} - {}!".
                format(data.input_data.version, data.status.name))

        return commands
Beispiel #4
0
def download_command_for(url):
    target_dir = tempfile.mkdtemp(prefix="envinstaller-")

    parsed_url = urlparse(url)
    file_name = path.basename(parsed_url.path)
    target_file_path = path.join(target_dir, file_name)

    return ReactorCommand(
        ["curl", "-s", "--compressed", "-o", target_file_path,
         url]), target_file_path
Beispiel #5
0
    def react(self, data: ValidationResult, ctx: Context):

        commands = []
        if data.status == Status.NOT_FOUND:
            commands.append(
                ReactorCommand(
                    cmd=["brew", "cask", "install", "google-cloud-sdk"]))
        else:
            ctx.logger.info("Gcloud already installed")

        return commands
Beispiel #6
0
    def react(self, data: ValidationResult, ctx: Context):

        commands = []
        if data.status == Status.NOT_FOUND:
            download_command, file_path = download_command_for(
                "https://raw.githubusercontent.com/Homebrew/install/master/install"
            )

            commands.append(download_command)
            commands.append(ReactorCommand(cmd=["ruby", "--", file_path]))
        else:
            ctx.logger.info("Homebrew already installed")

        return commands
Beispiel #7
0
    def react(self, data: ValidationResult, ctx: Context):

        commands = []
        if data.status == Status.NOT_FOUND:
            download_command, dmg_file = download_command_for(
                ctx.config["installer"]["docker"]["macos_package_url"])
            commands.append(download_command)
            commands.append(mount_command_for(dmg_file))
            commands.append(
                ReactorCommand([
                    "cp", "-r", "/Volumes/Docker/Docker.app", "/Applications"
                ]))
        elif data.status == Status.OK:
            ctx.logger.info("Docker already installed!")

        return commands
Beispiel #8
0
    def react(self, data: ValidationResult, ctx: Context):
        commands = []

        if data.status == Status.NOT_FOUND:
            ctx.logger.info(
                "Xcode CLI tools could not be detected! Will start interactive installer."
            )
            ctx.logger.warn("""IMPORTANT!
- If you recently changed/removed Xcode, it is recommended that you restart your machine after the installer 
  is done, unless you know exactly which programs need to be restarted.
- If Bazel complains about your Xcode path, please run `bazel clean --expunge` on the corresponding workspace."""
                            )
            commands.append(ReactorCommand(["xcode-select", "--install"]))

        elif data.status == Status.OK:
            ctx.logger.info("Xcode Command Line Tools already installed")

        return commands
Beispiel #9
0
    def test_no_execution_done(self):
        ctx = test_context()
        ctx.flags.plan = True

        executor = ExecPlanExecutor()
        collector = MockCollector("data")
        validator = MockValidator(result=validation_result_with("data"))
        reactor_command = ReactorCommand(cmd=["do", "nothing"])
        reactor = MockReactor(reactor_command)

        ctx.registry.register_collector("id", collector)
        ctx.registry.register_validator("id", validator)
        ctx.registry.register_reactor("id", reactor)

        executor.execute(ctx)

        self.assertFalse(collector.called)
        self.assertFalse(validator.called)
        self.assertFalse(reactor.called)
Beispiel #10
0
def _execute_command(command: ReactorCommand, ctx: Context):
    logger = ctx.logger
    logger.command_info(command)

    try:
        for line in execute_with_streamed_output(command.resolve(ctx)):
            if not command.silent:
                ctx.logger.command_output(line)

        logger.progress("Command '{}' executed successfully".format(command))
    except subprocess.CalledProcessError as err:
        logger.debug(err)
        if not command.silent:
            logger.failure("Command '{}' returned code {}".format(
                command, err.returncode))
    except FileNotFoundError as err:
        logger.debug(err)
        if not command.silent:
            logger.failure("Failed to execute command '{}' - {}".format(
                command, err))
Beispiel #11
0
    def test_basic_execute(self):
        ctx = test_context()
        handler = RecordingHandler()

        executor = Executor()
        collector = MockCollector("data")
        validator = MockValidator(result=validation_result_with("data"))
        reactor_command = ReactorCommand(cmd=["do", "nothing"])
        reactor = MockReactor(reactor_command)

        ctx.registry.register_collector("id", collector)
        ctx.registry.register_validator("id", validator)
        ctx.registry.register_reactor("id", reactor)

        self.assertEqual(ExecutionSummary(total_count=1, problem_count=1),
                         executor.execute(ctx, get_handler=handler.get))

        self.assertTrue(collector.called)
        self.assertTrue(validator.called)
        self.assertTrue(reactor.called)
        self.assertEqual(reactor_command, handler.recorded[0])
Beispiel #12
0
 def _uninstall_bazel_command():
     return ReactorCommand(["brew", "uninstall", "bazelbuild/tap/bazel"])
Beispiel #13
0
 def _upgrade_cmd(self) -> ReactorCommand:
     return ReactorCommand(["brew", "upgrade", self.formula])
    def test_command_with_user_input(self, patched_input):
        command = ReactorCommand(cmd=["cmd", UserInput("x", "test: ")])

        self.assertEqual(
            ["cmd", expected_user_input],
            command.resolve(ctx=test_context(mode=Mode.INTERACTIVE)))
Beispiel #15
0
 def _uninstall_cmd(self) -> ReactorCommand:
     return ReactorCommand(["brew", "uninstall", self.formula])
Beispiel #16
0
def install_pkg_command_for(pkg_file):
    return ReactorCommand(
        ["sudo", "installer", "-pkg", pkg_file, "-target", "/"])
Beispiel #17
0
def mount_command_for(dmg_file):
    return ReactorCommand(["sudo", "hdiutil", "attach", dmg_file])
Beispiel #18
0
 def _install_bazelisk_commands():
     return [
         ReactorCommand(["brew", "tap", "bazelbuild/tap"], silent=True),
         ReactorCommand(["brew", "tap-pin", "bazelbuild/tap"], silent=True),
         ReactorCommand(["brew", "install", "bazelbuild/tap/bazelisk"])
     ]
Beispiel #19
0
 def _upgrade_bazelisk_command() -> ReactorCommand:
     return ReactorCommand(["brew", "upgrade", "bazelbuild/tap/bazelisk"],
                           silent=True)