-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Azure Backup One SDK #1373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Backup One SDK #1373
Changes from 74 commits
ee4de5f
4aba273
c82ea41
6857479
f837a2c
35c3677
561354d
7a9ee68
26ca58e
4c8ee62
0d9acd5
1465664
7a5f6bb
3626db8
c73a228
a4b3acc
85e7612
e6224a5
b691a62
ea7d984
b7573e3
05b3490
b3f3f2f
6d3191c
7401f64
effb8a7
f851a82
12d0233
8d13797
90c26fc
8897421
5890fc8
5509500
3bb2bc9
e3c58a0
281f051
518374d
76743d9
0ae05a9
8302653
fd3398f
ab5297a
eca5768
af749ff
f543ab7
aab279c
9ef967d
b7bfd47
b52422a
a4f6def
9a73ea6
616682b
d31970b
b1e14d6
936f5d6
085ce88
0cc03c4
d48e493
3090dfa
667a47b
2f7083d
626ee17
3150829
cdcd4ca
18d2cbb
89a5ded
56894d4
1aee963
a48e020
2d1bba2
18b5d72
0efb71c
7b8244c
00e6000
d03fa19
9e72a5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| using Microsoft.Azure.Management.BackupServices; | ||
| using Microsoft.Azure.Management.BackupServices.Models; | ||
| using Microsoft.Azure.Test; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Configuration; | ||
| using System.Linq; | ||
| using System.Net; | ||
| using System.Text; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace BackupServices.Tests | ||
| { | ||
| public class AzureBackupItemTests : BackupServicesTestsBase | ||
| { | ||
| [Fact] | ||
| public void EnableAzureBackupProtectionTest() | ||
| { | ||
| using (UndoContext context = UndoContext.Current) | ||
| { | ||
| var client = GetServiceClient<BackupServicesManagementClient>(); | ||
| context.Start(); | ||
| SetProtectionRequestInput input = new SetProtectionRequestInput(); | ||
| input.PolicyId = ConfigurationManager.AppSettings["PolicyId"]; | ||
| input.ProtectableObjects.Add(ConfigurationManager.AppSettings["AzureBackupItemName"]); | ||
| input.ProtectableObjectType = ConfigurationManager.AppSettings["DataSourceType"]; | ||
| var response = client.DataSource.EnableProtection(GetCustomRequestHeaders(), input); | ||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void DisableAzureBackupProtectionTest() | ||
| { | ||
| using (UndoContext context = UndoContext.Current) | ||
| { | ||
| var client = GetServiceClient<BackupServicesManagementClient>(); | ||
| context.Start(); | ||
| RemoveProtectionRequestInput input1 = new RemoveProtectionRequestInput(); | ||
| input1.RemoveProtectionOption = "RetainBackupData"; | ||
| string containerName = ConfigurationManager.AppSettings["ContainerName"]; | ||
| string dataSourceType = ConfigurationManager.AppSettings["DataSourceType"]; | ||
| string dataSourceId = ConfigurationManager.AppSettings["DataSourceId"]; | ||
| var response = client.DataSource.DisableProtection(GetCustomRequestHeaders(), | ||
| containerName, | ||
| dataSourceType, | ||
| dataSourceId, | ||
| input1); | ||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ListAzureBackupItemPOTest() | ||
| { | ||
| using (UndoContext context = UndoContext.Current) | ||
| { | ||
| context.Start(); | ||
|
|
||
| POQueryParameter POQueryParam = new POQueryParameter() | ||
| { | ||
| Status = null, | ||
| Type = null | ||
| }; | ||
|
|
||
| var client = GetServiceClient<BackupServicesManagementClient>(); | ||
|
|
||
| var response = client.ProtectableObject.ListAsync(POQueryParam, GetCustomRequestHeaders()).Result; | ||
|
|
||
| Assert.True(response.ProtectableObject.ResultCount > 0, "Protectable Object Result count can't be less than 1"); | ||
|
|
||
| foreach (var po in response.ProtectableObject.Objects) | ||
| { | ||
| Assert.True(!string.IsNullOrEmpty(po.ContainerName), "ContainerName can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.ContainerType), "ContainerType can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.FriendlyName), "FriendlyName can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.Type), "Type can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.InstanceId), "Name can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.Name), "Name can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.ParentContainerFriendlyName), "ParentContainerFriendlyName can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.ParentContainerName), "ParentContainerName can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(po.ProtectionStatus), "ProtectionStatus can't be null or empty"); | ||
| } | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void ListAzureBackupItemDSTest() | ||
| { | ||
| using (UndoContext context = UndoContext.Current) | ||
| { | ||
| context.Start(); | ||
|
|
||
| DataSourceQueryParameter DSQueryParam = new DataSourceQueryParameter() | ||
| { | ||
| ProtectionStatus = null, | ||
| Status = null, | ||
| Type = null | ||
| }; | ||
|
|
||
| var client = GetServiceClient<BackupServicesManagementClient>(); | ||
|
|
||
| var response = client.DataSource.ListAsync(DSQueryParam, GetCustomRequestHeaders()).Result; | ||
| foreach (var ds in response.DataSources.Objects) | ||
| { | ||
| Assert.True(!string.IsNullOrEmpty(ds.ContainerName), "ContainerName can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.ContainerType), "ContainerType can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.FriendlyName), "FriendlyName can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.Type), "Type can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.RecoveryPointsCount.ToString()), "RecoveryPointsCount can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.ProtectableObjectName), "ProtectableObjectName can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.InstanceId), "Name can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.Name), "WorkloadType can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.ProtectionStatus), "ProtectionStatus can't be null or empty"); | ||
| Assert.True(!string.IsNullOrEmpty(ds.Status), "Status can't be null or empty"); ; | ||
| } | ||
|
|
||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using Microsoft.Azure.Management.BackupServices.Models; | ||
| using Microsoft.Azure.Management.BackupServices; | ||
| using Microsoft.Azure.Test; | ||
| using System.Net; | ||
| using Xunit; | ||
| using System.Configuration; | ||
| using System; | ||
|
|
||
| namespace BackupServices.Tests | ||
| { | ||
| public class BackUpTests : BackupServicesTestsBase | ||
| { | ||
| [Fact] | ||
| public void TriggerBackUpTest() | ||
| { | ||
| using (UndoContext context = UndoContext.Current) | ||
| { | ||
| context.Start(); | ||
| var client = GetServiceClient<BackupServicesManagementClient>(); | ||
|
|
||
| string containerName = ConfigurationManager.AppSettings["ContainerName"]; | ||
| string dataSourceType = ConfigurationManager.AppSettings["DataSourceType"]; | ||
| string dataSourceId = ConfigurationManager.AppSettings["DataSourceId"]; | ||
|
|
||
| var response = client.BackUp.TriggerBackUp(GetCustomRequestHeaders(), containerName, dataSourceType, dataSourceId); | ||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
|
|
||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Net; | ||
| using System.Security.Cryptography; | ||
| using System.Text; | ||
| using Microsoft.Azure.Management.BackupServices; | ||
| using Microsoft.Azure.Management.BackupServices.Models; | ||
| using Microsoft.Azure.Common.Internals; | ||
| using Hyak.Common.TransientFaultHandling; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.IO; | ||
| using System.Xml; | ||
| using Xunit; | ||
| using Microsoft.Azure.Test; | ||
| using Newtonsoft.Json; | ||
| using Microsoft.Azure.Test.HttpRecorder; | ||
| using System.Configuration; | ||
| using Microsoft.Azure; | ||
| using System.Reflection; | ||
| using System.Net.Http; | ||
| using System.Net.Security; | ||
|
|
||
| namespace BackupServices.Tests | ||
| { | ||
| public class BackupServicesTestsBase : TestBase | ||
| { | ||
| public new static T GetServiceClient<T>() where T : class | ||
| { | ||
| var factory = (TestEnvironmentFactory)new CSMTestEnvironmentFactory(); | ||
|
|
||
| var testEnvironment = factory.GetTestEnvironment(); | ||
| //testEnvironment.BaseUri = new Uri("https://localhost:8443/RdfeProxy.svc/"); | ||
| ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; | ||
|
|
||
| BackupServicesManagementClient client; | ||
|
|
||
| string resourceName = ConfigurationManager.AppSettings["ResourceName"]; | ||
| string resourceGroupName = ConfigurationManager.AppSettings["ResourceGroupName"]; | ||
| if (testEnvironment.UsesCustomUri()) | ||
| { | ||
| client = new BackupServicesManagementClient( | ||
| resourceName, | ||
| resourceGroupName, | ||
| testEnvironment.Credentials as SubscriptionCloudCredentials, | ||
| testEnvironment.BaseUri); | ||
| } | ||
|
|
||
| else | ||
| { | ||
| client = new BackupServicesManagementClient( | ||
| resourceName, | ||
| resourceGroupName, | ||
| testEnvironment.Credentials as SubscriptionCloudCredentials); | ||
| } | ||
|
|
||
| return GetServiceClient<T>(factory, client); | ||
| } | ||
|
|
||
|
|
||
| public static T GetServiceClient<T>(TestEnvironmentFactory factory, BackupServicesManagementClient client) where T : class | ||
| { | ||
| TestEnvironment testEnvironment = factory.GetTestEnvironment(); | ||
|
|
||
| HttpMockServer instance; | ||
| try | ||
| { | ||
| instance = HttpMockServer.CreateInstance(); | ||
| } | ||
| catch (ApplicationException) | ||
| { | ||
| HttpMockServer.Initialize("TestEnvironment", "InitialCreation"); | ||
| instance = HttpMockServer.CreateInstance(); | ||
| } | ||
| T obj2 = typeof(T).GetMethod("WithHandler", new Type[1] | ||
| { | ||
| typeof (DelegatingHandler) | ||
| }).Invoke((object)client, new object[1] | ||
| { | ||
| (object) instance | ||
| }) as T; | ||
|
|
||
| if (HttpMockServer.Mode == HttpRecorderMode.Record) | ||
| { | ||
| HttpMockServer.Variables[TestEnvironment.SubscriptionIdKey] = testEnvironment.SubscriptionId; | ||
| } | ||
|
|
||
| if (HttpMockServer.Mode == HttpRecorderMode.Playback) | ||
| { | ||
| PropertyInfo property1 = typeof(T).GetProperty("LongRunningOperationInitialTimeout", typeof(int)); | ||
| PropertyInfo property2 = typeof(T).GetProperty("LongRunningOperationRetryTimeout", typeof(int)); | ||
| if (property1 != (PropertyInfo)null && property2 != (PropertyInfo)null) | ||
| { | ||
| property1.SetValue((object)obj2, (object)0); | ||
| property2.SetValue((object)obj2, (object)0); | ||
| } | ||
| } | ||
| return obj2; | ||
| } | ||
|
|
||
| private static bool IgnoreCertificateErrorHandler | ||
| (object sender, | ||
| System.Security.Cryptography.X509Certificates.X509Certificate certificate, | ||
| System.Security.Cryptography.X509Certificates.X509Chain chain, | ||
| SslPolicyErrors sslPolicyErrors) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| public static CustomRequestHeaders GetCustomRequestHeaders() | ||
| { | ||
| return new CustomRequestHeaders() | ||
| { | ||
| ClientRequestId = Guid.NewGuid().ToString(), | ||
| }; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| using Microsoft.Azure.Management.BackupServices; | ||
|
||
| using Microsoft.Azure.Management.BackupServices.Models; | ||
| using Microsoft.Azure.Test; | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Net; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
| using System.Configuration; | ||
| using BackupServices.Tests.Helpers; | ||
|
|
||
| namespace BackupServices.Tests | ||
| { | ||
| public class ContainerTests : BackupServicesTestsBase | ||
| { | ||
| [Fact] | ||
| public void ListContainersReturnsValidResponseTest() | ||
| { | ||
| using (UndoContext undoContext = UndoContext.Current) | ||
| { | ||
| undoContext.Start(); | ||
|
|
||
| BackupServicesManagementClient client = GetServiceClient<BackupServicesManagementClient>(); | ||
|
|
||
| ListContainerResponse response = client.Container.List(string.Empty, GetCustomRequestHeaders()); | ||
|
|
||
| // Response Validation | ||
| Assert.NotNull(response); | ||
| Assert.Equal(HttpStatusCode.OK, response.StatusCode); | ||
| Assert.True(response.ResultCount > 0, "Should return at least one container"); | ||
| Assert.True(response.Objects.Count > 0, "Should return at least one container"); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void RegisterContainersReturnsValidResponseTest() | ||
| { | ||
| using (UndoContext undoContext = UndoContext.Current) | ||
| { | ||
| undoContext.Start(); | ||
|
|
||
| BackupServicesManagementClient client = GetServiceClient<BackupServicesManagementClient>(); | ||
| string containerName = ConfigurationManager.AppSettings["ContainerName"]; | ||
| var inputRequest = new RegisterContainerRequestInput(); | ||
| inputRequest.ContainerType = "IaasVMContainer"; | ||
| inputRequest.ContainerUniqueNameList = new List<string>(); | ||
| inputRequest.ContainerUniqueNameList.Add(containerName); | ||
|
|
||
| var response = client.Container.Register(inputRequest, GetCustomRequestHeaders()); | ||
|
|
||
| // Response Validation | ||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| Assert.NotNull(response); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void UnRegisterContainersReturnsValidResponseTest() | ||
| { | ||
| using (UndoContext undoContext = UndoContext.Current) | ||
| { | ||
| undoContext.Start(); | ||
|
|
||
| BackupServicesManagementClient client = GetServiceClient<BackupServicesManagementClient>(); | ||
| string containerName = ConfigurationManager.AppSettings["ContainerName"]; | ||
| var inputRequest = new UnregisterContainerRequestInput(); | ||
| inputRequest.ContainerType = "IaasVMContainer"; | ||
| inputRequest.ContainerUniqueName = containerName; | ||
|
|
||
| var response = client.Container.Unregister(inputRequest, GetCustomRequestHeaders()); | ||
|
|
||
| // Response Validation | ||
| Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); | ||
| Assert.NotNull(response); | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not put the folder under root, unless you have good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain how you want the folder structure to be ?