Skip to content

Commit

Permalink
mount storage for jenkins_home (#56)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: arturo-seijas <[email protected]>
  • Loading branch information
Thanhphan1147 and arturo-seijas committed Nov 16, 2023
1 parent a1f3cb0 commit 1b3eb93
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
10 changes: 10 additions & 0 deletions metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@ tags:
containers:
jenkins:
resource: jenkins-image
mounts:
- storage: jenkins-home
location: /var/lib/jenkins

resources:
jenkins-image:
type: oci-image
description: OCI image for Jenkins

storage:
jenkins-home:
type: filesystem
location: /var/lib/jenkins

requires:
agent-deprecated:
interface: jenkins-slave
Expand Down
44 changes: 43 additions & 1 deletion tests/integration/test_jenkins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
"""Integration tests for jenkins-k8s-operator charm."""

import typing
from secrets import token_hex

import jenkinsapi
import pytest
from juju.action import Action
from juju.application import Application
from juju.unit import Unit
from pytest_operator.plugin import OpsTest

from .helpers import install_plugins
from .helpers import gen_test_job_xml, install_plugins
from .substrings import assert_substrings_not_in_string
from .types_ import UnitWebClient

Expand Down Expand Up @@ -55,3 +59,41 @@ async def test_jenkins_automatic_update_out_of_range(
assert unit_web_client.client.has_plugin(
extra_plugin
), "additionally installed plugin cleanedup."


async def test_storage_mount(
application: Application,
jenkins_client: jenkinsapi.jenkins.Jenkins,
):
"""
arrange: a bare Jenkins charm.
act: Add a job, scale the charm to 0 unit and scale back to 1.
assert: The job configuration persists and is the same as the one used.
"""
test_job_name = token_hex(8)
job_configuration = gen_test_job_xml("built-in")
jenkins_client.create_job(test_job_name, job_configuration)

await application.scale(scale=0)
await application.model.wait_for_idle(
apps=[application.name],
timeout=20 * 60,
idle_period=30,
wait_for_exact_units=0,
)
await application.scale(scale=1)
await application.model.wait_for_idle(
apps=[application.name],
timeout=20 * 60,
idle_period=30,
wait_for_exact_units=1,
)

jenkins_unit: Unit = application.units[0]
assert jenkins_unit
command = f"cat /var/lib/jenkins/jobs/{test_job_name}/config.xml"
action: Action = await jenkins_unit.run(command=command, timeout=60)
await action.wait()
assert action.results.get("return-code") == 0
# Remove leading and trailing newline since jenkins client autoformat config
assert job_configuration.strip("\n") in str(action.results.get("stdout"))

0 comments on commit 1b3eb93

Please sign in to comment.