auto_updater: Remove LabTransfer

There is no use case for this class anymore. So just replace it with
LabEndToEndPayloadTransfer.

BUG=b:165619859
TEST=run_pytests
TEST=test_that --no-quickmerge chromeos6-row4-rack9-host11.cros autoupdate_EndToEndTest --args="update_type=full target_release=13517.0.0 target_payload_uri=gs://chromeos-releases/dev-channel/reef/13517.0.0/payloads/chromeos_13517.0.0_reef_dev-channel_full_test.bin-gvtdozjsguztfrdvj3t4mib6nln4jg7m"
TEST=cros flash

Change-Id: Idc9db91b0ac1ac1b910a3cdf994f0be647240cda
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/chromite/+/2365018
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Reviewed-by: Sanika Kulkarni <sanikak@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/lib/auto_update_util.py b/lib/auto_update_util.py
index 67ccd9e..35acca9 100644
--- a/lib/auto_update_util.py
+++ b/lib/auto_update_util.py
@@ -12,9 +12,6 @@
 from chromite.lib import cros_logging as logging
 
 
-LSB_RELEASE = '/etc/lsb-release'
-
-
 def GetChromeosBuildInfo(lsb_release_content=None, regex=None):
   """Get chromeos build info in device under test as string. None on fail.
 
diff --git a/lib/auto_updater_transfer.py b/lib/auto_updater_transfer.py
index 375c89f..f0d08a3 100644
--- a/lib/auto_updater_transfer.py
+++ b/lib/auto_updater_transfer.py
@@ -20,7 +20,7 @@
   * Transfer rootfs update files if rootfs update is required.
   * Transfer stateful update files if stateful update is required.
 
-LabTransfer includes:
+LabEndToEndPayloadTransfer includes:
 
   ----Precheck---
   * Pre-check payload's existence on the staging server before auto-update.
@@ -189,23 +189,6 @@
       Dict in the format: {'image_version': 12345.0.0, 'size': 123456789}.
     """
 
-  def _GetPayloadFormat(self):
-    """Gets the payload format that should be evaluated.
-
-    Returns:
-      The payload name as a string.
-    """
-    return self._payload_name
-
-  def _GetPayloadPattern(self):
-    """The regex pattern that the payload format must match.
-
-    Returns:
-      Regular expression.
-    """
-    return _PAYLOAD_PATTERN
-
-
 class LocalTransfer(Transfer):
   """Abstracts logic that handles transferring local files to the DUT."""
 
@@ -304,22 +287,20 @@
         'size': os.path.getsize(payload_filepath)
     }
     if self._payload_name != ROOTFS_FILENAME:
-      payload_format = self._GetPayloadFormat()
-      payload_pattern = self._GetPayloadPattern()
-      m = re.match(payload_pattern, payload_format)
+      m = re.match(_PAYLOAD_PATTERN, self._payload_name)
       if not m:
         raise ValueError(
             'Regular expression %r did not match the expected payload format '
-            '%s' % (payload_pattern, payload_format))
+            '%s' % (_PAYLOAD_PATTERN, self._payload_name))
       values.update(m.groupdict())
     return values
 
 
-class LabTransfer(Transfer):
+class LabEndToEndPayloadTransfer(Transfer):
   """Abstracts logic that transfers files from staging server to the DUT."""
 
   def __init__(self, staging_server, *args, **kwargs):
-    """Initialize LabTransfer to transfer files from staging server to DUT.
+    """Initialize to transfer files from staging server to DUT.
 
     Args:
       staging_server: Url of the server that's staging the payload files.
@@ -329,23 +310,7 @@
           complete list of accepted keyword arguments.
     """
     self._staging_server = staging_server
-    super(LabTransfer, self).__init__(*args, **kwargs)
-
-  def _GetPayloadFormat(self):
-    """Gets the payload format that should be evaluated.
-
-    Returns:
-      The payload dir as a string.
-    """
-    return self._payload_dir
-
-  def _GetPayloadPattern(self):
-    """The regex pattern that the payload format must match.
-
-    Returns:
-      Regular expression.
-    """
-    return r'.*/(R[0-9]+-)(?P<image_version>.+)'
+    super(LabEndToEndPayloadTransfer, self).__init__(*args, **kwargs)
 
   def _RemoteDevserverCall(self, cmd, stdout=False):
     """Runs a command on a remote devserver by sshing into it.
@@ -414,17 +379,27 @@
       payload_dir: Path to the payload directory on the device.
       payload_filename: Name of the file by which the downloaded payload should
         be saved. This is assumed to be the same as the name of the payload.
