Exemple #1
0
 def test_older_version(self):
     d = dict(version='0.0.1')
     save_ver = objects.CONFIG_VERSION
     try:
         objects.CONFIG_VERSION = '0.1.0'
         objects.check_version(d)
     finally:
         objects.CONFIG_VERSION = save_ver
Exemple #2
0
def main(argv=sys.argv):
    opts = parse_opts(argv)
    configure_logger(opts.verbose, opts.debug)
    logger.info('Using config file at: %s' % opts.config_file)
    part_array = []

    # NOTE(bnemec): Add alternate implementations here
    provider = impl_blivet.BlivetDiskConfig()

    disks = provider.disks()
    if len(disks) <= 1:
        logger.error('The system only has one disk')
        return 1
    logger.debug('Available disks: %s', disks)
    if os.path.exists(opts.config_file):
        with open(opts.config_file) as cf:
            cf_data = cf.read()
            # yaml will happily load a json file, but return worthless data
            # json will blow up on a yaml file, so try it first
            try:
                full_config = json.loads(cf_data)
            except ValueError:
                full_config = yaml.load(cf_data)
            objects.check_version(full_config)
            part_array = full_config.get("partitions")
            logger.debug('partitions JSON: %s' % str(part_array))
    else:
        logger.error('No config file exists at: %s' % opts.config_file)
        return 1
    if not isinstance(part_array, list):
        logger.error('No interfaces defined in config: %s' % opts.config_file)
        return 1
    for part_json in part_array:
        obj = objects.object_from_json(part_json)
        provider.add_object(obj)
    files_changed = provider.apply(noop=opts.noop)
    return 0
Exemple #3
0
def main(argv=sys.argv):
    opts = parse_opts(argv)
    configure_logger(opts.verbose, opts.debug)
    logger.info('Using config file at: %s' % opts.config_file)
    part_array = []

    # NOTE(bnemec): Add alternate implementations here
    provider = impl_blivet.BlivetDiskConfig()

    disks = provider.disks()
    if len(disks) <= 1:
        logger.error('The system only has one disk')
        return 1
    logger.debug('Available disks: %s', disks)
    if os.path.exists(opts.config_file):
        with open(opts.config_file) as cf:
            cf_data = cf.read()
            # yaml will happily load a json file, but return worthless data
            # json will blow up on a yaml file, so try it first
            try:
                full_config = json.loads(cf_data)
            except ValueError:
                full_config = yaml.load(cf_data)
            objects.check_version(full_config)
            part_array = full_config.get("partitions")
            logger.debug('partitions JSON: %s' % str(part_array))
    else:
        logger.error('No config file exists at: %s' % opts.config_file)
        return 1
    if not isinstance(part_array, list):
        logger.error('No interfaces defined in config: %s' % opts.config_file)
        return 1
    for part_json in part_array:
        obj = objects.object_from_json(part_json)
        provider.add_object(obj)
    files_changed = provider.apply(noop=opts.noop)
    return 0
Exemple #4
0
 def test_matching_versions(self):
     d = dict(version=objects.CONFIG_VERSION)
     objects.check_version(d)