Hi~
On 03/16/2012 01:30 PM, Alex Jia wrote:
>> +
>> + # Wait till VM is up.
>> + time.sleep(delay)
> I'm not sure whether virt_utils.wait_for() can do the same thing?
Hum, virt_utils.wait_for() can do the same thing. And it also can do the
"ping" thing below. Followed, thanks.:)
>> +
>> + exception = False
>> + try:
>> + # Confirm VM can be accessed through network.
>> + vm_ip = vm.get_address(index = 0)
>> + logging.info("VM IP: %s" % vm_ip)
>> + # Ping VM for 100 sec and return if no responding.
>> + i =1
>> + while (i<= 10):
>> + ping_result = utils.run("ping -c 2 %s" % vm_ip, ignore_status =
>> True)
>> + if ping_result.exit_status != 0:
>> + logging.info("Pinging VM %s has no responding after %d
>> sec." % (vm_name, i*10))
>> + i = i + 1
>> + time.sleep(10)
>> + else:
>> + logging.info("VM has responded.")
>> + break
>> + if i> 10:
>> + exception = True
>> + raise error.TestError("Pinging VM %s has no responding after
>> 100 sec." % vm_name)
>> +
>> + # Prepare for --xml.
>> + new_nic_mac = ""
>> + dest_xmlfile = ""
>> + if options.count("xml") or extra.count("xml"):
>> + new_nic_mac = virt_utils.generate_mac_address(vm, 1)
>> + logging.info("New mac address: %s" % new_nic_mac)
>> + dest_xmlfile = params.get("virsh_migrate_xml", "")
>> + if dest_xmlfile != "":
>> + ret_attach = vm.attach_interface("bridge", "--source virbr0
>> --mac %s" % new_nic_mac)
> I haven't seen you called vm.detach_interface() on clean up stage,
> need we to clean this environment after testing?
Actually, we don't need to detach-interface after test. I attach-interface
without a "--persistent" option,
so the nic is not persistent in VM. And once the VM is shutdown, the nic is
gone.
>> + finally:
>> + # Cleanup destination.
>> + # Make sure vm.connect_uri is the destination uri.
>> + vm.connect_uri = dest_uri
>> + if options.count("dname") or extra.count("dname"):
>> + # Use the VM object to remove
>> + vm.name = params.get("virsh_migrate_dname")
>> + cleanup_dest(vm, "")
>> + vm.name = vm_name
>> cleanup_dest(vm, src_uri)
>> +
>> + # Recover source (just in case).
>> + # vm.connect_uri has been set back to src_uri in cleanup_dest().
>> + if not libvirt_vm.virsh_domain_exists(vm_name, src_uri):
>> + vm.define(vm_xmlfile_bak)
>> + else:
>> + if not vm.shutdown():
>> + vm.destroy()
>> +
>> + # Cleanup source.
>> + if os.path.exists(vm_xmlfile_bak):
>> + os.remove(vm_xmlfile_bak)
>> + if os.path.exists(dest_xmlfile):
>> + os.remove(dest_xmlfile)
>> +
>> + if exception:
>> + raise error.TestError("Error occurred.")
>> +
>> + # Check test result.
>> + if status_error == 'yes':
>> + if ret_migrate:
>> + raise error.TestFail("Migration finished with unexpected
>> status.")
>> + else:
>> + if not ret_migrate:
>> + raise error.TestFail("Migration finished with unexpected
>> status.")
>> + if not check_dest_state:
>> + raise error.TestFail("Wrong VM state on destination.")
>> + if not check_dest_persistent:
>> + raise error.TestFail("VM is not persistent on destination.")
>> + if not check_src_undefine:
>> + raise error.TestFail("VM is not undefined on source.")
>> + if not check_dest_dname:
>> + raise error.TestFail("Wrong VM name %s on destination." %
>> dname)
>> + if not check_dest_xml:
>> + raise error.TestFail("Wrong xml configuration on
>> destination.")
>> +
>> +
>
>
--
Best Regards,
Tang chen
_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest