def main(): """ Run the cli (Do the syspurpose tool thing!!) :return: 0 """ log.debug("Running the syspurpose utility...") parser = setup_arg_parser() args = parser.parse_args() # Syspurpose is not intended to be used in containers for the time being (could change later). if in_container(): print(_("WARNING: Setting syspurpose in containers has no effect." "Please run syspurpose on the host.\n")) try: from subscription_manager.identity import Identity from subscription_manager.cp_provider import CPProvider identity = Identity() uuid = identity.uuid uep = CPProvider().get_consumer_auth_cp() except ImportError: uuid = None uep = None print(_("Warning: Unable to sync system purpose with subscription management server:" " subscription_manager module is not available.")) syspurposestore = SyncedStore(uep=uep, consumer_uuid=uuid) if getattr(args, 'func', None) is not None: args.func(args, syspurposestore) else: parser.print_help() return 0 return 0
def main(): """ Run the cli (Do the syspurpose tool thing!!) :return: 0 """ parser = setup_arg_parser() args = parser.parse_args() # Syspurpose is not intended to be used in containers for the time being (could change later). if in_container(): print(_("WARNING: Setting syspurpose in containers has no effect." "Please run syspurpose on the host.\n")) print(_("The 'syspurpose' command is deprecated and will be removed in a future major release." " Please use the 'subscription-manager syspurpose' command going forward."), file=sys.stderr) try: from subscription_manager.identity import Identity from subscription_manager.cp_provider import CPProvider identity = Identity() uuid = identity.uuid uep = CPProvider().get_consumer_auth_cp() except ImportError: uuid = None uep = None print(_("Warning: Unable to sync system purpose with subscription management server:" " subscription_manager module is not available.")) syspurposestore = SyncedStore(uep=uep, consumer_uuid=uuid, use_valid_fields=True) if getattr(args, 'func', None) is not None: args.func(args, syspurposestore) else: parser.print_help() return 0 return 0
def setUp(self): """ Initialization before each test """ self.cp_provider = CPProvider()
class CPProviderTests(unittest.TestCase): """ Test case used for testing method in CPProvider (provider of connection to Candlepin server) """ def setUp(self): """ Initialization before each test """ self.cp_provider = CPProvider() def test_create_cp_provider(self): """ Simple test of creating instance """ self.assertIsNotNone(self.cp_provider) def test_cert_file_is_not_none(self): """ Test that cp_provider is not created without default cert file """ self.assertEqual(self.cp_provider.cert_file, "/etc/pki/consumer/cert.pem") def test_key_file_is_not_none(self): """ Test that cp_provider is not created without default key file """ self.assertEqual(self.cp_provider.key_file, "/etc/pki/consumer/key.pem") def test_get_consumer_auth_cp(self): """ Test of getting connection to candlepin server using consumer certificate """ connection = self.cp_provider.get_consumer_auth_cp() self.assertIsNotNone(connection) @patch("subscription_manager.cp_provider.utils.get_client_versions") def test_consumer_auth_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {"subscription-manager": "1.23.45"} connection = self.cp_provider.get_consumer_auth_cp() self.assertTrue( "subscription-manager/1.23.45" in connection.conn.user_agent) def test_get_basic_auth_cp(self): """ Test of getting connection to candlepin server using username/password """ self.cp_provider.set_user_pass(username="******", password="******") connection = self.cp_provider.get_basic_auth_cp() self.assertIsNotNone(connection) @patch("subscription_manager.cp_provider.utils.get_client_versions") def test_basic_auth_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {"subscription-manager": "1.23.45"} self.cp_provider.set_user_pass(username="******", password="******") connection = self.cp_provider.get_basic_auth_cp() self.assertTrue( "subscription-manager/1.23.45" in connection.conn.user_agent) def test_get_no_auth_cp(self): """ Test of getting connection to candlepin server not using authentication """ connection = self.cp_provider.get_no_auth_cp() self.assertIsNotNone(connection) @patch("subscription_manager.cp_provider.utils.get_client_versions") def test_no_auth_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {"subscription-manager": "1.23.45"} connection = self.cp_provider.get_no_auth_cp() self.assertTrue( "subscription-manager/1.23.45" in connection.conn.user_agent) def test_get_content_conn(self): """ Test of getting connection to content server (yum repository) """ self.cp_provider.set_content_connection_info(cdn_hostname=None, cdn_port=None) connection = self.cp_provider.get_content_connection() self.assertIsNotNone(connection) @patch("subscription_manager.cp_provider.utils.get_client_versions") def test_content_conn_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {"subscription-manager": "1.23.45"} self.cp_provider.set_content_connection_info(cdn_hostname=None, cdn_port=None) connection = self.cp_provider.get_content_connection() self.assertTrue( "subscription-manager/1.23.45" in connection.conn.user_agent)
class CPProviderTests(unittest.TestCase): """ Test case used for testing method in CPProvider (provider of connection to Candlepin server) """ def setUp(self): """ Initialization before each test """ self.cp_provider = CPProvider() def test_create_cp_provider(self): """ Simple test of creating instance """ self.assertIsNotNone(self.cp_provider) def test_get_consumer_auth_cp(self): """ Test of getting connection to candlepin server using consumer certificate """ connection = self.cp_provider.get_consumer_auth_cp() self.assertIsNotNone(connection) @patch('subscription_manager.cp_provider.utils.get_client_versions') def test_consumer_auth_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {'subscription-manager': '1.23.45'} connection = self.cp_provider.get_consumer_auth_cp() self.assertTrue( 'subscription-manager/1.23.45' in connection.conn.user_agent) def test_get_basic_auth_cp(self): """ Test of getting connection to candlepin server using username/password """ self.cp_provider.set_user_pass(username='******', password='******') connection = self.cp_provider.get_basic_auth_cp() self.assertIsNotNone(connection) @patch('subscription_manager.cp_provider.utils.get_client_versions') def test_basic_auth_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {'subscription-manager': '1.23.45'} self.cp_provider.set_user_pass(username='******', password='******') connection = self.cp_provider.get_basic_auth_cp() self.assertTrue( 'subscription-manager/1.23.45' in connection.conn.user_agent) def test_get_no_auth_cp(self): """ Test of getting connection to candlepin server not using authentication """ connection = self.cp_provider.get_no_auth_cp() self.assertIsNotNone(connection) @patch('subscription_manager.cp_provider.utils.get_client_versions') def test_no_auth_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {'subscription-manager': '1.23.45'} connection = self.cp_provider.get_no_auth_cp() self.assertTrue( 'subscription-manager/1.23.45' in connection.conn.user_agent) def test_get_content_conn(self): """ Test of getting connection to content server (yum repository) """ self.cp_provider.set_content_connection_info(cdn_hostname=None, cdn_port=None) connection = self.cp_provider.get_content_connection() self.assertIsNotNone(connection) @patch('subscription_manager.cp_provider.utils.get_client_versions') def test_content_conn_setting_user_agent_version(self, mock_client_version): mock_client_version.return_value = {'subscription-manager': '1.23.45'} self.cp_provider.set_content_connection_info(cdn_hostname=None, cdn_port=None) connection = self.cp_provider.get_content_connection() self.assertTrue( 'subscription-manager/1.23.45' in connection.conn.user_agent)