Skip to content

Commit

Permalink
Merge pull request #3 from kian99/ales-charm-backport
Browse files Browse the repository at this point in the history
Minor tweaks
  • Loading branch information
alesstimec authored Jul 3, 2023
2 parents e18c986 + c578e0d commit 5b91384
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 209 deletions.
6 changes: 0 additions & 6 deletions charms/jimm-k8s/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ options:
type: string
default: https://jaas.ai/models
description: URL of the Juju Dashboard for this controller.
public-key:
type: string
description: The public part of JIMM's macaroon bakery keypair.
private-key:
type: string
description: The private part of JIMM's macaroon bakery keypair.
dns-name:
type: string
description: DNS hostname that JIMM is being served from.
3 changes: 0 additions & 3 deletions charms/jimm-k8s/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ def _update_workload(self, event):
"JIMM_UUID": self.config.get("uuid", ""),
"JIMM_DASHBOARD_LOCATION": self.config.get("juju-dashboard-location", "https://jaas.ai/models"),
"JIMM_LISTEN_ADDR": ":8080",
"PRIVATE_KEY": self.config.get("private-key", ""),
"PUBLIC_KEY": self.config.get("public-key", ""),
}
if self._state.dsn:
config_values["JIMM_DSN"] = self._state.dsn
Expand All @@ -247,7 +245,6 @@ def _update_workload(self, event):

if self.model.unit.is_leader():
config_values["JIMM_WATCH_CONTROLLERS"] = "1"
config_values["JIMM_ENABLE_JWKS_ROTATOR"] = "1"

if container.exists(self._dashboard_path):
config_values["JIMM_DASHBOARD_LOCATION"] = self._dashboard_path
Expand Down
3 changes: 0 additions & 3 deletions charms/jimm-k8s/tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ async def test_build_and_deploy(ops_test: OpsTest, local_charm):
config={
"uuid": "f4dec11e-e2b6-40bb-871a-cc38e958af49",
"candid-url": "https://api.jujucharms.com/identity",
"public-key": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
"private-key": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
"dns-name": "jimm.test.canonical.com",
},
)
await ops_test.model.deploy(
Expand Down
228 changes: 111 additions & 117 deletions charms/jimm-k8s/tests/integration/test_upgrade.py
Original file line number Diff line number Diff line change
@@ -1,117 +1,111 @@
# NOTE (alesstimec) This test is commented out until we have
# released juju-jimm-k8s to v1/edge
# #!/usr/bin/env python3
# # Copyright 2022 Canonical Ltd
# # See LICENSE file for licensing details.

# import asyncio
# import logging
# import time
# from pathlib import Path

# import pytest
# import utils
# import yaml
# from juju.action import Action
# from pytest_operator.plugin import OpsTest

# logger = logging.getLogger(__name__)

# METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
# APP_NAME = "juju-jimm-k8s"


# @pytest.mark.abort_on_fail
# async def test_upgrade_running_application(ops_test: OpsTest, local_charm):
# """Deploy latest published charm and upgrade it with charm-under-test.

# Assert on the application status and health check endpoint after upgrade/refresh took place.
# """

# # Deploy the charm and wait for active/idle status
# logger.debug("deploying charms")
# await ops_test.model.deploy(
# METADATA["name"],
# channel="edge",
# application_name=APP_NAME,
# series="focal",
# config={
# "uuid": "f4dec11e-e2b6-40bb-871a-cc38e958af49",
# "candid-url": "https://api.jujucharms.com/identity",
# "public-key": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
# "private-key": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
# },
# )
# await ops_test.model.deploy(
# "traefik-k8s",
# application_name="traefik",
# config={
# "external_hostname": "traefik.test.canonical.com",
# },
# )
# await asyncio.gather(
# ops_test.model.deploy("postgresql-k8s", application_name="postgresql", channel="14/stable", trust=True),
# )

# logger.info("waiting for postgresql and traefik")
# await ops_test.model.wait_for_idle(
# apps=["postgresql", "traefik"],
# status="active",
# raise_on_blocked=True,
# timeout=40000,
# )

# logger.info("adding traefik relation")
# await ops_test.model.relate("{}:ingress".format(APP_NAME), "traefik")

# logger.info("adding postgresql relation")
# await ops_test.model.relate(APP_NAME, "postgresql:database")

# logger.info("waiting for jimm")
# await ops_test.model.wait_for_idle(
# apps=[APP_NAME],
# status="active",
# # raise_on_blocked=True,
# timeout=40000,
# )

# assert ops_test.model.applications[APP_NAME].status == "active"

# # Starting upgrade/refresh
# logger.info("starting upgrade test")

# # Build and deploy charm from local source folder
# logger.info("building local charm")

# # (Optionally build) and deploy charm from local source folder
# if local_charm:
# charm = Path(utils.get_local_charm()).resolve()
# else:
# charm = await ops_test.build_charm(".")
# resources = {"jimm-image": "localhost:32000/jimm:latest"}

# # Deploy the charm and wait for active/idle status
# logger.info("refreshing running application with the new local charm")

# await ops_test.model.applications[APP_NAME].refresh(
# path=charm,
# resources=resources,
# )

# logger.info("waiting for the upgraded unit to be ready")
# async with ops_test.fast_forward():
# await ops_test.model.wait_for_idle(
# apps=[APP_NAME],
# status="active",
# timeout=60,
# )

# assert ops_test.model.applications[APP_NAME].status == "active"

# logger.info("checking status of the running unit")
# upgraded_jimm_unit = await utils.get_unit_by_name(APP_NAME, "0", ops_test.model.units)

# health = await upgraded_jimm_unit.run("curl -i http://localhost:8080/debug/status")
# await health.wait()
# assert health.results.get("return-code") == 0
# assert health.results.get("stdout").strip().splitlines()[0].endswith("200 OK")
#!/usr/bin/env python3
# Copyright 2022 Canonical Ltd
# See LICENSE file for licensing details.

import asyncio
import logging
from pathlib import Path

import pytest
import utils
import yaml
from pytest_operator.plugin import OpsTest

logger = logging.getLogger(__name__)

METADATA = yaml.safe_load(Path("./metadata.yaml").read_text())
APP_NAME = "juju-jimm-k8s"


@pytest.mark.abort_on_fail
async def test_upgrade_running_application(ops_test: OpsTest, local_charm):
"""Deploy latest published charm and upgrade it with charm-under-test.
Assert on the application status and health check endpoint after upgrade/refresh took place.
"""

# Deploy the charm and wait for active/idle status
logger.debug("deploying charms")
await ops_test.model.deploy(
METADATA["name"],
channel="edge",
application_name=APP_NAME,
series="focal",
config={
"uuid": "f4dec11e-e2b6-40bb-871a-cc38e958af49",
"candid-url": "https://api.jujucharms.com/identity",
},
)
await ops_test.model.deploy(
"traefik-k8s",
application_name="traefik",
config={
"external_hostname": "traefik.test.canonical.com",
},
)
await asyncio.gather(
ops_test.model.deploy("postgresql-k8s", application_name="postgresql", channel="14/stable", trust=True),
)

logger.info("waiting for postgresql and traefik")
await ops_test.model.wait_for_idle(
apps=["postgresql", "traefik"],
status="active",
raise_on_blocked=True,
timeout=40000,
)

logger.info("adding traefik relation")
await ops_test.model.relate("{}:ingress".format(APP_NAME), "traefik")

logger.info("adding postgresql relation")
await ops_test.model.relate(APP_NAME, "postgresql:database")

logger.info("waiting for jimm")
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
# raise_on_blocked=True,
timeout=40000,
)

