public void SetUp()
 {
     journal = Substitute.For <IDeploymentJournal>();
     journal.GetLatestInstallation(Arg.Any <string>()).Returns(_ => previous);
     journal.GetLatestSuccessfulInstallation(Arg.Any <string>()).Returns(_ => previous);
     variables = new CalamariVariables();
 }
Ejemplo n.º 2
0
        public void SetUp()
        {
            fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            // Ensure tenticle directory exists
            tentacleDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestTentacle");
            var tentacleHiddenDirectory = Path.Combine(tentacleDirectory, ".tentacle"); 
            fileSystem.EnsureDirectoryExists(tentacleDirectory);
            fileSystem.EnsureDirectoryExists(tentacleHiddenDirectory);
            fileSystem.PurgeDirectory(tentacleHiddenDirectory, FailureOptions.ThrowOnFailure);

            Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(tentacleHiddenDirectory, "DeploymentJournal.xml" ));

            variables = new VariableDictionary();
            variables.EnrichWithEnvironmentVariables();

            deploymentJournal = new DeploymentJournal(fileSystem, new SystemSemaphore(), variables);

            packagesDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestPackages");
            fileSystem.EnsureDirectoryExists(packagesDirectory);
            stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging");
            fileSystem.EnsureDirectoryExists(stagingDirectory);

            // Create some artificats
            const string retentionPolicySet1 = "retentionPolicySet1";

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.0.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.0.0"), 
                new DateTimeOffset(new DateTime(2015, 01, 26), new TimeSpan(10, 0,0)), retentionPolicySet1);

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.1.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.1.0"), 
                new DateTimeOffset(new DateTime(2015, 02, 01), new TimeSpan(10, 0,0)), retentionPolicySet1);

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.2.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.2.0"), 
                new DateTimeOffset(new DateTime(2015, 02, 10), new TimeSpan(10, 0,0)), retentionPolicySet1);
        }
Ejemplo n.º 3
0
        public void SetUp()
        {
            fileSystem        = Substitute.For <ICalamariFileSystem>();
            deploymentJournal = Substitute.For <IDeploymentJournal>();
            clock             = Substitute.For <IClock>();
            retentionPolicy   = new RetentionPolicy(fileSystem, deploymentJournal, clock);

            now = new DateTimeOffset(new DateTime(2015, 01, 15), new TimeSpan(0, 0, 0));
            clock.GetUtcTime().Returns(now);

            // Deployed 4 days prior to 'now'
            fourDayOldDeployment = new JournalEntry("fourDayOld", "blah", "blah", "blah", "blah", "blah", policySet1,
                                                    now.AddDays(-4).LocalDateTime,
                                                    "C:\\packages\\Acme.1.0.0.nupkg", "C:\\Applications\\Acme.1.0.0", null, true);

            // Deployed 4 days prior to 'now' but to the same location as the latest successful deployment
            fourDayOldSameLocationDeployment = new JournalEntry("twoDayOld", "blah", "blah", "blah", "blah", "blah", policySet1,
                                                                now.AddDays(-4).LocalDateTime,
                                                                "C:\\packages\\Acme.1.2.0.nupkg", "C:\\Applications\\Acme.1.2.0", null, true);

            // Deployed 3 days prior to 'now'
            threeDayOldDeployment = new JournalEntry("threeDayOld", "blah", "blah", "blah", "blah", "blah", policySet1,
                                                     now.AddDays(-3).LocalDateTime,
                                                     "C:\\packages\\Acme.1.1.0.nupkg", "C:\\Applications\\Acme.1.1.0", null, true);

            // Deployed 2 days prior to 'now'
            twoDayOldDeployment = new JournalEntry("twoDayOld", "blah", "blah", "blah", "blah", "blah", policySet1,
                                                   now.AddDays(-2).LocalDateTime,
                                                   "C:\\packages\\Acme.1.2.0.nupkg", "C:\\Applications\\Acme.1.2.0", null, true);

            // Deployed (unsuccessfully) 1 day prior to 'now'
            oneDayOldUnsuccessfulDeployment = new JournalEntry("oneDayOldUnsuccessful", "blah", "blah", "blah", "blah", "blah", policySet1,
                                                               now.AddDays(-1).LocalDateTime,
                                                               "C:\\packages\\Acme.1.3.0.nupkg", "C:\\Applications\\Acme.1.3.0", null, false);

            // Deployed 5 days prior to 'now', but has a different policy-set
            fiveDayOldNonMatchingDeployment = new JournalEntry("fiveDayOld", "blah", "blah", "blah", "blah", "blah", policySet2,
                                                               now.AddDays(-5).LocalDateTime,
                                                               "C:\\packages\\Beta.1.0.0.nupkg", "C:\\Applications\\Beta.1.0.0", null, true);

            var journalEntries = new List <JournalEntry>
            {
                fiveDayOldNonMatchingDeployment,
                fourDayOldDeployment,
                threeDayOldDeployment,
                twoDayOldDeployment,
                oneDayOldUnsuccessfulDeployment
            };

            deploymentJournal.GetAllJournalEntries().Returns(journalEntries);

            foreach (var journalEntry in journalEntries)
            {
                fileSystem.FileExists(journalEntry.ExtractedFrom).Returns(true);
                fileSystem.DirectoryExists(journalEntry.ExtractedTo).Returns(true);
            }

            Environment.SetEnvironmentVariable("TentacleHome", @"Q:\TentacleHome");
        }
