func (*cloudinitSuite) TestCloudInitConfigure(c *C) { for i, test := range cloudinitTests { test.cfg.Config = minimalConfig(c) c.Logf("test %d (Configure)", i) cloudcfg := coreCloudinit.New() ci, err := cloudinit.Configure(&test.cfg, cloudcfg) c.Assert(err, IsNil) c.Check(ci, NotNil) } }
// ComposeUserData puts together a binary (gzipped) blob of user data. // The additionalScripts are additional command lines that you need cloudinit // to run on the instance. Use with care. func ComposeUserData(cfg *cloudinit.MachineConfig, additionalScripts ...string) ([]byte, error) { cloudcfg := coreCloudinit.New() for _, script := range additionalScripts { cloudcfg.AddRunCmd(script) } cloudcfg, err := cloudinit.Configure(cfg, cloudcfg) if err != nil { return nil, err } data, err := cloudcfg.Render() if err != nil { return nil, err } return utils.Gzip(data), nil }
func (*cloudinitSuite) TestCloudInitConfigureUsesGivenConfig(c *C) { // Create a simple cloudinit config with a 'runcmd' statement. cloudcfg := coreCloudinit.New() script := "test script" cloudcfg.AddRunCmd(script) cloudinitTests[0].cfg.Config = minimalConfig(c) ci, err := cloudinit.Configure(&cloudinitTests[0].cfg, cloudcfg) c.Assert(err, IsNil) c.Check(ci, NotNil) data, err := ci.Render() c.Assert(err, IsNil) ciContent := make(map[interface{}]interface{}) err = goyaml.Unmarshal(data, &ciContent) c.Assert(err, IsNil) // The 'runcmd' statement is at the beginning of the list // of 'runcmd' statements. runCmd := ciContent["runcmd"].([]interface{}) c.Check(runCmd[0], Equals, script) }