def test_does_not_require_config(self): defaults = Config.get_defaults() no_file = os.path.join(self.make_dir(), factory.make_name() + '.yaml') self.useFixture( EnvironmentVariableFixture('MAAS_PROVISIONING_SETTINGS', no_file)) parser = make_arg_parser(factory.getRandomString()) args = parser.parse_args('') self.assertEqual(defaults['boot']['ephemeral']['images_directory'], args.output) self.assertItemsEqual([], args.filters)
def make_arg_parser(doc): """Create an `argparse.ArgumentParser` for this script. :param doc: Description of the script, for help output. """ try: config = Config.load_from_cache() except IOError as e: if e.errno != errno.ENOENT: raise # Plod on with defaults. There may be a legacy shell-script config. config = Config.get_defaults() # Merge legacy settings into our copy of the config. merge_legacy_ephemerals_config(config) filters = [] arches = config['boot'].get('architectures') if arches is not None: filters.append(compose_filter('arch', arches)) releases = config['boot']['ephemeral'].get('releases') if releases is not None: filters.append(compose_filter('release', releases)) images_directory = config['boot']['ephemeral'].get('images_directory') parser = ArgumentParser(description=doc) parser.add_argument( '--path', action="store", default="streams/v1/index.sjson", help="Path to simplestreams index file, relative to mirror URL") parser.add_argument( '--url', action='store', default=RELEASES_URL, help="Simplestreams mirror URL (may use 'file://' for local mirror)") parser.add_argument( '--output', action='store', default=images_directory, help="Directory where boot images should be stored") parser.add_argument( '--max', action='store', default=1, help="Store downloads for only the MAX most recent images.") parser.add_argument( '--keyring', action='store', default=DEFAULT_KEYRING, help="gpg keyring for verifying boot image metadata") parser.add_argument( '--delete', action='store_true', default=False, help="Delete local copies of images when no longer available") parser.add_argument( '--products', action='store', default=PRODUCTS_REGEX, help="Regular expression matching products to import, " "e.g. com.ubuntu.maas.daily:ephemerals:.* for daily") parser.add_argument( 'filters', nargs='*', default=filters, help="Simplestreams filters for image metadata to download, " "e.g. arch=i386 release=precise") return parser
def test_does_not_require_config(self): defaults = Config.get_defaults() no_file = os.path.join(self.make_dir(), factory.make_name() + '.yaml') self.useFixture( EnvironmentVariableFixture('MAAS_PROVISIONING_SETTINGS', no_file)) parser = make_arg_parser(factory.getRandomString()) args = parser.parse_args('') self.assertEqual( defaults['boot']['ephemeral']['images_directory'], args.output) self.assertItemsEqual([], args.filters)
def test_load_from_cache_uses_defaults(self): filename = self.make_file(name='config.yaml', contents='') self.assertEqual( Config.get_defaults(), Config.load_from_cache(filename))
def test_get_defaults_ignores_settings(self): self.useFixture(ConfigFixture({'logfile': self.make_file()})) self.assertEqual( self.default_production_config['logfile'], Config.get_defaults()['logfile'])
def test_get_defaults_returns_default_config(self): # The default configuration is production-ready. observed = Config.get_defaults() self.assertEqual(self.default_production_config, observed)