From 836674ae9c96738791463940d713e88d5928f7d8 Mon Sep 17 00:00:00 2001 From: dongwenjuan Date: Fri, 30 Dec 2016 10:23:09 +0800 Subject: [PATCH] fix the data which post to sample inspector align to SB API Change-Id: I18b0703541aa702ec833cd102260e92831a89e3a Signed-off-by: dongwenjuan --- tests/inspector.py | 9 +++++---- tests/monitor.py | 34 ++++++++++++++++------------------ 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/tests/inspector.py b/tests/inspector.py index 129a386a..3a0e9ade 100644 --- a/tests/inspector.py +++ b/tests/inspector.py @@ -75,10 +75,11 @@ def event_posted(): LOG.info('inspector = %s' % inspector) LOG.info('received data = %s' % request.data) d = json.loads(request.data) - hostname = d['hostname'] - event_type = d['type'] - if event_type == 'compute.host.down': - inspector.disable_compute_host(hostname) + for event in d: + hostname = event['details']['hostname'] + event_type = event['type'] + if event_type == 'compute.host.down': + inspector.disable_compute_host(hostname) return "OK" diff --git a/tests/monitor.py b/tests/monitor.py index 26c911da..75d82392 100644 --- a/tests/monitor.py +++ b/tests/monitor.py @@ -78,33 +78,31 @@ class DoctorMonitorSample(object): time.sleep(self.interval) def report_error(self): + payload = [ + { + 'id': 'monitor_sample_id1', + 'time': datetime.now().isoformat(), + 'type': self.event_type, + 'details': { + 'hostname': self.hostname, + 'status': 'down', + 'monitor': 'monitor_sample', + 'monitor_event_id': 'monitor_sample_event1' + }, + }, + ] + data = json.dumps(payload) + if self.inspector_type == 'sample': - payload = {"type": self.event_type, "hostname": self.hostname} - data = json.dumps(payload) headers = {'content-type': 'application/json'} requests.post(self.inspector_url, data=data, headers=headers) elif self.inspector_type == 'congress': - data = [ - { - 'id': 'monitor_sample_id1', - 'time': datetime.now().isoformat(), - 'type': self.event_type, - 'details': { - 'hostname': self.hostname, - 'status': 'down', - 'monitor': 'monitor_sample', - 'monitor_event_id': 'monitor_sample_event1' - }, - }, - ] - headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'X-Auth-Token':self.session.get_token(), } - - requests.put(self.inspector_url, data=json.dumps(data), headers=headers) + requests.put(self.inspector_url, data=data, headers=headers) def get_args(): -- 2.16.6