Skip to content

Commit a8bb7b1

Browse files
authored
SW-1014 fix missing netconnectd logrotate (mrbeam#1579)
* fix missing netconnectd logrotate * added additional unittests to check if all commands did run * fixed restart command for legacy image
1 parent 7fe0387 commit a8bb7b1

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

octoprint_mrbeam/migration/Mig003.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def _run(self):
3131
"mount_manager",
3232
"mrb_check",
3333
"mrbeam_ledstrips",
34+
"netconnectd",
3435
]
3536
for logrotate in logrotates:
3637
self._logger.debug("enable logrotate of " + logrotate)
@@ -43,7 +44,9 @@ def _run(self):
4344
self._logger.debug(
4445
"restarting logrotate in order for the changed config to take effect"
4546
)
46-
self.exec_cmd("sudo logrotate /etc/logrotate.conf")
47+
48+
# needs to be optional for legacy image, as this is returning 1 instead of 0
49+
self.exec_cmd("sudo logrotate /etc/logrotate.conf", optional=True)
4750
super(Mig003EnableLogrotateBuster, self)._run()
4851

4952
def _rollback(self):

octoprint_mrbeam/migration/migration_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ def exec_cmd(self, command, optional=False):
218218
if optional and not command_success:
219219
self._logger.warn("optional command failed - cmd: {}".format(command))
220220
else:
221-
raise MigrationException("error during migration for cmd:", command)
221+
raise MigrationException(
222+
"error during migration for cmd: {} - return: {}".format(
223+
command, command_success
224+
)
225+
)
222226

223227
@staticmethod
224228
def execute_restart(restart):

octoprint_mrbeam/util/cmd_exec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ def exec_cmd(cmd, log=True, shell=True, loglvl=DEBUG):
1919
try:
2020
code = subprocess.call(cmd, shell=shell)
2121
except Exception as e:
22-
_logger.debug(
22+
_logger.error(
2323
"Failed to execute command '%s', return code: %s, Exception: %s",
2424
cmd,
2525
code,
2626
e,
2727
)
2828
return None
2929
if code != 0 and log:
30-
_logger.info("cmd= '%s', return code: '%s'", code)
30+
_logger.error("cmd= '{}', return code: {}".format(cmd, code))
3131
return code == 0
3232

3333

tests/migrations/test-migration-Mig003.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import os
2+
3+
from mock import patch
4+
15
from octoprint_mrbeam.migration import Mig003EnableLogrotateBuster
26
import unittest
37

@@ -27,3 +31,33 @@ def test_beamos_versions(self):
2731

2832
def test_migration_id(self):
2933
self.assertEqual(self.m003.id, "003")
34+
35+
@patch.object(
36+
Mig003EnableLogrotateBuster,
37+
"exec_cmd",
38+
)
39+
def test_commands_executed(self, exec_cmd_mock):
40+
self.m003.run()
41+
exec_cmd_mock.assert_any_call(
42+
"sudo rm /etc/logrotate.d/iobeam.logrotate", optional=True
43+
)
44+
logrotates = [
45+
"analytics",
46+
"iobeam",
47+
"mount_manager",
48+
"mrb_check",
49+
"mrbeam_ledstrips",
50+
"netconnectd",
51+
]
52+
for logrotate in logrotates:
53+
dst = os.path.join("/etc/logrotate.d/" + logrotate)
54+
src = os.path.join(
55+
__package_path__,
56+
"files/migrate_logrotate",
57+
logrotate,
58+
)
59+
exec_cmd_mock.assert_any_call(
60+
"sudo cp {src} {dst}".format(src=src, dst=dst)
61+
)
62+
63+
exec_cmd_mock.ssert_any_call("sudo logrotate /etc/logrotate.conf")

0 commit comments

Comments
 (0)