+        If the payload_name must is in this format:
+        payloads/whatever_file_name, the 'payloads/' at the start will be
+        removed while saving the file as the files need to be saved in specific
+        directories for their subsequent installation. Keeping the 'payloads/'
+        at the beginning of the payload_filename, adds a new directory that
+        messes up its installation.
       build_id: This is the path at which the needed payload can be found. It
         is usually of the format <board_name>-release/R79-12345.6.0. By default,
         the path is set to None.
 
     Returns:
       A fully formed curl command in the format:
-        ['curl', '-o', '<path where payload should be saved>',
-         '<payload download URL>']
+      ['curl', '-o', '<path where payload should be saved>',
+      '<payload download URL>']
     """
-    return ['curl', '-o', os.path.join(payload_dir, payload_filename),
-            self._GetStagedUrl(payload_filename, build_id)]
+    saved_filename = payload_filename
+    if saved_filename.startswith('payloads/'):
+      saved_filename = '/'.join(saved_filename.split('/')[1:])
+    cmd = ['curl', '-o', os.path.join(payload_dir, saved_filename),
+           self._GetStagedUrl(payload_filename, build_id)]
+    return cmd
 
   def _TransferUpdateUtilsPackage(self):
     """Transfer update-utils package to work directory of the remote device.
@@ -550,70 +525,10 @@
       Dict - See parent class's function for full details.
     """
     values = {'size': self._GetPayloadSize()}
-    payload_format = self._GetPayloadFormat()
-    payload_pattern = self._GetPayloadPattern()
-    m = re.match(payload_pattern, payload_format)
+    m = re.match(_PAYLOAD_PATTERN, self._payload_name)
     if not m:
       raise ValueError('Regular expression %r did not match the expected '
-                       'payload format %s' % (payload_pattern, payload_format))
+                       'payload format %s' % (_PAYLOAD_PATTERN,
+                                              self._payload_name))
     values.update(m.groupdict())
     return values
-
-
-class LabEndToEndPayloadTransfer(LabTransfer):
-  """Abstracts logic that transfers files from staging server to the DUT.
-
-  TODO(crbug.com/1061570): AutoUpdate_endToEnd tests stage their payloads in a
-  different location on the devserver in comparison to the provision_AutoUpdate
-  test. Since we are removing the use of the cros_au RPC (see crbug.com/1049708
-  and go/devserver-deprecation) from the EndToEnd tests, it is necessary to
-  extend LabTransfer class to support this new payload staging location.
-  Ideally, the URL at which the payload is staged should be abstracted from the
-  actual transfer of payloads.
-  """
-
-  def _GetPayloadFormat(self):
-    """Gets the payload format that should be evaluated.
-
-    Returns:
-      The payload name as a string.
-    """
-    return self._payload_name
-
-  def _GetPayloadPattern(self):
-    """The regex pattern that the payload format must match.
-
-    Returns:
-      Regular expression.
-    """
-    return _PAYLOAD_PATTERN
-
-  def _GetCurlCmdForPayloadDownload(self, payload_dir, payload_filename,
-                                    build_id=None):
-    """Returns a valid curl command to download payloads into device tmp dir.
-
-    Args:
-      payload_dir: Path to the payload directory on the device.
-      payload_filename: Name of the file by which the downloaded payload should
-        be saved. This is assumed to be the same as the name of the payload.
-        If the payload_name must is in this format:
-        payloads/whatever_file_name, the 'payloads/' at the start will be
-        removed while saving the file as the files need to be saved in specific
-        directories for their subsequent installation. Keeping the 'payloads/'
-        at the beginning of the payload_filename, adds a new directory that
-        messes up its installation.
-      build_id: This is the path at which the needed payload can be found. It
-        is usually of the format <board_name>-release/R79-12345.6.0. By default,
-        the path is set to None.
-
-    Returns:
-      A fully formed curl command in the format:
-      ['curl', '-o', '<path where payload should be saved>',
-      '<payload download URL>']
-    """
-    saved_filename = payload_filename
-    if saved_filename.startswith('payloads/'):
-      saved_filename = '/'.join(saved_filename.split('/')[1:])
-    cmd = ['curl', '-o', os.path.join(payload_dir, saved_filename),
-           self._GetStagedUrl(payload_filename, build_id)]
-    return cmd
diff --git a/lib/auto_updater_transfer_unittest.py b/lib/auto_updater_transfer_unittest.py
index 8000f16..e647b2c 100644
--- a/lib/auto_updater_transfer_unittest.py
+++ b/lib/auto_updater_transfer_unittest.py
@@ -231,31 +231,33 @@
       expected = {'image_version': '99999.0.0', 'size': 101}
       self.assertDictEqual(transfer.GetPayloadProps(), expected)
 
-class CrosLabTransferTest(cros_test_lib.MockTempDirTestCase):
-  """Test all methods in auto_updater_transfer.LabTransfer."""
+class CrosLabEndToEndPayloadTransferTest(cros_test_lib.MockTempDirTestCase):
+  """Test all methods in auto_updater_transfer.LabEndToEndPayloadTransfer."""
 
   def CreateInstance(self, device, **kwargs):
-    """Create auto_updater_transfer.LabTransfer instance.
+    """Create auto_updater_transfer.LabEndToEndPayloadTransfer instance.
 
     Args:
       device: a remote_access.ChromiumOSDeviceHandler object.
       kwargs: contains parameter name and value pairs for any argument accepted
-        by auto_updater_transfer.LabTransfer. The values provided through
-        kwargs will supersede the defaults set within this function.
+        by auto_updater_transfer.LabEndToEndPayloadTransfer. The values provided
+        through kwargs will supersede the defaults set within this function.
 
     Returns:
-      An instance of auto_updater_transfer.LabTransfer.
+      An instance of auto_updater_transfer.LabEndToEndPayloadTransfer.
     """
     default_args = copy.deepcopy(_DEFAULT_ARGS)
     default_args['staging_server'] = 'http://0.0.0.0:8000'
 
     default_args.update(kwargs)
