diff options
author | Carlos Goncalves <carlos.goncalves@neclab.eu> | 2016-08-11 13:04:14 +0000 |
---|---|---|
committer | Ryota Mibu <r-mibu@cq.jp.nec.com> | 2016-08-19 11:01:12 +0000 |
commit | 1f2f6c3c33b74ca81eaeecba969720c85aad107d (patch) | |
tree | dfe4955252f2bd138461711c2a45db813e1884fe /tests/monitor.py | |
parent | abe65660eb689b6717a77aeeda8e445c2c68099b (diff) |
Test Congress Doctor driver support
When running Congress as Inspector implementation, the Monitor has to be
started after starting the Inspector because we need to first ensure the
Doctor datasource is created, otherwise the Monitor cannot get the
Doctor datasource ID at init.
This patch defaults the Inspector to 'sample' and for the time being
functest will run only against 'sample', not all supported Inspector
types ('sample' and 'congress'). Testing multiple Inspectors in single
functest run would require major additional changes to our test scripts.
It should still be done and addressed in a future patch. This patch
focus on adding testing support against Congress as first step.
One can test against Congress executing for example:
$ INSPECTOR_TYPE=congress INSTALLER_TYPE=local COMPUTE_HOST=compute1 ./run.sh
JIRA: DOCTOR-56
Change-Id: Icebd6fd6ad0c01d511c97e804727ad2a71f742e8
Signed-off-by: Carlos Goncalves <carlos.goncalves@neclab.eu>
Diffstat (limited to 'tests/monitor.py')
-rw-r--r-- | tests/monitor.py | 65 |
1 files changed, 59 insertions, 6 deletions
diff --git a/tests/monitor.py b/tests/monitor.py index 9e489865..caf4c321 100644 --- a/tests/monitor.py +++ b/tests/monitor.py @@ -8,16 +8,23 @@ ############################################################################## import argparse +from datetime import datetime import json +import os import requests import socket +import sys import time +from congressclient.v1 import client +from keystoneclient import session as ksc_session +from keystoneclient.auth.identity import v2 # NOTE: icmp message with all zero data (checksum = 0xf7ff) # see https://tools.ietf.org/html/rfc792 ICMP_ECHO_MESSAGE = '\x08\x00\xf7\xff\x00\x00\x00\x00' +SUPPORTED_INSPECTOR_TYPES = ['sample', 'congress'] class DoctorMonitorSample(object): @@ -26,10 +33,30 @@ class DoctorMonitorSample(object): event_type = "compute.host.down" def __init__(self, args): + if args.inspector_type not in SUPPORTED_INSPECTOR_TYPES: + raise Exception("Inspector type '%s' not supported", args.inspector_type) + self.hostname = args.hostname - self.inspector = args.inspector + self.inspector_url = args.inspector_url + self.inspector_type = args.inspector_type self.ip_addr = args.ip or socket.gethostbyname(self.hostname) + if self.inspector_type == 'congress': + auth = v2.Password(auth_url=os.environ['OS_AUTH_URL'], + username=os.environ['OS_USERNAME'], + password=os.environ['OS_PASSWORD'], + tenant_name=os.environ['OS_TENANT_NAME']) + self.session = ksc_session.Session(auth=auth) + + congress = client.Client(session=self.session, service_type='policy') + ds = congress.list_datasources()['results'] + doctor_ds = next((item for item in ds if item['driver'] == 'doctor'), + None) + + congress_endpoint = congress.httpclient.get_endpoint(auth=auth) + self.inspector_url = ('%s/v1/data-sources/%s/tables/events/rows' % + (congress_endpoint, doctor_ds['id'])) + def start_loop(self): print "start ping to host %(h)s (ip=%(i)s)" % {'h': self.hostname, 'i': self.ip_addr} @@ -48,10 +75,33 @@ class DoctorMonitorSample(object): time.sleep(self.interval) def report_error(self): - payload = {"type": self.event_type, "hostname": self.hostname} - data = json.dumps(payload) - headers = {'content-type': 'application/json'} - requests.post(self.inspector, data=data, headers=headers) + 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) def get_args(): @@ -60,7 +110,10 @@ def get_args(): help='a hostname to monitor connectivity') parser.add_argument('ip', metavar='IP', type=str, nargs='?', help='an IP address to monitor connectivity') - parser.add_argument('inspector', metavar='INSPECTOR', type=str, nargs='?', + parser.add_argument('inspector_type', metavar='INSPECTOR_TYPE', type=str, nargs='?', + help='inspector to report', + default='sample') + parser.add_argument('inspector_url', metavar='INSPECTOR_URL', type=str, nargs='?', help='inspector url to report error', default='http://127.0.0.1:12345/events') return parser.parse_args() |