Skip to content

Commit

Permalink
fix: license headers & lint & test
Browse files Browse the repository at this point in the history
  • Loading branch information
yanksyoon committed Jan 9, 2025
1 parent 455f58a commit 5c7ff6c
Show file tree
Hide file tree
Showing 55 changed files with 103 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Jenkins executable
CVE-2024-47072

Check notice on line 2 in .trivyignore

View workflow job for this annotation

GitHub Actions / integration-tests / Scan Image (ghcr.io-canonical-jenkins-46499b77ce3a525fd8366c7e0fc694a8234c53dd-_1.0_amd64.tar)

CVE-2024-47072 not present anymore, can be safely removed.
# Pebble vulnerabilities
CVE-2024-45338

Check notice on line 4 in .trivyignore

View workflow job for this annotation

GitHub Actions / integration-tests / Scan Image (ghcr.io-canonical-jenkins-46499b77ce3a525fd8366c7e0fc694a8234c53dd-_1.0_amd64.tar)

CVE-2024-45338 not present anymore, can be safely removed.
2 changes: 1 addition & 1 deletion actions.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

get-admin-password:
Expand Down
2 changes: 1 addition & 1 deletion charmcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

type: charm
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

options:
Expand Down
2 changes: 1 addition & 1 deletion generate-src-docs.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

