Skip to content

Commit

Permalink
Merge PR ceph#42075 into wip-pdonnell-testing-20210630.032050
Browse files Browse the repository at this point in the history
* refs/pull/42075/head:
	qa: avoid using sudo for regular test artifacts
	qa: convert mount calls to mount_wait
	qa: use run_shell_payload to avoid sudo
  • Loading branch information
batrick committed Jun 30, 2021
2 parents c9b4972 + 433b4b6 commit 3417ef0
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 102 deletions.
2 changes: 1 addition & 1 deletion qa/tasks/cephfs/caps_helper.py
Expand Up @@ -60,7 +60,7 @@ def conduct_pos_test_for_write_caps(self, filepaths, mounts):
self.assertEqual(data, contents1)

def conduct_neg_test_for_write_caps(self, filepaths, mounts):
cmdargs = ['echo', 'some random data', Raw('|'), 'sudo', 'tee']
cmdargs = ['echo', 'some random data', Raw('|'), 'tee']

for mount in mounts:
for path in filepaths:
Expand Down
2 changes: 1 addition & 1 deletion qa/tasks/cephfs/filesystem.py
Expand Up @@ -666,7 +666,7 @@ def run_client_payload(self, cmd):
from tasks.cephfs.fuse_mount import FuseMount
d = misc.get_testdir(self._ctx)
m = FuseMount(self._ctx, {}, d, "admin", self.client_remote, cephfs_name=self.name)
m.mount()
m.mount_wait()
m.run_shell_payload(cmd)
m.umount_wait(require_clean=True)

Expand Down
2 changes: 1 addition & 1 deletion qa/tasks/cephfs/fuse_mount.py
Expand Up @@ -459,7 +459,7 @@ def _find_admin_socket(client_name):
client_name="client.{0}".format(self.client_id),
mountpoint=self.mountpoint)

asok_path = self.run_python(pyscript)
asok_path = self.run_python(pyscript, sudo=True)
log.info("Found client admin socket at {0}".format(asok_path))
return asok_path

Expand Down
44 changes: 23 additions & 21 deletions qa/tasks/cephfs/mount.py
Expand Up @@ -12,7 +12,7 @@
from IPy import IP

from teuthology.contextutil import safe_while
from teuthology.misc import get_file, sudo_write_file
from teuthology.misc import get_file, write_file
from teuthology.orchestra import run
from teuthology.orchestra.run import CommandFailedError, ConnectionLostError, Raw

Expand Down Expand Up @@ -625,7 +625,7 @@ def create_files(self):
for suffix in self.test_files:
log.info("Creating file {0}".format(suffix))
self.client_remote.run(args=[
'sudo', 'touch', os.path.join(self.hostfs_mntpt, suffix)
'touch', os.path.join(self.hostfs_mntpt, suffix)
])

def test_create_file(self, filename='testfile', dirname=None, user=None,
Expand All @@ -639,7 +639,7 @@ def check_files(self):
for suffix in self.test_files:
log.info("Checking file {0}".format(suffix))
r = self.client_remote.run(args=[
'sudo', 'ls', os.path.join(self.hostfs_mntpt, suffix)
'ls', os.path.join(self.hostfs_mntpt, suffix)
], check_status=False)
if r.exitstatus != 0:
raise RuntimeError("Expected file {0} not found".format(suffix))
Expand All @@ -652,7 +652,7 @@ def write_file(self, path, data, perms=None):
if path.find(self.hostfs_mntpt) == -1:
path = os.path.join(self.hostfs_mntpt, path)

sudo_write_file(self.client_remote, path, data)
write_file(self.client_remote, path, data)

if perms:
self.run_shell(args=f'chmod {perms} {path}')
Expand All @@ -664,7 +664,7 @@ def read_file(self, path):
if path.find(self.hostfs_mntpt) == -1:
path = os.path.join(self.hostfs_mntpt, path)

return self.run_shell(args=['sudo', 'cat', path], omit_sudo=False).\
return self.run_shell(args=['cat', path]).\
stdout.getvalue().strip()

def create_destroy(self):
Expand All @@ -673,34 +673,36 @@ def create_destroy(self):
filename = "{0} {1}".format(datetime.datetime.now(), self.client_id)
log.debug("Creating test file {0}".format(filename))
self.client_remote.run(args=[
'sudo', 'touch', os.path.join(self.hostfs_mntpt, filename)
'touch', os.path.join(self.hostfs_mntpt, filename)
])
log.debug("Deleting test file {0}".format(filename))
self.client_remote.run(args=[
'sudo', 'rm', '-f', os.path.join(self.hostfs_mntpt, filename)
'rm', '-f', os.path.join(self.hostfs_mntpt, filename)
])

def _run_python(self, pyscript, py_version='python3'):
return self.client_remote.run(
args=['sudo', 'adjust-ulimits', 'daemon-helper', 'kill',
py_version, '-c', pyscript], wait=False, stdin=run.PIPE,
stdout=StringIO())
def _run_python(self, pyscript, py_version='python3', sudo=False):
args = []
if sudo:
args.append('sudo')
args += ['adjust-ulimits', 'daemon-helper', 'kill', py_version, '-c', pyscript]
return self.client_remote.run(args=args, wait=False, stdin=run.PIPE, stdout=StringIO())

def run_python(self, pyscript, py_version='python3'):
p = self._run_python(pyscript, py_version)
def run_python(self, pyscript, py_version='python3', sudo=False):
p = self._run_python(pyscript, py_version, sudo=sudo)
p.wait()
return p.stdout.getvalue().strip()

def run_shell(self, args, omit_sudo=True, timeout=900, **kwargs):
def run_shell(self, args, timeout=900, **kwargs):
args = args.split() if isinstance(args, str) else args
# XXX: all commands ran with CephFS mount as CWD must be executed with
# superuser privileges when tests are being run using teuthology.
if args[0] != 'sudo':
args.insert(0, 'sudo')
kwargs.pop('omit_sudo', False)
sudo = kwargs.pop('sudo', False)
cwd = kwargs.pop('cwd', self.mountpoint)
stdout = kwargs.pop('stdout', StringIO())
stderr = kwargs.pop('stderr', StringIO())

if sudo:
args.insert(0, 'sudo')

return self.client_remote.run(args=args, cwd=cwd, timeout=timeout, stdout=stdout, stderr=stderr, **kwargs)

def run_shell_payload(self, payload, **kwargs):
Expand Down Expand Up @@ -845,7 +847,7 @@ def wait_for_visible(self, basename="background_file", timeout=30):
i = 0
while i < timeout:
r = self.client_remote.run(args=[
'sudo', 'ls', os.path.join(self.hostfs_mntpt, basename)
'stat', os.path.join(self.hostfs_mntpt, basename)
], check_status=False)
if r.exitstatus == 0:
log.debug("File {0} became visible from {1} after {2}s".format(
Expand Down Expand Up @@ -943,7 +945,7 @@ def check_filelock(self, basename="background_file", do_flock=True):

log.info("check lock on file {0}".format(basename))
self.client_remote.run(args=[
'sudo', 'python3', '-c', pyscript
'python3', '-c', pyscript
])

def write_background(self, basename="background_file", loop=False):
Expand Down
2 changes: 1 addition & 1 deletion qa/tasks/cephfs/test_acls.py
Expand Up @@ -21,7 +21,7 @@ def test_acls(self):
elif isinstance(self.mount_a, KernelMount):
log.info('client is kernel mounted')

self.mount_a.client_remote.run(args=['sudo', './check',
self.mount_a.client_remote.run(args=['./check',
'generic/099'], cwd=self.repo_path, stdout=BytesIO(),
stderr=BytesIO(), timeout=30, check_status=True,
label='running tests for ACLs from xfstests-dev')
74 changes: 32 additions & 42 deletions qa/tasks/cephfs/test_cephfs_shell.py
Expand Up @@ -137,7 +137,7 @@ def run_cephfs_shell_script(self, script, mount_x=None,
scriptfile.write(script)
# copy script to the machine running cephfs-shell.
mount_x.client_remote.put_file(scriptpath, scriptpath)
mount_x.run_shell('chmod 755 ' + scriptpath)
mount_x.run_shell_payload(f"chmod 755 {scriptpath}")

args = ["cephfs-shell", '-b', scriptpath]
if shell_conf_path:
Expand Down Expand Up @@ -321,8 +321,7 @@ def test_without_target_dir(self):
size = i + 1
ofarg = 'of=' + path.join(tempdir, file_)
bsarg = 'bs=' + str(size) + 'M'
self.mount_a.run_shell(['dd', 'if=/dev/urandom', ofarg, bsarg,
'count=1'])
self.mount_a.run_shell_payload(f"dd if=/dev/urandom {ofarg} {bsarg} count=1")

self.run_cephfs_shell_cmd('put ' + tempdir)
for file_ in files:
Expand All @@ -332,16 +331,15 @@ def test_without_target_dir(self):
self.mount_a.stat(path.join(self.mount_a.mountpoint,
tempdirname, file_))

self.mount_a.run_shell(['rm', '-rf', tempdir])
self.mount_a.run_shell_payload(f"rm -rf {tempdir}")

self.run_cephfs_shell_cmd('get ' + tempdirname)
pwd = self.get_cephfs_shell_cmd_output('!pwd')
for file_ in files:
if file_ == tempdirname:
self.mount_a.run_shell('stat ' + path.join(pwd, file_))
self.mount_a.run_shell_payload(f"stat {path.join(pwd, file_)}")
else:
self.mount_a.run_shell('stat ' + path.join(pwd, tempdirname,
file_))
self.mount_a.run_shell_payload(f"stat {path.join(pwd, tempdirname, file_)}")

def test_get_with_target_name(self):
"""
Expand Down Expand Up @@ -488,7 +486,7 @@ def test_cd_with_no_args(self):
to root directory.
"""
path = 'dir1/dir2/dir3'
self.mount_a.run_shell('mkdir -p ' + path)
self.mount_a.run_shell_payload(f"mkdir -p {path}")
expected_cwd = '/'

script = 'cd {}\ncd\ncwd\n'.format(path)
Expand All @@ -501,7 +499,7 @@ def test_cd_with_args(self):
to the path passed in the argument.
"""
path = 'dir1/dir2/dir3'
self.mount_a.run_shell('mkdir -p ' + path)
self.mount_a.run_shell_payload(f"mkdir -p {path}")
expected_cwd = '/dir1/dir2/dir3'

script = 'cd {}\ncwd\n'.format(path)
Expand All @@ -514,8 +512,7 @@ class TestDU(TestCephFSShell):
def test_du_works_for_regfiles(self):
regfilename = 'some_regfile'
regfile_abspath = path.join(self.mount_a.mountpoint, regfilename)
self.mount_a.client_remote.write_file(regfile_abspath,
'somedata', sudo=True)
self.mount_a.client_remote.write_file(regfile_abspath, 'somedata')

size = humansize(self.mount_a.stat(regfile_abspath)['st_size'])
expected_output = r'{}{}{}'.format(size, " +", regfilename)
Expand All @@ -528,9 +525,8 @@ def test_du_works_for_non_empty_dirs(self):
dir_abspath = path.join(self.mount_a.mountpoint, dirname)
regfilename = 'some_regfile'
regfile_abspath = path.join(dir_abspath, regfilename)
self.mount_a.run_shell('mkdir ' + dir_abspath)
self.mount_a.client_remote.write_file(regfile_abspath,
'somedata', sudo=True)
self.mount_a.run_shell_payload(f"mkdir {dir_abspath}")
self.mount_a.client_remote.write_file(regfile_abspath, 'somedata')

# XXX: we stat `regfile_abspath` here because ceph du reports a non-empty
# directory's size as sum of sizes of all files under it.
Expand All @@ -544,7 +540,7 @@ def test_du_works_for_non_empty_dirs(self):
def test_du_works_for_empty_dirs(self):
dirname = 'some_directory'
dir_abspath = path.join(self.mount_a.mountpoint, dirname)
self.mount_a.run_shell('mkdir ' + dir_abspath)
self.mount_a.run_shell_payload(f"mkdir {dir_abspath}")

size = humansize(self.mount_a.stat(dir_abspath)['st_size'])
expected_output = r'{}{}{}'.format(size, " +", dirname)
Expand All @@ -555,12 +551,10 @@ def test_du_works_for_empty_dirs(self):
def test_du_works_for_hardlinks(self):
regfilename = 'some_regfile'
regfile_abspath = path.join(self.mount_a.mountpoint, regfilename)
self.mount_a.client_remote.write_file(regfile_abspath,
'somedata', sudo=True)
self.mount_a.client_remote.write_file(regfile_abspath, 'somedata')
hlinkname = 'some_hardlink'
hlink_abspath = path.join(self.mount_a.mountpoint, hlinkname)
self.mount_a.run_shell(['sudo', 'ln', regfile_abspath,
hlink_abspath], omit_sudo=False)
self.mount_a.run_shell_payload(f"ln {regfile_abspath} {hlink_abspath}")

size = humansize(self.mount_a.stat(hlink_abspath)['st_size'])
expected_output = r'{}{}{}'.format(size, " +", hlinkname)
Expand All @@ -571,11 +565,10 @@ def test_du_works_for_hardlinks(self):
def test_du_works_for_softlinks_to_files(self):
regfilename = 'some_regfile'
regfile_abspath = path.join(self.mount_a.mountpoint, regfilename)
self.mount_a.client_remote.write_file(regfile_abspath,
'somedata', sudo=True)
self.mount_a.client_remote.write_file(regfile_abspath, 'somedata')
slinkname = 'some_softlink'
slink_abspath = path.join(self.mount_a.mountpoint, slinkname)
self.mount_a.run_shell(['ln', '-s', regfile_abspath, slink_abspath])
self.mount_a.run_shell_payload(f"ln -s {regfile_abspath} {slink_abspath}")

size = humansize(self.mount_a.lstat(slink_abspath)['st_size'])
expected_output = r'{}{}{}'.format((size), " +", slinkname)
Expand All @@ -586,10 +579,10 @@ def test_du_works_for_softlinks_to_files(self):
def test_du_works_for_softlinks_to_dirs(self):
dirname = 'some_directory'
dir_abspath = path.join(self.mount_a.mountpoint, dirname)
self.mount_a.run_shell('mkdir ' + dir_abspath)
self.mount_a.run_shell_payload(f"mkdir {dir_abspath}")
slinkname = 'some_softlink'
slink_abspath = path.join(self.mount_a.mountpoint, slinkname)
self.mount_a.run_shell(['ln', '-s', dir_abspath, slink_abspath])
self.mount_a.run_shell_payload(f"ln -s {dir_abspath} {slink_abspath}")

size = humansize(self.mount_a.lstat(slink_abspath)['st_size'])
expected_output = r'{}{}{}'.format(size, " +", slinkname)
Expand All @@ -612,25 +605,23 @@ def _setup_files(self, return_path_to_files=False, path_prefix='./'):
slink_abspath = path.join(self.mount_a.mountpoint, slinkname)
slink2_abspath = path.join(self.mount_a.mountpoint, slink2name)

self.mount_a.run_shell('mkdir ' + dir_abspath)
self.mount_a.run_shell('touch ' + regfile_abspath)
self.mount_a.run_shell(['ln', regfile_abspath, hlink_abspath])
self.mount_a.run_shell(['ln', '-s', regfile_abspath, slink_abspath])
self.mount_a.run_shell(['ln', '-s', dir_abspath, slink2_abspath])
self.mount_a.run_shell_payload(f"mkdir {dir_abspath}")
self.mount_a.run_shell_payload(f"touch {regfile_abspath}")
self.mount_a.run_shell_payload(f"ln {regfile_abspath} {hlink_abspath}")
self.mount_a.run_shell_payload(f"ln -s {regfile_abspath} {slink_abspath}")
self.mount_a.run_shell_payload(f"ln -s {dir_abspath} {slink2_abspath}")

dir2_name = 'dir2'
dir21_name = 'dir21'
regfile121_name = 'regfile121'
dir2_abspath = path.join(self.mount_a.mountpoint, dir2_name)
dir21_abspath = path.join(dir2_abspath, dir21_name)
regfile121_abspath = path.join(dir21_abspath, regfile121_name)
self.mount_a.run_shell('mkdir -p ' + dir21_abspath)
self.mount_a.run_shell('touch ' + regfile121_abspath)
self.mount_a.run_shell_payload(f"mkdir -p {dir21_abspath}")
self.mount_a.run_shell_payload(f"touch {regfile121_abspath}")

self.mount_a.client_remote.write_file(regfile_abspath,
'somedata', sudo=True)
self.mount_a.client_remote.write_file(regfile121_abspath,
'somemoredata', sudo=True)
self.mount_a.client_remote.write_file(regfile_abspath, 'somedata')
self.mount_a.client_remote.write_file(regfile121_abspath, 'somemoredata')

# TODO: is there a way to trigger/force update ceph.dir.rbytes?
# wait so that attr ceph.dir.rbytes gets a chance to be updated.
Expand Down Expand Up @@ -731,7 +722,7 @@ def test_df_with_no_args(self):

def test_df_for_valid_directory(self):
dir_name = 'dir1'
mount_output = self.mount_a.run_shell('mkdir ' + dir_name)
mount_output = self.mount_a.run_shell_payload(f"mkdir {dir_name}")
log.info("cephfs-shell mount output:\n{}".format(mount_output))
self.validate_df(dir_name)

Expand Down Expand Up @@ -799,10 +790,10 @@ def test_set_invalid_values(self):
def test_exceed_file_limit(self):
self.test_set()
dir_abspath = path.join(self.mount_a.mountpoint, self.dir_name)
self.mount_a.run_shell('touch '+dir_abspath+'/file1')
self.mount_a.run_shell_payload(f"touch {dir_abspath}/file1")
file2 = path.join(dir_abspath, "file2")
try:
self.mount_a.run_shell('touch '+file2)
self.mount_a.run_shell_payload(f"touch {file2}")
raise Exception("Something went wrong!! File creation should have failed")
except CommandFailedError:
# Test should pass as file quota set to 2
Expand All @@ -818,8 +809,7 @@ def test_exceed_write_limit(self):
file_abspath = path.join(dir_abspath, filename)
try:
# Write should fail as bytes quota is set to 6
self.mount_a.client_remote.write_file(file_abspath,
'Disk raise Exception', sudo=True)
self.mount_a.client_remote.write_file(file_abspath, 'Disk raise Exception')
raise Exception("Write should have failed")
except CommandFailedError:
# Test should pass only when write command fails
Expand Down Expand Up @@ -924,8 +914,8 @@ def test_ls_H_prints_human_readable_file_size(self):

for (file_size, file_name) in zip(file_sizes, file_names):
temp_file = self.mount_a.client_remote.mktemp(file_name)
self.mount_a.run_shell(f"fallocate -l {file_size} {temp_file}")
self.mount_a.run_shell(f'mv {temp_file} ./')
self.mount_a.run_shell_payload(f"fallocate -l {file_size} {temp_file}")
self.mount_a.run_shell_payload(f'mv {temp_file} ./')

ls_H_output = self.get_cephfs_shell_cmd_output(['ls', '-lH'])

Expand Down
11 changes: 5 additions & 6 deletions qa/tasks/cephfs/test_client_recovery.py
Expand Up @@ -510,9 +510,8 @@ def test_stale_renew(self):
self.assertEqual(current_readdirs, initial_readdirs);

mount_b_gid = self.mount_b.get_global_id()
mount_b_pid = self.mount_b.get_client_pid()
# stop ceph-fuse process of mount_b
self.mount_b.client_remote.run(args=["sudo", "kill", "-STOP", mount_b_pid])
self.mount_b.suspend_netns()

self.assert_session_state(mount_b_gid, "open")
time.sleep(session_timeout * 1.5) # Long enough for MDS to consider session stale
Expand All @@ -521,7 +520,7 @@ def test_stale_renew(self):
self.assert_session_state(mount_b_gid, "stale")

# resume ceph-fuse process of mount_b
self.mount_b.client_remote.run(args=["sudo", "kill", "-CONT", mount_b_pid])
self.mount_b.resume_netns()
# Is the new file visible from mount_b? (caps become invalid after session stale)
self.mount_b.run_shell(["ls", "testdir/file2"])

Expand Down Expand Up @@ -617,10 +616,10 @@ def test_reconnect_after_blocklisted(self):
self.mount_a.umount_wait()

if isinstance(self.mount_a, FuseMount):
self.mount_a.mount(mntopts=['--client_reconnect_stale=1', '--fuse_disable_pagecache=1'])
self.mount_a.mount_wait(mntopts=['--client_reconnect_stale=1', '--fuse_disable_pagecache=1'])
else:
try:
self.mount_a.mount(mntopts=['recover_session=clean'])
self.mount_a.mount_wait(mntopts=['recover_session=clean'])
except CommandFailedError:
self.mount_a.kill_cleanup()
self.skipTest("Not implemented in current kernel")
Expand Down Expand Up @@ -684,7 +683,7 @@ def test_reconnect_after_blocklisted(self):
raise RuntimeError("read() failed to raise error")
""").format(path=path)
rproc = self.mount_a.client_remote.run(
args=['sudo', 'python3', '-c', pyscript],
args=['python3', '-c', pyscript],
wait=False, stdin=run.PIPE, stdout=run.PIPE)

rproc.stdout.readline()
Expand Down

0 comments on commit 3417ef0

Please sign in to comment.