itest+etcd: save etcd logs along the node logs
This commit is contained in:
1 file changed
+55
-21
+55
-21
@@ -11,6 +11,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@@ -324,6 +325,12 @@ func (cfg NodeConfig) genArgs() []string {
|
|||||||
NextAvailablePort(),
|
NextAvailablePort(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
args = append(
|
||||||
|
args, fmt.Sprintf(
|
||||||
|
"--db.etcd.embedded_log_file=%v",
|
||||||
|
path.Join(cfg.LogDir, "etcd.log"),
|
||||||
|
),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.FeeURL != "" {
|
if cfg.FeeURL != "" {
|
||||||
@@ -558,6 +565,15 @@ func (hn *HarnessNode) InvoiceMacPath() string {
|
|||||||
return hn.Cfg.InvoiceMacPath
|
return hn.Cfg.InvoiceMacPath
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// renameFile is a helper to rename (log) files created during integration tests.
|
||||||
|
func renameFile(fromFileName, toFileName string) {
|
||||||
|
err := os.Rename(fromFileName, toFileName)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("could not rename %s to %s: %v\n",
|
||||||
|
fromFileName, toFileName, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Start launches a new process running lnd. Additionally, the PID of the
|
// Start launches a new process running lnd. Additionally, the PID of the
|
||||||
// launched process is saved in order to possibly kill the process forcibly
|
// launched process is saved in order to possibly kill the process forcibly
|
||||||
// later.
|
// later.
|
||||||
@@ -584,6 +600,30 @@ func (hn *HarnessNode) start(lndBinary string, lndError chan<- error,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getFinalizedLogFilePrefix := func() string {
|
||||||
|
pubKeyHex := hex.EncodeToString(
|
||||||
|
hn.PubKey[:logPubKeyBytes],
|
||||||
|
)
|
||||||
|
|
||||||
|
return fmt.Sprintf("%s/%d-%s-%s-%s",
|
||||||
|
GetLogDir(), hn.NodeID,
|
||||||
|
hn.Cfg.LogFilenamePrefix,
|
||||||
|
hn.Cfg.Name, pubKeyHex)
|
||||||
|
}
|
||||||
|
|
||||||
|
finalizeEtcdLog := func() {
|
||||||
|
if hn.Cfg.DbBackend != BackendEtcd {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
etcdLogFileName := fmt.Sprintf("%s/etcd.log", hn.Cfg.LogDir)
|
||||||
|
newEtcdLogFileName := fmt.Sprintf("%v-etcd.log",
|
||||||
|
getFinalizedLogFilePrefix(),
|
||||||
|
)
|
||||||
|
|
||||||
|
renameFile(etcdLogFileName, newEtcdLogFileName)
|
||||||
|
}
|
||||||
|
|
||||||
// If the logoutput flag is passed, redirect output from the nodes to
|
// If the logoutput flag is passed, redirect output from the nodes to
|
||||||
// log files.
|
// log files.
|
||||||
if *logOutput {
|
if *logOutput {
|
||||||
@@ -600,29 +640,19 @@ func (hn *HarnessNode) start(lndBinary string, lndError chan<- error,
|
|||||||
fileName = fmt.Sprintf("%s/%d-%s-%s-tmp__.log", dir,
|
fileName = fmt.Sprintf("%s/%d-%s-%s-tmp__.log", dir,
|
||||||
hn.NodeID, hn.Cfg.LogFilenamePrefix,
|
hn.NodeID, hn.Cfg.LogFilenamePrefix,
|
||||||
hn.Cfg.Name)
|
hn.Cfg.Name)
|
||||||
|
}
|
||||||
|
|
||||||
// Once the node has done its work, the log file can be
|
// Once the node has done its work, the log file can be
|
||||||
// renamed.
|
// renamed.
|
||||||
finalizeLogfile = func() {
|
finalizeLogfile = func() {
|
||||||
if hn.logFile != nil {
|
if hn.logFile != nil {
|
||||||
hn.logFile.Close()
|
hn.logFile.Close()
|
||||||
|
|
||||||
pubKeyHex := hex.EncodeToString(
|
newFileName := fmt.Sprintf("%v.log",
|
||||||
hn.PubKey[:logPubKeyBytes],
|
getFinalizedLogFilePrefix(),
|
||||||
)
|
)
|
||||||
newFileName := fmt.Sprintf("%s/"+
|
|
||||||
"%d-%s-%s-%s.log",
|
renameFile(fileName, newFileName)
|
||||||
dir, hn.NodeID,
|
|
||||||
hn.Cfg.LogFilenamePrefix,
|
|
||||||
hn.Cfg.Name, pubKeyHex)
|
|
||||||
err := os.Rename(fileName, newFileName)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("could not rename "+
|
|
||||||
"%s to %s: %v\n",
|
|
||||||
fileName, newFileName,
|
|
||||||
err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -666,6 +696,10 @@ func (hn *HarnessNode) start(lndBinary string, lndError chan<- error,
|
|||||||
|
|
||||||
// Make sure log file is closed and renamed if necessary.
|
// Make sure log file is closed and renamed if necessary.
|
||||||
finalizeLogfile()
|
finalizeLogfile()
|
||||||
|
|
||||||
|
// Rename the etcd.log file if the node was running on embedded
|
||||||
|
// etcd.
|
||||||
|
finalizeEtcdLog()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Write process ID to a file.
|
// Write process ID to a file.
|
||||||
|
|||||||
Reference in new issue
Block a user