github.com/coreos/mantle@v0.13.0/kola/tests/misc/omaha.go (about)

     1  // Copyright 2015 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 misc
    16  
    17  import (
    18  	"fmt"
    19  	"time"
    20  
    21  	"github.com/coreos/go-omaha/omaha"
    22  
    23  	"github.com/coreos/mantle/kola/cluster"
    24  	"github.com/coreos/mantle/kola/register"
    25  	"github.com/coreos/mantle/platform/conf"
    26  	"github.com/coreos/mantle/platform/machine/qemu"
    27  )
    28  
    29  func init() {
    30  	register.Register(&register.Test{
    31  		Run:              OmahaPing,
    32  		ClusterSize:      0,
    33  		Name:             "cl.omaha.ping",
    34  		Platforms:        []string{"qemu"},
    35  		ExcludePlatforms: []string{"qemu-unpriv"},
    36  		Distros:          []string{"cl"},
    37  	})
    38  }
    39  
    40  type pingServer struct {
    41  	omaha.UpdaterStub
    42  
    43  	ping chan struct{}
    44  }
    45  
    46  func (ps *pingServer) Ping(req *omaha.Request, app *omaha.AppRequest) {
    47  	ps.ping <- struct{}{}
    48  }
    49  
    50  func OmahaPing(c cluster.TestCluster) {
    51  	qc, ok := c.Cluster.(*qemu.Cluster)
    52  	if !ok {
    53  		c.Fatal("test only works in qemu")
    54  	}
    55  
    56  	omahaserver := qc.LocalCluster.OmahaServer
    57  
    58  	svc := &pingServer{
    59  		ping: make(chan struct{}),
    60  	}
    61  
    62  	omahaserver.Updater = svc
    63  
    64  	hostport, err := qc.GetOmahaHostPort()
    65  	if err != nil {
    66  		c.Fatalf("couldn't get Omaha server address: %v", err)
    67  	}
    68  	config := fmt.Sprintf(`update:
    69    server: "http://%s/v1/update/"
    70  `, hostport)
    71  
    72  	m, err := c.NewMachine(conf.ContainerLinuxConfig(config))
    73  	if err != nil {
    74  		c.Fatalf("couldn't start machine: %v", err)
    75  	}
    76  
    77  	out, stderr, err := m.SSH("update_engine_client -check_for_update")
    78  	if err != nil {
    79  		c.Fatalf("couldn't check for update: %s, %s, %v", out, stderr, err)
    80  	}
    81  
    82  	tc := time.After(30 * time.Second)
    83  
    84  	select {
    85  	case <-tc:
    86  		c.Fatal("timed out waiting for omaha ping")
    87  	case <-svc.ping:
    88  	}
    89  }