本文整理汇总了Golang中github.com/coreos/mantle/platform.TestCluster类的典型用法代码示例。如果您正苦于以下问题:Golang TestCluster类的具体用法?Golang TestCluster怎么用?Golang TestCluster使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TestCluster类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: OmahaPing
func OmahaPing(c platform.TestCluster) error {
qc, ok := c.Cluster.(*platform.QEMUCluster)
if !ok {
return errors.New("test only works in qemu")
}
omahaserver := qc.LocalCluster.OmahaServer
svc := &pingServer{
ping: make(chan struct{}),
}
omahaserver.Updater = svc
m := c.Machines()[0]
out, err := m.SSH("update_engine_client -check_for_update")
if err != nil {
return fmt.Errorf("failed to execute update_engine_client -check_for_update: %v: %v", out, err)
}
tc := time.After(30 * time.Second)
select {
case <-tc:
platform.Manhole(m)
return errors.New("timed out waiting for omaha ping")
case <-svc.ping:
}
return nil
}
示例2: NTP
// Test that timesyncd starts using the local NTP server
func NTP(c platform.TestCluster) error {
m, err := c.NewMachine("")
if err != nil {
return fmt.Errorf("Cluster.NewMachine: %s", err)
}
defer m.Destroy()
out, err := m.SSH("networkctl status eth0")
if err != nil {
return fmt.Errorf("networkctl: %v", err)
}
if !bytes.Contains(out, []byte("NTP: 10.0.0.1")) {
return fmt.Errorf("Bad network config:\n%s", out)
}
plog.Info("Waiting for systemd-timesyncd.service")
for i := 0; i < 60; i++ {
out, err = m.SSH("systemctl status systemd-timesyncd.service")
if err != nil {
return fmt.Errorf("systemctl: %v", err)
}
if bytes.Contains(out, []byte(`Status: "Using Time Server 10.0.0.1:123 (10.0.0.1)."`)) {
plog.Info("systemd-timesyncd.service is working!")
return nil
}
time.Sleep(time.Second)
}
return fmt.Errorf("Bad status:\n%s", out)
}
示例3: VerityVerify
// VerityVerify asserts that the filesystem mounted on /usr matches the
// dm-verity hash that is embedded in the CoreOS kernel.
func VerityVerify(c platform.TestCluster) error {
m := c.Machines()[0]
// extract verity hash from kernel
hash, err := m.SSH("dd if=/boot/coreos/vmlinuz-a skip=64 count=64 bs=1 2>/dev/null")
if err != nil {
return fmt.Errorf("failed to extract verity hash from kernel: %v: %v", hash, err)
}
// find /usr dev
usrdev, err := m.SSH("findmnt -no SOURCE /usr")
if err != nil {
return fmt.Errorf("failed to find device for /usr: %v: %v", usrdev, err)
}
// figure out partition size for hash dev offset
offset, err := m.SSH("sudo e2size " + string(usrdev))
if err != nil {
return fmt.Errorf("failed to find /usr partition size: %v: %v", offset, err)
}
offset = bytes.TrimSpace(offset)
veritycmd := fmt.Sprintf("sudo veritysetup verify --verbose --hash-offset=%s %s %s %s", offset, usrdev, usrdev, hash)
verify, err := m.SSH(veritycmd)
if err != nil {
return fmt.Errorf("verity hash verification on %s failed: %v: %v", usrdev, verify, err)
}
return nil
}
示例4: MultiNodeSmoke
// Start a multi-node cluster from offcial kubernetes 1.0 guides. Once
// up, do a couple basic smoke checks. See:
// http://kubernetes.io/v1.0/docs/getting-started-guides/coreos/coreos_multinode_cluster.html
func MultiNodeSmoke(c platform.TestCluster) error {
const clusterSize = 3
// spawn master
master, err := c.NewMachine(masterConfig)
if err != nil {
return err
}
// get master private IP and place into nodeConfig
nodeConfig = strings.Replace(nodeConfig, "<master-private-ip>", master.PrivateIP(), -1)
var nodeConfigs []string
for i := 0; i < clusterSize-1; i++ {
nodeConfigs = append(nodeConfigs, nodeConfig)
}
// spawn nodes
nodes, err := platform.NewMachines(c, nodeConfigs)
if err != nil {
return err
}
// get kubectl in master
_, err = master.SSH("wget -q https://storage.googleapis.com/kubernetes-release/release/v1.0.1/bin/linux/amd64/kubectl")
if err != nil {
return err
}
_, err = master.SSH("chmod +x kubectl")
if err != nil {
return err
}
// check that all nodes appear in kubectl
f := func() error {
if err = nodeCheck(master, nodes); err != nil {
return err
}
return nil
}
if err := util.Retry(10, 5*time.Second, f); err != nil {
return err
}
// start nginx pod and curl endpoint
if err = nginxCheck(master, nodes); err != nil {
return err
}
// http://kubernetes.io/v1.0/docs/user-guide/secrets/ Also, ensures
// https://github.com/coreos/bugs/issues/447 does not re-occur.
if err = secretCheck(master, nodes); err != nil {
return err
}
return nil
}
示例5: setHostname
func setHostname(c platform.TestCluster) error {
m := c.Machines()[0]
out, err := m.SSH("hostnamectl")
if err != nil {
return fmt.Errorf("failed to run hostnamectl: %s: %v", out, err)
}
if !strings.Contains(string(out), "Static hostname: core1") {
return fmt.Errorf("hostname wasn't set correctly:\n%s", out)
}
return nil
}
示例6: JournalRemote
// JournalRemote tests that systemd-journal-remote can read log entries from
// a systemd-journal-gatewayd server.
func JournalRemote(c platform.TestCluster) error {
// start gatewayd and log a message
gateway, err := c.NewMachine(gatewayconf.String())
if err != nil {
return fmt.Errorf("Cluster.NewMachine: %s", err)
}
defer gateway.Destroy()
// log a unique message on gatewayd machine
msg := "supercalifragilisticexpialidocious"
out, err := gateway.SSH("logger " + msg)
if err != nil {
return fmt.Errorf("logger: %v: %v", out, err)
}
// spawn a machine to read from gatewayd
collector, err := c.NewMachine("")
if err != nil {
return fmt.Errorf("Cluster.NewMachine: %s", err)
}
defer collector.Destroy()
// collect logs from gatewayd machine
cmd := fmt.Sprintf("sudo systemd-run --unit systemd-journal-remote-client /usr/lib/systemd/systemd-journal-remote --url http://%s:19531", gateway.PrivateIP())
out, err = collector.SSH(cmd)
if err != nil {
return fmt.Errorf("failed to start systemd-journal-remote: %v: %v", out, err)
}
// find the message on the collector
journalReader := func() error {
cmd = fmt.Sprintf("sudo journalctl _HOSTNAME=%s -t core --file /var/log/journal/remote/remote-%s:19531.journal", gatewayconf.Hostname, gateway.PrivateIP())
out, err = collector.SSH(cmd)
if err != nil {
return fmt.Errorf("journalctl: %v: %v", out, err)
}
if !strings.Contains(string(out), msg) {
return fmt.Errorf("journal missing entry: expected %q got %q", msg, out)
}
return nil
}
if err := util.Retry(5, 2*time.Second, journalReader); err != nil {
return err
}
return nil
}
示例7: testRoot
func testRoot(c platform.TestCluster, fs string) error {
m := c.Machines()[0]
out, err := m.SSH("findmnt --noheadings --output FSTYPE --target /")
if err != nil {
return fmt.Errorf("failed to run findmnt: %s: %v", out, err)
}
if string(out) != fs {
return fmt.Errorf("root wasn't correctly reformatted:\n%s", out)
}
return nil
}
示例8: Install
// Test to make sure rkt install works.
func Install(c platform.TestCluster) error {
mach, err := c.NewMachine("")
if err != nil {
return fmt.Errorf("Cluster.NewMachine: %s", err)
}
defer mach.Destroy()
cmd := "sudo rkt install"
output, err := mach.SSH(cmd)
if err != nil {
return fmt.Errorf("failed to run %q: %s: %s", cmd, err, output)
}
return nil
}
示例9: scpKolet
// scpKolet searches for a kolet binary and copies it to the machine.
func scpKolet(t platform.TestCluster) error {
// TODO: determine the GOARCH for the remote machine
mArch := "amd64"
for _, d := range []string{
".",
filepath.Dir(os.Args[0]),
filepath.Join("/usr/lib/kola", mArch),
} {
kolet := filepath.Join(d, "kolet")
if _, err := os.Stat(kolet); err == nil {
return t.DropFile(kolet)
}
}
return fmt.Errorf("Unable to locate kolet binary for %s", mArch)
}
示例10: verify
func verify(c platform.TestCluster, keys ...string) error {
m := c.Machines()[0]
out, err := m.SSH("cat /run/metadata/coreos")
if err != nil {
return fmt.Errorf("failed to cat /run/metadata/coreos: %s: %v", out, err)
}
for _, key := range keys {
if !strings.Contains(string(out), key) {
return fmt.Errorf("%q wasn't found in %q", key, string(out))
}
}
return nil
}
示例11: verifyAWS
func verifyAWS(c platform.TestCluster) error {
m := c.Machines()[0]
out, err := m.SSH("coreos-metadata --version")
if err != nil {
return fmt.Errorf("failed to cat /run/metadata/coreos: %s: %v", out, err)
}
versionStr := strings.TrimPrefix(string(out), "coreos-metadata v")
version, err := semver.NewVersion(versionStr)
if err != nil {
return fmt.Errorf("failed to parse coreos-metadata version: %v", err)
}
if version.LessThan(semver.Version{Minor: 3}) {
return verify(c, "COREOS_IPV4_LOCAL", "COREOS_IPV4_PUBLIC", "COREOS_HOSTNAME")
} else {
return verify(c, "COREOS_EC2_IPV4_LOCAL", "COREOS_EC2_IPV4_PUBLIC", "COREOS_EC2_HOSTNAME")
}
}
示例12: NTP
// Test that timesyncd starts using the local NTP server
func NTP(c platform.TestCluster) error {
m, err := c.NewMachine("")
if err != nil {
return fmt.Errorf("Cluster.NewMachine: %s", err)
}
defer m.Destroy()
out, err := m.SSH("networkctl status eth0")
if err != nil {
return fmt.Errorf("networkctl: %v", err)
}
if !bytes.Contains(out, []byte("NTP: 10.0.0.1")) {
return fmt.Errorf("Bad network config:\n%s", out)
}
plog.Info("Waiting for systemd-timesyncd.service")
checker := func() error {
out, err = m.SSH("systemctl status systemd-timesyncd.service")
if err != nil {
return fmt.Errorf("systemctl: %v", err)
}
if !bytes.Contains(out, []byte(`Status: "Synchronized to time server 10.0.0.1:123 (10.0.0.1)."`)) {
return fmt.Errorf("unexpected systemd-timesyncd status: %v", out)
}
plog.Info("systemd-timesyncd.service is working!")
return nil
}
err = util.Retry(60, 1*time.Second, checker)
if err != nil {
return nil
}
return nil
}
示例13: ClusterTests
// run clustering based tests
func ClusterTests(c platform.TestCluster) error {
if plog.LevelAt(capnslog.DEBUG) {
// get journalctl -f from all machines before starting
for _, m := range c.Machines() {
if err := platform.StreamJournal(m); err != nil {
return fmt.Errorf("failed to start journal: %v", err)
}
}
}
// make sure etcd is up and running
var keyMap map[string]string
var retryFuncs []func() error
retryFuncs = append(retryFuncs, func() error {
var err error
keyMap, err = etcd.SetKeys(c, 3)
if err != nil {
return err
}
return nil
})
retryFuncs = append(retryFuncs, func() error {
if err := etcd.CheckKeys(c, keyMap, true); err != nil {
return err
}
return nil
})
for _, retry := range retryFuncs {
if err := util.Retry(5, 5*time.Second, retry); err != nil {
return fmt.Errorf("etcd failed health check: %v", err)
}
}
tests := c.ListNativeFunctions()
for _, name := range tests {
plog.Noticef("running %v...", name)
err := c.RunNative(name, c.Machines()[0])
if err != nil {
return err
}
}
return nil
}
示例14: InternetTests
// run internet based tests
func InternetTests(c platform.TestCluster) error {
tests := c.ListNativeFunctions()
for _, name := range tests {
plog.Noticef("running %v...", name)
err := c.RunNative(name, c.Machines()[0])
if err != nil {
return err
}
}
return nil
}
示例15: Proxy
// Test fleet running through an etcd2 proxy.
func Proxy(c platform.TestCluster) error {
masterconf.CoreOS.Etcd2.Discovery, _ = c.GetDiscoveryURL(1)
master, err := c.NewMachine(masterconf.String())
if err != nil {
return fmt.Errorf("Cluster.NewMachine: %s", err)
}
defer master.Destroy()
proxyconf.CoreOS.Etcd2.Discovery = masterconf.CoreOS.Etcd2.Discovery
proxy, err := c.NewMachine(proxyconf.String())
if err != nil {
return fmt.Errorf("Cluster.NewMachine: %s", err)
}
defer proxy.Destroy()
err = platform.InstallFile(strings.NewReader(fleetunit), proxy, "/home/core/hello.service")
if err != nil {
return fmt.Errorf("InstallFile: %s", err)
}
// settling...
fleetStart := func() error {
_, err = proxy.SSH("fleetctl start /home/core/hello.service")
if err != nil {
return fmt.Errorf("fleetctl start: %s", err)
}
return nil
}
if err := util.Retry(5, 5*time.Second, fleetStart); err != nil {
return fmt.Errorf("fleetctl start failed: %v", err)
}
var status []byte
fleetList := func() error {
status, err = proxy.SSH("fleetctl list-units -l -fields active -no-legend")
if err != nil {
return fmt.Errorf("fleetctl list-units: %s", err)
}
if !bytes.Equal(status, []byte("active")) {
return fmt.Errorf("unit not active")
}
return nil
}
if err := util.Retry(5, 1*time.Second, fleetList); err != nil {
return fmt.Errorf("fleetctl list-units failed: %v", err)
}
return nil
}