forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick elastic#20540 to 7.9: Fix Winlogbeat export index-pattern…
… with migration.6_to_7.enabled (elastic#20628) * Cherry-pick elastic#20540 to 7.x: Fix Winlogbeat export index-pattern with migration.6_to_7.enabled (elastic#20574) * Test export commands in all Beats (elastic#20016) This adds 4 new integration tests to all Beats that test export commands: > beatname export ilm-policy > beatname export template > beatname export index-pattern > beatname export config * [Filebeat] Add export tests to x-pack/filebeat (elastic#20156) * Add export tests to x-pack/filebeat Add export sub-command tests to x-pack/filebeat and add an assertion for the size the Kibana index-pattern due to the Kibana API limiting payloads to 1 MiB. * Assert size of index pattern document is less than 1 MiB * Fix Winlogbeat export index-pattern with migration.6_to_7.enabled (elastic#20540) - Test export index-pattern with migration.6_to_7.enabled=true - Always run these tests, not only when integration testing - Remove conflicting Winlogbeat alias Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co> (cherry picked from commit 66cfa25)
- Loading branch information
Showing
16 changed files
with
146 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import json | ||
import unittest | ||
import yaml | ||
|
||
from beat.beat import INTEGRATION_TESTS | ||
|
||
|
||
class TestExportsMixin: | ||
|
||
def run_export_cmd(self, cmd, extra=[]): | ||
""" | ||
Runs the given export command and returns the output as a string. | ||
Raises an exception if the command fails. | ||
:param cmd: the export command | ||
:param extra: Extra arguments (optional) | ||
:return: The output as a string. | ||
""" | ||
self.render_config_template() | ||
|
||
args = ["export", cmd] | ||
if len(extra) != 0: | ||
args += extra | ||
exit_code = self.run_beat(extra_args=args, logging_args=[]) | ||
assert exit_code == 0 | ||
output = self.get_log() | ||
trailer = "\nPASS\n" | ||
pos = output.rfind(trailer) | ||
if pos == -1: | ||
raise Exception("didn't return expected trailer:{} got:{}".format( | ||
trailer.__repr__(), | ||
output[-100:].__repr__())) | ||
return output[:pos] | ||
|
||
def test_export_ilm_policy(self): | ||
""" | ||
Test that the ilm-policy can be exported with `export ilm-policy` | ||
""" | ||
output = self.run_export_cmd("ilm-policy") | ||
js = json.loads(output) | ||
assert "policy" in js | ||
|
||
def test_export_template(self): | ||
""" | ||
Test that the template can be exported with `export template` | ||
""" | ||
output = self.run_export_cmd("template") | ||
js = json.loads(output) | ||
assert "index_patterns" in js and "mappings" in js | ||
|
||
def test_export_index_pattern(self): | ||
""" | ||
Test that the index-pattern can be exported with `export index-pattern` | ||
""" | ||
output = self.run_export_cmd("index-pattern") | ||
js = json.loads(output) | ||
assert "objects" in js | ||
size = len(output.encode('utf-8')) | ||
assert size < 1024*1024, "Kibana index pattern must be less than 1MiB " \ | ||
"to keep the Beat setup request size below " \ | ||
"Kibana's server.maxPayloadBytes." | ||
|
||
def test_export_index_pattern_migration(self): | ||
""" | ||
Test that the index-pattern can be exported with `export index-pattern` (migration enabled) | ||
""" | ||
output = self.run_export_cmd("index-pattern", extra=['-E', 'migration.6_to_7.enabled=true']) | ||
js = json.loads(output) | ||
assert "objects" in js | ||
size = len(output.encode('utf-8')) | ||
assert size < 1024*1024, "Kibana index pattern must be less than 1MiB " \ | ||
"to keep the Beat setup request size below " \ | ||
"Kibana's server.maxPayloadBytes." | ||
|
||
def test_export_config(self): | ||
""" | ||
Test that the config can be exported with `export config` | ||
""" | ||
output = self.run_export_cmd("config") | ||
yml = yaml.load(output) | ||
assert isinstance(yml, dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import os | ||
import sys | ||
from packetbeat import BaseTest | ||
|
||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../libbeat/tests/system'))) | ||
|
||
from beat import common_tests | ||
|
||
|
||
class Test(BaseTest, common_tests.TestExportsMixin): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import jinja2 | ||
import os | ||
import sys | ||
|
||
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../../filebeat/tests/system'))) | ||
|
||
from filebeat import BaseTest as FilebeatTest | ||
from beat import common_tests | ||
|
||
|
||
class FilebeatXPackTest(FilebeatTest, common_tests.TestExportsMixin): | ||
|
||
@classmethod | ||
def setUpClass(self): | ||
self.beat_name = "filebeat" | ||
self.beat_path = os.path.abspath( | ||
os.path.join(os.path.dirname(__file__), "../../")) | ||
|
||
super(FilebeatTest, self).setUpClass() | ||
|
||
def setUp(self): | ||
super(FilebeatTest, self).setUp() | ||
|
||
# Hack to make jinja2 have the right paths | ||
self.template_env = jinja2.Environment( | ||
loader=jinja2.FileSystemLoader([ | ||
os.path.abspath(os.path.join(self.beat_path, "../../filebeat")), | ||
os.path.abspath(os.path.join(self.beat_path, "../../libbeat")) | ||
]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters