github.com/coreos/mantle@v0.13.0/kola/tests/packages/ipvsadm.go (about) 1 // Copyright 2017 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package packages 16 17 import ( 18 "bytes" 19 "fmt" 20 21 "github.com/coreos/mantle/kola/cluster" 22 ) 23 24 func ipvsadm(c cluster.TestCluster) { 25 m := c.Machines()[0] 26 27 // Test it runs at all 28 out := c.MustSSH(m, "sudo ipvsadm") 29 if !bytes.Contains(out, []byte(`IP Virtual Server version`)) { 30 c.Fatalf("unexpected ipvsadm output: %v", string(out)) 31 } 32 33 // Test by using the example from the man page 34 cmd := `echo " 35 -A -t 207.175.44.110:80 -s rr 36 -a -t 207.175.44.110:80 -r 192.168.10.1:80 -m 37 -a -t 207.175.44.110:80 -r 192.168.10.2:80 -m 38 -a -t 207.175.44.110:80 -r 192.168.10.3:80 -m 39 -a -t 207.175.44.110:80 -r 192.168.10.4:80 -m 40 -a -t 207.175.44.110:80 -r 192.168.10.5:80 -m 41 " | sudo ipvsadm -R` 42 c.MustSSH(m, cmd) 43 44 // Test we can read back what we just did 45 out = c.MustSSH(m, "sudo ipvsadm -Ln") 46 if !bytes.Contains(out, []byte(`TCP 207.175.44.110:80 rr`)) { 47 c.Fatalf("could not create virtual service %v", string(out)) 48 } 49 for i := 1; i <= 5; i++ { 50 ip := []byte(fmt.Sprintf("-> 192.168.10.%d:80", i)) 51 if !bytes.Contains(out, ip) { 52 c.Fatalf("did not add real service %v", string(ip)) 53 } 54 } 55 56 // Test we can delete the service 57 c.MustSSH(m, "sudo ipvsadm -D -t 207.175.44.110:80") 58 59 // Ensure it was really deleted 60 out = c.MustSSH(m, "sudo ipvsadm -Ln") 61 if bytes.Contains(out, []byte(`TCP 207.175.44.110:80 rr`)) { 62 c.Fatalf("could not delete virtual service") 63 } 64 }