7
def check_response(response, expected_code=200):
8
if response.status_code != expected_code:
9
sys.exit("Elastic search did not respond as expected. \n"
10
"Expected status code: %{expected_code} \n"
11
"Status code: %{status_code} \n"
12
"Response text: %{response_text}".format(
13
expected_code=expected_code,
14
status_code=response.status_code,
15
response_text=response.text))
18
def setup_deployment(deployment, timeout=900):
19
"""Setup the deployment and wait until installed."""
21
deployment.setup(timeout=timeout)
22
deployment.sentry.wait()
23
except amulet.helpers.TimeoutError:
24
amulet.raise_status(amulet.SKIP, msg="Environment wasn't setup in time")
29
def get_unit_address(deployment, unit_number=0):
30
unit = deployment.sentry.unit['elasticsearch/%s' % unit_number]
31
elastic_ip = unit.info['public-address']
32
return 'http://' + elastic_ip + ":9200"
35
def get_cluster_health(deployment, unit_number=0, wait_for_nodes=0,
37
addr = get_unit_address(deployment, unit_number=0)
38
addr = addr + "/_cluster/health?timeout={}s".format(timeout)
39
if wait_for_nodes > 0:
40
addr = addr + "&wait_for_nodes={}".format(wait_for_nodes)
41
response = requests.get(addr)
42
check_response(response, expected_code=200)
43
return response.json()
46
def get_index_health(deployment, index_name, unit_number=0):
47
addr = get_unit_address(deployment, unit_number=0)
48
response = requests.get(addr + "/_cluster/health/" + index_name)
49
check_response(response, expected_code=200)
50
return response.json()
53
def assert_unit_ok(deployment, unit_number=0):
54
addr = get_unit_address(d, unit_number=unit_number)
55
response = requests.get(addr + "/_nodes/process")
56
check_response(response, expected_code=200)
57
response_dict = response.json()
58
if not response_dict['ok']:
59
sys.exit("Elastic search responded with ok=%s" % response_dict['ok'])