Example #1
0
    def test_ca_cert_files_checks_are_skipped_under_dev_and_msi_install(self):
        # Skip those checks under dev and msi install because those final generated certs files
        # are not present under dev install

        from scalyr_agent.agent_main import ScalyrAgent
        from scalyr_agent.platform_controller import PlatformController

        # 1. Dev install (boths checks should be skipped)
        with mock.patch("scalyr_agent.__scalyr__.INSTALL_TYPE",
                        __scalyr__.DEV_INSTALL):

            # ca_cert_path file doesn't exist
            config = mock.Mock()
            config.scalyr_server = "foo.bar.com"
            config.compression_level = 1

            config.verify_server_certificate = True
            config.ca_cert_path = "/tmp/doesnt.exist"
            config.use_new_ingestion = False

            agent = ScalyrAgent(PlatformController())
            agent._ScalyrAgent__config = config

            self.assertTrue(create_client(config=config))

            # intermediate_certs_path file doesn't exist
            config.verify_server_certificate = True
            config.ca_cert_path = __file__
            config.intermediate_certs_path = "/tmp/doesnt.exist"

            self.assertTrue(create_client(config=config))

        # 2. MSI install (only intermediate_certs_path check should be skipped)
        with mock.patch("scalyr_agent.__scalyr__.INSTALL_TYPE",
                        __scalyr__.MSI_INSTALL):

            config = mock.Mock()
            config.scalyr_server = "foo.bar.com"
            config.compression_level = 1

            config.verify_server_certificate = True
            config.ca_cert_path = "/tmp/doesnt.exist"
            config.use_new_ingestion = False

            agent = ScalyrAgent(PlatformController())
            agent._ScalyrAgent__config = config

            expected_msg = (
                r'Invalid path "/tmp/doesnt.exist" specified for the "ca_cert_path" config '
                "option: file does not exist")

            self.assertRaisesRegexp(ValueError, expected_msg,
                                    functools.partial(create_client, config))

            # intermediate_certs_path file doesn't exist
            config.verify_server_certificate = True
            config.ca_cert_path = __file__
            config.intermediate_certs_path = "/tmp/doesnt.exist"

            self.assertTrue(create_client(config=config))
Example #2
0
    def test_ca_cert_files_checks_are_skipped_under_dev_and_msi_install(self):
        # Skip those checks under dev and msi install because those final generated certs files
        # are not present under dev install
        import scalyr_agent.agent_main

        from scalyr_agent.agent_main import ScalyrAgent
        from scalyr_agent.platform_controller import PlatformController

        # 1. Dev install (boths checks should be skipped)
        scalyr_agent.agent_main.INSTALL_TYPE = DEV_INSTALL

        # ca_cert_path file doesn't exist
        config = mock.Mock()
        config.scalyr_server = "foo.bar.com"

        config.verify_server_certificate = True
        config.ca_cert_path = "/tmp/doesnt.exist"

        agent = ScalyrAgent(PlatformController())
        agent._ScalyrAgent__config = config

        self.assertTrue(agent._ScalyrAgent__create_client())

        # intermediate_certs_path file doesn't exist
        config.verify_server_certificate = True
        config.ca_cert_path = __file__
        config.intermediate_certs_path = "/tmp/doesnt.exist"

        self.assertTrue(agent._ScalyrAgent__create_client())

        # 2. MSI install (only intermediate_certs_path check should be skipped)
        scalyr_agent.agent_main.INSTALL_TYPE = MSI_INSTALL

        config = mock.Mock()
        config.scalyr_server = "foo.bar.com"

        config.verify_server_certificate = True
        config.ca_cert_path = "/tmp/doesnt.exist"

        agent = ScalyrAgent(PlatformController())
        agent._ScalyrAgent__config = config

        expected_msg = (
            r'Invalid path "/tmp/doesnt.exist" specified for the "ca_cert_path" config '
            "option: file does not exist"
        )

        self.assertRaisesRegexp(
            ValueError, expected_msg, agent._ScalyrAgent__create_client
        )

        # intermediate_certs_path file doesn't exist
        config.verify_server_certificate = True
        config.ca_cert_path = __file__
        config.intermediate_certs_path = "/tmp/doesnt.exist"

        self.assertTrue(agent._ScalyrAgent__create_client())
Example #3
0
    def test_create_client_ca_file_and_intermediate_certs_file_doesnt_exist(self):
        from scalyr_agent.agent_main import ScalyrAgent
        from scalyr_agent.platform_controller import PlatformController

        # 1. file doesn't exist but cert verification is disabled
        config = mock.Mock()
        config.scalyr_server = "foo.bar.com"

        config.verify_server_certificate = False
        config.ca_cert_path = "/tmp/doesnt.exist"

        agent = ScalyrAgent(PlatformController())
        agent._ScalyrAgent__config = config

        self.assertTrue(agent._ScalyrAgent__create_client())

        # ca_cert_path file doesn't exist
        config.verify_server_certificate = True
        config.ca_cert_path = "/tmp/doesnt.exist"

        agent = ScalyrAgent(PlatformController())
        agent._ScalyrAgent__config = config

        expected_msg = (
            r'Invalid path "/tmp/doesnt.exist" specified for the "ca_cert_path" config '
            "option: file does not exist"
        )

        self.assertRaisesRegexp(
            ValueError, expected_msg, agent._ScalyrAgent__create_client
        )

        # intermediate_certs_path file doesn't exist
        config.verify_server_certificate = True
        config.ca_cert_path = __file__
        config.intermediate_certs_path = "/tmp/doesnt.exist"

        agent = ScalyrAgent(PlatformController())
        agent._ScalyrAgent__config = config

        expected_msg = (
            r'Invalid path "/tmp/doesnt.exist" specified for the '
            '"intermediate_certs_path" config option: file does not exist'
        )

        self.assertRaisesRegexp(
            ValueError, expected_msg, agent._ScalyrAgent__create_client
        )
Example #4
0
    def setUp(self):
        super(AgentMainStatusHandlerTestCase, self).setUp()

        self.data_path = tempfile.mkdtemp(suffix="agent-data-path")
        self.status_format_file = os.path.join(self.data_path, STATUS_FORMAT_FILE)

        default_paths = mock.Mock()
        default_paths.agent_data_path = self.data_path
        default_paths.agent_log_path = "agent.log"

        config_file = os.path.join(BASE_DIR, "fixtures/configs/agent1.json")
        config = Configuration(config_file, default_paths, None)
        config.parse()

        self.agent = ScalyrAgent(PlatformController())
        self.agent._ScalyrAgent__config = config
Example #5
0
    def test_skipped_bytes_warnings(self):
        from scalyr_agent.agent_main import ScalyrAgent
        from scalyr_agent.platform_controller import PlatformController

        with mock.patch("scalyr_agent.__scalyr__.INSTALL_TYPE",
                        __scalyr__.DEV_INSTALL):

            config = mock.Mock()
            config.scalyr_server = "foo.bar.com"
            config.server_attributes = {"serverHost": "test"}
            config.additional_file_paths = []
            config.compression_level = 1
            config.copying_manager_stats_log_interval = 60
            config.parsed_max_send_rate_enforcement = 12345

            config.verify_server_certificate = True
            config.ca_cert_path = "/tmp/doesnt.exist"

            platform_controller = PlatformController()
            platform_controller.get_usage_info = AgentMainTestCase.fake_get_useage_info
            agent = ScalyrAgent(platform_controller)
            agent._ScalyrAgent__config = config

            client = create_client(config)

            def get_worker_session_statuses_mock(*args, **kwargs):
                return [client]

            with mock.patch.object(agent,
                                   "_ScalyrAgent__copying_manager") as m:

                m.generate_status = mock.MagicMock(return_value=None)
                m.get_worker_session_statuses = get_worker_session_statuses_mock
                base_stats = agent_status.OverallStats()
                base_stats.total_bytes_skipped = 500
                test = agent._ScalyrAgent__calculate_overall_stats(
                    base_stats, copy_manager_warnings=True)
                self.assertIsNotNone(test)
                self.assertLogFileContainsLineRegex(".*" + re.escape(
                    "Warning, skipping copying log lines.  Only copied 0.0 MB/s log bytes when 0.0 MB/s were generated over the last 1.0 minutes. This may be due to max_send_rate_enforcement. Log upload has been delayed 0.0 seconds in the last 1.0 minutes  This may be desired (due to excessive bytes from a problematic log file).  Please contact [email protected] for additional help."
                ))

            config = mock.Mock()
            config.scalyr_server = "foo.bar.com"
            config.server_attributes = {"serverHost": "test"}
            config.additional_file_paths = []
            config.compression_level = 1
            config.copying_manager_stats_log_interval = 60
            config.parsed_max_send_rate_enforcement = None

            config.verify_server_certificate = True
            config.ca_cert_path = "/tmp/doesnt.exist"

            platform_controller = PlatformController()
            platform_controller.get_usage_info = AgentMainTestCase.fake_get_useage_info
            agent = ScalyrAgent(platform_controller)
            agent._ScalyrAgent__config = config

            client = create_client(config)

            with mock.patch.object(agent,
                                   "_ScalyrAgent__copying_manager") as m:
                m.generate_status = mock.MagicMock(return_value=None)
                m.get_worker_session_statuses = get_worker_session_statuses_mock

                base_stats.total_bytes_skipped = 1000
                test = agent._ScalyrAgent__calculate_overall_stats(
                    base_stats, copy_manager_warnings=True)
                self.assertIsNotNone(test)
                with open(self.agent_log_path, "r") as f:
                    print((f.read()))
                self.assertLogFileContainsLineRegex(".*" + re.escape(
                    "Warning, skipping copying log lines.  Only copied 0.0 MB/s log bytes when 0.0 MB/s were generated over the last 1.0 minutes.  This may be desired (due to excessive bytes from a problematic log file).  Please contact [email protected] for additional help."
                ))