Skip to content

Commit e8798f2

Browse files
GowthamShanmugamshtripat
authored andcommitted
Added Exception handler for change_owner function
bugzilla: 1658245 tendrl-bug-id: #589 Signed-off-by: GowthamShanmugasundaram <[email protected]>
1 parent 0371a72 commit e8798f2

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

tendrl/monitoring_integration/upgrades/delete_dashboards.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ def main():
7979
print ("\n Allow apache to access graphite.db file \n")
8080
utils.change_owner(
8181
"/var/lib/graphite-web/graphite.db",
82+
"apache",
8283
"apache"
8384
)
8485
print ("\n Allow apache to log messages in graphite-web \n")
8586
utils.change_owner(
8687
"/var/log/graphite-web",
8788
"apache",
89+
"apache",
8890
True
8991
)
9092
print ("\n Starting carbon-cache service \n")

tendrl/monitoring_integration/upgrades/utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,21 @@ def remove_file(path):
1919
try:
2020
os.remove("/var/lib/graphite-web/graphite.db")
2121
except OSError as ex:
22-
print (ex)
22+
print (
23+
"\n Unable to remove graphiteDB. Error: %s \n" % ex
24+
)
2325

2426

25-
def change_owner(path, owner, recursive=False):
26-
uid = pwd.getpwnam(owner).pw_uid
27-
gid = grp.getgrnam(owner).gr_gid
28-
_chown(path, uid, gid, recursive)
27+
def change_owner(path, uname, gname, recursive=False):
28+
try:
29+
uid = pwd.getpwnam(uname).pw_uid
30+
gid = grp.getgrnam(gname).gr_gid
31+
_chown(path, uid, gid, recursive)
32+
except KeyError as ex:
33+
print (
34+
"\n Unable to modify ownership of file/directory. "
35+
"Error: %s \n" % ex
36+
)
2937

3038

3139
def _chown(path, uid, gid, recursive):

0 commit comments

Comments
 (0)