Fix -drive option from kvm-test.sh

The function drive() used to return a string in the following format:

  "-drive file=/path/to/iso,..."

However, qemu/kvm expects "-drive" to be an argument and
"file=/path/to/iso,..." to be another argument.

The command was constructed as below since the beginning:

  kvm = [
     "kvm",
     "-cdrom", "custom.iso",          # <- OK
     "-drive file=/path/to/iso,...",  # <- NOK
  ]

Before 06ac3f92, we would join all the arguments using spaces before
executing the kvm command. Therefore we would luckily end up with a
correct command:

  " ".join(kvm)  ->  "kvm -cdrom custom.iso -drive file=/path/to/iso,..."

However, now that we supply the command to subprocess.run directly, the
problem shows up.

Fixed by returning a tuple("-drive", "file=/path/to/iso,...") from
the drive() function.

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-01-13 10:25:06 +01:00 committed by Dan Bungert
parent 79b0c41b65
commit ed0e6861aa
1 changed files with 4 additions and 2 deletions

View File

@ -20,6 +20,7 @@ import socket
import subprocess import subprocess
import sys import sys
import tempfile import tempfile
from typing import Tuple
import yaml import yaml
@ -307,7 +308,8 @@ def create_seed(cloudconfig, tempdir):
return seed return seed
def drive(path, format='qcow2'): def drive(path, format='qcow2') -> Tuple[str, str]:
""" Return a tuple (-drive, <options>) that can be passed to kvm """
kwargs = [] kwargs = []
serial = None serial = None
cparam = 'writethrough' cparam = 'writethrough'
@ -318,7 +320,7 @@ def drive(path, format='qcow2'):
if serial: if serial:
kwargs.append(f'serial={serial}') kwargs.append(f'serial={serial}')
return ['-drive', ','.join(kwargs)] return ('-drive', ','.join(kwargs))
class PortFinder: class PortFinder: