auto_updater: Remove the need for original_build

We don't need to operate on original build anymore. Just deprecate this.

BUG=chromium:1093927
TEST=run_pytests

Change-Id: I9f6e009eeb24c928d84e417fa27fe60d56e04be0
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2242098
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Sanika Kulkarni <sanikak@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/lib/auto_updater.py b/lib/auto_updater.py
index c88600e..482e9a9 100644
--- a/lib/auto_updater.py
+++ b/lib/auto_updater.py
@@ -148,8 +148,7 @@
   PAYLOAD_DIR_NAME = 'payloads'
 
   def __init__(self, device, build_name, payload_dir, transfer_class,
-               dev_dir='', log_file=None, tempdir=None,
-               original_payload_dir=None, clobber_stateful=True,
+               dev_dir='', log_file=None, tempdir=None, clobber_stateful=True,
                local_devserver=False, yes=False, do_rootfs_update=True,
                do_stateful_update=True, reboot=True, disable_verification=False,
                send_payload_in_parallel=False, payload_filename=None,
@@ -168,11 +167,6 @@
           the tempdir for cros flash is /tmp/cros-flash****/, used to
           temporarily keep files when transferring update-utils package, and
           reserve nebraska and update engine logs.
-      original_payload_dir: The directory containing payloads whose version is
-          the same as current host's rootfs partition. If it's None, will first
-          try installing the matched stateful.tgz with the host's rootfs
-          Partition when restoring stateful. Otherwise, install the target
-          stateful.tgz.
       do_rootfs_update: whether to do rootfs partition update. The default is
           True.
       do_stateful_update: whether to do stateful partition update. The default
@@ -207,7 +201,6 @@
     self.update_version = None if local_devserver else build_name
 
     self.dev_dir = dev_dir
-    self.original_payload_dir = original_payload_dir
 
     # Update setting
     self._cmd_kwargs = {}
@@ -278,7 +271,6 @@
         cmd_kwargs=self._cmd_kwargs,
         transfer_rootfs_update=self._do_rootfs_update,
         transfer_stateful_update=self._do_rootfs_update, dev_dir=self.dev_dir,
-        original_payload_dir=self.original_payload_dir,
         device_restore_dir=self.device_restore_dir,
         device_payload_dir=self.device_payload_dir, tempdir=self.tempdir,
         payload_mode=self.payload_mode, **cls_kwargs)
@@ -551,21 +543,11 @@
           ignore_failures=True,
           **self._cmd_kwargs_omit_error)
 
