From dd5f4cee0f28eef42f6f08ac79aa806d9452f3e0 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Tue, 25 Apr 2023 22:32:14 +0800 Subject: [PATCH] fix(host): compatible with python3 Signed-off-by: wanyaoqi --- pkg/hostman/guestman/qemu-kvm.go | 2 +- pkg/hostman/guestman/qemu-kvmhelper.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pkg/hostman/guestman/qemu-kvm.go b/pkg/hostman/guestman/qemu-kvm.go index 240a5ffca5..874964bdfb 100644 --- a/pkg/hostman/guestman/qemu-kvm.go +++ b/pkg/hostman/guestman/qemu-kvm.go @@ -1712,7 +1712,7 @@ func (s *SKVMGuestInstance) pyLauncherPath() string { } func (s *SKVMGuestInstance) scriptStart(ctx context.Context) error { - output, err := procutils.NewRemoteCommandAsFarAsPossible("python2", s.pyLauncherPath()).Output() + output, err := procutils.NewRemoteCommandAsFarAsPossible("python", s.pyLauncherPath()).Output() if err != nil { return fmt.Errorf("Start VM Failed %s %s", output, err) } diff --git a/pkg/hostman/guestman/qemu-kvmhelper.go b/pkg/hostman/guestman/qemu-kvmhelper.go index 0b520462b8..65ab87c0d4 100644 --- a/pkg/hostman/guestman/qemu-kvmhelper.go +++ b/pkg/hostman/guestman/qemu-kvmhelper.go @@ -63,8 +63,7 @@ const ( DISK_DRIVER_SATA = qemu.DISK_DRIVER_SATA ) -const guestLauncher = ` -#!/usr/bin/env python +const guestLauncher = `#!/usr/bin/env python import sys import os import time @@ -111,7 +110,7 @@ else: logfd = os.open('%s', os.O_RDWR|os.O_CREAT|os.O_APPEND) os.dup2(logfd, 1) os.dup2(logfd, 2) - os.write(logfd, '%%s Run command: %%s\n' %% (time.strftime('%%Y-%%m-%%d %%H:%%M:%%S', time.localtime()), cmd)) + os.write(logfd, str.encode('%%s Run command: %%s\n' %% (time.strftime('%%Y-%%m-%%d %%H:%%M:%%S', time.localtime()), cmd))) os.close(logfd) if os.execv(cmd[0], cmd) < 0: