Skip to content

Commit 390abb9

Browse files
committed
Add hello-world demo verification
1 parent b28fc99 commit 390abb9

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

tests/interop/run_tests.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ pytest -lv --disable-warnings test_validate_hub_site_components.py --kubeconfig
3131

3232
pytest -lv --disable-warnings test_validate_edge_site_components.py --kubeconfig $KUBECONFIG_EDGE --junit-xml $WORKSPACE/test_validate_edge_site_components.xml
3333

34+
pytest -lv --disable-warnings test_modify_web_content.py --kubeconfig $KUBECONFIG --junit-xml $WORKSPACE/test_modify_web_content.xml
35+
3436
python3 create_ci_badge.py
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import logging
2+
import os
3+
import re
4+
import subprocess
5+
import time
6+
7+
import pytest
8+
import requests
9+
from ocp_resources.route import Route
10+
from openshift.dynamic.exceptions import NotFoundError
11+
from validatedpatterns_tests.interop.edge_util import modify_file_content
12+
13+
from . import __loggername__
14+
15+
logger = logging.getLogger(__loggername__)
16+
17+
18+
@pytest.mark.modify_web_content
19+
def test_modify_web_content(openshift_dyn_client):
20+
logger.info("Find the url for the hello-world route")
21+
try:
22+
for route in Route.get(
23+
dyn_client=openshift_dyn_client,
24+
namespace="hello-world",
25+
name="hello-world",
26+
):
27+
logger.info(route.instance.spec.host)
28+
except NotFoundError:
29+
err_msg = "hello-world url/route is missing in hello-world namespace"
30+
logger.error(f"FAIL: {err_msg}")
31+
assert False, err_msg
32+
33+
url = "http://" + route.instance.spec.host
34+
response = requests.get(url)
35+
logger.info(f"Current page content: {response.content}")
36+
37+
if os.getenv("EXTERNAL_TEST") != "true":
38+
chart = (
39+
f"{os.environ['HOME']}"
40+
+ "/validated_patterns/multicloud-gitops/charts/"
41+
+ "all/hello-world/templates/hello-world-cm.yaml"
42+
)
43+
else:
44+
chart = "../../charts/all/hello-world/templates/hello-world-cm.yaml"
45+
46+
logger.info("Modify the file content")
47+
orig_heading = "<h1>Hello World!</h1>"
48+
new_heading = "<h1>Validated Patterns QE was here!</h1>"
49+
modify_file_content(
50+
file_name=chart, orig_content=orig_heading, new_content=new_heading
51+
)
52+
53+
logger.info("Merge the change")
54+
patterns_repo = f"{os.environ['HOME']}/validated_patterns/multicloud-gitops"
55+
if os.getenv("EXTERNAL_TEST") != "true":
56+
subprocess.run(["git", "add", chart], cwd=f"{patterns_repo}")
57+
subprocess.run(
58+
["git", "commit", "-m", "Updating 'hello-world'"], cwd=f"{patterns_repo}"
59+
)
60+
push = subprocess.run(
61+
["git", "push"], cwd=f"{patterns_repo}", capture_output=True, text=True
62+
)
63+
else:
64+
subprocess.run(["git", "add", chart])
65+
subprocess.run(["git", "commit", "-m", "Updating 'hello-world'"])
66+
push = subprocess.run(["git", "push"], capture_output=True, text=True)
67+
logger.info(push.stdout)
68+
logger.info(push.stderr)
69+
70+
logger.info("Checking for updated page content")
71+
timeout = time.time() + 60 * 10
72+
while time.time() < timeout:
73+
time.sleep(30)
74+
response = requests.get(url)
75+
logger.info(response.content)
76+
77+
new_content = re.search(new_heading, str(response.content))
78+
79+
logger.info(new_content)
80+
if (new_content is None) or (new_content.group() != new_heading):
81+
continue
82+
break
83+
84+
if (new_content is None) or (new_content.group() != new_heading):
85+
err_msg = "Did not find updated page content"
86+
logger.error(f"FAIL: {err_msg}")
87+
assert False, err_msg
88+
else:
89+
logger.info("PASS: Found updated page content")

0 commit comments

Comments
 (0)