def main(self): managerlib.check_identity_cert_perms() ret = CLI.main(self) # Try to enable all yum plugins (subscription-manager and plugin-id) enabled_yum_plugins = YumPluginManager.enable_pkg_plugins() if len(enabled_yum_plugins) > 0: print("\n" + _("WARNING") + "\n\n" + YumPluginManager.warning_message(enabled_yum_plugins) + "\n") # Try to flush all outputs, see BZ: 1350402 try: sys.stdout.flush() sys.stderr.flush() except IOError as io_err: log.error("Error: Unable to print data to stdout/stderr output during exit process: %s" % io_err) return ret
def test_enabling_yum_plugin_with_missing_enabled_option(self): """ This test only test YumPluginManager.enable_yum_plugins() can survive reading of corrupted yum plugin configuration file (missing option 'enabled') """ self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_MISSING_ENABLED_OPTION) plugin_list = YumPluginManager.enable_pkg_plugins() self.assertEqual(len(plugin_list), 2)
def test_enabling_yum_plugin_with_corrupted_conf_file(self): """ This test only test YumPluginManager.enable_yum_plugins() can survive reading of corrupted yum plugin configuration file """ self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_CORRUPTED) plugin_list = YumPluginManager.enable_pkg_plugins() self.assertEqual(len(plugin_list), 0)
def test_enabling_yum_plugin_with_missing_main_section(self): """ This test only test YumPluginManager.enable_yum_plugins() can survive reading of corrupted yum plugin configuration file (missing main section) """ self.init_plugin_conf_files(conf_string=YUM_PLUGIN_CONF_MISSING_MAIN_SECTION) plugin_list = YumPluginManager.enable_yum_plugins() self.assertEqual(len(plugin_list), 2)
def test_enabling_yum_plugin_with_missing_main_section(self): """ This test only test YumPluginManager.enable_yum_plugins() can survive reading of corrupted yum plugin configuration file (missing main section) """ self.init_plugin_conf_files(conf_string=YUM_PLUGIN_CONF_MISSING_MAIN_SECTION) plugin_list = YumPluginManager.enable_yum_plugins() self.assertEqual(len(plugin_list), 2)
def test_enabling_yum_plugin_with_wrong_conf(self): """ Test automatic enabling of configuration files of already plugins with wrong values in conf file. """ self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_WRONG_VALUE) plugin_list = YumPluginManager.enable_pkg_plugins() self.assertEqual(len(plugin_list), 2) 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.getint('main', 'enabled') self.assertEqual(is_plugin_enabled, 1) self.restore_yum_plugin_conf_files()
def test_enabling_enabled_yum_plugin_int(self): """ Test automatic enabling of configuration files of already enabled plugins """ self.init_yum_plugin_conf_files(conf_string=PKG_PLUGIN_CONF_FILE_ENABLED_INT) 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.getint('main', 'enabled') self.assertEqual(is_plugin_enabled, 1) self.restore_yum_plugin_conf_files()
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_yum_plugin_with_invalid_values(self): """ Test automatic enabling of configuration files of already enabled plugins """ self.init_plugin_conf_files(conf_string=YUM_PLUGIN_CONF_FILE_INVALID_VALUE) plugin_list = YumPluginManager.enable_yum_plugins() self.assertEqual(len(plugin_list), 2) for plugin_conf_file_name in YumPluginManager.YUM_PLUGINS: yum_plugin_config = ConfigParser() result = yum_plugin_config.read(YumPluginManager.DNF_PLUGIN_DIR + '/' + plugin_conf_file_name + '.conf') self.assertGreater(len(result), 0) is_plugin_enabled = yum_plugin_config.getint('main', 'enabled') self.assertEqual(is_plugin_enabled, 1) self.restore_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()
def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() rhsm_cfg = config.initConfig() proxy_server = rhsm_cfg.get("server", "proxy_hostname") proxy_port = int(rhsm_cfg.get("server", "proxy_port") or config.DEFAULT_PROXY_PORT) def show_proxy_error_dialog(proxy_auth_required=False): """ When proxy server is set in configuration and it is not possible to connect to proxy server, then open dialog for setting proxy server. """ if proxy_auth_required: proxy_user = rhsm_cfg.get("server", "proxy_user") proxy_password = rhsm_cfg.get("server", "proxy_password") if proxy_user or proxy_password: err_msg = _("Wrong proxy username or password, please check your settings.") else: err_msg = _("Proxy authentication required, please check your settings.") else: err_msg = _("Proxy connection failed, please check your settings.") print_error(err_msg) error_dialog = messageWindow.ContinueDialog(err_msg, self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() # Sub-man gui will be terminated after saving settings and it is # necessary to start it once again. self.network_config_dialog.saveButton.connect("clicked", self._exit) self.network_config_dialog.cancelButton.connect("clicked", self._exit) self.backend = backend or Backend() cp = self.backend.cp_provider.get_consumer_auth_cp() if proxy_server: if not utils.test_proxy_reachability(proxy_server, proxy_port): show_proxy_error_dialog() return try: # Try to send to the simplest Rest API call to Candlepin server. # This result will be used for getting version of Candlepin server. # See self.log_server_version. cp.supports_resource("status") except socket.error as err: # See https://tools.ietf.org/html/rfc7235#section-4.3 if "407 Proxy Authentication Required" in err.message: show_proxy_error_dialog(proxy_auth_required=True) return self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) ga_GLib.idle_add(self.log_server_version, cp) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog(update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None) enabled_yum_plugins = YumPluginManager.enable_pkg_plugins() if len(enabled_yum_plugins) > 0: messageWindow.InfoDialog( YumPluginManager.warning_message(enabled_yum_plugins), self._get_window(), _("Warning - subscription-manager plugins were automatically enabled") )
def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() # When proxy server is set in configuration and it is not # possible to connect to proxy server, then open dialog # for setting proxy server. if not utils.test_proxy_reachability(): print_error( _("Proxy connection failed, please check your settings.")) error_dialog = messageWindow.ContinueDialog( _("Proxy connection failed, please check your settings."), self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() # Sub-man gui will be terminated after saving settings and it is # necessary to start it once again. self.network_config_dialog.saveButton.connect( "clicked", self._exit) self.network_config_dialog.cancelButton.connect( "clicked", self._exit) return self.backend = backend or Backend() self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) # Log the server version asynchronously ga_GLib.idle_add(self.log_server_version, self.backend.cp_provider.get_consumer_auth_cp()) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog( update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via rhsmdd for example, or manually provisioned). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None) enabled_yum_plugins = YumPluginManager.enable_yum_plugins() if len(enabled_yum_plugins) > 0: messageWindow.InfoDialog( YumPluginManager.warning_message(enabled_yum_plugins), self._get_window(), _("Warning - subscription-manager plugins were automatically enabled" ))
def __init__(self, backend=None, ent_dir=None, prod_dir=None, auto_launch_registration=False): super(MainWindow, self).__init__() rhsm_cfg = config.get_config_parser() proxy_server = rhsm_cfg.get("server", "proxy_hostname") proxy_port = int( rhsm_cfg.get("server", "proxy_port") or config.DEFAULT_PROXY_PORT) def show_proxy_error_dialog(proxy_auth_required=False): """ When proxy server is set in configuration and it is not possible to connect to proxy server, then open dialog for setting proxy server. """ if proxy_auth_required: proxy_user = rhsm_cfg.get("server", "proxy_user") proxy_password = rhsm_cfg.get("server", "proxy_password") if proxy_user or proxy_password: err_msg = _( "Wrong proxy username or password, please check your settings." ) else: err_msg = _( "Proxy authentication required, please check your settings." ) else: err_msg = _( "Proxy connection failed, please check your settings.") print_error(err_msg) error_dialog = messageWindow.ContinueDialog( err_msg, self._get_window()) error_dialog.connect("response", self._on_proxy_error_dialog_response) self.network_config_dialog = networkConfig.NetworkConfigDialog() # Sub-man gui will be terminated after saving settings and it is # necessary to start it once again. self.network_config_dialog.saveButton.connect( "clicked", self._exit) self.network_config_dialog.cancelButton.connect( "clicked", self._exit) self.backend = backend or Backend() cp = self.backend.cp_provider.get_consumer_auth_cp() # allow specifying no_proxy via api or config no_proxy = rhsm_cfg.get('server', 'no_proxy') if no_proxy: os.environ['no_proxy'] = no_proxy rhsm_utils.fix_no_proxy() log.debug('Environment variable NO_PROXY=%s will be used' % no_proxy) # Don't check the proxy server if the hostname we aim to connect to is covered by no_proxy if proxy_server and not urllib.request.proxy_bypass( rhsm_cfg.get('server', 'hostname')): if not utils.test_proxy_reachability(proxy_server, proxy_port): show_proxy_error_dialog() return try: # Try to send to the simplest Rest API call to Candlepin server. # This result will be used for getting version of Candlepin server. # See self.log_server_version. cp.supports_resource("status") except (socket.error, connection.ProxyException) as err: # See https://tools.ietf.org/html/rfc7235#section-4.3 if "407 Proxy Authentication Required" in str(err.message): show_proxy_error_dialog(proxy_auth_required=True) return self.identity = require(IDENTITY) log.debug("Client Versions: %s " % get_client_versions()) ga_GLib.idle_add(self.log_server_version, cp) settings = self.main_window.get_settings() # prevent gtk from trying to save a list of recently used files, which # as root, causes gtk warning: # "Attempting to set the permissions of `/root/.local/share/recently-used.xbel' # The __name__ use is just for the 'origin' value gtk uses to store # where a Gtk.Settings value was set. settings.set_long_property('gtk-recent-files-max-age', 0, "%s:%s" % (__name__, type(self).__name__)) ga_Gtk.Window.set_default_icon_name("subscription-manager") self.product_dir = prod_dir or self.backend.product_dir self.entitlement_dir = ent_dir or self.backend.entitlement_dir self.system_facts_dialog = factsgui.SystemFactsDialog( update_callback=self._handle_facts_updated) self.preferences_dialog = PreferencesDialog(self.backend, self._get_window()) self.repos_dialog = RepositoriesDialog(self.backend, self._get_window()) self.import_sub_dialog = ImportSubDialog() self.network_config_dialog = networkConfig.NetworkConfigDialog() self.network_config_dialog.saveButton.connect("clicked", self._config_changed) self.redeem_dialog = redeem.RedeemDialog(self.backend) self.installed_tab_icon = ga_Gtk.Image() self.installed_tab_icon.set_from_stock(ga_Gtk.STOCK_YES, ga_Gtk.IconSize.MENU) self.installed_tab = InstalledProductsTab(self.backend, self.installed_tab_icon, self, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.my_subs_tab = MySubscriptionsTab(self.backend, self.main_window, ent_dir=self.entitlement_dir, prod_dir=self.product_dir) self.all_subs_tab = AllSubscriptionsTab(self.backend, self.main_window) hbox = ga_Gtk.HBox(spacing=6) hbox.pack_start(self.installed_tab_icon, False, False, 0) hbox.pack_start(ga_Gtk.Label(self.installed_tab.get_label()), False, False, 0) self.notebook.append_page(self.installed_tab.get_content(), hbox) hbox.show_all() self.notebook.append_page(self.my_subs_tab.get_content(), ga_Gtk.Label(self.my_subs_tab.get_label())) self.connect_signals({ "on_register_menu_item_activate": self._register_item_clicked, "on_unregister_menu_item_activate": self._unregister_item_clicked, "on_import_cert_menu_item_activate": self._import_cert_item_clicked, "on_view_facts_menu_item_activate": self._facts_item_clicked, "on_proxy_config_menu_item_activate": self._proxy_config_item_clicked, "on_redeem_menu_item_activate": self._redeem_item_clicked, "on_preferences_menu_item_activate": self._preferences_item_clicked, "on_repos_menu_item_activate": self._repos_item_clicked, "on_about_menu_item_activate": self._about_item_clicked, "on_getting_started_menu_item_activate": self._getting_started_item_clicked, "on_online_docs_menu_item_activate": self._online_docs_item_clicked, "on_quit_menu_item_activate": ga_Gtk.main_quit, }) # various state tracking for async operations self._show_overrides = False self._can_redeem = False self.backend.cs.add_callback(self.on_cert_sorter_cert_change) self.main_window.show_all() # Check to see if already registered to old RHN/Spacewalk # and show dialog if so self._check_rhn_classic() # Update everything with compliance data self.backend.cs.notify() # managergui needs cert_sort.cert_monitor.run_check() to run # on a timer to detect cert changes from outside the gui # (via manual provisioning). cert_monitor_thread = threading.Thread(target=self._cert_check_timer, name="CertMonitorThread") cert_monitor_thread.daemon = True cert_monitor_thread.start() if auto_launch_registration and not self.registered(): self._register_item_clicked(None) enabled_yum_plugins = YumPluginManager.enable_pkg_plugins() if len(enabled_yum_plugins) > 0: messageWindow.InfoDialog( YumPluginManager.warning_message(enabled_yum_plugins), self._get_window(), _("Warning - subscription-manager plugins were automatically enabled" ))