-  def UpdateStateful(self, use_original_build=False):
-    """Update the stateful partition of the device.
-
-    Args:
-      use_original_build: True if we use stateful.tgz of original build for
-        stateful update, otherwise, as default, False.
-    """
-    if self.original_payload_dir and use_original_build:
-      payload_dir = self.device_restore_dir
-    else:
-      payload_dir = self.device.work_dir
-
+  def UpdateStateful(self):
+    """Update the stateful partition of the device."""
     try:
       stateful_update_payload = os.path.join(
-          payload_dir, auto_updater_transfer.STATEFUL_FILENAME)
+          self.device.work_dir, auto_updater_transfer.STATEFUL_FILENAME)
 
       updater = stateful_updater.StatefulUpdater(self.device)
       updater.Update(
@@ -1088,8 +1070,7 @@
     self.PreSetupStatefulUpdate()
     self._transfer_obj.TransferStatefulUpdate()
     self.ResetStatefulPartition()
-    use_original_build = bool(self.original_payload_dir)
-    self.UpdateStateful(use_original_build=use_original_build)
+    self.UpdateStateful()
     self.PostCheckStatefulUpdate()
     self._Reboot('stateful partition restoration')
     try:
diff --git a/lib/auto_updater_transfer.py b/lib/auto_updater_transfer.py
index f297716..8dcc0d8 100644
--- a/lib/auto_updater_transfer.py
+++ b/lib/auto_updater_transfer.py
@@ -98,8 +98,7 @@
 
   def __init__(self, device, payload_dir, device_restore_dir, tempdir,
                payload_name, cmd_kwargs, device_payload_dir, dev_dir='',
-               payload_mode='scp', original_payload_dir=None,
-               transfer_stateful_update=True,
+               payload_mode='scp', transfer_stateful_update=True,
                transfer_rootfs_update=True):
     """Initialize Base Class for transferring payloads functionality.
 
@@ -119,11 +118,6 @@
           directory.
       dev_dir: The directory of the nebraska that runs the CrOS auto-update.
       payload_mode: The payload mode - it can be 'parallel' or 'scp'.
-      original_payload_dir: The directory containing payloads whose version is
-          the same as current host's rootfs partition. If it's None, will first
-          try installing the matched stateful.tgz with the host's rootfs
-          Partition when restoring stateful. Otherwise, install the target
-          stateful.tgz.
       transfer_stateful_update: Whether to transfer payloads necessary for
           stateful update. The default is True.
       transfer_rootfs_update: Whether to transfer payloads necessary for
@@ -141,7 +135,6 @@
       raise ValueError('The given value %s for payload mode is not valid.' %
                        payload_mode)
     self._payload_mode = payload_mode
-    self._original_payload_dir = original_payload_dir
     self._transfer_stateful_update = transfer_stateful_update
     self._transfer_rootfs_update = transfer_rootfs_update
     self._local_payload_props_path = None
@@ -291,15 +284,6 @@
     The stateful update payloads are copied to the target remote device for
     stateful update.
     """
-    if self._original_payload_dir:
-      logging.notice('Copying original stateful payload to device...')
-      original_payload = os.path.join(
-          self._original_payload_dir, STATEFUL_FILENAME)
-      self._EnsureDeviceDirectory(self._device_restore_dir)
-      self._device.CopyToDevice(original_payload, self._device_restore_dir,
-                                mode=self._payload_mode, log_output=True,
-                                **self._cmd_kwargs)
-
     logging.notice('Copying target stateful payload to device...')
     payload = os.path.join(self._payload_dir, STATEFUL_FILENAME)
     self._device.CopyToWorkDir(payload, mode=self._payload_mode,
@@ -507,14 +491,6 @@
     # will avoid a disk copy but has the potential to be harder to debug if
     # update engine does not report the error clearly.
 
-    if self._original_payload_dir:
-      logging.notice('Copying original stateful payload to device...')
-      self._EnsureDeviceDirectory(self._device_restore_dir)
-      self._device.run(self._GetCurlCmdForPayloadDownload(
-          payload_dir=self._device_restore_dir,
-          build_id=self._original_payload_dir,
-          payload_filename=STATEFUL_FILENAME))
-
     logging.notice('Copying target stateful payload to device...')
     self._device.run(self._GetCurlCmdForPayloadDownload(
         payload_dir=self._device.work_dir, build_id=self._payload_dir,
diff --git a/lib/auto_updater_transfer_unittest.py b/lib/auto_updater_transfer_unittest.py
index 539aaea..3b5d336 100644
--- a/lib/auto_updater_transfer_unittest.py
+++ b/lib/auto_updater_transfer_unittest.py
@@ -412,90 +412,6 @@
       self.assertListEqual(lab_xfer._EnsureDeviceDirectory.call_args_list,
                            [mock.call(x) for x in expected])
 
-  def testTransferStatefulOriginalPayloadCurlCmdCalls(self):
-    """Test methods calls of LabTransfer._TransferStatefulUpdate().
-
-    Test whether LabTransfer._GetCurlCmdForPayloadDownload() is being called
-    the correct number of times with the correct arguments when original
-    payload directory exists.
-    """
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      CrOS_LabTransfer = CreateLabTransferInstance(
-          device, original_payload_dir='/test/original/payload/dir',
-          device_payload_dir='/test/device/payload/dir',
-          device_restore_dir='/test/device/restore/dir',
-          payload_dir='/test/payload/dir')
-      lab_xfer = auto_updater_transfer.LabTransfer
-
-      self.PatchObject(auto_updater_transfer, 'STATEFUL_FILENAME',
-                       'test_stateful.tgz')
-      self.PatchObject(lab_xfer, '_EnsureDeviceDirectory')
-      self.PatchObject(lab_xfer, '_GetCurlCmdForPayloadDownload')
-      self.PatchObject(remote_access.ChromiumOSDevice, 'run')
-
-      expected = [
-          {'payload_dir': CrOS_LabTransfer._device_restore_dir,
-           'payload_filename': auto_updater_transfer.STATEFUL_FILENAME,
-           'build_id': CrOS_LabTransfer._original_payload_dir},
-          {'payload_dir': device.work_dir,
-           'payload_filename': auto_updater_transfer.STATEFUL_FILENAME,
-           'build_id': CrOS_LabTransfer._payload_dir}]
-
-      CrOS_LabTransfer._TransferStatefulUpdate()
-      self.assertListEqual(
-          lab_xfer._GetCurlCmdForPayloadDownload.call_args_list,
-          [mock.call(**x) for x in expected])
-
-  def testTransferStatefulOriginalPayloadRunCmdCalls(self):
-    """Test methods calls of LabTransfer._TransferStatefulUpdate().
-
-    Test whether remote_access.ChromiumOSDevice.run() is being called
-    the correct number of times with the correct arguments when original
-    payload directory exists.
-    """
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      CrOS_LabTransfer = CreateLabTransferInstance(
-          device, original_payload_dir='/test/original/payload/dir',
-          device_restore_dir='/test/device/restore/dir')
-      lab_xfer = auto_updater_transfer.LabTransfer
-      expected = [
-          ['curl', '-o', '/test/device/restore/dir/stateful.tgz',
-           'http://0.0.0.0:8000/test/original/payload/dir/stateful.tgz'],
-          ['curl', '-o', '/test/work/dir/stateful.tgz',
-           'http://0.0.0.0:8000/static/stateful.tgz']]
-
-      self.PatchObject(lab_xfer, '_EnsureDeviceDirectory')
-      self.PatchObject(remote_access.ChromiumOSDevice, 'run')
-
-      CrOS_LabTransfer._TransferStatefulUpdate()
-      self.assertListEqual(
-          remote_access.ChromiumOSDevice.run.call_args_list,
-          [mock.call(x) for x in expected])
-
-
-  def testTransferStatefulOriginalPayloadEnsureDirCalls(self):
-    """Test methods calls of LabTransfer._TransferStatefulUpdate().
-
-    Test whether LabTransfer._EnsureDeviceDirectory() is being called
-    the correct number of times with the correct arguments when original
-    payload directory exists.
-    """
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      CrOS_LabTransfer = CreateLabTransferInstance(
-          device, original_payload_dir='/test/original/payload/dir',
-          device_payload_dir='/test/device/payload/dir',
-          device_restore_dir='/test/device/restore/dir')
-      lab_xfer = auto_updater_transfer.LabTransfer
-      expected = [CrOS_LabTransfer._device_payload_dir,
-                  CrOS_LabTransfer._device_restore_dir]
-
-      self.PatchObject(lab_xfer, '_EnsureDeviceDirectory')
-      self.PatchObject(remote_access.ChromiumOSDevice, 'run')
-
-      CrOS_LabTransfer._TransferStatefulUpdate()
-      self.assertListEqual(lab_xfer._EnsureDeviceDirectory.call_args_list,
-                           [mock.call(x) for x in expected])
-
   def testErrorTransferRootfsServerError(self):
     """Test errors thrown by LabTransfer._TransferRootfsUpdate()."""
     with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
diff --git a/scripts/cros_update.py b/scripts/cros_update.py
index eb78860..82f7c60 100644
--- a/scripts/cros_update.py
+++ b/scripts/cros_update.py
@@ -73,7 +73,7 @@
 
   def __init__(self, host_name, build_name, static_dir, progress_tracker=None,
                log_file=None, au_tempdir=None, force_update=False,
-               full_update=False, original_build=None, payload_filename=None,
+               full_update=False, payload_filename=None,
                clobber_stateful=True, quick_provision=False,
                devserver_url=None, static_url=None, staging_server=None,
                transfer_class=None):
@@ -85,7 +85,6 @@
     self.au_tempdir = au_tempdir
     self.force_update = force_update
     self.full_update = full_update
-    self.original_build = original_build
     self.payload_filename = payload_filename
     self.clobber_stateful = clobber_stateful
     self.quick_provision = quick_provision
@@ -134,19 +133,6 @@
     self._WriteAUStatus('post-check rootfs update')
     cros_updater.PostCheckRootfsUpdate()
 
-  def _GetOriginalPayloadDir(self):
-    """Get the directory of original payload.
-
-    Returns:
-      The directory of original payload, whose format is like:
-          'static/stable-channel/link/3428.210.0'
-    """
-    if self.original_build:
-      return os.path.join(self.static_dir, STABLE_BUILD_CHANNEL,
-                          self.original_build)
-    else:
-      return None
-
   def _MakeStatusUrl(self, devserver_url, host_name, pid):
     """Generates a URL to post auto update status to.
 
@@ -232,14 +218,12 @@
 
         logging.debug('Remote device %s is connected', self.host_name)
         payload_dir = os.path.join(self.static_dir, self.build_name)
-        original_payload_dir = self._GetOriginalPayloadDir()
 
         chromeos_AU = auto_updater.ChromiumOSUpdater(
             device, self.build_name, payload_dir,
             dev_dir=os.path.join(constants.SOURCE_ROOT, self.DEV_DIR),
             tempdir=self.au_tempdir,
             log_file=self.log_file,
-            original_payload_dir=original_payload_dir,
             yes=True,
             payload_filename=self.payload_filename,
             clobber_stateful=self.clobber_stateful,
@@ -346,9 +330,6 @@
                            'the same')
   parser.add_argument('--full_update', action='store_true', default=False,
                       help='force a rootfs update, skip stateful update')
-  parser.add_argument('--original_build', type=str, default='',
-                      help=('force stateful update with the same version of '
-                            'previous rootfs partition'))
   parser.add_argument('--payload_filename', type=str,
                       help='A custom payload filename')
   parser.add_argument('--clobber_stateful', action='store_true', default=False,
@@ -394,7 +375,6 @@
       au_tempdir=au_tempdir,
       force_update=options.force_update,
       full_update=options.full_update,
-      original_build=options.original_build,
       payload_filename=options.payload_filename,
       clobber_stateful=options.clobber_stateful,
       quick_provision=options.quick_provision,
diff --git a/scripts/cros_update_unittest.py b/scripts/cros_update_unittest.py
index 55ea9d5..eb5b2b5 100644
--- a/scripts/cros_update_unittest.py
+++ b/scripts/cros_update_unittest.py
@@ -26,20 +26,11 @@
     """Setup an instance of CrOSUpdateTrigger."""
     self._cros_update_trigger = cros_update.CrOSUpdateTrigger(
         'foo-host-name', 'foo-build-name', 'foo-static-dir',
-        original_build='foo-original-build', static_url='foo-static',
-        devserver_url='foo-devserver-url')
+        static_url='foo-static', devserver_url='foo-devserver-url')
     self._cros_updater = auto_updater.ChromiumOSUpdater(
         mock.MagicMock(work_dir='foo-dir'), 'foo-build-name', 'foo-payload-dir',
         transfer_class=auto_updater_transfer.LocalTransfer)
 
-  def test_GetOriginalPayloadDir(self):
-    """Tests getting the original payload directory."""
-    self.assertEqual(self._cros_update_trigger._GetOriginalPayloadDir(),
-                     'foo-static-dir/stable-channel/foo-original-build')
-
-    self._cros_update_trigger.original_build = None
-    self.assertIsNone(self._cros_update_trigger._GetOriginalPayloadDir())
-
   def test_MakeStatusUrl(self):
     """Tests generating a URL to post auto update status."""
     self.assertEqual(