summaryrefslogtreecommitdiffstats
path: root/qa/workunits/ceph-helpers-root.sh
blob: 5b5d2b409ee565be2b4b3114f37ed88f552baa3a (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/usr/bin/env bash
#
# Copyright (C) 2015 Red Hat <contact@redhat.com>
#
# Author: Loic Dachary <loic@dachary.org>
#
# 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.
#

#######################################################################

function distro_id() {
    source /etc/os-release
    echo $ID
}

function distro_version() {
    source /etc/os-release
    echo $VERSION
}

function install() {
    if [ $(distro_id) = "ubuntu" ]; then
        sudo apt-get purge -y gcc
        sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
    fi
    for package in "$@" ; do
        install_one $package
    done
    if [ $(distro_id) = "ubuntu" ]; then
        sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11
        sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11
        sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 11
        sudo update-alternatives --set cc /usr/bin/gcc
        sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 11
        sudo update-alternatives --set c++ /usr/bin/g++
    fi
}

function install_one() {
    case $(distro_id) in
        ubuntu|debian|devuan|softiron)
            sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"
            ;;
        centos|fedora|rhel)
            sudo yum install -y "$@"
            ;;
        opensuse*|suse|sles)
            sudo zypper --non-interactive install "$@"
            ;;
        *)
            echo "$(distro_id) is unknown, $@ will have to be installed manually."
            ;;
    esac
}

function install_pkg_on_ubuntu {
    local project=$1
    shift
    local sha1=$1
    shift
    local codename=$1
    shift
    local force=$1
    shift
    local pkgs=$@
    local missing_pkgs
    if [ $force = "force" ]; then
	missing_pkgs="$@"
    else
	for pkg in $pkgs; do
	    if ! dpkg -s $pkg &> /dev/null; then
		missing_pkgs+=" $pkg"
	    fi
	done
    fi
    if test -n "$missing_pkgs"; then
	local shaman_url="https://shaman.ceph.com/api/repos/${project}/master/${sha1}/ubuntu/${codename}/repo"
	sudo curl --silent --location $shaman_url --output /etc/apt/sources.list.d/$project.list
	sudo env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
	sudo env DEBIAN_FRONTEND=noninteractive apt-get install --allow-unauthenticated -y $missing_pkgs
    fi
}

#######################################################################

function control_osd() {
    local action=$1
    local id=$2

    sudo systemctl $action ceph-osd@$id

    return 0
}

#######################################################################

function pool_read_write() {
    local size=${1:-1}
    local dir=/tmp
    local timeout=360
    local test_pool=test_pool

    ceph osd pool delete $test_pool $test_pool --yes-i-really-really-mean-it || return 1
    ceph osd pool create $test_pool 4 || return 1
    ceph osd pool set $test_pool size $size --yes-i-really-mean-it || return 1
    ceph osd pool set $test_pool min_size $size || return 1
    ceph osd pool application enable $test_pool rados

    echo FOO > $dir/BAR
    timeout $timeout rados --pool $test_pool put BAR $dir/BAR || return 1
    timeout $timeout rados --pool $test_pool get BAR $dir/BAR.copy || return 1
    diff $dir/BAR $dir/BAR.copy || return 1
    ceph osd pool delete $test_pool $test_pool --yes-i-really-really-mean-it || return 1
}

#######################################################################

set -x

"$@"