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

log: add log file to the results tar archive #1710

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
2 changes: 1 addition & 1 deletion cnf-certification-test/tnf_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
targetNameSpaces:
- name: jmontesi
- name: tnf
podsUnderTestLabels:
- "test-network-function.com/generic: target"
# deprecated operator label ("test-network-function.com/operator:"") still configured by default, no need to add it here
Expand Down
7 changes: 4 additions & 3 deletions internal/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"time"
)

type Logger struct {
*slog.Logger
}
const (
LogFileName = "cnf-certsuite.log"
LogFilePermissions = 0o644
)

var logger *slog.Logger

Expand Down
10 changes: 4 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,20 @@ const (
junitFlagKey = "junit"
TNFReportKey = "cnf-certification-test"
extraInfoKey = "testsExtraInfo"
logFileName = "cnf-certsuite.log"
logFilePermissions = 0o644
)

func init() {
flags.InitFlags()
}

func createLogFile(outputDir string) (*os.File, error) {
logFilePath := outputDir + "/" + logFileName
logFilePath := outputDir + "/" + log.LogFileName
err := os.Remove(logFilePath)
if err != nil && !os.IsNotExist(err) {
return nil, fmt.Errorf("could not delete old log file, err: %v", err)
}

logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE, logFilePermissions)
logFile, err := os.OpenFile(logFilePath, os.O_RDWR|os.O_CREATE, log.LogFilePermissions)
if err != nil {
return nil, fmt.Errorf("could not open a new log file, err: %v", err)
}
Expand All @@ -68,7 +66,7 @@ func setupLogger(logFile *os.File) {
}

log.SetupLogger(logFile, logLevel)
log.Info("Log file: %s (level=%s)", logFileName, logLevel.String())
log.Info("Log file: %s (level=%s)", log.LogFileName, logLevel.String())
}

func main() {
Expand Down Expand Up @@ -97,7 +95,7 @@ func main() {
fmt.Printf("Claim file version: %s\n", versions.ClaimFormatVersion)
fmt.Printf("Checks filter: %s\n", *flags.LabelsFlag)
fmt.Printf("Output folder: %s\n", *flags.ClaimPath)
fmt.Printf("Log file: %s\n", logFileName)
fmt.Printf("Log file: %s\n", log.LogFileName)
fmt.Printf("\n")

if *flags.ListFlag {
Expand Down
3 changes: 3 additions & 0 deletions pkg/certsuite/certsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func Run(labelsFilter, outputFolder string) {
// Add all the web artifacts file paths.
allArtifactsFilePaths = append(allArtifactsFilePaths, webFilePaths...)

// Add the log file path
allArtifactsFilePaths = append(allArtifactsFilePaths, filepath.Join(outputFolder, log.LogFileName))

// tar.gz file creation with results and html artifacts, unless omitted by env var.
if !configuration.GetTestParameters().OmitArtifactsZipFile {
err = results.CompressResultsArtifacts(resultsOutputDir, allArtifactsFilePaths)
Expand Down
Loading