From 3ca932488c16cd7476dc34bd5f7eda5bb387afd4 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Wed, 2 May 2018 19:15:10 -0400 Subject: [PATCH] ceph-volume util.system capture file contents Signed-off-by: Alfredo Deza (cherry picked from commit 39792573dabac3b85a41760c965b60746ca1f059) --- src/ceph-volume/ceph_volume/util/system.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/ceph-volume/ceph_volume/util/system.py b/src/ceph-volume/ceph_volume/util/system.py index 928c88934ad..b637f023a44 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 -- 2.47.3