Skip to content

Commit d971d22

Browse files
committed
Merge pull request #375 from philips/fix-reset
fix(etcd): Fix forced config reset
2 parents af20be8 + e7839e8 commit d971d22

File tree

3 files changed

+33
-15
lines changed

3 files changed

+33
-15
lines changed

Diff for: etcd.go

-10
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ func main() {
5252
profile(config.CPUProfileFile)
5353
}
5454

55-
// Only guess the machine name if there is no data dir specified
56-
// because the info file will should have our name
57-
if config.Name == "" && config.DataDir == "" {
58-
config.NameFromHostname()
59-
}
60-
61-
if config.DataDir == "" && config.Name != "" {
62-
config.DataDirFromName()
63-
}
64-
6555
if config.DataDir == "" {
6656
log.Fatal("The data dir was not set and could not be guessed from machine name")
6757
}

Diff for: server/config.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ func (c *Config) Load(arguments []string) error {
131131
return fmt.Errorf("sanitize: %v", err)
132132
}
133133

134+
// Force remove server configuration if specified.
135+
if c.Force {
136+
c.Reset()
137+
}
138+
134139
return nil
135140
}
136141

@@ -278,11 +283,6 @@ func (c *Config) LoadFlags(arguments []string) error {
278283
c.CorsOrigins = trimsplit(cors, ",")
279284
}
280285

281-
// Force remove server configuration if specified.
282-
if c.Force {
283-
c.Reset()
284-
}
285-
286286
return nil
287287
}
288288

@@ -404,6 +404,16 @@ func (c *Config) Sanitize() error {
404404
return fmt.Errorf("Peer Listen Host: %s", err)
405405
}
406406

407+
// Only guess the machine name if there is no data dir specified
408+
// because the info file should have our name
409+
if c.Name == "" && c.DataDir == "" {
410+
c.NameFromHostname()
411+
}
412+
413+
if c.DataDir == "" && c.Name != "" {
414+
c.DataDirFromName()
415+
}
416+
407417
return nil
408418
}
409419

Diff for: server/config_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,24 @@ func TestConfigNameFlag(t *testing.T) {
313313
assert.Equal(t, c.Name, "test-name", "")
314314
}
315315

316+
// Ensures that a Name gets guessed if not specified
317+
func TestConfigNameGuess(t *testing.T) {
318+
c := NewConfig()
319+
assert.Nil(t, c.LoadFlags([]string{}), "")
320+
assert.Nil(t, c.Sanitize())
321+
name, _ := os.Hostname()
322+
assert.Equal(t, c.Name, name, "")
323+
}
324+
325+
// Ensures that a DataDir gets guessed if not specified
326+
func TestConfigDataDirGuess(t *testing.T) {
327+
c := NewConfig()
328+
assert.Nil(t, c.LoadFlags([]string{}), "")
329+
assert.Nil(t, c.Sanitize())
330+
name, _ := os.Hostname()
331+
assert.Equal(t, c.DataDir, name+".etcd", "")
332+
}
333+
316334
// Ensures that Snapshot can be parsed from the environment.
317335
func TestConfigSnapshotEnv(t *testing.T) {
318336
withEnv("ETCD_SNAPSHOT", "1", func(c *Config) {

0 commit comments

Comments
 (0)