2023-03-26 08:57:54 +00:00
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
namespace CodexDistTestCore
|
2023-03-26 08:45:01 +00:00
|
|
|
|
{
|
|
|
|
|
public interface IPodLogHandler
|
|
|
|
|
{
|
|
|
|
|
void Log(Stream log);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 08:57:54 +00:00
|
|
|
|
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
|
2023-03-27 12:49:34 +00:00
|
|
|
|
public class DontDownloadLogsAndMetricsOnFailureAttribute : PropertyAttribute
|
2023-03-26 08:57:54 +00:00
|
|
|
|
{
|
2023-03-27 12:49:34 +00:00
|
|
|
|
public DontDownloadLogsAndMetricsOnFailureAttribute()
|
2023-03-26 08:57:54 +00:00
|
|
|
|
: base(Timing.UseLongTimeoutsKey)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-26 08:45:01 +00:00
|
|
|
|
public class PodLogDownloader
|
|
|
|
|
{
|
2023-03-26 08:57:54 +00:00
|
|
|
|
public const string DontDownloadLogsOnFailureKey = "DontDownloadLogsOnFailure";
|
|
|
|
|
|
2023-03-26 08:45:01 +00:00
|
|
|
|
private readonly TestLog log;
|
|
|
|
|
private readonly IK8sManager k8SManager;
|
|
|
|
|
|
|
|
|
|
public PodLogDownloader(TestLog log, IK8sManager k8sManager)
|
|
|
|
|
{
|
|
|
|
|
this.log = log;
|
|
|
|
|
k8SManager = k8sManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CodexNodeLog DownloadLog(OnlineCodexNode node)
|
|
|
|
|
{
|
|
|
|
|
var description = node.Describe();
|
|
|
|
|
var subFile = log.CreateSubfile();
|
|
|
|
|
|
|
|
|
|
log.Log($"Downloading logs for {description} to file {subFile.FilenameWithoutPath}");
|
|
|
|
|
var handler = new PodLogDownloadHandler(description, subFile);
|
|
|
|
|
k8SManager.FetchPodLog(node, handler);
|
|
|
|
|
return handler.CreateCodexNodeLog();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PodLogDownloadHandler : IPodLogHandler
|
|
|
|
|
{
|
|
|
|
|
private readonly string description;
|
|
|
|
|
private readonly LogFile log;
|
|
|
|
|
|
|
|
|
|
public PodLogDownloadHandler(string description, LogFile log)
|
|
|
|
|
{
|
|
|
|
|
this.description = description;
|
|
|
|
|
this.log = log;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public CodexNodeLog CreateCodexNodeLog()
|
|
|
|
|
{
|
|
|
|
|
return new CodexNodeLog(log);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Log(Stream stream)
|
|
|
|
|
{
|
|
|
|
|
log.Write($"{description} -->> {log.FilenameWithoutPath}");
|
|
|
|
|
log.WriteRaw(description);
|
|
|
|
|
var reader = new StreamReader(stream);
|
|
|
|
|
var line = reader.ReadLine();
|
|
|
|
|
while (line != null)
|
|
|
|
|
{
|
|
|
|
|
log.WriteRaw(line);
|
|
|
|
|
line = reader.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|