[PATCH 3/3] KVM test: Add implementation of network based unattended installation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch could let the unattended installation to be done through
the following method:

- cdrom: the original method which does the installation from cdrom
- url: installing the linux guest from http or ftp, tree url was specified
through url
- nfs: installing the linux guest from nfs. the server address was
specified through nfs_server, and the director was specified through
nfs_dir

For url and nfs installation, the extra_params need to be configurated
to specify the location of unattended files:

- If the unattended file in the tree is used, "extra_parmas= append
  ks=floppy" and unattended_file params need to be specified in the
  configuration file.
- If the unattended file located at remote server is used,
  unattended_file option must be none and "extram_params= append
  ks=http://xxx"; need to be speficied in the configuration file and
  don't forget the add the finish nofitication part.

The --kernel and --initrd were used directly for the network
installation instead of the tftp/bootp param because the user mode
network is too slow to do this.

Only the unattended files for RHEL and Fedora gues ts are modified,
others are kept unmodified and could do the installation from cdrom.

Signed-off-by: Jason Wang <jasowang@xxxxxxxxxx>
---
 client/tests/kvm/scripts/unattended.py       |  103 +++++++++++++++++++++++++-
 client/tests/kvm/tests_base.cfg.sample       |    1 
 client/tests/kvm/unattended/Fedora-10.ks     |    2 -
 client/tests/kvm/unattended/Fedora-11.ks     |    2 -
 client/tests/kvm/unattended/Fedora-12.ks     |    2 -
 client/tests/kvm/unattended/Fedora-8.ks      |    2 -
 client/tests/kvm/unattended/Fedora-9.ks      |    2 -
 client/tests/kvm/unattended/RHEL-3-series.ks |    2 -
 client/tests/kvm/unattended/RHEL-4-series.ks |    2 -
 client/tests/kvm/unattended/RHEL-5-series.ks |    2 -
 10 files changed, 107 insertions(+), 13 deletions(-)

diff --git a/client/tests/kvm/scripts/unattended.py b/client/tests/kvm/scripts/unattended.py
index fdadd03..b738e3f 100755
--- a/client/tests/kvm/scripts/unattended.py
+++ b/client/tests/kvm/scripts/unattended.py
@@ -50,6 +50,7 @@ class UnattendedInstall(object):
         self.cdrom_iso = os.path.join(kvm_test_dir, cdrom_iso)
         self.floppy_mount = tempfile.mkdtemp(prefix='floppy_', dir='/tmp')
         self.cdrom_mount = tempfile.mkdtemp(prefix='cdrom_', dir='/tmp')
+        self.nfs_mount = tempfile.mkdtemp(prefix='nfs_', dir='/tmp')
         flopy_name = os.environ['KVM_TEST_floppy']
         self.floppy_img = os.path.join(kvm_test_dir, flopy_name)
         floppy_dir = os.path.dirname(self.floppy_img)
@@ -60,6 +61,16 @@ class UnattendedInstall(object):
         self.pxe_image = os.environ.get('KVM_TEST_pxe_image', '')
         self.pxe_initrd = os.environ.get('KVM_TEST_pxe_initrd', '')
 
