forked from neuvector/neuvector
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
186b972
commit cb468e5
Showing
37 changed files
with
561 additions
and
578 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,91 @@ | ||
package atmo | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"testing" | ||
"time" | ||
// Temporarily commented out since this test function is not currently in use. | ||
|
||
log "github.com/sirupsen/logrus" | ||
// func my_test_func(mover int, group string, probeDuration time.Duration) (bool, error) { | ||
// // log.WithFields(log.Fields{"group": group, "mover": mover}).Debug("ATMO:") | ||
// switch mover { | ||
// case Discover2Monitor: | ||
// return true, nil | ||
// case Monitor2Protect: | ||
// return true, nil | ||
// } | ||
// return false, common.ErrUnsupported | ||
// } | ||
|
||
"github.com/neuvector/neuvector/controller/common" | ||
"github.com/neuvector/neuvector/share/utils" | ||
) | ||
// func my_decision_func(mover int, group string, err error) error { | ||
// log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:") | ||
// if err != nil { | ||
// log.WithFields(log.Fields{"mover": mover, "error": err}).Debug("ATMO: member left") | ||
// return nil | ||
// } | ||
|
||
func my_test_func(mover int, group string, probeDuration time.Duration) (bool, error) { | ||
// log.WithFields(log.Fields{"group": group, "mover": mover}).Debug("ATMO:") | ||
switch mover { | ||
case Discover2Monitor: | ||
return true, nil | ||
case Monitor2Protect: | ||
return true, nil | ||
} | ||
return false, common.ErrUnsupported | ||
} | ||
// switch mover { | ||
// case Discover2Monitor: | ||
// return nil | ||
// case Monitor2Protect: | ||
// return nil | ||
// } | ||
// return common.ErrUnsupported | ||
// } | ||
|
||
func my_decision_func(mover int, group string, err error) error { | ||
log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:") | ||
if err != nil { | ||
log.WithFields(log.Fields{"mover": mover, "error": err}).Debug("ATMO: member left") | ||
return nil | ||
} | ||
// func my_completed(mover int, group string, err error) bool { | ||
// log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:") | ||
// switch mover { | ||
// case Discover2Monitor: | ||
// return true // promote Discover to Monitor | ||
// case Monitor2Protect: | ||
// return true // promote Monitor to Protect | ||
// } | ||
// return false | ||
// } | ||
|
||
switch mover { | ||
case Discover2Monitor: | ||
return nil | ||
case Monitor2Protect: | ||
return nil | ||
} | ||
return common.ErrUnsupported | ||
} | ||
// func initEnv() *automode_ctx { | ||
// log.SetOutput(os.Stdout) | ||
// log.SetLevel(log.DebugLevel) // change it later: log.InfoLevel | ||
// log.SetFormatter(&utils.LogFormatter{Module: "ATMO"}) | ||
// timerWheel := utils.NewTimerWheel() | ||
// timerWheel.Start() | ||
// ctx := Init(timerWheel, my_test_func, my_decision_func) | ||
// // testing purpose | ||
// ctx.ConfigProbeTime(Discover2Monitor, time.Second*5) | ||
// ctx.ConfigProbeTime(Monitor2Protect, time.Second*5) | ||
// return ctx | ||
// } | ||
|
||
func my_completed(mover int, group string, err error) bool { | ||
log.WithFields(log.Fields{"group": group, "mover": mover, "error": err}).Debug("ATMO:") | ||
switch mover { | ||
case Discover2Monitor: | ||
return true // promote Discover to Monitor | ||
case Monitor2Protect: | ||
return true // promote Monitor to Protect | ||
} | ||
return false | ||
} | ||
// func testAddGroups(t *testing.T) { | ||
// ctx := initEnv() | ||
// ctx.ConfigureCompleteDuration(Discover2Monitor, time.Second*30) | ||
// ctx.ConfigureCompleteDuration(Monitor2Protect, time.Second*60) | ||
|
||
func initEnv() *automode_ctx { | ||
log.SetOutput(os.Stdout) | ||
log.SetLevel(log.DebugLevel) // change it later: log.InfoLevel | ||
log.SetFormatter(&utils.LogFormatter{Module: "ATMO"}) | ||
timerWheel := utils.NewTimerWheel() | ||
timerWheel.Start() | ||
ctx := Init(timerWheel, my_test_func, my_decision_func) | ||
// testing purpose | ||
ctx.ConfigProbeTime(Discover2Monitor, time.Second*5) | ||
ctx.ConfigProbeTime(Monitor2Protect, time.Second*5) | ||
return ctx | ||
} | ||
// for i := 0; i < 2; i++ { | ||
// name := fmt.Sprintf("m2d%d", i) | ||
// if ok := ctx.AddGroup(Monitor2Protect, name, ProfileMode); !ok { | ||
// t.Errorf("Error: failed to add %s\n", name) | ||
// break | ||
// } | ||
// time.Sleep(time.Second * 10) | ||
// } | ||
|
||
func testAddGroups(t *testing.T) { | ||
ctx := initEnv() | ||
ctx.ConfigureCompleteDuration(Discover2Monitor, time.Second*30) | ||
ctx.ConfigureCompleteDuration(Monitor2Protect, time.Second*60) | ||
// for i := 0; i < 5; i++ { | ||
// name := fmt.Sprintf("d2m%d", i) | ||
// if ok := ctx.AddGroup(Discover2Monitor, name, ProfileMode); !ok { | ||
// t.Errorf("Error: failed to add %s\n", name) | ||
// break | ||
// } | ||
// time.Sleep(time.Second * 10) | ||
// } | ||
|
||
for i := 0; i < 2; i++ { | ||
name := fmt.Sprintf("m2d%d", i) | ||
if ok := ctx.AddGroup(Monitor2Protect, name, ProfileMode); !ok { | ||
t.Errorf("Error: failed to add %s\n", name) | ||
break | ||
} | ||
time.Sleep(time.Second * 10) | ||
} | ||
|
||
for i := 0; i < 5; i++ { | ||
name := fmt.Sprintf("d2m%d", i) | ||
if ok := ctx.AddGroup(Discover2Monitor, name, ProfileMode); !ok { | ||
t.Errorf("Error: failed to add %s\n", name) | ||
break | ||
} | ||
time.Sleep(time.Second * 10) | ||
} | ||
|
||
cnt := 12 | ||
for { | ||
time.Sleep(time.Second * 10) | ||
if ctx.Counts(Discover2Monitor) == 0 && ctx.Counts(Monitor2Protect) == 0 { | ||
break | ||
} | ||
cnt-- | ||
if cnt == 0 { | ||
t.Errorf("Error: failed to stop\n") | ||
break | ||
} | ||
} | ||
} | ||
// cnt := 12 | ||
// for { | ||
// time.Sleep(time.Second * 10) | ||
// if ctx.Counts(Discover2Monitor) == 0 && ctx.Counts(Monitor2Protect) == 0 { | ||
// break | ||
// } | ||
// cnt-- | ||
// if cnt == 0 { | ||
// t.Errorf("Error: failed to stop\n") | ||
// break | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.