Skip to content

Commit

Permalink
Added Exception handler for change_owner function
Browse files Browse the repository at this point in the history
bugzilla: 1658245
tendrl-bug-id: Tendrl#589

Signed-off-by: GowthamShanmugasundaram <gshanmug@redhat.com>
  • Loading branch information
GowthamShanmugam committed Jan 14, 2019
1 parent 3b903f8 commit ebf6c34
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions tendrl/monitoring_integration/upgrades/delete_dashboards.py
Expand Up @@ -79,12 +79,14 @@ def main():
print ("\n Allow apache to access graphite.db file \n")
utils.change_owner(
"/var/lib/graphite-web/graphite.db",
"apache",
"apache"
)
print ("\n Allow apache to log messages in graphite-web \n")
utils.change_owner(
"/var/log/graphite-web",
"apache",
"apache",
True
)
print ("\n Starting carbon-cache service \n")
Expand Down
18 changes: 13 additions & 5 deletions tendrl/monitoring_integration/upgrades/utils.py
Expand Up @@ -19,13 +19,21 @@ def remove_file(path):
try:
os.remove("/var/lib/graphite-web/graphite.db")
except OSError as ex:
print (ex)
print (
"\n Unable to remove graphiteDB. Error: %s \n" % ex
)


def change_owner(path, owner, recursive=False):
uid = pwd.getpwnam(owner).pw_uid
gid = grp.getgrnam(owner).gr_gid
_chown(path, uid, gid, recursive)
def change_owner(path, uname, gname, recursive=False):
try:
uid = pwd.getpwnam(uname).pw_uid
gid = grp.getgrnam(gname).gr_gid
_chown(path, uid, gid, recursive)
except KeyError as ex:
print (
"\n Unable to modify ownership of file/directory. "
"Error: %s \n" % ex
)


def _chown(path, uid, gid, recursive):
Expand Down

0 comments on commit ebf6c34

Please sign in to comment.