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
1diff --git a/plainbox/impl/exporter/jinja2.py b/plainbox/impl/exporter/jinja2.py
2index 1f780e4..abdba4c 100644
3--- a/plainbox/impl/exporter/jinja2.py
4+++ b/plainbox/impl/exporter/jinja2.py
5@@ -27,14 +27,15 @@
6
7 import json
8 import re
9+import jinja2
10 from collections import OrderedDict
11 from datetime import datetime
12+from packaging import version
13
14 from jinja2 import Environment
15 from jinja2 import FileSystemLoader
16-from jinja2 import Markup
17-from jinja2 import environmentfilter
18-from jinja2 import escape
19+from jinja2 import pass_environment
20+from markupsafe import escape, Markup
21
22 from plainbox import get_version_string
23 from plainbox.abc import ISessionStateExporter
24@@ -47,7 +48,7 @@ from plainbox.impl.unit.exporter import ExporterError
25 CERTIFICATION_NS = 'com.canonical.certification::'
26
27
28-@environmentfilter
29+@pass_environment
30 def do_strip_ns(_environment, unit_id, ns=CERTIFICATION_NS):
31 """Remove the namespace part of the identifier."""
32 # com.my.namespace::category/job-id → category/job-id
33@@ -111,7 +112,13 @@ class Jinja2SessionStateExporter(SessionStateExporterBase):
34 self.option_list = tuple(exporter_unit.option_list or ()) + tuple(
35 option_list or ())
36 loader = FileSystemLoader(paths)
37- env = Environment(loader=loader, extensions=['jinja2.ext.autoescape'])
38+ # For jinja2 version > 2.9.0 autoescape functionality is built-in,
39+ # no need to add extensions
40+ if version.parse(jinja2.__version__) >= version.parse('2.9.0'):
41+ env = Environment(loader=loader)
42+ else:
43+ env = Environment(loader=loader, extensions=['jinja2.ext.autoescape'])
44+
45 self.customize_environment(env)
46
47 def include_file(name):
48diff --git a/plainbox/impl/session/restart.py b/plainbox/impl/session/restart.py
49index 0aa67b4..d7f95b4 100644
50--- a/plainbox/impl/session/restart.py
51+++ b/plainbox/impl/session/restart.py
52@@ -276,13 +276,8 @@ def detect_restart_strategy(session=None, session_type=None) -> IRestartStrategy
53 # with the next release or when we do inclusive naming refactor
54 # or roughly after April of 2022
55 if session_type in ('remote', 'checkbox-slave'):
56- try:
57- subprocess.run(
58- ['systemctl', 'is-active', '--quiet', 'checkbox-ng.service'],
59- check=True)
60+ if check_service_is_active():
61 return RemoteDebRestartStrategy()
62- except subprocess.CalledProcessError:
63- pass
64
65 # XXX: RemoteSnappyRestartStrategy debug
66 remote_restart_stragegy_debug = os.getenv('REMOTE_RESTART_DEBUG')
67@@ -337,8 +332,21 @@ def detect_restart_strategy(session=None, session_type=None) -> IRestartStrategy
68 # NOTE: Assume this is a terminal application
69 return XDGRestartStrategy(app_terminal=True)
70
71+ # Systemctl
72+ if session_type == None:
73+ if check_service_is_active():
74+ return RemoteDebRestartStrategy()
75+
76 raise LookupError("Unable to find appropriate strategy.""")
77
78+def check_service_is_active() -> bool:
79+ try:
80+ subprocess.run(
81+ ['systemctl', 'is-active', '--quiet', 'checkbox-ng.service'],
82+ check=True)
83+ return True
84+ except subprocess.CalledProcessError:
85+ return False
86
87 def get_strategy_by_name(name: str) -> type:
88 """

Subscribers

People subscribed via source and target branches