File tree Expand file tree Collapse file tree 10 files changed +108
-9
lines changed Expand file tree Collapse file tree 10 files changed +108
-9
lines changed Original file line number Diff line number Diff line change 33
44/home/pi/.octoprint/analytics/analytics_log.json {
55 size 100M
6- rotate 2
6+ rotate 3
77 compress
88 delaycompress
99 missingok
1010 notifempty
11+ dateext
12+ dateformat .%Y-%m-%d
1113}
Original file line number Diff line number Diff line change 11/var/log/iobeam.log {
22 size 2M
3- rotate 4
3+ rotate 3
44 compress
55 delaycompress
66 missingok
77 notifempty
88 copytruncate
9+ dateext
10+ dateformat .%Y-%m-%d
911}
Original file line number Diff line number Diff line change 11/var/log/mount_manager.log {
22 size 2M
3- rotate 2
3+ rotate 3
44 compress
55 delaycompress
66 missingok
77 notifempty
88 copytruncate
99 create 644 root root
10+ dateext
11+ dateformat .%Y-%m-%d
1012}
Original file line number Diff line number Diff line change 11/var/log/mrb_check.log {
22 size 5M
3- rotate 4
3+ rotate 3
44 compress
55 delaycompress
66 missingok
77 notifempty
88 copytruncate
99 create 644 root root
10+ dateext
11+ dateformat .%Y-%m-%d
1012}
Original file line number Diff line number Diff line change 11/var/log/mrbeam_ledstrips.log {
22 size 2M
3- rotate 2
3+ rotate 3
44 compress
55 delaycompress
66 missingok
77 notifempty
88 copytruncate
99 create 644 root root
10+ dateext
11+ dateformat .%Y-%m-%d
1012}
Original file line number Diff line number Diff line change 11/var/log/netconnectd.log {
22 size 2M
3- rotate 2
3+ rotate 3
44 compress
55 delaycompress
66 missingok
77 notifempty
88 copytruncate
9+ dateext
10+ dateformat .%Y-%m-%d
911}
Original file line number Diff line number Diff line change 1+ import os
2+
3+ from octoprint_mrbeam .migration .migration_base import (
4+ MigrationBaseClass ,
5+ )
6+
7+
8+ class Mig003EnableLogrotateBuster (MigrationBaseClass ):
9+ """
10+ This migration should add logrotate for the buster image and change the lorotate for the legacy image
11+ """
12+
13+ MIGRATE_LOGROTATE_FOLDER = "files/migrate_logrotate/"
14+ BEAMOS_VERSION_LOW = "0.14.0"
15+ BEAMOS_VERSION_HIGH = "0.18.2"
16+
17+ def __init__ (self , plugin ):
18+ super (Mig003EnableLogrotateBuster , self ).__init__ (plugin )
19+
20+ @property
21+ def id (self ):
22+ return "003"
23+
24+ def _run (self ):
25+ self ._logger .debug ("delete wrong iobeam logrotate" )
26+ self .exec_cmd ("sudo rm /etc/logrotate.d/iobeam.logrotate" , optional = True )
27+
28+ logrotates = [
29+ "analytics" ,
30+ "iobeam" ,
31+ "mount_manager" ,
32+ "mrb_check" ,
33+ "mrbeam_ledstrips" ,
34+ ]
35+ for logrotate in logrotates :
36+ self ._logger .debug ("enable logrotate of " + logrotate )
37+ src = os .path .join (
38+ __package_path__ , self .MIGRATE_LOGROTATE_FOLDER , logrotate
39+ )
40+ dst = os .path .join ("/etc/logrotate.d/" + logrotate )
41+ self .exec_cmd ("sudo cp {src} {dst}" .format (src = src , dst = dst ))
42+
43+ self ._logger .debug (
44+ "restarting logrotate in order for the changed config to take effect"
45+ )
46+ self .exec_cmd ("sudo logrotate /etc/logrotate.conf" )
47+ super (Mig003EnableLogrotateBuster , self )._run ()
48+
49+ def _rollback (self ):
50+ # no rollback needed
51+ super (Mig003EnableLogrotateBuster , self )._rollback ()
Original file line number Diff line number Diff line change 2323# this is for internal use
2424from octoprint_mrbeam .migration .Mig001 import Mig001NetconnectdDisableLogDebugLevel
2525from octoprint_mrbeam .migration .Mig002 import Mig002EnableOnlineCheck
26+ from octoprint_mrbeam .migration .Mig003 import Mig003EnableLogrotateBuster
2627
2728# To add migrations they have to be added to this list till we automate it
2829list_of_migrations = [
2930 Mig001NetconnectdDisableLogDebugLevel ,
3031 Mig002EnableOnlineCheck ,
32+ Mig003EnableLogrotateBuster ,
3133]
Original file line number Diff line number Diff line change @@ -201,7 +201,7 @@ def state(self):
201201 """
202202 return self ._state
203203
204- def exec_cmd (self , command ):
204+ def exec_cmd (self , command , optional = False ):
205205 """
206206 wrapper of exec_cmd to change to errorstate in case of a error
207207 Args:
@@ -210,9 +210,14 @@ def exec_cmd(self, command):
210210 Returns:
211211 None
212212 Raises:
213- MigrationException: if the execution of the command ended with a errorcode different to 0
213+ MigrationException: if the execution of the command was not successful
214214 """
215- if not exec_cmd (command ):
215+ command_success = exec_cmd (command )
216+ if command_success :
217+ return
218+ if optional and not command_success :
219+ self ._logger .warn ("optional command failed - cmd: {}" .format (command ))
220+ else :
216221 raise MigrationException ("error during migration for cmd:" , command )
217222
218223 @staticmethod
Original file line number Diff line number Diff line change 1+ from octoprint_mrbeam .migration import Mig003EnableLogrotateBuster
2+ import unittest
3+
4+
5+ class TestMigrationMig003 (unittest .TestCase ):
6+ """
7+ Testclass for the migration Mig001
8+ """
9+
10+ def setUp (self ):
11+ self .m003 = Mig003EnableLogrotateBuster (None )
12+
13+ def test_beamos_versions (self ):
14+ # beamos versions where the migration should not run
15+ self .assertFalse (self .m003 .shouldrun (Mig003EnableLogrotateBuster , "0.19.0" ))
16+
17+ # beamos versions where the migration should run
18+ self .assertTrue (self .m003 .shouldrun (Mig003EnableLogrotateBuster , "0.14.0" ))
19+ self .assertTrue (self .m003 .shouldrun (Mig003EnableLogrotateBuster , "0.18.0" ))
20+ self .assertTrue (self .m003 .shouldrun (Mig003EnableLogrotateBuster , "0.18.1" ))
21+ self .assertTrue (self .m003 .shouldrun (Mig003EnableLogrotateBuster , "0.18.2" ))
22+
23+ # not matching pattern strings
24+ self .assertFalse (self .m003 .shouldrun (Mig003EnableLogrotateBuster , None ))
25+ self .assertFalse (self .m003 .shouldrun (Mig003EnableLogrotateBuster , "14.0" ))
26+ self .assertFalse (self .m003 .shouldrun (Mig003EnableLogrotateBuster , "0" ))
27+
28+ def test_migration_id (self ):
29+ self .assertEqual (self .m003 .id , "003" )
You can’t perform that action at this time.
0 commit comments