]> git.proxmox.com Git - ceph.git/blob - ceph/qa/workunits/ceph-helpers-root.sh
update ceph source to reef 18.1.2
[ceph.git] / ceph / qa / workunits / ceph-helpers-root.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (C) 2015 Red Hat <contact@redhat.com>
4 #
5 # Author: Loic Dachary <loic@dachary.org>
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU Library Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Library Public License for more details.
16 #
17
18 #######################################################################
19
20 function distro_id() {
21 source /etc/os-release
22 echo $ID
23 }
24
25 function distro_version() {
26 source /etc/os-release
27 echo $VERSION
28 }
29
30 function install() {
31 if [ $(distro_id) = "ubuntu" ]; then
32 sudo apt-get purge -y gcc
33 sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
34 fi
35 for package in "$@" ; do
36 install_one $package
37 done
38 if [ $(distro_id) = "ubuntu" ]; then
39 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 11
40 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-11 11
41 sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc 11
42 sudo update-alternatives --set cc /usr/bin/gcc
43 sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++ 11
44 sudo update-alternatives --set c++ /usr/bin/g++
45 fi
46 }
47
48 function install_one() {
49 case $(distro_id) in
50 ubuntu|debian|devuan|softiron)
51 sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"
52 ;;
53 centos|fedora|rhel)
54 sudo yum install -y "$@"
55 ;;
56 opensuse*|suse|sles)
57 sudo zypper --non-interactive install "$@"
58 ;;
59 *)
60 echo "$(distro_id) is unknown, $@ will have to be installed manually."
61 ;;
62 esac
63 }
64
65 function install_pkg_on_ubuntu {
66 local project=$1
67 shift
68 local sha1=$1
69 shift
70 local codename=$1
71 shift
72 local force=$1
73 shift
74 local pkgs=$@
75 local missing_pkgs
76 if [ $force = "force" ]; then
77 missing_pkgs="$@"
78 else
79 for pkg in $pkgs; do
80 if ! dpkg -s $pkg &> /dev/null; then
81 missing_pkgs+=" $pkg"
82 fi
83 done
84 fi
85 if test -n "$missing_pkgs"; then
86 local shaman_url="https://shaman.ceph.com/api/repos/${project}/master/${sha1}/ubuntu/${codename}/repo"
87 sudo curl --silent --location $shaman_url --output /etc/apt/sources.list.d/$project.list
88 sudo env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
89 sudo env DEBIAN_FRONTEND=noninteractive apt-get install --allow-unauthenticated -y $missing_pkgs
90 fi
91 }
92
93 #######################################################################
94
95 function control_osd() {
96 local action=$1
97 local id=$2
98
99 sudo systemctl $action ceph-osd@$id
100
101 return 0
102 }
103
104 #######################################################################
105
106 function pool_read_write() {
107 local size=${1:-1}
108 local dir=/tmp
109 local timeout=360
110 local test_pool=test_pool
111
112 ceph osd pool delete $test_pool $test_pool --yes-i-really-really-mean-it || return 1
113 ceph osd pool create $test_pool 4 || return 1
114 ceph osd pool set $test_pool size $size --yes-i-really-mean-it || return 1
115 ceph osd pool set $test_pool min_size $size || return 1
116 ceph osd pool application enable $test_pool rados
117
118 echo FOO > $dir/BAR
119 timeout $timeout rados --pool $test_pool put BAR $dir/BAR || return 1
120 timeout $timeout rados --pool $test_pool get BAR $dir/BAR.copy || return 1
121 diff $dir/BAR $dir/BAR.copy || return 1
122 ceph osd pool delete $test_pool $test_pool --yes-i-really-really-mean-it || return 1
123 }
124
125 #######################################################################
126
127 set -x
128
129 "$@"