Esempio n. 1
0
        public void Run(string args)
        {
            var stdErrBuilder = new StringBuilder();
            var stdOutBuilder = new StringBuilder();
            var outputBuilder = new StringBuilder();
            var path          = GetExePath();

            var exit = SilentProcessRunner.ExecuteCommand(path,
                                                          args,
                                                          GetCurrentDirectory(),
                                                          output =>
            {
                stdOutBuilder.AppendLine(output);
                outputBuilder.AppendLine(output);
                Trace.WriteLine(output);
            },
                                                          output =>
            {
                stdErrBuilder.AppendLine(output);
                outputBuilder.AppendLine(output);
                Trace.WriteLine(output);
            });

            StdErr   = stdErrBuilder.ToString();
            StdOut   = stdOutBuilder.ToString();
            Output   = outputBuilder.ToString();
            ExitCode = exit;
        }
Esempio n. 2
0
        public void Run(string args)
        {
            var stdErrBuilder = new StringBuilder();
            var stdOutBuilder = new StringBuilder();
            var outputBuilder = new StringBuilder();
            var path          = new Uri(typeof(DeltaBuilder).Assembly.CodeBase).LocalPath;

            var exit = SilentProcessRunner.ExecuteCommand(path,
                                                          args,
                                                          Environment.CurrentDirectory,
                                                          output =>
            {
                stdOutBuilder.AppendLine(output);
                outputBuilder.AppendLine(output);
                Trace.WriteLine(output);
            },
                                                          output =>
            {
                stdErrBuilder.AppendLine(output);
                outputBuilder.AppendLine(output);
                Trace.WriteLine(output);
            });

            StdErr   = stdErrBuilder.ToString();
            StdOut   = stdOutBuilder.ToString();
            Output   = outputBuilder.ToString();
            ExitCode = exit;
        }
Esempio n. 3
0
        public static string BuildSampleVhd(string name, bool twoPartitions = false)
        {
            var packageDirectory = TestEnvironment.GetTestPath("Fixtures", "Deployment", "Packages", name);

            Assert.That(Directory.Exists(packageDirectory), string.Format("Package {0} is not available (expected at {1}).", name, packageDirectory));

            var output  = GetTemporaryDirectory(); //create a new temp dir because later we'll zip it up and we want it to be empty
            var vhdPath = Path.Combine(output, name + ".vhdx");

            if (File.Exists(vhdPath))
            {
                File.Delete(vhdPath);
            }

            using (var scriptFile = new TemporaryFile(Path.GetTempFileName()))
            {
                // create an uninistialized VHD with diskpart
                // can't use New-VHD cmdlet as it requires the Hyper-V service which
                // won't run in EC2
                File.WriteAllText(scriptFile.FilePath, CreateVhdDiskPartScrtipt(vhdPath));
                var exitCode = SilentProcessRunner.ExecuteCommand("diskpart", $"/s {scriptFile.FilePath}", output, Console.WriteLine, Console.Error.WriteLine);
                exitCode.Should().Be(0);
            }

            using (var scriptFile = new TemporaryFile(Path.ChangeExtension(Path.GetTempFileName(), "ps1")))
            {
                File.WriteAllText(scriptFile.FilePath, InitializeAndCopyFilesScript(vhdPath, packageDirectory, twoPartitions));
                var result = ExecuteScript(new PowerShellScriptEngine(), scriptFile.FilePath, new CalamariVariableDictionary());
                result.AssertSuccess();
            }

            return(vhdPath);
        }
Esempio n. 4
0
        protected static void MsBuild(string commandLineArguments, Action <string> outputValidator)
        {
            var netFx   = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
            var msBuild = Path.Combine(netFx, "msbuild.exe");

            if (!File.Exists(msBuild))
            {
                Assert.Fail("Could not find MSBuild at: " + msBuild);
            }

            var allOutput = new StringBuilder();

            Action <string> writer = (output) =>
            {
                allOutput.AppendLine(output);
                Trace.WriteLine(output);
            };

            var result = SilentProcessRunner.ExecuteCommand(msBuild, commandLineArguments, Environment.CurrentDirectory, writer, e => writer("ERROR: " + e));

            if (result != 0)
            {
                Assert.Fail("MSBuild returned a non-zero exit code: " + result);
            }

            if (outputValidator != null)
            {
                outputValidator(allOutput.ToString());
            }
        }
Esempio n. 5
0
 public static Version SafelyGetPowerShellVersion()
 {
     try
     {
         foreach (var cmd in new[] { "powershell.exe", "pwsh.exe" })
         {
             var stdOut   = new StringBuilder();
             var stdError = new StringBuilder();
             var result   = SilentProcessRunner.ExecuteCommand(
                 cmd,
                 $"-command \"{"$PSVersionTable.PSVersion.ToString()"}\"",
                 Environment.CurrentDirectory,
                 s => stdOut.AppendLine(s),
                 s => stdError.AppendLine(s));
             if (result.ExitCode == 0)
             {
                 return(Version.Parse(stdOut.ToString()));
             }
         }
     }
     catch
     {
         //silently ignore it - we dont want to
     }
     return(Version.Parse("0.0.0"));
 }
Esempio n. 6
0
        public static void VerifyExists()
        {
            const string minimumJavaVersion = "1.8";
            var          jarFile            = Path.Combine(ExecutingDirectory, "javatest.jar");

            try
            {
                var silentProcessResult = SilentProcessRunner.ExecuteCommand(CmdPath,
                                                                             $"-jar \"{jarFile}\" {minimumJavaVersion}",
                                                                             ".",
                                                                             Console.WriteLine,
                                                                             i => Console.Error.WriteLine(i));

                if (silentProcessResult.ExitCode == 0)
                {
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            throw new CommandException(
                      $"Failed to run {CmdPath}. You must have Java {minimumJavaVersion} or later installed on the target machine, " +
                      "and have the java executable on the path or have the JAVA_HOME environment variable defined");
        }
        string GetTomcatVersion(CalamariVariableDictionary variables)
        {
            var catalinaHome = variables.Get(SpecialVariables.Action.Java.TomcatDeployCertificate.CatalinaHome) ??
                               Environment.GetEnvironmentVariable("CATALINA_HOME");;
            var catalinaPath = Path.Combine(catalinaHome, "lib", "catalina.jar");

            if (!File.Exists(catalinaPath))
            {
                throw new CommandException("TOMCAT-HTTPS-ERROR-0018: " +
                                           $"Failed to find the file {catalinaPath} " +
                                           "http://g.octopushq.com/JavaAppDeploy#tomcat-https-error-0018");
            }

            var version      = new StringBuilder();
            var versionCheck = SilentProcessRunner.ExecuteCommand(JavaRuntime.CmdPath,
                                                                  $"-cp \"{catalinaPath}\" org.apache.catalina.util.ServerInfo", ".",
                                                                  (stdOut) =>
            {
                Log.Verbose(stdOut);
                version.AppendLine(stdOut);
            },
                                                                  Console.Error.WriteLine);

            if (versionCheck.ExitCode != 0)
            {
                throw new CommandException($"Attempt to obtain tomcat version failed with exit code {versionCheck.ExitCode}.");
            }
            return(version.ToString());
        }
Esempio n. 8
0
        public void Run(string args, OctodiffAppVariant octodiff)
        {
            var stdErrBuilder = new StringBuilder();
            var stdOutBuilder = new StringBuilder();
            var outputBuilder = new StringBuilder();
            var path          = octodiff == OctodiffAppVariant.Sync ?
                                new Uri(typeof(OctodiffProgram).Assembly.CodeBase).LocalPath
                : new Uri(typeof(OctodiffAsyncProgram).Assembly.CodeBase).LocalPath;

            var exit = SilentProcessRunner.ExecuteCommand(path,
                                                          args,
                                                          TestContext.CurrentContext.TestDirectory,
                                                          output =>
            {
                stdOutBuilder.AppendLine(output);
                outputBuilder.AppendLine(output);
                Trace.WriteLine(output);
            },
                                                          output =>
            {
                stdErrBuilder.AppendLine(output);
                outputBuilder.AppendLine(output);
                Trace.WriteLine(output);
            });

            StdErr   = stdErrBuilder.ToString();
            StdOut   = stdOutBuilder.ToString();
            Output   = outputBuilder.ToString();
            ExitCode = exit;
        }
Esempio n. 9
0
        string RunTerraformInternal(string terraformWorkingFolder, Dictionary <string, string> env, bool printOut, params string[] args)
        {
            var sb = new StringBuilder();
            var environmentVars = GetEnvironmentVars();

            environmentVars["TF_IN_AUTOMATION"] = bool.TrueString;
            environmentVars.AddRange(env);

            var result = SilentProcessRunner.ExecuteCommand(installTools.TerraformExecutable,
                                                            string.Join(" ", args.Concat(new[] { "-no-color" })),
                                                            terraformWorkingFolder,
                                                            environmentVars,
                                                            s =>
            {
                sb.AppendLine(s);
                if (printOut)
                {
                    TestContext.Progress.WriteLine(s);
                }
            },
                                                            e =>
            {
                TestContext.Error.WriteLine(e);
            });

            result.ExitCode.Should().Be(0);

            return(sb.ToString().Trim(Environment.NewLine.ToCharArray()));
        }
Esempio n. 10
0
        protected static void MsBuild(string commandLineArguments, Action <string> outputValidator)
        {
            var vsMsBuild = VsMsBuildPaths().FirstOrDefault(path => File.Exists(path));

            var msBuild = vsMsBuild != null ? vsMsBuild : FrameworkMsbuild();

            if (!File.Exists(msBuild))
            {
                Assert.Fail("Could not find MSBuild at: " + msBuild);
            }

            var allOutput = new StringBuilder();

            Action <string> writer = (output) =>
            {
                allOutput.AppendLine(output);
                Console.WriteLine(output);
            };

            var result = SilentProcessRunner.ExecuteCommand(msBuild, commandLineArguments, Environment.CurrentDirectory, writer, e => writer("ERROR: " + e));

            if (result != 0)
            {
                Assert.Fail("MSBuild returned a non-zero exit code: " + result);
            }

            if (outputValidator != null)
            {
                outputValidator(allOutput.ToString());
            }
        }
 static void RemoveCachedImage(string image, string tag)
 {
     SilentProcessRunner.ExecuteCommand("docker",
                                        $"rmi {image}:{tag}",
                                        ".",
                                        new Dictionary <string, string>(),
                                        (output) => { },
                                        (error) => { });
 }
Esempio n. 12
0
        static HelmVersion GetVersion()
        {
            StringBuilder stdout = new StringBuilder();
            var           result = SilentProcessRunner.ExecuteCommand("helm", "version --client --short", Environment.CurrentDirectory, output => stdout.AppendLine(output), error => { });

            result.ExitCode.Should().Be(0, $"Failed to retrieve version from Helm (Exit code {result.ExitCode}). Error output: \r\n{result.ErrorOutput}");

            return(ParseVersion(stdout.ToString()));
        }
 public RequiresDockerInstalledAttribute()
 {
     isDockerInstalled = new Lazy <bool>(() =>
     {
         try
         {
             var result =
                 SilentProcessRunner.ExecuteCommand("docker", "ps -q", ".", (stdOut) => { }, (stdErr) => { });
             return(result.ExitCode == 0);
         }
         catch (Exception)
         {
             return(false);
         }
     });
 }
Esempio n. 14
0
        protected static void MsBuild(string commandLineArguments, Action <string> outputValidator = null, Dictionary <string, string> environmentVariables = null)
        {
            var msBuild   = GetMsBuildPath();
            var allOutput = new StringBuilder();

            Action <string> writer = (output) =>
            {
                allOutput.AppendLine(output);
                Console.WriteLine(output);
            };

            var result = SilentProcessRunner.ExecuteCommand(msBuild, commandLineArguments, Environment.CurrentDirectory, writer, e => writer("ERROR: " + e), environmentVariables);

            if (result != 0)
            {
                Assert.Fail("MSBuild returned a non-zero exit code: " + result);
            }

            outputValidator?.Invoke(allOutput.ToString());
        }
        void CheckHelmToolVersion(string customHelmExecutable, HelmVersion selectedVersion)
        {
            log.Verbose($"Helm version selected: {selectedVersion}");

            StringBuilder stdout = new StringBuilder();
            var           result = SilentProcessRunner.ExecuteCommand(customHelmExecutable ?? "helm", "version --client --short", Environment.CurrentDirectory, output => stdout.Append(output), error => { });

            if (result.ExitCode != 0)
            {
                log.Warn("Unable to retrieve the Helm tool version");
            }

            var toolVersion = HelmVersionParser.ParseVersion(stdout.ToString());

            if (!toolVersion.HasValue)
            {
                log.Warn("Unable to parse the Helm tool version text: " + stdout);
            }

            if (toolVersion.Value != selectedVersion)
            {
                log.Warn($"The Helm tool version '{toolVersion.Value}' ('{stdout}') doesn't match the Helm version selected '{selectedVersion}'");
            }
        }
Esempio n. 16
0
 private void ExecuteGitCommand(string command)
 {
     SilentProcessRunner.ExecuteCommand(_gitExecutable, command, _directory, o => _output.Info(o), e => _output.Error(e));
 }