protected override void EndProcessing()
        {
            if (ParameterSetName == RemountParamSet)
            {
                AsyncWait(_client.RemountSecretBackendAsync(OldMountName, NewMountName));
            }
            else
            {
                if (string.IsNullOrEmpty(MountName))
                {
                    MountName = Type;
                }

                MountConfiguration mc = null;
                if (!string.IsNullOrEmpty(DefaultLeaseTtl) || !string.IsNullOrEmpty(MaxLeaseTtl))
                {
                    mc = new MountConfiguration
                    {
                        DefaultLeaseTtl = DefaultLeaseTtl,
                        MaximumLeaseTtl = MaxLeaseTtl,
                    };
                }

                var sb = new SecretBackend
                {
                    BackendType        = new SecretBackendType(Type),
                    MountPoint         = MountName,
                    Description        = Description,
                    MountConfiguration = mc,
                };

                AsyncWait(_client.MountSecretBackendAsync(sb));
            }
        }
        public void GetConfigurationForAssetStreamingReturnsCorrectCombination()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_localDirStreaming);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(configuration, Is.EqualTo(MountConfiguration.LocalStreaming));
        }
        public void GetConfigurationForPackageRanDirectlyReturnsCorrectCombination()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_packageRanDirectly);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(configuration, Is.EqualTo(MountConfiguration.RunFromPackage));
        }
        public void GetConfigurationForCorruptedFileReturnsNone()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_corruptedFile);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(configuration, Is.EqualTo(MountConfiguration.None));
        }
        public void GetConfigurationForMountedWithNoOverlayReturnsCorrectCombination()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_mountedWithNoOverlay);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(configuration, Is.EqualTo(MountConfiguration.PackageMounted));
        }
        public void GetConfigurationForEmptyFileReturnsNone()
        {
            var emptyContent = new List <string>();
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(emptyContent);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(configuration, Is.EqualTo(MountConfiguration.None));
        }
        public void IsGameAssetsDetachedFromDeveloperFolderForPackageWithLocalDirAsOverlayIsFalse()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_localDirStreamingAsOverlay);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(mountChecker.IsGameAssetsDetachedFromDeveloperFolder(configuration),
                        Is.False);
        }
        public void IsGameAssetsDetachedFromDeveloperFolderForCleanStateIsFalse()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_cleanGamelet);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(mountChecker.IsGameAssetsDetachedFromDeveloperFolder(configuration),
                        Is.False);
        }
        public void IsGameAssetsDetachedFromDeveloperFolderAfterPackageRunIsTrue()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_packageRanDirectly);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(mountChecker.IsGameAssetsDetachedFromDeveloperFolder(configuration),
                        Is.True);
        }
        public void IsGameAssetsDetachedFromDeveloperFolderForMountWithoutOverlayIsTrue()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_mountedWithNoOverlay);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(mountChecker.IsGameAssetsDetachedFromDeveloperFolder(configuration),
                        Is.True);
        }
        public void GetConfigurationForMountedWithLocalFolderAsOverlayReturnsCorrectCombination()
        {
            GameletMountChecker mountChecker =
                CreateMountCheckerWithSpecifiedProcMountsInfo(_localDirStreamingAsOverlay);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);

            Assert.That(configuration,
                        Is.EqualTo(MountConfiguration.PackageMounted | MountConfiguration.Overlay |
                                   MountConfiguration.LocalStreaming));
        }
        protected override void EndProcessing()
        {
            MountConfiguration mc = null;

            if (!string.IsNullOrEmpty(DefaultLeaseTtl) || !string.IsNullOrEmpty(MaxLeaseTtl))
            {
                mc = new MountConfiguration
                {
                    DefaultLeaseTtl = DefaultLeaseTtl,
                    MaximumLeaseTtl = MaxLeaseTtl,
                };
            }

            AsyncWait(_client.TuneSecretBackendConfigurationAsync(MountName, mc));
        }
        public void TestCheckMountConfigurationWhenFailedSshIsFalseAndWarningShowed()
        {
            _remoteCommand
            .When(c => c.RunWithSuccessCapturingOutputAsync(Arg.Any <SshTarget>(),
                                                            Arg.Any <string>()))
            .Do(_ => throw new ProcessExecutionException("oops", 1));

            var mountChecker =
                new GameletMountChecker(_remoteCommand, _dialogUtil, _cancelableTaskFactory);

            MountConfiguration configuration =
                mountChecker.GetConfiguration(_gamelet, _actionRecorder);
            bool result = mountChecker.IsGameAssetsDetachedFromDeveloperFolder(configuration);

            Assert.That(result, Is.False);
            _dialogUtil.Received(1).ShowError(Arg.Any <string>(), Arg.Any <string>());
        }
Example #14
0
        public MountConfiguration GetConfiguration(Gamelet gamelet, ActionRecorder actionRecorder)
        {
            MountConfiguration mountConfiguration = MountConfiguration.None;
            List <string>      mountsInfo         = ReadMountsContentOrDefault(gamelet, actionRecorder);

            if (mountsInfo.Count == 0)
            {
                return(mountConfiguration);
            }

            Dictionary <string, Device> devices = GetDevices(mountsInfo);
            Device gameAssetsDevice             = devices[YetiConstants.GameAssetsMountingPoint];
            Device developerDevice = devices[YetiConstants.DeveloperMountingPoint];
            Device packageDevice   = devices[YetiConstants.PackageMountingPoint];

            if (gameAssetsDevice?.FileSystemType.Equals(_overlayFileSystem, _comparisonType)
                ?? false)
            {
                mountConfiguration |= MountConfiguration.Overlay;
            }

            if (developerDevice?.FileSystemType.Equals(_sshFileSystem, _comparisonType) ?? false)
            {
                mountConfiguration |= MountConfiguration.LocalStreaming;
            }

            if (string.IsNullOrWhiteSpace(packageDevice?.Address))
            {
                if (gameAssetsDevice == null || developerDevice == null)
                {
                    return(mountConfiguration);
                }

                if (!gameAssetsDevice.Address.Equals(developerDevice.Address, _comparisonType))
                {
                    mountConfiguration |= MountConfiguration.RunFromPackage;
                }
            }
            else
            {
                mountConfiguration |= MountConfiguration.PackageMounted;
            }

            return(mountConfiguration);
        }
Example #15
0
        /// <summary>
        /// Check whether the deployment configuration of the binary works correctly
        /// with the mount configuration of the gamelet.
        /// </summary>
        /// <param name="targetPath">Path to the generated binary.</param>
        /// <param name="deployOnLaunchSetting">Project's "Deploy On Launch" value.</param>
        /// <param name="gamelet">Gamelet to connect to.</param>
        /// <returns>True if no issues found or the user decided to proceed.</returns>
        bool ValidateMountConfiguration(string targetPath,
                                        DeployOnLaunchSetting deployOnLaunchSetting,
                                        Gamelet gamelet)
        {
            MountConfiguration configuration =
                _mountChecker.GetConfiguration(gamelet, _actionRecorder);

            string targetPathNormalized = GetNormalizedFullPath(targetPath);

            Trace.WriteLine($"TargetPath is set to {targetPathNormalized}");
            // If the /srv/game/assets folder is detached from /mnt/developer then
            // binaries generated by VS won't be used during the run/debug process.
            // Notify the user and let them decide whether this is expected behaviour or not.
            if (_mountChecker.IsGameAssetsDetachedFromDeveloperFolder(configuration))
            {
                // 'Yes' - continue; 'No' - interrupt (gamelet validation fails).
                return(_dialogUtil.ShowYesNo(
                           ErrorStrings.MountConfigurationWarning(YetiConstants.GameAssetsMountingPoint,
                                                                  YetiConstants.DeveloperMountingPoint),
                           _mountConfigurationDialogCaption));
            }

            if (_mountChecker.IsAssetStreamingActivated(configuration))
            {
                var sshChannels = new SshTunnels();
                IEnumerable <string> commandLines = sshChannels.GetSshCommandLines();
                string[]             mountPoints  = sshChannels.ExtractMountingPoints(commandLines).ToArray();

                if (mountPoints.Length == 0)
                {
                    // If asset streaming is set up on the gamelet but there is no ssh tunnels
                    // between the workstation and the gamelet then the connection was
                    // probably lost (or asset streaming is set to a different machine, and
                    // then it's ok).
                    // 'Yes' - continue; 'No' - interrupt (gamelet validation fails).
                    return(_dialogUtil.ShowYesNo(ErrorStrings.AssetStreamingBrokenWarning(),
                                                 _mountConfigurationDialogCaption));
                }

                if (deployOnLaunchSetting != DeployOnLaunchSetting.FALSE)
                {
                    foreach (string mountPoint in mountPoints)
                    {
                        string mountPointNormalized = GetNormalizedFullPath(mountPoint);
                        if (targetPathNormalized.StartsWith($@"{mountPointNormalized}\"))
                        {
                            // The mount point folder matches the output folder for the binaries;
                            // VS will try to upload the binaries to the gamelet and this might lead
                            // to an exception during 'scp' call. Instead, asset streaming should
                            // take care of uploading the generated data to the gamelet. 'Yes' -
                            // continue; 'No' - interrupt (gamelet validation fails).
                            string current  = GgpDeployOnLaunchToDisplayName(deployOnLaunchSetting);
                            string expected =
                                GgpDeployOnLaunchToDisplayName(DeployOnLaunchSetting.FALSE);
                            return(_dialogUtil.ShowYesNo(
                                       ErrorStrings.AssetStreamingDeployWarning(mountPointNormalized,
                                                                                current, expected), _mountConfigurationDialogCaption));
                        }
                    }
                }
            }

            return(true);

            string GetNormalizedFullPath(string path)
            {
                if (string.IsNullOrWhiteSpace(path))
                {
                    return(path);
                }

                string normalizedPath = FileUtil.GetNormalizedPath(path);

                if (File.Exists(normalizedPath) && FileUtil.IsPathSymlink(normalizedPath))
                {
                    string symlinkTarget = NativeMethods.GetTargetPathName(path);
                    return(FileUtil.GetNormalizedPath(symlinkTarget));
                }

                return(normalizedPath);
            }
        }
Example #16
0
 public bool IsAssetStreamingActivated(MountConfiguration currentMountConfiguration) =>
 currentMountConfiguration.HasFlag(MountConfiguration.LocalStreaming);
Example #17
0
 public bool IsGameAssetsDetachedFromDeveloperFolder(
     MountConfiguration currentMountConfiguration) =>
 (currentMountConfiguration == MountConfiguration.RunFromPackage ||
  (currentMountConfiguration.HasFlag(MountConfiguration.PackageMounted) &&
   !currentMountConfiguration.HasFlag(MountConfiguration.Overlay)));