summaryrefslogtreecommitdiffstats
path: root/extras/hs-test/hst_suite.go
diff options
context:
space:
mode:
authoradrianvillin <avillin@cisco.com>2024-02-12 02:44:53 -0500
committerFlorin Coras <florin.coras@gmail.com>2024-02-15 02:38:10 +0000
commit7c675471e87c72be272c078fd481844e4efa64d0 (patch)
tree0fe20b6de72178124750a7a8f92155bef4a7c815 /extras/hs-test/hst_suite.go
parent0215ef1010fbe41a72d57e7cddc4fb18dc3d53d2 (diff)
hs-test: improved logging
- improved readability of some error messages - printing container logs to stdout on test failure (last 20 lines) Type: test Change-Id: Idbb358bdd89aa7b1a6bdc9d96bf029d4c299ce64 Signed-off-by: adrianvillin <avillin@cisco.com>
Diffstat (limited to 'extras/hs-test/hst_suite.go')
-rw-r--r--extras/hs-test/hst_suite.go50
1 files changed, 49 insertions, 1 deletions
diff --git a/extras/hs-test/hst_suite.go b/extras/hs-test/hst_suite.go
index 7f93b15f50a..908c046d082 100644
--- a/extras/hs-test/hst_suite.go
+++ b/extras/hs-test/hst_suite.go
@@ -1,6 +1,7 @@
package main
import (
+ "bufio"
"errors"
"flag"
"fmt"
@@ -102,7 +103,54 @@ func (s *HstSuite) setupContainers() {
}
}
+func logVppInstance(container *Container, maxLines int){
+ if container.vppInstance == nil{
+ return
+ }
+
+ logSource := container.getHostWorkDir() + defaultLogFilePath
+ file, err := os.Open(logSource)
+
+ if err != nil{
+ return
+ }
+ defer file.Close()
+
+ scanner := bufio.NewScanner(file)
+ var lines []string
+ var counter int
+
+ for scanner.Scan(){
+ lines = append(lines, scanner.Text())
+ counter++
+ if counter > maxLines {
+ lines = lines[1:]
+ counter--
+ }
+ }
+
+ fmt.Println("vvvvvvvvvvvvvvv " + container.name + " [VPP instance]:")
+ for _, line := range lines{
+ fmt.Println(line)
+ }
+ fmt.Printf("^^^^^^^^^^^^^^^\n\n")
+
+}
+
func (s *HstSuite) hstFail() {
+ fmt.Println("Containers: " + fmt.Sprint(s.containers))
+ for _, container := range s.containers{
+ out, err := container.log(20)
+ if err != nil{
+ fmt.Printf("An error occured while obtaining '%s' container logs: %s\n", container.name, fmt.Sprint(err))
+ break
+ }
+ fmt.Printf("\nvvvvvvvvvvvvvvv " +
+ container.name + ":\n" +
+ out +
+ "^^^^^^^^^^^^^^^\n\n")
+ logVppInstance(container, 20)
+ }
s.T().FailNow()
}
@@ -369,7 +417,7 @@ func (s *HstSuite) startHttpServer(running chan struct{}, done chan struct{}, ad
err := cmd.Start()
s.log(cmd)
if err != nil {
- fmt.Println("Failed to start http server")
+ fmt.Println("Failed to start http server: " + fmt.Sprint(err))
return
}
running <- struct{}{}