Пример #1
0
        /// <summary>
        /// To get provider instance using provider type.
        /// </summary>
        public IPsBackupProvider GetProviderInstance(PsBackupProviderTypes providerType)
        {
            IPsBackupProvider psBackupProvider = null;

            switch (providerType)
            {
            case PsBackupProviderTypes.IaasVm:
                psBackupProvider = new IaasVmPsBackupProvider();
                break;

            case PsBackupProviderTypes.Mab:
                psBackupProvider = new MabPsBackupProvider();
                break;

            case PsBackupProviderTypes.Dpm:
                psBackupProvider = new DpmPsBackupProvider();
                break;

            default:
                break;
            }

            psBackupProvider.Initialize(providerData, serviceClientAdapter);

            return(psBackupProvider);
        }
Пример #2
0
        /// <summary>
        /// Gets an instance of the provider based on the container type and backup management type (optional)
        /// </summary>
        /// <param name="containerType">Type of the container</param>
        /// <param name="backupManagementType">Type of the backup management type (optional)</param>
        /// <returns></returns>
        public IPsBackupProvider GetProviderInstance
        (
            ContainerType containerType,
            BackupManagementType?backupManagementType
        )
        {
            PsBackupProviderTypes providerType = 0;

            switch (containerType)
            {
            case ContainerType.AzureVM:
                if (backupManagementType == BackupManagementType.AzureVM || backupManagementType == null)
                {
                    providerType = PsBackupProviderTypes.IaasVm;
                }
                else
                {
                    throw new ArgumentException(
                              String.Format(Resources.BackupManagementTypeIncorrectForContainerType,
                                            containerType)
                              );
                }
                break;

            case ContainerType.Windows:
                if (backupManagementType == BackupManagementType.MARS)
                {
                    providerType = PsBackupProviderTypes.Mab;
                }
                else if (backupManagementType == null)
                {
                    throw new ArgumentException(
                              String.Format(
                                  Resources.BackupManagementTypeRequiredForContainerType,
                                  containerType)
                              );
                }
                else
                {
                    throw new ArgumentException(
                              String.Format(
                                  Resources.BackupManagementTypeIncorrectForContainerType,
                                  containerType)
                              );
                }
                break;

            default:
                throw new ArgumentException(
                          String.Format(Resources.UnsupportedContainerType,
                                        containerType.ToString())
                          );
            }

            return(GetProviderInstance(providerType));
        }
Пример #3
0
        public void RunPsTest(PsBackupProviderTypes providerType, params string[] scripts)
        {
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            RunPsTestWorkflow(
                providerType,
                () => scripts,
                // no custom initializer
                null,
                // no custom cleanup
                null,
                callingClassType,
                mockName);
        }
Пример #4
0
        public Collection <PSObject> RunPsTest(XunitTracingInterceptor logger, PsBackupProviderTypes providerType, params string[] scripts)
        {
            var sf = new StackTrace().GetFrame(1);
            var callingClassType = sf.GetMethod().ReflectedType?.ToString();
            var mockName         = sf.GetMethod().Name;

            _helper.TracingInterceptor = logger;

            return(RunPsTestWorkflow(
                       providerType,
                       () => scripts,
                       // no custom cleanup
                       null,
                       callingClassType,
                       mockName));
        }
Пример #5
0
        public Collection <PSObject> RunPsTest(XunitTracingInterceptor logger, PsBackupProviderTypes providerType, params string[] scripts)
        {
            var callingClassType = TestUtilities.GetCallingClass(2);
            var mockName         = TestUtilities.GetCurrentMethodName(2);

            helper.TracingInterceptor = logger;

            return(RunPsTestWorkflow(
                       providerType,
                       () => scripts,
                       // no custom initializer
                       null,
                       // no custom cleanup
                       null,
                       callingClassType,
                       mockName));
        }
        /// <summary>
        /// To get provider instance using workload type.
        /// </summary>
        public IPsBackupProvider GetProviderInstance(WorkloadType workloadType)
        {
            PsBackupProviderTypes providerType = 0;

            switch (workloadType)
            {
            case WorkloadType.AzureVM:
                providerType = PsBackupProviderTypes.IaasVm;
                break;

            default:
                throw new ArgumentException(
                          String.Format(Resources.BackupManagementTypeRequiredForWorkloadType,
                                        workloadType.ToString()));
            }

            return(GetProviderInstance(providerType));
        }
