harness-extensions

Harness Extensions

Channel Revision Published Runs on
latest/beta 3 05 Jul 2022
Ubuntu 20.04
juju deploy harness-extensions --channel beta
Show information

Platform:

Ubuntu
20.04

charms.harness_extensions.v0.networking

This is a library providing a utility for adding networking mocking capability to Harness.

Basic usage:

from charms.harness_extensions.v0 import networking networking.activate()

Advanced use cases:

let's pretend 'foo' is a relation:

foo = charm.model.get_relation('foo', 1) with networking(networks={foo: Network(private_address="42.42.42.42")}): # the juju-info network is present by default unless you pass None assert c.model.get_binding("juju-info").network.bind_address == IPv4Address("1.1.1.1") # the custom foo endpoint is mocked: assert c.model.get_binding(foo).network.bind_address == IPv4Address("42.42.42.42") assert c.model.get_binding('foo').network.bind_address == IPv4Address("42.42.42.42")

CAVEAT: The patch is global; that is, if you instantiate two Harnesses (don't do that), you won't be able to mock network-get calls on a per-harness basis.


class NetworkingError

Description

Base class for errors raised from this module. None

def activate(juju_info_network)

Description

Patches harness.backend.network_get and initializes the juju-info binding. None

def deactivate()

Description

Undoes the patch. None

def add_network(
    endpoint_name: str,
    relation_id,
    network: _Network,
    make_default
)

Add a network to the harness.

Description

  • endpoint_name: the relation name this network belongs to
  • relation_id: ID of the relation this network belongs to. If None, this will be the default network for the relation.
  • network: network data.
  • make_default: Make this the default network for the endpoint. Equivalent to calling this again with relation_id==None.

def remove_network(
    endpoint_name: str,
    relation_id
)

Description

Remove a network from the harness. None

def Network(
    private_address: str,
    mac_address: str,
    hostname: str,
    cidr: str,
    interface_name: str,
    egress_subnets,
    ingress_addresses
)

Description

Construct a network object. None

def networking(
    juju_info_network,
    networks,
    make_default: bool
)

Context manager to activate/deactivate networking within a scope.

Arguments

- `juju_info_network`

network assigned to the implicit 'juju-info' endpoint.

- `networks`

mapping from endpoints (names, or relations) to networks.

- `make_default`

whether the networks passed as relations should also be interpreted as default networks for the endpoint.