+        self.medium = os.environ.get('KVM_TEST_medium', '')
+        self.url = os.environ.get('KVM_TEST_url', '')
+        self.kernel = os.environ.get('KVM_TEST_kernel', '')
+        self.initrd = os.environ.get('KVM_TEST_initrd', '')
+        self.nfs_server = os.environ.get('KVM_TEST_nfs_server', '')
+        self.nfs_dir = os.environ.get('KVM_TEST_nfs_dir', '')
+        self.image_path = kvm_test_dir
+        self.kernel_path = os.path.join(self.image_path, self.kernel)
+        self.initrd_path = os.path.join(self.image_path, self.initrd)
+
 
     def create_boot_floppy(self):
         """
@@ -106,7 +117,8 @@ class UnattendedInstall(object):
             dest = os.path.join(self.floppy_mount, dest_fname)
 
             # Replace KVM_TEST_CDKEY (in the unattended file) with the cdkey
-            # provided for this test
+            # provided for this test and replace the KVM_TEST_MEDIUM with
+            # the tree url or nfs address provided for this test.
             unattended_contents = open(self.unattended_file).read()
             dummy_cdkey_re = r'\bKVM_TEST_CDKEY\b'
             real_cdkey = os.environ.get('KVM_TEST_cdkey')
@@ -117,7 +129,20 @@ class UnattendedInstall(object):
                 else:
                     print ("WARNING: 'cdkey' required but not specified for "
                            "this unattended installation")
+            
+            dummy_re = r'\bKVM_TEST_MEDIUM\b'
+            if self.medium == "cdrom":
+                content = "cdrom"
+            elif self.medium == "url":
+                content = "url --url %s" % self.url
+            elif self.medium == "nfs":
+                content = "nfs --server=%s --dir=%s" % (self.nfs_server, self.nfs_dir)
+            else:
+                raise SetupError("Unexpected installation medium %s" % self.url)
+                
+            unattended_contents = re.sub(dummy_re, content, unattended_contents)
 
+            print unattended_contents
             # Write the unattended file contents to 'dest'
             open(dest, 'w').write(unattended_contents)
 
@@ -216,6 +241,58 @@ class UnattendedInstall(object):
         print "PXE boot successfuly set"
 
 
+    def setup_url(self):
+        """
+        Download the vmlinuz and initrd.img from URL
+        """
+        print "Downloading the vmlinuz and initrd.img"
+        os.chdir(self.image_path)
+
+        kernel_fetch_cmd = "wget %s/isolinux/%s" % (self.url, self.kernel)
+        initrd_fetch_cmd = "wget %s/isolinux/%s" % (self.url, self.initrd)
+
+        if os.path.exists(self.kernel):
+            os.unlink(self.kernel)
+        if os.path.exists(self.initrd):
+            os.unlink(self.initrd)
+
+        if os.system(kernel_fetch_cmd) != 0:
+            raise SetupError("Could not fetch vmlinuz from %s" % self.url)
+        if os.system(initrd_fetch_cmd) != 0:
+            raise SetupError("Could not fetch initrd.img from %s" % self.url)
+
+        print "Downloading finish"
+
+    def setup_nfs(self):
+        """
+        Copy the vmlinuz and initrd.img from nfs.
+        """
+        print "Copying the vmlinuz and initrd.img from nfs"
+
+        m_cmd = "mount %s:%s %s -o ro" % (self.nfs_server, self.nfs_dir, self.nfs_mount)
+        if os.system(m_cmd):
+            raise SetupError('Could not mount nfs server.')
+
+        kernel_fetch_cmd = "cp %s/isolinux/%s %s" % (self.nfs_mount,
+                                                     self.kernel,
+                                                     self.image_path)
+        initrd_fetch_cmd = "cp %s/isolinux/%s %s" % (self.nfs_mount,
+                                                     self.initrd,
+                                                     self.image_path)
+
+        try:
+            if os.system(kernel_fetch_cmd):
+                raise SetupError("Could not copy the vmlinuz from %s" %
+                                 self.nfs_mount)
+            if os.system(initrd_fetch_cmd):
+                raise SetupError("Could not copy the initrd.img from %s" %
+                                 self.nfs_mount)
+        finally:
+            u_cmd = "umount %s" % self.nfs_mount
+            if os.system(u_cmd):
+                raise SetupError("Could not unmont nfs at %s" % self.nfs_mount)
+            self.cleanup(self.nfs_mount)
+
     def cleanup(self, mount):
         """
         Clean up a previously used mountpoint.
@@ -234,6 +311,7 @@ class UnattendedInstall(object):
         print "Starting unattended install setup"
 
         print "Variables set:"
+        print "    medium: " + str(self.medium)
         print "    qemu_img_bin: " + str(self.qemu_img_bin)
         print "    cdrom iso: " + str(self.cdrom_iso)
         print "    unattended_file: " + str(self.unattended_file)
@@ -245,10 +323,25 @@ class UnattendedInstall(object):
         print "    pxe_dir: " + str(self.pxe_dir)
         print "    pxe_image: " + str(self.pxe_image)
         print "    pxe_initrd: " + str(self.pxe_initrd)
-
-        self.create_boot_floppy()
-        if self.tftp_root:
-            self.setup_pxe_boot()
+        print "    url: " + str(self.url)
+        print "    kernel: " + str(self.kernel)
+        print "    initrd: " + str(self.initrd)
+        print "    nfs_server: " + str(self.nfs_server)
+        print "    nfs_dir: " + str(self.nfs_dir)
+        print "    nfs_mount: " + str(self.nfs_mount)
+
+        if self.unattended_file:
+            self.create_boot_floppy()
+        if self.medium == "cdrom":
+            if self.tftp_root:
+                self.setup_pxe_boot()
+        elif self.medium == "url":
+            self.setup_url()
+        elif self.medium == "nfs":
+            self.setup_nfs()
+        else:
+            raise SetupError("Unexpected installation method %s" %
+                                   self.medium)
         print "Unattended install setup finished successfuly"
 
 
diff --git a/client/tests/kvm/tests_base.cfg.sample b/client/tests/kvm/tests_base.cfg.sample
index 646738b..789ae23 100644
--- a/client/tests/kvm/tests_base.cfg.sample
+++ b/client/tests/kvm/tests_base.cfg.sample
@@ -83,6 +83,7 @@ variants:
         nic_mode = user
         redirs += " unattended_install"
         guest_port_unattended_install = 12323
+	medium = cdrom
 
     - boot:         install setup unattended_install
         type = boot
diff --git a/client/tests/kvm/unattended/Fedora-10.ks b/client/tests/kvm/unattended/Fedora-10.ks
index 61e59d7..43c236a 100644
--- a/client/tests/kvm/unattended/Fedora-10.ks
+++ b/client/tests/kvm/unattended/Fedora-10.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US.UTF-8
diff --git a/client/tests/kvm/unattended/Fedora-11.ks b/client/tests/kvm/unattended/Fedora-11.ks
index 0be7d06..bef3af7 100644
--- a/client/tests/kvm/unattended/Fedora-11.ks
+++ b/client/tests/kvm/unattended/Fedora-11.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US
diff --git a/client/tests/kvm/unattended/Fedora-12.ks b/client/tests/kvm/unattended/Fedora-12.ks
index 0be7d06..bef3af7 100644
--- a/client/tests/kvm/unattended/Fedora-12.ks
+++ b/client/tests/kvm/unattended/Fedora-12.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US
diff --git a/client/tests/kvm/unattended/Fedora-8.ks b/client/tests/kvm/unattended/Fedora-8.ks
index f4a872d..cde85dd 100644
--- a/client/tests/kvm/unattended/Fedora-8.ks
+++ b/client/tests/kvm/unattended/Fedora-8.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US.UTF-8
diff --git a/client/tests/kvm/unattended/Fedora-9.ks b/client/tests/kvm/unattended/Fedora-9.ks
index f4a872d..cde85dd 100644
--- a/client/tests/kvm/unattended/Fedora-9.ks
+++ b/client/tests/kvm/unattended/Fedora-9.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US.UTF-8
diff --git a/client/tests/kvm/unattended/RHEL-3-series.ks b/client/tests/kvm/unattended/RHEL-3-series.ks
index 884b386..5321118 100644
--- a/client/tests/kvm/unattended/RHEL-3-series.ks
+++ b/client/tests/kvm/unattended/RHEL-3-series.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US.UTF-8
diff --git a/client/tests/kvm/unattended/RHEL-4-series.ks b/client/tests/kvm/unattended/RHEL-4-series.ks
index ce4a430..159998b 100644
--- a/client/tests/kvm/unattended/RHEL-4-series.ks
+++ b/client/tests/kvm/unattended/RHEL-4-series.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US.UTF-8
diff --git a/client/tests/kvm/unattended/RHEL-5-series.ks b/client/tests/kvm/unattended/RHEL-5-series.ks
index f4a872d..cde85dd 100644
--- a/client/tests/kvm/unattended/RHEL-5-series.ks
+++ b/client/tests/kvm/unattended/RHEL-5-series.ks
@@ -1,5 +1,5 @@
 install
-cdrom
+KVM_TEST_MEDIUM
 text
 reboot
 lang en_US.UTF-8

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux