mirror of
https://github.com/rancher/os.git
synced 2025-06-24 05:57:03 +00:00
Add a failing test for dualnics with static ip missing
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
parent
034073b8ab
commit
3978d93fca
@ -33,7 +33,8 @@ RUN echo "Acquire::http { Proxy \"$APTPROXY\"; };" >> /etc/apt/apt.conf.d/01prox
|
||||
syslinux-common \
|
||||
vim \
|
||||
wget \
|
||||
xorriso
|
||||
xorriso \
|
||||
telnet
|
||||
|
||||
########## Dapper Configuration #####################
|
||||
|
||||
|
@ -1 +1 @@
|
||||
APPEND rancher.autologin=tty1 rancher.autologin=ttyS0 console=tty0 console=ttyS0 printk.devkmsg=on ${APPEND}
|
||||
APPEND rancher.autologin=tty1 rancher.autologin=ttyS0 console=tty0 rancher.autologin=ttyS1 rancher.console=ttyS1 console=ttyS0 printk.devkmsg=on ${APPEND}
|
||||
|
19
scripts/run
19
scripts/run
@ -120,6 +120,9 @@ while [ "$#" -gt 0 ]; do
|
||||
# use the bios console, not serial (lets you see syslinux)
|
||||
CONSOLEDISPLAY=1
|
||||
;;
|
||||
--netconsole)
|
||||
NETCONSOLE=1
|
||||
;;
|
||||
--installed)
|
||||
./scripts/create-installed
|
||||
INSTALLED=1
|
||||
@ -162,6 +165,7 @@ if [ "$APPEND_INIT" != "" ]; then
|
||||
fi
|
||||
|
||||
if [ "$BOOT_PXE" == "1" ]; then
|
||||
KERNEL_ARGS="console=tty1 rancher.console=tty1 rancher.autologin=tty1 ${KERNEL_ARGS}"
|
||||
set -ex
|
||||
PIXIECORE=$(which pixiecore)
|
||||
sudo -E $PIXIECORE boot \
|
||||
@ -259,15 +263,19 @@ if [ "$QIND" != "1" ]; then
|
||||
HOME=${HOME:-/}
|
||||
fi
|
||||
|
||||
# default serial console
|
||||
DISPLAY_OPTS="-nographic -serial mon:stdio -display none"
|
||||
|
||||
if [ "$CONSOLEDISPLAY" == "1" ]; then
|
||||
DISPLAY_OPTS="-curses"
|
||||
else
|
||||
# default
|
||||
DISPLAY_OPTS="-nographic -serial mon:stdio -display none"
|
||||
fi
|
||||
if [ "$NETCONSOLE" == "1" ]; then
|
||||
# put ttyS1 on port 4444
|
||||
DISPLAY_OPTS="${DISPLAY_OPTS} -serial tcp::4444,server"
|
||||
KERNEL_ARGS="rancher.console=ttyS1 rancher.autologin=ttyS1 ${KERNEL_ARGS}"
|
||||
fi
|
||||
|
||||
if [ "$QEMU" == "1" ]; then
|
||||
|
||||
if [ "$INSTALLED" == "1" ]; then
|
||||
# kernel args only works when using -kernel
|
||||
KERNEL_ARGS=""
|
||||
@ -315,7 +323,8 @@ elif [ "$BOOT_ISO" == "1" ] ||
|
||||
$(eval "${hd["$ARCH"]} ${HD}") \
|
||||
${SECOND_DRIVE_ENABLE} \
|
||||
-smp 1 \
|
||||
${ISO_OPTS}
|
||||
${ISO_OPTS} \
|
||||
"${@}"
|
||||
elif [ "$QIND" == "1" ]; then
|
||||
|
||||
NAME=${NAME:-ros-qind}
|
||||
|
@ -9,6 +9,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/gbazil/telnet"
|
||||
|
||||
. "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
@ -41,6 +43,7 @@ type QemuSuite struct {
|
||||
runCommand string
|
||||
sshCommand string
|
||||
qemuCmd *exec.Cmd
|
||||
netConsole telnet.Telnet
|
||||
}
|
||||
|
||||
func (s *QemuSuite) TearDownTest(c *C) {
|
||||
@ -54,6 +57,9 @@ func (s *QemuSuite) RunQemuWith(c *C, additionalArgs ...string) error {
|
||||
|
||||
err := s.runQemu(c, additionalArgs...)
|
||||
c.Assert(err, IsNil)
|
||||
err = s.WaitForSSH()
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
@ -82,19 +88,84 @@ func (s *QemuSuite) RunQemuInstalled(c *C, additionalArgs ...string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// RunQemuWithNetConsole requires user to specify all the `scripts/run` arguments
|
||||
func (s *QemuSuite) RunQemuWithNetConsole(c *C, additionalArgs ...string) error {
|
||||
runArgs := []string{
|
||||
"--netconsole",
|
||||
}
|
||||
runArgs = append(runArgs, additionalArgs...)
|
||||
|
||||
err := s.runQemu(c, runArgs...)
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
// start telnet, and wait for prompt
|
||||
for i := 0; i < 20; i++ {
|
||||
s.netConsole, err = telnet.DialTimeout("127.0.0.1:4444", 5*time.Second)
|
||||
if err == nil {
|
||||
fmt.Printf("t%d SUCCEEDED\n", i)
|
||||
break
|
||||
}
|
||||
fmt.Printf("t%d", i)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
}
|
||||
c.Assert(err, IsNil)
|
||||
|
||||
for i := 0; i < 20; i++ {
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
res := s.NetCall("uname")
|
||||
if strings.Contains(res, "Linux") {
|
||||
fmt.Printf("W%d SUCCEEDED(%s)\n", i, res)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
s.NetCall("ip a")
|
||||
s.NetCall("cat /proc/cmdline")
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *QemuSuite) NetCall(cmd string) string {
|
||||
s.netConsole.Write(cmd + "\n")
|
||||
r, err := s.netConsole.Read("\n")
|
||||
fmt.Printf("cmd> %s", r)
|
||||
result := ""
|
||||
r = ""
|
||||
for err == nil {
|
||||
r, err = s.netConsole.Read("\n")
|
||||
fmt.Printf("\t%s", r)
|
||||
result = result + r
|
||||
}
|
||||
fmt.Printf("\n")
|
||||
// Note, if the result contains something like "+ cmd\n", you may have set -xe on
|
||||
return result
|
||||
}
|
||||
func (s *QemuSuite) NetCheckCall(c *C, additionalArgs ...string) {
|
||||
out := s.NetCall(strings.Join(additionalArgs, " "))
|
||||
c.Assert(out, Not(Equals), "")
|
||||
}
|
||||
func (s *QemuSuite) NetCheckOutput(c *C, result string, check Checker, additionalArgs ...string) string {
|
||||
out := s.NetCall(strings.Join(additionalArgs, " "))
|
||||
out = strings.Replace(out, "\r", "", -1)
|
||||
c.Assert(out, check, result)
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *QemuSuite) runQemu(c *C, args ...string) error {
|
||||
c.Assert(s.qemuCmd, IsNil) // can't run 2 qemu's at once (yet)
|
||||
s.qemuCmd = exec.Command(s.runCommand, args...)
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
//if os.Getenv("DEBUG") != "" {
|
||||
s.qemuCmd.Stdout = os.Stdout
|
||||
s.qemuCmd.Stderr = os.Stderr
|
||||
}
|
||||
//}
|
||||
if err := s.qemuCmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("--- %s: starting qemu %s, %v\n", c.TestName(), s.runCommand, args)
|
||||
|
||||
return s.WaitForSSH()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *QemuSuite) WaitForSSH() error {
|
||||
@ -171,12 +242,14 @@ func (s *QemuSuite) CheckOutputContains(c *C, result string, additionalArgs ...s
|
||||
}
|
||||
|
||||
func (s *QemuSuite) Stop(c *C) {
|
||||
//s.MakeCall("sudo halt")
|
||||
//time.Sleep(2000 * time.Millisecond)
|
||||
fmt.Printf("%s: stopping qemu\n", c.TestName())
|
||||
//s.MakeCall("sudo poweroff")
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
//c.Assert(s.WaitForSSH(), IsNil)
|
||||
|
||||
//fmt.Println("%s: stopping qemu", c.TestName())
|
||||
fmt.Printf("%s: stopping qemu 2\n", c.TestName())
|
||||
c.Assert(s.qemuCmd.Process.Kill(), IsNil)
|
||||
fmt.Printf("%s: stopping qemu 3\n", c.TestName())
|
||||
s.qemuCmd.Process.Wait()
|
||||
//time.Sleep(time.Millisecond * 1000)
|
||||
s.qemuCmd = nil
|
||||
|
@ -159,3 +159,112 @@ sync
|
||||
|
||||
s.Stop(c)
|
||||
}
|
||||
|
||||
func (s *QemuSuite) KillsMyServerTestInstalledDhcp(c *C) {
|
||||
// ./scripts/run --no-format --append "rancher.debug=true" --iso --fresh
|
||||
runArgs := []string{
|
||||
"--iso",
|
||||
"--fresh",
|
||||
// "-net", "nic,vlan=0,model=virtio",
|
||||
// "-net", "user,vlan=0",
|
||||
// "-net", "nic,vlan=0,model=virtio",
|
||||
// "-net", "user,vlan=0",
|
||||
}
|
||||
version := ""
|
||||
{
|
||||
s.RunQemuWith(c, runArgs...)
|
||||
|
||||
s.MakeCall("ip a")
|
||||
|
||||
version = s.CheckOutput(c, version, Not(Equals), "sudo ros -v")
|
||||
fmt.Printf("installing %s", version)
|
||||
|
||||
s.CheckCall(c, `
|
||||
echo "ssh_authorized_keys:" > config.yml
|
||||
echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
|
||||
echo "rancher:" >> config.yml
|
||||
echo " network:" >> config.yml
|
||||
echo " interfaces:" >> config.yml
|
||||
echo " eth2:" >> config.yml
|
||||
echo " dhcp: true" >> config.yml
|
||||
echo " eth1:" >> config.yml
|
||||
echo " address: 10.0.2.253/24" >> config.yml
|
||||
echo " dhcp: false" >> config.yml
|
||||
echo " gateway: 10.0.2.1" >> config.yml
|
||||
echo " mtu: 1500" >> config.yml
|
||||
ip a
|
||||
echo "==================="
|
||||
cat config.yml | sudo ros config merge
|
||||
sudo ros service stop network
|
||||
sleep 1
|
||||
sudo ros service start network
|
||||
sleep 1
|
||||
ip a
|
||||
echo "==================="
|
||||
sudo ros install --force --no-reboot --device /dev/vda -c config.yml -a "console=ttyS0 rancher.console=ttyS0 rancher.autologin=ttyS0 rancher.console=ttyS1 rancher.autologin=ttyS1 rancher.debug=true"
|
||||
sync
|
||||
`)
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
s.Stop(c)
|
||||
}
|
||||
|
||||
runArgs = []string{
|
||||
"--boothd",
|
||||
"-net", "nic,vlan=0,model=virtio",
|
||||
"-net", "user,vlan=0",
|
||||
"-net", "nic,vlan=0,model=virtio",
|
||||
"-net", "user,vlan=0",
|
||||
}
|
||||
s.RunQemuWithNetConsole(c, runArgs...)
|
||||
|
||||
s.NetCheckOutput(c, version, Equals, "sudo ros -v")
|
||||
s.NetCheckOutput(c, "", Not(Equals), "sh", "-c", "ip a show eth1 | grep 10.0.2..253")
|
||||
s.Stop(c)
|
||||
}
|
||||
|
||||
func (s *QemuSuite) TestConfigDhcp(c *C) {
|
||||
runArgs := []string{
|
||||
"--iso",
|
||||
"--fresh",
|
||||
"-net", "nic,vlan=0,model=virtio",
|
||||
"-net", "user,vlan=0",
|
||||
"-net", "nic,vlan=0,model=virtio",
|
||||
"-net", "user,vlan=0",
|
||||
}
|
||||
version := ""
|
||||
{
|
||||
s.RunQemuWithNetConsole(c, runArgs...)
|
||||
|
||||
s.NetCall("ip a")
|
||||
|
||||
version = s.NetCheckOutput(c, version, Not(Equals), "sudo ros -v")
|
||||
fmt.Printf("installing %s", version)
|
||||
|
||||
s.NetCheckCall(c, `
|
||||
echo "ssh_authorized_keys:" > config.yml
|
||||
echo " - $(cat /home/rancher/.ssh/authorized_keys)" >> config.yml
|
||||
echo "rancher:" >> config.yml
|
||||
echo " network:" >> config.yml
|
||||
echo " interfaces:" >> config.yml
|
||||
echo " eth2:" >> config.yml
|
||||
echo " dhcp: true" >> config.yml
|
||||
echo " eth1:" >> config.yml
|
||||
echo " address: 10.0.2.253/24" >> config.yml
|
||||
echo " dhcp: false" >> config.yml
|
||||
echo " gateway: 10.0.2.1" >> config.yml
|
||||
echo " mtu: 1500" >> config.yml
|
||||
ip a
|
||||
echo "==================="
|
||||
cat config.yml | sudo ros config merge
|
||||
sudo ros service stop network
|
||||
sleep 1
|
||||
sudo ros service start network
|
||||
sleep 1
|
||||
ip a
|
||||
`)
|
||||
|
||||
s.NetCheckOutput(c, version, Equals, "sudo ros -v")
|
||||
s.NetCheckOutput(c, "", Not(Equals), "sh", "-c", "ip a show eth1 2>/dev/null | grep 10.0.2.253")
|
||||
s.Stop(c)
|
||||
}
|
||||
}
|
||||
|
@ -59,3 +59,4 @@ golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/gol
|
||||
google.golang.org/grpc ab0be5212fb225475f2087566eded7da5d727960 https://github.com/grpc/grpc-go.git
|
||||
gopkg.in/fsnotify.v1 v1.2.0
|
||||
github.com/fatih/structs dc3312cb1a4513a366c4c9e622ad55c32df12ed3
|
||||
github.com/gbazil/telnet ba7da85c947a39063cddb0ffbff20b6bbbe9222f
|
||||
|
21
vendor/github.com/gbazil/telnet/LICENSE
generated
vendored
Normal file
21
vendor/github.com/gbazil/telnet/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2016 Vasily Suvorov
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
9
vendor/github.com/gbazil/telnet/README.md
generated
vendored
Normal file
9
vendor/github.com/gbazil/telnet/README.md
generated
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# telnet
|
||||
|
||||
[© Vasily Suvorov 2016](http://bazil.pro)
|
||||
|
||||
#### DESCRIPTION
|
||||
|
||||
Package telnet provides very simple interface for interacting with telnet devices from golang's routines.
|
||||
|
||||
[](https://godoc.org/github.com/gbazil/telnet)
|
81
vendor/github.com/gbazil/telnet/telnet.go
generated
vendored
Normal file
81
vendor/github.com/gbazil/telnet/telnet.go
generated
vendored
Normal file
@ -0,0 +1,81 @@
|
||||
// Package telnet provides very simple interface for interacting with telnet devices from go routines.
|
||||
package telnet
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Telnet presents struct with net.Conn interface for telnet protocol plus buffered reader and timeout setup
|
||||
type Telnet struct {
|
||||
conn net.Conn
|
||||
reader *bufio.Reader
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// Dial constructs connection to a telnet device. Address string must be in format: "ip:port" (e.g. "127.0.0.1:23").
|
||||
// Default timeout is set to 5 seconds.
|
||||
func Dial(addr string) (t Telnet, err error) {
|
||||
t.conn, err = net.Dial("tcp", addr)
|
||||
|
||||
if err == nil {
|
||||
t.reader = bufio.NewReader(t.conn)
|
||||
t.timeout = time.Second * 5 // default
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DialTimeout acts like Dial but takes a specific timeout (in nanoseconds).
|
||||
func DialTimeout(addr string, timeout time.Duration) (t Telnet, err error) {
|
||||
t.conn, err = net.DialTimeout("tcp", addr, timeout)
|
||||
|
||||
if err == nil {
|
||||
t.reader = bufio.NewReader(t.conn)
|
||||
t.timeout = timeout
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Read reads all data into string from telnet device until it meets the expected or stops on timeout.
|
||||
func (t Telnet) Read(expect string) (str string, err error) {
|
||||
var buf bytes.Buffer
|
||||
t.conn.SetReadDeadline(time.Now().Add(t.timeout))
|
||||
|
||||
for {
|
||||
b, e := t.reader.ReadByte()
|
||||
if e != nil {
|
||||
err = e
|
||||
break
|
||||
}
|
||||
|
||||
if b == 255 {
|
||||
t.reader.Discard(2)
|
||||
} else {
|
||||
buf.WriteByte(b)
|
||||
}
|
||||
|
||||
if strings.Contains(buf.String(), expect) {
|
||||
str = buf.String()
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Write writes string (command or data) to telnet device. Do not forget add LF to end of string!
|
||||
func (t Telnet) Write(s string) (i int, err error) {
|
||||
t.conn.SetWriteDeadline(time.Now().Add(t.timeout))
|
||||
i, err = t.conn.Write([]byte(s))
|
||||
return
|
||||
}
|
||||
|
||||
// SetTimeout changes default or start timeout for all interactions
|
||||
func (t Telnet) SetTimeout(timeout time.Duration) {
|
||||
t.timeout = timeout
|
||||
}
|
Loading…
Reference in New Issue
Block a user