Esempio n. 1
0
        public void GivenWorkloadInstallItCanRollBackPackInstallation()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android"), new WorkloadId("xamarin-android-build") };
            var testDirectory = _testAssetsManager.CreateTestDirectory().Path;
            var dotnetRoot = Path.Combine(testDirectory, "dotnet");
            var installer = new MockPackWorkloadInstaller(failingWorkload: "xamarin-android-build");
            var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), new string[] { dotnetRoot });
            var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "xamarin-android-build", "--skip-manifest-update" });
            var installManager = new WorkloadInstallCommand(parseResult, reporter: _reporter, workloadResolver: workloadResolver, workloadInstaller: installer, version: "6.0.100");

            try
            {
                installManager.InstallWorkloads(mockWorkloadIds, true);

                // Install should have failed
                true.Should().BeFalse();
            }
            catch (Exception e)
            {
                e.Message.Should().Be("Failing workload: xamarin-android-build");
                var expectedPacks = mockWorkloadIds
                    .SelectMany(workloadId => workloadResolver.GetPacksInWorkload(workloadId.ToString()))
                    .Distinct()
                    .Select(packId => workloadResolver.TryGetPackInfo(packId));
                installer.RolledBackPacks.ShouldBeEquivalentTo(expectedPacks);
                installer.WorkloadInstallRecord.Should().BeEmpty();
            }
        }
Esempio n. 2
0
        internal UpdateAvailableEntry[] GetUpdateAvailable(IEnumerable <WorkloadId> installedList)
        {
            HashSet <WorkloadId> installedWorkloads = installedList.ToHashSet();

            Task.Run(() => _workloadManifestUpdater.UpdateAdvertisingManifestsAsync(_includePreviews)).Wait();
            IEnumerable <(ManifestId manifestId, ManifestVersion existingVersion, ManifestVersion newVersion,
                          Dictionary <WorkloadId, WorkloadDefinition> Workloads)> manifestsToUpdate =
                _workloadManifestUpdater.CalculateManifestUpdates();

            List <UpdateAvailableEntry> updateList = new();

            foreach ((ManifestId _, ManifestVersion existingVersion, ManifestVersion newVersion,
                      Dictionary <WorkloadId, WorkloadDefinition> workloads) in manifestsToUpdate)
            {
                foreach ((WorkloadId WorkloadId, WorkloadDefinition workloadDefinition) in
                         workloads)
                {
                    if (installedWorkloads.Contains(new WorkloadId(WorkloadId.ToString())))
                    {
                        updateList.Add(new UpdateAvailableEntry(existingVersion.ToString(),
                                                                newVersion.ToString(),
                                                                workloadDefinition.Description, WorkloadId.ToString()));
                    }
                }
            }

            return(updateList.ToArray());
        }
Esempio n. 3
0
 public WorkloadContext(int count, int index, CancellationToken cancellationToken)
 {
     this.WorkloadId        = WorkloadId.New();
     this.WorkloadCount     = count;
     this.WorkloadIndex     = index;
     this.CancellationToken = cancellationToken;
 }
Esempio n. 4
0
        public override bool Execute()
        {
            if (!HasMetadata(WorkloadId, nameof(WorkloadId), "Version") ||
                !HasMetadata(WorkloadId, nameof(WorkloadId), "ManifestName"))
            {
                return(false);
            }

            if (!Directory.Exists(SdkDir))
            {
                Log.LogError($"Cannot find SdkDir={SdkDir}");
                return(false);
            }

            Log.LogMessage(MessageImportance.High, $"{Environment.NewLine}** Installing workload manifest {WorkloadId.ItemSpec} **{Environment.NewLine}");

            string nugetConfigContents = GetNuGetConfig();

            if (!InstallWorkloadManifest(WorkloadId.GetMetadata("ManifestName"), WorkloadId.GetMetadata("Version"), nugetConfigContents, stopOnMissing: true))
            {
                return(false);
            }

            if (OnlyUpdateManifests)
            {
                return(!Log.HasLoggedErrors);
            }

            string nugetConfigPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

            File.WriteAllText(nugetConfigPath, nugetConfigContents);

            Log.LogMessage(MessageImportance.High, $"{Environment.NewLine}** workload install **{Environment.NewLine}");
            (int exitCode, string output) = Utils.TryRunProcess(
                Log,
                Path.Combine(SdkDir, "dotnet"),
                $"workload install --skip-manifest-update --no-cache --configfile \"{nugetConfigPath}\" {WorkloadId.ItemSpec}",
                workingDir: Path.GetTempPath(),
                silent: false,
                debugMessageImportance: MessageImportance.High);
            if (exitCode != 0)
            {
                Log.LogError($"workload install failed: {output}");

                foreach (var dir in Directory.EnumerateDirectories(Path.Combine(SdkDir, "sdk-manifests"), "*", SearchOption.AllDirectories))
                {
                    Log.LogMessage(MessageImportance.Low, $"\t{Path.Combine(SdkDir, "sdk-manifests", dir)}");
                }

                foreach (var dir in Directory.EnumerateDirectories(Path.Combine(SdkDir, "packs"), "*", SearchOption.AllDirectories))
                {
                    Log.LogMessage(MessageImportance.Low, $"\t{Path.Combine(SdkDir, "packs", dir)}");
                }

                return(false);
            }

            return(!Log.HasLoggedErrors);
        }
Esempio n. 5
0
 public ExecuteResult(WorkloadId workloadId, TimeSpan elapsed, long executionNo, bool hasError, string?errorMessage)
 {
     WorkloadId   = workloadId;
     Elapsed      = elapsed;
     ExecutionNo  = executionNo;
     HasError     = hasError;
     ErrorMessage = errorMessage;
 }
 public void WriteWorkloadInstallationRecord(WorkloadId workloadId, SdkFeatureBand sdkFeatureBand)
 {
     WorkloadInstallRecord.Add(workloadId);
     if (workloadId.ToString().Equals(FailingWorkload))
     {
         throw new Exception($"Failing workload: {workloadId}");
     }
 }
        public void GivenManagedInstallItCanWriteInstallationRecord()
        {
            var workloadId = new WorkloadId("test-workload");
            var version    = "6.0.100";

            var(dotnetRoot, installer, _) = GetTestInstaller();
            installer.GetWorkloadInstallationRecordRepository().WriteWorkloadInstallationRecord(workloadId, new SdkFeatureBand(version));
            var expectedPath = Path.Combine(dotnetRoot, "metadata", "workloads", version, "InstalledWorkloads", workloadId.ToString());

            File.Exists(expectedPath).Should().BeTrue();
        }
Esempio n. 8
0
        public void GivenWorkloadInstallItWarnsOnGarbageCollectionFailure()
        {
            _reporter.Clear();
            var mockWorkloadIds  = new WorkloadId[] { new WorkloadId("xamarin-android"), new WorkloadId("xamarin-android-build") };
            var testDirectory    = _testAssetsManager.CreateTestDirectory().Path;
            var dotnetRoot       = Path.Combine(testDirectory, "dotnet");
            var installer        = new MockPackWorkloadInstaller(failingGarbageCollection: true);
            var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), new string[] { dotnetRoot });
            var parseResult      = Parser.Instance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "xamarin-android-build", "--skip-manifest-update" });
            var installManager   = new WorkloadInstallCommand(parseResult, reporter: _reporter, workloadResolver: workloadResolver, workloadInstaller: installer, version: "6.0.100");

            installManager.InstallWorkloads(mockWorkloadIds, true);
            string.Join(" ", _reporter.Lines).Should().Contain("Failing garbage collection");
        }
        public void GivenWorkloadUpdateItUpdatesOutOfDatePacks()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") };

            (_, var command, var installer, _, _, _) = GetTestInstallers(_parseResult, installedWorkloads: mockWorkloadIds);

            command.Execute();

            installer.GarbageCollectionCalled.Should().BeTrue();
            installer.CachePath.Should().BeNull();
            installer.InstallationRecordRepository.WorkloadInstallRecord.Should().BeEquivalentTo(mockWorkloadIds);
            installer.InstalledPacks.Count.Should().Be(8);
            installer.InstalledPacks.Where(pack => pack.Id.Contains("Android")).Count().Should().Be(8);
        }
Esempio n. 10
0
        public void GivenWorkloadInstallOnFailingRollbackItDisplaysTopLevelError()
        {
            var mockWorkloadIds  = new WorkloadId[] { new WorkloadId("xamarin-android"), new WorkloadId("xamarin-android-build") };
            var testDirectory    = _testAssetsManager.CreateTestDirectory().Path;
            var dotnetRoot       = Path.Combine(testDirectory, "dotnet");
            var installer        = new MockPackWorkloadInstaller(failingWorkload: "xamarin-android-build", failingRollback: true);
            var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), new string[] { dotnetRoot });
            var parseResult      = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "xamarin-android-build", "--skip-manifest-update" });
            var installManager   = new WorkloadInstallCommand(parseResult, reporter: _reporter, workloadResolver: workloadResolver, workloadInstaller: installer, version: "6.0.100");

            var exceptionThrown = Assert.Throws <Exception>(() => installManager.InstallWorkloads(mockWorkloadIds, true));

            exceptionThrown.Message.Should().Be("Failing workload: xamarin-android-build");
            string.Join(" ", _reporter.Lines).Should().Contain("Rollback failure");
        }
        public void GivenWorkloadUpdateItPrintsDownloadUrls()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") };
            var parseResult     = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--print-download-link-only" });

            (_, var command, _, _, _, _) = GetTestInstallers(parseResult, installedWorkloads: mockWorkloadIds, includeInstalledPacks: true);

            command.Execute();

            _reporter.Lines.Should().Contain("==allPackageLinksJsonOutputStart==");
            string.Join(" ", _reporter.Lines).Should().Contain("mock-url-xamarin.android.templates", "New pack urls should be included in output");
            string.Join(" ", _reporter.Lines).Should().Contain("mock-url-xamarin.android.framework", "Urls for packs with updated versions should be included in output");
            string.Join(" ", _reporter.Lines).Should().NotContain("mock-url-xamarin.android.sdk", "Urls for packs with the same version should not be included in output");
            string.Join(" ", _reporter.Lines).Should().Contain("mock-manifest-url");
        }
Esempio n. 12
0
        public void GivenWorkloadInstallItCanInstallPacks()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") };
            var parseResult     = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--skip-manifest-update" });

            (_, var installManager, var installer, _, _, _) = GetTestInstallers(parseResult);

            installManager.InstallWorkloads(mockWorkloadIds, true);

            installer.GarbageCollectionCalled.Should().BeTrue();
            installer.CachePath.Should().BeNull();
            installer.InstallationRecordRepository.WorkloadInstallRecord.Should().BeEquivalentTo(mockWorkloadIds);
            installer.InstalledPacks.Count.Should().Be(8);
            installer.InstalledPacks.Where(pack => pack.Id.Contains("Android")).Count().Should().Be(8);
        }
Esempio n. 13
0
        public void GivenWorkloadUpdateItRollsBackOnFailedUpdate()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android"), new WorkloadId("xamarin-android-build") };

            (_, var command, var installer, var workloadResolver, _, _) = GetTestInstallers(_parseResult, installedWorkloads: mockWorkloadIds, failingWorkload: "xamarin-android-build");

            var exceptionThrown = Assert.Throws <Exception>(() => command.Execute());

            exceptionThrown.Message.Should().Be("Failing workload: xamarin-android-build");
            var expectedPacks = mockWorkloadIds
                                .SelectMany(workloadId => workloadResolver.GetPacksInWorkload(workloadId.ToString()))
                                .Distinct()
                                .Select(packId => workloadResolver.TryGetPackInfo(packId));

            installer.RolledBackPacks.ShouldBeEquivalentTo(expectedPacks);
            installer.InstallationRecordRepository.WorkloadInstallRecord.Should().BeEmpty();
        }
        public void GivenWorkloadUpdateItCanInstallFromOfflineCache()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") };
            var cachePath       = "mockCachePath";
            var parseResult     = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--from-cache", cachePath });

            (_, var command, var installer, _, _, var nugetDownloader) = GetTestInstallers(parseResult, installedWorkloads: mockWorkloadIds);

            command.Execute();

            installer.GarbageCollectionCalled.Should().BeTrue();
            installer.CachePath.Should().Contain(cachePath);
            installer.InstallationRecordRepository.WorkloadInstallRecord.Should().BeEquivalentTo(mockWorkloadIds);
            installer.InstalledPacks.Count.Should().Be(8);
            installer.InstalledPacks.Where(pack => pack.Id.Contains("Android")).Count().Should().Be(8);
            nugetDownloader.DownloadCallParams.Count().Should().Be(0);
        }
        public void GivenWorkloadUpdateItCanDownloadToOfflineCache()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") };
            var cachePath       = Path.Combine(_testAssetsManager.CreateTestDirectory(identifier: "cachePath").Path, "mockCachePath");
            var parseResult     = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "update", "--download-to-cache", cachePath });

            (_, var command, var installer, _, var manifestUpdater, _) = GetTestInstallers(parseResult, installedWorkloads: mockWorkloadIds, includeInstalledPacks: true);

            command.Execute();

            // Manifest packages should have been 'downloaded' and used for pack resolution
            manifestUpdater.DownloadManifestPackagesCallCount.Should().Be(1);
            manifestUpdater.ExtractManifestPackagesToTempDirCallCount.Should().Be(1);
            // 6 android pack packages need to be updated
            installer.CachedPacks.Count.Should().Be(6);
            installer.CachedPacks.Select(pack => pack.Id).Should().NotContain("Xamarin.Android.Sdk"); // This pack is up to date, doesn't need to be cached
            installer.CachePath.Should().Be(cachePath);
        }
Esempio n. 16
0
        public void GivenWorkloadInstallItCanInstallPacks()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android") };
            var testDirectory = _testAssetsManager.CreateTestDirectory().Path;
            var dotnetRoot = Path.Combine(testDirectory, "dotnet");
            var installer = new MockPackWorkloadInstaller();
            var workloadResolver = WorkloadResolver.CreateForTests(new MockManifestProvider(new[] { _manifestPath }), new string[] { dotnetRoot });
            var parseResult = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "--skip-manifest-update" });
            var installManager = new WorkloadInstallCommand(parseResult, reporter: _reporter, workloadResolver: workloadResolver, workloadInstaller: installer, version: "6.0.100");

            installManager.InstallWorkloads(mockWorkloadIds, true);

            installer.GarbageCollectionCalled.Should().BeTrue();
            installer.WorkloadInstallRecord.Should().BeEquivalentTo(mockWorkloadIds);
            installer.InstalledPacks.Count.Should().Be(8);
            installer.InstalledPacks.Where(pack => pack.Id.Contains("Android")).Count().Should().Be(8);
            _reporter.Lines.Contains(string.Format(LocalizableStrings.InstallationSucceeded, "xamarin-android"));
        }
Esempio n. 17
0
        public void GivenWorkloadInstallItCanRollBackPackInstallation()
        {
            var mockWorkloadIds = new WorkloadId[] { new WorkloadId("xamarin-android"), new WorkloadId("xamarin-android-build") };
            var parseResult     = Parser.GetWorkloadsInstance.Parse(new string[] { "dotnet", "workload", "install", "xamarin-android", "xamarin-android-build", "--skip-manifest-update" });

            (_, var installManager, var installer, var workloadResolver, _, _) = GetTestInstallers(parseResult, failingWorkload: "xamarin-android-build");

            var exceptionThrown = Assert.Throws <Exception>(() => installManager.InstallWorkloads(mockWorkloadIds, true));

            exceptionThrown.Message.Should().Be("Failing workload: xamarin-android-build");
            var expectedPacks = mockWorkloadIds
                                .SelectMany(workloadId => workloadResolver.GetPacksInWorkload(workloadId.ToString()))
                                .Distinct()
                                .Select(packId => workloadResolver.TryGetPackInfo(packId));

            installer.RolledBackPacks.ShouldBeEquivalentTo(expectedPacks);
            installer.InstallationRecordRepository.WorkloadInstallRecord.Should().BeEmpty();
        }
 public void WriteWorkloadInstallationRecord(WorkloadId workloadId, SdkFeatureBand sdkFeatureBand) => throw new System.NotImplementedException();
Esempio n. 19
0
 /// <summary>
 /// Sends an <see cref="InstallRequestMessage"/> to create or delete a workload installation record.
 /// </summary>
 /// <param name="requestType">The action to perform on the workload record.</param>
 /// <param name="workloadId">The workload identifier.</param>
 /// <param name="sdkFeatureBand">The SDK feature band associated with the record.</param>
 /// <returns></returns>
 public InstallResponseMessage SendWorkloadRecordRequest(InstallRequestType requestType, WorkloadId workloadId, SdkFeatureBand sdkFeatureBand)
 {
     return(Send(new InstallRequestMessage
     {
         RequestType = requestType,
         WorkloadId = workloadId.ToString(),
         SdkFeatureBand = sdkFeatureBand.ToString(),
     }));
 }
 public void DeleteWorkloadInstallationRecord(WorkloadId workloadId, SdkFeatureBand sdkFeatureBand)
 {
     WorkloadInstallRecord.Remove(workloadId);
 }
Esempio n. 21
0
 public BatchedExecuteResult(WorkloadId workloadId, BatchList batchedElapsed)
 {
     WorkloadId     = workloadId;
     BatchedElapsed = batchedElapsed;
 }
Esempio n. 22
0
 public bool IsWorkloadPlatformCompatible(WorkloadId workloadId) => throw new NotImplementedException();
Esempio n. 23
0
 public bool IsPlatformIncompatibleWorkload(WorkloadId workloadId) => throw new NotImplementedException();
Esempio n. 24
0
 public IEnumerable <WorkloadPackId> GetPacksInWorkload(WorkloadId workloadId) => throw new NotImplementedException();