Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: Introduce constants for the network model strings
Browse files Browse the repository at this point in the history
Introduce constants for the network model strings, so as to
avoid using the strings directly at multiple places.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
  • Loading branch information
amshinde committed Oct 24, 2018
1 parent 5da973d commit 17be8e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
24 changes: 19 additions & 5 deletions virtcontainers/network.go
Expand Up @@ -68,22 +68,36 @@ func (n NetInterworkingModel) IsValid() bool {
return 0 <= int(n) && int(n) < int(NetXConnectInvalidModel)
}

const (
defaultNetModelStr = "default"

bridgedNetModelStr = "bridged"

macvtapNetModelStr = "macvtap"

enlightenedNetModelStr = "enlightened"

tcFilterNetModelStr = "tcfilter"

noneNetModelStr = "none"
)

//SetModel change the model string value
func (n *NetInterworkingModel) SetModel(modelName string) error {
switch modelName {
case "default":
case defaultNetModelStr:
*n = DefaultNetInterworkingModel
return nil
case "bridged":
case bridgedNetModelStr:
*n = NetXConnectBridgedModel
return nil
case "macvtap":
case macvtapNetModelStr:
*n = NetXConnectMacVtapModel
return nil
case "enlightened":
case enlightenedNetModelStr:
*n = NetXConnectEnlightenedModel
return nil
case "tcfilter":
case tcFilterNetModelStr:
*n = NetXConnectTCFilterModel
return nil
case "none":
Expand Down
12 changes: 6 additions & 6 deletions virtcontainers/network_test.go
Expand Up @@ -213,12 +213,12 @@ func TestNetInterworkingModelSetModel(t *testing.T) {
wantErr bool
}{
{"Invalid Model", "Invalid", true},
{"default Model", "default", false},
{"bridged Model", "bridged", false},
{"macvtap Model", "macvtap", false},
{"enlightened Model", "enlightened", false},
{"tcfilter Model", "tcfilter", false},
{"none Model", "none", false},
{"default Model", defaultNetModelStr, false},
{"bridged Model", bridgedNetModelStr, false},
{"macvtap Model", macvtapNetModelStr, false},
{"enlightened Model", enlightenedNetModelStr, false},
{"tcfilter Model", tcFilterNetModelStr, false},
{"none Model", noneNetModelStr, false},
}

for _, tt := range tests {
Expand Down

0 comments on commit 17be8e3

Please sign in to comment.