예제 #1
0
 def test_insecure(self, start_service, get_proxy):
     """Test StartRHSMTask - setting the server.insecure RHSM config key."""
     # create the task & disable SSL certificate validation
     task = StartRHSMTask(verify_ssl=False)
     # simulate successful systemd service start
     start_service.return_value = 0
     # return mock proxy
     config_proxy = Mock()
     get_proxy.return_value = config_proxy
     # run the task and expect it to succeed
     assert task.run()
     # check service was started correctly
     start_service.assert_called_once_with("rhsm.service")
     # check proxy was requested
     get_proxy.assert_called_once()
     # check expected values were set on the RHSM config proxy
     # - logging should be always set to DEBUG
     # - SSL certificate validation should be disabled if requested
     #   (insecure == 1)
     config_proxy.SetAll.assert_called_once_with(
         {
             'logging.default_log_level': get_variant(Str, 'DEBUG'),
             'server.insecure': get_variant(Str, '1'),
         },
         ''
     )
예제 #2
0
    def test_is_service_available_waiting(self, thread_mgr_get):
        """Test StartRHSMTask - test is_service_available() - waiting."""

        # put this into a variable to fit the patch invocation on single line
        is_running_import = 'pyanaconda.modules.common.task.task.Task.is_running'
        with patch(is_running_import, new_callable=PropertyMock) as is_running:
            # fake is_running
            is_running.return_value = True
            # create the task
            task = StartRHSMTask()
            # fake get_result()
            task.get_result = Mock()
            task.get_result.return_value = True
            # make sure is_running is True
            assert task.is_running
            # assure is_running switches to False before
            # the method starts waiting on the mock thread
            mock_thread = Mock()

            def set_running_false(thread):
                is_running.return_value = False
                return mock_thread

            thread_mgr_get.side_effect = set_running_false
            # by replacing the thread by Mock instance,
            # we can avoid running the method in a thread
            # as it will join() Mock instance not a real thread
            assert task.is_service_available(timeout=1.0)
            # check that the mock thread was joined with the
            # expected timeout value
            mock_thread.join.assert_called_once_with(1.0)
예제 #3
0
    def test_success(self, start_service, get_proxy):
        """Test StartRHSMTask - successful task."""

        # create the task
        task = StartRHSMTask()
        # simulate successful systemd service start
        start_service.return_value = 0
        # return mock proxy
        config_proxy = Mock()
        get_proxy.return_value = config_proxy
        # run the task and expect it to succeed
        assert task.run()
        # check service was started correctly
        start_service.assert_called_once_with("rhsm.service")
        # check proxy was requested
        get_proxy.assert_called_once_with(
            "com.redhat.RHSM1",
            "/com/redhat/RHSM1/Config",
            "com.redhat.RHSM1.Config",
        )
        # check expected values were set on the RHSM config proxy
        # - logging should be always set to DEBUG
        # - SSL certificate validation should be enabled by default
        #   (insecure == 0)
        config_proxy.SetAll.assert_called_once_with(
            {
                'logging.default_log_level': get_variant(Str, 'DEBUG'),
            },
            ''
        )
예제 #4
0
    def test_is_service_available_timeout(self, thread_mgr_get):
        """Test StartRHSMTask - test is_service_available() - timeout."""

        # put this into a variable to fit the patch invocation on single line
        is_running_import = 'pyanaconda.modules.common.task.task.Task.is_running'

        with patch(is_running_import, new_callable=PropertyMock) as is_running:
            # fake is_running
            is_running.return_value = True
            # create the task
            task = StartRHSMTask()
            # fake get_result()
            task.get_result = Mock()
            task.get_result.return_value = False
            # make sure is_running is True
            assert task.is_running
            # us a mock thread, so that it's
            # join method exists immediately
            mock_thread = Mock()
            thread_mgr_get.return_value = mock_thread
            # test the method times out
            assert not task.is_service_available(timeout=1.0)
            # check that the mock thread join() was called with expected
            # timeout
            mock_thread.join.assert_called_once_with(1.0)
예제 #5
0
    def test_is_service_available_failure(self):
        """Test StartRHSMTask - test is_service_available() - failure."""

        # create the task
        task = StartRHSMTask()
        # fake get_result()
        task.get_result = Mock()
        task.get_result.return_value = False
        # test the method
        assert not task.is_service_available(1)
예제 #6
0
    def test_is_service_available_success(self):
        """Test StartRHSMTask - test is_service_available() - success."""

        # create the task
        task = StartRHSMTask()
        # fake get_result()
        task.get_result = Mock()
        task.get_result.return_value = True
        # test the method
        assert task.is_service_available(1)
예제 #7
0
    def __init__(self):
        super().__init__()

        # system purpose

        self._valid_roles = []
        self._valid_slas = []
        self._valid_usage_types = []

        self._system_purpose_data = SystemPurposeData()
        self.system_purpose_data_changed = Signal()

        self._load_valid_system_purpose_values()

        # subscription request

        self._subscription_request = SubscriptionRequest()
        self.subscription_request_changed = Signal()

        # attached subscriptions
        self._attached_subscriptions = []
        self.attached_subscriptions_changed = Signal()

        # Insights

        # What are the defaults for Red Hat Insights ?
        # - during a kickstart installation, the user
        #   needs to opt-in by using the rhsm command
        #   with the --connect-to-insights option
        # - during a GUI interactive installation the
        #  "connect to Insights" checkbox is checked by default,
        #  making Insights opt-out
        # - in both cases the system also needs to be subscribed,
        #   or else the system can't be connected to Insights
        self._connect_to_insights = False
        self.connect_to_insights_changed = Signal()

        # registration status
        self.registered_changed = Signal()
        self._registered = False

        # subscription status
        self.subscription_attached_changed = Signal()
        self._subscription_attached = False

        # RHSM service startup and access
        self._rhsm_startup_task = StartRHSMTask(
            verify_ssl=conf.payload.verify_ssl)
        self._rhsm_observer = RHSMObserver(
            self._rhsm_startup_task.is_service_available)

        # RHSM config default values cache
        self._rhsm_config_defaults = None
예제 #8
0
    def test_unit_start_failed(self, start_service, get_proxy):
        """Test StartRHSMTask - systemd unit failed to start."""

        # create the task
        task = StartRHSMTask()
        # simulate successful systemd service start
        start_service.return_value = 1
        # run the task and expect it to fail
        assert not task.run()
        # check service was started correctly
        start_service.assert_called_once_with("rhsm.service")
        # check proxy was not requested
        get_proxy.assert_not_called()
예제 #9
0
    def success_test(self, start_service, get_proxy):
        """Test StartRHSMTask - successful task."""

        # create the task
        task = StartRHSMTask()
        # simulate successful systemd service start
        start_service.return_value = 0
        # return mock proxy
        config_proxy = Mock()
        get_proxy.return_value = config_proxy
        # run the task and expect it to succeed
        self.assertTrue(task.run())
        # check service was started correctly
        start_service.assert_called_once_with("rhsm.service")
        # check proxy was requested
        get_proxy.assert_called_once_with(RHSM_CONFIG)
        # check expected values were set on the RHSM config proxy
        config_proxy.Set.assert_called_once_with('logging.default_log_level',
                                                 get_variant(Str, 'DEBUG'), '')