github.com/coreos/mantle@v0.13.0/kola/tests/ignition/sethostname.go (about) 1 // Copyright 2016 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 ignition 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 // Set the hostname 27 configV1 := conf.Ignition(`{ 28 "ignitionVersion": 1, 29 "storage": { 30 "filesystems": [ 31 { 32 "device": "/dev/disk/by-partlabel/ROOT", 33 "format": "ext4", 34 "files": [ 35 { 36 "path": "/etc/hostname", 37 "mode": 420, 38 "contents": "core1" 39 } 40 ] 41 } 42 ] 43 } 44 }`) 45 configV2 := conf.Ignition(`{ 46 "ignition": { 47 "version": "2.0.0" 48 }, 49 "storage": { 50 "files": [ 51 { 52 "filesystem": "root", 53 "path": "/etc/hostname", 54 "mode": 420, 55 "contents": { 56 "source": "data:,core1" 57 } 58 } 59 ] 60 } 61 }`) 62 configV3 := conf.Ignition(`{ 63 "ignition": { 64 "version": "3.0.0" 65 }, 66 "storage": { 67 "files": [ 68 { 69 "path": "/etc/hostname", 70 "mode": 420, 71 "overwrite": true, 72 "contents": { 73 "source": "data:,core1" 74 } 75 } 76 ] 77 } 78 }`) 79 80 // These tests are disabled on Azure because the hostname 81 // is required by the API and is overwritten via waagent.service 82 // after the machine has booted. 83 register.Register(®ister.Test{ 84 Name: "cl.ignition.v1.sethostname", 85 Run: setHostname, 86 ClusterSize: 1, 87 UserData: configV1, 88 Distros: []string{"cl"}, 89 ExcludePlatforms: []string{"azure"}, 90 }) 91 register.Register(®ister.Test{ 92 Name: "coreos.ignition.sethostname", 93 Run: setHostname, 94 ClusterSize: 1, 95 UserData: configV2, 96 UserDataV3: configV3, 97 Distros: []string{"cl", "fcos", "rhcos"}, 98 ExcludePlatforms: []string{"azure"}, 99 }) 100 } 101 102 func setHostname(c cluster.TestCluster) { 103 m := c.Machines()[0] 104 105 out := c.MustSSH(m, "hostnamectl") 106 107 if !strings.Contains(string(out), "Static hostname: core1") { 108 c.Fatalf("hostname wasn't set correctly:\n%s", out) 109 } 110 }