public void Test_SetCredentialsFromWeb()
        {
            MoveToTemporaryDirectory();

            Console.WriteLine("");
            Console.WriteLine("Preparing set GreenSense credentials from web test...");
            Console.WriteLine("");

            var scriptName = "set-credentials-from-web.sh";

            PullFileFromProject("scripts-web/" + scriptName, true);

            var scriptPath = Path.GetFullPath(scriptName);

            var branchDetector = new BranchDetector();
            var branch         = branchDetector.Branch;

            var installDir = Path.GetFullPath("installation");

            var random = new Random();

            var wifiName = "MyWifi" + random.Next(99);
            var wifiPass = "******" + random.Next(99);

            var mqttHost = "10.0.0." + random.Next(99);
            var mqttUser = "******" + random.Next(99);
            var mqttPass = "******" + random.Next(99);
            var mqttPort = "18" + random.Next(99);

            var cmd = "bash " + scriptPath + " " + branch + " " + installDir + " " + wifiName + " " + wifiPass + " " + mqttHost + " " + mqttUser + " " + mqttPass + " " + mqttPort;

            Console.WriteLine("Command:");
            Console.WriteLine("  " + cmd);

            EnableMocking(installDir, "systemctl");
            EnableMocking(installDir, "mqtt-bridge");

            var starter = new ProcessStarter();

            Console.WriteLine("");
            Console.WriteLine("Performing test...");
            Console.WriteLine("");

            starter.Start(cmd);

            Console.Write(starter.Output);

            Assert.IsFalse(starter.IsError, "An error occurred.");

            AssertSecurityFile(installDir, "mqtt-host", mqttHost);
            AssertSecurityFile(installDir, "mqtt-username", mqttUser);
            AssertSecurityFile(installDir, "mqtt-password", mqttPass);
            AssertSecurityFile(installDir, "mqtt-port", mqttPort);
        }
        public void Test_AddRemoteIndexFromWeb()
        {
            MoveToTemporaryDirectory();

            Console.WriteLine("");
            Console.WriteLine("Preparing add remote index from web test...");
            Console.WriteLine("");

            var scriptName = "add-remote-index-from-web.sh";

            PullFileFromProject("scripts-web/" + scriptName, true);

            var scriptPath = Path.GetFullPath(scriptName);

            var branchDetector = new BranchDetector();
            var branch         = branchDetector.Branch;

            var installDir = Path.Combine(TemporaryDirectory, "installation");

            Directory.CreateDirectory(installDir);

            Directory.SetCurrentDirectory(installDir);

            PullFileFromProject("add-remote-index.sh");

            var random     = new Random();
            var remoteName = "remote" + random.Next(9);
            var remoteHost = "10.0.0." + random.Next(99);
            var remoteUser = "******" + random.Next(99);
            var remotePass = "******" + random.Next(99);

            var cmd = "bash " + scriptPath + " " + branch + " " + installDir + " " + remoteName + " " + remoteHost + " " + remoteUser + " " + remotePass;

            Console.WriteLine("Command:");
            Console.WriteLine("  " + cmd);

            var starter = new ProcessStarter();

            Console.WriteLine("");
            Console.WriteLine("Performing test...");
            Console.WriteLine("");

            starter.Start(cmd);

            Console.Write(starter.Output);

            Assert.IsFalse(starter.IsError, "An error occurred.");

            AssertRemoteIndexFile(installDir, remoteName, "host", remoteHost);
            AssertRemoteIndexFile(installDir, remoteName, "username", remoteUser);
            AssertRemoteIndexFile(installDir, remoteName, "password", remotePass);
        }
Beispiel #3
0
        public void Test_Upgrade()
        {
            MoveToTemporaryDirectory();

            Console.WriteLine("");
            Console.WriteLine("Preparing upgrade test...");
            Console.WriteLine("");

            var installDir    = Path.GetFullPath("GreenSense/Index");
            var pnpInstallDir = Path.GetFullPath("ArduinoPlugAndPlay");

            var branchDetector = new BranchDetector();
            var branch         = branchDetector.Branch;


            PrepareGreenSenseInstallation(branch, installDir, pnpInstallDir);

            Directory.SetCurrentDirectory(installDir);

            PullFileFromProject("upgrade.sh", true);

            var scriptPath = Path.GetFullPath("upgrade.sh");
            var cmd        = "bash " + scriptPath;

            Console.WriteLine("Command:");
            Console.WriteLine("  " + cmd);

            var starter = new ProcessStarter();

            Console.WriteLine("");
            Console.WriteLine("Performing upgrade test...");
            Console.WriteLine("");

            starter.Start(cmd);

            Console.Write(starter.Output);

            Assert.IsFalse(starter.IsError, "An error occurred.");

            Console.WriteLine("Checking that the ArduinoPlugAndPlay service file was installed.");
            var expectedServiceFile = Path.Combine(pnpInstallDir, "mock/services/arduino-plug-and-play.service");

            Assert.IsTrue(File.Exists(expectedServiceFile), "Plug and play service file not found.");

            Console.WriteLine("Checking that GreenSense index was installed.");
            var indexGitDir = Path.Combine(installDir, ".git");

            Assert.IsTrue(Directory.Exists(indexGitDir), "The GreenSense index .git folder wasn't found.");
        }
