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 20, 2019
1 parent 1d9df54 commit 13367b1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 32 deletions.
16 changes: 14 additions & 2 deletions changelogs/7.0.asciidoc
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
[[release-notes-7.0]]
== APM Server version 7.0

https://github.com/elastic/apm-server/compare/v6.7.0\...v7.0.0[View commits]

////
* <<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-beta1]]
=== APM Server version 7.0.0-beta1

https://github.com/elastic/apm-server/compare/v6.7.0\...v7.0.0[View commits]

[float]
==== Breaking Changes
- Move fields in ES to be ECS compliant {pull}1766[1766],{pull}1783[1783],{pull}1813[1813],{pull}1836[1836],{pull}1838[1838],{pull}1844[1844],{pull}1848[1848],{pull}1849[1849],{pull}1863[1863],{pull}1870[1870]
Expand Down
41 changes: 29 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,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
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
41 changes: 41 additions & 0 deletions tests/system/test_setup.py
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit 13367b1

Please sign in to comment.