test/run: pass cloud-init data to qemu
This passes the redhat user with ssh key as an ISO image to our qemu instances, making sure images relying on cloud-init rather than hardcoded user credentials can be used in our tests. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
59ab975fea
commit
49387604e4
4 changed files with 35 additions and 16 deletions
|
|
@ -21,7 +21,7 @@ matrix:
|
|||
- sudo env "PATH=$PATH" "PYTHONUNBUFFERED=1" "OSBUILD_TEST_BUILD_ENV=test/f27-build-from-ubuntu1804.json" test/run --image-info
|
||||
- language: python
|
||||
python: 3.7
|
||||
before_install: sudo apt-get install -y qemu-kvm
|
||||
before_install: sudo apt-get install -y qemu-kvm genisoimage
|
||||
script:
|
||||
# ubuntu's rpm package sets dbpath to ~/.rpmdb, which makes rpm fail...
|
||||
- sudo sh -c 'mkdir /etc/rpm; echo "%_dbpath /var/lib/rpm" > /etc/rpm/macros'
|
||||
|
|
|
|||
2
test/cloud-init/meta-data
Normal file
2
test/cloud-init/meta-data
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
instance-id: nocloud
|
||||
local-hostname: vm
|
||||
4
test/cloud-init/user-data
Normal file
4
test/cloud-init/user-data
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#cloud-config
|
||||
user: redhat
|
||||
ssh_authorized_keys:
|
||||
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC61wMCjOSHwbVb4VfVyl5sn497qW4PsdQ7Ty7aD6wDNZ/QjjULkDV/yW5WjDlDQ7UqFH0Sr7vywjqDizUAqK7zM5FsUKsUXWHWwg/ehKg8j9xKcMv11AkFoUoujtfAujnKODkk58XSA9whPr7qcw3vPrmog680pnMSzf9LC7J6kXfs6lkoKfBh9VnlxusCrw2yg0qI1fHAZBLPx7mW6+me71QZsS6sVz8v8KXyrXsKTdnF50FjzHcK9HXDBtSJS5wA3fkcRYymJe0o6WMWNdgSRVpoSiWaHHmFgdMUJaYoCfhXzyl7LtNb3Q+Sveg+tJK7JaRXBLMUllOlJ6ll5Hod
|
||||
43
test/run
43
test/run
|
|
@ -87,21 +87,34 @@ def create_ssh_keys():
|
|||
|
||||
@contextlib.contextmanager
|
||||
def qemu_boot_image(image_file):
|
||||
# run in background
|
||||
cmd = ["qemu-system-x86_64",
|
||||
"-m", "2048",
|
||||
"-snapshot",
|
||||
"-accel", "accel=kvm:hvf:tcg",
|
||||
"-net", "nic,model=rtl8139", "-net", "user,hostfwd=tcp::22-:22",
|
||||
"-nographic",
|
||||
image_file
|
||||
]
|
||||
print(f"running qemu command: {' '.join(cmd)}")
|
||||
vm = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
try:
|
||||
yield None
|
||||
finally:
|
||||
vm.kill()
|
||||
with tempfile.TemporaryDirectory() as dir:
|
||||
# Create an ISO that cloud-init can consume with userdata.
|
||||
subprocess.run(["genisoimage",
|
||||
"-quiet",
|
||||
"-input-charset", "utf-8",
|
||||
"-output", f"{dir}/cloudinit.iso",
|
||||
"-volid", "cidata",
|
||||
"-joliet",
|
||||
"-rock",
|
||||
f"{TEST_DIR}/cloud-init/user-data",
|
||||
f"{TEST_DIR}/cloud-init/meta-data"],
|
||||
check=True)
|
||||
# run in background
|
||||
cmd = ["qemu-system-x86_64",
|
||||
"-m", "2048",
|
||||
"-snapshot",
|
||||
"-accel", "accel=kvm:hvf:tcg",
|
||||
"-cdrom", f"{dir}/cloudinit.iso",
|
||||
"-net", "nic,model=rtl8139", "-net", "user,hostfwd=tcp::22-:22",
|
||||
"-nographic",
|
||||
image_file
|
||||
]
|
||||
print(f"running qemu command: {' '.join(cmd)}")
|
||||
vm = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
try:
|
||||
yield None
|
||||
finally:
|
||||
vm.kill()
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue