-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add version upgrade test * add version upgrade test * add version upgrade test * add version upgrade test * add version upgrade test * address comments * address comments * address comments * address comments * pin juju to fix CI * address comments * address comments * address comments * test possible CI failure * test CI * enable tmate debug * address comments * test CI * test CI * test CI * test CI * test CI * test CI * test CI * test CI * test CI with libjuju 3.1 * test CI with libjuju 3.1 * try deferring as possible fix for CI * storage mount fix attempt * storage mount fix attempt * fix linting * address comment * address comment * address comment * fix jenkins-agent test fails * fix jenkins-agent test fails * Include temporary for issue 989 in pylibjuju to see if that addresses test failures * Revert to pylibjuju version in main --------- Co-authored-by: Phan Trung Thanh <[email protected]> Co-authored-by: Tom Haddon <[email protected]>
- Loading branch information
1 parent
cc59cac
commit 866d05a
Showing
8 changed files
with
237 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,10 @@ | |
from pytest import FixtureRequest | ||
from pytest_operator.plugin import OpsTest | ||
|
||
import jenkins | ||
import state | ||
|
||
from .constants import ALLOWED_PLUGINS | ||
from .helpers import get_pod_ip | ||
from .helpers import generate_jenkins_client_from_application, get_pod_ip | ||
from .types_ import KeycloakOIDCMetadata, LDAPSettings, ModelAppUnit, UnitWebClient | ||
|
||
KUBECONFIG = os.environ.get("TESTING_KUBECONFIG", "~/.kube/config") | ||
|
@@ -136,17 +135,10 @@ async def jenkins_client_fixture( | |
web_address: str, | ||
) -> jenkinsapi.jenkins.Jenkins: | ||
"""The Jenkins API client.""" | ||
jenkins_unit: Unit = application.units[0] | ||
ret, api_token, stderr = await ops_test.juju( | ||
"ssh", | ||
"--container", | ||
"jenkins", | ||
jenkins_unit.name, | ||
"cat", | ||
str(jenkins.API_TOKEN_PATH), | ||
jenkins_client = await generate_jenkins_client_from_application( | ||
ops_test, application, web_address | ||
) | ||
assert ret == 0, f"Failed to get Jenkins API token, {stderr}" | ||
return jenkinsapi.jenkins.Jenkins(web_address, "admin", api_token, timeout=60) | ||
return jenkins_client | ||
|
||
|
||
@pytest_asyncio.fixture(scope="function", name="jenkins_user_client") | ||
|
@@ -184,6 +176,7 @@ async def jenkins_k8s_agents_fixture( | |
"""The Jenkins k8s agent.""" | ||
agent_app: Application = await model.deploy( | ||
"jenkins-agent-k8s", | ||
base="[email protected]", | ||
config={"jenkins_agent_labels": "k8s"}, | ||
channel="latest/edge", | ||
application_name=f"jenkins-agent-k8s-{app_suffix}", | ||
|
@@ -215,6 +208,7 @@ async def extra_jenkins_k8s_agents_fixture( | |
"""The Jenkins k8s agent.""" | ||
agent_app: Application = await model.deploy( | ||
"jenkins-agent-k8s", | ||
base="[email protected]", | ||
config={"jenkins_agent_labels": "k8s-extra"}, | ||
channel="latest/edge", | ||
application_name="jenkins-agent-k8s-extra", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
# Copyright 2024 Canonical Ltd. | ||
# See LICENSE file for licensing details. | ||
|
||
"""Integration test relation file.""" | ||
|
||
|
||
import logging | ||
|
||
import ops | ||
import pytest | ||
import pytest_asyncio | ||
import requests | ||
from juju.application import Application | ||
from juju.model import Model | ||
from pytest_operator.plugin import OpsTest | ||
|
||
from .helpers import ( | ||
gen_git_test_job_xml, | ||
generate_unit_web_client_from_application, | ||
get_model_jenkins_unit_address, | ||
) | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
JENKINS_APP_NAME = "jenkins-k8s-upgrade" | ||
JOB_NAME = "test_job" | ||
|
||
|
||
@pytest_asyncio.fixture(scope="module") | ||
async def jenkins_upgrade_depl(ops_test: OpsTest, model: Model): | ||
""" | ||
arrange: given a juju model. | ||
act: deploy Jenkins, instantiate the Jenkins client and define a job. | ||
assert: the deployment has no errors. | ||
""" | ||
application: Application = await model.deploy( | ||
"jenkins-k8s", | ||
application_name=JENKINS_APP_NAME, | ||
channel="stable", | ||
) | ||
await model.wait_for_idle(status="active", timeout=10 * 60) | ||
unit_web_client = await generate_unit_web_client_from_application(ops_test, model, application) | ||
unit_web_client.client.create_job(JOB_NAME, gen_git_test_job_xml("k8s")) | ||
|
||
|
||
@pytest.mark.usefixtures("jenkins_upgrade_depl") | ||
async def test_jenkins_upgrade_check_job( | ||
ops_test: OpsTest, jenkins_image: str, model: Model, charm: ops.CharmBase | ||
): | ||
""" | ||
arrange: given charm has been built, deployed and a job has been defined. | ||
act: get Jenkins' version and upgrade the charm. | ||
assert: if Jenkins versions differ, the job persists. | ||
""" | ||
application = model.applications[JENKINS_APP_NAME] | ||
unit_ip = await get_model_jenkins_unit_address(model, JENKINS_APP_NAME) | ||
address = f"http://{unit_ip}:8080" | ||
response = requests.get(address, timeout=60) | ||
old_version = response.headers["X-Jenkins"] | ||
await application.refresh(path=charm, resources={"jenkins-image": jenkins_image}) | ||
await model.wait_for_idle(status="active", timeout=10 * 60) | ||
unit_ip = await get_model_jenkins_unit_address(model, JENKINS_APP_NAME) | ||
address = f"http://{unit_ip}:8080" | ||
response = requests.get(address, timeout=60) | ||
if old_version != response.headers["X-Jenkins"]: | ||
unit_web_client = await generate_unit_web_client_from_application( | ||
ops_test, model, application | ||
) | ||
job = unit_web_client.client.get_job(JOB_NAME) | ||
assert job.name == JOB_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters