]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/cephadm/test_dashboard_e2e.sh
import quincy beta 17.1.0
[ceph.git] / ceph / qa / workunits / cephadm / test_dashboard_e2e.sh
1 #!/bin/bash -ex
2
3 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4 DASHBOARD_FRONTEND_DIR=${SCRIPT_DIR}/../../../src/pybind/mgr/dashboard/frontend
5
6 [ -z "$SUDO" ] && SUDO=sudo
7
8 install_common () {
9 NODEJS_VERSION="16"
10 if grep -q debian /etc/*-release; then
11 $SUDO apt-get update
12 # https://github.com/nodesource/distributions#manual-installation
13 $SUDO apt-get install curl gpg
14 KEYRING=/usr/share/keyrings/nodesource.gpg
15 curl -fsSL https://deb.nodesource.com/gpgkey/nodesource.gpg.key | gpg --dearmor | $SUDO tee "$KEYRING" >/dev/null
16 DISTRO="$(source /etc/lsb-release; echo $DISTRIB_CODENAME)"
17 VERSION="node_$NODEJS_VERSION.x"
18 echo "deb [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | $SUDO tee /etc/apt/sources.list.d/nodesource.list
19 echo "deb-src [signed-by=$KEYRING] https://deb.nodesource.com/$VERSION $DISTRO main" | $SUDO tee -a /etc/apt/sources.list.d/nodesource.list
20 $SUDO apt-get update
21 $SUDO apt-get install nodejs
22 elif grep -q rhel /etc/*-release; then
23 $SUDO yum module -y enable nodejs:$NODEJS_VERSION
24 $SUDO yum install -y jq npm
25 else
26 echo "Unsupported distribution."
27 exit 1
28 fi
29 }
30
31 install_chrome () {
32 if grep -q debian /etc/*-release; then
33 $SUDO bash -c 'echo "deb [arch=amd64] https://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google-chrome.list'
34 curl -fsSL https://dl.google.com/linux/linux_signing_key.pub | $SUDO apt-key add -
35 $SUDO apt-get update
36 $SUDO apt-get install -y google-chrome-stable
37 $SUDO apt-get install -y xvfb
38 $SUDO rm /etc/apt/sources.list.d/google-chrome.list
39 elif grep -q rhel /etc/*-release; then
40 $SUDO dd of=/etc/yum.repos.d/google-chrome.repo status=none <<EOF
41 [google-chrome]
42 name=google-chrome
43 baseurl=https://dl.google.com/linux/chrome/rpm/stable/\$basearch
44 enabled=1
45 gpgcheck=1
46 gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
47 EOF
48 $SUDO yum install -y google-chrome-stable
49 $SUDO rm /etc/yum.repos.d/google-chrome.repo
50 # Cypress dependencies
51 $SUDO yum install -y xorg-x11-server-Xvfb gtk2-devel gtk3-devel libnotify-devel GConf2 nss.x86_64 libXScrnSaver alsa-lib
52 else
53 echo "Unsupported distribution."
54 exit 1
55 fi
56 }
57
58 cypress_run () {
59 local specs="$1"
60 local timeout="$2"
61 local override_config="ignoreTestFiles=*.po.ts,retries=0,testFiles=${specs}"
62
63 if [ x"$timeout" != "x" ]; then
64 override_config="${override_config},defaultCommandTimeout=${timeout}"
65 fi
66 npx cypress run --browser chrome --headless --config "$override_config"
67 }
68
69 install_common
70 install_chrome
71
72 CYPRESS_BASE_URL=$(ceph mgr services | jq -r .dashboard)
73 export CYPRESS_BASE_URL
74
75 cd $DASHBOARD_FRONTEND_DIR
76
77 # This is required for Cypress to understand typescript
78 npm ci --unsafe-perm
79 npx cypress verify
80 npx cypress info
81
82 # Take `orch device ls` and `orch ps` as ground truth.
83 ceph orch device ls --refresh
84 ceph orch ps --refresh
85 sleep 10 # the previous call is asynchronous
86 ceph orch device ls --format=json | tee cypress/fixtures/orchestrator/inventory.json
87 ceph orch ps --format=json | tee cypress/fixtures/orchestrator/services.json
88
89 DASHBOARD_ADMIN_SECRET_FILE="/tmp/dashboard-admin-secret.txt"
90 printf 'admin' > "${DASHBOARD_ADMIN_SECRET_FILE}"
91 ceph dashboard ac-user-set-password admin -i "${DASHBOARD_ADMIN_SECRET_FILE}" --force-password
92
93 # Run Dashboard e2e tests.
94 # These tests are designed with execution order in mind, since orchestrator operations
95 # are likely to change cluster state, we can't just run tests in arbitrarily order.
96 # See /ceph/src/pybind/mgr/dashboard/frontend/cypress/integration/orchestrator/ folder.
97 find cypress # List all specs
98
99 cypress_run "orchestrator/01-hosts.e2e-spec.ts"
100
101 # Hosts are removed and added in the previous step. Do a refresh again.
102 ceph orch device ls --refresh
103 sleep 10
104 ceph orch device ls --format=json | tee cypress/fixtures/orchestrator/inventory.json
105
106 cypress_run "orchestrator/03-inventory.e2e-spec.ts"
107 cypress_run "orchestrator/04-osds.e2e-spec.ts" 300000