Skip to content

Commit 60df675

Browse files
committed
Merge pull request #146 from elvg/dev
Reimplementing the exisiting Automation cmdlets and adding new cmdlets
2 parents bc54d63 + aa06c8e commit 60df675

File tree

117 files changed

+6658
-2701
lines changed

Some content is hidden

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

117 files changed

+6658
-2701
lines changed

setup/azurecmdfiles.wxi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@
823823
<File Id="filD8D1F471ACDC72E34B1D13DA591F7B3F" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Automation\Microsoft.Azure.Common.NetFramework.dll" />
824824
</Component>
825825
<Component Id="cmp4EC3226B54BFE0FF4970968ABD1746E3" Guid="*">
826-
<File Id="filBEF499CCE9B33E61EA5BEFE2BEE86E92" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Automation\Microsoft.Azure.Management.Automation.dll" />
826+
<File Id="filBEF499CCE9B33E61EA5BEFE2BEE86E92" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Automation\Microsoft.WindowsAzure.Management.Automation.dll" />
827827
</Component>
828828
<Component Id="cmp86A3FC330AB128431B87D9FC2A1D3109" Guid="*">
829829
<File Id="fil08829B0CC57BEE7E650F0AE7867D27EE" KeyPath="yes" Source="$(var.sourceDir)\ServiceManagement\Azure\Automation\Microsoft.Azure.ResourceManager.dll" />

src/Common/Commands.ScenarioTest/Resources/Automation/AutomationTests.ps1

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
Checks whether the first string contains the second one
1818
#>
1919

20-
$accountName='AutomationAccount'
20+
$accountName='safeer'
21+
$location = "East US"
2122

2223
function AssertContains
2324
{
@@ -108,10 +109,10 @@ function Test-RunbookWithParameter
108109

109110
$runbook = CreateRunbook $runbookPath
110111
Assert-NotNull $runbook "runBook $runbookPath does not import successfully."
111-
$automationAccount | Publish-AzureAutomationRunbook -Id $runbook.Id
112+
$automationAccount | Publish-AzureAutomationRunbook -Name $runbook.Name
112113

113114
#Test
114-
$job = $automationAccount | Start-AzureAutomationRunbook -Id $runbook.Id -Parameters $parameters
115+
$job = $automationAccount | Start-AzureAutomationRunbook -Name $runbook.Name -Parameters $parameters
115116
WaitForJobStatus -Id $job.Id -Status "Completed"
116117
$jobOutput = $automationAccount | Get-AzureAutomationJobOutput -Id $job.Id -Stream Output
117118
$automationAccount | Remove-AzureAutomationRunbook -Name $runbook.Name -Force
@@ -126,16 +127,15 @@ function Test-AutomationStartAndStopRunbook
126127
{
127128
param([string] $runbookPath)
128129

129-
#Setup
130-
$automationAccount = Get-AzureAutomationAccount -Name $accountName
130+
$automationAccount = Get-AzureAutomationAccount -Name $accountName
131131
Assert-NotNull $automationAccount "Automation account $accountName does not exist."
132132

133133
$runbook = CreateRunbook $runbookPath
134134
Assert-NotNull $runbook "runBook $runbookPath does not import successfully."
135-
$automationAccount | Publish-AzureAutomationRunbook -Id $runbook.Id
135+
$automationAccount | Publish-AzureAutomationRunbook -Name $runbook.Name
136136

137137
#Test
138-
$job = $automationAccount | Start-AzureAutomationRunbook -Id $runbook.Id
138+
$job = Start-AzureAutomationRunbook -Name $runbook.Name -AutomationAccountName $accountName
139139
WaitForJobStatus -Id $job.Id -Status "Running"
140140
$automationAccount | Stop-AzureAutomationJob -Id $job.Id
141141
WaitForJobStatus -Id $job.Id -Status "Stopped"
@@ -153,31 +153,28 @@ function Test-AutomationPublishAndEditRunbook
153153

154154
$runbook = CreateRunbook $runbookPath $true
155155

156-
#Test
157-
158-
Assert-Null $runbook.PublishedRunbookVersionId
159-
Assert-NotNull $runbook.DraftRunbookVersionId
160156
#Publish Runbook
161-
$publishedRunbook = Publish-AzureAutomationRunbook $accountName -Id $runbook.Id
162-
Assert-NotNull $publishedRunbook.PublishedRunbookVersionId
163-
Assert-Null $publishedRunbook.DraftRunbookVersionId
164-
$publishedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName -VersionId $publishedRunbook.PublishedRunbookVersionId
157+
Publish-AzureAutomationRunbook $accountName -Name $runbook.Name
158+
$publishedRunbook = Get-AzureAutomationRunbook $accountName -Name $runbook.Name
159+
$runbookState = "Published"
160+
Assert-AreEqual $publishedRunbook.State $runbookState "Runbook should be in $runbookState state"
161+
$publishedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName -Name $runbook.Name
165162

166163
#Edit Runbook
167-
Set-AzureAutomationRunbookDefinition $accountName -Id $runbook.Id -Path $runbookPath -Overwrite
164+
Set-AzureAutomationRunbookDefinition $accountName -Name $runbook.Name -Path $runbookPath -Overwrite
168165
$runbook = Get-AzureAutomationRunbook $accountName -Name $runbook.Name
169-
Assert-AreEqual $publishedRunbook.PublishedRunbookVersionId $runbook.PublishedRunbookVersionId
170-
Assert-NotNull $runbook.DraftRunbookVersionId "Runbook should be in draft mode"
171-
$editedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName -VersionId $runbook.DraftRunbookVersionId
166+
$runbookState = "Edit"
167+
Assert-AreEqual $runbook.State $runbookState "Runbook should be in $runbookState state"
168+
$editedRunbookDefn = Get-AzureAutomationRunbookDefinition $accountName -Name $runbook.Name -Slot "Draft"
172169
Assert-AreNotEqual $editedRunbookDefn.Content $publishedRunbookDefn.Content "Old content and edited content of the runbook shouldn't be equal"
173170

174171
Assert-Throws {Set-AzureAutomationRunbookDefinition $accountName -Name $runbook.Name -Path $editRunbookPath -PassThru -ErrorAction Stop}
175172
Set-AzureAutomationRunbookDefinition $accountName -Name $runbook.Name -Path $editRunbookPath -Overwrite
176-
$editedRunbookDefn2 = Get-AzureAutomationRunbookDefinition $accountName -VersionId $runbook.DraftRunbookVersionId
173+
$editedRunbookDefn2 = Get-AzureAutomationRunbookDefinition $accountName -Name $runbook.Name -Slot "Draft"
177174
Assert-AreNotEqual $editedRunbookDefn2.Content $editedRunbookDefn.Content "Old content and edited content of the runbook shouldn't be equal"
178175

179-
Remove-AzureAutomationRunbook $accountName -Id $runbook.Id -Force
180-
Assert-Throws {Get-AzureAutomationRunbook $accountName -Id $runbook.Id}
176+
Remove-AzureAutomationRunbook $accountName -Name $runbook.Name -Force
177+
Assert-Throws {Get-AzureAutomationRunbook $accountName -Name $runbook.Name}
181178

182179
}
183180

@@ -194,30 +191,26 @@ function Test-AutomationConfigureRunbook
194191
Assert-NotNull $automationAccount "Automation account $accountName does not exist."
195192
$runbook = CreateRunbook $runbookPath
196193
Assert-NotNull $runbook "runbook ($runbookPath) isn't imported successfully."
197-
Publish-AzureAutomationRunbook -Id $runbook.Id -AutomationAccountName $accountName
194+
Publish-AzureAutomationRunbook -Name $runbook.Name -AutomationAccountName $accountName
198195

199196
#Test
200197

201198
#Change the runbook configuration
202-
$automationAccount | Set-AzureAutomationRunbook -Id $runbook.Id -LogDebug $true -LogVerbose $true -LogProgress $false
199+
$automationAccount | Set-AzureAutomationRunbook -Name $runbook.Name -LogVerbose $true -LogProgress $false
203200
$runbook = $automationAccount | Get-AzureAutomationRunbook -Name $runbook.Name
204201
Assert-NotNull $runbook "Runbook shouldn't be Null"
205-
Assert-AreEqual $true $runbook.LogDebug "Log Debug mode should be true."
206202
Assert-AreEqual $true $runbook.LogVerbose "Log Verbose mode should be true."
207203
Assert-AreEqual $false $runbook.LogProgress "Log Progress mode should be false."
208204

209205
#Start runbook and wait for job complete
210-
$job = $automationAccount | Start-AzureAutomationRunbook -Id $runbook.Id
206+
$job = $automationAccount | Start-AzureAutomationRunbook -Name $runbook.Name
211207
WaitForJobStatus -Id $job.Id -Status "Completed"
212208

213209
#Check job output streams
214210
$jobOutputs = $automationAccount | Get-AzureAutomationJobOutput -Id $job.Id -Stream "Output"
215211
Assert-AreEqual 1 $jobOutputs.Count
216212
AssertContains $jobOutputs[0].Text "output message" "The output stream is wrong."
217-
#Verify that debug and verbose streams are logged
218-
$jobDebugOutputs = $automationAccount | Get-AzureAutomationJobOutput -Id $job.Id -Stream "Debug"
219-
Assert-AreEqual 1 $jobDebugOutputs.Count
220-
AssertContains $jobDebugOutputs[0].Text "debug message" "The debug stream is wrong."
213+
#Verify that verbose streams are logged
221214
$jobVerboseOutputs = Get-AzureAutomationJobOutput $accountName -Id $job.Id -Stream "Verbose"
222215
Assert-AreEqual 1 $jobVerboseOutputs.Count
223216
AssertContains $jobVerboseOutputs[0].Text "verbose message" "The verbose stream is wrong."
@@ -226,26 +219,24 @@ function Test-AutomationConfigureRunbook
226219
Assert-AreEqual 0 $jobProgressOutputs.Count
227220

228221
#Change the runbook configuration again and start the runbook
229-
Set-AzureAutomationRunbook $accountName -Id $runbook.Id -LogDebug $false -LogVerbose $false -LogProgress $true
222+
Set-AzureAutomationRunbook $accountName -Name $runbook.Name -LogVerbose $false -LogProgress $true
230223
$job = Start-AzureAutomationRunbook $accountName -Name $runbook.Name
231224
WaitForJobStatus -Id $job.Id -Status "Completed"
232225
#Verify that progress stream is logged
233226
$jobProgressOutputs = Get-AzureAutomationJobOutput $accountName -Id $job.Id -Stream "Progress"
234227
Assert-AreNotEqual 0 $jobProgressOutputs.Count
235228
Assert-AreEqual $jobProgressOutputs[0].Type "Progress"
236-
#Verify that debug and verbose streams aren't logged
237-
$jobDebugOutputs = Get-AzureAutomationJobOutput $accountName -Id $job.Id -Stream "Debug"
238-
Assert-AreEqual 0 $jobDebugOutputs.Count
229+
#Verify that verbose streams aren't logged
239230
$jobVerboseOutputs = Get-AzureAutomationJobOutput $accountName -Id $job.Id -Stream "Verbose"
240231
Assert-AreEqual 0 $jobVerboseOutputs.Count
241232

242233
#Check whether the total number of jobs for the runbook is correct
243-
$jobs = Get-AzureAutomationJob $accountName -RunbookId $runbook.Id
234+
$jobs = Get-AzureAutomationJob $accountName -RunbookName $runbook.Name
244235
Assert-AreEqual 2 $jobs.Count "There should be 2 jobs in total for this runbook."
245236

246237
#Remove runbook
247238
$automationAccount | Remove-AzureAutomationRunbook -Name $runbook.Name -Force
248-
Assert-Throws {$automationAccount | Get-AzureAutomationRunbook -Id $runbook.Id}
239+
Assert-Throws {$automationAccount | Get-AzureAutomationRunbook -Name $runbook.Name}
249240
}
250241

251242
<#
@@ -263,17 +254,17 @@ function Test-AutomationSuspendAndResumeJob
263254

264255
#Test
265256

266-
$automationAccount | Publish-AzureAutomationRunbook -Id $runbook.Id
257+
$automationAccount | Publish-AzureAutomationRunbook -Name $runbook.Name
267258
#Start, suspend, and then resume job
268-
$job = Start-AzureAutomationRunbook $accountName -Id $runbook.Id
259+
$job = Start-AzureAutomationRunbook $accountName -Name $runbook.Name
269260
WaitForJobStatus -Id $job.Id -Status "Running"
270261
Suspend-AzureAutomationJob $accountName -Id $job.Id
271262
WaitForJobStatus -Id $job.Id -Status "Suspended"
272263
$automationAccount | Resume-AzureAutomationJob -Id $job.Id
273264
WaitForJobStatus -Id $job.Id -Status "Completed"
274265

275266
#Remove runbook
276-
Remove-AzureAutomationRunbook -AutomationAccountName $accountName -Id $runbook.Id -Force
267+
Remove-AzureAutomationRunbook -AutomationAccountName $accountName -Name $runbook.Name -Force
277268
Assert-Throws {Get-AzureAutomationRunbook $accountName -Name $runbook.Name}
278269
}
279270

@@ -319,31 +310,34 @@ function Test-AutomationStartRunbookOnASchedule
319310

320311
$runbook = Register-AzureAutomationScheduledRunbook $accountName -Name $runbook.Name -ScheduleName $oneTimeScheName
321312
Assert-AreEqual $oneTimeScheName $runbook.ScheduleNames "The runbook should be associated with $oneTimeScheName"
322-
$runbook = Register-AzureAutomationScheduledRunbook $accountName -Id $runbook.Id -ScheduleName $dailyScheName
313+
$runbook = Register-AzureAutomationScheduledRunbook $accountName -Name $runbook.Name -ScheduleName $dailyScheName
323314
Assert-True { $runbook.ScheduleNames -Contains $dailyScheName} "The runbook should be associated with $dailyScheName"
324315

325316
#waiting for seven minutes
326317
Wait-Seconds 420
327-
$job = Get-AzureAutomationJob $accountName -RunbookId $runbook.Id | where {$_.ScheduleName -eq $oneTimeScheName}
318+
$job = Get-AzureAutomationJob $accountName -Name $runbook.Name | where {$_.ScheduleName -eq $oneTimeScheName}
319+
$jobSchedule = Get-AzureAutomationScheduledRunbook $accountName -RunbookName $runbook.Name -ScheduleName $oneTimeScheName
320+
Assert-AreEqual 1 $jobSchedule.Count
328321
Assert-AreEqual 1 $job.Count
329322
WaitForJobStatus -Id $job.Id -Status "Completed"
330323

331324
#Edit schedule
332325
$description = "Daily Schedule Description"
333-
Set-AzureAutomationSchedule $accountName -Name $oneTimeScheName -Description $description
334-
$dailySchedule = Get-AzureAutomationSchedule $accountName -Name $oneTimeScheName
326+
Set-AzureAutomationSchedule $accountName -Name $dailyScheName -Description $description
327+
$dailySchedule = Get-AzureAutomationSchedule $accountName -Name $dailyScheName
335328
Assert-AreEqual $description $dailySchedule.Description
336329

337-
$runbook = Unregister-AzureAutomationScheduledRunbook $accountName -Name $runbook.Name -ScheduleName $dailyScheName
338-
Assert-False {$runbook.ScheduleNames -Contains $dailyScheName} "The runbook shouldn't have an association with $dailyScheName"
330+
Unregister-AzureAutomationScheduledRunbook $accountName -Name $runbook.Name -ScheduleName $dailyScheName
331+
$jobSchedule = Get-AzureAutomationScheduledRunbook $accountName -RunbookName $runbook.Name -ScheduleName $dailyScheName
332+
Assert-Null $jobSchedule "The runbook shouldn't have an association with $dailyScheName"
339333

340334
#Remove runbook and schedule
341335
Remove-AzureAutomationSchedule $accountName -Name $oneTimeScheName -Force
342336
Assert-Throws {$automationAccount | Get-AzureAutomationSchedule -Name $oneTimeScheName}
343337
$automationAccount | Remove-AzureAutomationSchedule -Name $dailyScheName -Force
344338
Assert-Throws {$automationAccount | Get-AzureAutomationSchedule -Name $dailyScheName}
345-
Remove-AzureAutomationRunbook $accountName -Id $runbook.Id -Force
346-
Assert-Throws {Get-AzureAutomationRunbook $accountName -Id $runbook.Id}
339+
Remove-AzureAutomationRunbook $accountName -Name $runbook.Name -Force
340+
Assert-Throws {Get-AzureAutomationRunbook $accountName -Name $runbook.Name}
347341
}
348342

349343
<#
@@ -362,8 +356,8 @@ function Test-AutomationStartUnpublishedRunbook
362356
Assert-NotNull $runbook "runBook $runbookPath does not import successfully."
363357
Assert-NotNull $runbook.Tags "Tags of the runbook shouldn't be Null."
364358
Assert-NotNull $runbook.Description "Description of the runbook shouldn't be Null."
365-
Assert-Throws {Start-AzureAutomationRunbook $accountName -Id $runbook.Id -Parameters $runbookParameters -PassThru -ErrorAction Stop}
359+
Assert-Throws {Start-AzureAutomationRunbook $accountName -Name $runbook.Name -Parameters $runbookParameters -PassThru -ErrorAction Stop}
366360

367-
Remove-AzureAutomationRunbook $accountName -Id $runbook.Id -Force
368-
Assert-Throws {Get-AzureAutomationRunbook $accountName -Id $runbook.Id -Parameters $runbookParameters -PassThru -ErrorAction Stop}
361+
Remove-AzureAutomationRunbook $accountName -Name $runbook.Name -Force
362+
Assert-Throws {Get-AzureAutomationRunbook $accountName -Name $runbook.Name -Parameters $runbookParameters -PassThru -ErrorAction Stop}
369363
}

src/ServiceManagement/Automation/Commands.Automation.Test/Commands.Automation.Test.csproj

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,42 @@
111111
</ItemGroup>
112112
<ItemGroup>
113113
<Compile Include="Properties\AssemblyInfo.cs" />
114+
<Compile Include="UnitTests\GetAzureAutomationConnectionTest.cs" />
115+
<Compile Include="UnitTests\GetAzureAutomationCertificateTest.cs" />
116+
<Compile Include="UnitTests\NewAzureAutomationAccountTest.cs" />
114117
<Compile Include="UnitTests\GetAzureAutomationAccountTest.cs" />
115-
<Compile Include="UnitTests\GetAzureAutomationJobOutputTest.cs" />
116-
<Compile Include="UnitTests\GetAzureAutomationJobTest.cs" />
117118
<Compile Include="UnitTests\GetAzureAutomationRunbookDefinitionTest.cs" />
118119
<Compile Include="UnitTests\GetAzureAutomationRunbookTest.cs" />
119-
<Compile Include="UnitTests\GetAzureAutomationScheduleTest.cs" />
120+
<Compile Include="UnitTests\GetAzureAutomationScheduledRunbookTest.cs" />
121+
<Compile Include="UnitTests\NewAzureAutomationConnectionTest.cs" />
122+
<Compile Include="UnitTests\NewAzureAutomationCertificateTest.cs" />
120123
<Compile Include="UnitTests\NewAzureAutomationRunbookTest.cs" />
121-
<Compile Include="UnitTests\NewAzureAutomationScheduleTest.cs" />
122124
<Compile Include="UnitTests\PublishAzureAutomationRunbookTest.cs" />
123-
<Compile Include="UnitTests\RegisterAzureAutomationScheduledJobTest.cs" />
125+
<Compile Include="UnitTests\RemoveAzureAutomationAccountTest.cs" />
126+
<Compile Include="UnitTests\RemoveAzureAutomationConnectionTest.cs" />
127+
<Compile Include="UnitTests\RemoveAzureAutomationCertificateTest.cs" />
128+
<Compile Include="UnitTests\RegisterAzureAutomationScheduledRunbookTest.cs" />
124129
<Compile Include="UnitTests\RemoveAzureAutomationRunbookTest.cs" />
125-
<Compile Include="UnitTests\RemoveAzureAutomationScheduleTest.cs" />
126-
<Compile Include="UnitTests\ResumeAzureAutomationJobTest.cs" />
127130
<Compile Include="UnitTests\SetAzureAutomationRunbookDefinitionTest.cs" />
128131
<Compile Include="UnitTests\SetAzureAutomationRunbookTest.cs" />
132+
<Compile Include="UnitTests\GetAzureAutomationCredentialTest.cs" />
133+
<Compile Include="UnitTests\GetAzureAutomationJobTest.cs" />
134+
<Compile Include="UnitTests\GetAzureAutomationModuleTest.cs" />
135+
<Compile Include="UnitTests\GetAzureAutomationScheduleTest.cs" />
136+
<Compile Include="UnitTests\NewAzureAutomationCredentialTest.cs" />
137+
<Compile Include="UnitTests\NewAzureAutomationModuleTest.cs" />
138+
<Compile Include="UnitTests\NewAzureAutomationScheduleTest.cs" />
139+
<Compile Include="UnitTests\NewAzureAutomationVariableTest.cs" />
140+
<Compile Include="UnitTests\RemoveAzureAutomationModuleTest.cs" />
141+
<Compile Include="UnitTests\RemoveAzureAutomationScheduleTest.cs" />
142+
<Compile Include="UnitTests\RemoveAzureAutomationVariableTest.cs" />
143+
<Compile Include="UnitTests\GetAzureAutomationVariableTest.cs" />
144+
<Compile Include="UnitTests\ResumeAzureAutomationJobTest.cs" />
145+
<Compile Include="UnitTests\SetAzureAutomationCredentialTest.cs" />
129146
<Compile Include="UnitTests\SetAzureAutomationScheduleTest.cs" />
130-
<Compile Include="UnitTests\StartAzureAutomationRunbookTest.cs" />
131147
<Compile Include="UnitTests\StopAzureAutomationJobTest.cs" />
132148
<Compile Include="UnitTests\SuspendAzureAutomationJobTest.cs" />
149+
<Compile Include="UnitTests\StartAzureAutomationRunbookTest.cs" />
133150
</ItemGroup>
134151
<ItemGroup>
135152
<ProjectReference Include="..\..\..\Common\Commands.Common.Test\Commands.Common.Test.csproj">
@@ -148,6 +165,7 @@
148165
<ItemGroup>
149166
<None Include="MSSharedLibKey.snk" />
150167
<None Include="packages.config" />
168+
<Compile Include="UnitTests\UnregisterAzureAutomationScheduledRunbookTest.cs" />
151169
</ItemGroup>
152170
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
153171
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

0 commit comments

Comments
 (0)