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
diff --git a/bin/net_if_management.py b/bin/net_if_management.py
index ef6fcde..b7daa9b 100755
--- a/bin/net_if_management.py
+++ b/bin/net_if_management.py
@@ -18,6 +18,7 @@
18# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.18# along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
1919
20from enum import Enum20from enum import Enum
21import os
21from shutil import which22from shutil import which
22import subprocess as sp23import subprocess as sp
23import sys24import sys
@@ -26,6 +27,12 @@ from checkbox_support.parsers.netplan import Netplan
26from checkbox_support.parsers.udevadm import UdevadmParser, UdevResult27from checkbox_support.parsers.udevadm import UdevadmParser, UdevResult
2728
2829
30def log(msg):
31 file = os.path.expandvars('$PLAINBOX_SESSION_SHARE/net_if_management.log')
32 with open(file, 'a') as f:
33 f.write(msg + '\n')
34
35
29class UdevInterfaceLister(UdevResult):36class UdevInterfaceLister(UdevResult):
3037
31 def __init__(self, categories):38 def __init__(self, categories):
@@ -95,8 +102,10 @@ def identify_managers(interfaces=None,
95 global_scope_manager = netplan_conf.network['renderer']102 global_scope_manager = netplan_conf.network['renderer']
96103
97 for n in results:104 for n in results:
105 log('=={}=='.format(n))
98 category_scope_manager = States.unspecified.value106 category_scope_manager = States.unspecified.value
99 if has_netplan:107 if has_netplan:
108 log('has netplan')
100 if n in netplan_conf.wifis:109 if n in netplan_conf.wifis:
101 category_scope_manager = netplan_conf.wifis.get(110 category_scope_manager = netplan_conf.wifis.get(
102 'renderer', States.unspecified.value)111 'renderer', States.unspecified.value)
@@ -108,23 +117,24 @@ def identify_managers(interfaces=None,
108 if (global_scope_manager == States.nm.value or117 if (global_scope_manager == States.nm.value or
109 category_scope_manager == States.nm.value or118 category_scope_manager == States.nm.value or
110 not has_netplan):119 not has_netplan):
120 log('NM indicated')
111 # if NM isnt actually available this is a bad config121 # if NM isnt actually available this is a bad config
112 if not has_nm:122 if not has_nm:
113 print('error: netplan defines NM or there is no netplan, '123 log('error: netplan defines NM or there is no netplan, '
114 'but NM unavailable')124 'but NM unavailable')
115 results[n] = States.error125 results[n] = States.error
116 continue126 continue
117 # NM does not know the interface127 # NM does not know the interface
118 if nm_conf.devices.get(n) is None:128 if nm_conf.devices.get(n) is None:
119 print('error: netplan defines NM or there is no netplan, '129 log('error: netplan defines NM or there is no netplan, '
120 'but interface unknown to NM')130 'but interface unknown to NM')
121 results[n] = States.error131 results[n] = States.error
122 continue132 continue
123 # NM thinks it doesnt manage the device despite netplan config133 # NM thinks it doesnt manage the device despite netplan config
124 if nm_conf.devices.get(n) == 'unmanaged':134 if nm_conf.devices.get(n) == 'unmanaged':
125 print('error: netplan defines NM or there is no netplan, '135 log('error: netplan defines NM or there is no netplan, '
126 'but NM reports unmanaged')136 'but NM reports unmanaged')
127 results[n] = States.error137 results[n] = States.unspecified
128 continue138 continue
129 results[n] = States.nm139 results[n] = States.nm
130 continue140 continue
diff --git a/jobs/resource.pxu b/jobs/resource.pxu
index a520deb..5d59466 100644
--- a/jobs/resource.pxu
+++ b/jobs/resource.pxu
@@ -453,6 +453,18 @@ user: root
453command:453command:
454 net_if_management.py454 net_if_management.py
455455
456id: net_if_management_attachment
457_summary: Collect logging from the net_if_management job
458_description:
459 Allows logging of debug info and errors by the associated resource job
460plugin: attachment
461estimated_duration: 1.0
462category_id: com.canonical.plainbox::info
463command:
464 log_file="$PLAINBOX_SESSION_SHARE/net_if_management.log"
465 [ -e "$log_file" ] && cat "$log_file"
466after: net_if_management
467
456id: bootloader468id: bootloader
457_summary: Detect which bootloader is used on the device469_summary: Detect which bootloader is used on the device
458_description:470_description:

Subscribers

People subscribed via source and target branches