Skip to content
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
8 changes: 4 additions & 4 deletions .github/workflows/pull-request-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ jobs:
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Add permission to run shell
run: chmod -R +x *.sh

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -54,6 +54,6 @@ jobs:
run: ./build-test.sh

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
8 changes: 4 additions & 4 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ jobs:
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x

- name: Initialize CodeQL
if: false # this is causing PR to fail on Windows with single slashes on Windows, temporarily disabling since we have it in Linux PR
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
Expand All @@ -53,6 +53,6 @@ jobs:

- name: Perform CodeQL Analysis
if: false # this is causing PR to fail on Windows with single slashes on Windows, temporarily disabling since we have it in Linux PR
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<PackageVersion Include="Polly" Version="8.5.0" />
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.2" />
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageVersion Include="SSH.NET" Version="2024.2.0" />
<PackageVersion Include="SSH.NET" Version="2026.0.0" />
<PackageVersion Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
<PackageVersion Include="System.Diagnostics.EventLog" Version="9.0.9" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace VirtualClient.Actions
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using VirtualClient.Common;
using VirtualClient.Common.Contracts;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;
Expand Down Expand Up @@ -117,6 +118,50 @@ public async Task SysbenchConfigurationSkipsSysbenchInitialization()
}
}

[Test]
public async Task SysbenchConfigurationWaitsForServerDependenciesBeforeRemotePopulation()
{
this.fixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchExecutor.SysbenchState()
{
SysbenchInitialized = true
}));

bool serverHeartbeatConfirmed = false;
this.fixture.ApiClient.OnGetHeartbeat().ReturnsAsync(() =>
{
serverHeartbeatConfirmed = true;
return this.fixture.CreateHttpResponse(HttpStatusCode.OK);
});

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
{
Assert.IsTrue(serverHeartbeatConfirmed);

return new InMemoryProcess
{
StartInfo = new ProcessStartInfo
{
FileName = exe,
Arguments = arguments
},
ExitCode = 0,
OnStart = () => true,
OnHasExited = () => true
};
};

using (TestSysbenchConfiguration sysbenchConfiguration = new TestSysbenchConfiguration(this.fixture.Dependencies, this.fixture.Parameters))
{
await sysbenchConfiguration.ExecuteAsync(CancellationToken.None);
}

this.fixture.ApiClient.Verify(
client => client.GetHeartbeatAsync(
It.IsAny<CancellationToken>(),
It.IsAny<IAsyncPolicy<HttpResponseMessage>>()),
Times.Once);
}

[Test]
public async Task SysbenchConfigurationPreparesDatabase()
{
Expand Down Expand Up @@ -163,6 +208,40 @@ public async Task SysbenchConfigurationPreparesDatabase()
}
}

[Test]
public void SysbenchConfigurationThrowsWhenPopulationReportsFatalError()
{
this.fixture.StateManager.OnGetState().ReturnsAsync(JObject.FromObject(new SysbenchExecutor.SysbenchState()
{
SysbenchInitialized = true
}));

this.fixture.ProcessManager.OnCreateProcess = (exe, arguments, workingDir) =>
{
return new InMemoryProcess
{
StartInfo = new ProcessStartInfo
{
FileName = exe,
Arguments = arguments
},
ExitCode = 0,
OnStart = () => true,
OnHasExited = () => true,
StandardOutput = new ConcurrentBuffer(new StringBuilder(
"FATAL: error 1130: Host '10.0.1.0' is not allowed to connect to this MySQL server"))
};
};

using (TestSysbenchConfiguration sysbenchConfiguration = new TestSysbenchConfiguration(this.fixture.Dependencies, this.fixture.Parameters))
{
WorkloadException error = Assert.ThrowsAsync<WorkloadException>(
() => sysbenchConfiguration.ExecuteAsync(CancellationToken.None));

Assert.AreEqual(ErrorReason.WorkloadUnexpectedAnomaly, error.Reason);
}
}

