mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-12 18:18:08 +00:00
fix linux proxy extensions provisioning failures (#2401)
* fix linux proxy extensions provisioning failures * format Co-authored-by: stas <statis@microsoft.com>
This commit is contained in:
@ -121,7 +121,7 @@ public class Extensions : IExtensions {
|
|||||||
public static VMExtensionWrapper AzSecExtension(AzureLocation region) {
|
public static VMExtensionWrapper AzSecExtension(AzureLocation region) {
|
||||||
return new VMExtensionWrapper {
|
return new VMExtensionWrapper {
|
||||||
Location = region,
|
Location = region,
|
||||||
Name = "AzureSecurityLinuxAgent",
|
Name = "Microsoft.Azure.Security.Monitoring.AzureSecurityLinuxAgent",
|
||||||
Publisher = "Microsoft.Azure.Security.Monitoring",
|
Publisher = "Microsoft.Azure.Security.Monitoring",
|
||||||
TypePropertiesType = "AzureSecurityLinuxAgent",
|
TypePropertiesType = "AzureSecurityLinuxAgent",
|
||||||
TypeHandlerVersion = "2.0",
|
TypeHandlerVersion = "2.0",
|
||||||
@ -147,7 +147,7 @@ public class Extensions : IExtensions {
|
|||||||
|
|
||||||
return new VMExtensionWrapper {
|
return new VMExtensionWrapper {
|
||||||
Location = region,
|
Location = region,
|
||||||
Name = "AzureMonitorLinuxAgent",
|
Name = "Microsoft.Azure.Monitor.AzureMonitorLinuxAgent",
|
||||||
Publisher = "Microsoft.Azure.Monitor",
|
Publisher = "Microsoft.Azure.Monitor",
|
||||||
TypePropertiesType = "AzureMonitorLinuxAgent",
|
TypePropertiesType = "AzureMonitorLinuxAgent",
|
||||||
AutoUpgradeMinorVersion = true,
|
AutoUpgradeMinorVersion = true,
|
||||||
|
@ -81,12 +81,12 @@ public class ProxyOperations : StatefulOrm<Proxy, VmState, ProxyOperations>, IPr
|
|||||||
public bool IsAlive(Proxy proxy) {
|
public bool IsAlive(Proxy proxy) {
|
||||||
var tenMinutesAgo = DateTimeOffset.UtcNow - TimeSpan.FromMinutes(10);
|
var tenMinutesAgo = DateTimeOffset.UtcNow - TimeSpan.FromMinutes(10);
|
||||||
|
|
||||||
if (proxy.Heartbeat != null && proxy.Heartbeat.TimeStamp < tenMinutesAgo) {
|
if (proxy.Heartbeat is not null && proxy.Heartbeat.TimeStamp < tenMinutesAgo) {
|
||||||
_logTracer.Info($"last heartbeat is more than an 10 minutes old: {proxy.Region} - last heartbeat:{proxy.Heartbeat} compared_to:{tenMinutesAgo}");
|
_logTracer.Info($"last heartbeat is more than an 10 minutes old: {proxy.Region} - last heartbeat:{proxy.Heartbeat} compared_to:{tenMinutesAgo}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxy.Heartbeat != null && proxy.TimeStamp != null && proxy.TimeStamp < tenMinutesAgo) {
|
if (proxy.Heartbeat is not null && proxy.TimeStamp is not null && proxy.TimeStamp < tenMinutesAgo) {
|
||||||
_logTracer.Error($"no heartbeat in the last 10 minutes: {proxy.Region} timestamp: {proxy.TimeStamp} compared_to:{tenMinutesAgo}");
|
_logTracer.Error($"no heartbeat in the last 10 minutes: {proxy.Region} timestamp: {proxy.TimeStamp} compared_to:{tenMinutesAgo}");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -104,7 +104,7 @@ public class ProxyOperations : StatefulOrm<Proxy, VmState, ProxyOperations>, IPr
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxy.CreatedTimestamp != null) {
|
if (proxy.CreatedTimestamp is not null) {
|
||||||
if (proxy.CreatedTimestamp < (DateTimeOffset.UtcNow - PROXY_LIFESPAN)) {
|
if (proxy.CreatedTimestamp < (DateTimeOffset.UtcNow - PROXY_LIFESPAN)) {
|
||||||
_logTracer.Info($"proxy older than 7 days:proxy-created:{proxy.CreatedTimestamp} state:{proxy.State}");
|
_logTracer.Info($"proxy older than 7 days:proxy-created:{proxy.CreatedTimestamp} state:{proxy.State}");
|
||||||
return true;
|
return true;
|
||||||
@ -205,7 +205,7 @@ public class ProxyOperations : StatefulOrm<Proxy, VmState, ProxyOperations>, IPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async Task<Proxy> SetFailed(Proxy proxy, Error error) {
|
private async Task<Proxy> SetFailed(Proxy proxy, Error error) {
|
||||||
if (proxy.Error != null) {
|
if (proxy.Error is not null) {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,9 +231,9 @@ public class ProxyOperations : StatefulOrm<Proxy, VmState, ProxyOperations>, IPr
|
|||||||
|
|
||||||
public static Vm GetVm(Proxy proxy, InstanceConfig config) {
|
public static Vm GetVm(Proxy proxy, InstanceConfig config) {
|
||||||
var tags = config.VmssTags;
|
var tags = config.VmssTags;
|
||||||
var proxyVmSku = "";
|
string proxyVmSku;
|
||||||
const string PROXY_IMAGE = "Canonical:UbuntuServer:18.04-LTS:latest";
|
const string PROXY_IMAGE = "Canonical:UbuntuServer:18.04-LTS:latest";
|
||||||
if (config.ProxyVmSku == null) {
|
if (config.ProxyVmSku is null) {
|
||||||
proxyVmSku = "Standard_B2s";
|
proxyVmSku = "Standard_B2s";
|
||||||
} else {
|
} else {
|
||||||
proxyVmSku = config.ProxyVmSku;
|
proxyVmSku = config.ProxyVmSku;
|
||||||
@ -255,7 +255,7 @@ public class ProxyOperations : StatefulOrm<Proxy, VmState, ProxyOperations>, IPr
|
|||||||
var vm = GetVm(proxy, config);
|
var vm = GetVm(proxy, config);
|
||||||
var vmData = await _context.VmOperations.GetVm(vm.Name);
|
var vmData = await _context.VmOperations.GetVm(vm.Name);
|
||||||
|
|
||||||
if (vmData == null) {
|
if (vmData is null) {
|
||||||
return await SetFailed(proxy, new Error(ErrorCode.PROXY_FAILED, new[] { "azure not able to find vm" }));
|
return await SetFailed(proxy, new Error(ErrorCode.PROXY_FAILED, new[] { "azure not able to find vm" }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -264,7 +264,7 @@ public class ProxyOperations : StatefulOrm<Proxy, VmState, ProxyOperations>, IPr
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ip = await _context.IpOperations.GetPublicIp(vmData.NetworkProfile.NetworkInterfaces[0].Id);
|
var ip = await _context.IpOperations.GetPublicIp(vmData.NetworkProfile.NetworkInterfaces[0].Id);
|
||||||
if (ip == null) {
|
if (ip is null) {
|
||||||
return proxy;
|
return proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user