def testStatefulUpdateCmdError(self): """Test ChromiumOSUpdater.UpdateStateful with raising exception. StatefulUpdateError is raised if device fails to update stateful partition. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater( device, None, self._payload_dir, do_rootfs_update=False, transfer_class=auto_updater_transfer.LocalTransfer) self.PatchObject( remote_access.ChromiumOSDevice, 'run', side_effect=cros_build_lib.RunCommandError('fail')) self.PatchObject(stateful_updater.StatefulUpdater, 'Update', side_effect=stateful_updater.Error()) self.PatchObject(stateful_updater.StatefulUpdater, 'Reset', side_effect=stateful_updater.Error()) self.assertRaises(auto_updater.StatefulUpdateError, CrOS_AU.RunUpdate)
def testRootfsUpdateTrackError(self): """Test ChromiumOSUpdater.UpdateRootfs with raising exception. RootfsUpdateError is raised if it fails to track device's status by GetUpdateStatus. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater( device, None, self._payload_dir, transfer_class=auto_updater_transfer.LocalTransfer) self.prepareRootfsUpdate() self.PatchObject(nebraska_wrapper.RemoteNebraskaWrapper, 'Start') self.PatchObject(nebraska_wrapper.RemoteNebraskaWrapper, 'GetURL') self.PatchObject(remote_access.ChromiumOSDevice, 'run') self.PatchObject( auto_updater.ChromiumOSUpdater, 'GetUpdateStatus', side_effect=ValueError('Cannot get update status')) self.PatchObject(auto_updater.ChromiumOSUpdater, '_FixPayloadPropertiesFile') with mock.patch('os.path.join', return_value=''): self.assertRaises(auto_updater.RootfsUpdateError, CrOS_AU.RunUpdate)
def testRootfsUpdateIdleError(self): """Test ChromiumOSUpdater.UpdateRootfs with raising exception. RootfsUpdateError is raised if the update engine goes to idle state after downloading. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater( device, None, self._payload_dir, transfer_class=auto_updater_transfer.LocalTransfer) self.prepareRootfsUpdate() self.PatchObject(nebraska_wrapper.RemoteNebraskaWrapper, 'Start') self.PatchObject(nebraska_wrapper.RemoteNebraskaWrapper, 'GetURL') mock_run = self.PatchObject(remote_access.ChromiumOSDevice, 'run') self.PatchObject(auto_updater.ChromiumOSUpdater, 'GetUpdateStatus', side_effect=( ('UPDATE_STATUS_DOWNLOADING', '0.5'), ('UPDATE_STATUS_DOWNLOADING', '0.9'), ('UPDATE_STATUS_FINALIZING', 0), ('UPDATE_STATUS_IDLE', 0), )) self.PatchObject(auto_updater.ChromiumOSUpdater, '_FixPayloadPropertiesFile') patch_join = mock.patch('os.path.join', return_value='') patch_sleep = mock.patch('time.sleep') with patch_sleep as mock_sleep, patch_join as _: self.assertRaises(auto_updater.RootfsUpdateError, CrOS_AU.RunUpdate) mock_sleep.assert_called() mock_run.assert_any_call(['cat', '/var/log/update_engine.log'])
def testRootfsUpdateCmdError(self): """Test ChromiumOSUpdater.UpdateRootfs with raising exception. RootfsUpdateError is raised if device fails to run rootfs update command 'update_engine_client ...'. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater( device, None, self._payload_dir, transfer_class=auto_updater_transfer.LocalTransfer) self.prepareRootfsUpdate() self.PatchObject(nebraska_wrapper.RemoteNebraskaWrapper, 'Start') self.PatchObject(nebraska_wrapper.RemoteNebraskaWrapper, 'GetURL') self.PatchObject( remote_access.ChromiumOSDevice, 'run', side_effect=cros_build_lib.RunCommandError('fail')) self.PatchObject(auto_updater.ChromiumOSUpdater, 'RevertBootPartition') self.PatchObject(auto_updater.ChromiumOSUpdater, '_FixPayloadPropertiesFile') with mock.patch('os.path.join', return_value=''): self.assertRaises(auto_updater.RootfsUpdateError, CrOS_AU.RunUpdate)
def test_FixPayloadLabTransfer(self): """Tests if correct LabTransfer 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, '{}') 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, '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)
def test_FixPayloadLocalTransfer(self): """Tests if correct LocalTransfer methods are called.""" payload_filename = ( 'payloads/chromeos_9334.58.2_reef_stable-' 'channel_full_test.bin-e6a3290274a5b2ae0b9f491712ae1d8') payload_path = os.path.join(self.tempdir, payload_filename) 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=self._payload_dir, payload_filename=payload_filename, transfer_class=auto_updater_transfer.LocalTransfer) self.PatchObject(auto_updater_transfer.LocalTransfer, 'GetPayloadPropsFile', return_value=payload_properties_path) self.PatchObject(auto_updater_transfer.LocalTransfer, 'GetPayloadProps', return_value={ 'size': '123', 'image_version': '99999.9.9' }) CrOS_AU._FixPayloadPropertiesFile() # pylint: disable=protected-access self.assertTrue( auto_updater_transfer.LocalTransfer.GetPayloadPropsFile.called) self.assertTrue( auto_updater_transfer.LocalTransfer.GetPayloadProps.called)
def RunRemote(self): """Handle remote debugging, via gdbserver & cross debugger.""" device = None try: device = remote_access.ChromiumOSDeviceHandler( self.remote, port=self.remote_port, connect_settings=self.ssh_settings, ping=self.ping).device except remote_access.DeviceNotPingableError: raise GdbBadRemoteDeviceError( 'Remote device %s is not responding to ' 'ping.' % self.remote) self.VerifyAndFinishInitialization(device) gdb_cmd = self.cross_gdb gdb_commands = self.GetGdbInitCommands(self.inf_cmd, device) gdb_args = ['--quiet' ] + ['--eval-command=%s' % x for x in gdb_commands] gdb_args += self.gdb_args if self.cgdb: gdb_args = ['-d', gdb_cmd, '--'] + gdb_args gdb_cmd = 'cgdb' logging.debug('Running: %s', [gdb_cmd] + gdb_args) os.chdir(self.sysroot) sys.exit(os.execvp(gdb_cmd, gdb_args))
def testTransferStatefulOriginalPayloadRunCmdCalls(self): """Test methods calls of LabTransfer._TransferStatefulUpdate(). Test whether remote_access.ChromiumOSDevice.RunCommand() 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') lab_xfer = auto_updater_transfer.LabTransfer expected = [ [ 'curl', '-o', 'stateful_update', 'http://0.0.0.0:8000/static/stateful_update' ], [ 'curl', '-o', '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, 'RunCommand') CrOS_LabTransfer._TransferStatefulUpdate() self.assertListEqual( remote_access.ChromiumOSDevice.RunCommand.call_args_list, [mock.call(x) for x in expected])
def testTargetStatefulUpdateFileDoNotExist(self): """Tests that we raise error if the target stateful file doesn't exist.""" with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: updater = stateful_updater.StatefulUpdater(device) with self.assertRaises(stateful_updater.Error): updater.Update('/foo/path')
def testCheckPayloadsNoStatefulTransfer(self): """Test auto_updater_transfer.CheckPayloads. Test CheckPayloads() method when transfer_rootfs_update is True and transfer_stateful_update is set to False. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_LabTransfer = CreateLabTransferInstance( device, payload_name='test_update.gz', payload_dir='board-release/12345.6.7', transfer_stateful_update=False) self.PatchObject(retry_util, 'RunCurl') expected = [ [ '-I', 'http://0.0.0.0:8000/static/board-release/12345.6.7/' 'test_update.gz', '--fail' ], [ '-I', 'http://0.0.0.0:8000/static/board-release/12345.6.7/' 'test_update.gz.json', '--fail' ] ] CrOS_LabTransfer.CheckPayloads() self.assertListEqual(retry_util.RunCurl.call_args_list, [mock.call(x) for x in expected])
def testTransferRootfsRunCmdLocalPayloadProps(self): """Test method calls of LabTransfer._TransferRootfsUpdate(). Test whether remote_access.ChromiumOSDevice.RunCommand() is being called the correct number of times with the correct arguments when LabTransfer.LocalPayloadPropsFile is set to a valid local filepath. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_LabTransfer = CreateLabTransferInstance( device, payload_name='test_update.gz') self.PatchObject(os.path, 'isfile', return_value=True) CrOS_LabTransfer.LocalPayloadPropsFile = '/existent/test.gz.json' lab_xfer = auto_updater_transfer.LabTransfer expected = [[ 'curl', '-o', 'test_update.gz', 'http://0.0.0.0:8000/static/test_update.gz' ]] self.PatchObject(lab_xfer, '_EnsureDeviceDirectory') self.PatchObject(remote_access.ChromiumOSDevice, 'RunCommand') self.PatchObject(remote_access.ChromiumOSDevice, 'CopyToWorkDir') CrOS_LabTransfer._TransferRootfsUpdate() self.assertListEqual( remote_access.ChromiumOSDevice.RunCommand.call_args_list, [mock.call(x) for x in expected])
def test_FixPayloadPropertiesFile(self): """Tests _FixPayloadPropertiesFile() correctly fixes the properties file.""" payload_filename = ( 'payloads/chromeos_9334.58.2_reef_stable-' 'channel_full_test.bin-e6a3290274a5b2ae0b9f491712ae1d8') payload_path = os.path.join(self._payload_dir, payload_filename) payload_properties_path = payload_path + '.json' osutils.WriteFile(payload_path, 'dummy-payload', makedirs=True) # Empty properties file. osutils.WriteFile(payload_properties_path, json.dumps({})) with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater( device, None, self._payload_dir, payload_filename=payload_filename) 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': '9334.58.2', } self.assertEqual(props, expected_props)
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, 'RunCommand') CrOS_LabTransfer._TransferStatefulUpdate() self.assertListEqual( lab_xfer._EnsureDeviceDirectory.call_args_list, [mock.call(x) for x in expected])
def testTransferRootfsCurlCmdCalls(self): """Test method calls of LabTransfer._TransferRootfsUpdate(). Test whether LabTransfer._GetCurlCmdForPayloadDownload() is being called the correct number of times with the correct arguments. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_LabTransfer = CreateLabTransferInstance( device, device_payload_dir='/test/device/payload/dir', payload_dir='test/payload/dir', payload_name='test_update.gz') lab_xfer = auto_updater_transfer.LabTransfer expected = [{ 'payload_dir': CrOS_LabTransfer._device_payload_dir, 'payload_filename': CrOS_LabTransfer._payload_name, 'build_id': CrOS_LabTransfer._payload_dir }] self.PatchObject(lab_xfer, '_EnsureDeviceDirectory') self.PatchObject(lab_xfer, '_GetCurlCmdForPayloadDownload') self.PatchObject(remote_access.ChromiumOSDevice, 'RunCommand') self.PatchObject(remote_access.ChromiumOSDevice, 'CopyToWorkDir') CrOS_LabTransfer._TransferRootfsUpdate() self.assertListEqual( lab_xfer._GetCurlCmdForPayloadDownload.call_args_list, [mock.call(**x) for x in expected])
def testTransferStatefulCurlCmdCalls(self): """Test methods calls of LabTransfer._TransferStatefulUpdate(). Test whether LabTransfer._GetCurlCmdForPayloadDownload() is being called the correct number of times with the correct arguments. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_LabTransfer = CreateLabTransferInstance( device, device_payload_dir='/test/device/payload/dir') lab_xfer = auto_updater_transfer.LabTransfer self.PatchObject(auto_updater_transfer, '_STATEFUL_UPDATE_FILENAME', 'test_stateful_update') self.PatchObject(lab_xfer, '_EnsureDeviceDirectory') self.PatchObject(lab_xfer, '_GetCurlCmdForPayloadDownload') self.PatchObject(remote_access.ChromiumOSDevice, 'RunCommand') expected = [{ 'payload_dir': CrOS_LabTransfer._device_payload_dir, 'payload_filename': auto_updater_transfer._STATEFUL_UPDATE_FILENAME }, { 'payload_dir': device.work_dir, 'payload_filename': 'stateful.tgz', 'build_id': '' }] CrOS_LabTransfer._TransferStatefulUpdate() self.assertListEqual( lab_xfer._GetCurlCmdForPayloadDownload.call_args_list, [mock.call(**x) for x in expected])
def testTransferForRootfs(self): """Test transfer functions for rootfs update. When rootfs update is enabled, update-utils and rootfs update payload are transferred. Stateful update payload is not. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater( device, None, self._payload_dir, do_stateful_update=False, transfer_class=auto_updater_transfer.LocalTransfer) self.PatchObject(auto_updater.ChromiumOSUpdater, '_FixPayloadPropertiesFile') CrOS_AU.RunUpdate() self.assertTrue( self._transfer_mock.patched['CheckPayloads'].called) self.assertTrue(self._transfer_mock. patched['TransferUpdateUtilsPackage'].called) self.assertTrue( self._transfer_mock.patched['TransferRootfsUpdate'].called) self.assertFalse( self._transfer_mock.patched['TransferStatefulUpdate'].called)
def testTransferStatefulUpdateNoNeedsTransfer(self): """Test transfer functions for stateful update. Test whether auto_updater_transfer.LocalTransfer._GetStatefulUpdateScript() and auto_updater_transfer.LocalTransfer._EnsureDeviceDirectory() are being called correctly. Test the value if the instance variable auto_updater_transfer.LocalTransfer._stateful_update_bin is set correctly when auto_updater_transfer.LocalTransfer._original_payload_dir is set to 'test_dir'. """ self.PatchObject(auto_updater_transfer.LocalTransfer, '_GetStatefulUpdateScript', return_value=[True, 'test_stateful_update_bin']) self.PatchObject(auto_updater_transfer.LocalTransfer, '_EnsureDeviceDirectory') self.PatchObject(auto_updater_transfer, 'STATEFUL_FILENAME', 'test_stateful.tgz') with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_LocalTransfer = CreateLocalTransferInstance( device, original_payload_dir='test_dir') CrOS_LocalTransfer._TransferStatefulUpdate() self.assertTrue(auto_updater_transfer.LocalTransfer. _GetStatefulUpdateScript.called) self.assertEqual(CrOS_LocalTransfer._stateful_update_bin, os.path.join(device.work_dir, 'stateful_update')) self.assertTrue(auto_updater_transfer.LocalTransfer. _EnsureDeviceDirectory.called)
def testRestoreStatefulError(self): """Test ChromiumOSUpdater.RestoreStateful with raising exception. Nebraska still cannot run after restoring stateful partition will lead to ChromiumOSUpdateError. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater(device, None, self._payload_dir) self.PatchObject(auto_updater.ChromiumOSUpdater, 'CheckRestoreStateful', return_value=True) self.PatchObject(auto_updater.ChromiumOSUpdater, 'RunUpdateRootfs') self.PatchObject(auto_updater.ChromiumOSUpdater, 'PreSetupStatefulUpdate') self.PatchObject(auto_updater.ChromiumOSUpdater, 'TransferStatefulUpdate') self.PatchObject(auto_updater.ChromiumOSUpdater, 'ResetStatefulPartition') self.PatchObject(auto_updater.ChromiumOSUpdater, 'UpdateStateful') self.PatchObject(auto_updater.ChromiumOSUpdater, 'PostCheckStatefulUpdate') self.PatchObject(auto_updater.ChromiumOSUpdater, '_IsUpdateUtilsPackageInstalled') self.PatchObject( auto_updater.ChromiumOSUpdater, '_CheckNebraskaCanRun', side_effect=nebraska_wrapper.NebraskaStartupError()) self.assertRaises(auto_updater.ChromiumOSUpdateError, CrOS_AU.RunUpdate)
def testPrepareLabPayloadPropsFile(self): """Tests that we correctly call ResolveAPPIDMismatchIfAny.""" self._payload_dir = self.tempdir with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_AU = auto_updater.ChromiumOSUpdater( device, None, self._payload_dir, staging_server='http://0.0.0.0:8082/') lab_xfer = auto_updater_transfer.LabTransfer cros_updater = auto_updater.ChromiumOSUpdater self.PatchObject(lab_xfer, 'GetPayloadPropsFile', return_value='/local/test_update.gz.json') self.PatchObject(cros_updater, 'ResolveAPPIDMismatchIfAny') CrOS_AU.PreparePayloadPropsFile() self.assertTrue(lab_xfer.GetPayloadPropsFile.called) self.assertListEqual( cros_updater.ResolveAPPIDMismatchIfAny.call_args_list, [mock.call('/local/test_update.gz.json')])
def testCheckRestoreStateful(self): """Test whether _CheckRestoreStateful is called in update process.""" precheck_mock = self.StartPatcher(ChromiumOSPreCheckMock()) with remote_access.ChromiumOSDeviceHandler('1.1.1.1') as device: CrOS_AU = auto_updater.ChromiumOSUpdater(device, self.payload_dir) CrOS_AU.RunUpdate() self.assertTrue(precheck_mock.patched['_CheckRestoreStateful'].called)
def testTransferRootfsCopyToWorkdirLocalPayloadProps(self): """Test method calls of LabTransfer._TransferRootfsUpdate(). Test whether LabTransfer.device.CopyToWorkDir() is being called the correct number of times with the correct arguments when LabTransfer.LocalPayloadPropsFile is set to a valid local filepath. """ with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: CrOS_LabTransfer = CreateLabTransferInstance( device, cmd_kwargs={'test': 'test'}) CrOS_LabTransfer._local_payload_props_path = '/existent/test.gz.json' lab_xfer = auto_updater_transfer.LabTransfer expected = [{ 'src': CrOS_LabTransfer._local_payload_props_path, 'dest': CrOS_LabTransfer.PAYLOAD_DIR_NAME, 'mode': CrOS_LabTransfer._payload_mode, 'log_output': True, 'test': 'test' }] self.PatchObject(lab_xfer, '_EnsureDeviceDirectory') self.PatchObject(remote_access.ChromiumOSDevice, 'RunCommand') self.PatchObject(remote_access.ChromiumOSDevice, 'CopyToWorkDir') CrOS_LabTransfer._TransferRootfsUpdate() self.assertListEqual( remote_access.ChromiumOSDevice.CopyToWorkDir.call_args_list, [mock.call(**x) for x in expected])
def _StageOnMoblab(self, tempdir): """Stage the generated payloads and test bits on a moblab device. Args: tempdir: Temporary Directory that contains the generated payloads and test bits. """ with remote_access.ChromiumOSDeviceHandler( self.options.remote) as device: device.RunCommand(['mkdir', '-p', self.stage_directory]) for f in os.listdir(tempdir): device.CopyToDevice(os.path.join(tempdir, f), self.stage_directory) device.RunCommand(['chown', '-R', 'moblab:moblab', MOBLAB_TMP_DIR]) # Delete this image from the Devserver in case it was previously staged. device.RunCommand([ 'rm', '-rf', os.path.join(MOBLAB_STATIC_DIR, self.staged_image_name) ]) stage_url = DEVSERVER_STAGE_URL % dict( moblab=self.options.remote, staged_dir=self.stage_directory) # Stage the image from the moblab, as port 8080 might not be reachable # from the developer's system. res = device.RunCommand( ['curl', '--fail', cros_build_lib.ShellQuote(stage_url)], error_code_ok=True) if res.returncode == 0: logging.info('\n\nStaging Completed!') logging.info('Image is staged on Moblab as %s', self.staged_image_name) else: logging.info('Staging failed. Error Message: %s', res.error) device.RunCommand(['rm', '-rf', self.stage_directory])
def TestDebug(self): """Tests the debug command.""" logging.info('Test to start and debug a new process on the VM device.') exe_path = '/bin/bash' start_cmd = self.BuildCommand('debug', device=self.vm.device_addr, opt_args=['--exe', exe_path]) result = cros_build_lib.RunCommand(start_cmd, capture_output=True, error_code_ok=True, input='\n') if result.returncode: logging.error('Failed to start and debug a new process on the VM device.') raise CommandError(result.error) logging.info('Test to attach a running process on the VM device.') with remote_access.ChromiumOSDeviceHandler( remote_access.LOCALHOST, port=self.vm.port) as device: exe = 'update_engine' pids = device.GetRunningPids(exe, full_path=False) if not pids: logging.error('Failed to find any running process to debug.') raise CommandError() pid = pids[0] attach_cmd = self.BuildCommand('debug', device=self.vm.device_addr, opt_args=['--pid', str(pid)]) result = cros_build_lib.RunCommand(attach_cmd, capture_output=True, error_code_ok=True, input='\n') if result.returncode: logging.error('Failed to attach a running process on the VM device.') raise CommandError(result.error)
def testInvalidUpdateType(self): """Tests we raise error on invalid given update type.""" with remote_access.ChromiumOSDeviceHandler( remote_access.TEST_IP) as device: updater = stateful_updater.StatefulUpdater(device) with self.assertRaises(stateful_updater.Error): updater._MarkUpdateType('foo')
def testRebootAndVerifyWithoutReboot(self): """Test RebootAndVerify doesn't run if reboot is unenabled.""" with remote_access.ChromiumOSDeviceHandler('1.1.1.1') as device: CrOS_AU = auto_updater.ChromiumOSUpdater(device, self.payload_dir, reboot=False) CrOS_AU.RunUpdate() self.assertFalse(self.base_updater_mock.patched['RebootAndVerify'].called)
def Run(self): """Run cros debug.""" commandline.RunInsideChroot(self) self.options.Freeze() self._ReadOptions() with remote_access.ChromiumOSDeviceHandler( self.ssh_hostname, port=self.ssh_port, username=self.ssh_username, private_key=self.ssh_private_key) as device: self.board = cros_build_lib.GetBoard(device_board=device.board, override_board=self.options.board, strict=True) logging.info('Board is %s', self.board) self.gdb_cmd = [ 'gdb_remote', '--ssh', '--board', self.board, '--remote', self.ssh_hostname, ] if self.ssh_port: self.gdb_cmd.extend(['--ssh_port', str(self.ssh_port)]) if not (self.pid or self.exe): cros_build_lib.Die( 'Must use --exe or --pid to specify the process to debug.') if self.pid: if self.list or self.exe: cros_build_lib.Die( '--list and --exe are disallowed when --pid is used.') self._DebugRunningProcess(self.pid) return if not self.exe.startswith('/'): cros_build_lib.Die('--exe must have a full pathname.') logging.debug('Executable path is %s', self.exe) if not device.IsFileExecutable(self.exe): cros_build_lib.Die( 'File path "%s" does not exist or is not executable on device %s', self.exe, self.ssh_hostname) pids = device.GetRunningPids(self.exe) self._ListProcesses(device, pids) if self.list: # If '--list' flag is on, do not launch GDB. return if pids: choices = ['Start a new process under GDB'] choices.extend(pids) idx = cros_build_lib.GetChoice( 'Please select the process pid to debug (select [0] to start a ' 'new process):', choices) if idx == 0: self._DebugNewProcess() else: self._DebugRunningProcess(pids[idx - 1]) else: self._DebugNewProcess()
def testRebootAndVerifyWithRootfsAndReboot(self): """Test RebootAndVerify if rootfs update and reboot are enabled.""" with remote_access.ChromiumOSDeviceHandler('1.1.1.1') as device: CrOS_AU = auto_updater.ChromiumOSFlashUpdater( device, self.payload_dir) CrOS_AU.RunUpdate() self.assertTrue( self.base_updater_mock.patched['RebootAndVerify'].called)
def testRestoreStateful(self): """Test RestoreStateful is called when it's required.""" with remote_access.ChromiumOSDeviceHandler('1.1.1.1') as device: CrOS_AU = auto_updater.ChromiumOSUpdater(device, self.payload_dir) self.PatchObject(auto_updater.ChromiumOSUpdater, '_CheckRestoreStateful', return_value=True) CrOS_AU.RunUpdate() self.assertTrue(self.base_updater_mock.patched['RestoreStateful'].called)
def testNoPomptWithYes(self): """Test prompts won't be called if yes is set as True.""" with remote_access.ChromiumOSDeviceHandler('1.1.1.1') as device: CrOS_AU = auto_updater.ChromiumOSUpdater(device, self.payload_dir, yes=True) self.PatchObject(cros_build_lib, 'BooleanPrompt') CrOS_AU.RunUpdate() self.assertFalse(cros_build_lib.BooleanPrompt.called)
def testCheckRestoreStatefulError(self): """Test _CheckRestoreStateful fails with raising ChromiumOSUpdateError.""" with remote_access.ChromiumOSDeviceHandler('1.1.1.1') as device: CrOS_AU = auto_updater.ChromiumOSUpdater(device, self.payload_dir) self.PatchObject(cros_build_lib, 'BooleanPrompt', return_value=False) self.PatchObject(auto_updater.ChromiumOSUpdater, '_CanRunDevserver', return_value=False) self.assertRaises(auto_updater.ChromiumOSUpdateError, CrOS_AU.RunUpdate)