From 521674fcda008be86cb7babfa22e890d863e356e Mon Sep 17 00:00:00 2001 From: simitt Date: Fri, 15 Feb 2019 12:01:28 +0100 Subject: [PATCH] Ensure setup cmd works as expected Add tests for template setup. fixes #1922 --- changelogs/7.0.asciidoc | 16 +++++++++++---- tests/system/apmserver.py | 41 ++++++++++++++++++++++++++----------- tests/system/test_export.py | 19 +---------------- tests/system/test_setup.py | 41 +++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 34 deletions(-) create mode 100644 tests/system/test_setup.py diff --git a/changelogs/7.0.asciidoc b/changelogs/7.0.asciidoc index 6bef7a662ff..157d64348e1 100644 --- a/changelogs/7.0.asciidoc +++ b/changelogs/7.0.asciidoc @@ -2,15 +2,24 @@ == APM Server version 7.0 //// -* <> +* <> //// +* <> * <> * <> +//// +[[release-notes-7.0.0-rc1]] +=== APM Server version 7.0.0-rc1 + +==== Bugfix + +- Ensure setup cmd uses expected configuration {pull}1934[1934]. //// -[[release-notes-7.0.0-beta]] -=== APM Server version 7.0.0-beta + +[[release-notes-7.0.0-beta1]] +=== APM Server version 7.0.0-beta1 https://github.com/elastic/apm-server/compare/v6.7.0\...v7.0.0[View commits] @@ -43,7 +52,6 @@ https://github.com/elastic/apm-server/compare/v6.7.0\...v7.0.0[View commits] - Remove `frontend` setting {pull}1751[1751]. - Remove `metrics.enabled` setting {pull}1759[1759]. - Remove dashboards from being shipped with APM Server and all logic around them {pull}[1815]. -//// [[release-notes-7.0.0-alpha2]] === APM Server version 7.0.0-alpha2 diff --git a/tests/system/apmserver.py b/tests/system/apmserver.py index 5ec3dfc4955..6f2ad9cdddb 100644 --- a/tests/system/apmserver.py +++ b/tests/system/apmserver.py @@ -178,7 +178,7 @@ class ElasticTest(ServerBaseTest): def config(self): cfg = super(ElasticTest, self).config() cfg.update({ - "elasticsearch_host": self.get_elasticsearch_url(), + "elasticsearch_host": get_elasticsearch_url(), "file_enabled": "false", }) cfg.update(self.config_overrides) @@ -203,7 +203,7 @@ def wait_until(self, cond, max_timeout=10, poll_interval=0.1, name="cond"): time.sleep(poll_interval) def setUp(self): - self.es = Elasticsearch([self.get_elasticsearch_url()]) + self.es = Elasticsearch([get_elasticsearch_url()]) # Cleanup index and template first self.es.indices.delete(index="*", ignore=[400, 404]) @@ -224,16 +224,6 @@ def setUp(self): super(ElasticTest, self).setUp() - def get_elasticsearch_url(self): - """ - Returns an elasticsearch.Elasticsearch url built from the - env variables like the integration tests. - """ - return "http://{host}:{port}".format( - host=os.getenv("ES_HOST", "localhost"), - port=os.getenv("ES_PORT", "9200"), - ) - def load_docs_with_template(self, data_path, url, endpoint, expected_events_count, query_index=None): if query_index is None: @@ -421,3 +411,30 @@ def config(self): def get_debug_vars(self): return requests.get(self.expvar_url) + + +def get_elasticsearch_url(): + """ + Returns an elasticsearch.Elasticsearch url built from the + env variables like the integration tests. + """ + return "http://{host}:{port}".format( + host=os.getenv("ES_HOST", "localhost"), + port=os.getenv("ES_PORT", "9200"), + ) + + +class SubCommandTest(ServerSetUpBaseTest): + def wait_until_started(self): + self.apmserver_proc.check_wait() + + # command and go test output is combined in log, pull out the command output + log = self.get_log() + pos = -1 + for _ in range(2): + # export always uses \n, not os.linesep + pos = log[:pos].rfind("\n") + self.command_output = log[:pos] + for trimmed in log[pos:].strip().splitlines(): + # ensure only skipping expected lines + assert trimmed.split(None, 1)[0] in ("PASS", "coverage:"), trimmed diff --git a/tests/system/test_export.py b/tests/system/test_export.py index 61030afb1a3..f4cf33203db 100644 --- a/tests/system/test_export.py +++ b/tests/system/test_export.py @@ -1,23 +1,6 @@ -import json import yaml -from apmserver import ServerSetUpBaseTest - - -class SubCommandTest(ServerSetUpBaseTest): - def wait_until_started(self): - self.apmserver_proc.check_wait() - - # command and go test output is combined in log, pull out the command output - log = self.get_log() - pos = -1 - for _ in range(2): - # export always uses \n, not os.linesep - pos = log[:pos].rfind("\n") - self.command_output = log[:pos] - for trimmed in log[pos:].strip().splitlines(): - # ensure only skipping expected lines - assert trimmed.split(None, 1)[0] in ("PASS", "coverage:"), trimmed +from apmserver import SubCommandTest class ExportConfigDefaultTest(SubCommandTest): diff --git a/tests/system/test_setup.py b/tests/system/test_setup.py new file mode 100644 index 00000000000..31e03d6a351 --- /dev/null +++ b/tests/system/test_setup.py @@ -0,0 +1,41 @@ +import unittest + +from apmserver import SubCommandTest, get_elasticsearch_url +from beat.beat import INTEGRATION_TESTS +from elasticsearch import Elasticsearch + + +class SetupTemplateDefaultTest(SubCommandTest): + """ + Test setup template subcommand with default option. + """ + + def config(self): + cfg = super(SubCommandTest, self).config() + cfg.update({ + "elasticsearch_host": get_elasticsearch_url(), + "file_enabled": "false", + }) + return cfg + + def start_args(self): + return { + "logging_args": ["-v", "-d", "*"], + "extra_args": ["-e", + "setup", + "-template"] + } + + @unittest.skipUnless(INTEGRATION_TESTS, "integration test") + def test_setup_default_template(self): + """ + Test setup default template + """ + + es = Elasticsearch([get_elasticsearch_url()]) + assert es.indices.exists_template(name='apm-*') + assert self.log_contains("Loaded index template") + assert self.log_contains("Index setup complete") + # by default overwrite is set to true when `setup` cmd is run + assert self.log_contains("Existing template will be overwritten, as overwrite is enabled.") + self.assertNotRegexpMatches(self.get_log(), "ILM")