Merge ~pgentili/checkbox-support:fix-zapper-control-api into checkbox-support:master

Proposed by Paolo Gentili
Status: Merged
Approved by: Paolo Gentili
Approved revision: 47d78d9ba85b421d02e73bc65eafd6c613215806
Merged at revision: 3089eaf057eb00e04b2cd0becd89a5793cac0ee7
Proposed branch: ~pgentili/checkbox-support:fix-zapper-control-api
Merge into: checkbox-support:master
Diff against target: 116 lines (+23/-28)
2 files modified
checkbox_support/scripts/tests/test_zapper_proxy.py (+19/-17)
checkbox_support/scripts/zapper_proxy.py (+4/-11)
Reviewer Review Type Date Requested Status
Maciej Kisielewski Approve
Review via email: mp+431289@code.launchpad.net

Commit message

Change: updated zapper zombiemux get/set state calls

To post a comment you must log in.
Revision history for this message
Maciej Kisielewski (kissiel) wrote :

wohoo, negative diff :D
+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/checkbox_support/scripts/tests/test_zapper_proxy.py b/checkbox_support/scripts/tests/test_zapper_proxy.py
2index db3e754..c641cb3 100644
3--- a/checkbox_support/scripts/tests/test_zapper_proxy.py
4+++ b/checkbox_support/scripts/tests/test_zapper_proxy.py
5@@ -1,6 +1,7 @@
6 # Copyright 2022 Canonical Ltd.
7 # Written by:
8 # Maciej Kisielewski <maciej.kisielewski@canonical.com>
9+# Paolo Gentili <paolo.gentili@canonical.com>
10 #
11 # This is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License version 3,
13@@ -31,16 +32,9 @@ class ZapperProxyV1Tests(TestCase):
14 def test_usb_get_state_smoke(self):
15 """
16 Check if usb_get_state calls appropriate function on the rpyc client.
17-
18- Current implementation on the service side uses mutable arguments for
19- returning values (C-style stuff that should be removed) this is why we
20- need the stateful side_effect below
21 """
22- def side_effect_fn(_, ret):
23- ret.append('ON')
24- return True
25 self._mocked_conn.root.zombiemux_get_state = Mock(
26- side_effect=side_effect_fn)
27+ return_value="ON")
28 zapctl = ZapperControlV1(self._mocked_conn)
29
30 with patch('builtins.print') as mocked_print:
31@@ -49,19 +43,23 @@ class ZapperProxyV1Tests(TestCase):
32 'State for address 0 is ON')
33
34 def test_usb_get_state_fails(self):
35- """Check if usb_get_state quits with a proper message on failure."""
36- self._mocked_conn.root.zombiemux_get_state = Mock(return_value=False)
37+ """
38+ Check if usb_get_state quits with the exception from
39+ the rpyc server on failure.
40+ """
41+ self._mocked_conn.root.zombiemux_get_state = Mock(
42+ side_effect=Exception("Failure message"))
43 zapctl = ZapperControlV1(self._mocked_conn)
44- with self.assertRaises(SystemExit) as context:
45+ with self.assertRaises(Exception) as context:
46 zapctl.usb_get_state(0)
47 self.assertEqual(
48- context.exception.code, 'Failed to get state for address 0.')
49+ str(context.exception), 'Failure message')
50
51 def test_usb_set_state_smoke(self):
52 """
53 Check if usb_set_state calls appropriate functions on the rpyc client.
54 """
55- self._mocked_conn.root.zombiemux_set_state = Mock(return_value=True)
56+ self._mocked_conn.root.zombiemux_set_state = Mock()
57 zapctl = ZapperControlV1(self._mocked_conn)
58 with patch('builtins.print') as mocked_print:
59 zapctl.usb_set_state(0, 'ON')
60@@ -69,13 +67,17 @@ class ZapperProxyV1Tests(TestCase):
61 "State 'ON' set for the address 0.")
62
63 def test_usb_set_state_fails(self):
64- """Check if usb_set_state quits with a proper message on failure."""
65- self._mocked_conn.root.zombiemux_set_state = Mock(return_value=False)
66+ """
67+ Check if usb_set_state quits with the exception from
68+ the rpcy server on failure.
69+ """
70+ self._mocked_conn.root.zombiemux_set_state = Mock(
71+ side_effect=Exception("Failure message"))
72 zapctl = ZapperControlV1(self._mocked_conn)
73- with self.assertRaises(SystemExit) as context:
74+ with self.assertRaises(Exception) as context:
75 zapctl.usb_set_state(0, 'ON')
76 self.assertEqual(
77- context.exception.code, "Failed to set 'ON' state for address 0.")
78+ str(context.exception), 'Failure message')
79
80 def test_get_capabilities_one_cap(self):
81 """
82diff --git a/checkbox_support/scripts/zapper_proxy.py b/checkbox_support/scripts/zapper_proxy.py
83index d3db200..8eff71d 100644
84--- a/checkbox_support/scripts/zapper_proxy.py
85+++ b/checkbox_support/scripts/zapper_proxy.py
86@@ -1,6 +1,7 @@
87 # Copyright 2022 Canonical Ltd.
88 # Written by:
89 # Maciej Kisielewski <maciej.kisielewski@canonical.com>
90+# Paolo Gentili <paolo.gentili@canonical.com>
91 #
92 # This is free software: you can redistribute it and/or modify
93 # it under the terms of the GNU General Public License version 3,
94@@ -72,19 +73,11 @@ class ZapperControlV1(IZapperControl):
95 self._conn = connection
96
97 def usb_get_state(self, address):
98- ret = []
99- success = self._conn.root.zombiemux_get_state(address, ret)
100- if not success:
101- raise SystemExit(
102- "Failed to get state for address {}.".format(address))
103- print("State for address {} is {}".format(address, ret[0]))
104+ state = self._conn.root.zombiemux_get_state(address)
105+ print("State for address {} is {}".format(address, state))
106
107 def usb_set_state(self, address, state):
108- success = self._conn.root.zombiemux_set_state(address, state)
109- if not success:
110- raise SystemExit(
111- "Failed to set '{}' state for address {}.".format(
112- state, address))
113+ self._conn.root.zombiemux_set_state(address, state)
114 print("State '{}' set for the address {}.".format(state, address))
115
116 def get_capabilities(self):

Subscribers

People subscribed via source and target branches