2015-08-25 04:52:47 -04:00
|
|
|
# Licensed to Elasticsearch under one or more contributor
|
|
|
|
# license agreements. See the NOTICE file distributed with
|
|
|
|
# this work for additional information regarding copyright
|
|
|
|
# ownership. Elasticsearch licenses this file to you under
|
|
|
|
# the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing,
|
|
|
|
# software distributed under the License is distributed on
|
|
|
|
# an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
# either express or implied. See the License for the specific
|
|
|
|
# language governing permissions and limitations under the License.
|
|
|
|
|
|
|
|
# Smoke-tests a release candidate
|
|
|
|
#
|
|
|
|
# 1. Downloads the tar.gz, deb, RPM and zip file from the staging URL
|
|
|
|
# 2. Verifies it's sha1 hashes and GPG signatures against the release key
|
|
|
|
# 3. Installs all official plugins
|
|
|
|
# 4. Starts one node for tar.gz and zip packages and checks:
|
2016-03-30 08:54:04 -04:00
|
|
|
# -- if it runs with Java 1.8
|
2015-08-25 04:52:47 -04:00
|
|
|
# -- if the build hash given is the one that is returned by the status response
|
|
|
|
# -- if the build is a release version and not a snapshot version
|
|
|
|
# -- if all plugins are loaded
|
|
|
|
# -- if the status response returns the correct version
|
|
|
|
#
|
|
|
|
# USAGE:
|
|
|
|
#
|
2015-08-26 10:07:50 -04:00
|
|
|
# python3 -B ./dev-tools/smoke_test_rc.py --version 2.0.0-beta1 --hash bfa3e47
|
2015-08-25 04:52:47 -04:00
|
|
|
#
|
|
|
|
# to also test other plugins try run
|
|
|
|
#
|
2015-08-26 10:07:50 -04:00
|
|
|
# python3 -B ./dev-tools/smoke_test_rc.py --version 2.0.0-beta1 --hash bfa3e47 --plugins license,shield,watcher
|
2015-08-25 04:52:47 -04:00
|
|
|
#
|
|
|
|
# Note: Ensure the script is run from the elasticsearch top level directory
|
|
|
|
#
|
2015-08-26 10:07:50 -04:00
|
|
|
# For testing a release from sonatype try this:
|
|
|
|
#
|
|
|
|
# python3 -B dev-tools/smoke_test_rc.py --version 2.0.0-beta1 --hash bfa3e47 --fetch_url https://oss.sonatype.org/content/repositories/releases/
|
|
|
|
#
|
2015-08-25 04:52:47 -04:00
|
|
|
|
|
|
|
import argparse
|
|
|
|
import tempfile
|
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
import shutil
|
|
|
|
import urllib
|
|
|
|
import urllib.request
|
|
|
|
import hashlib
|
|
|
|
import time
|
|
|
|
import socket
|
|
|
|
import json
|
|
|
|
import base64
|
2016-04-06 03:16:19 -04:00
|
|
|
from urllib.parse import urlparse
|
2015-08-25 04:52:47 -04:00
|
|
|
|
|
|
|
from prepare_release_candidate import run
|
|
|
|
from http.client import HTTPConnection
|
|
|
|
|
|
|
|
DEFAULT_PLUGINS = ["analysis-icu",
|
|
|
|
"analysis-kuromoji",
|
|
|
|
"analysis-phonetic",
|
|
|
|
"analysis-smartcn",
|
|
|
|
"analysis-stempel",
|
2016-06-30 08:39:23 -04:00
|
|
|
"discovery-azure-classic",
|
2015-09-03 13:12:52 -04:00
|
|
|
"discovery-ec2",
|
2016-09-13 20:52:39 -04:00
|
|
|
"discovery-file",
|
2015-09-26 05:53:21 -04:00
|
|
|
"discovery-gce",
|
2016-03-30 08:54:04 -04:00
|
|
|
"ingest-attachment",
|
|
|
|
"ingest-geoip",
|
2015-08-25 04:52:47 -04:00
|
|
|
"lang-javascript",
|
|
|
|
"lang-python",
|
2015-12-23 07:24:47 -05:00
|
|
|
"mapper-attachments",
|
2015-08-25 04:52:47 -04:00
|
|
|
"mapper-murmur3",
|
2015-09-03 13:12:52 -04:00
|
|
|
"mapper-size",
|
|
|
|
"repository-azure",
|
2015-09-15 11:35:10 -04:00
|
|
|
"repository-gcs",
|
2015-12-23 07:24:47 -05:00
|
|
|
"repository-hdfs",
|
2015-09-03 13:12:52 -04:00
|
|
|
"repository-s3",
|
|
|
|
"store-smb"]
|
2015-08-25 04:52:47 -04:00
|
|
|
|
|
|
|
try:
|
|
|
|
JAVA_HOME = os.environ['JAVA_HOME']
|
|
|
|
except KeyError:
|
|
|
|
raise RuntimeError("""
|
|
|
|
Please set JAVA_HOME in the env before running release tool
|
2016-03-30 08:54:04 -04:00
|
|
|
On OSX use: export JAVA_HOME=`/usr/libexec/java_home -v '1.8*'`""")
|
2015-08-25 04:52:47 -04:00
|
|
|
|
|
|
|
def java_exe():
|
|
|
|
path = JAVA_HOME
|
|
|
|
return 'export JAVA_HOME="%s" PATH="%s/bin:$PATH" JAVACMD="%s/bin/java"' % (path, path, path)
|
|
|
|
|
|
|
|
def verify_java_version(version):
|
|
|
|
s = os.popen('%s; java -version 2>&1' % java_exe()).read()
|
|
|
|
if ' version "%s.' % version not in s:
|
|
|
|
raise RuntimeError('got wrong version for java %s:\n%s' % (version, s))
|
|
|
|
|
|
|
|
|
|
|
|
def sha1(file):
|
|
|
|
with open(file, 'rb') as f:
|
|
|
|
return hashlib.sha1(f.read()).hexdigest()
|
|
|
|
|
|
|
|
def read_fully(file):
|
|
|
|
with open(file, encoding='utf-8') as f:
|
|
|
|
return f.read()
|
|
|
|
|
|
|
|
|
2016-04-06 03:16:19 -04:00
|
|
|
def wait_for_node_startup(es_dir, timeout=60, header={}):
|
2015-08-25 04:52:47 -04:00
|
|
|
print(' Waiting until node becomes available for at most %s seconds' % timeout)
|
|
|
|
for _ in range(timeout):
|
2016-04-06 03:16:19 -04:00
|
|
|
conn = None
|
2015-08-25 04:52:47 -04:00
|
|
|
try:
|
|
|
|
time.sleep(1)
|
2016-04-28 08:34:31 -04:00
|
|
|
host = get_host_from_ports_file(es_dir)
|
|
|
|
conn = HTTPConnection(host, timeout=1)
|
|
|
|
conn.request('GET', '/', headers=header)
|
2015-08-25 04:52:47 -04:00
|
|
|
res = conn.getresponse()
|
|
|
|
if res.status == 200:
|
|
|
|
return True
|
2016-04-06 03:16:19 -04:00
|
|
|
except IOError as e:
|
2015-08-25 04:52:47 -04:00
|
|
|
pass
|
|
|
|
#that is ok it might not be there yet
|
|
|
|
finally:
|
2016-04-06 03:16:19 -04:00
|
|
|
if conn:
|
|
|
|
conn.close()
|
2015-08-25 04:52:47 -04:00
|
|
|
return False
|
|
|
|
|
2015-10-01 09:13:23 -04:00
|
|
|
def download_and_verify(version, hash, files, base_url, plugins=DEFAULT_PLUGINS):
|
2015-08-25 04:52:47 -04:00
|
|
|
print('Downloading and verifying release %s from %s' % (version, base_url))
|
|
|
|
tmp_dir = tempfile.mkdtemp()
|
|
|
|
try:
|
|
|
|
downloaded_files = []
|
|
|
|
print(' ' + '*' * 80)
|
|
|
|
for file in files:
|
|
|
|
name = os.path.basename(file)
|
|
|
|
print(' Smoketest file: %s' % name)
|
|
|
|
url = '%s/%s' % (base_url, file)
|
|
|
|
print(' Downloading %s' % (url))
|
|
|
|
artifact_path = os.path.join(tmp_dir, file)
|
|
|
|
downloaded_files.append(artifact_path)
|
|
|
|
current_artifact_dir = os.path.dirname(artifact_path)
|
|
|
|
os.makedirs(current_artifact_dir)
|
|
|
|
urllib.request.urlretrieve(url, os.path.join(tmp_dir, file))
|
|
|
|
sha1_url = ''.join([url, '.sha1'])
|
|
|
|
checksum_file = artifact_path + ".sha1"
|
|
|
|
print(' Downloading %s' % (sha1_url))
|
|
|
|
urllib.request.urlretrieve(sha1_url, checksum_file)
|
|
|
|
print(' Verifying checksum %s' % (checksum_file))
|
|
|
|
expected = read_fully(checksum_file)
|
|
|
|
actual = sha1(artifact_path)
|
|
|
|
if expected != actual :
|
|
|
|
raise RuntimeError('sha1 hash for %s doesn\'t match %s != %s' % (name, expected, actual))
|
|
|
|
gpg_url = ''.join([url, '.asc'])
|
|
|
|
gpg_file = artifact_path + ".asc"
|
|
|
|
print(' Downloading %s' % (gpg_url))
|
|
|
|
urllib.request.urlretrieve(gpg_url, gpg_file)
|
|
|
|
print(' Verifying gpg signature %s' % (gpg_file))
|
|
|
|
# here we create a temp gpg home where we download the release key as the only key into
|
|
|
|
# when we verify the signature it will fail if the signed key is not in the keystore and that
|
|
|
|
# way we keep the executing host unmodified since we don't have to import the key into the default keystore
|
|
|
|
gpg_home_dir = os.path.join(current_artifact_dir, "gpg_home_dir")
|
|
|
|
os.makedirs(gpg_home_dir, 0o700)
|
2016-04-28 08:34:31 -04:00
|
|
|
run('gpg --homedir %s --keyserver pool.sks-keyservers.net --recv-key D88E42B4' % gpg_home_dir)
|
2015-10-01 09:13:23 -04:00
|
|
|
run('cd %s && gpg --homedir %s --verify %s' % (current_artifact_dir, gpg_home_dir, os.path.basename(gpg_file)))
|
2015-08-25 04:52:47 -04:00
|
|
|
print(' ' + '*' * 80)
|
|
|
|
print()
|
2015-10-01 09:13:23 -04:00
|
|
|
smoke_test_release(version, downloaded_files, hash, plugins)
|
2015-08-25 04:52:47 -04:00
|
|
|
print(' SUCCESS')
|
|
|
|
finally:
|
|
|
|
shutil.rmtree(tmp_dir)
|
|
|
|
|
2016-04-06 03:16:19 -04:00
|
|
|
def get_host_from_ports_file(es_dir):
|
2016-04-28 08:34:31 -04:00
|
|
|
return read_fully(os.path.join(es_dir, 'logs/http.ports')).splitlines()[0]
|
2016-04-06 03:16:19 -04:00
|
|
|
|
2015-10-01 09:13:23 -04:00
|
|
|
def smoke_test_release(release, files, expected_hash, plugins):
|
2015-08-25 04:52:47 -04:00
|
|
|
for release_file in files:
|
|
|
|
if not os.path.isfile(release_file):
|
|
|
|
raise RuntimeError('Smoketest failed missing file %s' % (release_file))
|
|
|
|
tmp_dir = tempfile.mkdtemp()
|
|
|
|
if release_file.endswith('tar.gz'):
|
2015-10-01 09:13:23 -04:00
|
|
|
run('tar -xzf %s -C %s' % (release_file, tmp_dir))
|
2015-08-25 04:52:47 -04:00
|
|
|
elif release_file.endswith('zip'):
|
2015-10-01 09:13:23 -04:00
|
|
|
run('unzip %s -d %s' % (release_file, tmp_dir))
|
2015-08-25 04:52:47 -04:00
|
|
|
else:
|
|
|
|
print(' Skip SmokeTest for [%s]' % release_file)
|
|
|
|
continue # nothing to do here
|
2016-04-06 03:16:19 -04:00
|
|
|
es_dir = os.path.join(tmp_dir, 'elasticsearch-%s' % (release))
|
|
|
|
es_run_path = os.path.join(es_dir, 'bin/elasticsearch')
|
2015-08-25 04:52:47 -04:00
|
|
|
print(' Smoke testing package [%s]' % release_file)
|
2016-04-06 03:16:19 -04:00
|
|
|
es_plugin_path = os.path.join(es_dir, 'bin/elasticsearch-plugin')
|
2015-08-25 04:52:47 -04:00
|
|
|
plugin_names = {}
|
|
|
|
for plugin in plugins:
|
|
|
|
print(' Install plugin [%s]' % (plugin))
|
2016-05-25 17:44:56 -04:00
|
|
|
run('%s; export ES_JAVA_OPTS="-Des.plugins.staging=%s"; %s %s %s' % (java_exe(), expected_hash, es_plugin_path, 'install -b', plugin))
|
2015-08-25 04:52:47 -04:00
|
|
|
plugin_names[plugin] = True
|
2016-03-30 08:54:04 -04:00
|
|
|
if 'x-pack' in plugin_names:
|
2015-08-25 04:52:47 -04:00
|
|
|
headers = { 'Authorization' : 'Basic %s' % base64.b64encode(b"es_admin:foobar").decode("UTF-8") }
|
2016-04-06 03:16:19 -04:00
|
|
|
es_shield_path = os.path.join(es_dir, 'bin/x-pack/users')
|
2015-08-25 04:52:47 -04:00
|
|
|
print(" Install dummy shield user")
|
2016-04-28 08:34:31 -04:00
|
|
|
run('%s; %s useradd es_admin -r superuser -p foobar' % (java_exe(), es_shield_path))
|
2015-08-25 04:52:47 -04:00
|
|
|
else:
|
|
|
|
headers = {}
|
2016-04-06 03:16:19 -04:00
|
|
|
print(' Starting elasticsearch deamon from [%s]' % es_dir)
|
2015-08-25 04:52:47 -04:00
|
|
|
try:
|
2016-05-19 14:08:08 -04:00
|
|
|
run('%s; %s -Enode.name=smoke_tester -Ecluster.name=prepare_release -Escript.inline=true -Escript.stored=true -Erepositories.url.allowed_urls=http://snapshot.test* %s -Epidfile=%s -Enode.portsfile=true'
|
2016-04-06 03:16:19 -04:00
|
|
|
% (java_exe(), es_run_path, '-d', os.path.join(es_dir, 'es-smoke.pid')))
|
|
|
|
if not wait_for_node_startup(es_dir, header=headers):
|
2015-08-25 04:52:47 -04:00
|
|
|
print("elasticsearch logs:")
|
|
|
|
print('*' * 80)
|
2016-04-06 03:16:19 -04:00
|
|
|
logs = read_fully(os.path.join(es_dir, 'logs/prepare_release.log'))
|
2015-08-25 04:52:47 -04:00
|
|
|
print(logs)
|
|
|
|
print('*' * 80)
|
|
|
|
raise RuntimeError('server didn\'t start up')
|
|
|
|
try: # we now get / and /_nodes to fetch basic infos like hashes etc and the installed plugins
|
2016-04-28 08:34:31 -04:00
|
|
|
host = get_host_from_ports_file(es_dir)
|
|
|
|
conn = HTTPConnection(host, timeout=20)
|
|
|
|
conn.request('GET', '/', headers=headers)
|
2015-08-25 04:52:47 -04:00
|
|
|
res = conn.getresponse()
|
|
|
|
if res.status == 200:
|
|
|
|
version = json.loads(res.read().decode("utf-8"))['version']
|
|
|
|
if release != version['number']:
|
|
|
|
raise RuntimeError('Expected version [%s] but was [%s]' % (release, version['number']))
|
|
|
|
if version['build_snapshot']:
|
|
|
|
raise RuntimeError('Expected non snapshot version')
|
2016-03-30 08:54:04 -04:00
|
|
|
if expected_hash != version['build_hash'].strip():
|
2015-08-25 04:52:47 -04:00
|
|
|
raise RuntimeError('HEAD hash does not match expected [%s] but got [%s]' % (expected_hash, version['build_hash']))
|
|
|
|
print(' Verify if plugins are listed in _nodes')
|
|
|
|
conn.request('GET', '/_nodes?plugin=true&pretty=true', headers=headers)
|
|
|
|
res = conn.getresponse()
|
|
|
|
if res.status == 200:
|
|
|
|
nodes = json.loads(res.read().decode("utf-8"))['nodes']
|
|
|
|
for _, node in nodes.items():
|
|
|
|
node_plugins = node['plugins']
|
|
|
|
for node_plugin in node_plugins:
|
|
|
|
if not plugin_names.get(node_plugin['name'].strip(), False):
|
2016-02-09 15:36:24 -05:00
|
|
|
raise RuntimeError('Unexpected plugin %s' % node_plugin['name'])
|
2015-08-25 04:52:47 -04:00
|
|
|
del plugin_names[node_plugin['name']]
|
|
|
|
if plugin_names:
|
|
|
|
raise RuntimeError('Plugins not loaded %s' % list(plugin_names.keys()))
|
|
|
|
|
|
|
|
else:
|
|
|
|
raise RuntimeError('Expected HTTP 200 but got %s' % res.status)
|
|
|
|
else:
|
|
|
|
raise RuntimeError('Expected HTTP 200 but got %s' % res.status)
|
|
|
|
finally:
|
|
|
|
conn.close()
|
|
|
|
finally:
|
2016-04-06 03:16:19 -04:00
|
|
|
pid_path = os.path.join(es_dir, 'es-smoke.pid')
|
2015-08-25 04:52:47 -04:00
|
|
|
if os.path.exists(pid_path): # try reading the pid and kill the node
|
|
|
|
pid = int(read_fully(pid_path))
|
|
|
|
os.kill(pid, signal.SIGKILL)
|
|
|
|
shutil.rmtree(tmp_dir)
|
|
|
|
print(' ' + '*' * 80)
|
|
|
|
print()
|
|
|
|
|
|
|
|
|
|
|
|
def parse_list(string):
|
|
|
|
return [x.strip() for x in string.split(',')]
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
parser = argparse.ArgumentParser(description='SmokeTests a Release Candidate from S3 staging repo')
|
|
|
|
parser.add_argument('--version', '-v', dest='version', default=None,
|
|
|
|
help='The Elasticsearch Version to smoke-tests', required=True)
|
|
|
|
parser.add_argument('--hash', '-s', dest='hash', default=None, required=True,
|
|
|
|
help='The sha1 short hash of the git commit to smoketest')
|
|
|
|
parser.add_argument('--plugins', '-p', dest='plugins', default=[], required=False, type=parse_list,
|
|
|
|
help='A list of additional plugins to smoketest')
|
2015-08-26 10:07:50 -04:00
|
|
|
parser.add_argument('--fetch_url', '-u', dest='url', default=None,
|
2015-10-01 09:13:23 -04:00
|
|
|
help='Fetched from the specified URL')
|
2015-08-25 04:52:47 -04:00
|
|
|
parser.set_defaults(hash=None)
|
|
|
|
parser.set_defaults(plugins=[])
|
|
|
|
parser.set_defaults(version=None)
|
2015-08-26 10:07:50 -04:00
|
|
|
parser.set_defaults(url=None)
|
2015-08-25 04:52:47 -04:00
|
|
|
args = parser.parse_args()
|
|
|
|
plugins = args.plugins
|
|
|
|
version = args.version
|
|
|
|
hash = args.hash
|
2015-08-26 10:07:50 -04:00
|
|
|
url = args.url
|
2015-08-27 17:20:01 -04:00
|
|
|
files = [ x % {'version': version} for x in [
|
|
|
|
'org/elasticsearch/distribution/tar/elasticsearch/%(version)s/elasticsearch-%(version)s.tar.gz',
|
|
|
|
'org/elasticsearch/distribution/zip/elasticsearch/%(version)s/elasticsearch-%(version)s.zip',
|
|
|
|
'org/elasticsearch/distribution/deb/elasticsearch/%(version)s/elasticsearch-%(version)s.deb',
|
|
|
|
'org/elasticsearch/distribution/rpm/elasticsearch/%(version)s/elasticsearch-%(version)s.rpm'
|
|
|
|
]]
|
2016-03-30 08:54:04 -04:00
|
|
|
verify_java_version('1.8')
|
2015-08-26 10:07:50 -04:00
|
|
|
if url:
|
|
|
|
download_url = url
|
|
|
|
else:
|
|
|
|
download_url = '%s/%s-%s' % ('http://download.elasticsearch.org/elasticsearch/staging', version, hash)
|
2015-10-01 09:13:23 -04:00
|
|
|
download_and_verify(version, hash, files, download_url, plugins=DEFAULT_PLUGINS + plugins)
|
2015-08-25 04:52:47 -04:00
|
|
|
|
|
|
|
|
|
|
|
|