Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
*: don't hardcode hostport of local Omaha server
Browse files Browse the repository at this point in the history
  • Loading branch information
bgilbert committed Nov 5, 2018
1 parent 1f2cfa5 commit 66c0840
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
6 changes: 5 additions & 1 deletion cmd/kola/spawn.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,11 @@ func doSpawn(cmd *cobra.Command, args []string) error {
if err := qc.OmahaServer.AddPackage(updatePayload, "update.gz"); err != nil {
return fmt.Errorf("bad payload: %v", err)
}
updateConf = strings.NewReader("GROUP=developer\nSERVER=http://10.0.0.1:34567/v1/update/\n")
hostport, err := qc.GetOmahaHostPort()
if err != nil {
return fmt.Errorf("getting Omaha server address: %v", err)
}
updateConf = strings.NewReader(fmt.Sprintf("GROUP=developer\nSERVER=http://%s/v1/update/\n", hostport))
}

var someMach platform.Machine
Expand Down
21 changes: 15 additions & 6 deletions kola/tests/misc/omaha.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package misc

import (
"fmt"
"time"

"github.com/coreos/go-omaha/omaha"
Expand All @@ -28,13 +29,10 @@ import (
func init() {
register.Register(&register.Test{
Run: OmahaPing,
ClusterSize: 1,
ClusterSize: 0,
Name: "cl.omaha.ping",
Platforms: []string{"qemu"},
UserData: conf.ContainerLinuxConfig(`update:
server: "http://10.0.0.1:34567/v1/update/"
`),
Distros: []string{"cl"},
Distros: []string{"cl"},
})
}

Expand Down Expand Up @@ -62,7 +60,18 @@ func OmahaPing(c cluster.TestCluster) {

omahaserver.Updater = svc

m := c.Machines()[0]
hostport, err := qc.GetOmahaHostPort()
if err != nil {
c.Fatalf("couldn't get Omaha server address: %v", err)
}
config := fmt.Sprintf(`update:
server: "http://%s/v1/update/"
`, hostport)

m, err := c.NewMachine(conf.ContainerLinuxConfig(config))
if err != nil {
c.Fatalf("couldn't start machine: %v", err)
}

out, stderr, err := m.SSH("update_engine_client -check_for_update")
if err != nil {
Expand Down
17 changes: 15 additions & 2 deletions platform/local/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package local
import (
"fmt"
"math/rand"
"net"
"net/http"
"net/url"
"strconv"
Expand Down Expand Up @@ -49,17 +50,21 @@ func (lc *LocalCluster) NewCommand(name string, arg ...string) exec.Cmd {
return cmd
}

func (lc *LocalCluster) etcdEndpoint() string {
func (lc *LocalCluster) hostIP() string {
// hackydoo
bridge := "br0"
for _, seg := range lc.Dnsmasq.Segments {
if bridge == seg.BridgeName {
return fmt.Sprintf("http://%s:%d", seg.BridgeIf.DHCPv4[0].IP, lc.SimpleEtcd.Port)
return seg.BridgeIf.DHCPv4[0].IP.String()
}
}
panic("Not a valid bridge!")
}

func (lc *LocalCluster) etcdEndpoint() string {
return fmt.Sprintf("http://%s:%d", lc.hostIP(), lc.SimpleEtcd.Port)
}

func (lc *LocalCluster) GetDiscoveryURL(size int) (string, error) {
baseURL := fmt.Sprintf("%v/v2/keys/discovery/%v", lc.etcdEndpoint(), rand.Int())

Expand All @@ -85,6 +90,14 @@ func (lc *LocalCluster) GetDiscoveryURL(size int) (string, error) {
return baseURL, nil
}

func (lc *LocalCluster) GetOmahaHostPort() (string, error) {
_, port, err := net.SplitHostPort(lc.OmahaServer.Addr().String())
if err != nil {
return "", err
}
return net.JoinHostPort(lc.hostIP(), port), nil
}

func (lc *LocalCluster) NewTap(bridge string) (*TunTap, error) {
nsExit, err := ns.Enter(lc.nshandle)
if err != nil {
Expand Down

0 comments on commit 66c0840

Please sign in to comment.