Skip to content

Commit

Permalink
When processing global mode change and arp mode change
Browse files Browse the repository at this point in the history
take the lock so that they are serialized like other
events in netplugin agent
  • Loading branch information
Vijay Krishnan committed Dec 21, 2016
1 parent a063024 commit 1b68adb
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
4 changes: 4 additions & 0 deletions mgmtfn/dockplugin/netDriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ func deleteEndpoint(hostname string) func(http.ResponseWriter, *http.Request) {
}

// delete the endpoint
netPlugin.Lock()
err = netPlugin.DeleteEndpoint(netID + "-" + delreq.EndpointID)
netPlugin.Unlock()
if err != nil {
log.Errorf("Error deleting endpoint %s. Err: %v", delreq.EndpointID, err)
httpError(w, "failed to delete endpoint", err)
Expand Down Expand Up @@ -225,7 +227,9 @@ func createEndpoint(hostname string) func(http.ResponseWriter, *http.Request) {
netID := netName + "." + tenantName

// Ask netplugin to create the endpoint
netPlugin.Lock()
err = netPlugin.CreateEndpoint(netID + "-" + cereq.EndpointID)
netPlugin.Unlock()
if err != nil {
log.Errorf("Endpoint creation failed. Error: %s", err)
httpError(w, "Could not create endpoint", err)
Expand Down
6 changes: 6 additions & 0 deletions netplugin/agent/state_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ func processEpgEvent(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, ID str

func processGlobalFwdModeUpdEvent(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, fwdMode string) {

netPlugin.Lock()
defer func() { netPlugin.Unlock() }()

// parse store URL
parts := strings.Split(opts.DbURL, "://")
if len(parts) < 2 {
Expand Down Expand Up @@ -269,6 +272,9 @@ func processGlobalFwdModeUpdEvent(netPlugin *plugin.NetPlugin, opts core.Instanc

func processGlobalConfigUpdEvent(netPlugin *plugin.NetPlugin, opts core.InstanceInfo, cfg *mastercfg.GlobConfig) {

netPlugin.Lock()
defer func() { netPlugin.Unlock() }()

// parse store URL
parts := strings.Split(opts.DbURL, "://")
if len(parts) < 2 {
Expand Down
3 changes: 3 additions & 0 deletions netplugin/plugin/netplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,14 @@ func (p *NetPlugin) GlobalFwdModeUpdate(cfg Config) {
var err error

if p.NetworkDriver != nil {
logrus.Infof("GlobalFwdModeUpdate De-initializing NetworkDriver")
p.NetworkDriver.Deinit()
p.NetworkDriver = nil
}

cfg.Instance.StateDriver, _ = utils.GetStateDriver()
p.NetworkDriver, err = utils.NewNetworkDriver(cfg.Drivers.Network, &cfg.Instance)
logrus.Infof("GlobalFwdModeUpdate Initializing NetworkDriver")

if err != nil {
logrus.Errorf("Error updating global forwarding mode %v", err)
Expand All @@ -239,6 +241,7 @@ func (p *NetPlugin) GlobalFwdModeUpdate(cfg Config) {

defer func() {
if err != nil {
logrus.Errorf("GlobalFwdModeUpdate De-initializing due to error: %v", err)
p.NetworkDriver.Deinit()
}
}()
Expand Down
10 changes: 8 additions & 2 deletions test/systemtests/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,10 @@ func (s *systemtestSuite) TestNetworkAddDeleteTenantFwdModeChangeVLAN(c *C) {
}

func (s *systemtestSuite) TestNetworkAddDeleteTenantArpModeChangeVXLAN(c *C) {
// Not applicable for routing mode
if s.fwdMode == "routing" {
return
}
arpMode := "proxy"
for i := 0; i < s.basicInfo.Iterations; i++ {
s.testNetworkAddDeleteTenant(c, "vxlan", "bridge")
Expand Down Expand Up @@ -461,9 +465,11 @@ func (s *systemtestSuite) TestNetworkAddDeleteTenantArpModeChangeVXLAN(c *C) {
}

func (s *systemtestSuite) TestNetworkAddDeleteTenantArpModeChangeVLAN(c *C) {

// Not applicable for routing mode
if s.fwdMode == "routing" {
return
}
for i := 0; i < s.basicInfo.Iterations; i++ {
s.testNetworkAddDeleteTenant(c, "vlan", s.fwdMode)
c.Assert(s.cli.GlobalPost(&client.Global{
FwdMode: "bridge",
Name: "global",
Expand Down
6 changes: 3 additions & 3 deletions test/systemtests/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1340,15 +1340,15 @@ func (s *systemtestSuite) SetUpTestVagrant(c *C) {

time.Sleep(5 * time.Second)
if s.basicInfo.Scheduler != "k8" {
for i := 0; i < 11; i++ {
for i := 0; i < 21; i++ {

_, err := s.cli.TenantGet("default")
if err == nil {
break
}
// Fail if we reached last iteration
c.Assert((i < 10), Equals, true)
time.Sleep(500 * time.Millisecond)
c.Assert((i < 20), Equals, true)
time.Sleep(1 * time.Second)
}
}

Expand Down

0 comments on commit 1b68adb

Please sign in to comment.