Merge pull request #4172 from rickard-von-essen/default-ssh-user

ssh: Remove ssh_username default values
This commit is contained in:
Rickard von Essen 2016-11-17 22:40:09 +01:00 committed by GitHub
commit 8257c2dabd
15 changed files with 11 additions and 151 deletions

View File

@ -113,14 +113,6 @@ func TestRunConfigPrepare_SSHPort(t *testing.T) {
}
}
func TestRunConfigPrepare_SSHUsername(t *testing.T) {
c := testConfig()
c.Comm.SSHUsername = ""
if err := c.Prepare(nil); len(err) != 1 {
t.Fatalf("err: %s", err)
}
}
func TestRunConfigPrepare_UserData(t *testing.T) {
c := testConfig()
tf, err := ioutil.TempFile("", "packer")

View File

@ -76,10 +76,6 @@ func NewConfig(raws ...interface{}) (*Config, error) {
c.AsyncTimeout = 30 * time.Minute
}
if c.Comm.SSHUsername == "" {
c.Comm.SSHUsername = "root"
}
if c.InstanceName == "" {
c.InstanceName = fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
}

View File

@ -151,6 +151,7 @@ func testConfig(config map[string]interface{}) map[string]interface{} {
"api_url": "https://cloudstack.com/client/api",
"api_key": "some-api-key",
"secret_key": "some-secret-key",
"ssh_username": "root",
"cidr_list": []interface{}{"0.0.0.0/0"},
"network": "c5ed8a14-3f21-4fa9-bd74-bb887fc0ed0d",
"service_offering": "a29c52b1-a83d-4123-a57d-4548befa47a0",

View File

@ -13,6 +13,7 @@ func testConfig() map[string]interface{} {
"api_token": "bar",
"region": "nyc2",
"size": "512mb",
"ssh_username": "root",
"image": "foo",
}
}
@ -151,39 +152,6 @@ func TestBuilderPrepare_Image(t *testing.T) {
}
}
func TestBuilderPrepare_SSHUsername(t *testing.T) {
var b Builder
config := testConfig()
// Test default
warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.Comm.SSHUsername != "root" {
t.Errorf("invalid: %s", b.config.Comm.SSHUsername)
}
// Test set
config["ssh_username"] = "foo"
b = Builder{}
warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
if b.config.Comm.SSHUsername != "foo" {
t.Errorf("invalid: %s", b.config.Comm.SSHUsername)
}
}
func TestBuilderPrepare_StateTimeout(t *testing.T) {
var b Builder
config := testConfig()

View File

@ -77,12 +77,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c.DropletName = fmt.Sprintf("packer-%s", uuid.TimeOrderedUUID())
}
if c.Comm.SSHUsername == "" {
// Default to "root". You can override this if your
// SourceImage has a different user account then the DO default
c.Comm.SSHUsername = "root"
}
if c.StateTimeout == 0 {
// Default to 6 minute timeouts waiting for
// desired state. i.e waiting for droplet to become active

View File

@ -130,10 +130,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c.RawStateTimeout = "5m"
}
if c.Comm.SSHUsername == "" {
c.Comm.SSHUsername = "root"
}
if es := c.Comm.Prepare(&c.ctx); len(es) > 0 {
errs = packer.MultiErrorAppend(errs, es...)
}

View File

@ -217,6 +217,7 @@ func testConfig(t *testing.T) map[string]interface{} {
"account_file": testAccountFile(t),
"project_id": "hashicorp",
"source_image": "foo",
"ssh_username": "root",
"image_family": "bar",
"zone": "us-east1-a",
}

View File

