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 alarm import Alarm
15 from consumer import get_consumer
16 from image import Image
17 from instance import Instance
18 from inspector import get_inspector
19 from installer import get_installer
20 import logger as doctor_log
22 from network import Network
23 from monitor import get_monitor
26 LOG = doctor_log.Logger('doctor').getLogger()
29 class DoctorTest(object):
31 def __init__(self, conf):
33 self.image = Image(self.conf, LOG)
34 self.user = User(self.conf, LOG)
35 self.network = Network(self.conf, LOG)
36 self.instance = Instance(self.conf, LOG)
37 self.alarm = Alarm(self.conf, LOG)
38 self.inspector = get_inspector(self.conf, LOG)
39 self.monitor = get_monitor(self.conf,
40 self.inspector.get_inspector_url(),
42 self.consumer = get_consumer(self.conf, LOG)
43 self.installer = get_installer(self.conf, LOG)
46 # prepare the cloud env
47 self.installer.setup()
49 # preparing VM image...
52 # creating test user...
54 self.user.update_quota()
58 self.instance.create()
59 self.instance.wait_for_vm_launch()
64 # starting doctor sample components...
65 self.inspector.start()
72 LOG.info('doctor test starting.......')
76 # injecting host failure...
78 # verify the test results
80 except Exception as e:
81 LOG.error('doctor test failed, Exception=%s' % e)
88 self.instance.delete()
95 self.installer.cleanup()
100 doctor_root_dir = os.path.dirname(sys.path[0])
101 config_file_dir = '{0}/{1}'.format(doctor_root_dir, 'etc/')
102 config_files = [join(config_file_dir, f) for f in os.listdir(config_file_dir)
103 if isfile(join(config_file_dir, f))]
105 conf = config.prepare_conf(args=sys.argv[1:],
106 config_files=config_files)
108 doctor = DoctorTest(conf)
112 if __name__ == '__main__':