Add assert for return code
* Add assertion that reposne was sucess
before process response.text()
* Add header to request to avoid 406 error
Change-Id: If41598e8c1ef5d9bf36847a750008d1203b4ed84
Closes-Prod: PROD-26423
(cherry picked from commit 30bd90c986234343aabf03ec5f174026d02d4988)
diff --git a/cvp-sanity/cvp_checks/tests/test_stacklight.py b/cvp-sanity/cvp_checks/tests/test_stacklight.py
index 1ffb118..ec6ed40 100644
--- a/cvp-sanity/cvp_checks/tests/test_stacklight.py
+++ b/cvp-sanity/cvp_checks/tests/test_stacklight.py
@@ -65,14 +65,20 @@
expr_form='pillar')
IP = salt_output.values()[0]
+ headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
proxies = {"http": None, "https": None}
- resp = json.loads(requests.post('http://{0}:9200/log-{1}/_search?pretty'.
- format(IP, today),
- proxies=proxies,
- data='{"size": 0, "aggs": '
- '{"uniq_hostname": '
- '{"terms": {"size": 500, '
- '"field": "Hostname.keyword"}}}}').text)
+ data = ('{"size": 0, "aggs": '
+ '{"uniq_hostname": '
+ '{"terms": {"size": 500, '
+ '"field": "Hostname.keyword"}}}}')
+ response = requests.post(
+ 'http://{0}:9200/log-{1}/_search?pretty'.format(IP, today),
+ proxies=proxies,
+ headers=headers,
+ data=data)
+ assert 200 == response.status_code, 'Unexpected code {}'.format(
+ response.text)
+ resp = json.loads(response.text)
cluster_domain = local_salt_client.cmd('salt:control',
'pillar.get',
['_param:cluster_domain'],