]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
qa/tasks/ceph: create a log file before redirecting to it
authorKefu Chai <kchai@redhat.com>
Fri, 21 Aug 2020 12:22:23 +0000 (20:22 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 22 Aug 2020 03:33:12 +0000 (11:33 +0800)
as it is shell who interprets ">>" and redirect the stderr to given
file, but the shell process is launched by ubuntu:ububunt without using
sudo, so the command fails with "Permission denied" failure. to address
this issue, in this change, a file with proper priviledges is created
beforehand using `install`, so shell is able to write to it.

also, instead of creating this file in `maybe_redirect_stderr()`, it
returns the command to create the log file.

Signed-off-by: Kefu Chai <kchai@redhat.com>
qa/tasks/ceph.py

index 692affd7e561c651b72c64be79bf3c6605865f0f..b78081f7aa4cd0daef36e7443bff94ce3445ac8c 100644 (file)
@@ -539,13 +539,15 @@ def create_simple_monmap(ctx, remote, conf, mons,
     return fsid
 
 
-def maybe_redirect_stderr(args, config, cluster, type_, id_):
+def maybe_redirect_stderr(config, type_, args, log_path):
     if type_ == 'osd' and \
        config.get('flavor', 'default') == 'crimson':
-        log_path = f'/var/log/ceph/{cluster}-{type_}.{id_}.log'
-        return args + [run.Raw('2>>'), log_path]
+        # teuthworker uses ubuntu:ubuntu to access the test nodes
+        create_log_cmd = \
+            f'sudo install -b -o ubuntu -g ubuntu /dev/null {log_path}'
+        return create_log_cmd, args + [run.Raw('2>>'), log_path]
     else:
-        return args
+        return None, args
 
 
 @contextlib.contextmanager
@@ -923,9 +925,12 @@ def cluster(ctx, config):
                         '--mkkey',
                         '-i', id_,
                         '--monmap', monmap_path]
-                remote.run(
-                    args=maybe_redirect_stderr(args, config,
-                                               cluster_name, 'osd', id_))
+                log_path = f'/var/log/ceph/{cluster_name}-osd.{id_}.log'
+                create_log_cmd, args = \
+                    maybe_redirect_stderr(config, 'osd', args, log_path)
+                if create_log_cmd:
+                    remote.sh(create_log_cmd)
+                remote.run(args=args)
             except run.CommandFailedError:
                 # try without --no-mon-config.. this may be an upgrade test
                 remote.run(
@@ -1377,10 +1382,11 @@ def run_daemon(ctx, config, type_):
                                                        valgrind_args)
 
             run_cmd.extend(run_cmd_tail)
-            run_cmd = maybe_redirect_stderr(run_cmd,
-                                            config,
-                                            cluster_name, type_, id_)
-
+            log_path = f'/var/log/ceph/{cluster_name}-{type_}.{id_}.log'
+            create_log_cmd, run_cmd = \
+                maybe_redirect_stderr(config, type_, run_cmd, log_path)
+            if create_log_cmd:
+                remote.sh(create_log_cmd)
             # always register mgr; don't necessarily start
             ctx.daemons.register_daemon(
                 remote, type_, id_,