mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-21 13:51:19 +00:00
Pool operations test hooks (#1909)
Co-authored-by: stas <statis@microsoft.com>
This commit is contained in:
@ -494,19 +494,19 @@ public record ReproConfig(
|
||||
|
||||
// Skipping AutoScaleConfig because it's not used anymore
|
||||
public record Pool(
|
||||
DateTimeOffset Timestamp,
|
||||
PoolName Name,
|
||||
Guid PoolId,
|
||||
[PartitionKey] PoolName Name,
|
||||
[RowKey] Guid PoolId,
|
||||
Os Os,
|
||||
bool Managed,
|
||||
Architecture Architecture,
|
||||
Architecture Arch,
|
||||
PoolState State,
|
||||
Guid? ClientId,
|
||||
List<Node>? Nodes,
|
||||
AgentConfig? Config,
|
||||
List<WorkSetSummary>? WorkQueue,
|
||||
List<ScalesetSummary>? ScalesetSummary
|
||||
) : StatefulEntityBase<PoolState>(State);
|
||||
Guid? ClientId
|
||||
) : StatefulEntityBase<PoolState>(State) {
|
||||
public List<Node>? Nodes { get; set; }
|
||||
public AgentConfig? Config { get; set; }
|
||||
public List<WorkSetSummary>? WorkQueue { get; set; }
|
||||
public List<ScalesetSummary>? ScalesetSummary { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public record ClientCredentials
|
||||
|
@ -8,8 +8,7 @@
|
||||
readonly bool isOk;
|
||||
|
||||
public ResultVoid() => (error, isOk) = (default, true);
|
||||
|
||||
public ResultVoid(T_Error error) => (this.error, isOk) = (error, false);
|
||||
private ResultVoid(T_Error error) => (this.error, isOk) = (error, false);
|
||||
|
||||
public bool IsOk => isOk;
|
||||
|
||||
@ -25,9 +24,9 @@
|
||||
readonly T_Error? error;
|
||||
readonly bool isOk;
|
||||
|
||||
public Result(T_Ok ok) => (this.ok, error, isOk) = (ok, default, true);
|
||||
private Result(T_Ok ok) => (this.ok, error, isOk) = (ok, default, true);
|
||||
|
||||
public Result(T_Error error) => (this.error, ok, isOk) = (error, default, false);
|
||||
private Result(T_Error error) => (this.error, ok, isOk) = (error, default, false);
|
||||
|
||||
public bool IsOk => isOk;
|
||||
|
||||
|
@ -30,6 +30,18 @@ namespace ApiService.TestHooks {
|
||||
var resp = req.CreateResponse(HttpStatusCode.OK);
|
||||
return resp;
|
||||
}
|
||||
|
||||
|
||||
[Function("SendEventTestHook")]
|
||||
public async Task<HttpResponseData> SendEvent([HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "testhooks/events/sendEvent")] HttpRequestData req) {
|
||||
_log.Info("Send event");
|
||||
|
||||
var s = await req.ReadAsStringAsync();
|
||||
var msg = JsonSerializer.Deserialize<EventMessage>(s!, EntityConverter.GetJsonSerializerOptions());
|
||||
await _events.SendEvent(msg!.Event);
|
||||
var resp = req.CreateResponse(HttpStatusCode.OK);
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
using System.Net;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Azure.Functions.Worker;
|
||||
using Microsoft.Azure.Functions.Worker.Http;
|
||||
using Microsoft.OneFuzz.Service;
|
||||
using Microsoft.OneFuzz.Service.OneFuzzLib.Orm;
|
||||
|
||||
#if DEBUG
|
||||
namespace ApiService.TestHooks {
|
||||
public class PoolOperationsTestHooks {
|
||||
private readonly ILogTracer _log;
|
||||
private readonly IConfigOperations _configOps;
|
||||
private readonly IPoolOperations _poolOps;
|
||||
|
||||
public PoolOperationsTestHooks(ILogTracer log, IConfigOperations configOps, IPoolOperations poolOps) {
|
||||
_log = log.WithTag("TestHooks", nameof(PoolOperationsTestHooks));
|
||||
_configOps = configOps; ;
|
||||
_poolOps = poolOps;
|
||||
}
|
||||
|
||||
|
||||
[Function("GetPoolTestHook")]
|
||||
public async Task<HttpResponseData> GetNsg([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "testhooks/poolOperations/pool")] HttpRequestData req) {
|
||||
_log.Info("get pool");
|
||||
|
||||
var query = UriExtension.GetQueryComponents(req.Url);
|
||||
var poolRes = await _poolOps.GetByName(query["name"]);
|
||||
|
||||
if (poolRes.IsOk) {
|
||||
var resp = req.CreateResponse(HttpStatusCode.OK);
|
||||
var data = poolRes.OkV;
|
||||
var msg = JsonSerializer.Serialize(data, EntityConverter.GetJsonSerializerOptions());
|
||||
await resp.WriteStringAsync(msg);
|
||||
return resp;
|
||||
} else {
|
||||
var resp = req.CreateResponse(HttpStatusCode.BadRequest);
|
||||
var msg = JsonSerializer.Serialize(poolRes.ErrorV, EntityConverter.GetJsonSerializerOptions());
|
||||
await resp.WriteStringAsync(msg);
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@ -4,7 +4,7 @@ using ApiService.OneFuzzLib.Orm;
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
|
||||
public interface IPoolOperations {
|
||||
public Async.Task<Result<Pool, Error>> GetByName(string poolName);
|
||||
public Async.Task<OneFuzzResult<Pool>> GetByName(string poolName);
|
||||
Task<bool> ScheduleWorkset(Pool pool, WorkSet workSet);
|
||||
}
|
||||
|
||||
@ -15,18 +15,18 @@ public class PoolOperations : StatefulOrm<Pool, PoolState>, IPoolOperations {
|
||||
|
||||
}
|
||||
|
||||
public async Async.Task<Result<Pool, Error>> GetByName(string poolName) {
|
||||
var pools = QueryAsync(filter: $"name eq '{poolName}'");
|
||||
public async Async.Task<OneFuzzResult<Pool>> GetByName(string poolName) {
|
||||
var pools = QueryAsync(filter: $"PartitionKey eq '{poolName}'");
|
||||
|
||||
if (pools == null) {
|
||||
return new Result<Pool, Error>(new Error(ErrorCode.INVALID_REQUEST, new[] { "unable to find pool" }));
|
||||
if (pools == null || await pools.CountAsync() == 0) {
|
||||
return OneFuzzResult<Pool>.Error(ErrorCode.INVALID_REQUEST, "unable to find pool");
|
||||
}
|
||||
|
||||
if (await pools.CountAsync() != 1) {
|
||||
return new Result<Pool, Error>(new Error(ErrorCode.INVALID_REQUEST, new[] { "error identifying pool" }));
|
||||
return OneFuzzResult<Pool>.Error(ErrorCode.INVALID_REQUEST, "error identifying pool");
|
||||
}
|
||||
|
||||
return new Result<Pool, Error>(await pools.SingleAsync());
|
||||
return OneFuzzResult<Pool>.Ok(await pools.SingleAsync());
|
||||
}
|
||||
|
||||
public async Task<bool> ScheduleWorkset(Pool pool, WorkSet workSet) {
|
||||
|
Reference in New Issue
Block a user