1
0
mirror of https://github.com/rancher/os.git synced 2025-09-17 07:30:42 +00:00

add integration tests for iso boot, install and then boot from disk.

Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
Sven Dowideit
2016-12-15 23:15:49 +10:00
parent 11e78892c1
commit f5230f1299
4 changed files with 107 additions and 44 deletions

View File

@@ -236,7 +236,7 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
log.InitLogger() log.InitLogger()
log.SetLevel(log.InfoLevel) log.SetLevel(log.InfoLevel)
log.Infof("running installation") log.Debugf("running installation")
if installType == "generic" || if installType == "generic" ||
installType == "syslinux" || installType == "syslinux" ||
@@ -245,6 +245,7 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
if installType == "gptsyslinux" { if installType == "gptsyslinux" {
diskType = "gpt" diskType = "gpt"
} }
log.Debugf("running setDiskpartitions")
err := setDiskpartitions(device, diskType) err := setDiskpartitions(device, diskType)
if err != nil { if err != nil {
log.Errorf("error setDiskpartitions %s", err) log.Errorf("error setDiskpartitions %s", err)
@@ -254,16 +255,18 @@ func runInstall(image, installType, cloudConfig, device, kappend string, force,
device = "/host" + device device = "/host" + device
} }
log.Debugf("running mountiso?")
if mountiso { if mountiso {
// TODO: I hope to remove this from here later. // TODO: I hope to remove this from here later.
if err := mountBootIso(); err != nil { if err := mountBootIso(); err != nil {
log.Errorf("error mountBootIso %s", err)
return err return err
} }
} }
err := layDownOS(image, installType, cloudConfig, device, kappend) err := layDownOS(image, installType, cloudConfig, device, kappend)
if err != nil { if err != nil {
log.Infof("error layDownOS %s", err) log.Errorf("error layDownOS %s", err)
return err return err
} }
@@ -368,7 +371,7 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
var err error var err error
bootDir, err = formatAndMount(baseName, bootDir, device, partition) bootDir, err = formatAndMount(baseName, bootDir, device, partition)
if err != nil { if err != nil {
log.Errorf("%s", err) log.Errorf("formatAndMount %s", err)
return err return err
} }
//log.Infof("installGrub") //log.Infof("installGrub")
@@ -377,13 +380,13 @@ func layDownOS(image, installType, cloudConfig, device, kappend string) error {
err = installSyslinux(device, baseName, bootDir, diskType) err = installSyslinux(device, baseName, bootDir, diskType)
if err != nil { if err != nil {
log.Errorf("%s", err) log.Errorf("installSyslinux %s", err)
return err return err
} }
log.Debugf("seedData") log.Debugf("seedData")
err = seedData(baseName, cloudConfig, FILES) err = seedData(baseName, cloudConfig, FILES)
if err != nil { if err != nil {
log.Errorf("%s", err) log.Errorf("seedData %s", err)
return err return err
} }
log.Debugf("seedData done") log.Debugf("seedData done")
@@ -572,11 +575,17 @@ func setDiskpartitions(device, diskType string) error {
log.Errorf("%s", err) log.Errorf("%s", err)
return err return err
} }
// TODO: work out where to do this - it is a so-so place for it
if err := os.Symlink("/usr/bin/ros", "/usr/bin/system-docker"); err != nil {
log.Errorf("ln error %s", err)
}
cmd := exec.Command("system-docker", "ps", "-q") cmd := exec.Command("system-docker", "ps", "-q")
var outb bytes.Buffer var outb bytes.Buffer
cmd.Stdout = &outb cmd.Stdout = &outb
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Printf("%s", err) log.Printf("ps error: %s", err)
return err return err
} }
for _, image := range strings.Split(outb.String(), "\n") { for _, image := range strings.Split(outb.String(), "\n") {
@@ -586,15 +595,17 @@ func setDiskpartitions(device, diskType string) error {
r, w := io.Pipe() r, w := io.Pipe()
go func() { go func() {
// TODO: consider a timeout // TODO: consider a timeout
// TODO:some of these containers don't have cat / shell
cmd := exec.Command("system-docker", "exec", image, "cat /proc/mount") cmd := exec.Command("system-docker", "exec", image, "cat /proc/mount")
cmd.Stdout = w cmd.Stdout = w
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Errorf("%s", err) log.Debugf("%s cat %s", image, err)
} }
w.Close()
}() }()
if partitionMounted(device, r) { if partitionMounted(device, r) {
err = fmt.Errorf("partition %s mounted in %s, cannot repartition", device, image) err = fmt.Errorf("partition %s mounted in %s, cannot repartition", device, image)
log.Errorf("%s", err) log.Errorf("k? %s", err)
return err return err
} }
} }
@@ -604,14 +615,14 @@ func setDiskpartitions(device, diskType string) error {
cmd := exec.Command("dd", "if=/dev/zero", "of="+device, "bs=512", "count=2048") cmd := exec.Command("dd", "if=/dev/zero", "of="+device, "bs=512", "count=2048")
//cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr //cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Errorf("%s", err) log.Errorf("dd error %s", err)
return err return err
} }
log.Debugf("running partprobe") log.Debugf("running partprobe")
cmd = exec.Command("partprobe", device) cmd = exec.Command("partprobe", device)
//cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr //cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Errorf("%s", err) log.Errorf("partprobe error %s", err)
return err return err
} }
@@ -626,7 +637,7 @@ func setDiskpartitions(device, diskType string) error {
"set 1 "+bootflag+" on") "set 1 "+bootflag+" on")
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
log.Errorf("%s", err) log.Errorf("parted: %s", err)
return err return err
} }
@@ -645,7 +656,7 @@ func partitionMounted(device string, file io.Reader) bool {
} }
} }
if err := scanner.Err(); err != nil { if err := scanner.Err(); err != nil {
log.Errorf("%s", err) log.Errorf("scanner %s", err)
return false return false
} }
} }
@@ -691,6 +702,7 @@ func mountdevice(baseName, bootDir, partition string, raw bool) (string, error)
rootfs = string(out) rootfs = string(out)
} }
} }
rootfs = strings.TrimSpace(rootfs)
log.Debugf("util.Mount %s, %s", rootfs, baseName) log.Debugf("util.Mount %s, %s", rootfs, baseName)
// return bootDir, util.Mount(rootfs, baseName, "", "") // return bootDir, util.Mount(rootfs, baseName, "", "")
@@ -707,14 +719,17 @@ func formatAndMount(baseName, bootDir, device, partition string) (string, error)
err := formatdevice(device, partition) err := formatdevice(device, partition)
if err != nil { if err != nil {
log.Errorf("formatdevice %s", err)
return bootDir, err return bootDir, err
} }
bootDir, err = mountdevice(baseName, bootDir, partition, false) bootDir, err = mountdevice(baseName, bootDir, partition, false)
if err != nil { if err != nil {
log.Errorf("mountdevice %s", err)
return bootDir, err return bootDir, err
} }
err = createbootDirs(baseName, bootDir) err = createbootDirs(baseName, bootDir)
if err != nil { if err != nil {
log.Errorf("createbootDirs %s", err)
return bootDir, err return bootDir, err
} }
return bootDir, nil return bootDir, nil

View File

@@ -65,6 +65,9 @@ while [ "$#" -gt 0 ]; do
--fresh) --fresh)
FRESH=1 FRESH=1
;; ;;
--nodisplay)
NODISPLAY=1
;;
--installed) --installed)
INSTALLED=1 INSTALLED=1
;; ;;
@@ -105,7 +108,7 @@ fi
if [ "$KVM" == "" ] && [ -c /dev/kvm ] && [ -r /dev/kvm ] && [ -w /dev/kvm ]; then if [ "$KVM" == "" ] && [ -c /dev/kvm ] && [ -r /dev/kvm ] && [ -w /dev/kvm ]; then
KVM=1 KVM=1
fi fi
set -x
if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ] || [ "$BOOT_HD" == "1" ]; then if [ "$QEMU" == "1" ] || [ "$BOOT_ISO" == "1" ] || [ "$BOOT_HD" == "1" ]; then
HD=${BASE}/state/hd.img HD=${BASE}/state/hd.img
HD2=${BASE}/state/hd2.img HD2=${BASE}/state/hd2.img
@@ -192,9 +195,14 @@ elif [ "$BOOT_ISO" == "1" ] ||
-device virtio-9p-pci,id=fs1,fsdev=fsdev1,mount_tag=home " -device virtio-9p-pci,id=fs1,fsdev=fsdev1,mount_tag=home "
echo "----- $ISO_OPTS" echo "----- $ISO_OPTS"
fi fi
if [ "$NODISPLAY" == "1" ]; then
DISPLAY_OPTS="-nographic -serial stdio -display none"
else
DISPLAY_OPTS="-curses"
fi
set -x set -x
exec qemu-system-${QEMUARCH} \ exec qemu-system-${QEMUARCH} \
-curses \ ${DISPLAY_OPTS} \
-rtc base=utc,clock=host \ -rtc base=utc,clock=host \
${KVM_ENABLE} \ ${KVM_ENABLE} \
${CPU} \ ${CPU} \

View File

@@ -1,29 +1,69 @@
package integration package integration
import . "gopkg.in/check.v1" import . "gopkg.in/check.v1"
func (s *QemuSuite) TestInstall(c *C) { // TODO: separate out into different tests - there's something that makes one pass and one fail.
// ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
runArgs := []string{ //func (s *QemuSuite) TestInstallMsDosMbr(c *C) {
"--iso", func (s *QemuSuite) TestInstall(c *C) {
"--fresh", // ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
"--no-format", runArgs := []string{
"--append", "rancher.debug=true", "--iso",
} "--fresh",
s.RunQemuWith(c, runArgs...) "--nodisplay",
}
s.CheckCall(c, ` {
set -ex s.RunQemuWith(c, runArgs...)
sudo ros install --force --no-reboot --device /dev/vda`) defer s.Stop(c)
s.Stop(c) s.CheckCall(c, `
echo "---------------------------------- generic"
// ./scripts/run --no-format --append "rancher.debug=true" set -ex
runArgs = []string{ sudo parted /dev/vda print
"--no-format", echo "ssh_authorized_keys:" > config.yml
"--append", "rancher.debug=true", echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
} sudo ros install --force --no-reboot --device /dev/vda -c config.yml`)
s.RunQemuWith(c, runArgs...) }
s.CheckCall(c, "sudo ros -v") // ./scripts/run --no-format --append "rancher.debug=true"
} runArgs = []string{
"--boothd",
"--nodisplay",
}
s.RunQemuWith(c, runArgs...)
defer s.Stop(c)
s.CheckCall(c, "sudo ros -v")
//}
//func (s *QemuSuite) TestInstallGptMbr(c *C) {
// ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
runArgs = []string{
"--iso",
"--fresh",
"--nodisplay",
}
{
s.RunQemuWith(c, runArgs...)
defer s.Stop(c)
s.CheckCall(c, `
echo "---------------------------------- gptsyslinux"
set -ex
sudo parted /dev/vda print
echo "ssh_authorized_keys:" > config.yml
echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
sudo ros install --force --no-reboot --device /dev/vda -t gptsyslinux -c config.yml`)
}
// ./scripts/run --no-format --append "rancher.debug=true"
runArgs = []string{
"--boothd",
"--nodisplay",
}
s.RunQemuWith(c, runArgs...)
defer s.Stop(c)
s.CheckCall(c, "sudo ros -v")
// TEST parted output? (gpt non-uefi == legacy_boot)
}

View File

@@ -15,7 +15,7 @@ import (
"errors" "errors"
) )
// Sadly, this isn't reliable - blkid -L LABEL works more often :( // ResolveDevice this isn't reliable - blkid -L LABEL works more often :(
func ResolveDevice(spec string) string { func ResolveDevice(spec string) string {
cSpec := C.CString(spec) cSpec := C.CString(spec)
defer C.free(unsafe.Pointer(cSpec)) defer C.free(unsafe.Pointer(cSpec))