Merge ~jocave/plainbox-provider-resource:net-if-update into plainbox-provider-resource:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 4e7eb4986069667cdc3cb6a1e581ad4fdc792eb6
Merged at revision: cf4957e4b11033b3fdc5a0804f72c2b21426eef3
Proposed branch: ~jocave/plainbox-provider-resource:net-if-update
Merge into: plainbox-provider-resource:master
Diff against target: 91 lines (+29/-7)
2 files modified
bin/net_if_management.py (+17/-7)
jobs/resource.pxu (+12/-0)
Reviewer Review Type Date Requested Status
Sheila Miguez (community) Approve
Review via email: mp+377427@code.launchpad.net

Description of the change

Update net_if_management job so that it does not pollute the resource output with error information. Add an attachment job to collect a log file with the debug information.

To post a comment you must log in.
Revision history for this message
Sheila Miguez (codersquid) wrote :

lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/net_if_management.py b/bin/net_if_management.py
2index ef6fcde..b7daa9b 100755
3--- a/bin/net_if_management.py
4+++ b/bin/net_if_management.py
5@@ -18,6 +18,7 @@
6 # along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
7
8 from enum import Enum
9+import os
10 from shutil import which
11 import subprocess as sp
12 import sys
13@@ -26,6 +27,12 @@ from checkbox_support.parsers.netplan import Netplan
14 from checkbox_support.parsers.udevadm import UdevadmParser, UdevResult
15
16
17+def log(msg):
18+ file = os.path.expandvars('$PLAINBOX_SESSION_SHARE/net_if_management.log')
19+ with open(file, 'a') as f:
20+ f.write(msg + '\n')
21+
22+
23 class UdevInterfaceLister(UdevResult):
24
25 def __init__(self, categories):
26@@ -95,8 +102,10 @@ def identify_managers(interfaces=None,
27 global_scope_manager = netplan_conf.network['renderer']
28
29 for n in results:
30+ log('=={}=='.format(n))
31 category_scope_manager = States.unspecified.value
32 if has_netplan:
33+ log('has netplan')
34 if n in netplan_conf.wifis:
35 category_scope_manager = netplan_conf.wifis.get(
36 'renderer', States.unspecified.value)
37@@ -108,23 +117,24 @@ def identify_managers(interfaces=None,
38 if (global_scope_manager == States.nm.value or
39 category_scope_manager == States.nm.value or
40 not has_netplan):
41+ log('NM indicated')
42 # if NM isnt actually available this is a bad config
43 if not has_nm:
44- print('error: netplan defines NM or there is no netplan, '
45- 'but NM unavailable')
46+ log('error: netplan defines NM or there is no netplan, '
47+ 'but NM unavailable')
48 results[n] = States.error
49 continue
50 # NM does not know the interface
51 if nm_conf.devices.get(n) is None:
52- print('error: netplan defines NM or there is no netplan, '
53- 'but interface unknown to NM')
54+ log('error: netplan defines NM or there is no netplan, '
55+ 'but interface unknown to NM')
56 results[n] = States.error
57 continue
58 # NM thinks it doesnt manage the device despite netplan config
59 if nm_conf.devices.get(n) == 'unmanaged':
60- print('error: netplan defines NM or there is no netplan, '
61- 'but NM reports unmanaged')
62- results[n] = States.error
63+ log('error: netplan defines NM or there is no netplan, '
64+ 'but NM reports unmanaged')
65+ results[n] = States.unspecified
66 continue
67 results[n] = States.nm
68 continue
69diff --git a/jobs/resource.pxu b/jobs/resource.pxu
70index a520deb..5d59466 100644
71--- a/jobs/resource.pxu
72+++ b/jobs/resource.pxu
73@@ -453,6 +453,18 @@ user: root
74 command:
75 net_if_management.py
76
77+id: net_if_management_attachment
78+_summary: Collect logging from the net_if_management job
79+_description:
80+ Allows logging of debug info and errors by the associated resource job
81+plugin: attachment
82+estimated_duration: 1.0
83+category_id: com.canonical.plainbox::info
84+command:
85+ log_file="$PLAINBOX_SESSION_SHARE/net_if_management.log"
86+ [ -e "$log_file" ] && cat "$log_file"
87+after: net_if_management
88+
89 id: bootloader
90 _summary: Detect which bootloader is used on the device
91 _description:

Subscribers

People subscribed via source and target branches