diff --git a/Jenkinsfile b/Jenkinsfile index 346a69169d..a59f39943a 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -89,7 +89,7 @@ pipeline { parallel { stage ('1: run first test suite') { steps { - sh script: "make -j$NPROC kind/retest TESTS=[api,deploytarget,active-standby-kubernetes,features-kubernetes,features-kubernetes-2,features-api-variables,tasks] BRANCH_NAME=${SAFEBRANCH_NAME}", label: "Running first test suite on kind cluster" + sh script: "make -j$NPROC kind/retest TESTS=[api,deploytarget,active-standby-kubernetes,features-kubernetes,features-kubernetes-2,features-api-variables,tasks,ssh-portal] BRANCH_NAME=${SAFEBRANCH_NAME}", label: "Running first test suite on kind cluster" sh script: "pkill -f './local-dev/stern'", label: "Closing off test-suite-1 log after test completion" } } diff --git a/Makefile b/Makefile index 7803526a98..ad5ed30234 100644 --- a/Makefile +++ b/Makefile @@ -510,7 +510,7 @@ GOJQ_VERSION = v0.12.5 STERN_VERSION = 2.1.17 CHART_TESTING_VERSION = v3.4.0 KIND_IMAGE = kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6 -TESTS = [nginx,api,features-kubernetes,features-kubernetes-2,features-api-variables,active-standby-kubernetes,tasks,drush,drupal-php80,drupal-postgres,python,gitlab,github,bitbucket,node-mongodb,elasticsearch] +TESTS = [nginx,api,features-kubernetes,ssh-portal,features-kubernetes-2,features-api-variables,active-standby-kubernetes,tasks,drush,drupal-php80,drupal-postgres,python,gitlab,github,bitbucket,node-mongodb,elasticsearch] CHARTS_TREEISH = ssh-portal # Symlink the installed kubectl client if the correct version is already @@ -584,6 +584,7 @@ helm/repos: local-dev/helm ./local-dev/helm repo add amazeeio https://amazeeio.github.io/charts/ ./local-dev/helm repo add lagoon https://uselagoon.github.io/lagoon-charts/ ./local-dev/helm repo add minio https://helm.min.io/ + ./local-dev/helm repo add nats https://nats-io.github.io/k8s/helm/charts/ ./local-dev/helm repo update # stand up a kind cluster configured appropriately for lagoon testing diff --git a/tests/entrypoint.sh b/tests/entrypoint.sh index 56bedba88b..8b60f1cafa 100755 --- a/tests/entrypoint.sh +++ b/tests/entrypoint.sh @@ -2,7 +2,7 @@ set -e # inject variables from environment into the Ansible var template -envsubst '$API_HOST $API_PORT $API_PROTOCOL $CLUSTER_TYPE $DELETED_STATUS_CODE $GIT_HOST $GIT_REPO_PREFIX $GIT_PORT $ROUTE_SUFFIX_HTTP $ROUTE_SUFFIX_HTTP_PORT $ROUTE_SUFFIX_HTTPS $ROUTE_SUFFIX_HTTPS_PORT $SSH_HOST $SSH_PORT $WEBHOOK_HOST $WEBHOOK_PORT $WEBHOOK_PROTOCOL $WEBHOOK_REPO_PREFIX' < /ansible/tests/vars/test_vars.yaml | sponge /ansible/tests/vars/test_vars.yaml +envsubst '$API_HOST $API_PORT $API_PROTOCOL $CLUSTER_TYPE $DELETED_STATUS_CODE $GIT_HOST $GIT_REPO_PREFIX $GIT_PORT $ROUTE_SUFFIX_HTTP $ROUTE_SUFFIX_HTTP_PORT $ROUTE_SUFFIX_HTTPS $ROUTE_SUFFIX_HTTPS_PORT $SSH_HOST $SSH_PORT $SSH_PORTAL_HOST $SSH_PORTAL_PORT $WEBHOOK_HOST $WEBHOOK_PORT $WEBHOOK_PROTOCOL $WEBHOOK_REPO_PREFIX' < /ansible/tests/vars/test_vars.yaml | sponge /ansible/tests/vars/test_vars.yaml if [ ! -z "$SSH_PRIVATE_KEY" ]; then mkdir -p ~/.ssh @@ -15,4 +15,4 @@ fi echo -e "Host * \n StrictHostKeyChecking no" >> /etc/ssh/ssh_config -exec "$@" \ No newline at end of file +exec "$@" diff --git a/tests/tasks/ssh/ssh-portal-command.yaml b/tests/tasks/ssh/ssh-portal-command.yaml new file mode 100644 index 0000000000..ee9899149a --- /dev/null +++ b/tests/tasks/ssh/ssh-portal-command.yaml @@ -0,0 +1,6 @@ +- name: "{{ testname }} - running {{ command }} on {{ username }}@{{ ssh_portal_host }} on port {{ ssh_portal_port }}, searching for '{{ expected_content }}'" + shell: ssh {{ username }}@{{ ssh_portal_host }} -p {{ ssh_portal_port }} {{ command }} + register: result + until: result.stdout is search(expected_content) + retries: 30 + delay: 10 diff --git a/tests/tests/features/remote-ssh-portal.yaml b/tests/tests/features/remote-ssh-portal.yaml new file mode 100644 index 0000000000..0a10598ae0 --- /dev/null +++ b/tests/tests/features/remote-ssh-portal.yaml @@ -0,0 +1,76 @@ +- name: "{{ testname }} - init git, add files, commit, git push" + hosts: localhost + serial: 1 + vars: + git_files: "node{{ node_version }}/" + tasks: + - include: ../../tasks/git-init.yaml + - include: ../../tasks/git-add-commit-push.yaml + +- name: "{{ testname }} - api deployEnvironmentBranch on {{ project }}, which should deploy the first commit" + hosts: localhost + serial: 1 + vars: + branch: "{{ branch }}" + project: "{{ project }}" + namespace: "{{ project | regex_replace('_', '-') }}-{{ branch | regex_replace('/', '-') }}" + tasks: + - include: ../../tasks/api/deploy-no-sha.yaml + +- name: "{{ testname }} - check if we can connect via oc project user" + hosts: localhost + serial: 1 + vars: + username: "{{ project }}-remoteshell" + command: service=node env + expected_content: "LAGOON_PROJECT={{ project }}" + tasks: + - include: ../../tasks/ssh/ssh-portal-command.yaml + +- name: "{{ testname }} - check if we can connect via oc project user and defining the container" + hosts: localhost + serial: 1 + vars: + username: "{{ project }}-remoteshell" + command: service=node container=node env + expected_content: "LAGOON_PROJECT={{ project }}" + tasks: + - include: ../../tasks/ssh/ssh-portal-command.yaml + +- name: "{{ testname }} - check if we are on the right git hash via oc project user" + hosts: localhost + serial: 1 + vars: + username: "{{ project }}-remoteshell" + command: service=node env + expected_content: "LAGOON_GIT_SHA={{ current_head }}" + tasks: + - include: ../../tasks/ssh/ssh-portal-command.yaml + +- name: "{{ testname }} - check if we are on the right git branch via oc project user" + hosts: localhost + serial: 1 + vars: + username: "{{ project }}-remoteshell" + command: service=node env + expected_content: "LAGOON_GIT_BRANCH={{ branch }}" + tasks: + - include: ../../tasks/ssh/ssh-portal-command.yaml + +- name: "{{ testname }} - api deleteEnvironment on {{ project }}, which should remove all resources" + hosts: localhost + serial: 1 + vars: + project: "{{ project }}" + branch: "{{ branch }}" + tasks: + - include: ../../tasks/api/delete-environment.yaml + +- name: "{{ testname }} - check if site for {{ project }} does not exist anymore" + hosts: localhost + serial: 1 + vars: + url: "{{ check_url }}" + expected_returncode: "{{ del_status_code }}" + tasks: + - include: ../../checks/check-url-returncode.yaml diff --git a/tests/tests/ssh-portal.yaml b/tests/tests/ssh-portal.yaml new file mode 100644 index 0000000000..87b603b0f4 --- /dev/null +++ b/tests/tests/ssh-portal.yaml @@ -0,0 +1,27 @@ +--- +- include: features/random-wait.yaml + +- include: features/api-token.yaml + vars: + testname: "API TOKEN" + +- include: api/add-project.yaml + vars: + project: ci-ssh-portal-{{ cluster_type }} + git_repo_name: features.git + git_url: "{{ localgit_url }}/{{ git_repo_name }}" + +- include: features/remote-ssh-portal.yaml + vars: + testname: "REMOTE SSH PORTAL {{ cluster_type|upper }}" + node_version: 16 + git_repo_name: features.git + project: ci-ssh-portal-{{ cluster_type }} + branch: remoteshell + check_url: "http://node.{{ project | regex_replace('_', '-') }}.{{ branch | regex_replace('/', '-') }}.{{ route_suffix }}" + ssh_host: "{{ ssh_portal_host }}" + ssh_auth_port: "{{ ssh_portal_port }}" + +- include: api/delete-project.yaml + vars: + project: ci-ssh-portal-{{ cluster_type }} diff --git a/tests/tests/vars/test_vars.yaml b/tests/tests/vars/test_vars.yaml index 261d18d471..98496f66ad 100644 --- a/tests/tests/vars/test_vars.yaml +++ b/tests/tests/vars/test_vars.yaml @@ -4,8 +4,10 @@ graphql_url: "$API_PROTOCOL://$API_HOST:$API_PORT/graphql" localgit_url: "ssh://git@$GIT_HOST:$GIT_PORT/git" ssh_host: "$SSH_HOST" ssh_auth_port: "$SSH_PORT" +ssh_portal_host: "$SSH_PORTAL_HOST" +ssh_portal_port: "$SSH_PORTAL_PORT" cluster_type: "$CLUSTER_TYPE" route_suffix: "$ROUTE_SUFFIX_HTTP:$ROUTE_SUFFIX_HTTP_PORT" route_suffix_https: "$ROUTE_SUFFIX_HTTPS:$ROUTE_SUFFIX_HTTPS_PORT" route_suffix_wo_port: "$ROUTE_SUFFIX_HTTP" -del_status_code: "$DELETED_STATUS_CODE" \ No newline at end of file +del_status_code: "$DELETED_STATUS_CODE"