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
diff --git a/checkbox_support/scripts/tests/test_zapper_proxy.py b/checkbox_support/scripts/tests/test_zapper_proxy.py
index db3e754..c641cb3 100644
--- a/checkbox_support/scripts/tests/test_zapper_proxy.py
+++ b/checkbox_support/scripts/tests/test_zapper_proxy.py
@@ -1,6 +1,7 @@
1# Copyright 2022 Canonical Ltd.1# Copyright 2022 Canonical Ltd.
2# Written by:2# Written by:
3# Maciej Kisielewski <maciej.kisielewski@canonical.com>3# Maciej Kisielewski <maciej.kisielewski@canonical.com>
4# Paolo Gentili <paolo.gentili@canonical.com>
4#5#
5# This is free software: you can redistribute it and/or modify6# This is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3,7# it under the terms of the GNU General Public License version 3,
@@ -31,16 +32,9 @@ class ZapperProxyV1Tests(TestCase):
31 def test_usb_get_state_smoke(self):32 def test_usb_get_state_smoke(self):
32 """33 """
33 Check if usb_get_state calls appropriate function on the rpyc client.34 Check if usb_get_state calls appropriate function on the rpyc client.
34
35 Current implementation on the service side uses mutable arguments for
36 returning values (C-style stuff that should be removed) this is why we
37 need the stateful side_effect below
38 """35 """
39 def side_effect_fn(_, ret):
40 ret.append('ON')
41 return True
42 self._mocked_conn.root.zombiemux_get_state = Mock(36 self._mocked_conn.root.zombiemux_get_state = Mock(
43 side_effect=side_effect_fn)37 return_value="ON")
44 zapctl = ZapperControlV1(self._mocked_conn)38 zapctl = ZapperControlV1(self._mocked_conn)
4539
46 with patch('builtins.print') as mocked_print:40 with patch('builtins.print') as mocked_print:
@@ -49,19 +43,23 @@ class ZapperProxyV1Tests(TestCase):
49 'State for address 0 is ON')43 'State for address 0 is ON')
5044
51 def test_usb_get_state_fails(self):45 def test_usb_get_state_fails(self):
52 """Check if usb_get_state quits with a proper message on failure."""46 """
53 self._mocked_conn.root.zombiemux_get_state = Mock(return_value=False)47 Check if usb_get_state quits with the exception from
48 the rpyc server on failure.
49 """
50 self._mocked_conn.root.zombiemux_get_state = Mock(
51 side_effect=Exception("Failure message"))
54 zapctl = ZapperControlV1(self._mocked_conn)52 zapctl = ZapperControlV1(self._mocked_conn)
55 with self.assertRaises(SystemExit) as context:53 with self.assertRaises(Exception) as context:
56 zapctl.usb_get_state(0)54 zapctl.usb_get_state(0)
57 self.assertEqual(55 self.assertEqual(
58 context.exception.code, 'Failed to get state for address 0.')56 str(context.exception), 'Failure message')
5957
60 def test_usb_set_state_smoke(self):58 def test_usb_set_state_smoke(self):
61 """59 """
62 Check if usb_set_state calls appropriate functions on the rpyc client.60 Check if usb_set_state calls appropriate functions on the rpyc client.
63 """61 """
64 self._mocked_conn.root.zombiemux_set_state = Mock(return_value=True)62 self._mocked_conn.root.zombiemux_set_state = Mock()
65 zapctl = ZapperControlV1(self._mocked_conn)63 zapctl = ZapperControlV1(self._mocked_conn)
66 with patch('builtins.print') as mocked_print:64 with patch('builtins.print') as mocked_print:
67 zapctl.usb_set_state(0, 'ON')65 zapctl.usb_set_state(0, 'ON')
@@ -69,13 +67,17 @@ class ZapperProxyV1Tests(TestCase):
69 "State 'ON' set for the address 0.")67 "State 'ON' set for the address 0.")
7068
71 def test_usb_set_state_fails(self):69 def test_usb_set_state_fails(self):
72 """Check if usb_set_state quits with a proper message on failure."""70 """
73 self._mocked_conn.root.zombiemux_set_state = Mock(return_value=False)71 Check if usb_set_state quits with the exception from
72 the rpcy server on failure.
73 """
74 self._mocked_conn.root.zombiemux_set_state = Mock(
75 side_effect=Exception("Failure message"))
74 zapctl = ZapperControlV1(self._mocked_conn)76 zapctl = ZapperControlV1(self._mocked_conn)
75 with self.assertRaises(SystemExit) as context:77 with self.assertRaises(Exception) as context:
76 zapctl.usb_set_state(0, 'ON')78 zapctl.usb_set_state(0, 'ON')
77 self.assertEqual(79 self.assertEqual(
78 context.exception.code, "Failed to set 'ON' state for address 0.")80 str(context.exception), 'Failure message')
7981
80 def test_get_capabilities_one_cap(self):82 def test_get_capabilities_one_cap(self):
81 """83 """
diff --git a/checkbox_support/scripts/zapper_proxy.py b/checkbox_support/scripts/zapper_proxy.py
index d3db200..8eff71d 100644
--- a/checkbox_support/scripts/zapper_proxy.py
+++ b/checkbox_support/scripts/zapper_proxy.py
@@ -1,6 +1,7 @@
1# Copyright 2022 Canonical Ltd.1# Copyright 2022 Canonical Ltd.
2# Written by:2# Written by:
3# Maciej Kisielewski <maciej.kisielewski@canonical.com>3# Maciej Kisielewski <maciej.kisielewski@canonical.com>
4# Paolo Gentili <paolo.gentili@canonical.com>
4#5#
5# This is free software: you can redistribute it and/or modify6# This is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 3,7# it under the terms of the GNU General Public License version 3,
@@ -72,19 +73,11 @@ class ZapperControlV1(IZapperControl):
72 self._conn = connection73 self._conn = connection
7374
74 def usb_get_state(self, address):75 def usb_get_state(self, address):
75 ret = []76 state = self._conn.root.zombiemux_get_state(address)
76 success = self._conn.root.zombiemux_get_state(address, ret)77 print("State for address {} is {}".format(address, state))
77 if not success:
78 raise SystemExit(
79 "Failed to get state for address {}.".format(address))
80 print("State for address {} is {}".format(address, ret[0]))
8178
82 def usb_set_state(self, address, state):79 def usb_set_state(self, address, state):
83 success = self._conn.root.zombiemux_set_state(address, state)80 self._conn.root.zombiemux_set_state(address, state)
84 if not success:
85 raise SystemExit(
86 "Failed to set '{}' state for address {}.".format(
87 state, address))
88 print("State '{}' set for the address {}.".format(state, address))81 print("State '{}' set for the address {}.".format(state, address))
8982
90 def get_capabilities(self):83 def get_capabilities(self):

Subscribers

People subscribed via source and target branches