From b35baf61e48a1d2aff88e7c3e100aa996422d849 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Sat, 29 Jul 2017 20:29:52 +0800 Subject: Correct the mapping of nodes and roles in virtual deploy JIRA: DAISY-56 Now the roles are assigned to nodes randomly, because the function 'add_hosts_interface' in tempest.py just uses zip to map the host's name to the host. libvirt_utils.py: get mac addresses from VM environment.py: save the mac addresses daisy_server.py: write a new deploy.yml which contains the mac addresses and copy the file to daisy server get_conf.py: get mac addresses from the new deploy.yml tempest.py: assigned roles to nodes when the mac addresses matched controller.xml: increase the RAM to make difference with computer nodes deploy.sh: apply this change to bash script Change-Id: Ia61b60d39d319c5d01e3505727fafc63a0585858 Signed-off-by: Alex Yang --- ci/deploy/deploy.sh | 24 ++++++++++++++++++++++++ deploy/daisy_server.py | 9 +++++++++ deploy/environment.py | 9 ++++++--- deploy/get_conf.py | 10 +++++++++- deploy/libvirt_utils.py | 18 ++++++++++-------- deploy/tempest.py | 11 ++++++++--- templates/virtual_environment/vms/controller.xml | 4 ++-- 7 files changed, 68 insertions(+), 17 deletions(-) diff --git a/ci/deploy/deploy.sh b/ci/deploy/deploy.sh index bb6418df..0abc4e25 100755 --- a/ci/deploy/deploy.sh +++ b/ci/deploy/deploy.sh @@ -330,6 +330,27 @@ ssh $SSH_PARAS $DAISY_IP "bash $REMOTE_SPACE/deploy/prepare.sh -n $NETWORK -b $I echo "====== prepare cluster and pxe ======" ssh $SSH_PARAS $DAISY_IP "python ${REMOTE_SPACE}/deploy/tempest.py --dha $DHA --network $NETWORK --cluster 'yes'" + +function get_mac_addresses_for_virtual() +{ + tmpfile=$(mktemp XXXXXXXX.yml) + cp $DHA_CONF $tmpfile + + for ((i=0;i<${#VM_MULTINODE[@]};i++));do + name=${VM_MULTINODE[$i]} + macs=$(virsh dumpxml $name | grep " %s' % (vm_name, temp_file)) - tree = ET.parse(temp_file) - root = tree.getroot() + root = ET.fromstring(vm.XMLDesc()) LI('Modify the boot order %s' % boot_devs) modify_vm_boot_order(root, boot_devs) - tree.write(temp_file) LI('Re-define and start the VM %s' % vm_name) vm.undefine() - vm = conn.defineXML(commands.getoutput('cat %s' % temp_file)) + vm = conn.defineXML(ET.tostring(root)) vm.create() vm.setAutostart(1) else: @@ -222,3 +218,9 @@ def delete_virtual_network(network_xml): conn.close() if not result: LI('Network %s is not found' % name) + + +def get_vm_mac_addresses(domain): + root = ET.fromstring(domain.XMLDesc()) + macs = root.findall('./devices/interface/mac') + return [mac.attrib['address'] for mac in macs] diff --git a/deploy/tempest.py b/deploy/tempest.py index ebd040ba..3c1a6c7d 100644 --- a/deploy/tempest.py +++ b/deploy/tempest.py @@ -68,7 +68,7 @@ def prepare_install(): print("get config...") conf = cfg.ConfigOpts() parse(conf, sys.argv[1:]) - host_interface_map, hosts_name, network_map, vip, ceph_disk_name = \ + host_interface_map, hosts_name, network_map, vip, ceph_disk_name, mac_address_map = \ get_conf.config(conf['dha'], conf['network']) if conf['cluster'] and conf['cluster'] == 'yes': print("add cluster...") @@ -90,7 +90,7 @@ def prepare_install(): hosts_info = get_hosts() cluster_info = get_cluster() cluster_id = cluster_info.id - add_hosts_interface(cluster_id, hosts_info, hosts_name, + add_hosts_interface(cluster_id, hosts_info, hosts_name, mac_address_map, host_interface_map, vip, isbare) if len(hosts_name) == 1: protocol_type = 'LVM' @@ -183,7 +183,8 @@ def get_cluster(): return cluster_info -def add_hosts_interface(cluster_id, hosts_info, hosts_name, host_interface_map, +def add_hosts_interface(cluster_id, hosts_info, hosts_name, mac_address_map, + host_interface_map, vip, isbare): for host_name, host in zip(hosts_name, hosts_info): host = host.to_dict() @@ -196,6 +197,10 @@ def add_hosts_interface(cluster_id, hosts_info, hosts_name, host_interface_map, if interface_name in host_interface_map: interface['assigned_networks'] = \ host_interface_map[interface_name] + if mac_address_map: + for nodename in mac_address_map: + if interface['mac'] in mac_address_map[nodename]: + host_name = nodename pathlist = os.listdir(iso_path) for filename in pathlist: if filename.endswith('iso'): diff --git a/templates/virtual_environment/vms/controller.xml b/templates/virtual_environment/vms/controller.xml index 22a98f51..72d255e6 100644 --- a/templates/virtual_environment/vms/controller.xml +++ b/templates/virtual_environment/vms/controller.xml @@ -1,7 +1,7 @@ controller - 8388608 - 8388608 + 12582912 + 12582912 4 /machine -- cgit 1.2.3-korg