summaryrefslogtreecommitdiffstats
path: root/qa/workunits/fs/upgrade/volume_client
blob: b3b6dd3e1cfe4fe72196d78c13511a4859353522 (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
#!/bin/bash

set -ex

PYTHON="python3"

function run_payload {
    local payload="$1"
    sudo "$PYTHON" <<EOF
from __future__ import print_function
from ceph_volume_client import CephFSVolumeClient, VolumePath
from sys import version_info as sys_version_info
from rados import OSError as rados_OSError
import logging
log = logging.getLogger("ceph_volume_client")
log.addHandler(logging.StreamHandler())
log.setLevel(logging.DEBUG)
vc = CephFSVolumeClient("manila", "/etc/ceph/ceph.conf", "ceph")
vc.connect()
${payload}
vc.disconnect()
EOF
}

function import_key {
  local client="$1"
  if [ -n "$2" ]; then
    local keyring="$2"
  else
    local keyring="/etc/ceph/ceph.client.${client}.keyring"
  fi
  local T=$(mktemp)
  tee "$T" >&2
  sudo touch -- "$keyring"
  sudo ceph-authtool "$keyring" --import-keyring "$T"
  rm -f -- "$T"
}

function conf_keys {
  local client="$1"
  ls /etc/ceph >&2
  ceph auth get-or-create "client.manila" mds 'allow *' osd 'allow rw' mon 'allow *' | import_key "$client" /etc/ceph/ceph.keyring
}

function create_data_isolated {
  local PAYLOAD='
vp = VolumePath(None, "vol_isolated")
vc.create_volume(vp, (1<<33), data_isolated=True)
auth_result = vc.authorize(vp, "vol_data_isolated", tenant_id="test")
print("[client.vol_data_isolated]\n\tkey = ", auth_result["auth_key"])
'

  run_payload "$PAYLOAD" | import_key "vol_data_isolated"
}

function create_default {
  local PAYLOAD='
vp = VolumePath(None, "vol_default")
vc.create_volume(vp, (1<<33))
auth_result = vc.authorize(vp, "vol_default", tenant_id="test")
print("[client.vol_default]\n\tkey = ", auth_result["auth_key"])
'
  run_payload "$PAYLOAD" | import_key "vol_default"
}

function create {
  create_data_isolated
  create_default
}

function populate {
  pwd
  df -h .
  ls -l
  cp -a /usr/bin .
}

function verify_data_isolated {
  ceph fs subvolume getpath cephfs vol_isolated
  stat bin
  ls bin | tail
}

function verify_default {
  ceph fs subvolume getpath cephfs vol_default
  stat bin
  ls bin | tail
}

function verify {
  diff <(ceph fs subvolume ls cephfs | jq -cS 'sort_by(.name)' | tee /dev/stderr) <(printf '[{"name":"vol_isolated"},{"name":"vol_default"}]' | jq -cS 'sort_by(.name)')
  verify_data_isolated
  verify_default
}

function main {
  if [ "$1" = create ]; then
    conf_keys
    create
  elif [ "$1" = populate ]; then
    populate
  elif [ "$1" = verify ]; then
    # verify (sub)volumes still exist and are configured correctly
    verify
  else
    exit 1
  fi
}

main "$ACTION"