X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=doctor_tests%2Fscenario%2Fmaintenance.py;h=e6cdcccdec4d353948e75565e1373044a01880ff;hb=34b4083b4d2d579f6dbd334df06fe9394453680a;hp=7c2c17e01c96b27c1753a4fcbea869daadf15695;hpb=73605c5c34b97ab56306bfa9af0f5888f3c7e46d;p=doctor.git diff --git a/doctor_tests/scenario/maintenance.py b/doctor_tests/scenario/maintenance.py index 7c2c17e0..e6cdcccd 100644 --- a/doctor_tests/scenario/maintenance.py +++ b/doctor_tests/scenario/maintenance.py @@ -1,5 +1,5 @@ ############################################################################## -# Copyright (c) 2018 Nokia Corporation and others. +# Copyright (c) 2019 Nokia Corporation and others. # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Apache License, Version 2.0 @@ -28,17 +28,23 @@ class Maintenance(object): def __init__(self, trasport_url, conf, log): self.conf = conf self.log = log + self.admin_session = get_session() self.keystone = keystone_client( self.conf.keystone_version, get_session()) self.nova = nova_client(conf.nova_version, get_session()) auth = get_identity_auth(project=self.conf.doctor_project) self.neutron = neutron_client(get_session(auth=auth)) self.stack = Stack(self.conf, self.log) + if self.conf.installer.type == "devstack": + self.endpoint_ip = trasport_url.split("@", 1)[1].split(":", 1)[0] + else: + self.endpoint_ip = self.conf.admin_tool.ip + self.endpoint = "http://%s:12347/" % self.endpoint_ip if self.conf.admin_tool.type == 'sample': self.admin_tool = get_admin_tool(trasport_url, self.conf, self.log) - self.endpoint = 'maintenance' + self.endpoint += 'maintenance' else: - self.endpoint = 'v1/maintenance' + self.endpoint += 'v1/maintenance' self.app_manager = get_app_manager(self.stack, self.conf, self.log) self.inspector = get_inspector(self.conf, self.log, trasport_url) @@ -127,8 +133,9 @@ class Maintenance(object): else: # TBD Now we expect Fenix is running in self.conf.admin_tool.port pass - self.app_manager.start() + # Inspector before app_manager, as floating ip might come late self.inspector.start() + self.app_manager.start() def start_maintenance(self): self.log.info('start maintenance.......') @@ -137,16 +144,15 @@ class Maintenance(object): for hvisor in hvisors: hostname = hvisor.__getattr__('hypervisor_hostname') maintenance_hosts.append(hostname) - - url = ('http://%s:%s/%s' % - (self.conf.admin_tool.ip, - self.conf.admin_tool.port, - self.endpoint)) + url = self.endpoint headers = { 'Content-Type': 'application/json', 'Accept': 'application/json'} - + if self.conf.admin_tool.type == 'fenix': + headers['X-Auth-Token'] = self.admin_session.get_token() + self.log.info('url %s headers %s' % (url, headers)) retries = 12 + ret = None while retries > 0: # let's start maintenance 20sec from now, so projects will have # time to ACK to it before that @@ -156,8 +162,12 @@ class Maintenance(object): data = {'state': 'MAINTENANCE', 'maintenance_at': maintenance_at, - 'metadata': {'openstack_version': 'Rocky'}, - 'workflow': 'default'} + 'metadata': {'openstack_version': 'Train'}} + + if self.conf.app_manager.type == 'vnfm': + data['workflow'] = 'vnf' + else: + data['workflow'] = 'default' if self.conf.admin_tool.type == 'sample': data['hosts'] = maintenance_hosts @@ -166,7 +176,7 @@ class Maintenance(object): try: ret = requests.post(url, data=json.dumps(data), headers=headers) - except: + except Exception: if retries == 0: raise Exception('admin tool did not respond in 120s') else: @@ -175,36 +185,39 @@ class Maintenance(object): time.sleep(10) continue break + if not ret: + raise Exception("admin tool did not respond") if ret.status_code != 200: raise Exception(ret.text) return ret.json()['session_id'] def remove_maintenance_session(self, session_id): self.log.info('remove maintenance session %s.......' % session_id) - url = ('http://%s:%s/%s/%s' % - (self.conf.admin_tool.ip, - self.conf.admin_tool.port, - self.endpoint, - session_id)) + + url = ('%s/%s' % (self.endpoint, session_id)) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json'} + if self.conf.admin_tool.type == 'fenix': + headers['X-Auth-Token'] = self.admin_session.get_token() + ret = requests.delete(url, data=None, headers=headers) if ret.status_code != 200: raise Exception(ret.text) def get_maintenance_state(self, session_id): - url = ('http://%s:%s/%s/%s' % - (self.conf.admin_tool.ip, - self.conf.admin_tool.port, - self.endpoint, - session_id)) + + url = ('%s/%s' % (self.endpoint, session_id)) headers = { 'Content-Type': 'application/json', 'Accept': 'application/json'} + + if self.conf.admin_tool.type == 'fenix': + headers['X-Auth-Token'] = self.admin_session.get_token() + ret = requests.get(url, data=None, headers=headers) if ret.status_code != 200: raise Exception(ret.text)