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
14 from doctor_tests import config
15 from doctor_tests.identity_auth import get_identity_auth
16 from doctor_tests.identity_auth import get_session
17 from doctor_tests.image import Image
18 from doctor_tests.installer import get_installer
19 import doctor_tests.logger as doctor_log
20 from doctor_tests.os_clients import nova_client
21 from doctor_tests.scenario.fault_management import FaultManagement
22 from doctor_tests.user import User
25 Logger = doctor_log.Logger('doctor')
26 LOG = Logger.getLogger()
27 LogFile = Logger.getLogFilename()
30 class DoctorTest(object):
32 def __init__(self, conf):
34 self.image = Image(self.conf, LOG)
35 self.user = User(self.conf, LOG)
36 self.installer = get_installer(self.conf, LOG)
37 auth = get_identity_auth(project=self.conf.doctor_project)
38 self.nova = nova_client(self.conf.nova_version,
39 get_session(auth=auth))
42 # prepare the cloud env
43 self.installer.setup()
45 # preparing VM image...
48 # creating test user...
51 def test_fault_management(self):
53 LOG.info('doctor fault management test starting.......')
55 self.fault_management = \
56 FaultManagement(self.conf, self.installer, self.user, LOG)
59 self.fault_management.setup()
61 # wait for aodh alarms are updated in caches for event evaluator,
62 # sleep time should be larger than event_alarm_cache_ttl
64 # (tojuvone) Fraser currently needs 120
67 # injecting host failure...
68 # NOTE (umar) add INTERFACE_NAME logic to host injection
69 self.fault_management.start()
72 # verify the test results
73 # NOTE (umar) copy remote monitor.log file when monitor=collectd
74 self.fault_management.check_host_status('down')
75 self.fault_management.check_notification_time()
77 except Exception as e:
78 LOG.error('doctor fault management test failed, '
82 self.fault_management.cleanup()
84 def _amount_compute_nodes(self):
85 services = self.nova.services.list(binary='nova-compute')
88 def test_maintenance(self):
89 cnodes = self._amount_compute_nodes()
91 # need 2 compute for redundancy and one spare to migrate
92 LOG.info('not enough compute nodes, skipping doctor '
96 LOG.info('doctor maintenance test starting.......')
97 # TODO (tojuvone) test setup and actual test
98 except Exception as e:
99 LOG.error('doctor maintenance test failed, Exception=%s' % e)
101 # TODO (tojuvone) finally: test case specific cleanup
104 """run doctor tests"""
106 LOG.info('doctor test starting.......')
107 # prepare common test env
109 if self.conf.test_case == 'all':
110 self.test_fault_management()
111 self.test_maintenance()
113 function = 'test_%s' % self.conf.test_case
114 if hasattr(self, function):
115 getattr(self, function)()
117 raise Exception('Can not find function <%s> in'
118 'DoctorTest, see config manual'
120 except Exception as e:
121 LOG.error('doctor test failed, Exception=%s' % e)
127 self.installer.cleanup()
134 test_dir = os.path.split(os.path.realpath(__file__))[0]
135 doctor_root_dir = os.path.dirname(test_dir)
137 config_file_dir = '{0}/{1}'.format(doctor_root_dir, 'etc/')
138 config_files = [join(config_file_dir, f)
139 for f in os.listdir(config_file_dir)
140 if isfile(join(config_file_dir, f))]
142 conf = config.prepare_conf(args=sys.argv[1:],
143 config_files=config_files)
145 doctor = DoctorTest(conf)