Пример #7
0
        public Collection <PSObject> RunPsTestWorkflow(
            PsBackupProviderTypes providerType,
            Func <string[]> scriptBuilder,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            var providers = new Dictionary <string, string>
            {
                { "Microsoft.Resources", null },
                { "Microsoft.Features", null },
                { "Microsoft.Authorization", null },
                { "Microsoft.Compute", null },
                { "Microsoft.Network", null },
                { "Microsoft.Storage", null }
            };
            var providersToIgnore = new Dictionary <string, string>
            {
                { "Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01" },
                { "Microsoft.Azure.Management.Internal.Resources.ResourceManagementClient", "2016-02-01" }
            };

            HttpMockServer.Matcher          = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore);
            HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

            using (var context = MockContext.Start(callingClassType, mockName))
            {
                SetupManagementClients(context);

                _helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var testFolderName   = providerType.ToString();
                var callingClassName = callingClassType.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                var commonPsFile     = "ScenarioTests\\" + testFolderName + "\\Common.ps1";

                var modules = new List <string>
                {
                    "ScenarioTests\\" + testFolderName + "\\" + callingClassName + ".ps1",
                    _helper.RMProfileModule,
                    _helper.GetRMModulePath("AzureRM.RecoveryServices.psd1"),
                    _helper.RMResourceModule,
#if !NETSTANDARD
                    _helper.GetRMModulePath("AzureRM.RecoveryServices.Backup.psd1"),
                    _helper.RMStorageDataPlaneModule,
#endif
                    _helper.RMStorageModule,
                    _helper.GetRMModulePath("AzureRM.Compute.psd1"),
                    _helper.GetRMModulePath("AzureRM.Network.psd1"),
                    "AzureRM.Storage.ps1",
                    "AzureRM.Resources.ps1"
                };

                if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, commonPsFile)))
                {
                    modules.Add(commonPsFile);
                }


                _helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());

                try
                {
                    var psScripts = scriptBuilder?.Invoke();
                    if (psScripts != null)
                    {
                        return(_helper.RunPowerShellTest(psScripts));
                    }
                }
                finally
                {
                    cleanup?.Invoke();
                }
            }

            return(null);
        }
Пример #8
0
        public void RunPsTestWorkflow(
            PsBackupProviderTypes providerType,
            Func <string[]> scriptBuilder,
            Action <CSMTestEnvironmentFactory> initialize,
            Action cleanup,
            string callingClassType,
            string mockName)
        {
            Dictionary <string, string> providers = new Dictionary <string, string>();

            providers.Add("Microsoft.Resources", null);
            providers.Add("Microsoft.Features", null);
            providers.Add("Microsoft.Authorization", null);
            providers.Add("Microsoft.Compute", null);
            var providersToIgnore = new Dictionary <string, string>();

            providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
            HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, providers, providersToIgnore);

            HttpMockServer.RecordsDirectory =
                Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");

            using (RestTestFramework.MockContext context =
                       RestTestFramework.MockContext.Start(callingClassType, mockName))
            {
                csmTestFactory = new CSMTestEnvironmentFactory();

                if (initialize != null)
                {
                    initialize.Invoke(csmTestFactory);
                }

                SetupManagementClients(context);

                helper.SetupEnvironment(AzureModule.AzureResourceManager);

                var testFolderName   = providerType.ToString();
                var callingClassName =
                    callingClassType
                    .Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries).Last();
                string psFile =
                    "ScenarioTests\\" + testFolderName + "\\" + callingClassName + ".ps1";
                string commonPsFile               = "ScenarioTests\\" + testFolderName + "\\Common.ps1";
                string rmProfileModule            = helper.RMProfileModule;
                string rmModulePath               = helper.GetRMModulePath("AzureRM.RecoveryServices.Backup.psd1");
                string recoveryServicesModulePath =
                    helper.GetRMModulePath("AzureRM.RecoveryServices.psd1");

                List <string> modules = new List <string>();

                if (File.Exists(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, commonPsFile)))
                {
                    modules.Add(commonPsFile);
                }

                modules.Add(psFile);
                modules.Add(rmProfileModule);
                modules.Add(rmModulePath);
                modules.Add(recoveryServicesModulePath);

                helper.SetupModules(AzureModule.AzureResourceManager, modules.ToArray());

                try
                {
                    if (scriptBuilder != null)
                    {
                        var psScripts = scriptBuilder();

                        if (psScripts != null)
                        {
                            helper.RunPowerShellTest(psScripts);
                        }
                    }
                }
                finally
                {
                    if (cleanup != null)
                    {
                        cleanup.Invoke();
                    }
                }
            }
        }
        /// <summary>
        /// To get provider instance using provider type.
        /// </summary>
        public IPsBackupProvider GetProviderInstance(PsBackupProviderTypes providerType)
        {
            IPsBackupProvider psBackupProvider = null;

            switch (providerType)
            {
                case PsBackupProviderTypes.IaasVm:
                    psBackupProvider = new IaasVmPsBackupProvider();
                    break;
                case PsBackupProviderTypes.Mab:
                    psBackupProvider = new MabPsBackupProvider();
                    break;
                case PsBackupProviderTypes.Dpm:
                    psBackupProvider = new DpmPsBackupProvider();
                    break;
                default:
                    break;
            }

            psBackupProvider.Initialize(providerData, serviceClientAdapter);

            return psBackupProvider;
        }