github.com/coreos/mantle@v0.13.0/kola/tests/misc/cloudinit.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 misc 16 17 import ( 18 "strings" 19 20 "github.com/coreos/mantle/kola/cluster" 21 "github.com/coreos/mantle/kola/register" 22 "github.com/coreos/mantle/platform/conf" 23 ) 24 25 func init() { 26 register.Register(®ister.Test{ 27 Run: CloudInitBasic, 28 ClusterSize: 1, 29 Name: "cl.cloudinit.basic", 30 UserData: conf.CloudConfig(`#cloud-config 31 hostname: "core1" 32 write_files: 33 - path: "/foo" 34 content: bar`), 35 Distros: []string{"cl"}, 36 ExcludePlatforms: []string{"qemu-unpriv"}, 37 }) 38 register.Register(®ister.Test{ 39 Run: CloudInitScript, 40 ClusterSize: 1, 41 Name: "cl.cloudinit.script", 42 UserData: conf.Script(`#!/bin/bash 43 echo bar > /foo 44 mkdir -p ~core/.ssh 45 cat <<EOF >> ~core/.ssh/authorized_keys 46 @SSH_KEYS@ 47 EOF 48 chown -R core.core ~core/.ssh 49 chmod 700 ~core/.ssh 50 chmod 600 ~core/.ssh/authorized_keys`), 51 Distros: []string{"cl"}, 52 ExcludePlatforms: []string{"qemu-unpriv"}, 53 }) 54 } 55 56 func CloudInitBasic(c cluster.TestCluster) { 57 m := c.Machines()[0] 58 59 out := c.MustSSH(m, "cat /foo") 60 if string(out) != "bar" { 61 c.Fatalf("cloud-config produced unexpected value %q", out) 62 } 63 64 out = c.MustSSH(m, "hostnamectl") 65 if !strings.Contains(string(out), "Static hostname: core1") { 66 c.Fatalf("hostname wasn't set correctly:\n%s", out) 67 } 68 } 69 70 func CloudInitScript(c cluster.TestCluster) { 71 m := c.Machines()[0] 72 73 out := c.MustSSH(m, "cat /foo") 74 if string(out) != "bar" { 75 c.Fatalf("userdata script produced unexpected value %q", out) 76 } 77 }