1 ##############################################################################
2 # Copyright (c) 2015 Huawei Technologies Co.,Ltd 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 ##############################################################################
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
19 LOG = logging.getLogger(__name__)
22 class Plugin(EnvBuilderPlugin):
25 super(Plugin, self).__init__()
26 self.vm_mgr = VMControlOperation()
27 self.vs_mgr = VswitchPluginManager()
28 self.dr_mgr = DriverPluginManager()
31 self.vm_mgr.clean_all_vms()
35 def load_drivers(self):
36 drivers = self.host_cfg['drivers']
37 self.dr_mgr.load(drivers)
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)
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)
54 for vm_cfg in self.host_cfg['vms']:
55 self.vm_mgr.create_vm(vm_cfg)
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'])
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]
71 raise Exception("ping ip:%s failed." % vm_ip)