Skip to content

Commit

Permalink
Add constants.py file
Browse files Browse the repository at this point in the history
  • Loading branch information
orfeas-k committed Apr 11, 2024
1 parent 63e8d5f commit 0d84841
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 39 deletions.
30 changes: 30 additions & 0 deletions tests/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2024 Canonical Ltd.
# See LICENSE file for licensing details.
"""Constants module including constants used in tests."""
from pathlib import Path

import yaml

KNATIVE_EVENTING_NAMESPACE = "knative-eventing"
KNATIVE_SERVING_NAMESPACE = "knative-serving"
KNATIVE_SERVING_SERVICE = "services.serving.knative.dev"
KNATIVE_OPERATOR_METADATA = yaml.safe_load(
Path("./charms/knative-operator/metadata.yaml").read_text()
)
KNATIVE_OPERATOR_IMAGE = KNATIVE_OPERATOR_METADATA["resources"]["knative-operator-image"][
"upstream-source"
]
KNATIVE_OPERATOR_WEBHOOK_IMAGE = KNATIVE_OPERATOR_METADATA["resources"][
"knative-operator-webhook-image"
]["upstream-source"]
KNATIVE_OPERATOR_RESOURCES = {
"knative-operator-image": KNATIVE_OPERATOR_IMAGE,
"knative-operator-webhook-image": KNATIVE_OPERATOR_WEBHOOK_IMAGE,
}

ISTIO_CHANNEL = "1.17/stable"
ISTIO_PILOT = "istio-pilot"
ISTIO_PILOT_TRUST = True
ISTIO_GATEWAY = "istio-gateway"
ISTIO_GATEWAY_APP_NAME = "istio-ingressgateway"
ISTIO_GATEWAY_TRUST = True
58 changes: 19 additions & 39 deletions tests/test_bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import pytest
import pytest_asyncio
import requests
import yaml
from lightkube import ApiError, Client
from lightkube.generic_resource import create_namespaced_resource
from lightkube.resources.apiextensions_v1 import CustomResourceDefinition
Expand All @@ -18,34 +17,13 @@
from pytest_operator.plugin import OpsTest
from tenacity import Retrying, stop_after_delay, wait_fixed

from tests.integration import constants

log = logging.getLogger(__name__)

KSVC = create_namespaced_resource(
group="serving.knative.dev", version="v1", kind="Service", plural="services"
)
KNATIVE_EVENTING_NAMESPACE = "knative-eventing"
KNATIVE_SERVING_NAMESPACE = "knative-serving"
KNATIVE_SERVING_SERVICE = "services.serving.knative.dev"
KNATIVE_OPERATOR_METADATA = yaml.safe_load(
Path("./charms/knative-operator/metadata.yaml").read_text()
)
KNATIVE_OPERATOR_IMAGE = KNATIVE_OPERATOR_METADATA["resources"]["knative-operator-image"][
"upstream-source"
]
KNATIVE_OPERATOR_WEBHOOK_IMAGE = KNATIVE_OPERATOR_METADATA["resources"][
"knative-operator-webhook-image"
]["upstream-source"]
KNATIVE_OPERATOR_RESOURCES = {
"knative-operator-image": KNATIVE_OPERATOR_IMAGE,
"knative-operator-webhook-image": KNATIVE_OPERATOR_WEBHOOK_IMAGE,
}

ISTIO_CHANNEL = "1.17/stable"
ISTIO_PILOT = "istio-pilot"
ISTIO_PILOT_TRUST = True
ISTIO_GATEWAY = "istio-gateway"
ISTIO_GATEWAY_APP_NAME = "istio-ingressgateway"
ISTIO_GATEWAY_TRUST = True


@pytest.mark.abort_on_fail
Expand All @@ -58,24 +36,24 @@ async def test_build_deploy_knative_charms(ops_test: OpsTest):

