Skip to content

Commit

Permalink
feat: add tests for ssh-portal
Browse files Browse the repository at this point in the history
This is a copy of the existing remote shell tests, just pointing at the
new ssh-portal endpoint.
  • Loading branch information
smlx committed Feb 25, 2022
1 parent abb71c6 commit 6113fc9
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,4 +15,4 @@ fi

echo -e "Host * \n StrictHostKeyChecking no" >> /etc/ssh/ssh_config

exec "$@"
exec "$@"
6 changes: 6 additions & 0 deletions tests/tasks/ssh/ssh-portal-command.yaml
Original file line number Diff line number Diff line change
@@ -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
76 changes: 76 additions & 0 deletions tests/tests/features/remote-ssh-portal.yaml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions tests/tests/ssh-portal.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
4 changes: 3 additions & 1 deletion tests/tests/vars/test_vars.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
del_status_code: "$DELETED_STATUS_CODE"

0 comments on commit 6113fc9

Please sign in to comment.