From: Alfredo Deza Date: Wed, 2 May 2018 23:15:10 +0000 (-0400) Subject: ceph-volume util.system capture file contents X-Git-Tag: v13.2.1~130^2~10 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=c97f1345a05c7553525d038a0872e332ff4d516a;p=ceph.git ceph-volume util.system capture file contents Signed-off-by: Alfredo Deza (cherry picked from commit 39792573dabac3b85a41760c965b60746ca1f059) --- diff --git a/src/ceph-volume/ceph_volume/util/system.py b/src/ceph-volume/ceph_volume/util/system.py index 0ba46d362766..ab5b2c7bba39 100644 --- a/src/ceph-volume/ceph_volume/util/system.py +++ b/src/ceph-volume/ceph_volume/util/system.py @@ -65,6 +65,19 @@ def get_ceph_user_ids(): return user[2], user[3] +def get_file_contents(path, default=''): + contents = default + if not os.path.exists(path): + return contents + try: + with open(path, 'r') as open_file: + contents = open_file.read().strip() + except Exception: + logger.exception('Failed to read contents from: %s' % path) + + return contents + + def mkdir_p(path, chown=True): """ A `mkdir -p` that defaults to chown the path to the ceph user