Пример #1
0
    def test_doesnt_call_collect_logs_on_invalid_cgroups(self):
        try:
            CollectLogsHandler.enable_cgroups_validation()

            @staticmethod
            def mock_cgroup_paths(*args, **kwargs):
                if args and args[0] == "self":
                    return ("NOT_THE_CORRECT_PATH", "NOT_THE_CORRECT_PATH")
                return SystemdCgroupsApi.get_process_cgroup_relative_paths(
                    *args, **kwargs)

            with patch.object(SystemdCgroupsApi,
                              "get_process_cgroup_relative_paths",
                              mock_cgroup_paths):
                agent = Agent(False,
                              conf_file_path=os.path.join(
                                  data_dir, "test_waagent.conf"))

                exit_error = RuntimeError("Exiting")
                with patch("sys.exit", return_value=exit_error) as mock_exit:
                    try:
                        agent.collect_logs(is_full_mode=True)
                    except RuntimeError as re:
                        mock_exit.assert_called_once_with(
                            logcollector.INVALID_CGROUPS_ERRCODE)
                        self.assertEqual(exit_error, re)
        finally:
            CollectLogsHandler.disable_cgroups_validation()
Пример #2
0
    def test_calls_collect_logs_on_valid_cgroups(self, mock_log_collector):
        try:
            CollectLogsHandler.enable_cgroups_validation()

            @staticmethod
            def mock_cgroup_paths(*args, **kwargs):
                if args and args[0] == "self":
                    relative_path = "{0}/{1}".format(
                        cgroupconfigurator.LOGCOLLECTOR_SLICE,
                        logcollector.CGROUPS_UNIT)
                    return (cgroupconfigurator.LOGCOLLECTOR_SLICE,
                            relative_path)
                return SystemdCgroupsApi.get_process_cgroup_relative_paths(
                    *args, **kwargs)

            with patch.object(SystemdCgroupsApi,
                              "get_process_cgroup_relative_paths",
                              mock_cgroup_paths):
                agent = Agent(False,
                              conf_file_path=os.path.join(
                                  data_dir, "test_waagent.conf"))
                agent.collect_logs(is_full_mode=True)

                mock_log_collector.assert_called_once()
        finally:
            CollectLogsHandler.disable_cgroups_validation()
Пример #3
0
    def test_agent_passes_configuration_path(self, mock_load, mock_handler):

        mock_daemon = Mock()
        mock_daemon.run = Mock()
        mock_handler.return_value = mock_daemon

        agent = Agent(False, conf_file_path="/foo/bar.conf")
        agent.daemon()

        mock_daemon.run.assert_called_once_with(child_args="-configuration-path:/foo/bar.conf")
        self.assertEqual(1, mock_load.call_count)
Пример #4
0
    def test_agent_does_not_pass_configuration_path(self, mock_load,
                                                    mock_handler):

        mock_daemon = Mock()
        mock_daemon.run = Mock()
        mock_handler.return_value = mock_daemon

        agent = Agent(False)
        agent.daemon()

        mock_daemon.run.assert_called_once_with(child_args=None)
        self.assertEqual(1, mock_load.call_count)
Пример #5
0
    def test_agent_get_configuration(self):
        Agent(False, conf_file_path=os.path.join(data_dir, "test_waagent.conf"))

        actual_configuration = []
        configuration = conf.get_configuration()
        for k in sorted(configuration.keys()):
            actual_configuration.append("{0} = {1}".format(k, configuration[k]))
        self.assertListEqual(EXPECTED_CONFIGURATION, actual_configuration)
Пример #6
0
    def test_agent_ensures_extension_log_directory(self, mock_dir):
        ext_log_dir = os.path.join(self.tmp_dir, "FauxLogDir")
        mock_dir.return_value = ext_log_dir

        self.assertFalse(os.path.isdir(ext_log_dir))
        agent = Agent(False,  # pylint: disable=unused-variable
                    conf_file_path=os.path.join(data_dir, "test_waagent.conf"))
        self.assertTrue(os.path.isdir(ext_log_dir))
Пример #7
0
    def test_agent_logs_if_extension_log_directory_is_a_file(self, mock_dir, mock_log):
        ext_log_dir = os.path.join(self.tmp_dir, "FauxLogDir")
        mock_dir.return_value = ext_log_dir
        fileutil.write_file(ext_log_dir, "Foo")

        self.assertTrue(os.path.isfile(ext_log_dir))
        self.assertFalse(os.path.isdir(ext_log_dir))
        agent = Agent(False,  # pylint: disable=unused-variable
                      conf_file_path=os.path.join(data_dir, "test_waagent.conf"))
        self.assertTrue(os.path.isfile(ext_log_dir))
        self.assertFalse(os.path.isdir(ext_log_dir))
        self.assertEqual(1, mock_log.call_count)
Пример #8
0
    def test_calls_collect_logs_with_proper_mode(self, mock_log_collector, *args):  # pylint: disable=unused-argument
        agent = Agent(False, conf_file_path=os.path.join(data_dir, "test_waagent.conf"))

        agent.collect_logs(is_full_mode=True)
        full_mode = mock_log_collector.call_args_list[0][0][0]
        self.assertTrue(full_mode)

        agent.collect_logs(is_full_mode=False)
        full_mode = mock_log_collector.call_args_list[1][0][0]
        self.assertFalse(full_mode)
Пример #9
0
 def test_agent_uses_default_configuration_path(self, mock_load):
     Agent(False)
     mock_load.assert_called_once_with("/etc/waagent.conf")
Пример #10
0
 def test_agent_accepts_configuration_path(self):
     Agent(False,
           conf_file_path=os.path.join(data_dir, "test_waagent.conf"))
     self.assertTrue(conf.get_fips_enabled())
Пример #11
0
 def run(self):
     _install.run(self)
     if self.register_service:
         Agent(False).register_service()