17
17
Checks whether the first string contains the second one
18
18
#>
19
19
20
- $accountName = ' AutomationAccount'
20
+ $accountName = ' safeer'
21
+ $location = " East US"
21
22
22
23
function AssertContains
23
24
{
@@ -108,10 +109,10 @@ function Test-RunbookWithParameter
108
109
109
110
$runbook = CreateRunbook $runbookPath
110
111
Assert-NotNull $runbook " runBook $runbookPath does not import successfully."
111
- $automationAccount | Publish-AzureAutomationRunbook - Id $runbook.Id
112
+ $automationAccount | Publish-AzureAutomationRunbook - Name $runbook.Name
112
113
113
114
# Test
114
- $job = $automationAccount | Start-AzureAutomationRunbook - Id $runbook.Id - Parameters $parameters
115
+ $job = $automationAccount | Start-AzureAutomationRunbook - Name $runbook.Name - Parameters $parameters
115
116
WaitForJobStatus - Id $job.Id - Status " Completed"
116
117
$jobOutput = $automationAccount | Get-AzureAutomationJobOutput - Id $job.Id - Stream Output
117
118
$automationAccount | Remove-AzureAutomationRunbook - Name $runbook.Name - Force
@@ -126,16 +127,15 @@ function Test-AutomationStartAndStopRunbook
126
127
{
127
128
param ([string ] $runbookPath )
128
129
129
- # Setup
130
- $automationAccount = Get-AzureAutomationAccount - Name $accountName
130
+ $automationAccount = Get-AzureAutomationAccount - Name $accountName
131
131
Assert-NotNull $automationAccount " Automation account $accountName does not exist."
132
132
133
133
$runbook = CreateRunbook $runbookPath
134
134
Assert-NotNull $runbook " runBook $runbookPath does not import successfully."
135
- $automationAccount | Publish-AzureAutomationRunbook - Id $runbook.Id
135
+ $automationAccount | Publish-AzureAutomationRunbook - Name $runbook.Name
136
136
137
137
# Test
138
- $job = $automationAccount | Start-AzureAutomationRunbook - Id $runbook.Id
138
+ $job = Start-AzureAutomationRunbook - Name $runbook.Name - AutomationAccountName $accountName
139
139
WaitForJobStatus - Id $job.Id - Status " Running"
140
140
$automationAccount | Stop-AzureAutomationJob - Id $job.Id
141
141
WaitForJobStatus - Id $job.Id - Status " Stopped"
@@ -153,31 +153,28 @@ function Test-AutomationPublishAndEditRunbook
153
153
154
154
$runbook = CreateRunbook $runbookPath $true
155
155
156
- # Test
157
-
158
- Assert-Null $runbook.PublishedRunbookVersionId
159
- Assert-NotNull $runbook.DraftRunbookVersionId
160
156
# 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
165
162
166
163
# Edit Runbook
167
- Set-AzureAutomationRunbookDefinition $accountName - Id $runbook.Id - Path $runbookPath - Overwrite
164
+ Set-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name - Path $runbookPath - Overwrite
168
165
$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 "
172
169
Assert-AreNotEqual $editedRunbookDefn.Content $publishedRunbookDefn.Content " Old content and edited content of the runbook shouldn't be equal"
173
170
174
171
Assert-Throws {Set-AzureAutomationRunbookDefinition $accountName - Name $runbook.Name - Path $editRunbookPath - PassThru - ErrorAction Stop}
175
172
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 "
177
174
Assert-AreNotEqual $editedRunbookDefn2.Content $editedRunbookDefn.Content " Old content and edited content of the runbook shouldn't be equal"
178
175
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 }
181
178
182
179
}
183
180
@@ -194,30 +191,26 @@ function Test-AutomationConfigureRunbook
194
191
Assert-NotNull $automationAccount " Automation account $accountName does not exist."
195
192
$runbook = CreateRunbook $runbookPath
196
193
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
198
195
199
196
# Test
200
197
201
198
# 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
203
200
$runbook = $automationAccount | Get-AzureAutomationRunbook - Name $runbook.Name
204
201
Assert-NotNull $runbook " Runbook shouldn't be Null"
205
- Assert-AreEqual $true $runbook.LogDebug " Log Debug mode should be true."
206
202
Assert-AreEqual $true $runbook.LogVerbose " Log Verbose mode should be true."
207
203
Assert-AreEqual $false $runbook.LogProgress " Log Progress mode should be false."
208
204
209
205
# Start runbook and wait for job complete
210
- $job = $automationAccount | Start-AzureAutomationRunbook - Id $runbook.Id
206
+ $job = $automationAccount | Start-AzureAutomationRunbook - Name $runbook.Name
211
207
WaitForJobStatus - Id $job.Id - Status " Completed"
212
208
213
209
# Check job output streams
214
210
$jobOutputs = $automationAccount | Get-AzureAutomationJobOutput - Id $job.Id - Stream " Output"
215
211
Assert-AreEqual 1 $jobOutputs.Count
216
212
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
221
214
$jobVerboseOutputs = Get-AzureAutomationJobOutput $accountName - Id $job.Id - Stream " Verbose"
222
215
Assert-AreEqual 1 $jobVerboseOutputs.Count
223
216
AssertContains $jobVerboseOutputs [0 ].Text " verbose message" " The verbose stream is wrong."
@@ -226,26 +219,24 @@ function Test-AutomationConfigureRunbook
226
219
Assert-AreEqual 0 $jobProgressOutputs.Count
227
220
228
221
# 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
230
223
$job = Start-AzureAutomationRunbook $accountName - Name $runbook.Name
231
224
WaitForJobStatus - Id $job.Id - Status " Completed"
232
225
# Verify that progress stream is logged
233
226
$jobProgressOutputs = Get-AzureAutomationJobOutput $accountName - Id $job.Id - Stream " Progress"
234
227
Assert-AreNotEqual 0 $jobProgressOutputs.Count
235
228
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
239
230
$jobVerboseOutputs = Get-AzureAutomationJobOutput $accountName - Id $job.Id - Stream " Verbose"
240
231
Assert-AreEqual 0 $jobVerboseOutputs.Count
241
232
242
233
# 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
244
235
Assert-AreEqual 2 $jobs.Count " There should be 2 jobs in total for this runbook."
245
236
246
237
# Remove runbook
247
238
$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 }
249
240
}
250
241
251
242
<#
@@ -263,17 +254,17 @@ function Test-AutomationSuspendAndResumeJob
263
254
264
255
# Test
265
256
266
- $automationAccount | Publish-AzureAutomationRunbook - Id $runbook.Id
257
+ $automationAccount | Publish-AzureAutomationRunbook - Name $runbook.Name
267
258
# Start, suspend, and then resume job
268
- $job = Start-AzureAutomationRunbook $accountName - Id $runbook.Id
259
+ $job = Start-AzureAutomationRunbook $accountName - Name $runbook.Name
269
260
WaitForJobStatus - Id $job.Id - Status " Running"
270
261
Suspend-AzureAutomationJob $accountName - Id $job.Id
271
262
WaitForJobStatus - Id $job.Id - Status " Suspended"
272
263
$automationAccount | Resume-AzureAutomationJob - Id $job.Id
273
264
WaitForJobStatus - Id $job.Id - Status " Completed"
274
265
275
266
# Remove runbook
276
- Remove-AzureAutomationRunbook - AutomationAccountName $accountName - Id $runbook.Id - Force
267
+ Remove-AzureAutomationRunbook - AutomationAccountName $accountName - Name $runbook.Name - Force
277
268
Assert-Throws {Get-AzureAutomationRunbook $accountName - Name $runbook.Name }
278
269
}
279
270
@@ -319,31 +310,34 @@ function Test-AutomationStartRunbookOnASchedule
319
310
320
311
$runbook = Register-AzureAutomationScheduledRunbook $accountName - Name $runbook.Name - ScheduleName $oneTimeScheName
321
312
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
323
314
Assert-True { $runbook.ScheduleNames -Contains $dailyScheName } " The runbook should be associated with $dailyScheName "
324
315
325
316
# waiting for seven minutes
326
317
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
328
321
Assert-AreEqual 1 $job.Count
329
322
WaitForJobStatus - Id $job.Id - Status " Completed"
330
323
331
324
# Edit schedule
332
325
$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
335
328
Assert-AreEqual $description $dailySchedule.Description
336
329
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 "
339
333
340
334
# Remove runbook and schedule
341
335
Remove-AzureAutomationSchedule $accountName - Name $oneTimeScheName - Force
342
336
Assert-Throws {$automationAccount | Get-AzureAutomationSchedule - Name $oneTimeScheName }
343
337
$automationAccount | Remove-AzureAutomationSchedule - Name $dailyScheName - Force
344
338
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 }
347
341
}
348
342
349
343
<#
@@ -362,8 +356,8 @@ function Test-AutomationStartUnpublishedRunbook
362
356
Assert-NotNull $runbook " runBook $runbookPath does not import successfully."
363
357
Assert-NotNull $runbook.Tags " Tags of the runbook shouldn't be Null."
364
358
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}
366
360
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}
369
363
}
0 commit comments