Skip to content

Commit

Permalink
Improve logger
Browse files Browse the repository at this point in the history
  • Loading branch information
abhisharma404 committed Jun 22, 2019
1 parent 513efce commit 0062612
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
20 changes: 16 additions & 4 deletions securetea/lib/auto_server_patcher/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,22 @@ def install(self):
None
"""
for command in self.os_config_data["commands"]:
output, error = self.excecute_command(command)
msg = "Command: " + command + ": " + str(output) + \
", Error: " + str(error)
self.logger.log(
msg,
"Executing command: " + command,
logtype="info"
)
output, error = self.excecute_command(command)

if output:
msg = "Ouput: " + str(output)
self.logger.log(
msg,
logtype="info"
)

if error:
msg = "Error: " + str(output)
self.logger.log(
msg,
logtype="info"
)
8 changes: 8 additions & 0 deletions securetea/lib/auto_server_patcher/patcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,19 @@ def patch(self):
in_front = True # found in forward refrencing

if not in_front: # not in forward refrencing
self.logger.log(
"Old config line: " + line.strip("\n"),
logtype="info"
)
new_config_line = rep_text + sep + \
self.os_config_data[path]["config"][rep_text]
new_data.append(new_config_line)
config_added.append(rep_text)
flag = 1 # write the new line
self.logger.log(
"New config line: " + new_config_line,
logtype="info"
)

if flag == 0: # write the original line
new_data.append(line.strip(" ").strip("\n"))
Expand Down
4 changes: 2 additions & 2 deletions test/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def test_install(self, mck_ex_com, mck_open_json, mck_log, mck_utils):
}
# Create Installer object
self.installer = Installer()
mck_ex_com.return_value = ("output", "error")
mck_ex_com.return_value = ("output", "")
self.installer.install()
mck_log.assert_called_with('Command: command1: output, Error: error', logtype='info')
mck_log.assert_called_with('Ouput: output', logtype='info')

@patch.object(Installer, "open_json")
@patch("securetea.lib.auto_server_patcher.installer.open")
Expand Down

0 comments on commit 0062612

Please sign in to comment.