diff --git a/.github/workflows/integration_test.yaml b/.github/workflows/integration_test.yaml index 47c953d2..4dd4afa5 100644 --- a/.github/workflows/integration_test.yaml +++ b/.github/workflows/integration_test.yaml @@ -11,7 +11,7 @@ jobs: channel: 1.28-strict/stable extra-arguments: | --kube-config ${GITHUB_WORKSPACE}/kube-config - modules: '["test_jenkins.py", "test_k8s_agent.py", "test_machine_agent.py", "test_plugins.py", "test_proxy.py", "test_cos.py"]' + modules: '["test_ingress.py", "test_jenkins.py", "test_k8s_agent.py", "test_machine_agent.py", "test_plugins.py", "test_proxy.py", "test_cos.py"]' pre-run-script: | -c "sudo microk8s config > ${GITHUB_WORKSPACE}/kube-config chmod +x tests/integration/pre_run_script.sh diff --git a/src/ingress.py b/src/ingress.py index a3f855a3..78242c75 100644 --- a/src/ingress.py +++ b/src/ingress.py @@ -20,5 +20,4 @@ def __init__(self, charm: ops.CharmBase): """ super().__init__(charm, "ingress-observer") self.charm = charm - - self.ingress = IngressPerAppRequirer(self.charm, port=jenkins.WEB_PORT) + self.ingress = IngressPerAppRequirer(self.charm, port=jenkins.WEB_PORT, strip_prefix=True) diff --git a/src/jenkins.py b/src/jenkins.py index 5e31ba93..de2cab74 100644 --- a/src/jenkins.py +++ b/src/jenkins.py @@ -31,7 +31,8 @@ WEB_PORT = 8080 WEB_URL = f"http://localhost:{WEB_PORT}" -LOGIN_URL = f"{WEB_URL}/login?from=%2F" +LOGIN_PATH = "/login?from=%2F" +LOGIN_URL = f"{WEB_URL}{LOGIN_PATH}" EXECUTABLES_PATH = Path("/srv/jenkins/") # Path to initial Jenkins password file PASSWORD_FILE_PATH = JENKINS_HOME_PATH / "secrets/initialAdminPassword" diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py index 95236abe..1df7d7a8 100644 --- a/tests/integration/conftest.py +++ b/tests/integration/conftest.py @@ -792,7 +792,10 @@ async def ingress_application_related_fixture(application: Application, external "traefik-k8s", channel="1.0/stable", trust=True, - config={"external_hostname": external_hostname}, + config={ + "external_hostname": external_hostname, + "routing_mode": "subdomain", + }, ) await application.model.wait_for_idle( status="active", apps=[traefik.name], raise_on_error=False, timeout=30 * 60 diff --git a/tests/integration/test_ingress.py b/tests/integration/test_ingress.py index fb819a51..e2a842b5 100644 --- a/tests/integration/test_ingress.py +++ b/tests/integration/test_ingress.py @@ -3,26 +3,32 @@ """Integration tests for jenkins-k8s-operator with ingress.""" + +# pylint: disable=unused-argument + import pytest import requests from juju.application import Application from juju.model import Model +import jenkins + @pytest.mark.abort_on_fail async def test_ingress_integration( - model: Model, ingress_related: Application, external_hostname: str + model: Model, application: Application, ingress_related: Application, external_hostname: str ): """ arrange: deploy the Jenkins charm and establish relations via ingress. act: send a request to the ingress in /. assert: the response succeeds. """ - status = await model.get_status(filters=[ingress_related.name]) - unit = next(iter(status.applications[ingress_related.name].units)) + status = await model.get_status(filters=[application.name]) + unit = next(iter(status.applications[application.name].units)) + address = status["applications"][application.name]["units"][unit]["address"] response = requests.get( - f"http://{unit.address}", - headers={"Host": f"{model.name}-{ingress_related.name}.{external_hostname}"}, + f"http://{address}:{jenkins.WEB_PORT}{jenkins.LOGIN_PATH}", + headers={"Host": f"{model.name}-{application.name}.{external_hostname}"}, timeout=5, - ).json() + ) assert response.status_code == 200