Skip to content

Commit

Permalink
Merge pull request #199 from canonical/kf-5655-add-dashboard-integrat…
Browse files Browse the repository at this point in the history
…ion-test

Add integration check to test if the dashboard is accessible
  • Loading branch information
mvlassis authored Jun 13, 2024
2 parents ce0be86 + ed902c7 commit 3b54463
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions requirements-integration.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
aiohttp
# Pinning to <4.0 due to compatibility with the 3.1 controller version
juju<4.0
lightkube
Expand Down
18 changes: 18 additions & 0 deletions requirements-integration.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
#
# pip-compile requirements-integration.in
#
aiohttp==3.9.5
# via -r requirements-integration.in
aiosignal==1.3.1
# via aiohttp
anyio==4.0.0
# via httpcore
asttokens==2.4.0
# via stack-data
async-timeout==4.0.3
# via aiohttp
attrs==23.1.0
# via
# aiohttp
# jsonschema
# outcome
# trio
Expand Down Expand Up @@ -57,6 +64,10 @@ exceptiongroup==1.1.3
# trio-websocket
executing==1.2.0
# via stack-data
frozenlist==1.4.1
# via
# aiohttp
# aiosignal
google-auth==2.17.3
# via kubernetes
h11==0.14.0
Expand All @@ -83,6 +94,7 @@ idna==3.4
# httpx
# requests
# trio
# yarl
importlib-resources==6.0.1
# via jsonschema
iniconfig==2.0.0
Expand Down Expand Up @@ -120,6 +132,10 @@ markupsafe==2.1.3
# via jinja2
matplotlib-inline==0.1.6
# via ipython
multidict==6.0.5
# via
# aiohttp
# yarl
mypy-extensions==1.0.0
# via typing-inspect
oauthlib==3.2.2
Expand Down Expand Up @@ -303,6 +319,8 @@ wsproto==1.2.0
# via
# selenium-wire
# trio-websocket
yarl==1.9.4
# via aiohttp
zipp==3.16.2
# via importlib-resources
zstandard==0.21.0
Expand Down
27 changes: 26 additions & 1 deletion tests/integration/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pathlib import Path
from typing import Dict, List

import aiohttp
import pytest
import pytest_asyncio
import yaml
Expand All @@ -16,7 +17,7 @@
)
from dashboard_links_requirer_tester_charm.src.charm import generate_links_for_location
from lightkube import Client
from lightkube.resources.core_v1 import ConfigMap
from lightkube.resources.core_v1 import ConfigMap, Service
from pytest_operator.plugin import OpsTest

from charm import ADDITIONAL_LINKS_CONFIG_NAME, EXTERNAL_LINKS_ORDER_CONFIG_NAME
Expand Down Expand Up @@ -315,3 +316,27 @@ async def assert_links_in_configmap_by_text_value(
assert item.text in links_texts

return links_texts


async def test_dashboard_access(ops_test: OpsTest, lightkube_client: Client):
"""Tests that the dashboard is accessible by sending an HTTP request to the
kubeflow-dashboard Service IP and checking the HTTP status code and the response
text.
"""
namespace = ops_test.model_name
application_ip = lightkube_client.get(Service, CHARM_NAME, namespace=namespace).spec.clusterIP
application_port = (await ops_test.model.applications[CHARM_NAME].get_config())["port"][
"value"
]
# The URL to access the central dashboard, in this case kubeflow-dashboard's
# IP + the port specified in the configuration
url = f"http://{str(application_ip)}:{str(application_port)}"

async with aiohttp.ClientSession() as session:
async with session.get(url, headers=None) as response:
result_status = response.status
result_text = str(await response.text())
# Assert that we receive the expected status code
assert result_status == 200
# And that the title is the one expected
assert "<title>Kubeflow Central Dashboard</title>" in result_text

0 comments on commit 3b54463

Please sign in to comment.