|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Diagnostics; |
| 4 | +using System.Linq; |
| 5 | +using System.Threading.Tasks; |
| 6 | +using Flurl.Http; |
| 7 | +using Xunit; |
| 8 | +using Xunit.Abstractions; |
| 9 | +using VolumeState = net.openstack.Core.Domain.VolumeState; |
| 10 | + |
| 11 | +namespace OpenStack.Compute.v2_1.Operator |
| 12 | +{ |
| 13 | + public class ServerTests : IDisposable |
| 14 | + { |
| 15 | + private readonly ComputeService _compute; |
| 16 | + private readonly ComputeTestDataManager _testData; |
| 17 | + |
| 18 | + public ServerTests(ITestOutputHelper testLog) |
| 19 | + { |
| 20 | + var testOutput = new XunitTraceListener(testLog); |
| 21 | + Trace.Listeners.Add(testOutput); |
| 22 | + OpenStackNet.Tracing.Http.Listeners.Add(testOutput); |
| 23 | + |
| 24 | + var authenticationProvider = TestIdentityProvider.GetOperatorIdentity(); |
| 25 | + _compute = new ComputeService(authenticationProvider, "RegionOne"); |
| 26 | + |
| 27 | + _testData = new ComputeTestDataManager(_compute); |
| 28 | + } |
| 29 | + |
| 30 | + public void Dispose() |
| 31 | + { |
| 32 | + Trace.Listeners.Clear(); |
| 33 | + OpenStackNet.Tracing.Http.Listeners.Clear(); |
| 34 | + |
| 35 | + _testData.Dispose(); |
| 36 | + } |
| 37 | + |
| 38 | + [Fact] |
| 39 | + public async Task EvacuateServerTest() |
| 40 | + { |
| 41 | + var server = await _testData.CreateServer(); |
| 42 | + await server.WaitUntilActiveAsync(); |
| 43 | + Trace.WriteLine($"Created server named: {server.Name}"); |
| 44 | + |
| 45 | + Trace.WriteLine("Evacuating the server to a new host..."); |
| 46 | + var request = new EvacuateServerRequest(false) |
| 47 | + { |
| 48 | + AdminPassword = "top-secret-password" |
| 49 | + }; |
| 50 | + |
| 51 | + // Our service isn't down, so we can't really evacuate. |
| 52 | + // Just check that the request would have gone through (i.e. was valid) |
| 53 | + // and only was rejected because the compute service is healthy |
| 54 | + try |
| 55 | + { |
| 56 | + await server.EvacuateAsync(request); |
| 57 | + } |
| 58 | + catch (FlurlHttpException httpError) when (httpError.Call.ErrorResponseBody.Contains("is still in use")) |
| 59 | + { |
| 60 | + // Hurray! the test passed |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments