Exemplo n.º 1
0
def _install_uat_in_container(
    container_name: str,
    deb_paths: "Optional[List[str]]" = [],
    cloud_api: "Optional[pycloudlib.cloud.BaseCloud]" = None,
) -> None:
    """Install ubuntu-advantage-tools into the specified container

    :param container_name:
        The name of the container into which ubuntu-advantage-tools should be
        installed.
    :param deb_paths: Optional paths to local deb files we need to install
    :param cloud_api: Optional pycloud BaseCloud api for applicable
        machine_types.
    """
    cmds = []
    if not deb_paths:
        deb_names = (" ".join(UA_DEBS)
                     if cloud_api else "ubuntu-advantage-tools")
        cmds.extend([
            [
                "sudo",
                "add-apt-repository",
                "--yes",
                "ppa:canonical-server/ua-client-daily",
            ],
            ["sudo", "apt-get", "update", "-qq"],
            ["sudo", "apt-get", "install", "-qq", "-y", deb_names],
        ])
    else:
        for deb_file in deb_paths:
            deb_name = os.path.basename(deb_file)
            cmds.append(["sudo", "dpkg", "-i", "/tmp/" + deb_name])
            cmds.append(["apt-cache", "policy", deb_name.rstrip(".deb")])
            if cloud_api:
                inst = cloud_api.get_instance(container_name)
                inst.push_file(deb_file, "/tmp/" + deb_name)
            else:
                cmd = [
                    "lxc",
                    "file",
                    "push",
                    deb_file,
                    container_name + "/tmp/",
                ]
                subprocess.check_call(cmd)
    if cloud_api:
        instance = cloud_api.get_instance(container_name)
        for cmd in cmds:
            instance.execute(cmd)
    else:
        for cmd in cmds:
            lxc_exec(container_name, cmd)
Exemplo n.º 2
0
def when_i_run_command(context, command, user_spec):
    prefix = get_command_prefix_for_user_spec(user_spec)
    process = lxc_exec(
        context.container_name,
        prefix + shlex.split(command),
        capture_output=True,
        text=True,
    )
    context.process = process
Exemplo n.º 3
0
def _install_uat_in_container(container_name: str,
                              deb_file: "Optional[str]") -> None:
    """Install ubuntu-advantage-tools into the specified container

    :param container_name:
        The name of the container into which ubuntu-advantage-tools should be
        installed.
    :param deb_file: Optional path to the deb_file we need to install
    """
    if deb_file:
        subprocess.run(
            ["lxc", "file", "push", deb_file, container_name + "/tmp/"])
        lxc_exec(container_name, ["sudo", "dpkg", "-i", deb_file])
        lxc_exec(container_name,
                 ["apt-cache", "policy", "ubuntu-advantage-tools"])
    else:
        lxc_exec(
            container_name,
            [
                "sudo",
                "add-apt-repository",
                "--yes",
                "ppa:canonical-server/ua-client-daily",
            ],
        )
        lxc_exec(container_name, ["sudo", "apt-get", "update", "-qq"])
        lxc_exec(
            container_name,
            [
                "sudo",
                "apt-get",
                "install",
                "-qq",
                "-y",
                "ubuntu-advantage-tools",
            ],
        )
Exemplo n.º 4
0
def when_i_run_command(context, command, user_spec):
    prefix = []
    if user_spec == "with sudo":
        prefix = ["sudo"]
    elif user_spec != "as non-root":
        raise Exception(
            "The two acceptable values for user_spec are: 'with sudo',"
            " 'as non-root'")
    process = lxc_exec(
        context.container_name,
        prefix + shlex.split(command),
        capture_output=True,
        text=True,
    )
    context.process = process
Exemplo n.º 5
0
def when_i_run_command(context, command, user_spec):
    prefix = get_command_prefix_for_user_spec(user_spec)
    full_cmd = prefix + shlex.split(command)
    if context.config.cloud_manager:
        result = context.instance.execute(full_cmd)
        process = subprocess.CompletedProcess(
            args=full_cmd,
            stdout=result.stdout,
            stderr=result.stderr,
            returncode=result.return_code,
        )
    else:
        process = lxc_exec(
            context.container_name, full_cmd, capture_output=True, text=True
        )
    context.process = process
Exemplo n.º 6
0
def _install_uat_in_container(container_name: str) -> None:
    """Install ubuntu-advantage-tools into the specified container

    :param container_name:
        The name of the container into which ubuntu-advantage-tools should be
        installed.
    """
    lxc_exec(
        container_name,
        [
            "sudo",
            "add-apt-repository",
            "--yes",
            "ppa:canonical-server/ua-client-daily",
        ],
    )
    lxc_exec(container_name, ["sudo", "apt-get", "update", "-qq"])
    lxc_exec(
        container_name,
        ["sudo", "apt-get", "install", "-qq", "-y", "ubuntu-advantage-tools"],
    )