Merge ~peter-sabaini/charm-hw-health:fix-removing-sudoer into ~nagios-charmers/charm-hw-health:master

Proposed by Peter Sabaini
Status: Merged
Approved by: Jeremy Lounder
Approved revision: 89207ab196619b95f37b731989460a04be68cc14
Merged at revision: 81841995fee9aa2fc2fbde8471fae717bc4dda9c
Proposed branch: ~peter-sabaini/charm-hw-health:fix-removing-sudoer
Merge into: ~nagios-charmers/charm-hw-health:master
Diff against target: 40 lines (+10/-5)
1 file modified
src/lib/hwhealth/tools.py (+10/-5)
Reviewer Review Type Date Requested Status
Jeremy Lounder (community) Approve
Alvaro Uria (community) Approve
Review via email: mp+376195@code.launchpad.net

Commit message

Fix file not found upon removal

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Alvaro Uria (aluria) wrote :

lgtm

review: Approve
Revision history for this message
Jeremy Lounder (jldev) :
review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 81841995fee9aa2fc2fbde8471fae717bc4dda9c

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/lib/hwhealth/tools.py b/src/lib/hwhealth/tools.py
2index fd6692d..0bf0121 100644
3--- a/src/lib/hwhealth/tools.py
4+++ b/src/lib/hwhealth/tools.py
5@@ -9,6 +9,7 @@ import shlex
6 import shutil
7 import subprocess
8
9+from pathlib import Path
10 from zipfile import ZipFile, BadZipFile
11 from tempfile import TemporaryDirectory
12
13@@ -209,9 +210,11 @@ class Tool():
14 )
15
16 def _remove_sudoer(self):
17- sudoer_path = os.path.join(self.SUDOERS_DIR, self._sudoer_file)
18- os.remove(sudoer_path)
19- hookenv.log('deleted sudoer file'.format(sudoer_path), hookenv.DEBUG)
20+ sudoer_path = Path(self.SUDOERS_DIR) / self._sudoer_file
21+ if not sudoer_path.exists():
22+ return
23+ sudoer_path.unlink()
24+ hookenv.log('deleted sudoer file: {}'.format(sudoer_path), hookenv.DEBUG)
25
26
27 class VendorTool(Tool):
28@@ -283,8 +286,10 @@ class VendorTool(Tool):
29 'error': error})
30
31 def _remove_binary(self):
32- binary_path = os.path.join(self.TOOLS_DIR, self._shortname)
33- os.remove(binary_path)
34+ binary_path = Path(self.TOOLS_DIR) / self._shortname
35+ if not binary_path.exists():
36+ return
37+ binary_path.unlink()
38 hookenv.log(
39 'Removed binary tool {}'.format(binary_path),
40 hookenv.DEBUG

Subscribers

People subscribed via source and target branches