def __generate(self): if not os.path.exists(self.repofile): return [] # Unfortuantely, we can not use the SafeConfigParser for zypper repo # files because the repository urls contains strings which the # SafeConfigParser don't like. It would crash with # ConfigParser.InterpolationSyntaxError: '%' must be followed by '%' or '(' if use_zypper: config = ConfigParser() else: config = SafeConfigParser() config.read(self.repofile) enabled_sections = [ section for section in config.sections() if config.getboolean(section, "enabled") ] enabled_repos = [] for section in enabled_sections: try: enabled_repos.append({ "repositoryid": section, "baseurl": [self._format_baseurl(config.get(section, "baseurl"))] }) except ImportError: break return enabled_repos
def test_not_enabling_disabled_yum_plugin(self): """ Test not enabling (disabled in rhsm.conf) of configuration files of disabled plugins """ self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_DISABLED_BOOL) plugin_list = YumPluginManager.enable_pkg_plugins() self.assertEqual(len(plugin_list), 0) for plugin_conf_file_name in YumPluginManager.PLUGINS: yum_plugin_config = ConfigParser() result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf') self.assertGreater(len(result), 0) is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled') self.assertEqual(is_plugin_enabled, False) self.restore_yum_plugin_conf_files()
def test_enabling_enabled_yum_plugin_bool(self): """ Test automatic enabling of configuration files of already enabled plugins """ self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_ENABLED_BOOL) plugin_list = YumPluginManager.enable_pkg_plugins() self.assertEqual(len(plugin_list), 0) for plugin_conf_file_name in YumPluginManager.PLUGINS: yum_plugin_config = ConfigParser() result = yum_plugin_config.read(YumPluginManager.YUM_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf') self.assertGreater(len(result), 0) # The file was not modified. We have to read value with with getboolean() is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled') self.assertEqual(is_plugin_enabled, True) self.restore_yum_plugin_conf_files()