Ejemplo n.º 4
0
        public void SetUp()
        {
            fileSystem = Substitute.For<ICalamariFileSystem>();
            deploymentJournal = Substitute.For<IDeploymentJournal>();
            clock = Substitute.For<IClock>();
            retentionPolicy = new RetentionPolicy(fileSystem, deploymentJournal, clock);

            now = new DateTimeOffset(new DateTime(2015, 01, 15), new TimeSpan(0, 0, 0));
            clock.GetUtcTime().Returns(now);

            // Deployed 4 days prior to 'now'
            fourDayOldDeployment = new JournalEntry("fourDayOld", "blah", "blah", "blah", "blah", policySet1,
                now.AddDays(-4).LocalDateTime,
                "C:\\packages\\Acme.1.0.0.nupkg", "C:\\Applications\\Acme.1.0.0", null, true);

            // Deployed 4 days prior to 'now' but to the same location as the latest successful deployment
            fourDayOldSameLocationDeployment = new JournalEntry("twoDayOld", "blah", "blah", "blah", "blah", policySet1,
                now.AddDays(-4).LocalDateTime,
                "C:\\packages\\Acme.1.2.0.nupkg", "C:\\Applications\\Acme.1.2.0", null, true);

            // Deployed 3 days prior to 'now'
            threeDayOldDeployment = new JournalEntry("threeDayOld", "blah", "blah", "blah", "blah", policySet1,
                now.AddDays(-3).LocalDateTime,
                "C:\\packages\\Acme.1.1.0.nupkg", "C:\\Applications\\Acme.1.1.0", null, true);

            // Deployed 2 days prior to 'now'
            twoDayOldDeployment = new JournalEntry("twoDayOld", "blah", "blah", "blah", "blah", policySet1,
                now.AddDays(-2).LocalDateTime,
                "C:\\packages\\Acme.1.2.0.nupkg", "C:\\Applications\\Acme.1.2.0", null, true);

            // Deployed (unsuccessfully) 1 day prior to 'now'
            oneDayOldUnsuccessfulDeployment = new JournalEntry("oneDayOldUnsuccessful", "blah", "blah", "blah", "blah", policySet1,
                now.AddDays(-1).LocalDateTime,
                "C:\\packages\\Acme.1.3.0.nupkg", "C:\\Applications\\Acme.1.3.0", null, false);

            // Deployed 5 days prior to 'now', but has a different policy-set
            fiveDayOldNonMatchingDeployment = new JournalEntry("fiveDayOld", "blah", "blah", "blah", "blah", policySet2,
                now.AddDays(-5).LocalDateTime,
                "C:\\packages\\Beta.1.0.0.nupkg", "C:\\Applications\\Beta.1.0.0", null, true);

            var journalEntries = new List<JournalEntry>
            {
                fiveDayOldNonMatchingDeployment,
                fourDayOldDeployment,
                threeDayOldDeployment,
                twoDayOldDeployment,
                oneDayOldUnsuccessfulDeployment
            };

            deploymentJournal.GetAllJournalEntries().Returns(journalEntries);

            foreach (var journalEntry in journalEntries)
            {
                fileSystem.FileExists(journalEntry.ExtractedFrom).Returns(true);
                fileSystem.DirectoryExists(journalEntry.ExtractedTo).Returns(true);
            }
        }
Ejemplo n.º 5
0
        internal static void PreviousSuccessful(IVariables variables, IDeploymentJournal journal, string policySet)
        {
            var previous = journal.GetLatestSuccessfulInstallation(policySet);

            if (previous == null)
            {
                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.OriginalInstalledPath, "");
                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.CustomInstallationDirectory, "");
                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.PackageFilePath, "");
                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.PackageVersion, "");
            }
            else
            {
                var previousPackage = previous.Packages.FirstOrDefault();

                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.OriginalInstalledPath, previous.ExtractedTo);
                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.CustomInstallationDirectory, previous.CustomInstallationDirectory);
                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.PackageFilePath, previousPackage?.DeployedFrom ?? "");
                variables.Set(TentacleVariables.PreviousSuccessfulInstallation.PackageVersion, previousPackage?.PackageVersion ?? "");
            }
        }
Ejemplo n.º 6
0
        public void SetUp()
        {
            fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            // Ensure tenticle directory exists
            tentacleDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestTentacle");
            var tentacleHiddenDirectory = Path.Combine(tentacleDirectory, ".tentacle");

            fileSystem.EnsureDirectoryExists(tentacleDirectory);
            fileSystem.EnsureDirectoryExists(tentacleHiddenDirectory);
            fileSystem.PurgeDirectory(tentacleHiddenDirectory, FailureOptions.ThrowOnFailure);

            Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(tentacleHiddenDirectory, "DeploymentJournal.xml"));
            Environment.SetEnvironmentVariable("TentacleHome", tentacleHiddenDirectory);

            variables = new VariableDictionary();
            variables.EnrichWithEnvironmentVariables();

            deploymentJournal = new DeploymentJournal(fileSystem, SemaphoreFactory.Get(), variables);

            packagesDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestPackages");
            fileSystem.EnsureDirectoryExists(packagesDirectory);
            stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging");
            fileSystem.EnsureDirectoryExists(stagingDirectory);

            // Create some artificats
            const string retentionPolicySet1 = "retentionPolicySet1";

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.0.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.0.0"),
                             new DateTimeOffset(new DateTime(2015, 01, 26), new TimeSpan(10, 0, 0)), retentionPolicySet1);

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.1.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.1.0"),
                             new DateTimeOffset(new DateTime(2015, 02, 01), new TimeSpan(10, 0, 0)), retentionPolicySet1);

            CreateDeployment(Path.Combine(packagesDirectory, "Acme.1.2.0.nupkg"), Path.Combine(stagingDirectory, "Acme.1.2.0"),
                             new DateTimeOffset(new DateTime(2015, 02, 10), new TimeSpan(10, 0, 0)), retentionPolicySet1);
        }
Ejemplo n.º 7
0
 public RetentionPolicy(ICalamariFileSystem fileSystem, IDeploymentJournal deploymentJournal, IClock clock)
 {
     this.fileSystem        = fileSystem;
     this.deploymentJournal = deploymentJournal;
     this.clock             = clock;
 }
 public void SetUp()
 {
     journal = Substitute.For<IDeploymentJournal>();
     journal.GetLatestInstallation(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>()).Returns(_ => previous);
     variables = new CalamariVariableDictionary();
 }
