Ejemplo n.º 1
0
def GetDeploymentTargetForArgs(args):
    """Constructs a deployment target object using parameters taken from
  command line arguments."""

    if args.system_log_file == '-':
        system_log_file = sys.stdout
    elif args.system_log_file:
        system_log_file = open(args.system_log_file, 'w')
    else:
        system_log_file = None

    if not args.device:
        # KVM is required on x64 test bots.
        require_kvm = hasattr(args, "test_launcher_bot_mode") and \
            args.test_launcher_bot_mode and args.target_cpu == "x64"

        return QemuTarget(output_dir=args.output_directory,
                          target_cpu=args.target_cpu,
                          cpu_cores=args.qemu_cpu_cores,
                          system_log_file=system_log_file,
                          require_kvm=require_kvm)
    else:
        return DeviceTarget(output_dir=args.output_directory,
                            target_cpu=args.target_cpu,
                            host=args.host,
                            node_name=args.node_name,
                            port=args.port,
                            ssh_config=args.ssh_config,
                            fuchsia_out_dir=args.fuchsia_out_dir,
                            system_log_file=system_log_file,
                            os_check=args.os_check)
Ejemplo n.º 2
0
 def testNoNodeNameTwoDevicesRaiseExceptionAmbiguousTarget(
     self, mock_daemon_stop):
   with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
        mock.patch.object(FfxRunner, 'list_targets') as mock_list_targets, \
        self.assertRaisesRegex(Exception, \
                               'More than one device was discovered'):
     mock_list_targets.return_value = [{
         "nodename": "device_name1",
         "rcs_state": "Y",
         "serial": "<unknown>",
         "target_type": "terminal.qemu-x64",
         "target_state": "Product",
         "addresses": ["address1"]
     }, {
         "nodename": "device_name2",
         "rcs_state": "Y",
         "serial": "<unknown>",
         "target_type": "terminal.qemu-x64",
         "target_state": "Product",
         "addresses": ["address2"]
     }]
     device_target_instance.Start()
     self.assertIsNone(device_target_instance._node_name)
     self.assertIsNone(device_target_instance._host)
   mock_daemon_stop.assert_called_once()
Ejemplo n.º 3
0
 def testNoDevicesFoundRaiseExceptionCouldNotFind(self):
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(FfxRunner, 'list_targets') as mock_list_targets, \
          self.assertRaisesRegex(Exception, 'Could not find device.'):
         mock_list_targets.return_value = []
         device_target_instance.Start()
         self.assertIsNone(device_target_instance._node_name)
         self.assertIsNone(device_target_instance._host)
Ejemplo n.º 4
0
 def testNodeNameDefinedDeviceNotFoundRaiseExceptionCouldNotFind(self):
     self.args.node_name = 'wrong_device_name'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch('subprocess.Popen') as mock_popen, \
          self.assertRaisesRegex(Exception, 'Could not find device.'):
         mock_popen.returncode = ('', '')
         device_target_instance.Start()
         self.assertIsNone(device_target_instance._node_name)
         self.assertIsNone(device_target_instance._host)
Ejemplo n.º 5
0
def GetDeploymentTargetForArgs(args):
    """Constructs a deployment target object using parameters taken from
  command line arguments."""

    if not args.device:
        return QemuTarget(args.output_directory, args.target_cpu)
    else:
        return DeviceTarget(args.output_directory, args.target_cpu, args.host,
                            args.port, args.ssh_config)
Ejemplo n.º 6
0
 def testProvisionIfOneNonDetectableDevice(self):
     self.args.os_check = 'update'
     self.args.node_name = 'mocknode'
     self.args.system_image_dir = 'mockdir'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch('subprocess.Popen') as mock_popen, \
          mock.patch.object(DeviceTarget, '_ProvisionDevice') as mock_provision:
         mock_popen.returncode = ('', '')
         device_target_instance.Start()
         self.assertEqual(mock_provision.call_count, 1)
Ejemplo n.º 7
0
 def testNoDevicesFoundRaiseExceptionCouldNotFind(self):
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(DeviceTarget, 'RunFFXCommand') as mock_ffx, \
          self.assertRaisesRegex(Exception, 'Could not find device.'):
         mock_spec_popen = mock.create_autospec(subprocess.Popen,
                                                instance=True)
         mock_spec_popen.communicate.return_value = ('', '')
         mock_spec_popen.returncode = 0
         mock_ffx.return_value = mock_spec_popen
         device_target_instance.Start()
         self.assertIsNone(device_target_instance._node_name)
         self.assertIsNone(device_target_instance._host)
Ejemplo n.º 8
0
 def testProvisionIfOneNonDetectableDevice(self):
     self.args.os_check = 'update'
     self.args.node_name = 'mocknode'
     self.args.system_image_dir = 'mockdir'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(
              FfxTarget, 'get_ssh_address') as mock_get_ssh_address, \
          mock.patch.object(DeviceTarget, '_ProvisionDevice') as mock_provision:
         mock_get_ssh_address.side_effect = subprocess.CalledProcessError(
             1, 'ffx', 'Timeout attempting to reach target "mocknode"')
         device_target_instance.Start()
         self.assertEqual(mock_provision.call_count, 1)
Ejemplo n.º 9
0
 def testNodeNameDefinedDeviceNotFoundRaiseExceptionCouldNotFind(self):
     self.args.node_name = 'wrong_device_name'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(
              FfxTarget, 'get_ssh_address') as mock_get_ssh_address, \
          self.assertRaisesRegex(Exception, 'Could not find device.'):
         mock_get_ssh_address.side_effect = subprocess.CalledProcessError(
             1, 'ffx',
             'Timeout attempting to reach target "wrong_device_name"')
         device_target_instance.Start()
         self.assertIsNone(device_target_instance._node_name)
         self.assertIsNone(device_target_instance._host)
Ejemplo n.º 10
0
 def testNodeNameDefinedDeviceFoundReturnNoneCheckNameAndHost(self):
     self.args.node_name = 'device_name'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch('subprocess.Popen') as mock_popen, \
          mock.patch.object(Target, '_WaitUntilReady') as mock_waituntilready:
         mock_popen.return_value.communicate.return_value = ('address',
                                                             'device_name')
         mock_popen.return_value.returncode = 0
         mock_waituntilready.return_value = True
         self.assertIsNone(device_target_instance.Start())
         self.assertEqual(device_target_instance._node_name, 'device_name')
         self.assertEqual(device_target_instance._host, 'address')
Ejemplo n.º 11
0
 def testNodeNameDefinedDeviceFoundReturnNoneCheckNameAndHost(self):
     self.args.node_name = 'device_name'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(
              FfxTarget, 'get_ssh_address') as mock_get_ssh_address, \
          mock.patch.object(
              DeviceTarget, '_ConnectToTarget') as mock_connecttotarget:
         mock_get_ssh_address.return_value = ('address', 12345)
         mock_connecttotarget.return_value = True
         self.assertIsNone(device_target_instance.Start())
         self.assertEqual(device_target_instance._node_name, 'device_name')
         self.assertEqual(device_target_instance._host, 'address')
         self.assertEqual(device_target_instance._port, 12345)
Ejemplo n.º 12
0
 def testNoNodeNameOneDeviceReturnNoneCheckNameAndAddress(self):
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(DeviceTarget, 'RunFFXCommand') as mock_ffx, \
          mock.patch.object(Target, '_WaitUntilReady') as mock_waituntilready:
         mock_spec_popen = mock.create_autospec(subprocess.Popen,
                                                instance=True)
         mock_spec_popen.communicate.return_value = ('address device_name',
                                                     '')
         mock_spec_popen.returncode = 0
         mock_ffx.return_value = mock_spec_popen
         mock_waituntilready.return_value = True
         self.assertIsNone(device_target_instance.Start())
         self.assertEqual(device_target_instance._node_name, 'device_name')
         self.assertEqual(device_target_instance._host, 'address')
Ejemplo n.º 13
0
 def testNoNodeNameDeviceDoesntHaveNameRaiseExceptionCouldNotFind(self):
     with (DeviceTarget.CreateFromArgs(
             self.args)) as device_target_instance:
         with mock.patch.object(DeviceTarget, 'RunFFXCommand') as mock_ffx:
             mock_spec_popen = mock.create_autospec(subprocess.Popen,
                                                    instance=True)
             mock_spec_popen.communicate.return_value = ('address', '')
             mock_spec_popen.returncode = 0
             mock_ffx.return_value = mock_spec_popen
             with self.assertRaisesRegex(Exception,
                                         'Could not find device'):
                 device_target_instance.Start()
                 self.assertIsNone(device_target_instance._node_name)
                 self.assertIsNone(device_target_instance._host)
Ejemplo n.º 14
0
 def testNoNodeNameTwoDevicesRaiseExceptionAmbiguousTarget(self):
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(DeviceTarget, 'RunFFXCommand') as mock_ffx, \
          self.assertRaisesRegex(Exception, \
                                 'More than one device was discovered'):
         mock_spec_popen = mock.create_autospec(subprocess.Popen,
                                                instance=True)
         mock_spec_popen.communicate.return_value = (
             'address1 device_name1\n'
             'address2 device_name2', '')
         mock_spec_popen.returncode = 0
         mock_ffx.return_value = mock_spec_popen
         device_target_instance.Start()
         self.assertIsNone(device_target_instance._node_name)
         self.assertIsNone(device_target_instance._host)
Ejemplo n.º 15
0
 def testNoNodeNameDeviceDoesntHaveNameRaiseExceptionCouldNotFind(self):
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(FfxRunner, 'list_targets') as mock_list_targets, \
          self.assertRaisesRegex(Exception, 'Could not find device.'):
         mock_list_targets.return_value = [{
             "nodename": "<unknown>",
             "rcs_state": "Y",
             "serial": "<unknown>",
             "target_type": "terminal.qemu-x64",
             "target_state": "Product",
             "addresses": ["address"]
         }]
         device_target_instance.Start()
         self.assertIsNone(device_target_instance._node_name)
         self.assertIsNone(device_target_instance._host)
Ejemplo n.º 16
0
 def testNoProvisionDeviceIfVersionsMatch(self):
     self.args.os_check = 'update'
     self.args.system_image_dir = 'mockdir'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(DeviceTarget, '_Discover') as mock_discover, \
          mock.patch.object(DeviceTarget, '_WaitUntilReady') as mock_ready, \
          mock.patch.object(DeviceTarget, '_GetSdkHash') as mock_hash, \
          mock.patch.object(
             DeviceTarget, '_GetInstalledSdkVersion') as mock_version, \
          mock.patch.object(DeviceTarget, '_ProvisionDevice') as mock_provision:
         mock_discover.return_value = True
         mock_hash.return_value = '1.0'
         mock_version.return_value = '1.0'
         device_target_instance.Start()
         self.assertEqual(mock_provision.call_count, 0)
Ejemplo n.º 17
0
def GetDeploymentTargetForArgs(args, require_kvm=False):
    """Constructs a deployment target object using parameters taken from
  command line arguments."""
    if args.system_log_file == '-':
        system_log_file = sys.stdout
    elif args.system_log_file:
        system_log_file = open(args.system_log_file, 'w')
    else:
        system_log_file = None

    # Allow fuchsia to run on emulator if device not explicitly chosen.
    # AEMU is the default emulator for x64 Fuchsia, and QEMU for others.
    if not args.device:
        if args.target_cpu == 'x64':
            args.device = 'aemu'
        else:
            args.device = 'qemu'

    target_args = {
        'output_dir': args.output_directory,
        'target_cpu': args.target_cpu,
        'system_log_file': system_log_file
    }
    if args.device == 'device':
        target_args.update({
            'host': args.host,
            'node_name': args.node_name,
            'port': args.port,
            'ssh_config': args.ssh_config,
            'fuchsia_out_dir': args.fuchsia_out_dir,
            'os_check': args.os_check
        })
        return DeviceTarget(**target_args)
    else:
        target_args.update({
            'cpu_cores': args.qemu_cpu_cores,
            'require_kvm': not args.no_kvm,
            'emu_type': args.device,
            'ram_size_mb': args.memory
        })
        if args.device == 'qemu':
            return QemuTarget(**target_args)
        else:
            target_args.update({
                'enable_graphics': args.enable_graphics,
                'hardware_gpu': args.hardware_gpu
            })
            return AemuTarget(**target_args)