# Deploy istio as dependency
await ops_test.model.deploy(
ISTIO_PILOT,
channel=ISTIO_CHANNEL,
constants.ISTIO_PILOT,
channel=constants.ISTIO_CHANNEL,
config={"default-gateway": "knative-gateway"},
trust=ISTIO_PILOT_TRUST,
trust=constants.ISTIO_PILOT_TRUST,
)

await ops_test.model.deploy(
ISTIO_GATEWAY,
application_name=ISTIO_GATEWAY_APP_NAME,
channel=ISTIO_CHANNEL,
constants.ISTIO_GATEWAY,
application_name=constants.ISTIO_GATEWAY_APP_NAME,
channel=constants.ISTIO_CHANNEL,
config={"kind": "ingress"},
trust=ISTIO_GATEWAY_TRUST,
trust=constants.ISTIO_GATEWAY_TRUST,
)

await ops_test.model.add_relation(ISTIO_PILOT, ISTIO_GATEWAY_APP_NAME)
await ops_test.model.add_relation(constants.ISTIO_PILOT, constants.ISTIO_GATEWAY_APP_NAME)

await ops_test.model.wait_for_idle(
[ISTIO_PILOT, ISTIO_GATEWAY_APP_NAME],
[constants.ISTIO_PILOT, constants.ISTIO_GATEWAY_APP_NAME],
raise_on_blocked=False,
status="active",
timeout=90 * 10,
Expand All @@ -86,7 +64,7 @@ async def test_build_deploy_knative_charms(ops_test: OpsTest):
knative_charms["knative-operator"],
application_name="knative-operator",
trust=True,
resources=KNATIVE_OPERATOR_RESOURCES,
resources=constants.KNATIVE_OPERATOR_RESOURCES,
)

await ops_test.model.wait_for_idle(
Expand All @@ -100,7 +78,7 @@ async def test_build_deploy_knative_charms(ops_test: OpsTest):
knative_charms["knative-serving"],
application_name="knative-serving",
config={
"namespace": KNATIVE_SERVING_NAMESPACE,
"namespace": constants.KNATIVE_SERVING_NAMESPACE,
"istio.gateway.namespace": ops_test.model_name,
},
trust=True,
Expand All @@ -109,7 +87,7 @@ async def test_build_deploy_knative_charms(ops_test: OpsTest):
await ops_test.model.deploy(
knative_charms["knative-eventing"],
application_name="knative-eventing",
config={"namespace": KNATIVE_EVENTING_NAMESPACE},
config={"namespace": constants.KNATIVE_EVENTING_NAMESPACE},
trust=True,
)

Expand Down Expand Up @@ -141,7 +119,7 @@ def wait_for_ksvc():
for attempt in RETRY_FOR_THREE_MINUTES:
with attempt:
log.info("Checking for ksvc CRD")
lightkube_client.get(CustomResourceDefinition, KNATIVE_SERVING_SERVICE)
lightkube_client.get(CustomResourceDefinition, constants.KNATIVE_SERVING_SERVICE)


@pytest.fixture()
Expand Down Expand Up @@ -256,7 +234,7 @@ async def test_eventing_custom_image(ops_test: OpsTest, restore_eventing_custom_
# Assert that the activator image is trying to use the custom image.
client = lightkube.Client()
activator_deployment = client.get(
Deployment, "eventing-controller", namespace=KNATIVE_EVENTING_NAMESPACE
Deployment, "eventing-controller", namespace=constants.KNATIVE_EVENTING_NAMESPACE
)
assert activator_deployment.spec.template.spec.containers[0].image == fake_image

Expand Down Expand Up @@ -298,5 +276,7 @@ async def test_serving_custom_image(ops_test: OpsTest, restore_serving_custom_im

# Assert that the activator image is trying to use the custom image.
client = lightkube.Client()
activator_deployment = client.get(Deployment, "activator", namespace=KNATIVE_SERVING_NAMESPACE)
activator_deployment = client.get(
Deployment, "activator", namespace=constants.KNATIVE_SERVING_NAMESPACE
)
assert activator_deployment.spec.template.spec.containers[0].image == fake_image

0 comments on commit 0d84841

Please sign in to comment.