kvm-test: allow to specify a cloud-init file not meant for autoinstall
The --cloud-config option now replaces the old --autoinstall-file option. The use of --autoinstall-file always made kvm-test pass the autoinstall argument to the kernel command line. With the --cloud-config option, we now determine if the autoinstall argument is needed by reading the cloud config and checking if an autoinstall section is present. The two new options --force-autoinstall and --force-no-autoinstall can be used to override this behaviour. The --autoinstall option is also dropped. If we want to use the default, hardcoded cloud-config, one can use --cloud-config-default. This can be useful to ease debugging of the VM using a config that looks like: #cloud-config users: - default - name: root ssh_import_id: lp:ogayot Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
parent
60d6746a41
commit
62a2f3104c
|
@ -133,8 +133,6 @@ packages from a cache.
|
||||||
|
|
||||||
See 'cfg' in script for expected layout of iso files,
|
See 'cfg' in script for expected layout of iso files,
|
||||||
which can be managed with ~/.kvm-test.yaml''')
|
which can be managed with ~/.kvm-test.yaml''')
|
||||||
parser.add_argument('-a', '--autoinstall', default=False,
|
|
||||||
action='store_true', help='use autoinstall')
|
|
||||||
parser.add_argument('-b', '--base', default=False, action='store_true',
|
parser.add_argument('-b', '--base', default=False, action='store_true',
|
||||||
help='use base iso')
|
help='use base iso')
|
||||||
parser.add_argument('--basesnap', default=None, action='store',
|
parser.add_argument('--basesnap', default=None, action='store',
|
||||||
|
@ -147,9 +145,6 @@ parser.add_argument('-c', '--channel', action='store',
|
||||||
help='build iso with snap from channel')
|
help='build iso with snap from channel')
|
||||||
parser.add_argument('-d', '--disksize', default='12G', action='store',
|
parser.add_argument('-d', '--disksize', default='12G', action='store',
|
||||||
help='size of disk to create (12G default)')
|
help='size of disk to create (12G default)')
|
||||||
parser.add_argument('-f', '--autoinstall-file', action='store',
|
|
||||||
type=argparse.FileType(),
|
|
||||||
help='load autoinstall from file')
|
|
||||||
parser.add_argument('-i', '--img', action='store', help='use this img')
|
parser.add_argument('-i', '--img', action='store', help='use this img')
|
||||||
parser.add_argument('-n', '--nets', action='store', default=1, type=int,
|
parser.add_argument('-n', '--nets', action='store', default=1, type=int,
|
||||||
help='''number of network interfaces.
|
help='''number of network interfaces.
|
||||||
|
@ -191,8 +186,23 @@ parser.add_argument('--install', default=False, action='store_true',
|
||||||
iso, use a base iso, or reuse previous test iso''')
|
iso, use a base iso, or reuse previous test iso''')
|
||||||
parser.add_argument('--boot', default=False, action='store_true',
|
parser.add_argument('--boot', default=False, action='store_true',
|
||||||
help='boot test image')
|
help='boot test image')
|
||||||
|
parser.add_argument('--force-autoinstall', default=None,
|
||||||
|
action='store_true', dest="autoinstall",
|
||||||
|
help='pass autoinstall on the kernel command line')
|
||||||
|
parser.add_argument('--force-no-autoinstall', default=None,
|
||||||
|
action='store_false', dest="autoinstall",
|
||||||
|
help='do not pass autoinstall on the kernel command line')
|
||||||
|
|
||||||
|
|
||||||
|
cc_group = parser.add_mutually_exclusive_group()
|
||||||
|
cc_group.add_argument('--cloud-config', action='store',
|
||||||
|
type=argparse.FileType(),
|
||||||
|
help='specify the cloud-config file to use (it may'
|
||||||
|
' contain an autoinstall section or not)')
|
||||||
|
cc_group.add_argument('--cloud-config-default',
|
||||||
|
action="store_true",
|
||||||
|
help='use hardcoded cloud-config template')
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
ctx = Context(parser.parse_args())
|
ctx = Context(parser.parse_args())
|
||||||
if ctx.args.quick or ctx.args.basesnap or ctx.args.snap \
|
if ctx.args.quick or ctx.args.basesnap or ctx.args.snap \
|
||||||
|
@ -468,11 +478,20 @@ def install(ctx):
|
||||||
kvm.append('-nographic')
|
kvm.append('-nographic')
|
||||||
appends.append('console=ttyS0')
|
appends.append('console=ttyS0')
|
||||||
|
|
||||||
if ctx.args.autoinstall or ctx.args.autoinstall_file:
|
if ctx.args.cloud_config is not None or ctx.args.cloud_config_default:
|
||||||
if ctx.args.autoinstall_file:
|
if ctx.args.cloud_config is not None:
|
||||||
ctx.cloudconfig = ctx.args.autoinstall_file.read()
|
ctx.cloudconfig = ctx.args.cloud_config.read()
|
||||||
kvm.extend(drive(create_seed(ctx.cloudconfig, tempdir), 'raw'))
|
kvm.extend(drive(create_seed(ctx.cloudconfig, tempdir), 'raw'))
|
||||||
appends.append('autoinstall')
|
if ctx.args.autoinstall is None:
|
||||||
|
# Let's inspect the yaml and check if there is an autoinstall
|
||||||
|
# section.
|
||||||
|
autoinstall = "autoinstall" in yaml.safe_load(ctx.cloudconfig)
|
||||||
|
else:
|
||||||
|
autoinstall = ctx.args.autoinstall
|
||||||
|
|
||||||
|
if autoinstall:
|
||||||
|
appends.append('autoinstall')
|
||||||
|
|
||||||
|
|
||||||
if ctx.args.update:
|
if ctx.args.update:
|
||||||
appends.append('subiquity-channel=' + ctx.args.update)
|
appends.append('subiquity-channel=' + ctx.args.update)
|
||||||
|
|
Loading…
Reference in New Issue