cellular: Migrate network_3GModemControl to new test_environment

BUG=chromium:415293
TEST=Run network_3GModemControl on E362, Gobi3k, hefty, pseudomodem

Change-Id: Id28e86479b7386290a8b06458ccd7f7f4097db97
Reviewed-on: https://chromium-review.googlesource.com/220964
Tested-by: Thieu Le <thieule@chromium.org>
Commit-Queue: Thieu Le <thieule@chromium.org>
Reviewed-by: Thieu Le <thieule@chromium.org>
diff --git a/client/cros/cellular/modem1.py b/client/cros/cellular/modem1.py
index 0519e3c..3449113 100644
--- a/client/cros/cellular/modem1.py
+++ b/client/cros/cellular/modem1.py
@@ -133,12 +133,12 @@
     def GetCurrentTechnologyFamily(self):
         """Returns the modem technology family."""
         props = self.GetAll(mm1.MODEM_INTERFACE)
-        sim = props.get('Sim')
-        log.debug('Modem.Sim = %s' % sim)
-        if sim is not None:
-            return cellular.TechnologyFamily.UMTS
-        else:
+        capabilities = props.get('SupportedCapabilities')
+        if self._IsCDMAModem(capabilities):
             return cellular.TechnologyFamily.CDMA
+        if self._Is3GPPModem(capabilities):
+            return cellular.TechnologyFamily.UMTS
+        raise error.TestError('Invalid modem type')
 
     def GetVersion(self):
         """Returns the modem version information."""
diff --git a/client/cros/cellular/test_environment.py b/client/cros/cellular/test_environment.py
index 93293a2..723343d 100644
--- a/client/cros/cellular/test_environment.py
+++ b/client/cros/cellular/test_environment.py
@@ -134,6 +134,10 @@
     def __exit__(self, exception, value, traceback):
         if self._nested:
             return self._nested.__exit__(exception, value, traceback)
+        self.shill = None
+        self.flim = None
+        self.modem_manager = None
+        self.modem = None
 
 
     def _get_shill_cellular_device_object(self):
diff --git a/client/cros/networking/cellular_proxy.py b/client/cros/networking/cellular_proxy.py
index d4277ab..b63b18f 100644
--- a/client/cros/networking/cellular_proxy.py
+++ b/client/cros/networking/cellular_proxy.py
@@ -21,6 +21,10 @@
     DEVICE_PROPERTY_TECHNOLOGY_FAMILY = 'Cellular.Family'
     DEVICE_PROPERTY_TECHNOLOGY_FAMILY_CDMA = 'CDMA'
     DEVICE_PROPERTY_TECHNOLOGY_FAMILY_GSM = 'GSM'
+    SERVICE_PROPERTY_LAST_GOOD_APN = 'Cellular.LastGoodAPN'
+
+    # APN info property names.
+    APN_INFO_PROPERTY_APN = 'apn'
 
     # Keys into the dictionaries exposed as properties.
     PROPERTY_KEY_SIM_LOCK_TYPE = 'LockType'
diff --git a/client/site_tests/network_3GModemControl/control b/client/site_tests/network_3GModemControl/control
index 4545752..602b223 100644
--- a/client/site_tests/network_3GModemControl/control
+++ b/client/site_tests/network_3GModemControl/control
@@ -21,5 +21,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False, tag='no-autoconnect')
-job.run_test('network_3GModemControl', autoconnect=True, tag='autoconnect')
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
+             tag='no-autoconnect')
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
+             tag='autoconnect')
diff --git a/client/site_tests/network_3GModemControl/control.alt3100 b/client/site_tests/network_3GModemControl/control.alt3100
index e5de2ef..202e4b7 100644
--- a/client/site_tests/network_3GModemControl/control.alt3100
+++ b/client/site_tests/network_3GModemControl/control.alt3100
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-alt3100')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-alt3100')
diff --git a/client/site_tests/network_3GModemControl/control.clumsy b/client/site_tests/network_3GModemControl/control.clumsy
index c43fe77..6b8da7a 100644
--- a/client/site_tests/network_3GModemControl/control.clumsy
+++ b/client/site_tests/network_3GModemControl/control.clumsy
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-clumsy')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-clumsy')
diff --git a/client/site_tests/network_3GModemControl/control.e362 b/client/site_tests/network_3GModemControl/control.e362
index 4133bef..2b74fd0 100644
--- a/client/site_tests/network_3GModemControl/control.e362
+++ b/client/site_tests/network_3GModemControl/control.e362
@@ -30,11 +30,14 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
+from autotest_lib.client.cros.cellular import test_environment
+
 # For E362 modems, we need to prevent the modem from disconnecting too quickly
 # or else the out-of-credits logic will kick in and attempt to reconnect (see
 # shill/cellular_service.cc).  This is accomplished by setting |slow_connect|
 # to True.
-job.run_test('network_3GModemControl', autoconnect=False, slow_connect=True,
-             tag='no-autoconnect-e362')
-job.run_test('network_3GModemControl', autoconnect=True, slow_connect=True,
-             tag='autoconnect-e362')
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
+             slow_connect=True, tag='no-autoconnect-e362')
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
+             slow_connect=True, tag='autoconnect-e362')
diff --git a/client/site_tests/network_3GModemControl/control.gobi2k b/client/site_tests/network_3GModemControl/control.gobi2k
index 90d26b9..c65b4f8 100644
--- a/client/site_tests/network_3GModemControl/control.gobi2k
+++ b/client/site_tests/network_3GModemControl/control.gobi2k
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-gobi2k')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-gobi2k')
diff --git a/client/site_tests/network_3GModemControl/control.gobi3k b/client/site_tests/network_3GModemControl/control.gobi3k
index 913e3b3..a13aecb 100644
--- a/client/site_tests/network_3GModemControl/control.gobi3k
+++ b/client/site_tests/network_3GModemControl/control.gobi3k
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-gobi3k')
diff --git a/client/site_tests/network_3GModemControl/control.hefty b/client/site_tests/network_3GModemControl/control.hefty
index 96b1735..c460f6c 100644
--- a/client/site_tests/network_3GModemControl/control.hefty
+++ b/client/site_tests/network_3GModemControl/control.hefty
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-hefty')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-hefty')
diff --git a/client/site_tests/network_3GModemControl/control.mu736 b/client/site_tests/network_3GModemControl/control.mu736
index 9c1c67e..3b7f8ea 100644
--- a/client/site_tests/network_3GModemControl/control.mu736
+++ b/client/site_tests/network_3GModemControl/control.mu736
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-mu736')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-mu736')
diff --git a/client/site_tests/network_3GModemControl/control.pseudomodem b/client/site_tests/network_3GModemControl/control.pseudomodem
index 61c6b92..2fca415 100644
--- a/client/site_tests/network_3GModemControl/control.pseudomodem
+++ b/client/site_tests/network_3GModemControl/control.pseudomodem
@@ -24,18 +24,20 @@
   be run on a virtual machine.
 """
 
+from autotest_lib.client.cros.cellular import test_environment
+
 # 3GPP
-job.run_test('network_3GModemControl', pseudo_modem=True,
-             autoconnect=False, tag='no-autoconnect-pseudomodem.3GPP')
-job.run_test('network_3GModemControl', pseudo_modem=True,
-             autoconnect=True, tag='autoconnect-pseudomodem.3GPP')
+test_env = test_environment.CellularPseudoMMTestEnvironment(
+        pseudomm_args=({'family': '3GPP'},))
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
+             tag='no-autoconnect-pseudomodem.3GPP')
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
+             tag='autoconnect-pseudomodem.3GPP')
 
 # CDMA
-job.run_test('network_3GModemControl', pseudo_modem=True,
-             pseudomodem_family='CDMA',
-             autoconnect=False,
+test_env = test_environment.CellularPseudoMMTestEnvironment(
+        pseudomm_args=({'family': 'CDMA'},))
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-pseudomodem.CDMA')
-job.run_test('network_3GModemControl', pseudo_modem=True,
-             pseudomodem_family='CDMA',
-             autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-pseudomodem.CDMA')
diff --git a/client/site_tests/network_3GModemControl/control.wooly b/client/site_tests/network_3GModemControl/control.wooly
index 8680676..4bae4a5 100644
--- a/client/site_tests/network_3GModemControl/control.wooly
+++ b/client/site_tests/network_3GModemControl/control.wooly
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-wooly')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-wooly')
diff --git a/client/site_tests/network_3GModemControl/control.y3300 b/client/site_tests/network_3GModemControl/control.y3300
index b5bfdd6..3c41fe7 100644
--- a/client/site_tests/network_3GModemControl/control.y3300
+++ b/client/site_tests/network_3GModemControl/control.y3300
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-y3300')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-y3300')
diff --git a/client/site_tests/network_3GModemControl/control.y3400 b/client/site_tests/network_3GModemControl/control.y3400
index c30927f..a9eb9af 100644
--- a/client/site_tests/network_3GModemControl/control.y3400
+++ b/client/site_tests/network_3GModemControl/control.y3400
@@ -23,7 +23,10 @@
   if the commands are sent to the modem manager instead of flimflam.
 """
 
-job.run_test('network_3GModemControl', autoconnect=False,
+from autotest_lib.client.cros.cellular import test_environment
+
+test_env = test_environment.CellularOTATestEnvironment()
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=False,
              tag='no-autoconnect-y3400')
-job.run_test('network_3GModemControl', autoconnect=True,
+job.run_test('network_3GModemControl', test_env=test_env, autoconnect=True,
              tag='autoconnect-y3400')
diff --git a/client/site_tests/network_3GModemControl/network_3GModemControl.py b/client/site_tests/network_3GModemControl/network_3GModemControl.py
index 1232f7a..52c425d 100644
--- a/client/site_tests/network_3GModemControl/network_3GModemControl.py
+++ b/client/site_tests/network_3GModemControl/network_3GModemControl.py
@@ -9,14 +9,10 @@
 
 from autotest_lib.client.bin import test, utils
 from autotest_lib.client.common_lib import error
-from autotest_lib.client.cros import backchannel
 from autotest_lib.client.cros.cellular import cell_tools
-from autotest_lib.client.cros.cellular import emulator_config
-from autotest_lib.client.cros.cellular import mm
-from autotest_lib.client.cros.cellular.pseudomodem import pseudomodem_context
-
-from autotest_lib.client.cros import flimflam_test_path
-import flimflam
+from autotest_lib.client.cros.cellular import cellular
+from autotest_lib.client.cros.networking import cellular_proxy
+from autotest_lib.client.cros.networking import shill_proxy
 
 # Number of seconds we wait for the cellular service to perform an action.
 DEVICE_TIMEOUT=45
@@ -32,16 +28,18 @@
 
 
 class TechnologyCommands():
-    """Control the modem mostly using flimflam Technology interfaces."""
-    def __init__(self, flim, command_delegate):
-        self.flim = flim
+    """Control the modem mostly using shill Technology interfaces."""
+    def __init__(self, shill, command_delegate):
+        self.shill = shill
         self.command_delegate = command_delegate
 
     def Enable(self):
-        self.flim.EnableTechnology('cellular')
+        self.shill.manager.EnableTechnology(
+                shill_proxy.ShillProxy.TECHNOLOGY_CELLULAR)
 
     def Disable(self):
-        self.flim.DisableTechnology('cellular')
+        self.shill.manager.DisableTechnology(
+                shill_proxy.ShillProxy.TECHNOLOGY_CELLULAR)
 
     def Connect(self, **kwargs):
         self.command_delegate.Connect(**kwargs)
@@ -76,15 +74,13 @@
         Disconnect Modem.
 
         Returns:
-            True - to indicate that flimflam may autoconnect again.
+            True - to indicate that shill may autoconnect again.
         """
         try:
             self.modem.Disconnect()
-        except dbus.exceptions.DBusException, e:
-            if e._dbus_error_name == ('org.chromium.ModemManager'
-                                      '.Error.OperationInitiated'):
-                pass
-            else:
+        except dbus.DBusException as e:
+            if (e.get_dbus_name() !=
+                    'org.chromium.ModemManager.Error.OperationInitiated'):
                 raise e
         return True
 
@@ -93,15 +89,15 @@
 
 
 class DeviceCommands():
-    """Control the modem using flimflam device interfaces."""
-    def __init__(self, flim, device, slow_connect):
-        self.flim = flim
+    """Control the modem using shill device interfaces."""
+    def __init__(self, shill, device, slow_connect):
+        self.shill = shill
         self.device = device
         self.slow_connect = slow_connect
         self.service = None
 
     def GetService(self):
-        service = self.flim.FindCellularService()
+        service = self.shill.find_cellular_service_object()
         if not service:
             raise error.TestFail(
                 'Service failed to appear when using device commands.')
@@ -124,7 +120,7 @@
         Disconnect Modem.
 
         Returns:
-            False - to indicate that flimflam may not autoconnect again.
+            False - to indicate that shill may not autoconnect again.
         """
         self.GetService().Disconnect()
         return False
@@ -173,14 +169,14 @@
         return modem.IsEnabled() == expected_state
 
     def CompareDevicePowerState(self, device, expected_state):
-        """Compare the flimflam device power state to an expected state."""
+        """Compare the shill device power state to an expected state."""
         device_properties = device.GetProperties(utf8_strings=True);
         state = device_properties['Powered']
         logging.info('Device Enabled = %s' % state)
         return state == expected_state
 
     def CompareServiceState(self, service, expected_states):
-        """Compare the flimflam service state to a set of expected states."""
+        """Compare the shill service state to a set of expected states."""
         if not service:
             logging.info('Service not found.')
             return False
@@ -203,7 +199,7 @@
         # attempts.
         for _ in range(NUM_MODEM_STATE_CHECKS):
             utils.poll_for_condition(
-                lambda: not self.modem.IsConnectingOrDisconnecting(),
+                lambda: not self.test_env.modem.IsConnectingOrDisconnecting(),
                 error.TestFail('Timed out waiting for modem to finish ' +
                                'connecting or disconnecting.'),
                 timeout=SERVICE_TIMEOUT)
@@ -217,13 +213,13 @@
             error.TestFail if the states are not consistent.
         """
         utils.poll_for_condition(
-            lambda: self.CompareModemPowerState(self.modem, False),
+            lambda: self.CompareModemPowerState(self.test_env.modem, False),
             error.TestFail('Modem failed to enter state Disabled.'))
         utils.poll_for_condition(
             lambda: self.CompareDevicePowerState(self.device, False),
             error.TestFail('Device failed to enter state Powered=False.'))
         utils.poll_for_condition(
-            lambda: not self.flim.FindCellularService(timeout=1),
+            lambda: not self.test_env.shill.find_cellular_service_object(),
             error.TestFail('Service should not be available.'),
             timeout=SERVICE_TIMEOUT)
 
@@ -240,18 +236,17 @@
             error.TestFail if the states are not consistent.
         """
         utils.poll_for_condition(
-            lambda: self.CompareModemPowerState(self.modem, True),
+            lambda: self.CompareModemPowerState(self.test_env.modem, True),
             error.TestFail('Modem failed to enter state Enabled'))
         utils.poll_for_condition(
             lambda: self.CompareDevicePowerState(self.device, True),
             error.TestFail('Device failed to enter state Powered=True.'),
             timeout=30)
 
+        service = self.test_env.shill.wait_for_cellular_service_object()
         if check_idle:
             utils.poll_for_condition(
-                lambda: self.CompareServiceState(
-                    self.flim.FindCellularService(timeout=SERVICE_TIMEOUT),
-                    ['idle']),
+                lambda: self.CompareServiceState(service, ['idle']),
                 error.TestFail('Service failed to enter idle state.'),
                 timeout=SERVICE_TIMEOUT)
 
@@ -264,8 +259,9 @@
         """
         self.EnsureEnabled(check_idle=False)
         utils.poll_for_condition(
-            lambda: self.CompareServiceState(self.flim.FindCellularService(),
-                                             ['ready', 'portal', 'online']),
+            lambda: self.CompareServiceState(
+                    self.test_env.shill.find_cellular_service_object(),
+                    ['ready', 'portal', 'online']),
             error.TestFail('Service failed to connect.'),
             timeout=SERVICE_TIMEOUT)
 
@@ -276,7 +272,7 @@
 
         Changes the state of the modem in various ways including
         disable while connected and then verifies the state of the
-        modem manager and flimflam.
+        modem manager and shill.
 
         Raises:
             error.TestFail if the states are not consistent.
@@ -288,7 +284,8 @@
         commands.Enable()
         self.EnsureEnabled(check_idle=not self.autoconnect)
 
-        if self.pseudo_modem and self.pseudomodem_family == 'CDMA':
+        technology_family = self.test_env.modem.GetCurrentTechnologyFamily()
+        if technology_family == cellular.TechnologyFamily.CDMA:
             simple_connect_props = {'number': r'#777'}
         else:
             simple_connect_props = {'number': r'#777', 'apn': self.FindAPN()}
@@ -336,70 +333,50 @@
         self.EnsureDisabled()
 
     def FindAPN(self):
-        return cell_tools.FindLastGoodAPN(self.flim.FindCellularService(),
-                                          default='None')
+        default = 'None'
+        service = self.test_env.shill.find_cellular_service_object()
+        props = service.GetProperties()
+        last_good_apn = props.get(
+                cellular_proxy.CellularProxy.SERVICE_PROPERTY_LAST_GOOD_APN,
+                None)
+        if not last_good_apn:
+            return default
+        return last_good_apn.get(
+                cellular_proxy.CellularProxy.APN_INFO_PROPERTY_APN, default)
 
-    def run_once(self, autoconnect,
-                 pseudo_modem=False,
-                 pseudomodem_family='3GPP',
-                 mixed_iterations=2,
-                 config=None, technology=None, slow_connect=False):
-        # Use a backchannel so that flimflam will restart when the
-        # test is over.  This ensures flimflam is in a known good
-        # state even if this test fails.
-        with backchannel.Backchannel():
-            self.autoconnect = autoconnect
-            self.pseudo_modem = pseudo_modem
-            self.pseudomodem_family = pseudomodem_family
+    def run_once(self, test_env, autoconnect, mixed_iterations=2,
+                 slow_connect=False):
+        self.test_env = test_env
+        self.autoconnect = autoconnect
 
-            if config and technology:
-                bs, verifier = emulator_config.StartDefault(config, technology)
-                cell_tools.PrepareModemForTechnology('', technology)
+        with test_env:
+            self.device = self.test_env.shill.find_cellular_device_object()
 
-                # Clear all errors before we start.
-                # Preparing the modem above may have caused some errors on the
-                # 8960 (eg. lost connection, etc).
-                bs.ClearErrors()
+            modem_commands = ModemCommands(self.test_env.modem,
+                                           slow_connect)
+            technology_commands = TechnologyCommands(self.test_env.shill,
+                                                     modem_commands)
+            device_commands = DeviceCommands(self.test_env.shill,
+                                             self.device,
+                                             slow_connect)
 
-            with pseudomodem_context.PseudoModemManagerContext(
-                pseudo_modem,
-                {'family' : pseudomodem_family}):
-                self.flim = flimflam.FlimFlam()
+            with cell_tools.AutoConnectContext(self.device,
+                                               self.test_env.flim,
+                                               autoconnect):
+                # Start with cellular disabled.
+                self.test_env.shill.manager.DisableTechnology(
+                        shill_proxy.ShillProxy.TECHNOLOGY_CELLULAR)
+                self.EnsureDisabled()
 
-                # Enabling flimflam debugging makes it easier to debug
-                # problems.  Tags will be cleared when the Backchannel
-                # context exits and flimflam is restarted.
-                self.flim.SetDebugTags(
-                    'dbus+service+device+modem+cellular+portal+network+'
-                    'manager+dhcp')
+                # Run the device commands test first to make sure we have
+                # a valid APN needed to connect using the modem commands.
+                self.TestCommands(device_commands)
+                self.TestCommands(technology_commands)
+                self.TestCommands(modem_commands)
 
-                self.device = self.flim.FindCellularDevice()
-                if not self.device:
-                    raise error.TestFail('Failed to find a cellular device.')
-                manager, modem_path = mm.PickOneModem('')
-                self.modem = manager.GetModem(modem_path)
-
-                modem_commands = ModemCommands(self.modem, slow_connect)
-                technology_commands = TechnologyCommands(self.flim,
-                                                         modem_commands)
-                device_commands = DeviceCommands(self.flim, self.device,
-                                                 slow_connect)
-
-                with cell_tools.AutoConnectContext(self.device, self.flim,
-                                                   autoconnect):
-                    # Get to a well known state.
-                    self.flim.DisableTechnology('cellular')
-                    self.EnsureDisabled()
-
-                    # Run the device commands test first to make sure we have
-                    # a valid APN needed to connect using the modem commands.
-                    self.TestCommands(device_commands)
-                    self.TestCommands(technology_commands)
-                    self.TestCommands(modem_commands)
-
-                    # Run several times using commands mixed from each type
-                    mixed = MixedRandomCommands([modem_commands,
-                                                 technology_commands,
-                                                 device_commands])
-                    for _ in range(mixed_iterations):
-                        self.TestCommands(mixed)
+                # Run several times using commands mixed from each type
+                mixed = MixedRandomCommands([modem_commands,
+                                             technology_commands,
+                                             device_commands])
+                for _ in range(mixed_iterations):
+                    self.TestCommands(mixed)