-    return auto_updater_transfer.LabTransfer(device=device, **default_args)
+    return auto_updater_transfer.LabEndToEndPayloadTransfer(device=device,
+                                                            **default_args)
+
 
   def setUp(self):
     """Mock remote_access.RemoteDevice/ChromiumOSDevice functions for update."""
     self.PatchObject(remote_access.RemoteDevice, 'work_dir', '/test/work/dir')
-    self._transfer_class = auto_updater_transfer.LabTransfer
+    self._transfer_class = auto_updater_transfer.LabEndToEndPayloadTransfer
 
   def testTransferUpdateUtilsCurlCalls(self):
     """Test methods calls of _TransferUpdateUtilsPackage().
@@ -285,7 +287,7 @@
     """
     with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
       transfer = self.CreateInstance(device)
-      self._transfer_class = auto_updater_transfer.LabTransfer
+      self._transfer_class = auto_updater_transfer.LabEndToEndPayloadTransfer
       expected = [['curl', '-o', '/test/work/dir/src/nebraska.py',
                    'http://0.0.0.0:8000/static/nebraska.py']]
 
@@ -552,12 +554,12 @@
       transfer = self.CreateInstance(device)
       expected_cmd = ['curl', '-o',
                       '/tmp/test_payload_dir/payload_filename.ext',
-                      'http://0.0.0.0:8000/static/board-release/12345.0.0/'
-                      'payload_filename.ext']
+                      'http://0.0.0.0:8000/static/stable-channel/board/'
+                      '12345.0.0/payloads/payload_filename.ext']
       cmd = transfer._GetCurlCmdForPayloadDownload(
           payload_dir='/tmp/test_payload_dir',
-          payload_filename='payload_filename.ext',
-          build_id='board-release/12345.0.0/')
+          payload_filename='payloads/payload_filename.ext',
+          build_id='stable-channel/board/12345.0.0')
       self.assertEqual(cmd, expected_cmd)
 
   def testGetCurlCmdNoImageName(self):
@@ -848,28 +850,6 @@
       self.assertRaises(auto_updater_transfer.ChromiumOSTransferError,
                         transfer._GetPayloadSize)
 
-  def testGetPayloadPropsLab(self):
-    """Test GetPayloadProps()."""
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      transfer = self.CreateInstance(
-          device, payload_dir='test-board-name/R77-12345.0.0')
-      self.PatchObject(self._transfer_class, '_GetPayloadSize',
-                       return_value=123)
-      expected = {'image_version': '12345.0.0', 'size': 123}
-      self.assertDictEqual(transfer.GetPayloadProps(), expected)
-
-  def testGetPayloadPropsLabError(self):
-    """Test error thrown by GetPayloadProps().
-
-    Test error thrown when payload_dir is not in the expected format of
-    <board-name>/Rxx-12345.6.7.
-    """
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      transfer = self.CreateInstance(
-          device, payload_dir='/wrong/format/will/fail')
-      self.PatchObject(self._transfer_class, '_GetPayloadSize')
-      self.assertRaises(ValueError, transfer.GetPayloadProps)
-
   def test_RemoteDevserverCall(self):
     """Test _RemoteDevserverCall()."""
     with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
@@ -910,96 +890,3 @@
       self.assertRaises(cros_build_lib.RunCommandError,
                         transfer._RemoteDevserverCall,
                         cmd=['test', 'command'])
-
-
-class CrosLabEndToEndPayloadTransferTest(cros_test_lib.MockTempDirTestCase):
-  """Test all methods in LabEndToEndPayloadTransfer()."""
-
-  def CreateInstance(self, device, **kwargs):
-    """Create auto_updater_transfer.LabEndToEndPayloadTransfer instance.
-
-    Args:
-      device: a remote_access.ChromiumOSDeviceHandler object.
-      kwargs: contains parameter name and value pairs for any argument accepted
-        by auto_updater_transfer.LabEndToEndPayloadTransfer. The values provided
-        through kwargs will supersede the defaults set within this function.
-
-    Returns:
-      An instance of auto_updater_transfer.LabEndToEndPayloadTransfer.
-    """
-    default_args = copy.deepcopy(_DEFAULT_ARGS)
-    default_args['staging_server'] = 'http://0.0.0.0:8000'
-
-    default_args.update(kwargs)
-    return auto_updater_transfer.LabEndToEndPayloadTransfer(device=device,
-                                                            **default_args)
-
-  def setUp(self):
-    """Mock remote_access.RemoteDevice/ChromiumOSDevice functions for update."""
-    self.PatchObject(remote_access.RemoteDevice, 'work_dir', '/test/work/dir')
-    self._transfer_class = auto_updater_transfer.LabEndToEndPayloadTransfer
-
-  def testGetPayloadProps(self):
-    """Test GetPayloadProps()."""
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      payload_name = 'payloads/chromeos_12345.0.0_board_channel_test.bin-blah'
-      transfer = self.CreateInstance(
-          device, payload_name=payload_name)
-      self.PatchObject(self._transfer_class, '_GetPayloadSize',
-                       return_value=123)
-      expected = {'image_version': '12345.0.0', 'size': 123}
-      self.assertDictEqual(transfer.GetPayloadProps(), expected)
-
-  def testGetPayloadPropsEndError(self):
-    """Test error thrown by GetPayloadProps().
-
-    Test error thrown when payload_name is not in the expected format of
-    payloads/chromeos_12345.0.0_board_channel_full_test.bin-blah.
-    """
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      transfer = self.CreateInstance(
-          device, payload_name='/wrong/format/will/fail')
-      self.PatchObject(self._transfer_class, '_GetPayloadSize')
-      self.assertRaises(ValueError, transfer.GetPayloadProps)
-
-  def testLabGetCurlCmdStandard(self):
-    """Test _GetCurlCmdForPayloadDownload().
-
-    Tests the typical usage of the _GetCurlCmdForPayloadDownload() method.
-    """
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      transfer = self.CreateInstance(device)
-      expected_cmd = ['curl', '-o',
-                      '/tmp/test_payload_dir/payload_filename.ext',
-                      'http://0.0.0.0:8000/static/stable-channel/board/'
-                      '12345.0.0/payloads/payload_filename.ext']
-      cmd = transfer._GetCurlCmdForPayloadDownload(
-          payload_dir='/tmp/test_payload_dir',
-          payload_filename='payloads/payload_filename.ext',
-          build_id='stable-channel/board/12345.0.0')
-      self.assertEqual(cmd, expected_cmd)
-
-  def testGetPayloadPropsFile(self):
-    """Test GetPayloadPropsFile()."""
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      payload_name = 'payloads/test_update.gz'
-      payload_props_path = os.path.join(self.tempdir, payload_name + '.json')
-      output = ('{"appid": "{0BB3F9E1-A066-9352-50B8-5C1356D09AEB}", '
-                '"is_delta": false, "metadata_signature": null, '
-                '"metadata_size": 57053, '
-                '"sha256_hex": "aspPgQRWLu5wPM5NucqAYVmVCvL5lxQJ/n9ckhZS83Y=", '
-                '"size": 998103540, '
-                '"target_version": "99999.0.0", "version": 2}')
-      bin_op = six.ensure_binary(output)
-
-      transfer = self.CreateInstance(
-          device, tempdir=self.tempdir, payload_name=payload_name)
-
-      self.PatchObject(self._transfer_class, '_RemoteDevserverCall',
-                       return_value=cros_build_lib.CommandResult(stdout=bin_op))
-      transfer.GetPayloadPropsFile()
-      props = osutils.ReadFile(payload_props_path)
-
-      self.assertEqual(props, output)
-      self.assertEqual(transfer._local_payload_props_path,
-                       payload_props_path)
diff --git a/lib/auto_updater_unittest.py b/lib/auto_updater_unittest.py
index c5f6be9..4bdf1ab 100644
--- a/lib/auto_updater_unittest.py
+++ b/lib/auto_updater_unittest.py
@@ -263,40 +263,6 @@
     }
     self.assertEqual(props, expected_props)
 
-  def test_FixPayloadPropertiesFileLab(self):
-    """Tests _FixPayloadPropertiesFile() correctly fixes the properties file.
-
-    Tests if the payload properties file gets filled with correct data when
-    LabTransfer methods are invoked internally.
-    """
-    payload_dir = 'nyan_kitty-release/R76-12345.17.0'
-    payload_path = os.path.join(self.tempdir, 'test_update.gz')
-    payload_properties_path = payload_path + '.json'
-    osutils.WriteFile(payload_path, 'dummy-payload', makedirs=True)
-    # Empty properties file.
-    osutils.WriteFile(payload_properties_path, '{}')
-    with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
-      CrOS_AU = auto_updater.ChromiumOSUpdater(
-          device, None, payload_dir=payload_dir,
-          transfer_class=auto_updater_transfer.LabTransfer,
-          staging_server='http://0.0.0.0:8082')
-
-      self.PatchObject(auto_updater_transfer.LabTransfer, 'GetPayloadPropsFile',
-                       return_value=payload_properties_path)
-      self.PatchObject(auto_updater_transfer.LabTransfer, '_GetPayloadSize',
-                       return_value=os.path.getsize(payload_path))
-      CrOS_AU._FixPayloadPropertiesFile() # pylint: disable=protected-access
-
-    # The payload properties file should be updated with new fields.
-    props = json.loads(osutils.ReadFile(payload_properties_path))
-    expected_props = {
-        'appid': '',
-        'is_delta': False,
-        'size': os.path.getsize(payload_path),
-        'target_version': '12345.17.0',
-    }
-    self.assertEqual(props, expected_props)
-
   def testRunRootfs(self):
     """Test the update functions are called correctly.
 
@@ -403,33 +369,32 @@
       self.assertTrue(
           auto_updater_transfer.LocalTransfer.GetPayloadProps.called)
 
-  def test_FixPayloadLabTransfer(self):
-    """Tests if correct LabTransfer methods are called."""
+  def test_FixPayloadLabEndToEndPayloadTransfer(self):
+    """Tests if correct LabEndToEndPayloadTransfer methods are called."""
     payload_dir = 'nyan_kitty-release/R76-12345.17.0'
     payload_path = os.path.join(self.tempdir, 'test_update.gz')
     payload_properties_path = payload_path + '.json'
     osutils.WriteFile(payload_path, 'dummy-payload', makedirs=True)
     # Empty properties file.
     osutils.WriteFile(payload_properties_path, '{}')
+    transfer_class = auto_updater_transfer.LabEndToEndPayloadTransfer
 
     with remote_access.ChromiumOSDeviceHandler(remote_access.TEST_IP) as device:
       CrOS_AU = auto_updater.ChromiumOSUpdater(
           device, None, payload_dir=payload_dir,
-          transfer_class=auto_updater_transfer.LabTransfer,
+          transfer_class=transfer_class,
           staging_server='http://0.0.0.0:8082')
 
+      self.PatchObject(transfer_class,
+                       'GetPayloadPropsFile',
+                       return_value=payload_properties_path)
       self.PatchObject(
-          auto_updater_transfer.LabTransfer, 'GetPayloadPropsFile',
-          return_value=payload_properties_path)
-      self.PatchObject(
-          auto_updater_transfer.LabTransfer, 'GetPayloadProps',
+          transfer_class, 'GetPayloadProps',
           return_value={'size': '123', 'image_version': '99999.9.9'})
 
       CrOS_AU._FixPayloadPropertiesFile() # pylint: disable=protected-access
-      self.assertTrue(
-          auto_updater_transfer.LabTransfer.GetPayloadPropsFile.called)
-      self.assertTrue(
-          auto_updater_transfer.LabTransfer.GetPayloadProps.called)
+      self.assertTrue(transfer_class.GetPayloadPropsFile.called)
+      self.assertTrue(transfer_class.GetPayloadProps.called)
 
 
 class ChromiumOSUpdaterVerifyTest(ChromiumOSUpdaterBaseTest):