summaryrefslogtreecommitdiffstats
path: root/src/test/mgr/mgr-dashboard-smoke.sh
blob: c3f2a822efc7177cd2aac91b3a4c4dd031933268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
#
# Copyright (C) 2014,2015,2017 Red Hat <contact@redhat.com>
# Copyright (C) 2018 SUSE LLC
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Library Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library Public License for more details.
#
source $(dirname $0)/../detect-build-env-vars.sh
source $CEPH_ROOT/qa/standalone/ceph-helpers.sh

function run() {
    local dir=$1
    shift

    export CEPH_MON=127.0.0.1:7160  # git grep '\<7160\>' : there must be only one
    export CEPH_ARGS
    CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none "
    CEPH_ARGS+="--mon-initial-members=a --mon-host=$MON "
    CEPH_ARGS+="--mgr-initial-modules=dashboard "
    CEPH_ARGS+="--mon-host=$CEPH_MON"

    setup $dir || return 1
    TEST_dashboard $dir || return 1
    teardown $dir || return 1
}

function TEST_dashboard() {
    local dir=$1
    shift

    run_mon $dir a || return 1
    timeout 30 ceph mon stat || return 1
    ceph config-key set mgr/dashboard/x/server_port 7161
    MGR_ARGS+="--mgr_module_path=${CEPH_ROOT}/src/pybind/mgr "
    run_mgr $dir x ${MGR_ARGS} || return 1

    tries=0
    while [[ $tries < 30 ]] ; do
        if [ $(ceph status -f json | jq .mgrmap.available) = "true" ]
        then
            break
        fi
        tries=$((tries+1))
        sleep 1
    done

    DASHBOARD_ADMIN_SECRET_FILE="/tmp/dashboard-admin-secret.txt"
    printf 'admin' > "${DASHBOARD_ADMIN_SECRET_FILE}"
    ceph_adm tell mgr dashboard ac-user-create admin -i "${DASHBOARD_ADMIN_SECRET_FILE}"

    tries=0
    while [[ $tries < 30 ]] ; do
        if curl -c $dir/cookiefile -X POST -d '{"username":"admin","password":"admin"}' http://127.0.0.1:7161/api/auth
        then
            if curl -b $dir/cookiefile -s http://127.0.0.1:7161/api/summary | \
                 jq '.health.overall_status' | grep HEALTH_
            then
                break
            fi
        fi
        tries=$((tries+1))
        sleep 0.5
    done
}

main mgr-dashboard-smoke "$@"

# Local Variables:
# compile-command: "cd ../.. ; make -j4 TESTS=test/mgr/mgr-dashboard-smoke.sh check"
# End: