Skip to content

Commit 050cc96

Browse files
authored
Do not hardcode IP addresses in Ansible inventory groups
Since we already define the IP addresses of the target hosts in Jenkins[1], there's no need to duplicate this information in static inventory files, when setting up fixtures with night-rally. Switch to a dynamic inventory script for setting up the needed host groups for Ansible fixtures. [1] https://github.com/elastic/infra/blob/8dd21b2e6e451407515186ab60e71b5d22114ba9/ci/jjb/elasticsearch-ci/globals/templates/elastic-elasticsearch/macrobenchmarks.yml#L26-L29 Relates elastic#75
1 parent 8684458 commit 050cc96

File tree

9 files changed

+113
-45
lines changed

9 files changed

+113
-45
lines changed

night_rally/fixtures/ansible/Vagrantfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ master_ip = '192.168.180.10'
55

66
benchmark_boxes = %w(
77
coordinator
8-
target1
8+
target01
9+
memorybenchmark01
910
)
1011

1112
nodes = benchmark_boxes.collect do |nodename|

night_rally/fixtures/ansible/inventory/local/vagrant.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def update_the_cache():
176176
_group: list(ssh_config.keys()),
177177
'elasticsearch-ci-slaves-macrobenchmarks': [i for i in all_hostnames if 'coordinator' in i],
178178
'macrobenchmarks-targets': [i for i in all_hostnames if 'target' in i],
179+
'memorybenchmarks': [i for i in all_hostnames if 'memorybenchmark' in i],
179180
'_meta': meta
180181
}, **vagrant_groups(ssh_config)))
181182
cache = open(cache_file, 'w')
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python
2+
3+
'''
4+
Extremely simple dynamic inventory script for Ansible.
5+
6+
Expects TARGET_HOSTS env var to create the target-hosts group
7+
and COORDINATING_NODES env var to create the coordinating-nodes group.
8+
'''
9+
10+
import argparse
11+
import os
12+
13+
try:
14+
import json
15+
except ImportError:
16+
import simplejson as json
17+
18+
ANSIBLE_SSH_PRIVATE_KEY_FILE = "/var/lib/jenkins/.ssh/rally"
19+
ANSIBLE_USER = "rally"
20+
21+
class Inventory(object):
22+
def __init__(self):
23+
self.inventory = {}
24+
self.read_cli_args()
25+
26+
# Called with `--list`
27+
if self.args.list:
28+
self.inventory = self.build_inventory()
29+
# Called with `--host [hostname]`
30+
elif self.args.host:
31+
# Not implemented as `--list`` returns _meta
32+
# see https://docs.ansible.com/ansible/latest/dev_guide/developing_inventory.html#tuning-the-external-inventory-script
33+
self.inventory = self.empty_inventory()
34+
# --refresh is a no-op as we don't cache results
35+
elif self.args.refresh:
36+
return
37+
else:
38+
self.inventory = self.empty_inventory()
39+
40+
print json.dumps(self.inventory);
41+
42+
def build_inventory(self):
43+
inventory = self.dynamic_groups(group_name="target-hosts", env_var="TARGET_HOSTS").copy()
44+
inventory.update(self.dynamic_groups(group_name="coordinating-nodes", env_var="COORDINATING_NODES"))
45+
inventory.update(
46+
{
47+
'_meta': {
48+
'hostvars': {}
49+
}
50+
}
51+
)
52+
53+
return inventory
54+
55+
def dynamic_groups(self, group_name=None, env_var=None):
56+
if group_name is None or env_var is None or env_var not in os.environ:
57+
return {}
58+
else:
59+
group_hosts = os.environ[env_var]
60+
61+
return {
62+
group_name: {
63+
'hosts': group_hosts.split(","),
64+
'vars': {
65+
'ansible_ssh_user': ANSIBLE_USER,
66+
'ansible_ssh_private_key_file': ANSIBLE_SSH_PRIVATE_KEY_FILE
67+
}
68+
}
69+
}
70+
71+
def empty_inventory(self):
72+
return {'_meta': {'hostvars': {}}}
73+
74+
def read_cli_args(self):
75+
parser = argparse.ArgumentParser()
76+
parser.add_argument('--list', action = 'store_true')
77+
parser.add_argument('--host', action = 'store')
78+
parser.add_argument('--refresh', action = 'store_true')
79+
self.args = parser.parse_args()
80+
81+
Inventory()

night_rally/fixtures/ansible/inventory/production/macrobenchmarks

Lines changed: 0 additions & 17 deletions
This file was deleted.

night_rally/fixtures/ansible/playbooks/setup.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
22

3-
- name: run fixtures on macrobenchmarks targets
4-
# =============================================
5-
hosts: macrobenchmarks-targets
3+
- name: run fixtures on target hosts
4+
# ==================================
5+
hosts: target-hosts
66
gather_facts: true
77
roles:
88
- { role: trim, tags: trim }

night_rally/fixtures/ansible/playbooks/update-rally.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# ================================================================
55
# First the Rally master (coordinating node which is running on the (only) Jenkins slave node, then the Rally slaves (running
66
# on the target machines)
7-
hosts: elasticsearch-ci-slaves-macrobenchmarks, macrobenchmarks-targets
7+
hosts: coordinating-nodes, target-hosts
88
gather_facts: true
99
roles:
1010
- { role: rally-update, tags: rally-update }

night_rally/fixtures/ansible/roles/rally-update/tasks/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222

2323
- name: start rallyd
24-
command: ./rallyd start --node-ip {{ inventory_hostname }} --coordinator-ip {{ groups['elasticsearch-ci-slaves-macrobenchmarks'][0] }}
24+
command: ./rallyd start --node-ip {{ inventory_hostname }} --coordinator-ip {{ groups['coordinating-nodes'][0] }}
2525
args:
2626
chdir: /var/lib/jenkins/bin
2727
environment:

night_rally/night_rally.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
ROOT = os.path.dirname(os.path.realpath(__file__))
1313
RALLY_BINARY = "rally --skip-update"
14-
1514
VERSION_PATTERN = re.compile("^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$")
15+
# The port that Elasticsearch is configured to use for rest requests
16+
TARGET_PORT = 39200
1617

1718
# console logging
1819
logging.basicConfig(level=logging.INFO, format="[%(asctime)s][%(levelname)s] %(message)s")
@@ -472,6 +473,8 @@ def __str__(self):
472473

473474

474475
def run_rally(tracks, available_hosts, command, dry_run=False, skip_ansible=False, system=os.system):
476+
# Build list of host:port pairs for target hosts
477+
available_hosts_with_ports = list(map(lambda x: "{}:{}".format(x, TARGET_PORT), available_hosts))
475478
rally_failure = False
476479
if dry_run:
477480
runner = logger.info
@@ -480,7 +483,7 @@ def run_rally(tracks, available_hosts, command, dry_run=False, skip_ansible=Fals
480483
for track in tracks:
481484
track_name = track["track"]
482485
for combination in track["combinations"]:
483-
race_cfg = RaceConfig(track_name, combination, available_hosts)
486+
race_cfg = RaceConfig(track_name, combination, available_hosts_with_ports)
484487

485488
if race_cfg.target_hosts:
486489
if command.runnable(race_cfg):
@@ -495,7 +498,7 @@ def run_rally(tracks, available_hosts, command, dry_run=False, skip_ansible=Fals
495498
logger.info("Running Rally on [%s]", race_cfg)
496499
start = time.perf_counter()
497500
try:
498-
wait_until_port_is_free(available_hosts)
501+
wait_until_port_is_free(available_hosts_with_ports)
499502
if runner(command.command_line(race_cfg)):
500503
rally_failure = True
501504
logger.error("Failed to run [%s]. Please check the logs.", race_cfg)

tests/night_rally_test.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,13 @@ def test_run_two_challenges_successfully(self, mocked_wait_until_port_is_free):
121121
self.assertEqual(2, len(system_call.calls))
122122
self.assertEqual(
123123
[
124-
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost\" "
124+
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost:39200\" "
125125
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
126126
"--car=\"defaults\" --user-tag=\"env:bare,name:geonames-defaults\" --runtime-jdk=\"8\" "
127127
"--car-params=\"verbose_iw_logging_enabled:true\" --pipeline=\"from-sources-complete\" "
128128
"--revision=\"@2016-01-01T00:00:00Z\"",
129129

130-
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost\" "
130+
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost:39200\" "
131131
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
132132
"--car=\"4gheap\" --user-tag=\"env:bare,name:geonames-4g\" --runtime-jdk=\"8\" --pipeline=\"from-sources-skip-build\" "
133133
"--revision=\"@2016-01-01T00:00:00Z\""
@@ -170,12 +170,12 @@ def test_run_two_tracks_successfully(self, mocked_wait_until_port_is_free):
170170
self.assertEqual(2, len(system_call.calls))
171171
self.assertEqual(
172172
[
173-
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost\" "
173+
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost:39200\" "
174174
"--effective-start-date=\"2016-10-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
175175
"--car=\"defaults\" --user-tag=\"env:bare,name:geonames-defaults\" --runtime-jdk=\"8\" "
176176
"--pipeline=\"from-sources-complete\" --revision=\"@2016-10-01T00:00:00Z\"",
177177

178-
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost\" "
178+
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost:39200\" "
179179
"--effective-start-date=\"2016-10-01 00:00:00\" --track=\"percolator\" --challenge=\"append-no-conflicts\" "
180180
"--car=\"4gheap\" --user-tag=\"env:bare,name:percolator-4g\" --runtime-jdk=\"8\" --pipeline=\"from-sources-skip-build\" "
181181
"--revision=\"@2016-10-01T00:00:00Z\""
@@ -219,12 +219,12 @@ def test_run_adhoc_benchmark(self, mocked_wait_until_port_is_free):
219219
self.assertEqual(2, len(system_call.calls))
220220
self.assertEqual(
221221
[
222-
"rally --skip-update --configuration-name=\"lucene-7\" --quiet --target-host=\"localhost\" "
222+
"rally --skip-update --configuration-name=\"lucene-7\" --quiet --target-host=\"localhost:39200\" "
223223
"--effective-start-date=\"2016-10-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
224224
"--car=\"defaults\" --user-tag=\"env:bare,name:geonames-defaults\" --runtime-jdk=\"8\" "
225225
"--pipeline=\"from-sources-complete\" --revision=\"66202dc\"",
226226

227-
"rally --skip-update --configuration-name=\"lucene-7\" --quiet --target-host=\"localhost\" "
227+
"rally --skip-update --configuration-name=\"lucene-7\" --quiet --target-host=\"localhost:39200\" "
228228
"--effective-start-date=\"2016-10-01 00:00:00\" --track=\"percolator\" --challenge=\"append-no-conflicts\" "
229229
"--car=\"4gheap\" --user-tag=\"env:bare,name:percolator-4g\" --runtime-jdk=\"8\" "
230230
"--pipeline=\"from-sources-skip-build\" --revision=\"66202dc\""
@@ -261,12 +261,12 @@ def test_run_release_benchmark_without_plugins(self, mocked_wait_until_port_is_f
261261
self.assertEqual(2, len(system_call.calls))
262262
self.assertEqual(
263263
[
264-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
264+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
265265
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
266266
"--car=\"defaults\" --user-tag=\"env:bare,name:geonames-defaults\" --runtime-jdk=\"8\" --distribution-version=\"5.3.0\" "
267267
"--pipeline=\"from-distribution\"",
268268

269-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
269+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
270270
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
271271
"--car=\"4gheap\" --user-tag=\"env:bare,name:geonames-4g\" --runtime-jdk=\"8\" --distribution-version=\"5.3.0\" "
272272
"--pipeline=\"from-distribution\""
@@ -315,14 +315,14 @@ def test_run_release_benchmark_with_plugins(self, mocked_wait_until_port_is_free
315315
self.assertEqual(2, len(system_call.calls))
316316
self.assertEqual(
317317
[
318-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
318+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
319319
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
320320
"--car=\"defaults\" --user-tag=\"env:x-pack,name:geonames-defaults,x-pack:true\" --runtime-jdk=\"8\" "
321321
"--track-params=\"bulk_size:3000\" --client-options=\"timeout:60,use_ssl:true,verify_certs:false,basic_auth_user:'rally',"
322322
"basic_auth_password:'rally-password'\" --elasticsearch-plugins=\"x-pack:security,monitoring\" "
323323
"--distribution-version=\"5.3.0\" --pipeline=\"from-distribution\"",
324324

325-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
325+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
326326
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
327327
"--car=\"4gheap\" --user-tag=\"env:x-pack,name:geonames-4g,x-pack:true\" --runtime-jdk=\"8\" "
328328
"--track-params=\"bulk_size:2000\" --client-options=\"timeout:60,use_ssl:true,verify_certs:false,basic_auth_user:'rally',"
@@ -371,13 +371,13 @@ def test_run_release_benchmark_with_x_pack_module(self, mocked_wait_until_port_i
371371
self.assertEqual(2, len(system_call.calls))
372372
self.assertEqual(
373373
[
374-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
374+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
375375
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
376376
"--car=\"defaults,x-pack-security,x-pack-monitoring\" --user-tag=\"env:x-pack,name:geonames-defaults,x-pack:true\" "
377377
"--runtime-jdk=\"8\" --client-options=\"timeout:60,use_ssl:true,verify_certs:false,basic_auth_user:'rally',"
378378
"basic_auth_password:'rally-password'\" --distribution-version=\"6.3.0\" --pipeline=\"from-distribution\"",
379379

380-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
380+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
381381
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
382382
"--car=\"4gheap,x-pack-security,x-pack-monitoring\" --user-tag=\"env:x-pack,name:geonames-4g,x-pack:true\" "
383383
"--runtime-jdk=\"8\" --client-options=\"timeout:60,use_ssl:true,verify_certs:false,basic_auth_user:'rally',"
@@ -412,7 +412,7 @@ def test_run_release_benchmark_with_transport_nio(self, mocked_wait_until_port_i
412412
self.assertEqual(1, len(system_call.calls))
413413
self.assertEqual(
414414
[
415-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
415+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
416416
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
417417
"--car=\"defaults\" --user-tag=\"env:bare,name:geonames-defaults\" --runtime-jdk=\"8\" "
418418
"--elasticsearch-plugins=\"transport-nio:transport+http\" --distribution-version=\"7.0.0\" "
@@ -500,12 +500,12 @@ def test_run_docker_benchmark(self, mocked_wait_until_port_is_free):
500500
self.assertEqual(2, len(system_call.calls))
501501
self.assertEqual(
502502
[
503-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
503+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
504504
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
505505
"--car=\"defaults\" --user-tag=\"env:docker,name:geonames-defaults\" --runtime-jdk=\"8\" "
506506
"--distribution-version=\"5.3.0\" --pipeline=\"docker\"",
507507

508-
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost\" "
508+
"rally --skip-update --configuration-name=\"release\" --quiet --target-host=\"localhost:39200\" "
509509
"--effective-start-date=\"2016-01-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
510510
"--car=\"4gheap\" --user-tag=\"env:docker,name:geonames-4g\" --runtime-jdk=\"8\" "
511511
"--distribution-version=\"5.3.0\" --pipeline=\"docker\""
@@ -550,12 +550,12 @@ def test_run_continues_on_error(self, mocked_wait_until_port_is_free):
550550
self.assertEqual(2, len(system_call.calls))
551551
self.assertEqual(
552552
[
553-
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost\" "
553+
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost:39200\" "
554554
"--effective-start-date=\"2016-10-01 00:00:00\" --track=\"geonames\" --challenge=\"append-no-conflicts\" "
555555
"--car=\"defaults\" --user-tag=\"env:bare,name:geonames-defaults\" --runtime-jdk=\"8\" "
556556
"--pipeline=\"from-sources-complete\" --revision=\"@2016-10-01T00:00:00Z\"",
557557

558-
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost\" "
558+
"rally --skip-update --configuration-name=\"nightly\" --quiet --target-host=\"localhost:39200\" "
559559
"--effective-start-date=\"2016-10-01 00:00:00\" --track=\"percolator\" --challenge=\"append-no-conflicts\" "
560560
"--car=\"4gheap\" --user-tag=\"env:bare,name:percolator-4g\" --runtime-jdk=\"8\" "
561561
"--pipeline=\"from-sources-skip-build\" --revision=\"@2016-10-01T00:00:00Z\""
@@ -595,11 +595,10 @@ def test_run_with_telemetry(self, mocked_wait_until_port_is_free):
595595
self.assertEqual(
596596
[
597597
"rally --skip-update --telemetry=\"jfr,gc,jit\" --telemetry-params=\"recording-template:profile\" "
598-
"--configuration-name=\"nightly\" --quiet --target-host=\"localhost\" --effective-start-date=\"2016-01-01 00:00:00\" "
598+
"--configuration-name=\"nightly\" --quiet --target-host=\"localhost:39200\" --effective-start-date=\"2016-01-01 00:00:00\" "
599599
"--track=\"geonames\" --challenge=\"append-no-conflicts\" --car=\"defaults\" --user-tag=\"env:bare,name:geonames-defaults\""
600600
" --runtime-jdk=\"8\" --pipeline=\"from-sources-complete\" --revision=\"@2016-01-01T00:00:00Z\""
601601
]
602602
,
603603
system_call.calls
604604
)
605-

0 commit comments

Comments
 (0)