lazydocs --no-watermark --output-path src-docs src/*
2 changes: 1 addition & 1 deletion jenkins_rock/rockcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

name: jenkins
Expand Down
2 changes: 1 addition & 1 deletion lib/charms/traefik_k8s/v2/ingress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

r"""# Interface Library for ingress.
Expand Down
2 changes: 1 addition & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

name: jenkins-k8s
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

[tool.bandit]
Expand Down
2 changes: 1 addition & 1 deletion src/actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Jenkins charm actions."""
Expand Down
2 changes: 1 addition & 1 deletion src/agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""The Jenkins agent relation observer."""
Expand Down
2 changes: 1 addition & 1 deletion src/auth_proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Observer module for Jenkins to auth_proxy integration."""
Expand Down
2 changes: 1 addition & 1 deletion src/charm.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Charm Jenkins."""
Expand Down
2 changes: 1 addition & 1 deletion src/cos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Observer module for Jenkins to COS integration."""
Expand Down
2 changes: 1 addition & 1 deletion src/ingress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Observer module for Jenkins to ingress integration."""
Expand Down
2 changes: 1 addition & 1 deletion src/jenkins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Functions to operate Jenkins."""
Expand Down
2 changes: 1 addition & 1 deletion src/pebble.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Pebble functionality."""
Expand Down
2 changes: 1 addition & 1 deletion src/state.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Jenkins States."""
Expand Down
2 changes: 1 addition & 1 deletion src/timerange.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""The module for checking time ranges."""
Expand Down
2 changes: 1 addition & 1 deletion templates/logging.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

# Use with java logging property
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Tests module."""
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for jenkins-k8s charm tests."""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests module."""
34 changes: 11 additions & 23 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Fixtures for Jenkins-k8s-operator charm integration tests."""
Expand All @@ -19,7 +19,6 @@
import requests
from juju.action import Action
from juju.application import Application
from juju.client._definitions import FullStatus, UnitStatus
from juju.model import Controller, Model
from juju.unit import Unit
from keycloak import KeycloakAdmin, KeycloakOpenIDConnection
Expand All @@ -38,7 +37,7 @@
get_dex_service_url,
update_redirect_uri,
)
from .helpers import generate_jenkins_client_from_application, get_pod_ip
from .helpers import generate_jenkins_client_from_application, get_model_unit_addresses, get_pod_ip
from .types_ import KeycloakOIDCMetadata, LDAPSettings, ModelAppUnit, UnitWebClient

KUBECONFIG = os.environ.get("TESTING_KUBECONFIG", "./kube-config")
Expand Down Expand Up @@ -129,13 +128,9 @@ def model_app_unit_fixture(model: Model, application: Application, unit: Unit):
@pytest_asyncio.fixture(scope="module", name="unit_ip")
async def unit_ip_fixture(model: Model, application: Application):
"""Get Jenkins charm unit IP."""
status: FullStatus = await model.get_status([application.name])
try:
unit_status: UnitStatus = next(iter(status.applications[application.name].units.values()))
assert unit_status.address, "Invalid unit address"
return unit_status.address
except StopIteration as exc:
raise StopIteration("Invalid unit status") from exc
unit_ips = await get_model_unit_addresses(model=model, app_name=application.name)
assert unit_ips, f"Unit IP address not found for {application.name}"
return unit_ips[0]


@pytest.fixture(scope="module", name="web_address")
Expand Down Expand Up @@ -480,15 +475,9 @@ async def jenkins_with_proxy_fixture(
@pytest_asyncio.fixture(scope="module", name="proxy_jenkins_unit_ip")
async def proxy_jenkins_unit_ip_fixture(model: Model, jenkins_with_proxy: Application):
"""Get Jenkins charm w/ proxy enabled unit IP."""
status: FullStatus = await model.get_status([jenkins_with_proxy.name])
try:
unit_status: UnitStatus = next(
iter(status.applications[jenkins_with_proxy.name].units.values())
)
assert unit_status.address, "Invalid unit address"
return unit_status.address
except StopIteration as exc:
raise StopIteration("Invalid unit status") from exc
unit_ips = await get_model_unit_addresses(model=model, app_name=jenkins_with_proxy.name)
assert unit_ips, f"Unit IP address not found for {jenkins_with_proxy.name}"
return unit_ips[0]


@pytest_asyncio.fixture(scope="module", name="proxy_jenkins_web_address")
Expand Down Expand Up @@ -781,10 +770,9 @@ async def traefik_application_fixture(model: Model):
await model.wait_for_idle(
status="active", apps=[traefik.name], timeout=20 * 60, idle_period=30, raise_on_error=False
)
status = await model.get_status(filters=[traefik.name])
unit = next(iter(status.applications[traefik.name].units))
traefik_address = status["applications"][traefik.name]["units"][unit]["address"]
return (traefik, traefik_address)
unit_ips = await get_model_unit_addresses(model=model, app_name=traefik.name)
assert unit_ips, f"Unit IP address not found for {traefik.name}"
return (traefik, unit_ips[0])


@pytest_asyncio.fixture(scope="module", name="oathkeeper_related")
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Constants for Jenkins-k8s-operator charm integration tests."""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/dex.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""DEX deployment and utilities for testing."""
Expand Down
26 changes: 18 additions & 8 deletions tests/integration/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Helpers for Jenkins-k8s-operator charm integration tests."""
Expand All @@ -14,6 +14,7 @@
import requests
import tenacity
from juju.application import Application
from juju.client._definitions import ApplicationStatus, FullStatus, UnitStatus
from juju.model import Model
from juju.unit import Unit
from pytest_operator.plugin import OpsTest
Expand Down Expand Up @@ -70,7 +71,7 @@ async def install_plugins(
)


async def get_model_jenkins_unit_address(model: Model, app_name: str):
async def get_model_unit_addresses(model: Model, app_name: str) -> list[str]:
"""Extract the address of a given unit.
Args:
Expand All @@ -80,10 +81,18 @@ async def get_model_jenkins_unit_address(model: Model, app_name: str):
Returns:
the IP address of the Jenkins unit.
"""
status = await model.get_status()
unit = list(status.applications[app_name].units)[0]
address = status["applications"][app_name]["units"][unit]["address"]
return address
status: FullStatus = await model.get_status()
# mypy cannot infer the type ApplicationStatus but thinks its the base class type "Type".
application_status: ApplicationStatus | None = status.applications[app_name] # type: ignore
assert application_status, f"Application status {app_name} not found in {status}"
# mypy cannot infer the type UnitStatus but thinks its the base class type "Type".
unit_status_map: dict[typing.Any, UnitStatus | None] = application_status.units # type: ignore
units_statuses: list[UnitStatus | None] = list(unit_status_map.values())
return [
str(unit_status.address)
for unit_status in units_statuses
if unit_status and unit_status.address
]


def gen_test_job_xml(node_label: str):
Expand Down Expand Up @@ -314,8 +323,9 @@ async def generate_unit_web_client_from_application(
A Jenkins web client.
"""
assert model
unit_ip = await get_model_jenkins_unit_address(model, jenkins_app.name)
address = f"http://{unit_ip}:8080"
unit_ips = await get_model_unit_addresses(model, jenkins_app.name)
assert unit_ips, f"Unit IP address not found for {jenkins_app.name}"
address = f"http://{unit_ips[0]}:8080"
jenkins_unit = jenkins_app.units[0]
jenkins_client = await generate_jenkins_client_from_application(ops_test, jenkins_app, address)
unit_web_client = UnitWebClient(unit=jenkins_unit, web=address, client=jenkins_client)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/pre_run_script.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

# Pre-run script for integration test operator-workflows action.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/substrings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Helper functions for tests."""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_auth_proxy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for jenkins-k8s-operator with auth_proxy."""
Expand Down
29 changes: 14 additions & 15 deletions tests/integration/test_cos.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for jenkins-k8s-operator with COS."""
Expand All @@ -11,11 +11,10 @@
import requests
from juju.action import Action
from juju.application import Application
from juju.client._definitions import FullStatus
from juju.model import Model
from kubernetes.client import CoreV1Api

from .helpers import wait_for
from .helpers import get_model_unit_addresses, wait_for
from .types_ import UnitWebClient

logger = logging.getLogger(__name__)
Expand All @@ -36,11 +35,10 @@ async def test_prometheus_integration(
assert res.status_code == 200

model: Model = unit_web_client.unit.model
status: FullStatus = await model.get_status(filters=[prometheus_related.name])
for unit in status.applications[prometheus_related.name].units.values():
query_targets = requests.get(
f"http://{unit.address}:9090/api/v1/targets", timeout=10
).json()
unit_ips = await get_model_unit_addresses(model=model, app_name=prometheus_related.name)
assert unit_ips, f"Unit IP address not found for {prometheus_related.name}"
for ip in unit_ips:
query_targets = requests.get(f"http://{ip}:9090/api/v1/targets", timeout=10).json()
assert len(query_targets["data"]["activeTargets"])


Expand Down Expand Up @@ -85,12 +83,13 @@ async def test_loki_integration(
loki to scrape.
"""
model: Model = unit_web_client.unit.model
status: FullStatus = await model.get_status(filters=[loki_related.name])
for unit in status.applications[loki_related.name].units.values():
unit_ips = await get_model_unit_addresses(model=model, app_name=loki_related.name)
assert unit_ips, f"Unit IP address not found for {loki_related.name}"
for ip in unit_ips:
await wait_for(
functools.partial(
log_files_exist,
unit.address,
ip,
application.name,
("/var/lib/jenkins/logs/jenkins.log",),
),
Expand Down Expand Up @@ -151,20 +150,20 @@ async def test_grafana_integration(
assert: grafana Jenkins dashboard can be found
"""
model: Model = application.model
status: FullStatus = await model.get_status(filters=[grafana_related.name])
action: Action = await grafana_related.units[0].run_action("get-admin-password")
await action.wait()
password = action.results["admin-password"]
for unit in status.applications[grafana_related.name].units.values():
unit_ips = await get_model_unit_addresses(model=model, app_name=grafana_related.name)
for ip in unit_ips:
sess = requests.session()
sess.post(
f"http://{unit.address}:3000/login",
f"http://{ip}:3000/login",
json={
"user": "admin",
"password": password,
},
).raise_for_status()
await wait_for(
functools.partial(dashboard_exist, loggedin_session=sess, unit_address=unit.address),
functools.partial(dashboard_exist, loggedin_session=sess, unit_address=ip),
timeout=60 * 20,
)
2 changes: 1 addition & 1 deletion tests/integration/test_external_agent.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for jenkins-k8s-operator with ingress."""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_ingress.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for jenkins-k8s-operator with ingress."""
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_jenkins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2024 Canonical Ltd.
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""Integration tests for jenkins-k8s-operator charm."""
Expand Down
Loading

0 comments on commit 5c7ff6c

Please sign in to comment.