Beispiel #4
0
        public void Test_DeployUpgrade()
        {
            Console.WriteLine("Testing deploy upgrade...");

            var version = File.ReadAllText(ProjectDirectory + "/full-version.txt").Trim();

            var branch = new BranchDetector(ProjectDirectory).Branch;

            Console.WriteLine("  Version: " + version);
            Console.WriteLine("  Branch: " + branch);

            var deployment = GetDeploymentInfo(branch);

            Console.WriteLine("  Host: " + deployment.Ssh.Host);
            Console.WriteLine("  SSH Username: "******"  SSH Password: hidden (length " + (String.IsNullOrEmpty(deployment.Ssh.Password) ? deployment.Ssh.Password.Length : 0) + ")");
            Console.WriteLine("  SSH Port: " + deployment.Ssh.Port);

            Console.WriteLine("  MQTT Host: " + deployment.Mqtt.Host);
            Console.WriteLine("  MQTT Username: "******"  MQTT Password: hidden (length " + (String.IsNullOrEmpty(deployment.Mqtt.Password) ? deployment.Mqtt.Password.Length : 0) + ")");
            Console.WriteLine("  MQTT Port: " + deployment.Mqtt.Port);

            var ssh = new SshHelper(deployment.Ssh);

            ssh.UseSshPass = true;

            var manager = new DeploymentManager(deployment, branch, version);

            manager.CreateReleaseZipAndPushToHost(ProjectDirectory, deployment, ssh);

            if (!manager.IsInstalledOnTarget())
            {
                Assert.Fail("Can't upgrade when GrowSense is not currently installed.");
            }

            // TODO: Remove if not needed. Used for debugging
            //manager.Ssh.Execute("echo helloworld");
            //manager.Ssh.Execute("sudo echo hello > /usr/local/GrowSense/Installer/hello.txt");

            manager.DownloadAndLaunchUpgrade();

            manager.SetConfigValues();

            Console.WriteLine("Setting supervisor settings...");
            manager.Ssh.Execute("echo 10 > supervisor-status-check-frequency.txt && echo 10 > supervisor-docker-check-frequency.txt && echo 10 > supervisor-mqtt-check-frequency.txt");

            Console.WriteLine("Deploy upgrade successful.");
        }
        public void Should_use_solution_dir_as_base_dir()
        {
            Assert.True(BranchDetector.CanDetectBranch());
            Assert.IsNotEmpty(BranchDetector.Current());


            BranchDetector.Live();

            //simulate a no git dir
            RippleFileSystem.StubCurrentDirectory(Path.GetTempPath());

            Assert.False(BranchDetector.CanDetectBranch());

            Assert.Throws <RippleFatalError>(() => BranchDetector.Current());
        }
Beispiel #6
0
        public void description_for_no_branch()
        {
            BranchDetector.Stub(() => false);
            BranchDetector.Stub(() => "test");

            var operation = new RippleOperation(new Solution {
                Name = "Test"
            }, new SolutionInput(), new RippleStepRunner(new FileSystem()));
            var description = new Description();

            operation.Describe(description);

            description.ShortDescription.ShouldEqual("Test");

            BranchDetector.Live();
        }
