kvm-test: allow deadnet simulation with --nets -1

This commit is contained in:
Dan Bungert 2022-01-24 17:03:00 -07:00
parent 229e364956
commit a6901ddc25
1 changed files with 9 additions and 5 deletions

View File

@ -148,7 +148,8 @@ parser.add_argument('-f', '--autoinstall-file', action='store',
help='load autoinstall from file')
parser.add_argument('-i', '--img', action='store', help='use this img')
parser.add_argument('-n', '--nets', action='store', default=1, type=int,
help='number of network interfaces')
help='''number of network interfaces.
0=no network, -1=deadnet''')
parser.add_argument('-o', '--overwrite', default=False, action='store_true',
help='allow overwrite of the target image')
parser.add_argument('-q', '--quick', default=False, action='store_true',
@ -339,18 +340,21 @@ class PortFinder:
def nets(ctx):
ports = PortFinder()
if ctx.args.nets > 0:
ports = PortFinder()
ret = []
for _ in range(ctx.args.nets):
port = ports.get()
ret.extend(('-nic',
'user,model=virtio-net-pci,' +
f'hostfwd=tcp::{port}-:22'))
else:
ret = ['-nic', 'none']
return ret
elif ctx.args.nets == 0:
# no network
return ('-nic', 'none')
else:
# nic present but restricted - simulate deadnet environment
return ('-nic', 'user,model=virtio-net-pci,restrict=on')
def bios(ctx):