Ejemplo n.º 18
0
 def testRaiseExceptionIfCheckVersionsNoMatch(self):
     self.args.os_check = 'check'
     self.args.system_image_dir = 'mockdir'
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(DeviceTarget, '_Discover') as mock_discover, \
          mock.patch.object(DeviceTarget, '_WaitUntilReady') as mock_ready, \
          mock.patch.object(DeviceTarget, '_GetSdkHash') as mock_hash, \
          mock.patch.object(
             DeviceTarget, '_GetInstalledSdkVersion') as mock_version, \
          mock.patch.object(
             DeviceTarget, '_ProvisionDevice') as mock_provision, \
          self.assertRaisesRegex(Exception, 'Image and Fuchsia version'):
         mock_discover.return_value = True
         mock_hash.return_value = '2.0'
         mock_version.return_value = '1.0'
         device_target_instance.Start()
Ejemplo n.º 19
0
 def testNoNodeNameTwoDevicesRaiseExceptionAmbiguousTarget(self):
     with (DeviceTarget.CreateFromArgs(
             self.args)) as device_target_instance:
         with mock.patch.object(DeviceTarget, 'RunFFXCommand') as mock_ffx:
             mock_spec_popen = mock.create_autospec(subprocess.Popen,
                                                    instance=True)
             mock_spec_popen.communicate.return_value = (
                 'address1 device_name1\n'
                 'address2 device_name2', '')
             mock_spec_popen.returncode = 0
             mock_spec_popen.stdout = ''
             mock_ffx.return_value = mock_spec_popen
             with self.assertRaisesRegex(
                     Exception, 'Ambiguous target device specification.'):
                 device_target_instance.Start()
                 self.assertIsNone(device_target_instance._node_name)
                 self.assertIsNone(device_target_instance._host)
Ejemplo n.º 20
0
def GetDeploymentTargetForArgs(args):
  """Constructs a deployment target object using parameters taken from
  command line arguments."""

  if args.system_log_file == '-':
    system_log_file = sys.stdout
  elif args.system_log_file:
    system_log_file = open(args.system_log_file, 'w')
  else:
    system_log_file = None

  if not args.device:
    return QemuTarget(args.output_directory, args.target_cpu,
                      args.qemu_cpu_cores, system_log_file)
  else:
    return DeviceTarget(args.output_directory, args.target_cpu, args.host,
                        args.port, args.ssh_config, system_log_file)
Ejemplo n.º 21
0
 def testNoNodeNameOneDeviceReturnNoneCheckNameAndAddress(self):
     with DeviceTarget.CreateFromArgs(self.args) as device_target_instance, \
          mock.patch.object(FfxRunner, 'list_targets') as mock_list_targets, \
          mock.patch.object(
              FfxTarget, 'get_ssh_address') as mock_get_ssh_address, \
          mock.patch.object(
              DeviceTarget, '_ConnectToTarget') as mock_connecttotarget:
         mock_list_targets.return_value = [{
             "nodename": "device_name",
             "rcs_state": "Y",
             "serial": "<unknown>",
             "target_type": "terminal.qemu-x64",
             "target_state": "Product",
             "addresses": ["address"]
         }]
         mock_get_ssh_address.return_value = ('address', 12345)
         mock_connecttotarget.return_value = True
         self.assertIsNone(device_target_instance.Start())
         self.assertEqual(device_target_instance._node_name, 'device_name')
         self.assertEqual(device_target_instance._host, 'address')
         self.assertEqual(device_target_instance._port, 12345)