@ -71,20 +71,6 @@ func TestConfigPrepare_host(t *testing.T) {
testConfigOk(t, warns, errs)
}
func TestConfigPrepare_sshUsername(t *testing.T) {
raw := testConfig()
// No ssh_username
delete(raw, "ssh_username")
_, warns, errs := NewConfig(raw)
testConfigErr(t, warns, errs)
// Good ssh_username
raw["ssh_username"] = "good"
_, warns, errs = NewConfig(raw)
testConfigOk(t, warns, errs)
}
func TestConfigPrepare_sshCredential(t *testing.T) {
raw := testConfig()

View File

@ -35,10 +35,6 @@ type RunConfig struct {
}
func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
// Defaults
if c.Comm.SSHUsername == "" {
c.Comm.SSHUsername = "root"
}
if c.UseFloatingIp && c.FloatingIpPool == "" {
c.FloatingIpPool = "public"

View File

@ -70,11 +70,3 @@ func TestRunConfigPrepare_SSHPort(t *testing.T) {
t.Fatalf("invalid value: %d", c.Comm.SSHPort)
}
}
func TestRunConfigPrepare_SSHUsername(t *testing.T) {
c := testRunConfig()
c.Comm.SSHUsername = ""
if err := c.Prepare(nil); len(err) != 0 {
t.Fatalf("err: %s", err)
}
}

View File

@ -77,25 +77,6 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
}
}
func TestSSHConfigPrepare_SSHUser(t *testing.T) {
var c *SSHConfig
var errs []error
c = testSSHConfig()
c.Comm.SSHUsername = ""
errs = c.Prepare(testConfigTemplate(t))
if len(errs) == 0 {
t.Fatalf("should have error")
}
c = testSSHConfig()
c.Comm.SSHUsername = "exists"
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("should not have error: %#v", errs)
}
}
const testPem = `
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAxd4iamvrwRJvtNDGQSIbNvvIQN8imXTRWlRY62EvKov60vqu

View File

@ -488,31 +488,6 @@ func TestBuilderPrepare_SSHPrivateKey(t *testing.T) {
}
}
func TestBuilderPrepare_SSHUser(t *testing.T) {
var b Builder
config := testConfig()
config["ssh_username"] = ""
b = Builder{}
warns, err := b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err == nil {
t.Fatal("should have error")
}
config["ssh_username"] = "exists"
b = Builder{}
warns, err = b.Prepare(config)
if len(warns) > 0 {
t.Fatalf("bad: %#v", warns)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}
}
func TestBuilderPrepare_SSHWaitTimeout(t *testing.T) {
var b Builder
config := testConfig()

View File

@ -108,25 +108,6 @@ func TestSSHConfigPrepare_SSHPrivateKey(t *testing.T) {
}
}
func TestSSHConfigPrepare_SSHUser(t *testing.T) {
var c *SSHConfig
var errs []error
c = testSSHConfig()
c.Comm.SSHUsername = ""
errs = c.Prepare(testConfigTemplate(t))
if len(errs) == 0 {
t.Fatalf("should have error")
}
c = testSSHConfig()
c.Comm.SSHUsername = "exists"
errs = c.Prepare(testConfigTemplate(t))
if len(errs) > 0 {
t.Fatalf("should not have error: %#v", errs)
}
}
const testPem = `
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEAxd4iamvrwRJvtNDGQSIbNvvIQN8imXTRWlRY62EvKov60vqu

View File

@ -146,7 +146,7 @@ func (c *Config) prepareSSH(ctx *interpolate.Context) []error {
// Validation
var errs []error
if c.SSHUsername == "" {
errs = append(errs, errors.New("An ssh_username must be specified"))
errs = append(errs, errors.New("An ssh_username must be specified\n Note: some builders used to default ssh_username to \"root\"."))
}
if c.SSHPrivateKey != "" {

View File

@ -70,7 +70,7 @@ The SSH communicator has the following options:
host.
* `ssh_disable_agent` (boolean) - If true, SSH agent forwarding will be
disabled.
disabled. Defaults to false.
* `ssh_file_transfer_method` (`scp` or `sftp`) - How to transfer files, Secure
copy (default) or SSH File Transfer Protocol.
@ -96,7 +96,8 @@ The SSH communicator has the following options:
Packer uses this to determine when the machine has booted so this is
usually quite long. Example value: "10m"
* `ssh_username` (string) - The username to connect to SSH with.
* `ssh_username` (string) - The username to connect to SSH with. Required
if using SSH.
## WinRM Communicator