diff --git a/libbeat/Jenkinsfile.yml b/libbeat/Jenkinsfile.yml index b97771161451..4ef08116814a 100644 --- a/libbeat/Jenkinsfile.yml +++ b/libbeat/Jenkinsfile.yml @@ -37,6 +37,9 @@ stages: goIntegTest: mage: "mage goIntegTest" stage: mandatory + pythonIntegTest: + mage: "mage pythonIntegTest" + stage: mandatory crosscompile: make: "make -C libbeat crosscompile" stage: mandatory diff --git a/libbeat/magefile.go b/libbeat/magefile.go index eddc4f5e7aae..937b3f880015 100644 --- a/libbeat/magefile.go +++ b/libbeat/magefile.go @@ -36,6 +36,7 @@ import ( func init() { unittest.RegisterPythonTestDeps(Fields) integtest.RegisterGoTestDeps(Fields) + integtest.RegisterPythonTestDeps(Fields) } // Build builds the Beat binary. diff --git a/libbeat/tests/files/testbeat-dashboards.zip b/libbeat/tests/files/testbeat-dashboards.zip index 1a68706ed719..78c185faaafd 100644 Binary files a/libbeat/tests/files/testbeat-dashboards.zip and b/libbeat/tests/files/testbeat-dashboards.zip differ diff --git a/libbeat/tests/system/test_dashboard.py b/libbeat/tests/system/test_dashboard.py index 8022953042c3..338e832b0457 100644 --- a/libbeat/tests/system/test_dashboard.py +++ b/libbeat/tests/system/test_dashboard.py @@ -126,30 +126,6 @@ def test_load_only_index_patterns(self): assert self.log_contains("Kibana dashboards successfully loaded") is True - @unittest.skipUnless(INTEGRATION_TESTS, "integration test") - @pytest.mark.tag('integration') - def test_export_dashboard_cmd_export_dashboard_by_id_and_decoding(self): - """ - Test testbeat export dashboard can export dashboards - and removes unsupported characters - """ - self.render_config_template() - self.test_load_dashboard() - beat = self.start_beat( - logging_args=["-e", "-d", "*"], - extra_args=["export", - "dashboard", - "-E", "setup.kibana.protocol=http", - "-E", "setup.kibana.host=" + self.get_kibana_host(), - "-E", "setup.kibana.port=" + self.get_kibana_port(), - "-decode", - "-id", "Metricbeat-system-overview"] - ) - - beat.check_wait(exit_code=0) - - assert self.log_contains("\"id\": \"Metricbeat-system-overview\",") is True - @unittest.skipUnless(INTEGRATION_TESTS, "integration test") @pytest.mark.tag('integration') def test_export_dashboard_cmd_export_dashboard_by_id(self): @@ -165,12 +141,12 @@ def test_export_dashboard_cmd_export_dashboard_by_id(self): "-E", "setup.kibana.protocol=http", "-E", "setup.kibana.host=" + self.get_kibana_host(), "-E", "setup.kibana.port=" + self.get_kibana_port(), - "-id", "Metricbeat-system-overview"] + "-id", "Metricbeat-system-overview", + "-folder", "system-overview"] ) beat.check_wait(exit_code=0) - - assert self.log_contains("\"id\": \"Metricbeat-system-overview\",") is True + self._check_if_dashboard_exported("system-overview") @unittest.skipUnless(INTEGRATION_TESTS, "integration test") @pytest.mark.tag('integration') @@ -186,7 +162,8 @@ def test_export_dashboard_cmd_export_dashboard_by_id_unknown_id(self): "-E", "setup.kibana.protocol=http", "-E", "setup.kibana.host=" + self.get_kibana_host(), "-E", "setup.kibana.port=" + self.get_kibana_port(), - "-id", "No-such-dashboard"] + "-id", "No-such-dashboard", + "-folder", "system-overview"] ) beat.check_wait(exit_code=1) @@ -194,61 +171,6 @@ def test_export_dashboard_cmd_export_dashboard_by_id_unknown_id(self): expected_error = re.compile("error exporting dashboard:.*not found", re.IGNORECASE) assert self.log_contains(expected_error) - @unittest.skipUnless(INTEGRATION_TESTS, "integration test") - @pytest.mark.tag('integration') - def test_export_dashboard_cmd_export_dashboard_from_yml(self): - """ - Test testbeat export dashboard can export dashboards from dashboards YAML file - and removes unsupported characters - """ - - self.render_config_template() - self.test_load_dashboard() - beat = self.start_beat( - logging_args=["-e", "-d", "*"], - extra_args=["export", - "dashboard", - "-E", "setup.kibana.protocol=http", - "-E", "setup.kibana.host=" + self.get_kibana_host(), - "-E", "setup.kibana.port=" + self.get_kibana_port(), - "-yml", os.path.join(self.beat_path, "tests", "files", "dashboards.yml")] - ) - - beat.check_wait(exit_code=0) - - version = self.get_version() - kibana_semver = semver.VersionInfo.parse(version) - exported_dashboard_path = os.path.join(self.beat_path, "tests", "files", "_meta", - "kibana", str(kibana_semver.major), "dashboard", "Metricbeat-system-test-overview.ndjson") - - with open(exported_dashboard_path) as f: - content = f.read() - assert "Metricbeat-system-overview" in content - - os.remove(exported_dashboard_path) - - @unittest.skipUnless(INTEGRATION_TESTS, "integration test") - @pytest.mark.tag('integration') - def test_export_dashboard_cmd_export_dashboard_from_not_existent_yml(self): - """ - Test testbeat export dashboard fails gracefully when cannot find YAML file - """ - - self.render_config_template() - beat = self.start_beat( - logging_args=["-e", "-d", "*"], - extra_args=["export", - "dashboard", - "-E", "setup.kibana.protocol=http", - "-E", "setup.kibana.host=" + self.get_kibana_host(), - "-E", "setup.kibana.port=" + self.get_kibana_port(), - "-yml", os.path.join(self.beat_path, "tests", "files", "no-such-file.yml")] - ) - - beat.check_wait(exit_code=1) - assert self.log_contains("Error exporting dashboards from yml") - assert self.log_contains("error opening the list of dashboards") - @unittest.skipUnless(INTEGRATION_TESTS, "integration test") @pytest.mark.tag('integration') def test_dev_tool_export_dashboard_by_id(self): @@ -258,60 +180,17 @@ def test_dev_tool_export_dashboard_by_id(self): self.test_load_dashboard() - path = os.path.normpath(self.beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go") - command = path + " -kibana http://" + self.get_kibana_host() + ":" + self.get_kibana_port() - command = "go run " + command + " -dashboard Metricbeat-system-overview" - - p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - content, err = p.communicate() - - assert p.returncode == 0 - - assert os.path.isfile("output.ndjson") is True - - with open('output.ndjson') as f: - content = f.read() - assert "Metricbeat-system-overview" in content - - os.remove("output.ndjson") - - @unittest.skipUnless(INTEGRATION_TESTS, "integration test") - @pytest.mark.tag('integration') - def test_dev_tool_export_dashboard_by_id_to_folder(self): - """ - Test dev-tools/cmd/dashboards exports dashboard and removes unsupported characters - and separates each asset into a file under the appropriate folder - """ - - self.test_load_dashboard() - - folder_name = "my-system" + folder_name = "system-overview" path = os.path.normpath(self.beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go") command = path + " -kibana http://" + self.get_kibana_host() + ":" + self.get_kibana_port() command = "go run " + command + " -dashboard Metricbeat-system-overview -folder " + folder_name p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) content, err = p.communicate() - print(content, err) assert p.returncode == 0 - assert os.path.isfile("output.ndjson") is False - assert os.path.isdir(folder_name) is True - - kibana_semver = semver.VersionInfo.parse(self.get_version()) - assets_root = os.path.join(folder_name, "_meta", "kibana", str(kibana_semver.major)) - assert os.path.isdir(assets_root) is True - assert os.path.isdir(os.path.join(assets_root, "dashboard")) is True - assert os.path.isdir(os.path.join(assets_root, "visualization")) is True - - with open(os.path.join(assets_root, "dashboard", "Metricbeat-system-overview.json")) as dashboard_file: - dashboard = json.load(dashboard_file) - for reference in dashboard["references"]: - reference_path = os.path.join(assets_root, reference["type"], reference["id"]+".json") - assert os.path.isfile(reference_path) - - shutil.rmtree(folder_name) + self._check_if_dashboard_exported(folder_name) @unittest.skipUnless(INTEGRATION_TESTS, "integration test") @pytest.mark.tag('integration') @@ -343,52 +222,28 @@ def test_dev_tool_export_dashboard_by_id_from_space(self): self.test_load_dashboard_into_space(False) + folder_name = "system-overview" path = os.path.normpath(self.beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go") command = path + " -kibana http://" + self.get_kibana_host() + ":" + self.get_kibana_port() - command = "go run " + command + " -dashboard Metricbeat-system-overview -space-id foo-bar" + command = "go run " + command + " -dashboard Metricbeat-system-overview -space-id foo-bar -folder " + folder_name p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) content, err = p.communicate() assert p.returncode == 0 - assert os.path.isfile("output.ndjson") is True - - with open('output.ndjson') as f: - content = f.read() - assert "Metricbeat-system-overview" in content - - os.remove("output.ndjson") - - @unittest.skipUnless(INTEGRATION_TESTS, "integration test") - @pytest.mark.tag('integration') - def test_dev_tool_export_dashboard_from_yml(self): - """ - Test dev-tools/cmd/dashboards exports dashboard from dashboards YAML file - and removes unsupported characters - """ - - self.test_load_dashboard() - - path = os.path.normpath(self.beat_path + "/../dev-tools/cmd/dashboards/export_dashboards.go") - command = path + " -kibana http://" + self.get_kibana_host() + ":" + self.get_kibana_port() - command = "go run " + command + " -yml " + os.path.join(self.beat_path, "tests", "files", "dashboards.yml") - - p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - content, err = p.communicate() - - assert p.returncode == 0 + self._check_if_dashboard_exported(folder_name) - version = self.get_version() - kibana_semver = semver.VersionInfo.parse(version) - exported_dashboard_path = os.path.join(self.beat_path, "tests", "files", "_meta", - "kibana", str(kibana_semver.major), "dashboard", "Metricbeat-system-test-overview.ndjson") + def _check_if_dashboard_exported(self, folder_name): + kibana_semver = semver.VersionInfo.parse(self.get_version()) + dashboard_folder = os.path.join(folder_name, "_meta", "kibana", str(kibana_semver.major), "dashboard") + assert os.path.isdir(dashboard_folder) - with open(exported_dashboard_path) as f: + with open(os.path.join(dashboard_folder, "Metricbeat-system-overview.json")) as f: content = f.read() assert "Metricbeat-system-overview" in content - os.remove(exported_dashboard_path) + shutil.rmtree(folder_name) def get_host(self): return os.getenv('ES_HOST', 'localhost') + ':' + os.getenv('ES_PORT', '9200')