]> git.proxmox.com Git - ceph.git/blame - ceph/qa/tasks/cephfs/xfstests_dev.py
bump version to 18.2.2-pve1
[ceph.git] / ceph / qa / tasks / cephfs / xfstests_dev.py
CommitLineData
1e59de90
TL
1from io import StringIO
2from logging import getLogger
3from os import getcwd as os_getcwd
4from os.path import join
5from textwrap import dedent
6
7
9f95a23c 8from tasks.cephfs.cephfs_test_case import CephFSTestCase
1e59de90
TL
9from tasks.cephfs.fuse_mount import FuseMount
10from tasks.cephfs.kernel_mount import KernelMount
9f95a23c 11
1e59de90
TL
12
13log = getLogger(__name__)
9f95a23c
TL
14
15
16# TODO: add code to run non-ACL tests too.
9f95a23c 17# TODO: make xfstests-dev tests running without running `make install`.
9f95a23c
TL
18class XFSTestsDev(CephFSTestCase):
19
1e59de90
TL
20 RESULTS_DIR = "results"
21
9f95a23c 22 def setUp(self):
1911f103 23 super(XFSTestsDev, self).setUp()
1e59de90
TL
24 self.setup_xfsprogs_devs()
25 self.prepare_xfstests_devs()
9f95a23c 26
1e59de90
TL
27 def setup_xfsprogs_devs(self):
28 self.install_xfsprogs = False
29
30 def prepare_xfstests_devs(self):
31 # NOTE: To run a quick test with vstart_runner.py, enable next line
32 # and disable calls to get_repo(), install_deps(), and
33 # build_and_install() and also disable lines in tearDown() for repo
34 # deletion.
35 #self.xfstests_repo_path = '/path/to/xfstests-dev'
36
37 self.get_repos()
9f95a23c
TL
38 self.get_test_and_scratch_dirs_ready()
39 self.install_deps()
40 self.create_reqd_users()
41 self.write_local_config()
1e59de90
TL
42 self.write_ceph_exclude()
43 self.build_and_install()
44
45 def tearDown(self):
46 self.del_users_and_groups()
47 self.del_repos()
48 super(XFSTestsDev, self).tearDown()
49
50 def del_users_and_groups(self):
51 self.mount_a.client_remote.run(args=['sudo', 'userdel', '--force',
52 '--remove', 'fsgqa'],
53 omit_sudo=False, check_status=False)
54 self.mount_a.client_remote.run(args=['sudo', 'userdel', '--force',
55 '--remove', '123456-fsgqa'],
56 omit_sudo=False, check_status=False)
57 self.mount_a.client_remote.run(args=['sudo', 'groupdel', 'fsgqa'],
58 omit_sudo=False, check_status=False)
59
60 def del_repos(self):
61 self.save_results_dir()
62 self.mount_a.client_remote.run(args=f'sudo rm -rf {self.xfstests_repo_path}',
63 omit_sudo=False, check_status=False)
64
65 if self.install_xfsprogs:
66 self.mount_a.client_remote.run(args=f'sudo rm -rf {self.xfsprogs_repo_path}',
67 omit_sudo=False, check_status=False)
68
69 def save_results_dir(self):
70 """
71 When tests in xfstests-dev repo are executed, logs are created and
72 saved, under a directory named "results" that lies at the repo root.
73 In case a test from xfstests-dev repo fails, these logs will help find
74 the cause of the failure.
75
76 Since there's no option in teuthology to copy a directory lying at a
77 custom location in order to save it from teuthology test runner's tear
78 down, let's copy this directory to a standard location that teuthology
79 copies away before erasing all data on the test machine. The standard
80 location chosen in the case here is the Ceph log directory.
81
82 In case of vstart_runner.py, this methods does nothing.
83 """
84 # No need to save results dir in case of vstart_runner.py.
85 for x in ('LocalFuseMount', 'LocalKernelMount'):
86 if x in self.mount_a.__class__.__name__:
87 return
88
89 src = join(self.xfstests_repo_path, self.RESULTS_DIR)
90
91 if self.mount_a.run_shell(f'sudo stat {src}',
92 check_status=False, omit_sudo=False).returncode != 0:
93 log.info(f'xfstests-dev repo contains not directory named '
94 f'"{self.RESULTS_DIR}". repo location: {self.xfstests_repo_path}')
95 return
9f95a23c 96
1e59de90
TL
97 std_loc = '/var/log/ceph' # standard location
98 dst = join(std_loc, 'xfstests-dev-results')
99 self.mount_a.run_shell(f'sudo mkdir -p {dst}', omit_sudo=False)
100 self.mount_a.run_shell(f'sudo cp -r {src} {dst}', omit_sudo=False)
101 log.info(f'results dir from xfstests-dev has been saved; it was '
102 f'copied from {self.xfstests_repo_path} to {std_loc}.')
103
104 def build_and_install(self):
9f95a23c
TL
105 # NOTE: On teuthology machines it's necessary to run "make" as
106 # superuser since the repo is cloned somewhere in /tmp.
107 self.mount_a.client_remote.run(args=['sudo', 'make'],
1e59de90
TL
108 cwd=self.xfstests_repo_path, stdout=StringIO(),
109 stderr=StringIO())
9f95a23c 110 self.mount_a.client_remote.run(args=['sudo', 'make', 'install'],
1e59de90
TL
111 cwd=self.xfstests_repo_path, omit_sudo=False,
112 stdout=StringIO(), stderr=StringIO())
113
114 if self.install_xfsprogs:
115 self.mount_a.client_remote.run(args=['sudo', 'make'],
116 cwd=self.xfsprogs_repo_path,
117 stdout=StringIO(), stderr=StringIO())
118 self.mount_a.client_remote.run(args=['sudo', 'make', 'install'],
119 cwd=self.xfsprogs_repo_path, omit_sudo=False,
120 stdout=StringIO(), stderr=StringIO())
9f95a23c 121
1e59de90 122 def get_repos(self):
9f95a23c 123 """
1e59de90
TL
124 Clone xfstests_dev and xfsprogs-dev repositories. If already present,
125 update them. The xfsprogs-dev will be used to test the encrypt.
9f95a23c 126 """
9f95a23c
TL
127 # TODO: make sure that repo is not cloned for every test. it should
128 # happen only once.
39ae355f 129 remoteurl = 'https://git.ceph.com/xfstests-dev.git'
1e59de90 130 self.xfstests_repo_path = self.mount_a.client_remote.mkdtemp(suffix=
9f95a23c 131 'xfstests-dev')
39ae355f 132 self.mount_a.run_shell(['git', 'clone', remoteurl, '--depth', '1',
1e59de90
TL
133 self.xfstests_repo_path])
134
135 if self.install_xfsprogs:
136 remoteurl = 'https://git.ceph.com/xfsprogs-dev.git'
137 self.xfsprogs_repo_path = self.mount_a.client_remote.mkdtemp(suffix=
138 'xfsprogs-dev')
139 self.mount_a.run_shell(['git', 'clone', remoteurl, '--depth', '1',
140 self.xfsprogs_repo_path])
9f95a23c
TL
141
142 def get_admin_key(self):
143 import configparser
9f95a23c
TL
144
145 cp = configparser.ConfigParser()
f67539c2
TL
146 cp.read_string(self.fs.mon_manager.raw_cluster_cmd(
147 'auth', 'get-or-create', 'client.admin'))
9f95a23c
TL
148
149 return cp['client.admin']['key']
150
151 def get_test_and_scratch_dirs_ready(self):
152 """ "test" and "scratch" directories are directories inside Ceph FS.
153 And, test and scratch mounts are path on the local FS where "test"
154 and "scratch" directories would be mounted. Look at xfstests-dev
155 local.config's template inside this file to get some context.
156 """
9f95a23c
TL
157 self.test_dirname = 'test'
158 self.mount_a.run_shell(['mkdir', self.test_dirname])
159 # read var name as "test dir's mount path"
160 self.test_dirs_mount_path = self.mount_a.client_remote.mkdtemp(
161 suffix=self.test_dirname)
9f95a23c
TL
162
163 self.scratch_dirname = 'scratch'
164 self.mount_a.run_shell(['mkdir', self.scratch_dirname])
165 # read var name as "scratch dir's mount path"
166 self.scratch_dirs_mount_path = self.mount_a.client_remote.mkdtemp(
167 suffix=self.scratch_dirname)
9f95a23c
TL
168
169 def install_deps(self):
170 from teuthology.misc import get_system_type
171
172 distro, version = get_system_type(self.mount_a.client_remote,
173 distro=True, version=True)
174 distro = distro.lower()
175 major_ver_num = int(version.split('.')[0]) # only keep major release
176 # number
1e59de90 177 log.info(f'distro and version detected is "{distro}" and "{version}".')
9f95a23c
TL
178
179 # we keep fedora here so that right deps are installed when this test
180 # is run locally by a dev.
181 if distro in ('redhatenterpriseserver', 'redhatenterprise', 'fedora',
1e59de90 182 'centos', 'centosstream', 'rhel'):
9f95a23c
TL
183 deps = """acl attr automake bc dbench dump e2fsprogs fio \
184 gawk gcc indent libtool lvm2 make psmisc quota sed \
185 xfsdump xfsprogs \
186 libacl-devel libattr-devel libaio-devel libuuid-devel \
aee94f69 187 xfsprogs-devel btrfs-progs-devel python3 sqlite""".split()
1e59de90
TL
188
189 if self.install_xfsprogs:
aee94f69
TL
190 if distro == 'centosstream' and major_ver_num == 8:
191 deps += ['--enablerepo=powertools']
1e59de90
TL
192 deps += ['inih-devel', 'userspace-rcu-devel', 'libblkid-devel',
193 'gettext', 'libedit-devel', 'libattr-devel',
194 'device-mapper-devel', 'libicu-devel']
195
9f95a23c
TL
196 deps_old_distros = ['xfsprogs-qa-devel']
197
198 if distro != 'fedora' and major_ver_num > 7:
199 deps.remove('btrfs-progs-devel')
200
201 args = ['sudo', 'yum', 'install', '-y'] + deps + deps_old_distros
202 elif distro == 'ubuntu':
203 deps = """xfslibs-dev uuid-dev libtool-bin \
204 e2fsprogs automake gcc libuuid1 quota attr libattr1-dev make \
205 libacl1-dev libaio-dev xfsprogs libgdbm-dev gawk fio dbench \
206 uuid-runtime python sqlite3""".split()
207
1e59de90
TL
208 if self.install_xfsprogs:
209 deps += ['libinih-dev', 'liburcu-dev', 'libblkid-dev',
210 'gettext', 'libedit-dev', 'libattr1-dev',
211 'libdevmapper-dev', 'libicu-dev', 'pkg-config']
212
9f95a23c
TL
213 if major_ver_num >= 19:
214 deps[deps.index('python')] ='python2'
215 args = ['sudo', 'apt-get', 'install', '-y'] + deps
216 else:
217 raise RuntimeError('expected a yum based or a apt based system')
218
219 self.mount_a.client_remote.run(args=args, omit_sudo=False)
220
221 def create_reqd_users(self):
1e59de90 222 self.mount_a.client_remote.run(args=['sudo', 'useradd', '-m', 'fsgqa'],
9f95a23c
TL
223 omit_sudo=False, check_status=False)
224 self.mount_a.client_remote.run(args=['sudo', 'groupadd', 'fsgqa'],
225 omit_sudo=False, check_status=False)
1e59de90
TL
226 self.mount_a.client_remote.run(args=['sudo', 'useradd', 'fsgqa2'],
227 omit_sudo=False, check_status=False)
9f95a23c
TL
228 self.mount_a.client_remote.run(args=['sudo', 'useradd',
229 '123456-fsgqa'], omit_sudo=False,
230 check_status=False)
231
1e59de90
TL
232 def write_local_config(self, options=None):
233 if isinstance(self.mount_a, KernelMount):
234 conf_contents = self._gen_conf_for_kernel_mnt(options)
235 elif isinstance(self.mount_a, FuseMount):
236 conf_contents = self._gen_conf_for_fuse_mnt(options)
237
238 self.mount_a.client_remote.write_file(join(self.xfstests_repo_path,
239 'local.config'),
240 conf_contents, sudo=True)
241 log.info(f'local.config\'s contents -\n{conf_contents}')
9f95a23c 242
1e59de90
TL
243 def _gen_conf_for_kernel_mnt(self, options=None):
244 """
245 Generate local.config for CephFS kernel client.
246 """
247 _options = '' if not options else ',' + options
9f95a23c 248 mon_sock = self.fs.mon_manager.get_msgrv1_mon_socks()[0]
1e59de90
TL
249 test_dev = mon_sock + ':/' + self.test_dirname
250 scratch_dev = mon_sock + ':/' + self.scratch_dirname
9f95a23c 251
1e59de90 252 return dedent(f'''\
9f95a23c 253 export FSTYP=ceph
1e59de90
TL
254 export TEST_DEV={test_dev}
255 export TEST_DIR={self.test_dirs_mount_path}
256 export SCRATCH_DEV={scratch_dev}
257 export SCRATCH_MNT={self.scratch_dirs_mount_path}
258 export CEPHFS_MOUNT_OPTIONS="-o name=admin,secret={self.get_admin_key()}{_options}"
259 ''')
9f95a23c 260
1e59de90
TL
261 def _gen_conf_for_fuse_mnt(self, options=None):
262 """
263 Generate local.config for CephFS FUSE client.
264 """
265 mon_sock = self.fs.mon_manager.get_msgrv1_mon_socks()[0]
266 test_dev = 'ceph-fuse'
267 scratch_dev = ''
268 # XXX: Please note that ceph_fuse_bin_path is not ideally required
269 # because ceph-fuse binary ought to be present in one of the standard
270 # locations during teuthology tests. But then testing with
271 # vstart_runner.py will not work since ceph-fuse binary won't be
272 # present in a standard locations during these sessions. Thus, this
273 # workaround.
274 ceph_fuse_bin_path = 'ceph-fuse' # bin expected to be in env
275 if 'LocalFuseMount' in str(type(self.mount_a)): # for vstart_runner.py runs
276 ceph_fuse_bin_path = join(os_getcwd(), 'bin', 'ceph-fuse')
9f95a23c 277
1e59de90
TL
278 keyring_path = self.mount_a.client_remote.mktemp(
279 data=self.fs.mon_manager.get_keyring('client.admin')+'\n')
9f95a23c 280
1e59de90
TL
281 lastline = (f'export CEPHFS_MOUNT_OPTIONS="-m {mon_sock} -k '
282 f'{keyring_path} --client_mountpoint /{self.test_dirname}')
283 lastline += f'-o {options}"' if options else '"'
1911f103 284
1e59de90
TL
285 return dedent(f'''\
286 export FSTYP=ceph-fuse
287 export CEPH_FUSE_BIN_PATH={ceph_fuse_bin_path}
288 export TEST_DEV={test_dev} # without this tests won't get started
289 export TEST_DIR={self.test_dirs_mount_path}
290 export SCRATCH_DEV={scratch_dev}
291 export SCRATCH_MNT={self.scratch_dirs_mount_path}
292 {lastline}
293 ''')
294
295 def write_ceph_exclude(self):
296 # These tests will fail or take too much time and will
297 # make the test timedout, just skip them for now.
298 xfstests_exclude_contents = dedent('''\
299 {c}/001 {g}/003 {g}/020 {g}/075 {g}/317 {g}/538 {g}/531
300 ''').format(g="generic", c="ceph")
301
302 self.mount_a.client_remote.write_file(join(self.xfstests_repo_path, 'ceph.exclude'),
303 xfstests_exclude_contents, sudo=True)