aboutsummaryrefslogtreecommitdiffstats
path: root/extras/hs-test/infra/hst_suite.go
diff options
context:
space:
mode:
authorAdrian Villin <avillin@cisco.com>2024-09-25 14:49:11 +0200
committerFlorin Coras <florin.coras@gmail.com>2024-10-10 15:50:15 +0000
commit2acdf1e629a0e5463ed6820b9de4ae5ab7101cf6 (patch)
treec4a31f7720046076b01529308cf8afc50b124ed5 /extras/hs-test/infra/hst_suite.go
parent77ca487742310e4cdab5cad134de408b755e388b (diff)
hs-test: added dry run mode
- DRYRUN=true will set up most containers. Some need to be started manually (curl, nginx...). The framework will create a vpp-config file with interface configs that will get executed on VPP startup. - set Ginkgo to use -v instead of -vv when running a single test - s.Log() now supports formatting - added 'useEnvVars' parameter to container.Exec Type: test Change-Id: Id1da7947a1448ee4b74b86cc4f243442256a5ba8 Signed-off-by: Adrian Villin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/infra/hst_suite.go')
-rw-r--r--extras/hs-test/infra/hst_suite.go49
1 files changed, 38 insertions, 11 deletions
diff --git a/extras/hs-test/infra/hst_suite.go b/extras/hs-test/infra/hst_suite.go
index 0de748b51c7..435001afba7 100644
--- a/extras/hs-test/infra/hst_suite.go
+++ b/extras/hs-test/infra/hst_suite.go
@@ -41,6 +41,7 @@ var IsDebugBuild = flag.Bool("debug_build", false, "some paths are different wit
var UseCpu0 = flag.Bool("cpu0", false, "use cpu0")
var IsLeakCheck = flag.Bool("leak_check", false, "run leak-check tests")
var ParallelTotal = flag.Lookup("ginkgo.parallel.total")
+var DryRun = flag.Bool("dryrun", false, "set up containers but don't run tests")
var NumaAwareCpuAlloc bool
var SuiteTimeout time.Duration
@@ -62,6 +63,18 @@ type HstSuite struct {
Docker *client.Client
}
+type colors struct {
+ grn string
+ pur string
+ rst string
+}
+
+var Colors = colors{
+ grn: "\033[32m",
+ pur: "\033[35m",
+ rst: "\033[0m",
+}
+
// used for colorful ReportEntry
type StringerStruct struct {
Label string
@@ -104,8 +117,8 @@ func (s *HstSuite) newDockerClient() {
func (s *HstSuite) SetupSuite() {
s.CreateLogger()
+ s.Log("[* SUITE SETUP]")
s.newDockerClient()
- s.Log("Suite Setup")
RegisterFailHandler(func(message string, callerSkip ...int) {
s.HstFail()
Fail(message, callerSkip...)
@@ -139,13 +152,16 @@ func (s *HstSuite) AddCpuContext(cpuCtx *CpuContext) {
func (s *HstSuite) TearDownSuite() {
defer s.LogFile.Close()
defer s.Docker.Close()
- s.Log("Suite Teardown")
+ if *IsPersistent || *DryRun {
+ return
+ }
+ s.Log("[* SUITE TEARDOWN]")
s.UnconfigureNetworkTopology()
}
func (s *HstSuite) TearDownTest() {
- s.Log("Test Teardown")
- if *IsPersistent {
+ s.Log("[* TEST TEARDOWN]")
+ if *IsPersistent || *DryRun {
return
}
coreDump := s.WaitForCoreDump()
@@ -167,7 +183,7 @@ func (s *HstSuite) SkipIfUnconfiguring() {
}
func (s *HstSuite) SetupTest() {
- s.Log("Test Setup")
+ s.Log("[* TEST SETUP]")
s.StartedContainers = s.StartedContainers[:0]
s.SkipIfUnconfiguring()
s.SetupContainers()
@@ -306,13 +322,13 @@ func (s *HstSuite) CreateLogger() {
// Logs to files by default, logs to stdout when VERBOSE=true with GinkgoWriter
// to keep console tidy
-func (s *HstSuite) Log(arg any) {
- logs := strings.Split(fmt.Sprint(arg), "\n")
+func (s *HstSuite) Log(log any, arg ...any) {
+ logs := strings.Split(fmt.Sprintf(fmt.Sprint(log), arg...), "\n")
for _, line := range logs {
s.Logger.Println(line)
}
if *IsVerbose {
- GinkgoWriter.Println(arg)
+ GinkgoWriter.Println(fmt.Sprintf(fmt.Sprint(log), arg...))
}
}
@@ -477,6 +493,13 @@ func (s *HstSuite) LoadContainerTopology(topologyName string) {
}
s.Containers[newContainer.Name] = newContainer
}
+
+ if *DryRun {
+ s.Log(Colors.pur + "* Containers used by this suite (some might already be running):" + Colors.rst)
+ for name := range s.Containers {
+ s.Log("%sdocker start %s && docker exec -it %s bash%s", Colors.pur, name, name, Colors.rst)
+ }
+ }
}
func (s *HstSuite) LoadNetworkTopology(topologyName string) {
@@ -564,14 +587,18 @@ func (s *HstSuite) ConfigureNetworkTopology(topologyName string) {
}
func (s *HstSuite) UnconfigureNetworkTopology() {
- if *IsPersistent {
- return
- }
for _, nc := range s.NetConfigs {
nc.unconfigure()
}
}
+func (s *HstSuite) LogStartedContainers() {
+ s.Log("%s* Started containers:%s", Colors.grn, Colors.rst)
+ for _, container := range s.StartedContainers {
+ s.Log(Colors.grn + container.Name + Colors.rst)
+ }
+}
+
func (s *HstSuite) GetTestId() string {
testName := s.GetCurrentTestName()