Skip to content

Commit 5166435

Browse files
author
dragonfly91
committed
Adding cmdlets to manage IaaS VM Backup
1 parent ead1b01 commit 5166435

File tree

57 files changed

+3968
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+3968
-7
lines changed

src/ResourceManager/AzureBackup/Commands.AzureBackup.Test/Commands.AzureBackup.Test.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,17 @@
125125
</ItemGroup>
126126
<ItemGroup>
127127
<Compile Include="ScenarioTests\AzureBackupContainerTests.cs" />
128+
<Compile Include="ScenarioTests\AzureBackupItemTestCases.cs" />
129+
<Compile Include="ScenarioTests\AzureBackupJobTests.cs" />
130+
<Compile Include="ScenarioTests\AzureBackupPolicyTests.cs" />
131+
<Compile Include="ScenarioTests\AzureBackupScenarioTests.cs" />
128132
<Compile Include="ScenarioTests\AzureBackupTestBase.cs" />
129133
<Compile Include="Properties\AssemblyInfo.cs" />
130134
<Compile Include="ScenarioTests\AzureBackupVaultTests.cs">
131135
<SubType>Code</SubType>
132136
</Compile>
137+
<Compile Include="ScenarioTests\BackupItemTests.cs" />
138+
<Compile Include="ScenarioTests\RecoveryPointTests.cs" />
133139
</ItemGroup>
134140
<ItemGroup>
135141
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">
@@ -158,9 +164,15 @@
158164
<None Include="ScenarioTests\AzureBackupContainerTests.ps1">
159165
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
160166
</None>
167+
<None Include="ScenarioTests\AzureBackupItemTestCases.ps1" />
168+
<None Include="ScenarioTests\AzureBackupJobTests.ps1" />
169+
<None Include="ScenarioTests\AzureBackupPolicyTests.ps1" />
170+
<None Include="ScenarioTests\AzureBackupScenarioTests.ps1" />
161171
<None Include="ScenarioTests\AzureBackupVaultTests.ps1">
162172
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
163173
</None>
174+
<None Include="ScenarioTests\BackupItemTests.ps1" />
175+
<None Include="ScenarioTests\RecoveryPointTests.ps1" />
164176
<None Include="SessionRecords\Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests.AzureBackupContainerTests\AzureBackupMarsContainerScenarioTests.json">
165177
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
166178
</None>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests
19+
{
20+
public class AzureBackupItemTestCases : AzureBackupTestsBase
21+
{
22+
[Fact]
23+
public void ListAzureBackupItemTests()
24+
{
25+
this.RunPowerShellTest("Test-GetAzureBackupItemTests");
26+
}
27+
28+
[Fact]
29+
public void EnableAzureBackupProtectionTest()
30+
{
31+
this.RunPowerShellTest("Test-EnableAzureBackupProtection");
32+
}
33+
34+
[Fact]
35+
public void DisableAzureBackupProtectionTest()
36+
{
37+
this.RunPowerShellTest("Test-DisableAzureBackupProtection");
38+
}
39+
}
40+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
$ResourceGroupName = "backuprg"
2+
$ResourceName = "backuprn"
3+
$ContainerName = "iaasvmcontainer;dev01testing;dev01testing"
4+
$ContainerType = "IaasVMContainer"
5+
$DataSourceType = "VM"
6+
$DataSourceId = "17593283453810"
7+
$Location = "SouthEast Asia"
8+
$PolicyName = "Policy9";
9+
$PolicyId = "c87bbada-6e1b-4db2-b76c-9062d28959a4";
10+
$POName = "iaasvmcontainer;dev01testing;dev01testing"
11+
12+
13+
function Test-GetAzureBackupItemTests
14+
{
15+
$azureBackUpContainer = New-Object Microsoft.Azure.Commands.AzureBackup.Models.AzureBackupContainer
16+
$azureBackUpContainer.ResourceGroupName = $ResourceGroupName
17+
$azureBackUpContainer.ResourceName = $ResourceName
18+
$azureBackUpContainer.Location = $Location
19+
$azureBackUpContainer.ContainerUniqueName = $ContainerName
20+
$azureBackUpContainer.ContainerType = $ContainerType
21+
$item = Get-AzureBackupItem -Container $azureBackUpContainer
22+
if (!($item -eq $null))
23+
{
24+
foreach($backupitem in $item)
25+
{
26+
Assert-NotNull $backupitem.ProtectionStatus 'ProtectionStatus should not be null'
27+
Assert-NotNull $backupitem.Name 'Name should not be null'
28+
Assert-NotNull $backupitem.Type 'Type should not be null'
29+
Assert-NotNull $backupitem.ContainerType 'ContainerType should not be null'
30+
Assert-NotNull $backupitem.ContainerUniqueName 'ContainerUniqueName should not be null'
31+
Assert-NotNull $backupitem.ResourceGroupName 'ResourceGroupName should not be null'
32+
Assert-NotNull $backupitem.ResourceName 'ResourceName should not be null'
33+
Assert-NotNull $backupitem.Location 'Location should not be null'
34+
}
35+
}
36+
}
37+
38+
function Test-EnableAzureBackupProtection
39+
{
40+
$policy = New-Object Microsoft.Azure.Commands.AzureBackup.Models.AzureBackupProtectionPolicy
41+
$policy.InstanceId = $PolicyId
42+
$policy.Name = $PolicyName
43+
$policy.ResourceGroupName = $ResourceGroupName
44+
$policy.ResourceName = $ResourceName
45+
$policy.Location = $Location
46+
$policy.WorkloadType = "VM"
47+
$policy.RetentionType = "1"
48+
$policy.ScheduleRunTimes = "2015-06-13T20:30:00"
49+
50+
$azureBackUpItem = New-Object Microsoft.Azure.Commands.AzureBackup.Models.AzureBackupItem
51+
$azureBackUpItem.ResourceGroupName = $ResourceGroupName
52+
$azureBackUpItem.ResourceName = $ResourceName
53+
$azureBackUpItem.Location = $Location
54+
$azureBackUpItem.ContainerUniqueName = $ContainerName
55+
$azureBackUpItem.ContainerType = $ContainerType
56+
$azureBackUpItem.DataSourceId = $DataSourceId
57+
$azureBackUpItem.Type = $DataSourceType
58+
$azureBackUpItem.Name = $POName
59+
$jobId = Enable-AzureBackupProtection -Item $azureBackUpItem -Policy $policy
60+
61+
}
62+
63+
function Test-DisableAzureBackupProtection
64+
{
65+
$azureBackUpItem = New-Object Microsoft.Azure.Commands.AzureBackup.Models.AzureBackupItem
66+
$azureBackUpItem.ResourceGroupName = $ResourceGroupName
67+
$azureBackUpItem.ResourceName = $ResourceName
68+
$azureBackUpItem.Location = $Location
69+
$azureBackUpItem.ContainerUniqueName = $ContainerName
70+
$azureBackUpItem.ContainerType = $ContainerType
71+
$azureBackUpItem.DataSourceId = $DataSourceId
72+
$azureBackUpItem.Type = $DataSourceType
73+
$azureBackUpItem.Name = $POName
74+
$jobId1 = Disable-AzureBackupProtection -Item $azureBackUpItem
75+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests
19+
{
20+
public class AzureBackupJobTests : AzureBackupTestsBase
21+
{
22+
23+
[Fact]
24+
public void GetAzureBackupJobTests()
25+
{
26+
this.RunPowerShellTest("Test-GetAzureBackupJob");
27+
}
28+
29+
[Fact]
30+
public void StopAzureBackupJobTests()
31+
{
32+
this.RunPowerShellTest("Test-StopAzureBackupJob");
33+
}
34+
}
35+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
$ResourceGroupName = "backuprg"
2+
$ResourceName = "backuprn"
3+
$ContainerName = "iaasvmcontainer;dev01testing;dev01testing"
4+
$ContainerType = "IaasVMContainer"
5+
$DataSourceType = "VM"
6+
$DataSourceId = "17593283453810"
7+
$Location = "SouthEast Asia"
8+
$PolicyName = "Policy9";
9+
$PolicyId = "c87bbada-6e1b-4db2-b76c-9062d28959a4";
10+
$POName = "iaasvmcontainer;dev01testing;dev01testing"
11+
12+
13+
function Test-GetAzureBackupJob
14+
{
15+
$vault = Get-AzureBackupVault -Name $ResourceName;
16+
$OneMonthBack = Get-Date;
17+
$OneMonthBack = $OneMonthBack.AddDays(-30);
18+
$jobs = Get-AzureBackupJob -Vault $vault -From $OneMonthBack
19+
Assert-NotNull $jobs 'Jobs list should not be null'
20+
foreach($job in $jobs)
21+
{
22+
Assert-NotNull $jobs.InstanceId 'JobID should not be null';
23+
Assert-NotNull $jobs.StartTime 'StartTime should not be null';
24+
Assert-NotNull $jobs.WorkloadType 'WorkloadType should not be null';
25+
Assert-NotNull $jobs.WorkloadName 'WorkloadName should not be null';
26+
Assert-NotNull $jobs.Status 'Status should not be null';
27+
Assert-NotNull $jobs.Operation 'Operation should not be null';
28+
29+
$jobDetails = Get-AzureBackupJobDetails -Job $job
30+
Assert-NotNull $jobDetails.InstanceId 'JobID should not be null';
31+
Assert-NotNull $jobDetails.StartTime 'StartTime should not be null';
32+
Assert-NotNull $jobDetails.WorkloadType 'WorkloadType should not be null';
33+
Assert-NotNull $jobDetails.WorkloadName 'WorkloadName should not be null';
34+
Assert-NotNull $jobDetails.Status 'Status should not be null';
35+
Assert-NotNull $jobDetails.Operation 'Operation should not be null';
36+
Assert-NotNull $jobDetails.Properties 'Properties in job details cannot be null';
37+
Assert-NotNull $jobDetails.SubTasks 'SubTasks in job details cannot be null';
38+
}
39+
}
40+
41+
42+
function Test-StopAzureBackupJob
43+
{
44+
$OneMonthBack = Get-Date;
45+
$OneMonthBack = $OneMonthBack.AddDays(-30);
46+
47+
$azureBackUpItem = New-Object Microsoft.Azure.Commands.AzureBackup.Models.AzureBackupItem
48+
$azureBackUpItem.ResourceGroupName = $ResourceGroupName
49+
$azureBackUpItem.ResourceName = $ResourceName
50+
$azureBackUpItem.Location = $Location
51+
$azureBackUpItem.ContainerUniqueName = $ContainerName
52+
$azureBackUpItem.ContainerType = $ContainerType
53+
$azureBackUpItem.DataSourceId = $DataSourceId
54+
$azureBackUpItem.Type = $DataSourceType
55+
56+
$job = Backup-AzureBackupItem -Item $azureBackUpItem
57+
58+
Stop-AzureBackupJob -Job $job;
59+
Wait-AzureBackupJob -Job $job;
60+
$jobDetails = Get-AzureBackupJobDetails -Job $job;
61+
Assert-AreEqual 'Cancelled' $jobDetails.Status
62+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.AzureBackup.Test.ScenarioTests
19+
{
20+
public class AzureBackupPolicyTests : AzureBackupTestsBase
21+
{
22+
[Fact]
23+
public void ListProtectionPolicyTests()
24+
{
25+
this.RunPowerShellTest("Test-GetAzureBackupProtectionPolicyTests");
26+
}
27+
28+
[Fact]
29+
public void NewProtectionPolicyTests()
30+
{
31+
this.RunPowerShellTest("Test-NewAzureBackupProtectionPolicyTests");
32+
}
33+
34+
[Fact]
35+
public void ListProtectionPolicyByNameTests()
36+
{
37+
this.RunPowerShellTest("Test-GetAzureBackupProtectionPolicyByNameTests");
38+
}
39+
40+
[Fact]
41+
public void SetProtectionPolicyTests()
42+
{
43+
this.RunPowerShellTest("Test-SetAzureBackupProtectionPolicyTests");
44+
}
45+
46+
[Fact]
47+
public void RemoveProtectionPolicyTests()
48+
{
49+
this.RunPowerShellTest("Test-RemoveAzureBackupProtectionPolicyTests");
50+
}
51+
52+
53+
}
54+
}

0 commit comments

Comments
 (0)