Revert "CA initialization while boostrapping and TestLeader_ChangeServerID fix." (#4497)

* Revert "BUGFIX: Unit test relying on WaitForLeader() did not work due to wrong test (#4472)"

This reverts commit cec5d72396.

* Revert "CA initialization while boostrapping and TestLeader_ChangeServerID fix. (#4493)"

This reverts commit 589b589b53.
This commit is contained in:
Siva Prasad 2018-08-07 08:29:48 -04:00 committed by GitHub
parent cec5d72396
commit 288d350a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 15 deletions

View File

@ -45,18 +45,23 @@ func NewConsulProvider(rawConfig map[string]interface{}, delegate ConsulProvider
// Check if this configuration of the provider has already been // Check if this configuration of the provider has already been
// initialized in the state store. // initialized in the state store.
state := delegate.State() state := delegate.State()
idx, providerState, err := state.CAProviderState(provider.id) _, providerState, err := state.CAProviderState(provider.id)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// Exit early if the state store has already been populated for this config.
if providerState != nil {
return provider, nil
}
newState := structs.CAConsulProviderState{ newState := structs.CAConsulProviderState{
ID: provider.id, ID: provider.id,
} }
// Write the initial provider state to get the index to use for the // Write the initial provider state to get the index to use for the
// CA serial number. // CA serial number.
if providerState == nil { {
args := &structs.CARequest{ args := &structs.CARequest{
Op: structs.CAOpSetProviderState, Op: structs.CAOpSetProviderState,
ProviderState: &newState, ProviderState: &newState,
@ -64,12 +69,12 @@ func NewConsulProvider(rawConfig map[string]interface{}, delegate ConsulProvider
if err := delegate.ApplyCARequest(args); err != nil { if err := delegate.ApplyCARequest(args); err != nil {
return nil, err return nil, err
} }
}
idx, _, err = state.CAProviderState(provider.id) idx, _, err := state.CAProviderState(provider.id)
if err != nil { if err != nil {
return nil, err return nil, err
} }
}
// Generate a private key if needed // Generate a private key if needed
if conf.PrivateKey == "" { if conf.PrivateKey == "" {

View File

@ -864,16 +864,21 @@ func TestLeader_RollRaftServer(t *testing.T) {
func TestLeader_ChangeServerID(t *testing.T) { func TestLeader_ChangeServerID(t *testing.T) {
t.Parallel() t.Parallel()
conf := func(c *Config) {
dir1, s1 := testServerDCBootstrap(t, "dc1", true) c.Bootstrap = false
c.BootstrapExpect = 3
c.Datacenter = "dc1"
c.RaftConfig.ProtocolVersion = 3
}
dir1, s1 := testServerWithConfig(t, conf)
defer os.RemoveAll(dir1) defer os.RemoveAll(dir1)
defer s1.Shutdown() defer s1.Shutdown()
dir2, s2 := testServerDCBootstrap(t, "dc1", false) dir2, s2 := testServerWithConfig(t, conf)
defer os.RemoveAll(dir2) defer os.RemoveAll(dir2)
defer s2.Shutdown() defer s2.Shutdown()
dir3, s3 := testServerDCBootstrap(t, "dc1", false) dir3, s3 := testServerWithConfig(t, conf)
defer os.RemoveAll(dir3) defer os.RemoveAll(dir3)
defer s3.Shutdown() defer s3.Shutdown()
@ -886,12 +891,8 @@ func TestLeader_ChangeServerID(t *testing.T) {
retry.Run(t, func(r *retry.R) { r.Check(wantPeers(s, 3)) }) retry.Run(t, func(r *retry.R) { r.Check(wantPeers(s, 3)) })
} }
testrpc.WaitForLeader(t, s1.RPC, "dc1")
// Shut down a server, freeing up its address/port // Shut down a server, freeing up its address/port
if err := s3.Shutdown(); err != nil { s3.Shutdown()
t.Fatal(err)
}
retry.Run(t, func(r *retry.R) { retry.Run(t, func(r *retry.R) {
alive := 0 alive := 0
@ -908,6 +909,9 @@ func TestLeader_ChangeServerID(t *testing.T) {
// Bring up a new server with s3's address that will get a different ID // Bring up a new server with s3's address that will get a different ID
dir4, s4 := testServerWithConfig(t, func(c *Config) { dir4, s4 := testServerWithConfig(t, func(c *Config) {
c.Bootstrap = false c.Bootstrap = false
c.BootstrapExpect = 3
c.Datacenter = "dc1"
c.RaftConfig.ProtocolVersion = 3
c.SerfLANConfig.MemberlistConfig = s3.config.SerfLANConfig.MemberlistConfig c.SerfLANConfig.MemberlistConfig = s3.config.SerfLANConfig.MemberlistConfig
c.RPCAddr = s3.config.RPCAddr c.RPCAddr = s3.config.RPCAddr
c.RPCAdvertise = s3.config.RPCAdvertise c.RPCAdvertise = s3.config.RPCAdvertise