Skip to content

Commit 3ee81c5

Browse files
committed
Fix Release tool to run smoke tests off tags
this commit allows to run the release tool for smoke testing without being on the actually released branch. This commit also added a list of plugins that will be installed for smoke testing to see if the plugin startup mechanism works correctly.
1 parent 0dfacef commit 3ee81c5

File tree

1 file changed

+60
-18
lines changed

1 file changed

+60
-18
lines changed

dev-tools/build_release.py

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
"""
5858
env = os.environ
5959

60+
PLUGINS = [('bigdesk', 'lukas-vlcek/bigdesk'),
61+
('paramedic', 'karmi/elasticsearch-paramedic'),
62+
('segmentspy', 'polyfractal/elasticsearch-segmentspy'),
63+
('inquisitor', 'polyfractal/elasticsearch-inquisitor'),
64+
('head', 'mobz/elasticsearch-head')]
65+
6066
LOG = env.get('ES_RELEASE_LOG', '/tmp/elasticsearch_release.log')
6167

6268
def log(msg):
@@ -116,10 +122,11 @@ def verify_mvn_java_version(version, mvn):
116122

117123
# Returns the hash of the current git HEAD revision
118124
def get_head_hash():
119-
return get_hash('HEAD')
125+
return os.popen(' git rev-parse --verify HEAD 2>&1').read().strip()
120126

121-
def get_hash(version):
122-
return os.popen('git rev-parse --verify %s 2>&1' % (version)).read().strip()
127+
# Returns the hash of the given tag revision
128+
def get_tag_hash(tag):
129+
return os.popen('git show-ref --tags %s --hash 2>&1' % (tag)).read().strip()
123130

124131
# Returns the name of the current branch
125132
def get_current_branch():
@@ -132,6 +139,10 @@ def get_current_branch():
132139
def release_branch(version):
133140
return 'release_branch_%s' % version
134141

142+
# runs get fetch on the given remote
143+
def fetch(remote):
144+
run('git fetch %s' % remote)
145+
135146
# Creates a new release branch from the given source branch
136147
# and rebases the source branch from the remote before creating
137148
# the release branch. Note: This fails if the source branch
@@ -308,7 +319,7 @@ def generate_checksums(files):
308319
res = res + [os.path.join(directory, checksum_file), release_file]
309320
return res
310321

311-
def download_and_verify(release, files, base_url='https://download.elasticsearch.org/elasticsearch/elasticsearch'):
322+
def download_and_verify(release, files, plugins=None, base_url='https://download.elasticsearch.org/elasticsearch/elasticsearch'):
312323
print('Downloading and verifying release %s from %s' % (release, base_url))
313324
tmp_dir = tempfile.mkdtemp()
314325
try:
@@ -325,11 +336,11 @@ def download_and_verify(release, files, base_url='https://download.elasticsearch
325336
urllib.request.urlretrieve(url, checksum_file)
326337
print(' Verifying checksum %s' % (checksum_file))
327338
run('cd %s && sha1sum -c %s' % (tmp_dir, os.path.basename(checksum_file)))
328-
smoke_test_release(release, downloaded_files, get_hash('v%s' % release))
339+
smoke_test_release(release, downloaded_files, get_tag_hash('v%s' % release), plugins)
329340
finally:
330341
shutil.rmtree(tmp_dir)
331342

332-
def smoke_test_release(release, files, expected_hash):
343+
def smoke_test_release(release, files, expected_hash, plugins):
333344
for release_file in files:
334345
if not os.path.isfile(release_file):
335346
raise RuntimeError('Smoketest failed missing file %s' % (release_file))
@@ -343,9 +354,20 @@ def smoke_test_release(release, files, expected_hash):
343354
continue # nothing to do here
344355
es_run_path = os.path.join(tmp_dir, 'elasticsearch-%s' % (release), 'bin/elasticsearch')
345356
print(' Smoke testing package [%s]' % release_file)
357+
es_plugin_path = os.path.join(tmp_dir, 'elasticsearch-%s' % (release),'bin/plugin')
358+
plugin_names = {}
359+
for name, plugin in plugins:
360+
print(' Install plugin [%s] from [%s]' % (name, plugin))
361+
run('%s %s %s' % (es_plugin_path, '-install', plugin))
362+
plugin_names[name] = True
363+
364+
if release.startswith("0.90."):
365+
background = '' # 0.90.x starts in background automatically
366+
else:
367+
background = '-d'
346368
print(' Starting elasticsearch deamon from [%s]' % os.path.join(tmp_dir, 'elasticsearch-%s' % release))
347-
run('%s; %s -Des.node.name=smoke_tester -Des.cluster.name=prepare_release -Des.discovery.zen.ping.multicast.enabled=false'
348-
% (java_exe(), es_run_path))
369+
run('%s; %s -Des.node.name=smoke_tester -Des.cluster.name=prepare_release -Des.discovery.zen.ping.multicast.enabled=false %s'
370+
% (java_exe(), es_run_path, background))
349371
conn = HTTPConnection('127.0.0.1', 9200, 20);
350372
wait_for_node_startup()
351373
try:
@@ -359,9 +381,25 @@ def smoke_test_release(release, files, expected_hash):
359381
if version['build_snapshot']:
360382
raise RuntimeError('Expected non snapshot version')
361383
if version['build_hash'].strip() != expected_hash:
362-
raise RuntimeError('HEAD hash does not match expected [%s] but got [%s]' % (get_head_hash(), version['build_hash']))
384+
raise RuntimeError('HEAD hash does not match expected [%s] but got [%s]' % (expected_hash, version['build_hash']))
363385
print(' Running REST Spec tests against package [%s]' % release_file)
364386
run_mvn('test -Dtests.rest=%s -Dtests.class=*.*RestTests' % ("127.0.0.1:9200"))
387+
print(' Verify if plugins are listed in _nodes')
388+
conn.request('GET', '/_nodes?plugin=true&pretty=true')
389+
res = conn.getresponse()
390+
if res.status == 200:
391+
nodes = json.loads(res.read().decode("utf-8"))['nodes']
392+
for _, node in nodes.items():
393+
node_plugins = node['plugins']
394+
for node_plugin in node_plugins:
395+
if not plugin_names.get(node_plugin['name'], False):
396+
raise RuntimeError('Unexpeced plugin %s' % node_plugin['name'])
397+
del plugin_names[node_plugin['name']]
398+
if plugin_names:
399+
raise RuntimeError('Plugins not loaded %s' % list(plugin_names.keys()))
400+
401+
else:
402+
raise RuntimeError('Expected HTTP 200 but got %s' % res.status)
365403
else:
366404
raise RuntimeError('Expected HTTP 200 but got %s' % res.status)
367405
finally:
@@ -470,14 +508,11 @@ def check_s3_credentials():
470508
print('Preparing Release from branch [%s] running tests: [%s] dryrun: [%s]' % (src_branch, run_tests, dry_run))
471509
print(' JAVA_HOME is [%s]' % JAVA_HOME)
472510
print(' Running with maven command: [%s] ' % (MVN))
473-
release_version = find_release_version(src_branch)
474-
475-
if not smoke_test_version and not dry_run:
476-
smoke_test_version = release_version
477-
elif smoke_test_version:
478-
print("Skipping build - smoketest only against version %s" % smoke_test_version)
479511

480512
if build:
513+
release_version = find_release_version(src_branch)
514+
if not dry_run:
515+
smoke_test_version = release_version
481516
head_hash = get_head_hash()
482517
run_mvn('clean') # clean the env!
483518
print(' Release version: [%s]' % release_version)
@@ -496,11 +531,14 @@ def check_s3_credentials():
496531
print(''.join(['-' for _ in range(80)]))
497532
print('Building Release candidate')
498533
input('Press Enter to continue...')
499-
print(' Running maven builds now and publish to sonartype- run-tests [%s]' % run_tests)
534+
if not dry_run:
535+
print(' Running maven builds now and publish to sonartype - run-tests [%s]' % run_tests)
536+
else:
537+
print(' Running maven builds now run-tests [%s]' % run_tests)
500538
build_release(run_tests=run_tests, dry_run=dry_run, cpus=cpus)
501539
artifacts = get_artifacts(release_version)
502540
artifacts_and_checksum = generate_checksums(artifacts)
503-
smoke_test_release(release_version, artifacts, get_head_hash())
541+
smoke_test_release(release_version, artifacts, get_head_hash(), PLUGINS)
504542
print(''.join(['-' for _ in range(80)]))
505543
print('Finish Release -- dry_run: %s' % dry_run)
506544
input('Press Enter to continue...')
@@ -529,5 +567,9 @@ def check_s3_credentials():
529567
run('git tag -d v%s' % release_version)
530568
# we delete this one anyways
531569
run('git branch -D %s' % (release_branch(release_version)))
570+
else:
571+
print("Skipping build - smoketest only against version %s" % smoke_test_version)
572+
532573
if smoke_test_version:
533-
download_and_verify(smoke_test_version, artifact_names(smoke_test_version))
574+
fetch(remote)
575+
download_and_verify(smoke_test_version, artifact_names(smoke_test_version), plugins=PLUGINS)

0 commit comments

Comments
 (0)