PlanningAnalyticsEnvironment
from skipcheck_tm1_testcontainers import PlanningAnalyticsEnvironmentA whole Planning Analytics environment for tests, wired together on one Docker network: any number of named TM1 servers, and optionally an Admin Server, TM1 Web, PAW, and Cognos (CAM) security with LDAP and OIDC test users. Two servers and TM1 Web, with a client for each server:
# Two servers on one Admin Server, and TM1 Web listing both
builder = PlanningAnalyticsEnvironment.builder().tm1("planning", lambda tm1: tm1.with_seed(Tm1Seed.SDATA)).tm1("reporting").tm1_web()
# Entering the block starts everything: TM1 Web is at env.tm1_web().url
with builder.build() as env:
cubes = {}
for name, server in env.tm1_servers().items():
with Tm1Client.builder().base_url(server.rest_url).basic_auth(server.username, server.password).build() as tm1:
cubes[name] = [cube.name for cube in tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME))]
return cubes # planning: SData's cubes; reporting: none
Every part is optional, but TM1 Web, PAW and Cognos need at least one TM1 server. Each
part is the module's ordinary container class (Tm1ServerContainer,
Tm1AdminServerContainer, Tm1WebContainer, PawContainer,
CognosContainer, KeycloakContainer), and each builder method takes a
customizer that receives it, so every setting of those classes is available. The TM1,
Admin Server, TM1 Web, PAW and Keycloak customizers run after the environment's own
wiring, so they can also change it. The Cognos customizer runs first, because the TM1
servers are wired from its test users.
The wiring:
- TM1 servers are named (
TM1_SERVER_NAME) and reachable by that name on the network. - With more than one TM1 server, or with
Builder.admin_server, they register with oneTm1AdminServerContainer, and TM1 Web and PAW list every server from it. With one server, its own Admin Server is used. - With Cognos, every TM1 server runs in CAM security against it
(
Builder.cam_security); withBuilder.keycloak, Cognos also has an OIDC namespace. PAW then logs users on through Cognos too, in the same namespace. startstarts everything in dependency order, independent parts in parallel.closestops it all.
Where IBM's software comes from is found from the environment, as for each container
(Tm1Source.discover and the like), unless set on the builder.
With Cognos, each test user logs in to every server as themselves:
# Every server in CAM security, with Cognos's test users as its users
builder = (
PlanningAnalyticsEnvironment.builder()
.tm1("planning")
.cognos(lambda cognos: cognos.with_user("admin", "adminpw", "Admins").with_user("viewer", "viewerpw", "Readers"))
)
with builder.build() as env:
viewer = auth.cam_namespace("viewer", "viewerpw", CognosContainer.NAMESPACE)
with Tm1Client.builder().base_url(env.tm1("planning").rest_url).authenticator(viewer).build() as tm1:
# The cubes the viewer's groups may see
return [cube.name for cube in tm1.cubes.model_cubes(ODataQuery.none().select(Cube.NAME))]
Cognos takes minutes to start, and PAW longer. With Builder.reuse, the
environment keeps its containers running between test runs, so the next run starts in
seconds:
# Cognos and the server keep running after the run, for the next one, when
# testcontainers.reuse.enable=true is set too
builder = PlanningAnalyticsEnvironment.builder().tm1("planning").cognos(lambda cognos: cognos.with_user("admin", "adminpw", "Admins")).reuse(True)
# Entering the block starts it, in seconds once a run with this configuration has started it
with builder.build() as env:
return env.tm1("planning").rest_url
# Leaving the block left it running
Reuse also needs your own switch, as for any Testcontainers container:
testcontainers.reuse.enable=true in ~/.testcontainers.properties, or
TESTCONTAINERS_REUSE_ENABLE=true. Without it, reuse has no effect. With
both:
- The containers and the network are named after the environment's configuration (its
identity, a hash): the label
io.skipcheck.tm1.environmenton each container, and the networktm1-environment-<identity>. A run with the same configuration finds them; a different configuration gets its own, and never another's. stopleaves them running, PAW too. Testcontainers doesn't remove reusable containers at the end of a run either.- What tests leave behind stays: objects they created in TM1, sessions, content saved
in Cognos. Tests should create uniquely named objects and delete them, as with
Tm1ServerContainer.shared. - A configuration you no longer use keeps its containers running, and Cognos holds
about 8 GB. To start clean, remove them all:
docker rm -f $(docker ps -aq --filter label=io.skipcheck.tm1.environment), thendocker network rm $(docker network ls -q --filter label=io.skipcheck.tm1.environment). - The identity covers each part's image, source, environment variables, command, network aliases, labels, exposed ports and copied files, the Cognos users and the CAM settings. A change to anything else about a container, such as how it's created, isn't seen: remove the containers after making one.
- PAW isn't a Testcontainers container: IBM's compose files give it fixed names, so there's one per Docker host whatever the identity. Each start runs IBM's compose again, which takes about a minute.
Members
__init__ constructor | |
builder static | Starts building an environment. |
from_config static | Starts building the environment a pa-environment.yaml describes, the file pa-setup reads (docker/pa-setup), so tests run what developers run. |
start | Starts every part, each after what it depends on; PAW last. |
stop | Stops every part, the dependents first, and removes the network if it made it. |
close | The same as stop. |
tm1 | A TM1 server by the name it was added with. |
tm1_servers | The TM1 servers, by name, in the order they were added. |
admin_server | The shared Admin Server, present with more than one TM1 server or when asked for; None otherwise. |
tm1_web | TM1 Web. |
paw | PAW. |
cognos | Cognos, with the test users. |
keycloak | Keycloak, the OIDC provider. |
network | The Docker network every part is on. |
containers | Every part, in start order. |
__init__
constructor__init__(b: PlanningAnalyticsEnvironment.Builder, reuse_enabled: bool) -> Nonebuilder
staticbuilder() -> PlanningAnalyticsEnvironment.BuilderStarts building an environment.
from_config
staticfrom_config(path: Path | str) -> PlanningAnalyticsEnvironment.BuilderStarts building the environment a pa-environment.yaml describes, the file pa-setup reads (docker/pa-setup), so tests run what developers run. The file is checked as pa-setup checks it, with its defaults. The builder comes back configured; change it further, or call Builder.build.
How each setting maps:
* tm1.servers.<name>: Builder.tm1, with seed as Tm1ServerContainer.with_seed and each cfg parameter as TM1_CFG_<name>, written as pa-setup writes it (true is True); * tm1.adminServer: Builder.admin_server; with more than one server there's one anyway, and false then fails, as in pa-setup; * tm1Web: Builder.tm1_web, with heap as TM1_WEB_HEAP (1g); * cognos: Builder.cognos, with users as CognosContainer.with_user and memory as COGNOS_MAX_MEMORY (6144); oidc adds Builder.keycloak; cam is Builder.cam_security, by default LDAP with the first user as administrator; * paw: Builder.paw with PawContainer.accept_license, which the file must say (acceptLicense: true); the zip is zip in ibm, or the newest there; * ibm: each part's source, the folder as Tm1Source.Bundle, Tm1WebSource.Bundle and CognosSource.Zip. A relative path is from the file's folder; ~ is the user's home; * images: the image each part runs, as a container's image argument. A part with no other source takes its image as the private image with IBM's software built in (Tm1Source.PrivateImage and the like).
A part's source is the one set on the builder, else ibm, else what discover() finds (the variables pa-setup's .env sets, such as TM1_BUNDLE_URL), else its image as a private image.
Ignored, because they place things on the host that Testcontainers manages itself: name (the compose project; the environment has its own network), every port, adminPort and keycloakPort (Testcontainers maps random host ports), and files (the host folder pa-setup keeps databases in; each test environment starts from a new database, or one copied in with Tm1ServerContainer.with_data). They're still checked as pa-setup checks them.
Refused, because the environment can't run them yet: cognos without tm1.servers, and seed: 24retail.
A ValueError if the file can't be read, isn't valid, or asks for what the environment can't run; the message starts with the file's name and names the setting.
# The environment pa-setup runs from the same file, with random host ports
with PlanningAnalyticsEnvironment.from_config(Path("pa-environment.yaml")).build() as env:
return env.tm1("planning").rest_urlstart
start() -> NoneStarts every part, each after what it depends on; PAW last.
stop
stop() -> NoneStops every part, the dependents first, and removes the network if it made it. A reused <Builder.reuse> environment is left running for the next run.
close
close() -> NoneThe same as stop.
tm1
tm1(name: str) -> Tm1ServerContainerA TM1 server by the name it was added with. A ValueError if there's no such server.
tm1_servers
tm1_servers() -> dict[str, Tm1ServerContainer]The TM1 servers, by name, in the order they were added.
admin_server
admin_server() -> Tm1AdminServerContainer | NoneThe shared Admin Server, present with more than one TM1 server or when asked for; None otherwise.
tm1_web
tm1_web() -> Tm1WebContainerTM1 Web. A RuntimeError if it wasn't added.
paw
paw() -> PawContainerPAW. A RuntimeError if it wasn't added.
cognos
cognos() -> CognosContainerCognos, with the test users. A RuntimeError if it wasn't added.
keycloak
keycloak() -> KeycloakContainerKeycloak, the OIDC provider. A RuntimeError if it wasn't added.
network
network() -> AnyThe Docker network every part is on.
containers
containers() -> list[Part]Every part, in start order.