コード例 #1
0
        public static string SaveVolumes(string simulationId, TemplateData template)
        {
            Console.WriteLine($"[TC] Saving volumes for simulationId:{simulationId}");

            var volumePath = GetSimulationVolumesPath(simulationId);

            if (!Directory.Exists(volumePath))
            {
                Directory.CreateDirectory(volumePath);
            }

            foreach (var parameter in template.Parameters)
            {
                if (parameter.VariableType == "volume")
                {
                    Console.WriteLine($"[TC] Saving volume {parameter.Alias} '{parameter.ParameterName}' as '{parameter.VariableName}'");
                    var targetFilePath = Path.Combine(volumePath, parameter.VariableName);

                    using (FileStream fs = File.Create(targetFilePath))
                    {
                        byte[] content = new UTF8Encoding(true).GetBytes(parameter.GetValue <string>());
                        fs.Write(content, 0, content.Length);
                    }
                }
            }

            return(volumePath);
        }
コード例 #2
0
        public static void UpdateTestCaseEnvironment(TemplateData template, IDictionary <string, string> environment)
        {
            // Important note: Variable names are subject of further updates.
            ExtractEnvironmentVariables(template, environment);

            environment.Add("SIMULATOR_TC_RUNTIME", template.Alias);

            if (!environment.ContainsKey("LGSVL__SIMULATOR_HOST"))
            {
                var hostname = Config.ApiHost == "*" ? "localhost" : Config.ApiHost;
                environment.Add("SIMULATOR_HOST", hostname);
                environment.Add("LGSVL__SIMULATOR_HOST", hostname);
            }

            if (!environment.ContainsKey("LGSVL__SIMULATOR_PORT"))
            {
                environment.Add("SIMULATOR_PORT", Config.ApiPort.ToString());
                environment.Add("LGSVL__SIMULATOR_PORT", Config.ApiPort.ToString());
            }
        }
コード例 #3
0
 static public bool IsInternalTemplate(TemplateData template)
 {
     return(template.Alias == InternalTemplateAliases.API_ONLY || template.Alias == InternalTemplateAliases.RANDOM_TRAFFIC);
 }
コード例 #4
0
 public static void ExtractEnvironmentVariables(
     TemplateData template,
     IDictionary <string, string> environment)
 {
     foreach (var parameter in template.Parameters)
     {
         if (parameter.VariableType == "env")
         {
             if (parameter.ParameterType == "boolean")
             {
                 // Special case for bool -> 1/0
                 environment.Add(parameter.VariableName, parameter.GetValue <bool>() ? "1" : "0");
             }
             else if (parameter.ParameterType == "map")
             {
                 environment.Add(parameter.VariableName, parameter.GetValue <MapData>().Id);
             }
             else if (parameter.ParameterType == "vehicles")
             {
                 var i = 0;
                 foreach (var vehicle in parameter.GetValue <VehicleData[]>())
                 {
                     environment.Add($"LGSVL__VEHICLE_{i}", vehicle.Id);
                     if (vehicle.Bridge != null && !String.IsNullOrEmpty(vehicle.Bridge.ConnectionString))
                     {
                         var parts = vehicle.Bridge.ConnectionString.Split(':');
                         // ipv6 not supported - ipv6 has many : in the address part so its harder to find the port
                         // unfortunately we do not have IPEndpoint.TryParse in .net core 2
                         if (parts.Length == 1)
                         {
                             if (i == 0)
                             {
                                 environment.Add("BRIDGE_HOST", vehicle.Bridge.ConnectionString); // legacy - vse_runner.py only supports one vehicle right now
                             }
                             environment.Add($"LGSVL__AUTOPILOT_{i}_HOST", vehicle.Bridge.ConnectionString);
                         }
                         else if (parts.Length == 2)
                         {
                             if (i == 0)
                             {
                                 environment.Add("BRIDGE_HOST", parts[0]); // legacy
                                 environment.Add("BRIDGE_PORT", parts[1]); // legacy
                             }
                             environment.Add($"LGSVL__AUTOPILOT_{i}_HOST", parts[0]);
                             environment.Add($"LGSVL__AUTOPILOT_{i}_PORT", parts[1]);
                         }
                         else
                         {
                             Debug.LogWarning("malformed ipv4 connection string: " + vehicle.Bridge.ConnectionString);
                         }
                     }
                     i++;
                 }
             }
             else
             {
                 environment.Add(parameter.VariableName, parameter.GetValue <string>());
             }
         }
     }
 }