From patchwork Wed May 19 09:20:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 100820 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4J9Fn6V032400 for ; Wed, 19 May 2010 09:15:58 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755025Ab0ESJPz (ORCPT ); Wed, 19 May 2010 05:15:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31583 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754051Ab0ESJPy (ORCPT ); Wed, 19 May 2010 05:15:54 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o4J9Frrb008944 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 19 May 2010 05:15:53 -0400 Received: from dhcp-91-25.nay.redhat.com (dhcp-91-25.nay.redhat.com [10.66.91.25]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o4J9Focx026434; Wed, 19 May 2010 05:15:51 -0400 Subject: [PATCH 3/3] KVM test: Add implementation of network based unattended installation To: lmr@redhat.com, autotest@test.kernel.org From: Jason Wang Cc: kvm@vger.kernel.org Date: Wed, 19 May 2010 17:20:52 +0800 Message-ID: <20100519092052.13721.7219.stgit@dhcp-91-25.nay.redhat.com> In-Reply-To: <20100519092036.13721.59023.stgit@dhcp-91-25.nay.redhat.com> References: <20100519092036.13721.59023.stgit@dhcp-91-25.nay.redhat.com> User-Agent: StGit/0.15 MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Wed, 19 May 2010 09:15:58 +0000 (UTC) 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