Skip to content

Commit 2a04b86

Browse files
ahmed-mrbeamJFSolutionkhaledsherkawi
committed
SW-1027-release-0-10-1-hotfix-1 (mrbeam#1429)
* SW-974 - Disable netconnectd debug log (mrbeam#1428) * SW-974 - * SW-1046 - Modify the "userData" sent to design store by sanitizing the mr beam plugin verison (mrbeam#1432) * SW-1048 - Modify the version comparative methods in the mr beam plugin (mrbeam#1433) - Add semantic versioning comparison library https://www.npmjs.com/package/compare-versions Co-authored-by: Josef-MrBeam <[email protected]> Co-authored-by: khaledsherkawi <[email protected]>
1 parent cf81f92 commit 2a04b86

File tree

16 files changed

+661
-149
lines changed

16 files changed

+661
-149
lines changed

octoprint_mrbeam/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,7 @@ def get_assets(self):
610610
# core UI here.
611611
assets = dict(
612612
js=[
613+
"js/lib/compare-versions.js",
613614
"js/helpers/quick_shape_helper.js",
614615
"js/helpers/element_helper.js",
615616
"js/helpers/debug_rendering_helper.js",

octoprint_mrbeam/__version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""
22
Version of Mr beam plugin
33
"""
4-
__version__ = "0.10.2"
4+
__version__ = "0.10.3"

octoprint_mrbeam/migrate.py

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import sys
1+
import json
22
from collections import Iterable, Sized, Mapping
33
import os
4-
import platform
54
import re
65
import shutil
76
from datetime import datetime
@@ -11,11 +10,16 @@
1110
from octoprint_mrbeam.software_update_information import BEAMOS_LEGACY_DATE
1211
from octoprint_mrbeam.mrb_logger import mrb_logger
1312
from octoprint_mrbeam.util.cmd_exec import exec_cmd, exec_cmd_output
14-
from octoprint_mrbeam.util import logExceptions, dict_get
13+
from octoprint_mrbeam.util import logExceptions
1514
from octoprint_mrbeam.printing.profile import laserCutterProfileManager
1615
from octoprint_mrbeam.printing.comm_acc2 import MachineCom
1716
from octoprint_mrbeam.__version import __version__
1817
from octoprint_mrbeam.materials import materials
18+
from octoprint_mrbeam.migration import (
19+
MIGRATION_STATE,
20+
MigrationBaseClass,
21+
list_of_migrations,
22+
)
1923

2024

2125
def migrate(plugin):
@@ -70,6 +74,7 @@ def __init__(self, plugin):
7074
self.plugin._settings.get(["dev", "suppress_migrations"]) or IS_X86
7175
)
7276
beamos_tier, self.beamos_date = self.plugin._device_info.get_beamos_version()
77+
self.beamos_version = self.plugin._device_info.get_beamos_version_number()
7378

7479
def run(self):
7580
try:
@@ -249,6 +254,7 @@ def run(self):
249254
equal_ok=False,
250255
):
251256
self.fix_octoprint_prerelease_setting()
257+
252258
# migrations end
253259

254260
self._logger.info(
@@ -262,14 +268,86 @@ def run(self):
262268
"No migration done because 'suppress_migrations' is set to true in settings."
263269
)
264270
else:
265-
self._logger.debug("No migration required.")
271+
self._logger.info("old migration - No migration required.")
266272

273+
self._run_migration()
267274
self.save_current_version()
268275
except MigrationException as e:
269276
self._logger.exception("Error while migration: {}".format(e))
270277
except Exception as e:
271278
self._logger.exception("Unhandled exception during migration: {}".format(e))
272279

280+
def _run_migration(self):
281+
"""
282+
run the new migrations
283+
@return:
284+
"""
285+
self._logger.debug("beamos_version: {}".format(self.beamos_version))
286+
287+
list_of_migrations_obj_available_to_run = [
288+
MigrationBaseClass.return_obj(migration, self.plugin)
289+
for migration in list_of_migrations
290+
if migration.shouldrun(migration, self.beamos_version)
291+
]
292+
self._logger.debug(list_of_migrations_obj_available_to_run)
293+
294+
if not len(list_of_migrations_obj_available_to_run):
295+
self._logger.info("new migration - no migration needed")
296+
return
297+
298+
migrations_json_file_path = os.path.join(
299+
self.plugin._settings.getBaseFolder("base"), "migrations.json"
300+
)
301+
302+
# if file is not there create it
303+
if not os.path.exists(migrations_json_file_path):
304+
self._logger.info("create " + migrations_json_file_path + " file")
305+
with open(migrations_json_file_path, "w") as f:
306+
json.dump({}, f)
307+
308+
try:
309+
with open(migrations_json_file_path, "r") as f:
310+
try:
311+
migration_executed = json.load(f)
312+
except ValueError:
313+
raise MigrationException(
314+
"couldn't read migrations json file content filepath:"
315+
+ migrations_json_file_path
316+
)
317+
318+
list_of_migrations_to_run = list(
319+
list_of_migrations_obj_available_to_run
320+
)
321+
for migration in list_of_migrations_obj_available_to_run:
322+
if migration.id in migration_executed:
323+
if migration_executed[migration.id]:
324+
list_of_migrations_to_run.remove(migration)
325+
else:
326+
# migration failed, should stay in execution queue and the following too
327+
break
328+
329+
if not len(list_of_migrations_to_run):
330+
self._logger.info("new migration - all migrations already done")
331+
return
332+
333+
for migration in list_of_migrations_to_run:
334+
migration.run()
335+
336+
# if migration sucessfull append to executed successfull
337+
if migration.state == MIGRATION_STATE.migration_done:
338+
migration_executed[migration.id] = True
339+
else:
340+
# mark migration as failed and skipp the following ones
341+
migration_executed[migration.id] = False
342+
break
343+
344+
with open(migrations_json_file_path, "w") as f:
345+
f.write(json.dumps(migration_executed))
346+
except IOError:
347+
self._logger.error("migration execution file IO error")
348+
except MigrationException as e:
349+
self._logger.exception("error during migration {}".format(e))
350+
273351
def is_migration_required(self):
274352
self._logger.debug(
275353
"beomosdate %s version %s",
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
from octoprint_mrbeam.migration.migration_base import (
2+
MigrationBaseClass,
3+
)
4+
5+
6+
class Mig001NetconnectdDisableLogDebugLevel(MigrationBaseClass):
7+
"""
8+
Migration for beamos versions 0.18.0 up to 0.18.1 to disable the the netconnectd debug mode
9+
"""
10+
11+
BEAMOS_VERSION_LOW = "0.18.0"
12+
BEAMOS_VERSION_HIGH = "0.18.1"
13+
14+
def __init__(self, plugin):
15+
"""
16+
initalization of the migration 001
17+
18+
Args:
19+
plugin: Mr Beam Plugin
20+
"""
21+
super(Mig001NetconnectdDisableLogDebugLevel, self).__init__(plugin)
22+
23+
@property
24+
def id(self):
25+
"""
26+
return the id of the migration
27+
28+
Returns:
29+
string: id of the migration
30+
"""
31+
return "001"
32+
33+
def _run(self):
34+
"""
35+
migration steps executet during migration
36+
37+
Returns:
38+
None
39+
"""
40+
self._logger.debug("stop netconnectd service")
41+
self.exec_cmd("sudo service netconnectd stop")
42+
43+
self._logger.debug("disable debug mode of netconnect")
44+
self.exec_cmd("sudo truncate -s 0 /etc/default/netconnectd")
45+
46+
self._logger.debug("purge content of netconnectd.log")
47+
self.exec_cmd("sudo truncate -s 0 /var/log/netconnectd.log")
48+
49+
self._logger.debug("restart netconnectd service")
50+
self.exec_cmd("sudo service netconnectd restart")
51+
52+
super(Mig001NetconnectdDisableLogDebugLevel, self)._run()
53+
54+
def _rollback(self):
55+
"""
56+
rollback steps executet during rollback
57+
58+
Returns:
59+
None
60+
"""
61+
self._logger.debug("restart netconnectd service")
62+
self.exec_cmd("sudo service netconnectd restart")
63+
super(Mig001NetconnectdDisableLogDebugLevel, self)._rollback()
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
This package contains all the migrations that are needed for the beamOS
3+
To add a new migration create a child class of the MigrationBaseClass and extend the run and rollback method with
4+
the steps needed for the new migration and the beamOS versions it should run for
5+
6+
How to use:
7+
- import list_of_migrations
8+
- iterate over the list items and run the shouldrun(<migrationclass>, <beamos_version>)
9+
- compare the result list with the already executed list and call the run() of the result list
10+
"""
11+
# these imports are for external use
12+
from octoprint_mrbeam.migration.migration_base import MIGRATION_STATE as MIGRATION_STATE
13+
from octoprint_mrbeam.migration.migration_base import (
14+
MigrationBaseClass as MigrationBaseClass,
15+
)
16+
from octoprint_mrbeam.migration.migration_base import (
17+
MigrationException as MigrationException,
18+
)
19+
20+
# this is for internal use
21+
from octoprint_mrbeam.migration.Mig001 import Mig001NetconnectdDisableLogDebugLevel
22+
23+
# To add migrations they have to be added to this list till we automate it
24+
list_of_migrations = [
25+
Mig001NetconnectdDisableLogDebugLevel,
26+
]

0 commit comments

Comments
 (0)