Skip to content
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

Fix issue #124: acl add/delete code isn't handling external_ids correctly #125

Merged
merged 1 commit into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,6 @@ func (odbi *ovndb) aclAddImp(lsw, direct, match, action string, priority int, ex
row["match"] = match
row["priority"] = priority

if external_ids != nil {
oMap, err := libovsdb.NewOvsMap(external_ids)
if err != nil {
return nil, err
}
row["external_ids"] = oMap
}

_, err = odbi.getACLUUIDByRow(lsw, TableACL, row)
switch err {
case ErrorNotFound:
Expand All @@ -162,6 +154,14 @@ func (odbi *ovndb) aclAddImp(lsw, direct, match, action string, priority int, ex
return nil, err
}

if external_ids != nil {
oMap, err := libovsdb.NewOvsMap(external_ids)
if err != nil {
return nil, err
}
row["external_ids"] = oMap
}

row["action"] = action
row["log"] = logflag
if logflag {
Expand Down
76 changes: 74 additions & 2 deletions acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,34 @@ func TestACLs(t *testing.T) {
}
assert.Equal(t, true, len(acls) == 2, "test[%s]", "add second acl")

// The following should fail because it is considered a duplicate of an existing ACL
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "b", "B": "b"}, false, "", "")
if err == nil {
t.Fatal(err)
}
if cmd != nil {
t.Fatal(err)
}
// cmd is nil, so this is noop
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}

acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 2, "test[%s]", "add second acl")

// The following should fail because it is considered a duplicate of an existing ACL
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1001, nil, false, "", "")
if err == nil {
t.Fatal(err)
}

// Different priority is a different ACL, so this should succeed
cmd, err = ovndbapi.ACLAdd(LSW, "to-lport", MATCH_SECOND, "drop", 1002, map[string]string{"A": "a", "B": "b"}, false, "", "")
if err != nil {
t.Fatal(err)
}
Expand All @@ -156,7 +183,39 @@ func TestACLs(t *testing.T) {
}
assert.Equal(t, true, len(acls) == 3, "test[%s]", "add second acl")

cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH, 1001, map[string]string{})
// Different direction is a different ACL, so this should succeed
cmd, err = ovndbapi.ACLAdd(LSW, "from-lport", MATCH_SECOND, "drop", 1001, map[string]string{"A": "a", "B": "b"}, false, "", "")
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}

acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 4, "test[%s]", "add second acl")


cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1002, nil)
if err != nil {
t.Fatal(err)
}
err = ovndbapi.Execute(cmd)
if err != nil {
t.Fatal(err)
}

acls, err = ovndbapi.ACLList(LSW)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, true, len(acls) == 3, "test[%s]", "add second acl")

cmd, err = ovndbapi.ACLDel(LSW, "from-lport", MATCH_SECOND, 1001, nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -171,7 +230,7 @@ func TestACLs(t *testing.T) {
}
assert.Equal(t, true, len(acls) == 2, "test[%s]", "acl remove")

cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1001, map[string]string{"A": "a"})
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH, 1001, map[string]string{})
if err != nil {
t.Fatal(err)
}
Expand All @@ -187,7 +246,14 @@ func TestACLs(t *testing.T) {

assert.Equal(t, true, len(acls) == 1, "test[%s]", "acl remove")

//The following delete should fail because external ids are provided, but they don't exist in any ACL
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1001, map[string]string{"A": "b"})
if err == nil {
t.Fatal(err)
}

//The following delete should succeed because the provided external_ids provided are a subset of thoe in an existing ACL
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1001, map[string]string{"A": "a"})
if err != nil {
t.Fatal(err)
}
Expand All @@ -202,6 +268,12 @@ func TestACLs(t *testing.T) {
}
assert.Equal(t, true, len(acls) == 0, "test[%s]", "acl remove")

// The following ACLDel should fail because all the ACLs have been deleted.
cmd, err = ovndbapi.ACLDel(LSW, "to-lport", MATCH_SECOND, 1001, map[string]string{"A": "b"})
if err == nil {
t.Fatal(err)
}

cmd, err = ovndbapi.LSPDel(LSP)
if err != nil {
t.Fatal(err)
Expand Down