Skip to content

Commit 2c43b30

Browse files
s1monwbrusic
authored andcommitted
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 a79df85 commit 2c43b30

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
@@ -58,6 +58,12 @@
5858
"""
5959
env = os.environ
6060

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

6369
def log(msg):
@@ -117,10 +123,11 @@ def verify_mvn_java_version(version, mvn):
117123

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

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

125132
# Returns the name of the current branch
126133
def get_current_branch():
@@ -133,6 +140,10 @@ def get_current_branch():
133140
def release_branch(version):
134141
return 'release_branch_%s' % version
135142

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

312-
def download_and_verify(release, files, base_url='https://download.elasticsearch.org/elasticsearch/elasticsearch'):
323+
def download_and_verify(release, files, plugins=None, base_url='https://download.elasticsearch.org/elasticsearch/elasticsearch'):
313324
print('Downloading and verifying release %s from %s' % (release, base_url))
314325
tmp_dir = tempfile.mkdtemp()
315326
try:
@@ -326,11 +337,11 @@ def download_and_verify(release, files, base_url='https://download.elasticsearch
326337
urllib.request.urlretrieve(url, checksum_file)
327338
print(' Verifying checksum %s' % (checksum_file))
328339
run('cd %s && sha1sum -c %s' % (tmp_dir, os.path.basename(checksum_file)))
329-
smoke_test_release(release, downloaded_files, get_hash('v%s' % release))
340+
smoke_test_release(release, downloaded_files, get_tag_hash('v%s' % release), plugins)
330341
finally:
331342
shutil.rmtree(tmp_dir)
332343

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

481513
if build:
514+
release_version = find_release_version(src_branch)
515+
if not dry_run:
516+
smoke_test_version = release_version
482517
head_hash = get_head_hash()
483518
run_mvn('clean') # clean the env!
484519
print(' Release version: [%s]' % release_version)
@@ -497,11 +532,14 @@ def check_s3_credentials():
497532
print(''.join(['-' for _ in range(80)]))
498533
print('Building Release candidate')
499534
input('Press Enter to continue...')
500-
print(' Running maven builds now and publish to sonartype- run-tests [%s]' % run_tests)
535+
if not dry_run:
536+
print(' Running maven builds now and publish to sonartype - run-tests [%s]' % run_tests)
537+
else:
538+
print(' Running maven builds now run-tests [%s]' % run_tests)
501539
build_release(run_tests=run_tests, dry_run=dry_run, cpus=cpus)
502540
artifacts = get_artifacts(release_version)
503541
artifacts_and_checksum = generate_checksums(artifacts)
504-
smoke_test_release(release_version, artifacts, get_head_hash())
542+
smoke_test_release(release_version, artifacts, get_head_hash(), PLUGINS)
505543
print(''.join(['-' for _ in range(80)]))
506544
print('Finish Release -- dry_run: %s' % dry_run)
507545
input('Press Enter to continue...')
@@ -530,5 +568,9 @@ def check_s3_credentials():
530568
run('git tag -d v%s' % release_version)
531569
# we delete this one anyways
532570
run('git branch -D %s' % (release_branch(release_version)))
571+
else:
572+
print("Skipping build - smoketest only against version %s" % smoke_test_version)
573+
533574
if smoke_test_version:
534-
download_and_verify(smoke_test_version, artifact_names(smoke_test_version))
575+
fetch(remote)
576+
download_and_verify(smoke_test_version, artifact_names(smoke_test_version), plugins=PLUGINS)

0 commit comments

Comments
 (0)