Merge "Change PTL informatin in INFO"
[bottlenecks.git] / testsuites / vstf / vstf_scripts / vstf / agent / env / plugins / libvirt_plugin.py
1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd and others.
3 #
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 ##############################################################################
9
10 import logging
11
12 from vstf.common.utils import ping, my_sleep
13 from vstf.agent.env.plugins.model import EnvBuilderPlugin
14 from vstf.agent.env.basic.source_manager import SourceCodeManager
15 from vstf.agent.env.basic.vm_manager import VMControlOperation
16 from vstf.agent.env.vswitch_plugins.manager import VswitchPluginManager
17 from vstf.agent.env.driver_plugins.manager import DriverPluginManager
18
19 LOG = logging.getLogger(__name__)
20
21
22 class Plugin(EnvBuilderPlugin):
23
24     def __init__(self):
25         super(Plugin, self).__init__()
26         self.vm_mgr = VMControlOperation()
27         self.vs_mgr = VswitchPluginManager()
28         self.dr_mgr = DriverPluginManager()
29
30     def clean(self):
31         self.vm_mgr.clean_all_vms()
32         self.vs_mgr.clean()
33         self.dr_mgr.clean()
34
35     def load_drivers(self):
36         drivers = self.host_cfg['drivers']
37         self.dr_mgr.load(drivers)
38
39     def create_brs(self):
40         for br_cfg in self.host_cfg['bridges']:
41             plugin = self.vs_mgr.get_vs_plugin(br_cfg['type'])
42             plugin.create_br(br_cfg)
43
44     def config_br_ports(self):
45         for vm_cfg in self.host_cfg['vms']:
46             for tap_cfg in vm_cfg['taps']:
47                 plugin = self.vs_mgr.get_vs_plugin(tap_cfg['br_type'])
48                 plugin.set_tap_vid(tap_cfg)
49         for br_cfg in self.host_cfg['bridges']:
50             plugin = self.vs_mgr.get_vs_plugin(br_cfg['type'])
51             plugin.set_fastlink(br_cfg)
52
53     def create_vms(self):
54         for vm_cfg in self.host_cfg['vms']:
55             self.vm_mgr.create_vm(vm_cfg)
56
57     def wait_vms(self):
58         for vm_cfg in self.host_cfg['vms']:
59             self.vm_mgr.wait_vm(vm_cfg['vm_name'])
60             self.vm_mgr.init_config_vm(vm_cfg['vm_name'])
61
62     def check_vm_connectivity(self):
63         for vm_cfg in self.host_cfg['vms']:
64             vm_ip = vm_cfg['init_config']['ctrl_ip_setting'].split('/')[0]
65             for _ in range(3):
66                 ret = ping(vm_ip)
67                 if ret:
68                     break
69                 my_sleep(3)
70             else:
71                 raise Exception("ping ip:%s failed." % vm_ip)