Skip to content

Commit

Permalink
ROCK definitions for v2.6.3 and v2.9.3. (#18)
Browse files Browse the repository at this point in the history
---------

Signed-off-by: Nashwan Azhari <[email protected]>
  • Loading branch information
aznashwan authored Jul 24, 2024
1 parent 932d90b commit 751ce5a
Show file tree
Hide file tree
Showing 60 changed files with 6,139 additions and 91 deletions.
15 changes: 0 additions & 15 deletions tests/integration/test_harbor.py

This file was deleted.

105 changes: 105 additions & 0 deletions tests/integration/test_harbor_rocks_in_helm_chart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# Copyright 2024 Canonical, Ltd.
# See LICENSE file for licensing details
#

import json
import logging
import sys

import pytest

from k8s_test_harness import harness
from k8s_test_harness.util import constants
from k8s_test_harness.util import env_util
from k8s_test_harness.util import k8s_util
from k8s_test_harness.util import platform_util


LOG: logging.Logger = logging.getLogger(__name__)

LOG.addHandler(logging.FileHandler(f"{__name__}.log"))
LOG.addHandler(logging.StreamHandler(sys.stdout))


IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]
CHART_RELEASE_URL = (
"https://github.com/goharbor/harbor-helm/archive/refs/tags/v1.15.0.tar.gz")
INSTALL_NAME = "harbor"

# This mapping indicates which fields of the upstream Harbor Helm chart
# contain the 'image' fields which should be overriden with the ROCK
# image URLs and version during testing.
# https://github.com/goharbor/harbor-helm/blob/main/values.yaml
IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP = {
"harbor-db": "database.internal",
"harbor-core": "core",
"harbor-jobservice": "jobservice",
"harbor-registryctl": "registry.controller",
"harbor-exporter": "exporter",
"harbor-portal": "portal",
"nginx-photon": "nginx",
"redis-photon": "redis.internal",
"registry-photon": "registry.registry",
"trivy-adapter-photon": "trivy",
}


@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_harbor_chart_deployment(
module_instance: harness.Instance, image_version: str):

architecture = platform_util.get_current_rockcraft_platform_architecture()

# Compose the Helm command line args for overriding the
# image fields for each component:
all_chart_value_overrides_args = []
found_env_rocks_metadata = []
all_rocks_meta_info = env_util.get_rocks_meta_info_from_env()

# NOTE(aznashwan): GitHub actions UI sometimes truncates env values:
LOG.info(
f"All built rocks metadata from env was: "
f"{json.dumps([rmi.__dict__ for rmi in all_rocks_meta_info])}")

for rmi in all_rocks_meta_info:
if rmi.name in IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP and (
rmi.version == image_version and rmi.arch == architecture):
chart_section = IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP[rmi.name]
repo, tag = rmi.image.split(':')
all_chart_value_overrides_args.extend([
"--set", f"{chart_section}.image.repository={repo}",
"--set", f"{chart_section}.image.tag={tag}"
])
found_env_rocks_metadata.append(rmi.name)

missing = [
img
for img in IMAGE_NAMES_TO_CHART_VALUES_OVERRIDES_MAP
if img not in found_env_rocks_metadata]
if missing:
pytest.fail(
f"Failed to find built ROCK metadata for images {missing} "
f"of version '{image_version}' and architecture '{architecture}'. "
f"All built images metadata was: {all_rocks_meta_info}")

install_name = f"{INSTALL_NAME}-{image_version.replace('.', '-')}"
helm_command = [
"sudo",
"k8s",
"helm",
"install",
install_name,
CHART_RELEASE_URL,
]
helm_command.extend(all_chart_value_overrides_args)

module_instance.exec(helm_command)

# TODO(aznashwan): determine why integration tests don't work on the GH runners:
# deployments = [
# "harbor-core", "harbor-jobservice", "harbor-portal", "harbor-registry"]
# for deployment in deployments:
# k8s_util.wait_for_deployment(
# module_instance, deployment,
# condition=constants.K8S_CONDITION_AVAILABLE)
3 changes: 1 addition & 2 deletions tests/requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ pytest==7.3.1
PyYAML==6.0.1
tenacity==8.2.3
charmed-kubeflow-chisme>=0.4
# TODO(aznashwan): update with upstream Canonical repo when the time comes:
git+https://github.com/aznashwan/k8s-test-harness.git@main
git+https://github.com/canonical/k8s-test-harness.git@main
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util


