Skip to content

Commit

Permalink
Ensure setup cmd works as expected
Browse files Browse the repository at this point in the history
Add tests for template setup.
fixes elastic#1922
  • Loading branch information
simitt committed Feb 18, 2019
1 parent e42561c commit 848e38a
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 34 deletions.
16 changes: 12 additions & 4 deletions changelogs/7.0.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@
== APM Server version 7.0

////
* <<release-notes-7.0.0-beta>>
* <<release-notes-7.0.0-rc1>>
////
* <<release-notes-7.0.0-beta1>>
* <<release-notes-7.0.0-alpha2>>
* <<release-notes-7.0.0-alpha1>>

////
[[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]

Expand Down Expand Up @@ -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
Expand Down
45 changes: 33 additions & 12 deletions tests/system/apmserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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:
Expand Down Expand Up @@ -421,3 +411,34 @@ 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(ElasticTest):
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

def tearDown(self):
# nothing to do, process already stopped
return
19 changes: 1 addition & 18 deletions tests/system/test_export.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
31 changes: 31 additions & 0 deletions tests/system/test_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import unittest

from apmserver import SubCommandTest
from beat.beat import INTEGRATION_TESTS


class SetupTemplateDefaultTest(SubCommandTest):
"""
Test setup template subcommand with default option.
"""

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
"""

assert self.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")

0 comments on commit 848e38a

Please sign in to comment.