]> git.proxmox.com Git - ceph.git/blame - ceph/qa/workunits/ceph-helpers-root.sh
buildsys: switch source download to quincy
[ceph.git] / ceph / qa / workunits / ceph-helpers-root.sh
CommitLineData
11fdf7f2 1#!/usr/bin/env bash
7c673cae
FG
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
494da23a
TL
20function distro_id() {
21 source /etc/os-release
22 echo $ID
23}
24
eafe8130
TL
25function distro_version() {
26 source /etc/os-release
27 echo $VERSION
28}
29
7c673cae
FG
30function install() {
31 for package in "$@" ; do
32 install_one $package
33 done
7c673cae
FG
34}
35
36function install_one() {
494da23a
TL
37 case $(distro_id) in
38 ubuntu|debian|devuan)
39 sudo env DEBIAN_FRONTEND=noninteractive apt-get install -y "$@"
7c673cae 40 ;;
494da23a 41 centos|fedora|rhel)
7c673cae
FG
42 sudo yum install -y "$@"
43 ;;
494da23a 44 opensuse*|suse|sles)
7c673cae
FG
45 sudo zypper --non-interactive install "$@"
46 ;;
47 *)
494da23a 48 echo "$(distro_id) is unknown, $@ will have to be installed manually."
7c673cae
FG
49 ;;
50 esac
51}
52
eafe8130
TL
53function install_pkg_on_ubuntu {
54 local project=$1
55 shift
56 local sha1=$1
57 shift
58 local codename=$1
59 shift
60 local force=$1
61 shift
62 local pkgs=$@
63 local missing_pkgs
64 if [ $force = "force" ]; then
65 missing_pkgs="$@"
66 else
67 for pkg in $pkgs; do
68 if ! dpkg -s $pkg &> /dev/null; then
69 missing_pkgs+=" $pkg"
70 fi
71 done
72 fi
73 if test -n "$missing_pkgs"; then
74 local shaman_url="https://shaman.ceph.com/api/repos/${project}/master/${sha1}/ubuntu/${codename}/repo"
75 sudo curl --silent --location $shaman_url --output /etc/apt/sources.list.d/$project.list
76 sudo env DEBIAN_FRONTEND=noninteractive apt-get update -y -o Acquire::Languages=none -o Acquire::Translation=none || true
77 sudo env DEBIAN_FRONTEND=noninteractive apt-get install --allow-unauthenticated -y $missing_pkgs
78 fi
79}
80
7c673cae
FG
81#######################################################################
82
83function control_osd() {
84 local action=$1
85 local id=$2
86
11fdf7f2 87 sudo systemctl $action ceph-osd@$id
7c673cae 88
7c673cae
FG
89 return 0
90}
91
92#######################################################################
93
94function pool_read_write() {
95 local size=${1:-1}
96 local dir=/tmp
97 local timeout=360
98 local test_pool=test_pool
99
100 ceph osd pool delete $test_pool $test_pool --yes-i-really-really-mean-it || return 1
101 ceph osd pool create $test_pool 4 || return 1
f67539c2 102 ceph osd pool set $test_pool size $size --yes-i-really-mean-it || return 1
7c673cae 103 ceph osd pool set $test_pool min_size $size || return 1
c07f9fc5 104 ceph osd pool application enable $test_pool rados
7c673cae
FG
105
106 echo FOO > $dir/BAR
107 timeout $timeout rados --pool $test_pool put BAR $dir/BAR || return 1
108 timeout $timeout rados --pool $test_pool get BAR $dir/BAR.copy || return 1
109 diff $dir/BAR $dir/BAR.copy || return 1
110 ceph osd pool delete $test_pool $test_pool --yes-i-really-really-mean-it || return 1
111}
112
113#######################################################################
114
115set -x
116
117"$@"