flash_unittest: rework mocks
The magic mocking of remote_access.ChromiumOSDevice leads to a lot
of nonsense behavior: the code under test tries to use properties
of the mock to create paths via os.path.join. Under Python 2, this
ends up producing another MagicMock, while under Python 3, it throws
an exception about arguments must be strings or bytes only.
Change the mocks so that we mock out the remote access attempts of
the RemoteDevice class (the parent of ChromiumOSDevice) so that we
leave the rest of the behavior intact.
BUG=chromium:997354
TEST=`./run_tests` passes
Change-Id: I4f083e5f7e407f9a76337fdc2434c21157a0ca31
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/1932721
Reviewed-by: Amin Hassani <ahassani@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/cli/flash_unittest.py b/cli/flash_unittest.py
index bc511b7..23cc77d 100644
--- a/cli/flash_unittest.py
+++ b/cli/flash_unittest.py
@@ -21,6 +21,7 @@
from chromite.lib import osutils
from chromite.lib import partial_mock
from chromite.lib import remote_access
+from chromite.lib import remote_access_unittest
from chromite.lib.paygen import paygen_payload_lib
from chromite.lib.paygen import paygen_stateful_payload_lib
@@ -51,6 +52,18 @@
"""Mock out ResolveAPPIDMismatchIfAny."""
+class RemoteAccessMock(remote_access_unittest.RemoteShMock):
+ """Mock out RemoteAccess."""
+
+ ATTRS = ('RemoteSh', 'Rsync', 'Scp')
+
+ def Rsync(self, *_args, **_kwargs):
+ return cros_build_lib.CommandResult(returncode=0)
+
+ def Scp(self, *_args, **_kwargs):
+ return cros_build_lib.CommandResult(returncode=0)
+
+
class RemoteDeviceUpdaterTest(cros_test_lib.MockTempDirTestCase):
"""Test the flow of flash.Flash() with RemoteDeviceUpdater."""
@@ -69,7 +82,12 @@
self.PatchObject(paygen_payload_lib, 'GenerateUpdatePayload')
self.PatchObject(paygen_stateful_payload_lib, 'GenerateStatefulPayload')
self.PatchObject(remote_access, 'CHECK_INTERVAL', new=0)
- self.PatchObject(remote_access, 'ChromiumOSDevice')
+ self.PatchObject(remote_access.ChromiumOSDevice, 'Pingable',
+ return_value=True)
+ m = self.StartPatcher(RemoteAccessMock())
+ m.AddCmdResult(['cat', '/etc/lsb-release'],
+ stdout='CHROMEOS_RELEASE_BOARD=board')
+ m.SetDefaultCmdResult()
def testUpdateAll(self):
"""Tests that update methods are called correctly."""