def default_write_test(self): conf = AnacondaConfiguration.from_defaults() with tempfile.NamedTemporaryFile("r+") as f: conf.write(f.name) f.flush() self.assertTrue(f.read(), "The file shouldn't be empty.")
def test_system(self): conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline([]) conf.set_from_opts(opts) assert conf.system._is_boot_iso is True assert conf.system._is_live_os is False assert conf.system._is_unknown is False opts, _removed = self._parseCmdline(['--liveinst']) conf.set_from_opts(opts) assert conf.system._is_boot_iso is False assert conf.system._is_live_os is True assert conf.system._is_unknown is False opts, _removed = self._parseCmdline(['--dirinstall=/what/ever']) conf.set_from_opts(opts) assert conf.system._is_boot_iso is False assert conf.system._is_live_os is False assert conf.system._is_unknown is True opts, _removed = self._parseCmdline(['--image=/what/ever.img']) conf.set_from_opts(opts) assert conf.system._is_boot_iso is False assert conf.system._is_live_os is False assert conf.system._is_unknown is True
def set_from_buildstamp_product_test(self): conf = AnacondaConfiguration.from_defaults() # Test an unknown .buildstamp product. with self.assertRaises(ConfigurationError) as cm: conf.set_from_product( buildstamp_product="Unknown product", buildstamp_variant="Unknown variant", ) expected = "Unable to find any suitable configuration files " \ "for this product." self.assertEqual(str(cm.exception), expected) # Test a known .buildstamp product. conf.set_from_product( buildstamp_product="Fedora", buildstamp_variant="Workstation", ) self._check_configuration_sources(conf, [ "anaconda.conf", "product.d/fedora.conf", "product.d/fedora-workstation.conf" ])
def system_test(self): conf = AnacondaConfiguration.from_defaults() opts, _deprecated = self._parseCmdline([]) conf.set_from_opts(opts) self.assertEqual(conf.system._is_boot_iso, True) self.assertEqual(conf.system._is_live_os, False) self.assertEqual(conf.system._is_unknown, False) opts, _deprecated = self._parseCmdline(['--liveinst']) conf.set_from_opts(opts) self.assertEqual(conf.system._is_boot_iso, False) self.assertEqual(conf.system._is_live_os, True) self.assertEqual(conf.system._is_unknown, False) opts, _deprecated = self._parseCmdline(['--dirinstall=/what/ever']) conf.set_from_opts(opts) self.assertEqual(conf.system._is_boot_iso, False) self.assertEqual(conf.system._is_live_os, False) self.assertEqual(conf.system._is_unknown, True) opts, _deprecated = self._parseCmdline(['--image=/what/ever.img']) conf.set_from_opts(opts) self.assertEqual(conf.system._is_boot_iso, False) self.assertEqual(conf.system._is_live_os, False) self.assertEqual(conf.system._is_unknown, True)
def test_set_from_requested_product(self): conf = AnacondaConfiguration.from_defaults() # Test an unknown requested product. with self.assertRaises(ConfigurationError) as cm: conf.set_from_product( requested_product="Unknown product", requested_variant="Unknown variant", ) expected = "Unable to find any suitable configuration files " \ "for the product name 'Unknown product' and the " \ "variant name 'Unknown variant'." self.assertEqual(str(cm.exception), expected) # Test a known requested product. conf.set_from_product( requested_product="Fedora", requested_variant="Workstation", ) self._check_configuration_sources(conf, [ "anaconda.conf", "product.d/fedora.conf", "product.d/fedora-workstation.conf" ])
def test_kickstart_modules(self): """Test the kickstart_modules option.""" conf = AnacondaConfiguration.from_defaults() self.assertEqual(conf.anaconda.activatable_modules, [ "org.fedoraproject.Anaconda.Modules.*", "org.fedoraproject.Anaconda.Addons.*" ]) parser = conf.get_parser() parser.read_string( dedent(""" [Anaconda] kickstart_modules = org.fedoraproject.Anaconda.Modules.Timezone org.fedoraproject.Anaconda.Modules.Localization org.fedoraproject.Anaconda.Modules.Security """)) self.assertEqual(conf.anaconda.activatable_modules, [ "org.fedoraproject.Anaconda.Modules.Timezone", "org.fedoraproject.Anaconda.Modules.Localization", "org.fedoraproject.Anaconda.Modules.Security", "org.fedoraproject.Anaconda.Addons.*" ]) for pattern in conf.anaconda.activatable_modules: self._check_pattern(pattern)
def test_set_from_buildstamp_product(self): conf = AnacondaConfiguration.from_defaults() # Test an unknown .buildstamp product. with self.assertLogs(level="WARNING") as cm: conf.set_from_product( buildstamp_product="Unknown product", buildstamp_variant="Unknown variant", ) expected = \ "Unable to find any suitable configuration files for the detected " \ "product and variant names. No product configuration will be used." self.assertIn(expected, "\n".join(cm.output)) # Test a known .buildstamp product. conf.set_from_product( buildstamp_product="Fedora", buildstamp_variant="Workstation", ) self._check_configuration_sources(conf, [ "anaconda.conf", "product.d/fedora.conf", "product.d/fedora-workstation.conf" ])
def test_target(self): conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline([]) conf.set_from_opts(opts) assert conf.target.is_hardware is True assert conf.target.is_image is False assert conf.target.is_directory is False assert conf.target.physical_root == "/mnt/sysimage" opts, _removed = self._parseCmdline(['--image=/what/ever.img']) conf.set_from_opts(opts) assert conf.target.is_hardware is False assert conf.target.is_image is True assert conf.target.is_directory is False assert conf.target.physical_root == "/mnt/sysimage" opts, _removed = self._parseCmdline(['--dirinstall=/what/ever']) conf.set_from_opts(opts) assert conf.target.is_hardware is False assert conf.target.is_image is False assert conf.target.is_directory is True assert conf.target.physical_root == "/what/ever"
def target_test(self): conf = AnacondaConfiguration.from_defaults() opts, _deprecated = self._parseCmdline([]) conf.set_from_opts(opts) self.assertEqual(conf.target.is_hardware, True) self.assertEqual(conf.target.is_image, False) self.assertEqual(conf.target.is_directory, False) self.assertEqual(conf.target.physical_root, "/mnt/sysimage") opts, _deprecated = self._parseCmdline(['--image=/what/ever.img']) conf.set_from_opts(opts) self.assertEqual(conf.target.is_hardware, False) self.assertEqual(conf.target.is_image, True) self.assertEqual(conf.target.is_directory, False) self.assertEqual(conf.target.physical_root, "/mnt/sysimage") opts, _deprecated = self._parseCmdline(['--dirinstall=/what/ever']) conf.set_from_opts(opts) self.assertEqual(conf.target.is_hardware, False) self.assertEqual(conf.target.is_image, False) self.assertEqual(conf.target.is_directory, True) self.assertEqual(conf.target.physical_root, "/what/ever")
def apply_none_to_configuration_test(self, proxy_getter): anaconda_conf = AnacondaConfiguration.from_defaults() with patch("pyanaconda.pwpolicy.conf", anaconda_conf): apply_password_policy_from_kickstart(self.handler) self.assertEqual(anaconda_conf.ui.can_change_root, False) self.assertEqual(anaconda_conf.ui.can_change_users, False)
def set_from_no_product_test(self): conf = AnacondaConfiguration.from_defaults() with self.assertRaises(ConfigurationError) as cm: conf.set_from_product() expected = "Unable to find any suitable configuration files " \ "for this product." self.assertEqual(str(cm.exception), expected)
def kickstart_modules_test(self): conf = AnacondaConfiguration.from_defaults() self.assertEqual( set(conf.anaconda.kickstart_modules), set(service.service_name for service in (services.TIMEZONE, services.NETWORK, services.LOCALIZATION, services.SECURITY, services.USERS, services.PAYLOADS, services.STORAGE, services.SERVICES)))
def test_addons_enabled_modules(self): """Test the addons_enabled option.""" conf = AnacondaConfiguration.from_defaults() self.assertEqual(conf.anaconda.forbidden_modules, []) parser = conf.get_parser() parser.read_string( dedent(""" [Anaconda] forbidden_modules = org.fedoraproject.Anaconda.Modules.Timezone org.fedoraproject.Anaconda.Modules.Localization org.fedoraproject.Anaconda.Modules.Security """)) self.assertEqual(conf.anaconda.forbidden_modules, [ "org.fedoraproject.Anaconda.Modules.Timezone", "org.fedoraproject.Anaconda.Modules.Localization", "org.fedoraproject.Anaconda.Modules.Security", ]) parser.read_string( dedent(""" [Anaconda] addons_enabled = True """)) self.assertEqual(conf.anaconda.forbidden_modules, [ "org.fedoraproject.Anaconda.Modules.Timezone", "org.fedoraproject.Anaconda.Modules.Localization", "org.fedoraproject.Anaconda.Modules.Security", ]) parser.read_string( dedent(""" [Anaconda] addons_enabled = False """)) self.assertEqual(conf.anaconda.forbidden_modules, [ "org.fedoraproject.Anaconda.Addons.*", "org.fedoraproject.Anaconda.Modules.Timezone", "org.fedoraproject.Anaconda.Modules.Localization", "org.fedoraproject.Anaconda.Modules.Security", ]) for pattern in conf.anaconda.forbidden_modules: self._check_pattern(pattern)
def test_default_partitioning(self): conf = AnacondaConfiguration.from_defaults() assert conf.storage.default_partitioning == [{ 'name': '/', 'min': Size("1024 MiB"), 'max': Size("70 GiB"), }, { 'name': '/home', 'min': Size("500 MiB"), 'free': Size("50 GiB"), }]
def _get_config(self, product_name, variant_name=""): """Get parsed config file.""" config = AnacondaConfiguration.from_defaults() paths = self._loader.collect_configurations(product_name, variant_name) for path in paths: config.read(path) config.validate() return config
def test_set_from_no_product(self): conf = AnacondaConfiguration.from_defaults() with self.assertLogs(level="WARNING") as cm: conf.set_from_product() expected = \ "Unable to find any suitable configuration files for the detected " \ "product and variant names. No product configuration will be used." self.assertIn(expected, "\n".join(cm.output))
def default_partitioning_test(self): conf = AnacondaConfiguration.from_defaults() self.assertEqual(conf.storage.default_partitioning, [{ 'name': '/', 'min': Size("1024 MiB"), 'max': Size("70 GiB"), }, { 'name': '/home', 'min': Size("500 MiB"), 'free': Size("50 GiB"), }])
def _check_default_product(self, product_name, variant_name, file_names): """Check a default product.""" self._check_product( product_name, variant_name, [os.path.join(PRODUCT_DIR, path) for path in file_names]) config = AnacondaConfiguration.from_defaults() paths = self._loader.collect_configurations(product_name, variant_name) for path in paths: config.read(path) config.validate()
def _check_default_product(self, product_name, variant_name, file_names): """Check a default product.""" self._check_product( product_name, variant_name, [os.path.join(PRODUCT_DIR, path) for path in file_names] ) config = AnacondaConfiguration.from_defaults() paths = self._loader.collect_configurations(product_name, variant_name) for path in paths: config.read(path) config.validate()
def test_storage(self): conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline([]) conf.set_from_opts(opts) assert conf.storage.dmraid is True assert conf.storage.ibft is True opts, _removed = self._parseCmdline(['--nodmraid', '--ibft']) conf.set_from_opts(opts) assert conf.storage.dmraid is False assert conf.storage.ibft is True
def storage_test(self): conf = AnacondaConfiguration.from_defaults() opts, _deprecated = self._parseCmdline([]) conf.set_from_opts(opts) self.assertEqual(conf.storage.dmraid, True) self.assertEqual(conf.storage.ibft, True) opts, _deprecated = self._parseCmdline(['--nodmraid', '--ibft']) conf.set_from_opts(opts) self.assertEqual(conf.storage.dmraid, False) self.assertEqual(conf.storage.ibft, True)
def kickstart_modules_test(self): conf = AnacondaConfiguration.from_defaults() self.assertEqual( set(conf.anaconda.kickstart_modules), set(service.service_name for service in ( services.TIMEZONE, services.NETWORK, services.LOCALIZATION, services.SECURITY, services.USERS, services.PAYLOAD, services.STORAGE, services.SERVICES )) )
def _check_default_profile(self, profile_id, os_release_values, file_names, partitioning): """Check a default profile.""" paths = [os.path.join(PROFILE_DIR, path) for path in file_names] self._check_profile(profile_id, paths) config = AnacondaConfiguration.from_defaults() paths = self._loader.collect_configurations(profile_id) for path in paths: config.read(path) config.validate() self._check_detection(profile_id, *os_release_values) self._check_partitioning(config, partitioning) self.assertEqual("{}.conf".format(profile_id), file_names[-1])
def apply_nochanges_to_configuration_test(self, proxy_getter): anaconda_conf = AnacondaConfiguration.from_defaults() ks_in = """ %anaconda pwpolicy root --nochanges pwpolicy user --nochanges pwpolicy luks --nochanges %end """ self.ksparser.readKickstartFromString(dedent(ks_in)) with patch("pyanaconda.pwpolicy.conf", anaconda_conf): apply_password_policy_from_kickstart(self.handler) self.assertEqual(anaconda_conf.ui.can_change_root, False) self.assertEqual(anaconda_conf.ui.can_change_users, False)
def test_default_password_policies(self): conf = AnacondaConfiguration.from_defaults() assert conf.ui.password_policies == [ { 'name': 'root', "quality": 1, "length": 6, }, { 'name': 'user', "quality": 1, "length": 6, "empty": True, }, { 'name': 'luks', "quality": 1, "length": 6, }, ]
def set_from_files_test(self): conf = AnacondaConfiguration.from_defaults() paths = [] with tempfile.TemporaryDirectory() as d: # Add nonexistent file. nonexistent = os.path.join(d, "nonexistent") paths.append(nonexistent) # Add empty directory. empty_dir = os.path.join(d, "empty") os.mkdir(empty_dir) paths.append(empty_dir) # Add existing file. existing = os.path.join(d, "a.conf") paths.append(existing) with open(existing, mode="w") as f: f.write("") # Add non-empty directory. conf_dir = os.path.join(d, "conf.d") os.mkdir(conf_dir) paths.append(conf_dir) for name in ["b.conf", "c.conf", "d"]: with open(os.path.join(conf_dir, name), mode="w") as f: f.write("") # Check the paths. self.assertEqual( [os.path.relpath(path, d) for path in paths], ["nonexistent", "empty", "a.conf", "conf.d"] ) conf._sources = [] conf.set_from_files(paths) # Check the loaded files. self.assertEqual( [os.path.relpath(path, d) for path in conf.get_sources()], ["a.conf", "conf.d/b.conf", "conf.d/c.conf"] )
def default_validation_test(self): conf = AnacondaConfiguration.from_defaults() conf.validate() # Set invalid value. parser = conf.get_parser() parser["Anaconda"]["debug"] = "string" with self.assertRaises(ConfigurationError): conf.validate() # Remove a required option. parser.remove_option("Anaconda", "debug") with self.assertRaises(ConfigurationError): conf.validate() # Remove a required section. parser.remove_section("Anaconda") with self.assertRaises(ConfigurationError): conf.validate()
def test_set_from_requested_profile(self): conf = AnacondaConfiguration.from_defaults() # Test an unknown requested profile. with self.assertRaises(ConfigurationError) as cm: conf.set_from_profile("unknown-profile") expected = "Unable to find any suitable configuration files " \ "for the 'unknown-profile' profile." self.assertEqual(str(cm.exception), expected) # Test a known requested profile. conf.set_from_profile("fedora-workstation") self._check_configuration_sources(conf, [ "anaconda.conf", "profile.d/fedora.conf", "profile.d/fedora-workstation.conf" ])
def default_password_policies_test(self): conf = AnacondaConfiguration.from_defaults() self.assertEqual(conf.ui.password_policies, [ { 'name': 'root', "quality": 1, "length": 6, }, { 'name': 'user', "quality": 1, "length": 6, "empty": True, }, { 'name': 'luks', "quality": 1, "length": 6, }, ])
def test_set_from_detected_profile(self): conf = AnacondaConfiguration.from_defaults() # Test unknown os-release values. with self.assertLogs(level="WARNING") as cm: conf.set_from_detected_profile("unknown-os", "unknown-variant") expected = \ "Unable to find any suitable configuration files for the detected " \ "os-release values. No profile configuration will be used." self.assertIn(expected, "\n".join(cm.output)) # Test known os-release values. conf.set_from_detected_profile("fedora", "workstation") self._check_configuration_sources(conf, [ "anaconda.conf", "profile.d/fedora.conf", "profile.d/fedora-workstation.conf" ])
def test_target_nosave(self): conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline([]) conf.set_from_opts(opts) assert conf.target.can_copy_input_kickstart is True assert conf.target.can_save_installation_logs is True assert conf.target.can_save_output_kickstart is True conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline(['--nosave=all']) conf.set_from_opts(opts) assert conf.target.can_copy_input_kickstart is False assert conf.target.can_save_installation_logs is False assert conf.target.can_save_output_kickstart is False conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline(['--nosave=all_ks']) conf.set_from_opts(opts) assert conf.target.can_copy_input_kickstart is False assert conf.target.can_save_installation_logs is True assert conf.target.can_save_output_kickstart is False conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline(['--nosave=logs']) conf.set_from_opts(opts) assert conf.target.can_copy_input_kickstart is True assert conf.target.can_save_installation_logs is False assert conf.target.can_save_output_kickstart is True conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline(['--nosave=input_ks']) conf.set_from_opts(opts) assert conf.target.can_copy_input_kickstart is False assert conf.target.can_save_installation_logs is True assert conf.target.can_save_output_kickstart is True conf = AnacondaConfiguration.from_defaults() opts, _removed = self._parseCmdline(['--nosave=output_ks']) conf.set_from_opts(opts) assert conf.target.can_copy_input_kickstart is True assert conf.target.can_save_installation_logs is True assert conf.target.can_save_output_kickstart is False
def test_kickstart_modules(self): """Test the kickstart_modules option.""" message = \ "The kickstart_modules configuration option is " \ "deprecated and will be removed in in the future." conf = AnacondaConfiguration.from_defaults() assert conf.anaconda.activatable_modules == [ "org.fedoraproject.Anaconda.Modules.*", "org.fedoraproject.Anaconda.Addons.*" ] parser = conf.get_parser() parser.read_string( dedent(""" [Anaconda] kickstart_modules = org.fedoraproject.Anaconda.Modules.Timezone org.fedoraproject.Anaconda.Modules.Localization org.fedoraproject.Anaconda.Modules.Security """)) with pytest.warns(DeprecationWarning, match=message): activatable_modules = conf.anaconda.activatable_modules assert activatable_modules == [ "org.fedoraproject.Anaconda.Modules.Timezone", "org.fedoraproject.Anaconda.Modules.Localization", "org.fedoraproject.Anaconda.Modules.Security", "org.fedoraproject.Anaconda.Addons.*" ] for pattern in activatable_modules: self._check_pattern(pattern)
def default_source_test(self): conf = AnacondaConfiguration.from_defaults() sources = conf.get_sources() self.assertEqual(len(sources), 1) self.assertEqual(sources[0], os.environ.get("ANACONDA_CONFIG_TMP"))
def default_read_test(self): AnacondaConfiguration.from_defaults()