-
Notifications
You must be signed in to change notification settings - Fork 181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global fwd and subnet error msgs fix & test cases #1051
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ import ( | |
"testing" | ||
"time" | ||
|
||
"github.com/contiv/contivmodel" | ||
contivModel "github.com/contiv/contivmodel" | ||
"github.com/contiv/contivmodel/client" | ||
"github.com/contiv/netplugin/core" | ||
"github.com/contiv/netplugin/netmaster/gstate" | ||
|
@@ -297,7 +297,7 @@ func checkInspectGlobal(t *testing.T, expError bool, allocedVlans, allocedVxlans | |
} | ||
|
||
// checkGlobalSet sets global state and verifies state | ||
func checkGlobalSet(t *testing.T, expError bool, fabMode, vlans, vxlans, fwdMode, arpMode, pvtSubnet string) { | ||
func checkGlobalSet(t *testing.T, expError bool, fabMode, vlans, vxlans, fwdMode, arpMode, pvtSubnet string) *error { | ||
gl := client.Global{ | ||
Name: "global", | ||
NetworkInfraType: fabMode, | ||
|
@@ -358,7 +358,9 @@ func checkGlobalSet(t *testing.T, expError bool, fabMode, vlans, vxlans, fwdMode | |
if err := vlanRsrc.Read("global"); err != nil { | ||
t.Fatalf("Error reading vlan resource. Err: %v", err) | ||
} | ||
return nil | ||
} | ||
return &err | ||
} | ||
|
||
// checkAciGwSet sets AciGw state and verifies verifies it | ||
|
@@ -1317,8 +1319,80 @@ func TestDynamicGlobalVxlanRange(t *testing.T) { | |
|
||
} | ||
|
||
// TestGlobalSetting tests global REST api | ||
func TestGlobalSettingFwdMode(t *testing.T) { | ||
// set to default values (no-op) | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this returns an error, we should probably be asserting that it's nil or some expected value... If there's a legit reason for skipping error checks on a call, maybe add a comment above the call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, i was just copy pasting that part, but I can make a helper checkGlobalSetNotNil(..) to avoid if block every call |
||
|
||
// Create a vxlan network to verify you cannot change forward mode | ||
checkCreateNetwork(t, false, "default", "contiv7", "", "vxlan", "16.1.1.1/24", "16.1.1.254", 3200, "", "", "") | ||
|
||
// Should fail when changing the forwarding mode whenever there is a network | ||
var err *error | ||
var expErr string | ||
err = checkGlobalSet(t, true, "default", "1-4094", "1-10000", "routing", "proxy", "172.19.0.0/16") | ||
expErr = "Unable to update forwarding mode due to existing 1 vxlans" | ||
if strings.TrimSpace((*err).Error()) != expErr { | ||
t.Fatalf("Wrong error message, expected: '%v', got '%v'", expErr, (*err).Error()) | ||
} | ||
// remove the vxlan network and add a vlan network | ||
checkDeleteNetwork(t, false, "default", "contiv7") | ||
checkCreateNetwork(t, false, "default", "contiv7", "", "vlan", "16.1.1.1/24", "16.1.1.254", 3200, "", "", "") | ||
err = checkGlobalSet(t, true, "default", "1-4094", "1-10000", "routing", "proxy", "172.19.0.0/16") | ||
expErr = "Unable to update forwarding mode due to existing 1 vlans" | ||
if strings.TrimSpace((*err).Error()) != expErr { | ||
t.Fatalf("Wrong error message, expected: '%v', got '%v'", expErr, (*err).Error()) | ||
} | ||
|
||
// remove the vlan network | ||
checkDeleteNetwork(t, false, "default", "contiv7") | ||
|
||
// make sure can change forwarding mode after network deleted | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "routing", "proxy", "172.21.0.0/16") | ||
|
||
// reset back to default values | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
} | ||
|
||
func TestGlobalSettingSubnet(t *testing.T) { | ||
// set to default values (no-op) | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
// Create a network to see if global subnet changes are blocked | ||
checkCreateNetwork(t, false, "default", "contiv7", "", "vxlan", "16.1.1.1/24", "16.1.1.254", 3200, "", "", "") | ||
|
||
var err *error | ||
var expErr string | ||
// This should fail | ||
err = checkGlobalSet(t, true, "default", "1-4094", "1-10000", "bridge", "proxy", "172.21.0.0/16") | ||
expErr = "Unable to update private subnet due to existing 1 vxlans" | ||
if strings.TrimSpace((*err).Error()) != expErr { | ||
t.Fatalf("Wrong error message, expected: '%v', got '%v'", expErr, (*err).Error()) | ||
} | ||
|
||
// remove the vxlan network and add a vlan network | ||
checkDeleteNetwork(t, false, "default", "contiv7") | ||
checkCreateNetwork(t, false, "default", "contiv7", "", "vlan", "16.1.1.1/24", "16.1.1.254", 3200, "", "", "") | ||
|
||
// This should still fail | ||
err = checkGlobalSet(t, true, "default", "1-4094", "1-10000", "bridge", "proxy", "172.21.0.0/16") | ||
expErr = "Unable to update private subnet due to existing 1 vlans" | ||
if strings.TrimSpace((*err).Error()) != expErr { | ||
t.Fatalf("Wrong error message, expected: '%v', got '%v'", expErr, (*err).Error()) | ||
} | ||
|
||
// remove the network | ||
checkDeleteNetwork(t, false, "default", "contiv7") | ||
// make sure can change subnet after network deleted | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.21.0.0/16") | ||
// reset back to default values | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
} | ||
|
||
// TestGlobalSetting tests global REST api | ||
func TestGlobalSetting(t *testing.T) { | ||
// set to default values (no-op) | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
|
||
// try basic modification | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.20.0.0/16") | ||
// set aci mode | ||
|
@@ -1342,11 +1416,6 @@ func TestGlobalSetting(t *testing.T) { | |
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.21.0.0/16") | ||
// Try invalid pvt subnet | ||
checkGlobalSet(t, true, "default", "1-4094", "1-10000", "bridge", "proxy", "172.21.0.0/24") | ||
// Try changing subnet with active network | ||
checkCreateNetwork(t, false, "default", "contiv7", "", "vxlan", "16.1.1.1/24", "16.1.1.254", 3200, "", "", "") | ||
checkGlobalSet(t, true, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
checkDeleteNetwork(t, false, "default", "contiv7") | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
|
||
// reset back to default values | ||
checkGlobalSet(t, false, "default", "1-4094", "1-10000", "bridge", "proxy", "172.19.0.0/16") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return
error
instead of*error
hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done