Merge ~levanquach/checkbox-ng:oniro_patch into checkbox-ng:master

Proposed by Le Van Quach
Status: Needs review
Proposed branch: ~levanquach/checkbox-ng:oniro_patch
Merge into: checkbox-ng:master
Diff against target: 88 lines (+26/-11)
2 files modified
plainbox/impl/exporter/jinja2.py (+12/-5)
plainbox/impl/session/restart.py (+14/-6)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Pending
Review via email: mp+429157@code.launchpad.net

Commit message

Modify jinja2.py and restart.py files in order to integrate checkbox in Oniro

Description of the change

Changes in jinja2.py file are related to deprecated functionalities.

Checkbox restart strategy is modified in order to work also when checkbox is run as a service.

To post a comment you must log in.

Unmerged commits

e6a0005... by Le Van Quach

Manage autoescape extension according to jinja2 installed version

6a3cd3b... by Le Van Quach

Adjust for deprecated jinja2 markup, environment filter and escape alias

e9b88d9... by Le Van Quach

Add new checkbox restart strategy

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/plainbox/impl/exporter/jinja2.py b/plainbox/impl/exporter/jinja2.py
index 1f780e4..abdba4c 100644
--- a/plainbox/impl/exporter/jinja2.py
+++ b/plainbox/impl/exporter/jinja2.py
@@ -27,14 +27,15 @@
2727
28import json28import json
29import re29import re
30import jinja2
30from collections import OrderedDict31from collections import OrderedDict
31from datetime import datetime32from datetime import datetime
33from packaging import version
3234
33from jinja2 import Environment35from jinja2 import Environment
34from jinja2 import FileSystemLoader36from jinja2 import FileSystemLoader
35from jinja2 import Markup37from jinja2 import pass_environment
36from jinja2 import environmentfilter38from markupsafe import escape, Markup
37from jinja2 import escape
3839
39from plainbox import get_version_string40from plainbox import get_version_string
40from plainbox.abc import ISessionStateExporter41from plainbox.abc import ISessionStateExporter
@@ -47,7 +48,7 @@ from plainbox.impl.unit.exporter import ExporterError
47CERTIFICATION_NS = 'com.canonical.certification::'48CERTIFICATION_NS = 'com.canonical.certification::'
4849
4950
50@environmentfilter51@pass_environment
51def do_strip_ns(_environment, unit_id, ns=CERTIFICATION_NS):52def do_strip_ns(_environment, unit_id, ns=CERTIFICATION_NS):
52 """Remove the namespace part of the identifier."""53 """Remove the namespace part of the identifier."""
53 # com.my.namespace::category/job-id → category/job-id54 # com.my.namespace::category/job-id → category/job-id
@@ -111,7 +112,13 @@ class Jinja2SessionStateExporter(SessionStateExporterBase):
111 self.option_list = tuple(exporter_unit.option_list or ()) + tuple(112 self.option_list = tuple(exporter_unit.option_list or ()) + tuple(
112 option_list or ())113 option_list or ())
113 loader = FileSystemLoader(paths)114 loader = FileSystemLoader(paths)
114 env = Environment(loader=loader, extensions=['jinja2.ext.autoescape'])115 # For jinja2 version > 2.9.0 autoescape functionality is built-in,
116 # no need to add extensions
117 if version.parse(jinja2.__version__) >= version.parse('2.9.0'):
118 env = Environment(loader=loader)
119 else:
120 env = Environment(loader=loader, extensions=['jinja2.ext.autoescape'])
121
115 self.customize_environment(env)122 self.customize_environment(env)
116123
117 def include_file(name):124 def include_file(name):
diff --git a/plainbox/impl/session/restart.py b/plainbox/impl/session/restart.py
index 0aa67b4..d7f95b4 100644
--- a/plainbox/impl/session/restart.py
+++ b/plainbox/impl/session/restart.py
@@ -276,13 +276,8 @@ def detect_restart_strategy(session=None, session_type=None) -> IRestartStrategy
276 # with the next release or when we do inclusive naming refactor276 # with the next release or when we do inclusive naming refactor
277 # or roughly after April of 2022277 # or roughly after April of 2022
278 if session_type in ('remote', 'checkbox-slave'):278 if session_type in ('remote', 'checkbox-slave'):
279 try:279 if check_service_is_active():
280 subprocess.run(
281 ['systemctl', 'is-active', '--quiet', 'checkbox-ng.service'],
282 check=True)
283 return RemoteDebRestartStrategy()280 return RemoteDebRestartStrategy()
284 except subprocess.CalledProcessError:
285 pass
286281
287 # XXX: RemoteSnappyRestartStrategy debug282 # XXX: RemoteSnappyRestartStrategy debug
288 remote_restart_stragegy_debug = os.getenv('REMOTE_RESTART_DEBUG')283 remote_restart_stragegy_debug = os.getenv('REMOTE_RESTART_DEBUG')
@@ -337,8 +332,21 @@ def detect_restart_strategy(session=None, session_type=None) -> IRestartStrategy
337 # NOTE: Assume this is a terminal application332 # NOTE: Assume this is a terminal application
338 return XDGRestartStrategy(app_terminal=True)333 return XDGRestartStrategy(app_terminal=True)
339334
335 # Systemctl
336 if session_type == None:
337 if check_service_is_active():
338 return RemoteDebRestartStrategy()
339
340 raise LookupError("Unable to find appropriate strategy.""")340 raise LookupError("Unable to find appropriate strategy.""")
341341
342def check_service_is_active() -> bool:
343 try:
344 subprocess.run(
345 ['systemctl', 'is-active', '--quiet', 'checkbox-ng.service'],
346 check=True)
347 return True
348 except subprocess.CalledProcessError:
349 return False
342350
343def get_strategy_by_name(name: str) -> type:351def get_strategy_by_name(name: str) -> type:
344 """352 """

Subscribers

People subscribed via source and target branches