LOG: logging.Logger = logging.getLogger(__name__)
Expand All @@ -16,22 +17,25 @@


IMAGE_NAME = "harbor-core"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"
IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]


@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_compare_rock_files_to_original(image_version):
"""Test ROCK contains same fileset as original image."""

original_image = f"docker.io/goharbor/{IMAGE_NAME}:{image_version}"
architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
IMAGE_NAME, image_version, architecture)
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
original_image, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util


LOG: logging.Logger = logging.getLogger(__name__)
Expand All @@ -16,16 +17,18 @@


IMAGE_NAME = "harbor-db"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"
IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]


@pytest.mark.abort_on_fail
def test_check_rock_contains_files():
@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_check_rock_contains_files(image_version):
"""Test ROCK contains same fileset as original image."""

architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
IMAGE_NAME, image_version, architecture)
rock_image = rock_meta.image

image_files_to_check = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util


LOG: logging.Logger = logging.getLogger(__name__)
Expand All @@ -16,22 +17,25 @@


IMAGE_NAME = "harbor-exporter"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"
IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]


@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_compare_rock_files_to_original(image_version):
"""Test ROCK contains same fileset as original image."""

original_image = f"docker.io/goharbor/{IMAGE_NAME}:{image_version}"
architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
IMAGE_NAME, image_version, architecture)
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
original_image, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util


LOG: logging.Logger = logging.getLogger(__name__)
Expand All @@ -16,22 +17,25 @@


IMAGE_NAME = "harbor-jobservice"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"
IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]


@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_compare_rock_files_to_original(image_version):
"""Test ROCK contains same fileset as original image."""

architecture = platform_util.get_current_rockcraft_platform_architecture()
original_image = f"docker.io/goharbor/{IMAGE_NAME}:{image_version}"

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
IMAGE_NAME, image_version, architecture)
rock_image = rock_meta.image

dir_to_check = "/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
original_image, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util


LOG: logging.Logger = logging.getLogger(__name__)
Expand All @@ -17,16 +18,18 @@


IMAGE_NAME = "harbor-portal"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"
IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]


@pytest.mark.abort_on_fail
def test_check_rock_contains_files():
@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_check_rock_contains_files(image_version):
"""Test ROCK contains expected files"""

architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
IMAGE_NAME, image_version, architecture)
rock_image = rock_meta.image

image_files_to_check = [
Expand All @@ -38,17 +41,21 @@ def test_check_rock_contains_files():
rock_image, image_files_to_check)

@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_compare_rock_files_to_original(image_version):
"""Test ROCK contains same fileset as original image."""

original_image = f"docker.io/goharbor/{IMAGE_NAME}:{image_version}"
architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
IMAGE_NAME, image_version, architecture)
rock_image = rock_meta.image

dir_to_check = "/usr/share/nginx/html"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
original_image, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from k8s_test_harness.util import docker_util
from k8s_test_harness.util import env_util
from k8s_test_harness.util import platform_util


LOG: logging.Logger = logging.getLogger(__name__)
Expand All @@ -16,22 +17,25 @@


IMAGE_NAME = "harbor-registryctl"
IMAGE_TAG = "v2.10.2"
ORIGINAL_IMAGE = f"docker.io/goharbor/{IMAGE_NAME}:{IMAGE_TAG}"
IMAGE_VERSIONS = ["v2.6.3", "v2.9.3", "v2.10.2"]


@pytest.mark.abort_on_fail
def test_compare_rock_files_to_original():
@pytest.mark.parametrize("image_version", IMAGE_VERSIONS)
def test_compare_rock_files_to_original(image_version):
"""Test ROCK contains same fileset as original image."""

original_image = f"docker.io/goharbor/{IMAGE_NAME}:{image_version}"
architecture = platform_util.get_current_rockcraft_platform_architecture()

rock_meta = env_util.get_build_meta_info_for_rock_version(
IMAGE_NAME, IMAGE_TAG, "amd64")
IMAGE_NAME, image_version, architecture)
rock_image = rock_meta.image

dir_to_check = "/home/harbor"

original_image_files = docker_util.list_files_under_container_image_dir(
ORIGINAL_IMAGE, root_dir=dir_to_check)
original_image, root_dir=dir_to_check)
rock_image_files = docker_util.list_files_under_container_image_dir(
rock_image, root_dir=dir_to_check)

Expand Down
Loading

0 comments on commit 751ce5a

Please sign in to comment.