本文整理汇总了Python中autotest.client.shared.syncdata.SyncData类的典型用法代码示例。如果您正苦于以下问题:Python SyncData类的具体用法?Python SyncData怎么用?Python SyncData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SyncData类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: migration_scenario
def migration_scenario(self):
sync = SyncData(self.master_id(), self.hostid, self.hosts,
self.id, self.sync_server)
self.vm = params.get("vms").split()[0]
address_cache = env.get("address_cache")
if (self.hostid == self.master_id()):
utils.run("dd if=/dev/urandom of=%s bs=1M"
" count=%s" % (host_path, file_size))
self.vm_addr = self._prepare_vm(self.vm).get_address()
end_event = threading.Event()
bg = utils.InterruptedThread(self._copy_until_end,
(end_event,))
self._hosts_barrier(self.hosts, self.id, "befor_mig", 120)
sync.sync(address_cache, timeout=120)
error.context("ping-pong between host and guest while"
" migrating", logging.info)
self._run_and_migrate(bg, end_event, sync, migrate_count)
# Check if guest lives.
remote.wait_for_login(shell_client, self.vm_addr,
shell_port, guest_root,
guest_pass, shell_prompt)
self._hosts_barrier(self.hosts, self.id, "After_check", 120)
error.context("comparing hashes", logging.info)
orig_hash = client_utils.hash_file(host_path)
returned_hash = client_utils.hash_file(host_path_returned)
#Check all check sum
wrong_check_sum = False
for i in range(len(self.file_check_sums)):
check_sum = self.file_check_sums[i]
if check_sum != orig_hash:
wrong_check_sum = True
logging.error("Checksum in transfer number"
" %d if wrong." % (i))
if wrong_check_sum:
raise error.TestFail("Returned file hash (%s) differs from"
" original one (%s)" % (returned_hash,
orig_hash))
else:
#clean temp
utils.run("rm -rf %s" % (host_path))
utils.run("rm -rf %s" % (returned_hash))
error.context()
else:
self._hosts_barrier(self.hosts, self.id, "befor_mig", 260)
address_cache.update(sync.sync(timeout=120)[self.master_id()])
logging.debug("Address cache updated to %s" % address_cache)
self._slave_migrate(sync)
#Wait for check if guest lives.
self._hosts_barrier(self.hosts, self.id, "After_check", 120)
示例2: migration_scenario
def migration_scenario(self):
sync = SyncData(self.master_id(), self.hostid, self.hosts,
self.id, self.sync_server)
srchost = self.params.get("hosts")[0]
dsthost = self.params.get("hosts")[1]
vms = [params.get("vms").split()[0]]
def worker(mig_data):
vm = mig_data.vms[0]
session = vm.wait_for_login(timeout=self.login_timeout)
cpuflags.install_cpuflags_util_on_vm(test, vm, install_path,
extra_flags="-msse3 -msse2")
cmd = ("%s/cpuflags-test --stressmem %d,%d" %
(os.path.join(install_path, "cpu_flags"),
vm_mem * 4, vm_mem / 2))
logging.debug("Sending command: %s" % (cmd))
session.sendline(cmd)
if self.master_id() == self.hostid:
server_port = utils_misc.find_free_port(5200, 6000)
server = listen_server(port=server_port)
data_len = 0
sync.sync(server_port, timeout=120)
client = server.socket.accept()[0]
endtime = time.time() + 30
while endtime > time.time():
data_len += len(client.recv(2048))
client.close()
server.close()
self.link_speed = data_len / (30 * 1024 * 1024)
logging.info("Link speed %d MB/s" % (self.link_speed))
ms = utils.convert_data_size(mig_speed, 'M')
if (ms > data_len / 30):
logging.warn("Migration speed %s MB/s is set faster than "
"real link speed %d MB/s" % (mig_speed,
self.link_speed))
else:
self.link_speed = ms / (1024 * 1024)
else:
data = ""
for _ in range(10000):
data += "i"
server_port = sync.sync(timeout=120)[self.master_id()]
sock = socket.socket(socket.AF_INET,
socket.SOCK_STREAM)
sock.connect((self.master_id(), server_port))
try:
endtime = time.time() + 10
while endtime > time.time():
sock.sendall(data)
sock.close()
except:
pass
self.migrate_wait(vms, srchost, dsthost, worker)
示例3: _check_vms_source
def _check_vms_source(self, mig_data):
start_mig_tout = mig_data.params.get("start_migration_timeout", None)
if start_mig_tout is None:
for vm in mig_data.vms:
vm.wait_for_login(timeout=self.login_timeout)
if mig_data.params.get("host_mig_offline") != "yes":
sync = SyncData(self.master_id(), self.hostid, mig_data.hosts, mig_data.mig_id, self.sync_server)
mig_data.vm_ports = sync.sync(timeout=240)[mig_data.dst]
logging.info("Received from destination the migration port %s", str(mig_data.vm_ports))
示例4: __init__
def __init__(self, test, params, env):
super(TestMultihostMigration, self).__init__(test, params, env)
self.srchost = self.params.get("hosts")[0]
self.dsthost = self.params.get("hosts")[1]
self.is_src = params["hostid"] == self.srchost
self.vms = params["vms"].split()
self.migrate_count = int(params.get("migrate_count", "1"))
self.migration_timeout = int(params.get("migrate_timeout", "240"))
self.time_command = params["time_command"]
self.time_filter_re = params["time_filter_re"]
self.time_format = params["time_format"]
self.create_file = params["create_file"]
self.diff_limit = float(params.get("time_diff_limit", "0.1"))
self.start_ht = {}
self.start_gt = {}
self.diff_ht = {}
self.diff_gt = {}
self.id = {'src': self.srchost,
'dst': self.dsthost,
"type": "timedrift"}
self.sync = SyncData(self.master_id(), self.hostid, self.hosts,
self.id, self.sync_server)
示例5: migration_scenario
def migration_scenario(self):
srchost = self.params.get("hosts")[0]
dsthost = self.params.get("hosts")[1]
mig_port = None
if params.get("hostid") == self.master_id():
mig_port = virt_utils.find_free_port(5200, 6000)
sync = SyncData(self.master_id(), self.hostid,
self.params.get("hosts"),
{'src': srchost, 'dst': dsthost,
'port': "ports"}, self.sync_server)
mig_port = sync.sync(mig_port, timeout=120)
mig_port = mig_port[srchost]
logging.debug("Migration port %d" % (mig_port))
if params.get("hostid") != self.master_id():
s = self._connect_to_server(srchost, mig_port)
try:
fd = s.fileno()
logging.debug("File descrtiptor %d used for"
" migration." % (fd))
self.migrate_wait(["vm1"], srchost, dsthost, mig_mode="fd",
params_append={"migration_fd": fd})
finally:
s.close()
else:
s = self._create_server(mig_port)
try:
conn, _ = s.accept()
fd = conn.fileno()
logging.debug("File descrtiptor %d used for"
" migration." % (fd))
#Prohibits descriptor inheritance.
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
self.migrate_wait(["vm1"], srchost, dsthost, mig_mode="fd",
params_append={"migration_fd": fd})
conn.close()
finally:
s.close()
示例6: test
def test(self):
super(test_multihost_copy, self).test()
copy_timeout = int(params.get("copy_timeout", 480))
checksum_timeout = int(params.get("checksum_timeout", 180))
pid = None
sync_id = {'src': self.srchost,
'dst': self.dsthost,
"type": "file_trasfer"}
filename = "orig"
if self.is_src: # Starts in source
vm = env.get_vm(self.vms[0])
vm.monitor.migrate_set_speed("1G")
session = vm.wait_for_login(timeout=login_timeout)
cdrom_dev_list = list_guest_cdroms(session)
logging.debug("cdrom_dev_list: %s", cdrom_dev_list)
cdrom = cdrom_dev_list[-1]
mount_point = get_cdrom_mount_point(session, cdrom, params)
mount_cmd = params["mount_cdrom_cmd"] % (cdrom, mount_point)
src_file = params["src_file"] % (mount_point, filename)
dst_file = params["dst_file"] % filename
copy_file_cmd = params[
"copy_file_cmd"] % (mount_point, filename)
remove_file_cmd = params["remove_file_cmd"] % filename
md5sum_cmd = params["md5sum_cmd"]
if params["os_type"] != "windows":
error.context("Mount and copy data")
session.cmd(mount_cmd, timeout=30)
error.context("File copying test")
session.cmd(copy_file_cmd)
pid = disk_copy(vm, src_file, dst_file, copy_timeout)
sync = SyncData(self.mig.master_id(), self.mig.hostid,
self.mig.hosts, sync_id, self.mig.sync_server)
pid = sync.sync(pid, timeout=cdrom_prepare_timeout)[self.srchost]
self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost)
if not self.is_src: # Starts in source
vm = env.get_vm(self.vms[0])
session = vm.wait_for_login(timeout=login_timeout)
error.context("Wait for copy finishing.")
def is_copy_done():
if params["os_type"] == "windows":
cmd = "tasklist /FI \"PID eq %s\"" % pid
else:
cmd = "ps -p %s" % pid
return session.cmd_status(cmd) != 0
if utils.wait_for(is_copy_done, timeout=copy_timeout) is None:
raise error.TestFail("Wait for file copy finish timeout")
error.context("Compare file on disk and on cdrom")
f1_hash = session.cmd("%s %s" % (md5sum_cmd, dst_file),
timeout=checksum_timeout).split()[0]
f2_hash = session.cmd("%s %s" % (md5sum_cmd, src_file),
timeout=checksum_timeout).split()[0]
if f1_hash.strip() != f2_hash.strip():
raise error.TestFail("On disk and on cdrom files are"
" different, md5 mismatch")
session.cmd(remove_file_cmd)
self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts,
'Finish_cdrom_test', login_timeout)
示例7: migrate_wait
def migrate_wait(self, vms_name, srchost, dsthost, start_work=None,
check_work=None, mig_mode="fd", params_append=None):
vms_count = len(vms_name)
mig_ports = []
if self.params.get("hostid") == srchost:
last_port = 5199
for _ in range(vms_count):
last_port = utils_misc.find_free_port(last_port + 1, 6000)
mig_ports.append(last_port)
sync = SyncData(self.master_id(), self.hostid,
self.params.get("hosts"),
{'src': srchost, 'dst': dsthost,
'port': "ports"}, self.sync_server)
mig_ports = sync.sync(mig_ports, timeout=120)
mig_ports = mig_ports[srchost]
logging.debug("Migration port %s" % (mig_ports))
if self.params.get("hostid") != srchost:
sockets = []
for mig_port in mig_ports:
sockets.append(self._connect_to_server(srchost, mig_port))
try:
fds = {}
for s, vm_name in zip(sockets, vms_name):
fds["migration_fd_%s" % vm_name] = s.fileno()
logging.debug("File descrtiptors %s used for"
" migration." % (fds))
super_cls = super(MultihostMigrationFd, self)
super_cls.migrate_wait(vms_name, srchost, dsthost,
start_work=start_work, mig_mode="fd",
params_append=fds)
finally:
for s in sockets:
s.close()
else:
sockets = []
for mig_port in mig_ports:
sockets.append(self._create_server(mig_port))
try:
conns = []
for s in sockets:
conns.append(s.accept()[0])
fds = {}
for conn, vm_name in zip(conns, vms_name):
fds["migration_fd_%s" % vm_name] = conn.fileno()
logging.debug("File descrtiptors %s used for"
" migration." % (fds))
# Prohibits descriptor inheritance.
for fd in fds.values():
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
flags |= fcntl.FD_CLOEXEC
fcntl.fcntl(fd, fcntl.F_SETFD, flags)
super_cls = super(MultihostMigrationFd, self)
super_cls.migrate_wait(vms_name, srchost, dsthost,
start_work=start_work, mig_mode="fd",
params_append=fds)
for conn in conns:
conn.close()
finally:
for s in sockets:
s.close()
示例8: test
def test(self):
super(test_multihost_copy, self).test()
copy_timeout = int(params.get("copy_timeout", 480))
checksum_timeout = int(params.get("checksum_timeout", 180))
pid = None
sync_id = {'src': self.srchost,
'dst': self.dsthost,
"type": "file_trasfer"}
filename = "orig"
if self.is_src: # Starts in source
vm = env.get_vm(self.vms[0])
vm.monitor.migrate_set_speed("1G")
session = vm.wait_for_login(timeout=login_timeout)
output = session.get_command_output("ls /dev/cdrom*")
cdrom_dev_list = re.findall("/dev/cdrom-\w+|/dev/cdrom\d*",
output)
logging.debug("cdrom_dev_list: %s", cdrom_dev_list)
cdrom = cdrom_dev_list[0]
error.context("Mount and copy data")
session.cmd("mount %s %s" % (cdrom, "/mnt"), timeout=30)
error.context("File copying test")
session.cmd("rm -f /%s" % filename)
pid = disk_copy(vm, os.path.join("/mnt", filename), "/",
copy_timeout)
sync = SyncData(self.mig.master_id(), self.mig.hostid,
self.mig.hosts, sync_id, self.mig.sync_server)
pid = sync.sync(pid, timeout=cdrom_prepare_timeout)[self.srchost]
self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost)
if not self.is_src: # Starts in source
vm = env.get_vm(self.vms[0])
session = vm.wait_for_login(timeout=login_timeout)
error.context("Wait for copy finishing.")
status = int(session.cmd_status("wait %s" % pid,
timeout=copy_timeout))
if not status in [0, 127]:
raise error.TestFail("Copy process was terminatted with"
" error code %s" % (status))
if status == 127:
logging.warn("Param cdrom_size should be bigger because "
"copying finished before migration finish.")
error.context("Compare file on disk and on cdrom")
f1_hash = session.cmd("md5sum /mnt/%s" % filename,
timeout=checksum_timeout).split()[0]
f2_hash = session.cmd("md5sum /%s" % filename,
timeout=checksum_timeout).split()[0]
if f1_hash.strip() != f2_hash.strip():
raise error.TestFail("On disk and on cdrom files are"
" different, md5 mismatch")
session.cmd("rm -f /%s" % filename)
self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts,
'Finish_cdrom_test', login_timeout)
示例9: test
def test(self):
super(test_multihost_write, self).test()
copy_timeout = int(params.get("copy_timeout", 480))
self.mount_dir = params["mount_dir"]
format_floppy_cmd = params["format_floppy_cmd"]
check_copy_path = params["check_copy_path"]
pid = None
sync_id = {'src': self.srchost,
'dst': self.dsthost,
"type": "file_trasfer"}
filename = "orig"
if self.is_src: # Starts in source
vm = env.get_vm(self.vms[0])
session = vm.wait_for_login(timeout=login_timeout)
if self.mount_dir:
session.cmd("rm -f %s" % (os.path.join(self.mount_dir,
filename)))
session.cmd("rm -f %s" % (check_copy_path))
# If mount_dir specified, treat guest as a Linux OS
# Some Linux distribution does not load floppy at boot
# and Windows needs time to load and init floppy driver
error.context("Prepare floppy for writing.")
if self.mount_dir:
lsmod = session.cmd("lsmod")
if not 'floppy' in lsmod:
session.cmd("modprobe floppy")
else:
time.sleep(20)
session.cmd(format_floppy_cmd)
error.context("Mount and copy data")
if self.mount_dir:
session.cmd("mount -t vfat %s %s" % (guest_floppy_path,
self.mount_dir),
timeout=30)
error.context("File copying test")
pid = lazy_copy(vm, os.path.join(self.mount_dir, filename),
check_copy_path, copy_timeout)
sync = SyncData(self.mig.master_id(), self.mig.hostid,
self.mig.hosts, sync_id, self.mig.sync_server)
pid = sync.sync(pid, timeout=floppy_prepare_timeout)[self.srchost]
self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost)
if not self.is_src: # Starts in destination
vm = env.get_vm(self.vms[0])
session = vm.wait_for_login(timeout=login_timeout)
error.context("Wait for copy finishing.")
status = int(session.cmd_status("kill %s" % pid,
timeout=copy_timeout))
if not status in [0]:
raise error.TestFail("Copy process was terminatted with"
" error code %s" % (status))
session.cmd_status("kill -s SIGINT %s" % (pid),
timeout=copy_timeout)
error.context("Check floppy file checksum.")
md5_cmd = params.get("md5_cmd")
if md5_cmd:
md5_floppy = session.cmd("%s %s" % (params.get("md5_cmd"),
os.path.join(self.mount_dir, filename)))
try:
md5_floppy = md5_floppy.split(" ")[0]
except IndexError:
error.TestError("Failed to get md5 from source file,"
" output: '%s'" % md5_floppy)
md5_check = session.cmd("%s %s" % (params.get("md5_cmd"),
check_copy_path))
try:
md5_check = md5_check.split(" ")[0]
except IndexError:
error.TestError("Failed to get md5 from source file,"
" output: '%s'" % md5_floppy)
if md5_check != md5_floppy:
raise error.TestFail("There is mistake in copying,"
" it is possible to check file on vm.")
session.cmd("rm -f %s" % (os.path.join(self.mount_dir,
filename)))
session.cmd("rm -f %s" % (check_copy_path))
self.mig._hosts_barrier(self.mig.hosts, self.mig.hosts,
'finish_floppy_test', login_timeout)
示例10: TestMultihostMigration
class TestMultihostMigration(base_class):
def __init__(self, test, params, env):
super(TestMultihostMigration, self).__init__(test, params, env)
self.srchost = self.params.get("hosts")[0]
self.dsthost = self.params.get("hosts")[1]
self.vms = params.get("vms").split()
self.migrate_count = int(params.get("migrate_count", "1"))
self.migration_timeout = int(params.get("migrate_timeout", "240"))
self.time_command = params.get("time_command")
self.time_filter_re = params.get("time_filter_re")
self.time_format = params.get("time_format")
self.create_file = params.get("create_file")
self.diff_limit = float(params.get("time_diff_limit", "0.1"))
self.start_ht = {}
self.start_gt = {}
self.diff_ht = {}
self.diff_gt = {}
self.id = {'src': self.srchost,
'dst': self.dsthost,
"type": "timedrift"}
self.sync = SyncData(self.master_id(), self.hostid, self.hosts,
self.id, self.sync_server)
def check_diff(self, mig_data):
logging.debug("Sleep 10s")
time.sleep(10)
time_drifted = False
for vm in mig_data.vms:
session = vm.wait_for_login()
(ht, gt) = utils_test.get_time(session, self.time_command,
self.time_filter_re,
self.time_format)
session.cmd(self.create_file)
if not vm.name in self.start_ht.keys():
(self.start_ht[vm.name], self.start_gt[vm.name]) = (ht, gt)
if abs(ht - gt) > self.diff_limit:
logging.warning("Host and %s time diff %s is greater "
"than time_diff_limit:%s" %
(vm.name, abs(ht - gt),
self.diff_limit))
logging.warning("Host time:%s Guest %s time:%s" %
(ht, vm.name, gt))
else:
self.diff_ht[vm.name] = ht - self.start_ht[vm.name]
self.diff_gt[vm.name] = gt - self.start_gt[vm.name]
gh_diff = self.diff_ht[vm.name] - self.diff_gt[vm.name]
if gh_diff > self.diff_limit:
time_drifted = True
if time_drifted:
difs = ""
for vm in mig_data.vms:
difs += ("\n VM=%s HOST=%ss GUEST=%ss"
" DIFF=%s" %
(vm.name, self.diff_ht[vm.name],
self.diff_gt[vm.name],
(self.diff_ht[vm.name] -
self.diff_gt[vm.name])))
raise error.TestError("Time DIFFERENCE for VM is greater than"
" LIMIT:%ss.%s\n" % (self.diff_limit,
difs))
def before_migration(self, mig_data):
"""
Sync time values
"""
data = self.sync.sync((self.start_ht, self.start_gt), timeout=120)
(self.start_ht, self.start_gt) = data[self.srchost]
def ping_pong_migrate(self):
for _ in range(self.migrate_count):
logging.info("File transfer not ended, starting"
" a round of migration...")
self.sync.sync(True, timeout=self.migration_timeout)
self.migrate_wait(self.vms, self.srchost, self.dsthost,
start_work=self.check_diff,
check_work=self.check_diff)
tmp = self.dsthost
self.dsthost = self.srchost
self.srchost = tmp
def migration_scenario(self, worker=None):
error.context("Migration from %s to %s over protocol %s." %
(self.srchost, self.dsthost, mig_protocol),
logging.info)
self.ping_pong_migrate()
示例11: migration_scenario
def migration_scenario(self):
error.context("Migration from %s to %s over protocol %s." %
(self.srchost, self.dsthost, mig_protocol),
logging.info)
sync = SyncData(self.master_id(), self.hostid, self.hosts,
self.id, self.sync_server)
address_cache = env.get("address_cache")
def worker_cpu_mem(mig_data):
vm = mig_data.vms[0]
session = vm.wait_for_login(timeout=self.login_timeout)
utils_misc.install_cpuflags_util_on_vm(test, vm,
self.install_path,
extra_flags="-msse3 -msse2")
cmd = ("nohup %s/cpuflags-test --stressmem %d 32"
" > %s &" %
(os.path.join(self.install_path, "test_cpu_flags"),
self.stress_memory,
self.cpuflags_test_out))
logging.debug("Sending command: %s" % (cmd))
session.sendline(cmd)
if session.cmd_status("killall -s 0 cpuflags-test") != 0:
cpu_flags_out = ("\n cpuflags_test_output: \n" +
session.cmd_output("cat %s" %
(self.cpuflags_test_out)))
raise error.TestFail("Something wrong happend"
" during migration cpuflags-test"
" should be running all time"
" during this test.\n%s" %
(cpu_flags_out))
def worker_disk(mig_data):
vm = mig_data.vms[0]
session = vm.wait_for_login(timeout=self.login_timeout)
utils_misc.install_disktest_on_vm(test, vm, self.disk_srcdir,
self.install_path)
cmd = ("nohup %s/disktest -m %s -L -S > %s &" %
(os.path.join(self.install_path, "disktest", "src"),
self.disk_usage,
self.disktest_out))
logging.debug("Sending command: %s" % (cmd))
session.sendline(cmd)
if session.cmd_status("killall -s 0 disktest") != 0:
disk_out = ("\n cpuflags_test_output: \n" +
session.cmd_output("cat %s" %
(self.disktest_out)))
raise error.TestFail("Something wrong happend"
" during migration disktest"
" should be running all time"
" during this test.\n%s" %
(disk_out))
def worker_all(mig_data):
worker_cpu_mem(mig_data)
worker_disk(mig_data)
self.worker = None
if self.stress_type == "cpu_memory":
self.worker = worker_cpu_mem
elif self.stress_type == "disk":
if (self.hostid == self.master_id()):
self.install_disktest()
self.worker = worker_disk
elif self.stress_type == "all":
if (self.hostid == self.master_id()):
self.install_disktest()
self.worker = worker_all
if (self.hostid == self.master_id()):
self.vm_addr = self._prepare_vm(self.vm).get_address()
self._hosts_barrier(self.hosts, self.id, "befor_mig", 120)
sync.sync(address_cache, timeout=120)
else:
self._hosts_barrier(self.hosts, self.id, "befor_mig", 260)
address_cache.update(sync.sync(timeout=120)[self.master_id()])
self.migrate_wait([self.vm], self.srchost, self.dsthost,
start_work=self.worker)
sync.sync(True, timeout=self.migration_timeout)
tmp = self.dsthost
self.dsthost = self.srchost
self.srchost = tmp
self.ping_pong_migrate(sync, self.worker)
示例12: test
def test(self):
from autotest.client.shared.syncdata import SyncData
super(test_multihost_eject, self).test()
self.mount_dir = params.get("mount_dir", None)
format_floppy_cmd = params["format_floppy_cmd"]
floppy = params["floppy_name"]
second_floppy = params["second_floppy_name"]
if not os.path.isabs(floppy):
floppy = os.path.join(data_dir.get_data_dir(), floppy)
if not os.path.isabs(second_floppy):
second_floppy = os.path.join(data_dir.get_data_dir(),
second_floppy)
if not self.is_src:
self.floppy = create_floppy(params)
pid = None
sync_id = {'src': self.srchost,
'dst': self.dsthost,
"type": "file_trasfer"}
filename = "orig"
src_file = os.path.join(self.mount_dir, filename)
if self.is_src: # Starts in source
vm = env.get_vm(self.vms[0])
session = vm.wait_for_login(timeout=login_timeout)
if self.mount_dir: # If linux
session.cmd("rm -f %s" % (src_file))
# If mount_dir specified, treat guest as a Linux OS
# Some Linux distribution does not load floppy at boot
# and Windows needs time to load and init floppy driver
error_context.context("Prepare floppy for writing.",
logging.info)
if self.mount_dir: # If linux
lsmod = session.cmd("lsmod")
if 'floppy' not in lsmod:
session.cmd("modprobe floppy")
else:
time.sleep(20)
if floppy not in vm.monitor.info("block"):
test.fail("Wrong floppy image is placed in vm.")
try:
session.cmd(format_floppy_cmd)
except aexpect.ShellCmdError as e:
if e.status == 1:
logging.error("First access to floppy failed, "
" Trying a second time as a workaround")
session.cmd(format_floppy_cmd)
error_context.context("Check floppy")
if self.mount_dir: # If linux
session.cmd("mount %s %s" % (guest_floppy_path,
self.mount_dir), timeout=30)
session.cmd("umount %s" % (self.mount_dir), timeout=30)
written = None
if self.mount_dir:
filepath = os.path.join(self.mount_dir, "test.txt")
session.cmd("echo 'test' > %s" % (filepath))
output = session.cmd("cat %s" % (filepath))
written = "test\n"
else: # Windows version.
filepath = "A:\\test.txt"
session.cmd("echo test > %s" % (filepath))
output = session.cmd("type %s" % (filepath))
written = "test \n\n"
if output != written:
test.fail("Data read from the floppy differs"
"from the data written to it."
" EXPECTED: %s GOT: %s" %
(repr(written), repr(output)))
error_context.context("Change floppy.")
vm.monitor.cmd("eject floppy0")
vm.monitor.cmd("change floppy %s" % (second_floppy))
session.cmd(format_floppy_cmd)
error_context.context("Mount and copy data")
if self.mount_dir: # If linux
session.cmd("mount %s %s" % (guest_floppy_path,
self.mount_dir), timeout=30)
if second_floppy not in vm.monitor.info("block"):
test.fail("Wrong floppy image is placed in vm.")
sync = SyncData(self.mig.master_id(), self.mig.hostid,
self.mig.hosts, sync_id, self.mig.sync_server)
pid = sync.sync(pid, timeout=floppy_prepare_timeout)[self.srchost]
self.mig.migrate_wait([self.vms[0]], self.srchost, self.dsthost)
if not self.is_src: # Starts in destination
vm = env.get_vm(self.vms[0])
session = vm.wait_for_login(timeout=login_timeout)
written = None
#.........这里部分代码省略.........