In-Memory Provider

A cloud provider in memory, for tests and local development without a cloud account.

Its DNS zones, records and certificates are kept in memory, and behave like a cloud’s, so that tests exercise the service layer, and its signals, without reaching real infrastructure.

from smarter.apps.infrastructure.providers import configure_provider
from smarter.apps.infrastructure.providers.memory import InMemoryProvider

provider = InMemoryProvider()
configure_provider(lambda: provider)
provider.dns.add_zone("example.com")
provider.certificates.issue_all = True
provider.storage.objects  # the private objects that were saved, by key
class smarter.apps.infrastructure.providers.memory.InMemoryCertificateService(provider, dns, **kwargs)[source]

Bases: CertificateService

TLS certificates in memory, issued once their validation records exist, or at once with issue_all.

__init__(provider, dns, **kwargs)[source]
issue_all

Issue every certificate, whether or not its validation records exist.

issue_wait_seconds: float = 0

Seconds between the checks.

property ready: bool

Whether the in-memory provider is ready.

validation_wait_seconds: float = 0

Seconds between the attempts.

A provider generates validation records in seconds.

class smarter.apps.infrastructure.providers.memory.InMemoryDNSService(provider, **kwargs)[source]

Bases: DNSService

DNS zones and records in memory.

__init__(provider, **kwargs)[source]
add_zone(domain, a_record=None)[source]

Add a zone, e.g. the environment’s API domain, optionally with an A record.

Parameters:
  • domain (str) – The zone’s domain, e.g. api.example.com.

  • a_record (list[str] | None) – The A record’s values, IP addresses, or None for no A record.

Return type:

DNSZone

Returns:

The new zone.

property ready: bool

Whether the in-memory provider is ready.

record_wait_seconds: float = 0

Seconds between the attempts.

class smarter.apps.infrastructure.providers.memory.InMemoryProvider(ready=True, **kwargs)[source]

Bases: CloudProvider

A cloud provider in memory.

Parameters:

ready (bool) – Whether the provider is authenticated.

__init__(ready=True, **kwargs)[source]
property account_id: str | None

The fake account id, or None if the provider is not ready.

property certificates: InMemoryCertificateService

The in-memory certificate service.

cluster_health

The cluster’s health, or None for the one that cluster_info describes.

cluster_resources

The cloud resources of the cluster, by resource type, for the inventory.

property dns: InMemoryDNSService

The in-memory DNS service.

get_kubernetes_cluster_health()[source]

Return the cluster’s health that a test set in cluster_health.

Without one, it is built from cluster_info, as the base class builds it.

Return type:

ClusterHealth

Returns:

A copy of the health, so that a caller cannot change the test’s.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

get_kubernetes_cluster_info()[source]

Return a copy of cluster_info.

Return type:

dict[str, Any]

Returns:

The cluster’s description.

Raises:

InfrastructureNotReadyError – If the provider is not ready.

get_kubernetes_cluster_resources()[source]

Return a copy of cluster_resources, which tests set.

Return type:

dict[str, list[DiscoveredResource]]

Returns:

The cluster’s cloud resources, by resource type, or an empty dict if the provider is not ready.

property identity: dict[str, Any] | None

A fake account identity, or None if the provider is not ready.

name: str = 'memory'

The provider’s name, see CloudProviders.

property ready: bool

Whether the provider is ready, as set with the setter.

Records the authentication state, which sends a signal when it changes.

property sdk_version: str

The fixed version memory.

property storage: InMemoryStorageService

The in-memory private object storage.

update_kubeconfig()[source]

Count the call in kubeconfig_updates, rather than write a kubeconfig.

Return type:

bool

Returns:

Whether the provider is ready.

class smarter.apps.infrastructure.providers.memory.InMemoryStorageService(provider, **kwargs)[source]

Bases: StorageService

Private objects in memory, in objects.

Its presigned urls are fake: they name the object and when the url expires, but download nothing.

__init__(provider, **kwargs)[source]
property bucket: str

The fixed bucket memory-exports.

fail

Set to make every operation fail with this error.

objects

The objects, by key.

property ready: bool

Whether the in-memory provider is ready.

class smarter.apps.infrastructure.providers.memory.StoredObject(content, content_type)[source]

Bases: object

An object that InMemoryStorageService saved.

__init__(content, content_type)
content: bytes
content_type: str