[virt-tools-list] [virt-manager PATCH] cloudinit: Add cli option root-password-file=/path/to/file.txt

Athina Plaskasoviti athina.plaskasoviti at gmail.com
Mon Jul 15 13:33:43 UTC 2019


Signed-off-by: Athina Plaskasoviti <athina.plaskasoviti at gmail.com>
---
 tests/cli-test-xml/root-password.txt | 1 +
 tests/clitest.py                     | 4 +++-
 virtinst/cli.py                      | 1 +
 virtinst/install/cloudinit.py        | 7 +++++++
 4 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 tests/cli-test-xml/root-password.txt

diff --git a/tests/cli-test-xml/root-password.txt b/tests/cli-test-xml/root-password.txt
new file mode 100644
index 00000000..cdf799c6
--- /dev/null
+++ b/tests/cli-test-xml/root-password.txt
@@ -0,0 +1 @@
+a1b2c3d4
diff --git a/tests/clitest.py b/tests/clitest.py
index 1f7730fb..04fe17e8 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -91,6 +91,7 @@ test_files = {
     'COLLIDE': "/dev/default-pool/collidevol1.img",
     'ADMIN-PASSWORD-FILE': "%s/admin-password.txt" % XMLDIR,
     'USER-PASSWORD-FILE': "%s/user-password.txt" % XMLDIR,
+    'ROOT-PASSWORD-FILE': "%s/root-password.txt" % XMLDIR,
 }
 
 
@@ -872,7 +873,8 @@ c.add_compare("--connect %s --os-variant fedora26" % (utils.URIs.test_suite), "o
 c.add_compare("--connect %s --os-variant fedora26 --pxe --print-xml" % (utils.URIs.test_suite), "osvariant-defaults-pxe", use_default_args=False)  # No arguments
 c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init", "cloud-init-default")  # default --cloud-init behavior is root-password=generate,disable=yes
 c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password=generate,disable=no", "cloud-init-options")  # --cloud-init options
-c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password=a1b2c3d4,disable=no", "cloud-init-options")  #--cloud-init-options
+c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password=a1b2c3d4,disable=no", "cloud-init-options")  # --cloud-init-options
+c.add_compare("--disk %(EXISTIMG1)s --os-variant fedora28 --cloud-init root-password-file=%(ROOT-PASSWORD-FILE)s,disable=no", "cloud-init-options")  # --cloud-init-options
 c.add_valid("--panic help --disk=? --check=help", grep="path_in_use")  # Make sure introspection doesn't blow up
 c.add_valid("--connect test:///default --test-stub-command", use_default_args=False)  # --test-stub-command
 c.add_valid("--nodisks --pxe", grep="VM performance may suffer")  # os variant warning
diff --git a/virtinst/cli.py b/virtinst/cli.py
index 2ca286be..f9479eb5 100644
--- a/virtinst/cli.py
+++ b/virtinst/cli.py
@@ -1614,6 +1614,7 @@ class ParserCloudInit(VirtCLIParser):
     def _init_class(cls, **kwargs):
         VirtCLIParser._init_class(**kwargs)
         cls.add_arg("root-password", "root_password")
+        cls.add_arg("root-password-file", "root_password_file")
         cls.add_arg("disable", "disable", is_onoff=True)
 
 
diff --git a/virtinst/install/cloudinit.py b/virtinst/install/cloudinit.py
index 158b8d4e..80e0bafb 100644
--- a/virtinst/install/cloudinit.py
+++ b/virtinst/install/cloudinit.py
@@ -8,6 +8,7 @@ class CloudInitData():
     disable = None
     root_password = None
     generated_root_password = None
+    root_password_file = None
 
     def generate_password(self):
         self.generated_root_password = ""
@@ -15,9 +16,15 @@ class CloudInitData():
             self.generated_root_password += random.choice(string.ascii_letters + string.digits)
         return self.generated_root_password
 
+    def _get_password(self, pwdfile):
+        with open(pwdfile, "r") as fobj:
+            return fobj.readline().rstrip("\n\r")
+
     def get_root_password(self):
         if self.root_password == "generate":
             return self.generate_password()
+        elif self.root_password_file:
+            return self._get_password(self.root_password_file)
         else:
             return self.root_password
 
-- 
2.20.1




More information about the virt-tools-list mailing list