Skip to content

Machine does not come online #997

@yanksyoon

Description

@yanksyoon

Description

When adding a machine and using machine.ssh commands, the ssh address is None (i.e. ubuntu@None). A bit of investigation shows that the machine address is None, even if the juju status reports the machine as started.

Urgency

Annoying bug in our test suite

Python-libjuju version

3.3

Juju version

3.1.6

Reproduce / Test

import inspect
import time
import typing

import pytest_asyncio
from juju.machine import Machine
from juju.model import Model


async def wait_for(
    func: typing.Callable[[], typing.Union[typing.Awaitable, typing.Any]],
    timeout: int = 300,
    check_interval: int = 10,
) -> typing.Any:
    """Wait for function execution to become truthy.

    Args:
        func: A callback function to wait to return a truthy value.
        timeout: Time in seconds to wait for function result to become truthy.
        check_interval: Time in seconds to wait between ready checks.

    Raises:
        TimeoutError: if the callback function did not return a truthy value within timeout.

    Returns:
        The result of the function if any.
    """
    deadline = time.time() + timeout
    is_awaitable = inspect.iscoroutinefunction(func)
    while time.time() < deadline:
        if is_awaitable:
            if result := await func():
                return result
        else:
            if result := func():
                return result
        time.sleep(check_interval)

    # final check before raising TimeoutError.
    if is_awaitable:
        if result := await func():
            return result
    else:
        if result := func():
            return result
    raise TimeoutError()


@pytest_asyncio.fixture(scope="module", name="ssh_machine")
async def ssh_machine_fixture(model: Model):
    """A machine to test tmate ssh connection"""
    machine: Machine = await model.add_machine()

    def wait_machine_ip():
        wait_machine: Machine = model.machines[machine.entity_id]
        print(wait_machine.dns_name, wait_machine.agent_status)
        return wait_machine.dns_name and wait_machine.agent_status == "started"

    await wait_for(wait_machine_ip, timeout=60 * 10)
    print(machine.data)

    await machine.ssh("sudo apt update -y")
    await machine.ssh("sudo apt install -y tmate")

async def test_machine(ssh_machine: Machine):
    ssh_machine.ssh("echo hello")

Metadata

Metadata

Assignees

No one assigned

    Labels

    hint/3.xgoing on main branchkind/bugindicates a bug in the projectstate/incompleteneed more information

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions