github.com/coreos/mantle@v0.13.0/kola/tests/metadata/contents.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 metadata
    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  	enableMetadataService := conf.Ignition(`{
    27  	    "ignitionVersion": 1,
    28  	    "systemd": {
    29  		"units": [
    30  		    {
    31  			"name": "coreos-metadata.service",
    32  			"enable": true
    33  		    },
    34  		    {
    35  			"name": "metadata.target",
    36  			"enable": true,
    37  			"contents": "[Install]\nWantedBy=multi-user.target"
    38  		    }
    39  		]
    40  	    }
    41  	}`)
    42  
    43  	register.Register(&register.Test{
    44  		Name:        "cl.metadata.aws",
    45  		Run:         verifyAWS,
    46  		ClusterSize: 1,
    47  		Platforms:   []string{"aws"},
    48  		UserData:    enableMetadataService,
    49  		Distros:     []string{"cl"},
    50  	})
    51  
    52  	register.Register(&register.Test{
    53  		Name:        "cl.metadata.azure",
    54  		Run:         verifyAzure,
    55  		ClusterSize: 1,
    56  		Platforms:   []string{"azure"},
    57  		UserData:    enableMetadataService,
    58  		Distros:     []string{"cl"},
    59  	})
    60  
    61  	register.Register(&register.Test{
    62  		Name:        "cl.metadata.packet",
    63  		Run:         verifyPacket,
    64  		ClusterSize: 1,
    65  		Platforms:   []string{"packet"},
    66  		UserData:    enableMetadataService,
    67  		Distros:     []string{"cl"},
    68  	})
    69  }
    70  
    71  func verifyAWS(c cluster.TestCluster) {
    72  	verify(c, "COREOS_EC2_IPV4_LOCAL", "COREOS_EC2_IPV4_PUBLIC", "COREOS_EC2_HOSTNAME")
    73  }
    74  
    75  func verifyAzure(c cluster.TestCluster) {
    76  	verify(c, "COREOS_AZURE_IPV4_DYNAMIC")
    77  	// kola tests do not spawn machines behind a load balancer on Azure
    78  	// which is required for COREOS_AZURE_IPV4_VIRTUAL to be present
    79  }
    80  
    81  func verifyPacket(c cluster.TestCluster) {
    82  	verify(c, "COREOS_PACKET_HOSTNAME", "COREOS_PACKET_PHONE_HOME_URL", "COREOS_PACKET_IPV4_PUBLIC_0", "COREOS_PACKET_IPV4_PRIVATE_0", "COREOS_PACKET_IPV6_PUBLIC_0")
    83  }
    84  
    85  func verify(c cluster.TestCluster, keys ...string) {
    86  	m := c.Machines()[0]
    87  
    88  	out := c.MustSSH(m, "cat /run/metadata/coreos")
    89  
    90  	for _, key := range keys {
    91  		if !strings.Contains(string(out), key) {
    92  			c.Errorf("%q wasn't found in %q", key, string(out))
    93  		}
    94  	}
    95  }