assert ops_test.model.applications[APP_NAME].status == "active"

# Starting upgrade/refresh
logger.info("starting upgrade test")

# Build and deploy charm from local source folder
logger.info("building local charm")

# (Optionally build) and deploy charm from local source folder
if local_charm:
charm = Path(utils.get_local_charm()).resolve()
else:
charm = await ops_test.build_charm(".")
resources = {"jimm-image": "localhost:32000/jimm:latest"}

# Deploy the charm and wait for active/idle status
logger.info("refreshing running application with the new local charm")

await ops_test.model.applications[APP_NAME].refresh(
path=charm,
resources=resources,
)

logger.info("waiting for the upgraded unit to be ready")
async with ops_test.fast_forward():
await ops_test.model.wait_for_idle(
apps=[APP_NAME],
status="active",
timeout=60,
)

assert ops_test.model.applications[APP_NAME].status == "active"

logger.info("checking status of the running unit")
upgraded_jimm_unit = await utils.get_unit_by_name(APP_NAME, "0", ops_test.model.units)

health = await upgraded_jimm_unit.run("curl -i http://localhost:8080/debug/status")
await health.wait()
assert health.results.get("return-code") == 0
assert health.results.get("stdout").strip().splitlines()[0].endswith("200 OK")
16 changes: 0 additions & 16 deletions charms/jimm-k8s/tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
MINIMAL_CONFIG = {
"uuid": "1234567890",
"candid-url": "test-candid-url",
"public-key": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
"private-key": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
}


Expand Down Expand Up @@ -73,13 +71,10 @@ def test_on_pebble_ready(self):
"CANDID_URL": "test-candid-url",
"JIMM_DASHBOARD_LOCATION": "https://jaas.ai/models",
"JIMM_DNS_NAME": "juju-jimm-k8s-0.juju-jimm-k8s-endpoints.None.svc.cluster.local",
"JIMM_ENABLE_JWKS_ROTATOR": "1",
"JIMM_LISTEN_ADDR": ":8080",
"JIMM_LOG_LEVEL": "info",
"JIMM_UUID": "1234567890",
"JIMM_WATCH_CONTROLLERS": "1",
"PRIVATE_KEY": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
"PUBLIC_KEY": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
},
}
}
Expand Down Expand Up @@ -111,13 +106,10 @@ def test_on_config_changed(self):
"CANDID_URL": "test-candid-url",
"JIMM_DASHBOARD_LOCATION": "https://jaas.ai/models",
"JIMM_DNS_NAME": "juju-jimm-k8s-0.juju-jimm-k8s-endpoints.None.svc.cluster.local",
"JIMM_ENABLE_JWKS_ROTATOR": "1",
"JIMM_LISTEN_ADDR": ":8080",
"JIMM_LOG_LEVEL": "info",
"JIMM_UUID": "1234567890",
"JIMM_WATCH_CONTROLLERS": "1",
"PRIVATE_KEY": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
"PUBLIC_KEY": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
},
}
}
Expand All @@ -135,8 +127,6 @@ def test_bakery_configuration(self):
"candid-agent-username": "test-username",
"candid-agent-public-key": "test-public-key",
"candid-agent-private-key": "test-private-key",
"public-key": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
"private-key": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
}
)

Expand All @@ -159,13 +149,10 @@ def test_bakery_configuration(self):
"CANDID_URL": "test-candid-url",
"JIMM_DASHBOARD_LOCATION": "https://jaas.ai/models",
"JIMM_DNS_NAME": "juju-jimm-k8s-0.juju-jimm-k8s-endpoints.None.svc.cluster.local",
"JIMM_ENABLE_JWKS_ROTATOR": "1",
"JIMM_LISTEN_ADDR": ":8080",
"JIMM_LOG_LEVEL": "info",
"JIMM_UUID": "1234567890",
"JIMM_WATCH_CONTROLLERS": "1",
"PRIVATE_KEY": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
"PUBLIC_KEY": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
},
}
}
Expand Down Expand Up @@ -210,12 +197,9 @@ def test_install_dashboard(self, exec):
"JIMM_LISTEN_ADDR": ":8080",
"JIMM_DASHBOARD_LOCATION": "/root/dashboard",
"JIMM_DNS_NAME": "juju-jimm-k8s-0.juju-jimm-k8s-endpoints.None.svc.cluster.local",
"JIMM_ENABLE_JWKS_ROTATOR": "1",
"JIMM_LOG_LEVEL": "info",
"JIMM_UUID": "1234567890",
"JIMM_WATCH_CONTROLLERS": "1",
"PRIVATE_KEY": "ly/dzsI9Nt/4JxUILQeAX79qZ4mygDiuYGqc2ZEiDEc=",
"PUBLIC_KEY": "izcYsQy3TePp6bLjqOo3IRPFvkQd2IKtyODGqC6SdFk=",
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion charms/jimm-k8s/tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ commands =
[testenv:integration]
description = Run integration tests
deps =
juju~=3.2
juju~=2.9
pytest
pytest-operator
-r{toxinidir}/requirements.txt
Expand Down
6 changes: 0 additions & 6 deletions charms/jimm/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,3 @@ options:
type: string
default: https://jaas.ai/models
description: URL of the Juju Dashboard for this controller.
public-key:
type: string
description: The public part of JIMM's macaroon bakery keypair.
private-key:
type: string
description: The private part of JIMM's macaroon bakery keypair.
2 changes: 1 addition & 1 deletion charms/jimm/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-r requirements.txt
coverage
flake8
flake8
4 changes: 0 additions & 4 deletions charms/jimm/src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,12 @@ def _on_config_changed(self, _):
"log_level": self.config.get("log-level"),
"uuid": self.config.get("uuid"),
"dashboard_location": self.config.get("juju-dashboard-location"),
"public_key": self.config.get("public-key"),
"private_key": self.config.get("private-key"),
}
if os.path.exists(self._dashboard_path):
args["dashboard_location"] = self._dashboard_path

with open(self._env_filename(), "wt") as f:
f.write(self._render_template("jimm.env", **args))

if self._ready():
self.restart()
self._on_update_status(None)
Expand All @@ -156,7 +153,6 @@ def _on_leader_elected(self, _):
args = {"jimm_watch_controllers": ""}
if self.model.unit.is_leader():
args["jimm_watch_controllers"] = "1"
args["jimm_enable_jwks_rotator"] = "1"
with open(self._env_filename("leader"), "wt") as f:
f.write(self._render_template("jimm-leader.env", **args))
if self._ready():
Expand Down
1 change: 0 additions & 1 deletion charms/jimm/templates/jimm-leader.env
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
JIMM_WATCH_CONTROLLERS={{jimm_watch_controllers}}
JIMM_ENABLE_JWKS_ROTATOR={{jimm_enable_jwks_rotator}}
Loading

0 comments on commit 5b91384

Please sign in to comment.