def main(argv): parser = GetParser() options = parser.parse_args(argv) if options.action == 'run' and ((not options.bin or len(options.bin) == 0) and not options.cmdline): raise AssertionError('You must specify a binary for the "run" action') if options.host and options.board: raise AssertionError('You must provide only one of --board or --host') elif not options.host and not options.board and not options.sysroot: raise AssertionError('You must provide --board or --host or --sysroot') if options.sysroot: # Normalize the value so we can assume certain aspects. options.sysroot = osutils.ExpandPath(options.sysroot) if not os.path.isdir(options.sysroot): raise AssertionError('Sysroot does not exist: %s' % options.sysroot) # Once we've finished sanity checking args, make sure we're root. _ReExecuteIfNeeded([sys.argv[0]] + argv, ns_net=options.ns_net, ns_pid=options.ns_pid) p2test = Platform2Test(options.bin, options.board, options.host, options.framework, options.run_as_root, options.gtest_filter, options.user_gtest_filter, options.sysroot, options.cmdline) getattr(p2test, options.action)()
def _UploadConditionsMet(cls, stats): """Return True if upload conditions are met.""" def CheckDomain(hostname): return any(hostname.endswith(d) for d in cls._DOMAIN_WHITELIST) def CheckEmail(email): return any(email.endswith(e) for e in cls._EMAIL_WHITELIST) upload = False # Verify that host domain is in golo.chromium.org or corp.google.com. if not stats.host or not CheckDomain(stats.host): logging.debug('Host %s is not a Google machine.', stats.host) elif not stats.username: logging.debug('Unable to determine current "git id".') elif not CheckEmail(stats.username): logging.debug('%s is not a Google or Chromium user.', stats.username) elif os.path.exists(osutils.ExpandPath(cls._DISABLE_FILE)): logging.debug('Found %s', cls._DISABLE_FILE) else: upload = True if not upload: logging.debug('Skipping stats upload.') return upload
def main(argv): actions = ['pre_test', 'post_test', 'run'] parser = argparse.ArgumentParser() group = parser.add_argument_group('Namespaces') group.add_argument('--no-ns-net', dest='ns_net', default=True, action='store_false', help='Do not create a new network namespace') group.add_argument('--no-ns-pid', dest='ns_pid', default=True, action='store_false', help='Do not create a new PID namespace') parser.add_argument('--action', default='run', choices=actions, help='action to perform') parser.add_argument('--bin', help='test binary to run') parser.add_argument('--board', default=None, help='board to build for') parser.add_argument('--sysroot', default=None, help='sysroot to run tests inside') parser.add_argument('--framework', default='auto', choices=('auto', 'ldso', 'qemu'), help='framework to be used to run tests') parser.add_argument('--gtest_filter', default='', help='args to pass to gtest/test binary') parser.add_argument('--host', action='store_true', default=False, help='specify that we\'re testing for the host') parser.add_argument('--run_as_root', action='store_true', help='should the test be run as root') parser.add_argument('--user_gtest_filter', default='', help=argparse.SUPPRESS) parser.add_argument('cmdline', nargs='*') options = parser.parse_args(argv) if options.action == 'run' and ((not options.bin or len(options.bin) == 0) and not options.cmdline): raise AssertionError('You must specify a binary for the "run" action') if options.host and options.board: raise AssertionError('You must provide only one of --board or --host') elif not options.host and not options.board and not options.sysroot: raise AssertionError('You must provide --board or --host or --sysroot') if options.sysroot: # Normalize the value so we can assume certain aspects. options.sysroot = osutils.ExpandPath(options.sysroot) if not os.path.isdir(options.sysroot): raise AssertionError('Sysroot does not exist: %s' % options.sysroot) # Once we've finished sanity checking args, make sure we're root. _ReExecuteIfNeeded([sys.argv[0]] + argv, ns_net=options.ns_net, ns_pid=options.ns_pid) p2test = Platform2Test(options.bin, options.board, options.host, options.framework, options.run_as_root, options.gtest_filter, options.user_gtest_filter, options.sysroot, options.cmdline) getattr(p2test, options.action)()
def _GenerateImageNameFromLocalPath(self, image): """Generate the name as which |image| will be staged onto Moblab. If the board name has not been specified, set the board name based on the image path. Args: image: Path to image we want to stage. It should be in the format of /.../.../board/build/<image>.bin Returns: Name the image will be staged as. Raises: CustomImageStagingException: If the image name supplied is not valid. """ realpath = osutils.ExpandPath(image) if not realpath.endswith('.bin'): raise CustomImageStagingException( 'Image path: %s does not end in .bin !' % realpath) build_name = os.path.basename(os.path.dirname(realpath)) # Custom builds are name with the suffix of '-a1' but the build itself # is missing this suffix in its filesystem. Therefore lets rename the build # name to match the name inside the build. if build_name.endswith('-a1'): build_name = build_name[:-len('-a1')] if not self.board: self.board = os.path.basename( os.path.dirname(os.path.dirname(realpath))) return CUSTOM_BUILD_NAME % dict(board=self.board, build=build_name)
def TranslatedPathToLocalPath(translated_path, static_dir): """Convert the translated path to a local path to the image file. Args: translated_path: the translated xbuddy path (e.g., peppy-release/R36-5760.0.0/chromiumos_image). static_dir: The static directory used by the devserver. Returns: A local path to the image file. """ real_path = osutils.ExpandPath(os.path.join(static_dir, translated_path)) if os.path.exists(real_path): return real_path else: return path_util.FromChrootPath(real_path)
def Flash(device, image, board=None, install=False, src_image_to_delta=None, rootfs_update=True, stateful_update=True, clobber_stateful=False, reboot=True, wipe=True, ping=True, disable_rootfs_verification=False, clear_cache=False, yes=False, force=False, debug=False): """Flashes a device, USB drive, or file with an image. This provides functionality common to `cros flash` and `brillo flash` so that they can parse the commandline separately but still use the same underlying functionality. Args: device: commandline.Device object; None to use the default device. image: Path (string) to the update image. Can be a local or xbuddy path; non-existant local paths are converted to xbuddy. board: Board to use; None to automatically detect. install: Install to USB using base disk layout; USB |device| scheme only. src_image_to_delta: Local path to an image to be used as the base to generate delta payloads; SSH |device| scheme only. rootfs_update: Update rootfs partition; SSH |device| scheme only. stateful_update: Update stateful partition; SSH |device| scheme only. clobber_stateful: Clobber stateful partition; SSH |device| scheme only. reboot: Reboot device after update; SSH |device| scheme only. wipe: Wipe temporary working directory; SSH |device| scheme only. ping: Ping the device before attempting update; SSH |device| scheme only. disable_rootfs_verification: Remove rootfs verification after update; SSH |device| scheme only. clear_cache: Clear the devserver static directory. yes: Assume "yes" for any prompt. force: Ignore sanity checks and prompts. Overrides |yes| if True. debug: Print additional debugging messages. Raises: FlashError: An unrecoverable error occured. ValueError: Invalid parameter combination. """ if force: yes = True if clear_cache: logging.info('Clearing the cache...') ds_wrapper.DevServerWrapper.WipeStaticDirectory(DEVSERVER_STATIC_DIR) try: osutils.SafeMakedirsNonRoot(DEVSERVER_STATIC_DIR) except OSError: logging.error('Failed to create %s', DEVSERVER_STATIC_DIR) if install: if not device or device.scheme != commandline.DEVICE_SCHEME_USB: raise ValueError( '--install can only be used when writing to a USB device') if not cros_build_lib.IsInsideChroot(): raise ValueError('--install can only be used inside the chroot') if not device or device.scheme == commandline.DEVICE_SCHEME_SSH: if device: hostname, port = device.hostname, device.port else: hostname, port = None, None logging.notice('Preparing to update the remote device %s', hostname) updater = RemoteDeviceUpdater( hostname, port, image, board=board, src_image_to_delta=src_image_to_delta, rootfs_update=rootfs_update, stateful_update=stateful_update, clobber_stateful=clobber_stateful, reboot=reboot, wipe=wipe, debug=debug, yes=yes, force=force, ping=ping, disable_verification=disable_rootfs_verification) updater.Run() elif device.scheme == commandline.DEVICE_SCHEME_USB: path = osutils.ExpandPath(device.path) if device.path else '' logging.info('Preparing to image the removable device %s', path) imager = USBImager(path, board, image, debug=debug, install=install, yes=yes) imager.Run() elif device.scheme == commandline.DEVICE_SCHEME_FILE: logging.info('Preparing to copy image to %s', device.path) imager = FileImager(device.path, board, image, debug=debug, yes=yes) imager.Run()
def AbsolutePath(_option, _opt, value): """Expand paths and make them absolute.""" return osutils.ExpandPath(value)
def ExpandGSPath(path): """Expand a path, possibly a gs:// URL.""" if path.startswith(gs.BASE_GS_URL): return path return osutils.ExpandPath(path)