func (*cloudinitSuite) TestSetUbuntuUserPreciseNoKeys(c *gc.C) { ci, err := cloudinit.New("precise") c.Assert(err, jc.ErrorIsNil) cloudconfig.SetUbuntuUser(ci, "") data, err := ci.RenderYAML() c.Assert(err, jc.ErrorIsNil) c.Assert(string(data), jc.YAMLEquals, map[string]interface{}{}) }
func (*cloudinitSuite) TestSetUbuntuUserCentOS(c *gc.C) { ci, err := cloudinit.New("centos7") c.Assert(err, jc.ErrorIsNil) cloudconfig.SetUbuntuUser(ci, "akey\n#also\nbkey") data, err := ci.RenderYAML() c.Assert(err, jc.ErrorIsNil) keys := []string{"akey", "bkey"} expected := expectedUbuntuUser(cloudconfig.CentOSGroups, keys) c.Assert(string(data), jc.YAMLEquals, expected) }
func (*cloudinitSuite) TestSetUbuntuUserQuantal(c *gc.C) { ci, err := cloudinit.New("quantal") c.Assert(err, jc.ErrorIsNil) cloudconfig.SetUbuntuUser(ci, "akey") data, err := ci.RenderYAML() c.Assert(err, jc.ErrorIsNil) keys := []string{"akey"} expected := expectedUbuntuUser(cloudconfig.UbuntuGroups, keys) c.Assert(string(data), jc.YAMLEquals, expected) }
// TemplateUserData returns a minimal user data necessary for the template. // This should have the authorized keys, base packages, the cloud archive if // necessary, initial apt proxy config, and it should do the apt-get // update/upgrade initially. func TemplateUserData( series string, authorizedKeys string, aptProxy proxy.Settings, aptMirror string, enablePackageUpdates bool, enableOSUpgrades bool, networkConfig *container.NetworkConfig, ) ([]byte, error) { var config cloudinit.CloudConfig var err error if networkConfig != nil { config, err = newCloudInitConfigWithNetworks(series, networkConfig) if err != nil { return nil, errors.Trace(err) } } else { config, err = cloudinit.New(series) if err != nil { return nil, errors.Trace(err) } } cloudconfig.SetUbuntuUser(config, authorizedKeys) config.AddScripts( "set -xe", // ensure we run all the scripts or abort. ) // For LTS series which need support for the cloud-tools archive, // we need to enable apt-get update regardless of the environ // setting, otherwise provisioning will fail. if series == "precise" && !enablePackageUpdates { logger.Warningf("series %q requires cloud-tools archive: enabling updates", series) enablePackageUpdates = true } if enablePackageUpdates && config.RequiresCloudArchiveCloudTools() { config.AddCloudArchiveCloudTools() } config.AddPackageCommands(aptProxy, aptMirror, enablePackageUpdates, enableOSUpgrades) initSystem, err := service.VersionInitSystem(series) if err != nil { return nil, errors.Trace(err) } cmds, err := shutdownInitCommands(initSystem, series) if err != nil { return nil, errors.Trace(err) } config.AddScripts(strings.Join(cmds, "\n")) data, err := config.RenderYAML() if err != nil { return nil, err } return data, nil }
func (*cloudinitSuite) TestSetUbuntuUserPrecise(c *gc.C) { ci, err := cloudinit.New("precise") c.Assert(err, jc.ErrorIsNil) cloudconfig.SetUbuntuUser(ci, "akey") data, err := ci.RenderYAML() c.Assert(err, jc.ErrorIsNil) expected := map[string]interface{}{"ssh_authorized_keys": []string{ "akey", }} c.Assert(string(data), jc.YAMLEquals, expected) }