def setup_image(args, image): """Set up image as specified in args. @param args: cmdline arguments @param image: cloud_tests.image instance to operate on @return_value: tuple of results and fail count """ # update the args if necessary for this image overrides = image.setup_overrides LOG.debug('updating args for setup with: %s', overrides) args = util.update_args(args, overrides, preserve_old=True) # mapping of setup cmdline arg name to setup function # represented as a tuple rather than a dict or odict as lookup by name not # needed, and order is important as --script and --upgrade go at the end handlers = ( # arg handler description ('deb', install_deb, 'setup func for --deb, install deb'), ('rpm', install_rpm, 'setup func for --rpm, install rpm'), ('repo', enable_repo, 'setup func for --repo, enable repo'), ('ppa', enable_ppa, 'setup func for --ppa, enable ppa'), ('script', run_script, 'setup func for --script, run script'), ('upgrade', upgrade, 'setup func for --upgrade, upgrade cloud-init'), ('upgrade-full', upgrade_full, 'setup func for --upgrade-full'), ) # determine which setup functions needed calls = [partial(stage.run_single, desc, partial(func, args, image)) for name, func, desc in handlers if getattr(args, name, None)] LOG.info('setting up %s', image) res = stage.run_stage( 'set up for {}'.format(image), calls, continue_after_error=False) return res
def setup_image(args, image): """Set up image as specified in args. @param args: cmdline arguments @param image: cloud_tests.image instance to operate on @return_value: tuple of results and fail count """ # update the args if necessary for this image overrides = image.setup_overrides LOG.debug('updating args for setup with: %s', overrides) args = util.update_args(args, overrides, preserve_old=True) # mapping of setup cmdline arg name to setup function # represented as a tuple rather than a dict or odict as lookup by name not # needed, and order is important as --script and --upgrade go at the end handlers = ( # arg handler description ('deb', install_deb, 'setup func for --deb, install deb'), ('rpm', install_rpm, 'setup func for --rpm, install rpm'), ('repo', enable_repo, 'setup func for --repo, enable repo'), ('ppa', enable_ppa, 'setup func for --ppa, enable ppa'), ('script', run_script, 'setup func for --script, run script'), ('upgrade', upgrade, 'setup func for --upgrade, upgrade cloud-init'), ('upgrade-full', upgrade_full, 'setup func for --upgrade-full'), ) # determine which setup functions needed calls = [partial(stage.run_single, desc, partial(func, args, image)) for name, func, desc in handlers if getattr(args, name, None)] try: data = yaml.load(image.read_data("/etc/cloud/build.info", decode=True)) info = ' '.join(["%s=%s" % (k, data.get(k)) for k in ("build_name", "serial") if k in data]) except Exception as e: info = "N/A (%s)" % e LOG.info('setting up %s (%s)', image, info) res = stage.run_stage( 'set up for {}'.format(image), calls, continue_after_error=False) return res