def test_start_security_disabled(self, mock_tarfile_open, mock_dump,
                                     mock_file, mock_pid, mock_process):

        dependency_installer = MagicMock()

        service = ServiceOpenSearch(self.version, self.additional_config,
                                    False, dependency_installer, self.work_dir)

        bundle_full_name = "test_bundle_name"
        dependency_installer.download_dist.return_value = bundle_full_name

        mock_dump_result_for_security = MagicMock()
        mock_dump_result_for_additional_config = MagicMock()

        mock_dump.side_effect = [
            mock_dump_result_for_security,
            mock_dump_result_for_additional_config
        ]

        mock_bundle_tar = MagicMock()
        mock_tarfile_open.return_value = mock_bundle_tar

        mock_file_hanlder_for_security = mock_open().return_value
        mock_file_hanlder_for_additional_config = mock_open().return_value

        # open() will be called twice, one for disabling security, second for additional_config
        mock_file.side_effect = [
            mock_file_hanlder_for_security,
            mock_file_hanlder_for_additional_config
        ]

        # call test target function
        service.start()

        mock_dump.assert_has_calls([
            call({"plugins.security.disabled": "true"}),
            call(self.additional_config)
        ])

        mock_file.assert_has_calls(
            [
                call(
                    os.path.join(self.work_dir, "opensearch-1.1.0", "config",
                                 "opensearch.yml"), "a")
            ],
            [
                call(
                    os.path.join(self.work_dir, "opensearch-1.1.0", "config",
                                 "opensearch.yml"), "a")
            ],
        )
        mock_file_hanlder_for_security.write.assert_called_once_with(
            mock_dump_result_for_security)
        mock_file_hanlder_for_additional_config.write.assert_called_once_with(
            mock_dump_result_for_additional_config)
Esempio n. 2
0
    def test_start(self, mock_tarfile_open: Mock, mock_dump: Mock, mock_file: Mock, mock_pid: Mock, mock_process: Mock) -> None:

        dependency_installer = MagicMock()

        service = ServiceOpenSearch(
            self.version,
            self.distribution,
            self.additional_config,
            True,
            dependency_installer,
            self.work_dir
        )

        bundle_full_name = "test_bundle_name"
        dependency_installer.download_dist.return_value = bundle_full_name

        mock_dump_result = MagicMock()
        mock_dump.return_value = mock_dump_result

        mock_bundle_tar = MagicMock()
        mock_tarfile_open.return_value.__enter__.return_value = mock_bundle_tar

        # call test target function
        service.start()

        mock_process.assert_called_once_with("./opensearch-tar-install.sh", os.path.join(self.work_dir, "opensearch-1.1.0"))

        mock_dump.assert_called_once_with(self.additional_config)

        mock_file.assert_called_once_with(os.path.join(self.work_dir, "opensearch-1.1.0", "config", "opensearch.yml"), "a")
        mock_file.return_value.write.assert_called_once_with(mock_dump_result)

        dependency_installer.download_dist.assert_called_once_with(self.work_dir)
        mock_tarfile_open.assert_called_once_with(bundle_full_name, "r:gz")
        mock_bundle_tar.extractall.assert_called_once_with(self.work_dir)

        self.assertEqual(mock_pid.call_count, 1)