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

Added Test for Reload #265

Merged
merged 29 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
617491a
Added Test for Reload
sammychinedu2ky Nov 2, 2023
56be74f
style: fix whitespaces
octocat Nov 2, 2023
77e1359
edit
sammychinedu2ky Nov 2, 2023
f36989a
fix
sammychinedu2ky Nov 3, 2023
e8c24e7
fix
sammychinedu2ky Nov 3, 2023
8bef4df
style: fix whitespaces
octocat Nov 3, 2023
7ebc45e
fixed
sammychinedu2ky Nov 3, 2023
afb77a4
Update Consul.Test/AgentTest.cs
sammychinedu2ky Nov 3, 2023
ef7b3cd
Update Consul.Test/AgentTest.cs
sammychinedu2ky Nov 3, 2023
e948eb5
style: fix whitespaces
octocat Nov 3, 2023
69bf013
added changes
sammychinedu2ky Nov 3, 2023
5990d46
Merge branch 'master' into agentreload
sammychinedu2ky Nov 3, 2023
1a103f7
testing env
sammychinedu2ky Nov 6, 2023
1283946
Merge branch 'agentreload' of https://github.com/sammychinedu2ky/cons…
sammychinedu2ky Nov 6, 2023
10d55cd
testing env
sammychinedu2ky Nov 6, 2023
7d3bbf9
testing env
sammychinedu2ky Nov 6, 2023
98ccbad
test env
sammychinedu2ky Nov 6, 2023
55d7e57
test env
sammychinedu2ky Nov 6, 2023
3724680
test env
sammychinedu2ky Nov 6, 2023
0d0ce5f
test env
sammychinedu2ky Nov 6, 2023
a6a5f05
test env
sammychinedu2ky Nov 6, 2023
27a5f29
testing env
sammychinedu2ky Nov 6, 2023
ec545b7
testing env
sammychinedu2ky Nov 6, 2023
b1c600d
testing env
sammychinedu2ky Nov 6, 2023
99148ba
testing env
sammychinedu2ky Nov 6, 2023
aa0e3e9
changed github workflow
sammychinedu2ky Nov 6, 2023
51afe8f
Merge branch 'master' into agentreload
sammychinedu2ky Nov 29, 2023
38bb8b2
added extra skippable
sammychinedu2ky Nov 29, 2023
3d98503
edit
sammychinedu2ky Nov 29, 2023
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
env:
RUN_CONSUL_ENTERPRISE_TESTS: ${{env.RUN_CONSUL_ENTERPRISE_TESTS }}
CONSUL_LICENSE: ${{ secrets.CONSUL_LICENSE }}
CONSUL_AGENT_CONFIG_PATH: ${{ github.workspace }}/Consul.Test/test_config.json
- name: Upload Consul logs
if: failure()
uses: actions/upload-artifact@v3
Expand Down
37 changes: 33 additions & 4 deletions Consul.Test/AgentTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// -----------------------------------------------------------------------
// <copyright file="AgentTest.cs" company="PlayFab Inc">
// Copyright 2015 PlayFab Inc.
// <copyright file="AgentTest.cs" company="G-Research Limited">
// Copyright 2020 G-Research Limited
//
// Licensed under the Apache License, Version 2.0 (the "License");
// Licensed under the Apache License, Version 2.0 (the "License"),
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -1014,5 +1013,35 @@ public async Task Agent_Metrics()
Assert.NotNull(agentMetrics.Response.Points);
Assert.NotNull(agentMetrics.Response.Samples);
}

[SkippableFact]
public async Task Agent_Reload()
{
var cutOffVersion = SemanticVersion.Parse("1.14.0");
Skip.If(AgentVersion < cutOffVersion, $"Current version is {AgentVersion}, but `Agent_Reload` is only supported from Consul {cutOffVersion}");
string configFile = Environment.GetEnvironmentVariable("CONSUL_AGENT_CONFIG_PATH");
Skip.If(string.IsNullOrEmpty(configFile), "The CONSUL_AGENT_CONFIG_PATH environment variable was not set");
var initialConfig = System.IO.File.ReadAllText(configFile);
var udpatedConfig = initialConfig.Replace("TRACE", "DEBUG");
try
{
var agentDetails = await _client.Agent.Self();
var agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"];
Assert.Equal("TRACE", agentLogLevel.Value);
System.IO.File.WriteAllText(configFile, udpatedConfig);

await _client.Agent.Reload();
agentDetails = await _client.Agent.Self();
agentLogLevel = agentDetails.Response["DebugConfig"]["Logging"]["LogLevel"];
Assert.Equal("DEBUG", agentLogLevel.Value);

System.IO.File.WriteAllText(configFile, initialConfig);
await _client.Agent.Reload();
}
finally
{
System.IO.File.WriteAllText(configFile, initialConfig);
}
}
}
}
2 changes: 1 addition & 1 deletion Consul.Test/Consul.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;net5.0;net6.0;net7.0</TargetFrameworks>
Expand Down
11 changes: 11 additions & 0 deletions Consul/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,17 @@ public Task<WriteResult> Leave(string node, CancellationToken ct = default)
/// Reload triggers a configuration reload for the agent we are connected to.
/// </summary>
/// <returns>An empty write result</returns>
public Task<WriteResult> Reload(CancellationToken ct = default)
{
return _client.PutNothing("/v1/agent/reload").Execute(ct);
}

/// <summary>
/// Reload triggers a configuration reload for the agent we are connected to.
/// </summary>
/// <param name="node">The node name to reload</param>
/// <returns>An empty write result</returns>
[Obsolete]
public Task<WriteResult> Reload(string node, CancellationToken ct = default)
{
return _client.PutNothing("/v1/agent/reload").Execute(ct);
Expand Down
4 changes: 3 additions & 1 deletion Consul/Interfaces/IAgentEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ public interface IAgentEndpoint
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, QueryOptions q, CancellationToken ct = default);
Task<QueryResult<LocalServiceHealth>> GetLocalServiceHealthByID(string serviceID, CancellationToken ct = default);
Task<QueryResult<Metrics>> GetAgentMetrics(CancellationToken ct = default);
Task<WriteResult> Reload(CancellationToken ct = default);
[Obsolete]
Task<WriteResult> Reload(string node, CancellationToken ct = default);
Task<QueryResult<AgentHostInfo>> GetAgentHostInfo(CancellationToken ct = default);
Task<WriteResult> Leave(string node, CancellationToken ct = default);
Task<WriteResult> Reload(string node, CancellationToken ct = default);
sammychinedu2ky marked this conversation as resolved.
Show resolved Hide resolved
}
}