Skip to content

Commit c502669

Browse files
author
jojimt
authored
Merge pull request #579 from jojimt/upgrade
Make sure driver oper state can upgrade gracefully
2 parents 0e3e6d0 + df1ac9f commit c502669

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

drivers/ovsdriver.go

+10
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,16 @@ func (d *OvsDriver) Init(info *core.InstanceInfo) error {
151151
}
152152
}
153153

154+
// make sure LocalEpInfo exists
155+
if d.oper.LocalEpInfo == nil {
156+
d.oper.LocalEpInfo = make(map[string]*EpInfo)
157+
// write the oper
158+
err = d.oper.Write()
159+
if err != nil {
160+
return err
161+
}
162+
}
163+
154164
log.Infof("Initializing ovsdriver")
155165

156166
// Init switch DB

drivers/ovsdriver_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,48 @@ func TestOvsDriverDeinit(t *testing.T) {
276276

277277
}
278278

279+
func TestOvsDriverStateUpgrade(t *testing.T) {
280+
driver := &OvsDriver{}
281+
fMode := "bridge"
282+
stateDriver := &state.FakeStateDriver{}
283+
stateDriver.Init(nil)
284+
instInfo := &core.InstanceInfo{HostLabel: testHostLabelStateful,
285+
StateDriver: stateDriver, FwdMode: fMode}
286+
287+
operOvs := &OvsDriverOperState{CurrPortNum: testCurrPortNum}
288+
operOvs.StateDriver = stateDriver
289+
operOvs.ID = testHostLabelStateful
290+
err := operOvs.Write()
291+
if err != nil {
292+
t.Fatalf("writing driver oper state failed. Error: %s", err)
293+
}
294+
295+
err = driver.Init(instInfo)
296+
if err != nil {
297+
t.Fatalf("driver init failed. Error: %s", err)
298+
}
299+
300+
if driver.oper.CurrPortNum != testCurrPortNum {
301+
t.Fatalf("Unexpected driver oper state. Expected port num: %d, rcvd port number: %d",
302+
testCurrPortNum, driver.oper.CurrPortNum)
303+
}
304+
305+
// Try to save local endpoint info
306+
driver.oper.localEpInfoMutex.Lock()
307+
driver.oper.LocalEpInfo["testID"] = &EpInfo{
308+
Ovsportname: "testVport",
309+
EpgKey: "testTen:testEpg",
310+
BridgeType: "vlan",
311+
}
312+
driver.oper.localEpInfoMutex.Unlock()
313+
err = driver.oper.Write()
314+
if err != nil {
315+
t.Fatalf("driver opern write failed. Error: %s", err)
316+
}
317+
318+
defer func() { driver.Deinit() }()
319+
}
320+
279321
func TestOvsDriverCreateEndpoint(t *testing.T) {
280322
driver := initOvsDriver(t)
281323
defer func() { driver.Deinit() }()

0 commit comments

Comments
 (0)