From cdcec1fb03155c41958987faaa0073b756b10c6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 17 Oct 2019 18:01:25 +0200 Subject: [PATCH] unattended: Add option to set the user-login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's allow setting the login of the guest user. Using the user from the system is a quite good fallback, but would break unattended installations when running virt-install as root. Thus, for those cases, it makes sense to have the option of setting the user login. Signed-off-by: Fabiano FidĂȘncio --- man/virt-install.pod | 8 +++++++- tests/clitest.py | 2 +- virtinst/cli.py | 1 + virtinst/install/unattended.py | 12 +++++++++--- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/man/virt-install.pod b/man/virt-install.pod index ff05a672..c611faf0 100644 --- a/man/virt-install.pod +++ b/man/virt-install.pod @@ -628,12 +628,18 @@ password-file. Note that only the first line of the file will be considered, including any whitespace characters and excluding new-line. +=item B + +The user login name to be used in th VM. virt-install will default to your +current host username if this is unspecified. + =item B A file used to set the VM user password. This option can be used either as "user-password-file=/path/to/password-file" or as "user-password-file=/dev/fd/n", being n the file descriptor of the -password-file. The username is your current host username. +password-file. The username is either the user-login specified or your current +host username. Note that only the first line of the file will be considered, including any whitespace characters and excluding new-line. diff --git a/tests/clitest.py b/tests/clitest.py index 2a382022..3282d679 100644 --- a/tests/clitest.py +++ b/tests/clitest.py @@ -887,7 +887,7 @@ c.add_valid("--connect %s --pxe --disk size=1" % utils.URIs.test_defaultpool_col #################### c = vinst.add_category("unattended-install", "--connect %(URI-KVM)s --nographics --noautoconsole --disk none", prerun_check=no_osinfo_unattend_cb) -c.add_compare("--install fedora26 --unattended profile=desktop,admin-password-file=%(ADMIN-PASSWORD-FILE)s,user-password-file=%(USER-PASSWORD-FILE)s,product-key=1234", "osinfo-url-unattended", prerun_check=lambda: not unattended.OSInstallScript.have_libosinfo_installation_url()) # unattended install for fedora, using initrd injection +c.add_compare("--install fedora26 --unattended profile=desktop,admin-password-file=%(ADMIN-PASSWORD-FILE)s,user-password-file=%(USER-PASSWORD-FILE)s,product-key=1234,user-login=foobar", "osinfo-url-unattended", prerun_check=lambda: not unattended.OSInstallScript.have_libosinfo_installation_url()) # unattended install for fedora, using initrd injection c.add_compare("--cdrom %(ISO-WIN7)s --unattended profile=desktop,admin-password-file=%(ADMIN-PASSWORD-FILE)s", "osinfo-win7-unattended", prerun_check=no_osinfo_unattended_win_drivers_cb) # unattended install for win7 c.add_compare("--os-variant fedora26 --unattended profile=jeos,admin-password-file=%(ADMIN-PASSWORD-FILE)s --location %(ISO-F26-NETINST)s", "osinfo-netinst-unattended") # triggering the special netinst checking code c.add_compare("--os-variant silverblue29 --location http://example.com", "network-install-resources") # triggering network-install resources override diff --git a/virtinst/cli.py b/virtinst/cli.py index d704e6f2..7eeb9395 100644 --- a/virtinst/cli.py +++ b/virtinst/cli.py @@ -1514,6 +1514,7 @@ class ParserUnattended(VirtCLIParser): VirtCLIParser._init_class(**kwargs) cls.add_arg("profile", "profile") cls.add_arg("admin-password-file", "admin_password_file") + cls.add_arg("user-login", "user_login") cls.add_arg("user-password-file", "user_password_file") cls.add_arg("product-key", "product_key") diff --git a/virtinst/install/unattended.py b/virtinst/install/unattended.py index c637ab57..05793ba6 100644 --- a/virtinst/install/unattended.py +++ b/virtinst/install/unattended.py @@ -36,9 +36,14 @@ def _make_installconfig(script, osobj, unattended_data, arch, hostname, url): config = Libosinfo.InstallConfig() - # Set user login and name based on the one from the system - config.set_user_login(getpass.getuser()) - config.set_user_realname(pwd.getpwnam(getpass.getuser()).pw_gecos) + # Set user login and name + # In case it's specified via command-line, use the specified one as login + # and realname. Otherwise, fallback fto the one from the system + login = unattended_data.user_login or getpass.getuser() + login = login.lower() + realname = unattended_data.user_login or pwd.getpwnam(login).pw_gecos + config.set_user_login(login) + config.set_user_realname(realname) # Set user-password. # In case it's required and not passed, just raise a RuntimeError. @@ -252,6 +257,7 @@ class OSInstallScript: class UnattendedData(): profile = None admin_password_file = None + user_login = None user_password_file = None product_key = None