Ejemplo n.º 9
0
        public void SetUp()
        {
            fileSystem        = Substitute.For <ICalamariFileSystem>();
            deploymentJournal = Substitute.For <IDeploymentJournal>();
            clock             = Substitute.For <IClock>();
            retentionPolicy   = new RetentionPolicy(fileSystem, deploymentJournal, clock);

            now = new DateTimeOffset(new DateTime(2015, 01, 15), new TimeSpan(0, 0, 0));
            clock.GetUtcTime().Returns(now);

            // Deployed 4 days prior to 'now'
            fourDayOldDeployment = new JournalEntry("fourDayOld", "blah", "blah", "blah", policySet1,
                                                    now.AddDays(-4).LocalDateTime, "C:\\Applications\\Acme.1.0.0", null, true,
                                                    new DeployedPackage("blah", "blah", "C:\\packages\\Acme.1.0.0.nupkg"));

            // Deployed 4 days prior to 'now' but to the same location as the latest successful deployment
            fourDayOldSameLocationDeployment = new JournalEntry("fourDayOldSameLocation", "blah", "blah", "blah", policySet1,
                                                                now.AddDays(-4).LocalDateTime, "C:\\Applications\\Acme.1.2.0", null, true,
                                                                new DeployedPackage("blah", "blah", "C:\\packages\\Acme.1.2.0.nupkg"));

            // Deployed 3 days prior to 'now'
            threeDayOldDeployment = new JournalEntry("threeDayOld", "blah", "blah", "blah", policySet1,
                                                     now.AddDays(-3).LocalDateTime, "C:\\Applications\\Acme.1.1.0", null, true,
                                                     new DeployedPackage("blah", "blah", "C:\\packages\\Acme.1.1.0.nupkg"));

            // Deployed 2 days prior to 'now'
            twoDayOldDeployment = new JournalEntry("twoDayOld", "blah", "blah", "blah", policySet1,
                                                   now.AddDays(-2).LocalDateTime, "C:\\Applications\\Acme.1.2.0", null, true,
                                                   new DeployedPackage("blah", "blah", "C:\\packages\\Acme.1.2.0.nupkg"));

            // Deployed (unsuccessfully) 1 day prior to 'now'
            oneDayOldUnsuccessfulDeployment = new JournalEntry("oneDayOldUnsuccessful", "blah", "blah", "blah", policySet1,
                                                               now.AddDays(-1).LocalDateTime, "C:\\Applications\\Acme.1.3.0", null, false,
                                                               new DeployedPackage("blah", "blah", "C:\\packages\\Acme.1.3.0.nupkg"));

            // Deployed 5 days prior to 'now', but has a different policy-set
            fiveDayOldNonMatchingDeployment = new JournalEntry("fiveDayOld", "blah", "blah", "blah", policySet2,
                                                               now.AddDays(-5).LocalDateTime, "C:\\Applications\\Beta.1.0.0", null, true,
                                                               new DeployedPackage("blah", "blah", "C:\\packages\\Beta.1.0.0.nupkg"));

            // Step with multiple packages, deployed 4 days prior, and referencing the same source file as the latest successful
            // deployment from a different step
            fourDayOldMultiPackageDeployment = new JournalEntry("fourDayOldMultiPackage", "blah", "blah", "blah", policySet3,
                                                                now.AddDays(-4).LocalDateTime, null, null, true,
                                                                new []
            {
                new DeployedPackage("blah", "blah", "C:\\packages\\Acme.1.2.0.nupkg"),
                new DeployedPackage("foo", "blah", "C:\\packages\\Foo.0.0.9.nupkg")
            });

            // Step with multiple packages, deployed 2 days prior
            twoDayOldMultiPackageDeployment = new JournalEntry("twoDayOldMultiPackage", "blah", "blah", "blah", policySet3,
                                                               now.AddDays(-2).LocalDateTime, null, null, true,
                                                               new []
            {
                new DeployedPackage("blah", "blah", "C:\\packages\\Acme.1.2.0.nupkg"),
                new DeployedPackage("foo", "blah", "C:\\packages\\Foo.1.0.0.nupkg")
            });

            // We may reference packages which are not acquired (e.g. docker containers from script steps).
            // These will not have a `DeployedFrom` path.
            twoDayOldDeploymentWithPackageThatWasNotAcquired = new JournalEntry("twoDayOldNotAcquired",
                                                                                "blah", "blah", "blah", policySet4,
                                                                                now.AddDays(-2).LocalDateTime, null, null, true,
                                                                                new[]
            {
                new DeployedPackage("blah", "blah", null)
            });

            fiveDayOldDeploymentWithPackageThatWasNotAcquired = new JournalEntry("fiveDayOldNotAcquired",
                                                                                 "blah", "blah", "blah", policySet4,
                                                                                 now.AddDays(-5).LocalDateTime, null, null, true,
                                                                                 new[]
            {
                new DeployedPackage("blah", "blah", null)
            });


            var journalEntries = new List <JournalEntry>
            {
                fiveDayOldNonMatchingDeployment,
                fourDayOldDeployment,
                threeDayOldDeployment,
                twoDayOldDeployment,
                oneDayOldUnsuccessfulDeployment,
                fourDayOldMultiPackageDeployment,
                twoDayOldMultiPackageDeployment,
                fiveDayOldDeploymentWithPackageThatWasNotAcquired
            };

            deploymentJournal.GetAllJournalEntries().Returns(journalEntries);

            foreach (var journalEntry in journalEntries)
            {
                if (!string.IsNullOrEmpty(journalEntry.ExtractedTo))
                {
                    fileSystem.DirectoryExists(journalEntry.ExtractedTo).Returns(true);
                }

                foreach (var deployedPackage in journalEntry.Packages)
                {
                    fileSystem.FileExists(deployedPackage.DeployedFrom).Returns(true);
                }
            }

            Environment.SetEnvironmentVariable("TentacleHome", @"Q:\TentacleHome");
        }
 public ContributePreviousInstallationConvention(IDeploymentJournal journal)
 {
     this.journal = journal;
 }
 public AlreadyInstalledConvention(IDeploymentJournal journal)
 {
     this.journal = journal;
 }
Ejemplo n.º 12
0
 public AlreadyInstalledConvention(IDeploymentJournal journal)
 {
     this.journal = journal;
 }
Ejemplo n.º 13
0
 public RetentionPolicy(ICalamariFileSystem fileSystem, IDeploymentJournal deploymentJournal, IClock clock)
 {
     this.fileSystem = fileSystem;
     this.deploymentJournal = deploymentJournal;
     this.clock = clock;
 }
Ejemplo n.º 14
0
 public AlreadyInstalledConvention(ILog log, IDeploymentJournal journal)
 {
     this.log     = log;
     this.journal = journal;
 }
 public ContributePreviousInstallationConvention(IDeploymentJournal journal)
 {
     this.journal = journal;
 }
 public void SetUp()
 {
     journal = Substitute.For <IDeploymentJournal>();
     journal.GetLatestInstallation(Arg.Any <string>()).Returns(_ => previous);
     variables = new VariableDictionary();
 }