Пример #1
0
    def test_not_subscribed(self, exec_with_redirect):
        """Test that nothing is done if Insights is requested but system is not subscribed."""

        with tempfile.TemporaryDirectory() as sysroot:
            task = ConnectToInsightsTask(sysroot=sysroot,
                                         subscription_attached=False,
                                         connect_to_insights=True)
            task.run()
            # check that no attempt to call the Insights client has been attempted
            exec_with_redirect.assert_not_called()
Пример #2
0
    def test_utility_not_available(self, exec_with_redirect):
        """Test that the client-missing exception is raised if Insights client is missing."""

        with tempfile.TemporaryDirectory() as sysroot:
            task = ConnectToInsightsTask(sysroot=sysroot,
                                         subscription_attached=True,
                                         connect_to_insights=True)
            with self.assertRaises(InsightsClientMissingError):
                task.run()
            # check that no attempt to call the Insights client has been attempted
            exec_with_redirect.assert_not_called()
Пример #3
0
    def install_with_tasks(self):
        """Return the installation tasks of this module.

        Order of execution is important:
        - before transferring subscription tokens we need to restore
          the INFO log level in rhsm.conf or else target system will
          end up with RHSM logging in DEBUG mode
        - transfer subscription tokens
        - connect to insights, this can run only once subscription
          tokens are in place on the target system or else it would
          fail as Insights client needs the subscription tokens to
          authenticate to the Red Hat Insights online service

        :returns: list of installation tasks
        """
        return [
            RestoreRHSMDefaultsTask(
                rhsm_config_proxy=self.rhsm_observer.get_proxy(RHSM_CONFIG)),
            TransferSubscriptionTokensTask(
                sysroot=conf.target.system_root,
                transfer_subscription_tokens=self.subscription_attached),
            ConnectToInsightsTask(
                sysroot=conf.target.system_root,
                subscription_attached=self.subscription_attached,
                connect_to_insights=self.connect_to_insights)
        ]
Пример #4
0
 def test_connect_error(self, exec_with_redirect):
     """Test that the expected exception is raised if the Insights client fails when called."""
     with tempfile.TemporaryDirectory() as sysroot:
         # create a fake insights client tool file
         utility_path = ConnectToInsightsTask.INSIGHTS_TOOL_PATH
         directory = os.path.split(utility_path)[0]
         os.makedirs(util.join_paths(sysroot, directory))
         os.mknod(util.join_paths(sysroot, utility_path))
         task = ConnectToInsightsTask(sysroot=sysroot,
                                      subscription_attached=True,
                                      connect_to_insights=True)
         # make sure execWithRedirect has a non zero return code
         exec_with_redirect.return_value = 1
         with self.assertRaises(InsightsConnectError):
             task.run()
         # check that call to the insights client has been done with the expected parameters
         exec_with_redirect.assert_called_once_with(
             '/usr/bin/insights-client', ['--register'], root=sysroot)
Пример #5
0
 def test_connect(self, exec_with_redirect):
     """Test that it is possible to connect to Insights."""
     with tempfile.TemporaryDirectory() as sysroot:
         # create a fake insights client tool file
         utility_path = ConnectToInsightsTask.INSIGHTS_TOOL_PATH
         directory = os.path.split(utility_path)[0]
         # we use + here instead of os.path.join() as both paths are absolute and
         # os.path.join() does not handle that very well
         os.makedirs(sysroot + directory)
         os.mknod(sysroot + utility_path)
         task = ConnectToInsightsTask(sysroot=sysroot,
                                      subscription_attached=True,
                                      connect_to_insights=True)
         # make sure execWithRedirect has a zero return code
         exec_with_redirect.return_value = 0
         task.run()
         # check that call to the insights client has been done with the expected parameters
         exec_with_redirect.assert_called_once_with(
             '/usr/bin/insights-client', ['--register'], root=sysroot)