public void IsMSIEnabled_ReturnsMSIEndpointAndMSIStatus(string msiSecret, string msiEndpoint, bool expectedMsiEnabled) { var hostAssignmentContext = new HostAssignmentContext(); hostAssignmentContext.Environment = new Dictionary <string, string>(); hostAssignmentContext.Environment[EnvironmentSettingNames.MsiSecret] = msiSecret; hostAssignmentContext.Environment[EnvironmentSettingNames.MsiEndpoint] = msiEndpoint; string actualMsiEndpoint; var actualMsiEnabled = hostAssignmentContext.IsMSIEnabled(out actualMsiEndpoint); Assert.Equal(expectedMsiEnabled, actualMsiEnabled); Assert.Equal(msiEndpoint, actualMsiEndpoint); }
public async Task <string> SpecializeMSISidecar(HostAssignmentContext context) { // No cold start optimization needed for side car scenarios if (context.IsWarmupRequest) { return(null); } string endpoint; var msiEnabled = context.IsMSIEnabled(out endpoint); _logger.LogInformation($"MSI enabled status: {msiEnabled}"); if (msiEnabled) { using (_metricsLogger.LatencyEvent(MetricEventNames.LinuxContainerSpecializationMSIInit)) { var uri = new Uri(endpoint); var address = $"http://{uri.Host}:{uri.Port}{ScriptConstants.LinuxMSISpecializationStem}"; _logger.LogDebug($"Specializing sidecar at {address}"); var requestMessage = new HttpRequestMessage(HttpMethod.Post, address) { Content = new StringContent(JsonConvert.SerializeObject(context.MSIContext), Encoding.UTF8, "application/json") }; var response = await _client.SendAsync(requestMessage); _logger.LogInformation($"Specialize MSI sidecar returned {response.StatusCode}"); if (!response.IsSuccessStatusCode) { var message = $"Specialize MSI sidecar call failed. StatusCode={response.StatusCode}"; _logger.LogError(message); return(message); } } } return(null); }