Beispiel #7
0
        public void Describe(Description description)
        {
            if (!BranchDetector.CanDetectBranch())
            {
                description.ShortDescription = _solution.Name;
            }
            else
            {
                description.ShortDescription = _solution.Name + " ({0})".ToFormat(BranchDetector.Current());
            }

            var list = description.AddList("RippleSteps", _steps);

            list.Label            = "Ripple Steps";
            list.IsOrderDependent = true;
        }
        public void Test_Uninstall_FromWeb()
        {
            MoveToTemporaryDirectory();

            Console.WriteLine("");
            Console.WriteLine("Preparing uninstall from web test...");
            Console.WriteLine("");

            var installDir    = Path.GetFullPath("GreenSense/Index");
            var pnpInstallDir = Path.GetFullPath("ArduinoPlugAndPlay");

            var branchDetector = new BranchDetector();
            var branch         = branchDetector.Branch;


            PrepareGreenSenseInstallation(branch, installDir, pnpInstallDir);

            PullFileFromProject("scripts-web/uninstall-plug-and-play-from-web.sh", true);

            var scriptPath = Path.GetFullPath("uninstall-plug-and-play-from-web.sh");
            var cmd        = "bash " + scriptPath + " " + branch + " " + installDir;

            Console.WriteLine("Command:");
            Console.WriteLine("  " + cmd);

            var starter = new ProcessStarter();

            Console.WriteLine("");
            Console.WriteLine("Performing uninstall from web test...");
            Console.WriteLine("");

            starter.Start(cmd);

            Console.Write(starter.Output);

            Assert.IsFalse(starter.IsError, "An error occurred.");

            Console.WriteLine("Checking that the ArduinoPlugAndPlay service file was installed.");
            var expectedServiceFile = Path.Combine(pnpInstallDir, "mock/services/arduino-plug-and-play.service");

            Assert.IsFalse(File.Exists(expectedServiceFile), "Plug and play service file still exists.");

            Console.WriteLine("Checking that GreenSense index was installed.");
            var indexDir = installDir;

            Assert.IsFalse(Directory.Exists(indexDir), "The GreenSense index directory still exists.");
        }
        public void Execute(RippleInput input, IRippleStepRunner runner)
        {
            var feeds = Solution.Feeds.ToArray();

            if (input is IOverrideFeeds)
            {
                var overrides = input.As <IOverrideFeeds>().Feeds();
                if (overrides.Any())
                {
                    Solution.ClearFeeds();
                    Solution.AddFeeds(overrides);
                }
            }

            if (input is IAllowExplicitBranch)
            {
                var branchingInput = input.As <IAllowExplicitBranch>();
                if (branchingInput.BranchFlag.IsNotEmpty())
                {
                    BranchDetector.SetBranch(branchingInput.BranchFlag);
                }
            }

            var missing = Solution.MissingNugets().ToList();
            var nugets  = new List <INugetFile>();
            var report  = new MissingNugetReport();

            if (missing.Any())
            {
                var tasks = missing.Select(x => restore(x, Solution, report, nugets)).ToArray();
                Task.WaitAll(tasks);
            }

            Solution.ClearFeeds();
            Solution.AddFeeds(feeds);

            if (!report.IsValid())
            {
                RippleLog.InfoMessage(report);
                RippleAssert.Fail("Could not restore dependencies");
            }

            runner.Set(new DownloadedNugets(nugets));
        }
        public void Test_SetWiFiCredentialsFromWeb()
        {
            MoveToTemporaryDirectory();

            Console.WriteLine("");
            Console.WriteLine("Preparing set WiFi credentials from web test...");
            Console.WriteLine("");

            var scriptName = "set-wifi-credentials-from-web.sh";

            PullFileFromProject("scripts-web/" + scriptName, true);

            var scriptPath = Path.GetFullPath(scriptName);

            var branchDetector = new BranchDetector();
            var branch         = branchDetector.Branch;

            var installDir = "installation";

            var random = new Random();

            var wifiName = "MyWifi" + random.Next(99);
            var wifiPass = "******" + random.Next(99);

            var cmd = "bash " + scriptPath + " " + branch + " " + installDir + " " + wifiName + " " + wifiPass;

            Console.WriteLine("Command:");
            Console.WriteLine("  " + cmd);

            var starter = new ProcessStarter();

            Console.WriteLine("");
            Console.WriteLine("Performing test...");
            Console.WriteLine("");

            starter.Start(cmd);

            Console.Write(starter.Output);

            Assert.IsFalse(starter.IsError, "An error occurred.");

            AssertSecurityFile(installDir, "wifi-name", wifiName);
            AssertSecurityFile(installDir, "wifi-password", wifiPass);
        }
Beispiel #11
0
 public void TearDown()
 {
     BranchDetector.Live();
 }
Beispiel #12
0
 public void SetUp()
 {
     theProvider = new FeedProvider();
     BranchDetector.Stub(() => "testBranch");
 }
        public void Test_Install_FromWeb()
        {
            MoveToTemporaryDirectory();

            Console.WriteLine("");
            Console.WriteLine("Preparing install from web test...");
            Console.WriteLine("");

            PullFileFromProject("scripts-web/install-plug-and-play-from-web.sh", true);

            var scriptPath = Path.GetFullPath("install-plug-and-play-from-web.sh");

            var branchDetector = new BranchDetector();
            var branch         = branchDetector.Branch;

            var installDir = Path.GetFullPath("GreenSense/Index");

            EnableMocking(installDir, "systemctl");
            EnableMocking(installDir, "mqtt-bridge");
            EnableMocking(installDir, "docker");
            EnableMocking(installDir, "install");

            var pnpInstallDir = Path.GetFullPath("ArduinoPlugAndPlay");

            EnableMocking(pnpInstallDir, "systemctl");

            var random = new Random();

            var wifiName = "MyWifi" + random.Next(99);
            var wifiPass = "******" + random.Next(99);

            var mqttHost = "10.0.0." + random.Next(99);
            var mqttUser = "******" + random.Next(99);
            var mqttPass = "******" + random.Next(99);
            var mqttPort = "18" + random.Next(99);

            var cmd = "bash " + scriptPath + " " + branch + " " + installDir + " " + wifiName + " " + wifiPass + " " + mqttHost + " " + mqttUser + " " + mqttPass + " " + mqttPort;

            Console.WriteLine("Command:");
            Console.WriteLine("  " + cmd);

            var starter = new ProcessStarter();

            Console.WriteLine("");
            Console.WriteLine("Performing install from web test...");
            Console.WriteLine("");

            starter.Start(cmd);

            Console.Write(starter.Output);

            Assert.IsFalse(starter.IsError, "An error occurred.");

            Console.WriteLine("Checking that the ArduinoPlugAndPlay service file was installed.");
            var expectedServiceFile = Path.Combine(pnpInstallDir, "mock/services/arduino-plug-and-play.service");

            Assert.IsTrue(File.Exists(expectedServiceFile), "Plug and play service file not found.");

            Console.WriteLine("Checking that GreenSense index was installed.");
            var indexGitDir = Path.Combine(installDir, ".git");

            Assert.IsTrue(Directory.Exists(indexGitDir), "The GreenSense index .git folder wasn't found.");
        }
Beispiel #14
0
        public void Test_DeployInstall()
        {
            Console.WriteLine("Testing deploy install...");

            var version = File.ReadAllText(ProjectDirectory + "/full-version.txt").Trim();

            var branch = new BranchDetector(ProjectDirectory).Branch;


            Console.WriteLine("  Version: " + version);
            Console.WriteLine("  Branch: " + branch);

            var deployment = GetDeploymentInfo(branch);


            Console.WriteLine("  Username: "******"  Password: hidden (length " + (String.IsNullOrEmpty(deployment.Password) ? deployment.Password.Length : 0) + ")");

            Console.WriteLine("  SSH Host: " + deployment.Ssh.Host);
            Console.WriteLine("  SSH Username: "******"  SSH Password: hidden (length " + (String.IsNullOrEmpty(deployment.Ssh.Password) ? deployment.Ssh.Password.Length : 0) + ")");
            Console.WriteLine("  SSH Port: " + deployment.Ssh.Port);

            Console.WriteLine("  MQTT Host: " + deployment.Mqtt.Host);
            Console.WriteLine("  MQTT Username: "******"  MQTT Password: hidden (length " + (String.IsNullOrEmpty(deployment.Mqtt.Password) ? deployment.Mqtt.Password.Length : 0) + ")");
            Console.WriteLine("  MQTT Port: " + deployment.Mqtt.Port);

            var ssh = new SshHelper(deployment.Ssh);

            ssh.UseSshPass = true;

            var manager = new DeploymentManager(deployment, branch, version);

            manager.CreateReleaseZipAndPushToHost(ProjectDirectory, deployment, ssh);

            if (manager.IsInstalledOnTarget())
            {
                manager.WaitForUnlock();

                Console.WriteLine("Renaming GrowSense devices to ensure the name is set correctly after installation...");

                // TODO: Fix and reimplement
                //   manager.RenameDevice("irrigatorW1", "NewIrrigatorW");
                //   manager.RenameDevice("illuminator1", "NewIlluminator");
            }
            else
            {
                manager.Ssh.CreateDirectory("/usr/local/GrowSense/Index");
            }


            Console.WriteLine("");
            Console.WriteLine("Adding GrowSense remotes...");
            manager.AddRemotes();

            // TODO: Remove if not needed. Used for debugging
            //manager.Ssh.Execute("echo helloworld");
            //manager.Ssh.Execute("sudo echo hello > /usr/local/GrowSense/Installer/hello.txt");

            manager.DownloadAndLaunchInstall();

            manager.SetConfigValues();

            Console.WriteLine("Setting supervisor settings...");
            manager.Ssh.Execute("echo 10 > supervisor-status-check-frequency.txt && echo 10 > supervisor-docker-check-frequency.txt && echo 10 > supervisor-mqtt-check-frequency.txt");

            Console.WriteLine("Deploy installation successful.");
        }
Beispiel #15
0
 public override bool Execute(SolutionInput input)
 {
     Console.WriteLine(BranchDetector.Current());
     return(true);
 }