1 ##############################################################################
2 # Copyright (c) 2017 ZTE Corporation and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
10 from os.path import isfile, join
13 from traceback import format_exc
15 from doctor_tests import config
16 from doctor_tests.identity_auth import get_identity_auth
17 from doctor_tests.identity_auth import get_session
18 from doctor_tests.image import Image
19 from doctor_tests.installer import get_installer
20 import doctor_tests.logger as doctor_log
21 from doctor_tests.scenario.fault_management import FaultManagement
22 from doctor_tests.os_clients import nova_client
23 from doctor_tests.scenario.maintenance import Maintenance
24 from doctor_tests.user import User
27 Logger = doctor_log.Logger('doctor')
28 LOG = Logger.getLogger()
29 LogFile = Logger.getLogFilename()
32 class DoctorTest(object):
34 def __init__(self, conf):
36 self.image = Image(self.conf, LOG)
37 self.user = User(self.conf, LOG)
38 self.installer = get_installer(self.conf, LOG)
39 auth = get_identity_auth(project=self.conf.doctor_project)
40 self.nova = nova_client(self.conf.nova_version,
41 get_session(auth=auth))
44 # prepare the cloud env
45 self.installer.setup()
47 # preparing VM image...
50 # creating test user...
53 def test_fault_management(self):
55 LOG.info('doctor fault management test starting.......')
56 transport_url = self.installer.get_transport_url()
57 self.fault_management = \
58 FaultManagement(self.conf, self.installer, self.user, LOG,
62 self.fault_management.setup()
64 # wait for aodh alarms are updated in caches for event evaluator,
65 # sleep time should be larger than event_alarm_cache_ttl
67 # (tojuvone) Fraser currently needs 120
70 # injecting host failure...
71 # NOTE (umar) add INTERFACE_NAME logic to host injection
72 self.fault_management.start()
75 # verify the test results
76 # NOTE (umar) copy remote monitor.log file when monitor=collectd
77 self.fault_management.check_host_status('down')
78 self.fault_management.check_notification_time()
80 except Exception as e:
81 LOG.error('doctor fault management test failed, '
83 LOG.error(format_exc())
86 self.fault_management.cleanup()
88 def _amount_compute_nodes(self):
89 services = self.nova.services.list(binary='nova-compute')
92 def test_maintenance(self):
93 cnodes = self._amount_compute_nodes()
95 # need 2 compute for redundancy and one spare to migrate
96 LOG.info('not enough compute nodes, skipping doctor '
99 elif self.conf.installer.type != 'apex':
100 LOG.info('not supported installer, skipping doctor '
104 LOG.info('doctor maintenance test starting.......')
105 trasport_url = self.installer.get_transport_url()
106 maintenance = Maintenance(trasport_url, self.conf, LOG)
107 maintenance.setup_maintenance(self.user)
109 # wait for aodh alarms are updated in caches for event evaluator,
110 # sleep time should be larger than event_alarm_cache_ttl
112 LOG.info('wait aodh for 120s.......')
115 session_id = maintenance.start_maintenance()
116 maintenance.wait_maintenance_complete(session_id)
118 LOG.info('doctor maintenance complete.......')
120 except Exception as e:
121 LOG.error('doctor maintenance test failed, Exception=%s' % e)
122 LOG.error(format_exc())
125 maintenance.cleanup_maintenance()
128 """run doctor tests"""
130 LOG.info('doctor test starting.......')
132 # prepare common test env
135 if self.conf.test_case == 'all':
136 self.test_fault_management()
137 self.test_maintenance()
139 function = 'test_%s' % self.conf.test_case
140 if hasattr(self, function):
141 getattr(self, function)()
143 raise Exception('Can not find function <%s> in'
144 'DoctorTest, see config manual'
146 except Exception as e:
147 LOG.error('doctor test failed, Exception=%s' % e)
148 LOG.error(format_exc())
154 self.installer.cleanup()
161 test_dir = os.path.split(os.path.realpath(__file__))[0]
162 doctor_root_dir = os.path.dirname(test_dir)
164 config_file_dir = '{0}/{1}'.format(doctor_root_dir, 'etc/')
165 config_files = [join(config_file_dir, f)
166 for f in os.listdir(config_file_dir)
167 if isfile(join(config_file_dir, f))]
169 conf = config.prepare_conf(args=sys.argv[1:],
170 config_files=config_files)
172 doctor = DoctorTest(conf)