diff --git a/README.md b/README.md index 5a5c159..1c1168d 100644 --- a/README.md +++ b/README.md @@ -216,13 +216,11 @@ new instance using **testcloud**. : To set the amount of VCPUS that will be available to the virtual machine. -\--no-graphic +\--graphics {spice,vnc,none} -: This turns off the graphical display of the virtual machine. - -\--vnc - -: To open a VNC connection at the `:1` display of the instance. +: Set the graphics display type. `spice` or `vnc` enables graphical + output viewable via `virt-viewer`/`remote-viewer`, `none` (default) + runs headless. -n, \--name NAME @@ -252,6 +250,17 @@ new instance using **testcloud**. : To provide virtual iommu device +### Connecting to graphical display + +When an instance is created with `--graphics spice` or `--graphics vnc`, +you can connect to its display using `virt-viewer` or `remote-viewer`: + + $ virt-viewer --connect qemu:///system + +For session mode: + + $ virt-viewer --connect qemu:///session + There are several additional options that can be used to create a new Coreos instance using **testcloud**. diff --git a/conf/testcloud b/conf/testcloud index e9ede30..7f635db 100644 --- a/conf/testcloud +++ b/conf/testcloud @@ -9,7 +9,7 @@ __testcloud() base_opts="instance image -h --help" image_opts="list destroy -h --help" instance_opts="list start stop remove create -c -h --help" - instance_create_opts="-h --ram --no-graphic --vnc --timeout --disksize" + instance_create_opts="-h --ram --graphics --timeout --disksize" echo ${COMP_WORDS[@]} >> /tmp/compwords diff --git a/manpages/testcloud.1 b/manpages/testcloud.1 index ac3386b..7048eac 100644 --- a/manpages/testcloud.1 +++ b/manpages/testcloud.1 @@ -106,11 +106,8 @@ recognized. \fB--disksize DISKSIZE\fR Set the disk size of the instance VM (in GiB). -\fB--vnc\fR - Open a VNC connection to the \fB:1\fR display of the instance VM. - -\fB--no-graphic\fR - Turn off the instance VM's graphical display. +\fB--graphics {spice,vnc,none}\fR + Set the graphics display type. \fBspice\fR or \fBvnc\fR enables graphical output viewable via virt-viewer/remote-viewer, \fBnone\fR (default) runs headless. \fB--timeout TIMEOUT\fR Specify the time (in seconds) to wait for the instance boot to complete. To disable waiting time (default behaviour) set to \fB0\fR. diff --git a/test/test_domain_configuration.py b/test/test_domain_configuration.py new file mode 100644 index 0000000..2b33528 --- /dev/null +++ b/test/test_domain_configuration.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +# Copyright 2025, Red Hat, Inc. +# License: GPL-2.0+ +# See the LICENSE file for more details on Licensing + +"""Tests for domain configuration, specifically GraphicsConfiguration.""" + +from unittest.mock import patch + +import peewee as pw + +from testcloud import image +from testcloud.domain_configuration import ( + GraphicsConfiguration, + _get_default_domain_conf, +) +from testcloud.sql import DBImage, DB + +DB = pw.SqliteDatabase(":memory:") + + +class TestGraphicsConfiguration(object): + + def test_generate_spice(self): + gc = GraphicsConfiguration(graphics_type="spice") + xml = gc.generate() + assert "" in xml + assert "" in xml + + def test_generate_vnc(self): + gc = GraphicsConfiguration(graphics_type="vnc") + xml = gc.generate() + assert "" in xml + + def test_generate_with_listen_address(self): + gc = GraphicsConfiguration(graphics_type="spice", listen_address="127.0.0.1") + xml = gc.generate() + assert "listen='127.0.0.1'" in xml + + def test_generate_without_listen_address(self): + gc = GraphicsConfiguration(graphics_type="spice") + xml = gc.generate() + assert "listen=" not in xml + + +class TestDefaultDomainConfGraphics(object): + + def setup_method(self, method): + DB.bind([DBImage], bind_refs=False, bind_backrefs=False) + DB.connect() + DB.create_tables([DBImage]) + self.patcher = patch('testcloud.sql.data_dir_changed', return_value=None) + self.mocked_method = self.patcher.start() + + def teardown_method(self, method): + self.patcher.stop() + DB.drop_tables([DBImage]) + DB.close() + + def _make_image(self): + return image.Image("file:///someimage.qcow2") + + def test_graphics_none(self): + conf = _get_default_domain_conf("test-vm", self._make_image(), graphics="none") + assert conf.graphics_configuration is None + + def test_graphics_spice(self): + conf = _get_default_domain_conf("test-vm", self._make_image(), graphics="spice") + assert conf.graphics_configuration is not None + assert conf.graphics_configuration.graphics_type == "spice" + + def test_graphics_vnc(self): + conf = _get_default_domain_conf("test-vm", self._make_image(), graphics="vnc") + assert conf.graphics_configuration is not None + assert conf.graphics_configuration.graphics_type == "vnc" + + def test_graphics_spice_system_listen_address(self): + conf = _get_default_domain_conf( + "test-vm", self._make_image(), graphics="spice", connection="qemu:///system") + assert conf.graphics_configuration.listen_address == "127.0.0.1" + + def test_graphics_in_generated_xml(self): + conf = _get_default_domain_conf("test-vm", self._make_image(), graphics="vnc") + xml = conf.generate() + assert 'type="vnc"' in xml + assert "