Skip to content

Commit

Permalink
fix(chart): fix object naming and add test to verify
Browse files Browse the repository at this point in the history
Fixed #2148

Signed-off-by: Viet Nguyen Duc <[email protected]>
  • Loading branch information
VietND96 committed Feb 26, 2024
1 parent e4d40c9 commit c4bcb36
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 37 deletions.
2 changes: 1 addition & 1 deletion charts/selenium-grid/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: selenium-grid
description: A Helm chart for creating a Selenium Grid Server in Kubernetes
type: application
version: 0.28.2
version: 0.28.3
appVersion: 4.18.1-20240224
icon: https://github.com/SeleniumHQ/docker-selenium/raw/trunk/logo.png
dependencies:
Expand Down
2 changes: 1 addition & 1 deletion charts/selenium-grid/templates/_nameHelpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Selenium Hub fullname
Event bus fullname
*/}}
{{- define "seleniumGrid.eventBus.fullname" -}}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-event-bus" $)) .Values.components.eventBus.nameOverride) $ | trunc 63 | trimSuffix "-" | trimPrefix "selenium-" -}}
{{- tpl (default (include "seleniumGrid.component.name" (list "selenium-event-bus" $)) .Values.components.eventBus.nameOverride) $ | trunc 63 | trimSuffix "-" -}}
{{- end -}}

{{/*
Expand Down
14 changes: 8 additions & 6 deletions tests/charts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ python -m pip install pyyaml==6.0.1 \

cd ..

helm template dummy --values tests/charts/templates/render/dummy.yaml \
RELEASE_NAME="selenium"

helm template ${RELEASE_NAME} --values tests/charts/templates/render/dummy.yaml \
--set-file 'nodeConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'recorderConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'uploaderConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
charts/selenium-grid > ./tests/tests/dummy_template_manifests.yaml

python tests/charts/templates/test.py "./tests/tests/dummy_template_manifests.yaml" dummy
python tests/charts/templates/test.py "./tests/tests/dummy_template_manifests.yaml" ${RELEASE_NAME}
if [ $? -ne 0 ]; then
echo "Failed to validate the chart"
exit 1
Expand All @@ -28,13 +30,15 @@ fi
helm dependency update tests/charts/umbrella-charts
helm dependency build tests/charts/umbrella-charts

helm template dummy --values tests/charts/templates/render/dummy_solution.yaml \
RELEASE_NAME="test"

helm template ${RELEASE_NAME} --values tests/charts/templates/render/dummy_solution.yaml \
--set-file 'selenium-grid.nodeConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'selenium-grid.recorderConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
--set-file 'selenium-grid.uploaderConfigMap.extraScripts.setFromCommand\.sh=tests/charts/templates/render/dummy_external.sh' \
tests/charts/umbrella-charts > ./tests/tests/dummy_solution_template_manifests.yaml

python tests/charts/templates/test.py "./tests/tests/dummy_solution_template_manifests.yaml" dummy
python tests/charts/templates/test.py "./tests/tests/dummy_solution_template_manifests.yaml" ${RELEASE_NAME}
if [ $? -ne 0 ]; then
echo "Failed to validate the umbrella chart"
exit 1
Expand All @@ -43,5 +47,3 @@ fi
if [ "${CI:-false}" = "false" ]; then
deactivate
fi

exit $ret_code
61 changes: 33 additions & 28 deletions tests/charts/templates/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ def load_template(yaml_file):

class ChartTemplateTests(unittest.TestCase):
def test_set_affinity(self):
resources_name = ['{0}-selenium-chrome-node'.format(RELEASE_NAME),
'{0}-selenium-distributor'.format(RELEASE_NAME),
'{0}-selenium-edge-node'.format(RELEASE_NAME),
'{0}-selenium-firefox-node'.format(RELEASE_NAME),
'{0}-selenium-event-bus'.format(RELEASE_NAME),
'{0}-selenium-router'.format(RELEASE_NAME),
'{0}-selenium-session-map'.format(RELEASE_NAME),
'{0}-selenium-session-queue'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-chrome-node'.format(RELEASE_NAME),
'{0}selenium-distributor'.format(RELEASE_NAME),
'{0}selenium-edge-node'.format(RELEASE_NAME),
'{0}selenium-firefox-node'.format(RELEASE_NAME),
'{0}selenium-event-bus'.format(RELEASE_NAME),
'{0}selenium-router'.format(RELEASE_NAME),
'{0}selenium-session-map'.format(RELEASE_NAME),
'{0}selenium-session-queue'.format(RELEASE_NAME)]
count = 0
logger.info(f"Assert affinity is set in global and nodes")
for doc in LIST_OF_DOCUMENTS:
Expand All @@ -35,7 +35,7 @@ def test_set_affinity(self):
self.assertEqual(count, len(resources_name), "Not all resources have affinity set")

def test_ingress_nginx_annotations(self):
resources_name = ['{0}-selenium-ingress'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-ingress'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Ingress':
Expand All @@ -52,7 +52,7 @@ def test_ingress_nginx_annotations(self):
self.assertEqual(count, len(resources_name), "No ingress resources found")

def test_sub_path_append_to_node_grid_url(self):
resources_name = ['{0}-selenium-node-config'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-node-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
Expand All @@ -62,7 +62,7 @@ def test_sub_path_append_to_node_grid_url(self):
self.assertEqual(count, len(resources_name), "No node config resources found")

def test_sub_path_set_to_grid_env_var(self):
resources_name = ['{0}-selenium-router'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-router'.format(RELEASE_NAME)]
is_present = False
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Deployment':
Expand All @@ -74,7 +74,7 @@ def test_sub_path_set_to_grid_env_var(self):
self.assertTrue(is_present, "ENV variable SE_SUB_PATH is not populated")

def test_disable_ui_set_to_grid_env_var(self):
resources_name = ['{0}-selenium-router'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-router'.format(RELEASE_NAME)]
is_present = False
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'Deployment':
Expand All @@ -86,18 +86,18 @@ def test_disable_ui_set_to_grid_env_var(self):
self.assertTrue(is_present, "ENV variable SE_DISABLE_UI is not populated")

def test_log_level_set_to_logging_config_map(self):
resources_name = ['{0}-selenium-chrome-node'.format(RELEASE_NAME),
'{0}-selenium-distributor'.format(RELEASE_NAME),
'{0}-selenium-edge-node'.format(RELEASE_NAME),
'{0}-selenium-firefox-node'.format(RELEASE_NAME),
'{0}-selenium-event-bus'.format(RELEASE_NAME),
'{0}-selenium-router'.format(RELEASE_NAME),
'{0}-selenium-session-map'.format(RELEASE_NAME),
'{0}-selenium-session-queue'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-chrome-node'.format(RELEASE_NAME),
'{0}selenium-distributor'.format(RELEASE_NAME),
'{0}selenium-edge-node'.format(RELEASE_NAME),
'{0}selenium-firefox-node'.format(RELEASE_NAME),
'{0}selenium-event-bus'.format(RELEASE_NAME),
'{0}selenium-router'.format(RELEASE_NAME),
'{0}selenium-session-map'.format(RELEASE_NAME),
'{0}selenium-session-queue'.format(RELEASE_NAME)]
logger.info(f"Assert log level value is set to logging ConfigMap")
count_config = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] == '{0}-selenium-logging-config'.format(RELEASE_NAME) and doc['kind'] == 'ConfigMap':
if doc['metadata']['name'] == '{0}selenium-logging-config'.format(RELEASE_NAME) and doc['kind'] == 'ConfigMap':
self.assertTrue(doc['data']['SE_LOG_LEVEL'] == 'FINE')
count_config += 1
self.assertEqual(count_config, 1, "No logging ConfigMap found")
Expand All @@ -109,16 +109,16 @@ def test_log_level_set_to_logging_config_map(self):
list_env_from = doc['spec']['template']['spec']['containers'][0]['envFrom']
for env in list_env_from:
if env.get('configMapRef') is not None:
if env['configMapRef']['name'] == '{0}-selenium-logging-config'.format(RELEASE_NAME):
if env['configMapRef']['name'] == '{0}selenium-logging-config'.format(RELEASE_NAME):
is_present = True
self.assertTrue(is_present, "envFrom doesn't contain logging ConfigMap")
count += 1
self.assertEqual(count, len(resources_name), "Logging ConfigMap is not present in expected resources")

def test_node_port_set_when_service_type_is_node_port(self):
single_node_port = {'{0}-selenium-distributor'.format(RELEASE_NAME): 30553,
'{0}-selenium-router'.format(RELEASE_NAME): 30444,
'{0}-selenium-session-queue'.format(RELEASE_NAME): 30559}
single_node_port = {'{0}selenium-distributor'.format(RELEASE_NAME): 30553,
'{0}selenium-router'.format(RELEASE_NAME): 30444,
'{0}selenium-session-queue'.format(RELEASE_NAME): 30559}
count = 0
logger.info(f"Assert NodePort is set to components service")
for doc in LIST_OF_DOCUMENTS:
Expand All @@ -130,13 +130,14 @@ def test_node_port_set_when_service_type_is_node_port(self):

def test_all_metadata_name_is_prefixed_with_release_name(self):
logger.info(f"Assert all metadata name is prefixed with RELEASE NAME")
prefix = "selenium-" if RELEASE_NAME == "" else RELEASE_NAME
for doc in LIST_OF_DOCUMENTS:
logger.info(f"Assert metadata name: {doc['metadata']['name']}")
self.assertTrue(doc['metadata']['name'].startswith(RELEASE_NAME),
f"Metadata name {doc['metadata']['name']} is not prefixed with RELEASE NAME: {RELEASE_NAME}")

def test_extra_script_import_to_node_configmap(self):
resources_name = ['{0}-selenium-node-config'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-node-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
Expand All @@ -149,7 +150,7 @@ def test_extra_script_import_to_node_configmap(self):
self.assertEqual(count, len(resources_name), "No node config resources found")

def test_extra_script_import_to_uploader_configmap(self):
resources_name = ['{0}-selenium-uploader-config'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-uploader-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
Expand All @@ -160,7 +161,7 @@ def test_extra_script_import_to_uploader_configmap(self):
self.assertEqual(count, len(resources_name), "No uploader config resources found")

def test_extra_script_import_to_recorder_configmap(self):
resources_name = ['{0}-selenium-recorder-config'.format(RELEASE_NAME)]
resources_name = ['{0}selenium-recorder-config'.format(RELEASE_NAME)]
count = 0
for doc in LIST_OF_DOCUMENTS:
if doc['metadata']['name'] in resources_name and doc['kind'] == 'ConfigMap':
Expand All @@ -175,6 +176,10 @@ def test_extra_script_import_to_recorder_configmap(self):
try:
FILE_NAME = sys.argv[1]
RELEASE_NAME = sys.argv[2]
if RELEASE_NAME == "selenium":
RELEASE_NAME = ""
else:
RELEASE_NAME = RELEASE_NAME + "-"
LIST_OF_DOCUMENTS = load_template(FILE_NAME)
suite = unittest.TestLoader().loadTestsFromTestCase(ChartTemplateTests)
test_runner = unittest.TextTestRunner(verbosity=3)
Expand Down
2 changes: 1 addition & 1 deletion tests/charts/umbrella-charts/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ version: 0.0.1
appVersion: "1.0.0"
dependencies:
- name: selenium-grid
version: 0.28.2
version: 0.28.3
repository: file://../../../charts/selenium-grid

0 comments on commit c4bcb36

Please sign in to comment.