[Test]
public async Task SysbenchConfigurationUsesDefinedParametersWhenRunningTheWorkload()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public SysbenchConfiguration(IServiceCollection dependencies, IDictionary<string
: base(dependencies, parameters)
{
this.stateManager = this.Dependencies.GetService<IStateManager>();
this.PollingTimeout = TimeSpan.FromMinutes(10);
}

/// <summary>
Expand All @@ -45,6 +46,11 @@ public string Action
}
}

/// <summary>
/// The amount of time to wait for the server dependencies to complete.
/// </summary>
protected TimeSpan PollingTimeout { get; set; }

/// <summary>
/// Executes the workload.
/// </summary>
Expand Down Expand Up @@ -110,6 +116,14 @@ private async Task PopulateDatabase(EventContext telemetryContext, CancellationT

if (!state.DatabasePopulated)
{
if (this.IsMultiRoleLayout() && this.IsInRole(ClientRole.Client))
{
this.Logger.LogTraceMessage("Synchronization: Poll server API for heartbeat before database population...");

await this.ServerApiClient.PollForHeartbeatAsync(this.PollingTimeout, cancellationToken)
.ConfigureAwait(false);
}

await this.Logger.LogMessageAsync($"{this.TypeName}.PopulateDatabase", telemetryContext.Clone(), async () =>
{
string serverIp = (this.IsMultiRoleLayout() && this.IsInRole(ClientRole.Client)) ? this.ServerIpAddress : "localhost";
Expand All @@ -131,6 +145,14 @@ await this.Logger.LogMessageAsync($"{this.TypeName}.PopulateDatabase", telemetry
await this.LogProcessDetailsAsync(process, telemetryContext, "Sysbench", logToFile: true);
process.ThrowIfErrored<WorkloadException>(process.StandardError.ToString(), ErrorReason.WorkloadUnexpectedAnomaly);

if (process.StandardOutput.ToString().Contains("FATAL:", StringComparison.OrdinalIgnoreCase)
|| process.StandardError.ToString().Contains("FATAL:", StringComparison.OrdinalIgnoreCase))
{
throw new WorkloadException(
"Sysbench reported a fatal error while populating the database.",
ErrorReason.WorkloadUnexpectedAnomaly);
}

this.AddPopulationDurationMetric(sysbenchLoggingArguments, process, telemetryContext, cancellationToken);

state.DatabasePopulated = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void SshClientProxyConstructorsSetPropertiesToExpectedValues()
Assert.IsTrue(object.ReferenceEquals(expectedInfo, client.ConnectionInfo));
Assert.IsTrue(object.ReferenceEquals(expectedInfo, client.SessionClient.ConnectionInfo));
Assert.IsTrue(object.ReferenceEquals(expectedInfo, client.SessionScpClient.ConnectionInfo));
Assert.IsTrue(object.ReferenceEquals(RemotePathTransformation.ShellQuote, client.SessionScpClient.RemotePathTransformation));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/VirtualClient/VirtualClient.Core/SshClientProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public SshClientProxy(ConnectionInfo connectionInfo)
{
connectionInfo.ThrowIfNull(nameof(connectionInfo));
this.SessionClient = new SshClient(connectionInfo);
this.SessionScpClient = new ScpClient(connectionInfo);
this.SessionScpClient = new ScpClient(connectionInfo, RemotePathTransformation.ShellQuote);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
"Parameters": {
"Scenario": "DownloadMySqlServerPackage",
"BlobContainer": "packages",
"BlobName": "mysql-server-8.0.36-v5.zip",
"BlobName": "mysql-server-8.0.46-v1.zip",
"PackageName": "mysql-server",
"Extract": true,
"Role": "Server"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"Parameters": {
"Scenario": "DownloadMySqlServerPackage",
"BlobContainer": "packages",
"BlobName": "mysql-server-8.0.36-v5.zip",
"BlobName": "mysql-server-8.0.46-v1.zip",
"PackageName": "mysql-server",
"Extract": true,
"Role": "Server"
Expand Down
Loading