Skip to content

Commit 7760890

Browse files
author
Sushil Upadhyay
committed
Added test cases for RunBook Pattern changes as per public doc https://learn.microsoft.com/en-us/azure/automation/manage-runbooks
1 parent 2c6181f commit 7760890

File tree

9 files changed

+4393
-201
lines changed

9 files changed

+4393
-201
lines changed

src/Automation/Automation.Sdk/Generated/RunbookDraftOperations.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ internal RunbookDraftOperations(AutomationClient client)
120120
}
121121
if (runbookName != null)
122122
{
123-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
123+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
124124
{
125-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
125+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
126126
}
127127
}
128128
string apiVersion = "2022-08-08";
@@ -362,9 +362,9 @@ internal RunbookDraftOperations(AutomationClient client)
362362
}
363363
if (runbookName != null)
364364
{
365-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
365+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
366366
{
367-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
367+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
368368
}
369369
}
370370
string apiVersion = "2022-08-08";
@@ -583,9 +583,9 @@ internal RunbookDraftOperations(AutomationClient client)
583583
}
584584
if (runbookName != null)
585585
{
586-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
586+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
587587
{
588-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
588+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
589589
}
590590
}
591591
string apiVersion = "2022-08-08";
@@ -807,9 +807,9 @@ internal RunbookDraftOperations(AutomationClient client)
807807
}
808808
if (runbookName != null)
809809
{
810-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
810+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
811811
{
812-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
812+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
813813
}
814814
}
815815
if (runbookContent == null)

src/Automation/Automation.Sdk/Generated/RunbookOperations.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ internal RunbookOperations(AutomationClient client)
146146
}
147147
if (runbookName != null)
148148
{
149-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
149+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
150150
{
151-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
151+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
152152
}
153153
}
154154
string apiVersion = "2022-08-08";
@@ -359,9 +359,9 @@ internal RunbookOperations(AutomationClient client)
359359
}
360360
if (runbookName != null)
361361
{
362-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
362+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
363363
{
364-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
364+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
365365
}
366366
}
367367
string apiVersion = "2022-08-08";
@@ -584,9 +584,9 @@ internal RunbookOperations(AutomationClient client)
584584
}
585585
if (runbookName != null)
586586
{
587-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
587+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
588588
{
589-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
589+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
590590
}
591591
}
592592
if (parameters == null)
@@ -841,9 +841,9 @@ internal RunbookOperations(AutomationClient client)
841841
}
842842
if (runbookName != null)
843843
{
844-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
844+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
845845
{
846-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
846+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
847847
}
848848
}
849849
if (parameters == null)
@@ -1070,9 +1070,9 @@ internal RunbookOperations(AutomationClient client)
10701070
}
10711071
if (runbookName != null)
10721072
{
1073-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
1073+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
10741074
{
1075-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
1075+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
10761076
}
10771077
}
10781078
string apiVersion = "2022-08-08";
@@ -1475,9 +1475,9 @@ internal RunbookOperations(AutomationClient client)
14751475
}
14761476
if (runbookName != null)
14771477
{
1478-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
1478+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
14791479
{
1480-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
1480+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
14811481
}
14821482
}
14831483
string apiVersion = "2022-08-08";

src/Automation/Automation.Sdk/Generated/TestJobOperations.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ internal TestJobOperations(AutomationClient client)
122122
}
123123
if (runbookName != null)
124124
{
125-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
125+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
126126
{
127-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
127+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
128128
}
129129
}
130130
if (parameters == null)
@@ -354,9 +354,9 @@ internal TestJobOperations(AutomationClient client)
354354
}
355355
if (runbookName != null)
356356
{
357-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
357+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
358358
{
359-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
359+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
360360
}
361361
}
362362
string apiVersion = "2022-08-08";
@@ -572,9 +572,9 @@ internal TestJobOperations(AutomationClient client)
572572
}
573573
if (runbookName != null)
574574
{
575-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
575+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
576576
{
577-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
577+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
578578
}
579579
}
580580
string apiVersion = "2022-08-08";
@@ -772,9 +772,9 @@ internal TestJobOperations(AutomationClient client)
772772
}
773773
if (runbookName != null)
774774
{
775-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
775+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
776776
{
777-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
777+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
778778
}
779779
}
780780
string apiVersion = "2022-08-08";
@@ -972,9 +972,9 @@ internal TestJobOperations(AutomationClient client)
972972
}
973973
if (runbookName != null)
974974
{
975-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
975+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
976976
{
977-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
977+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
978978
}
979979
}
980980
string apiVersion = "2022-08-08";

src/Automation/Automation.Sdk/Generated/TestJobStreamsOperations.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ internal TestJobStreamsOperations(AutomationClient client)
123123
}
124124
if (runbookName != null)
125125
{
126-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
126+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
127127
{
128-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
128+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
129129
}
130130
}
131131
if (jobStreamId == null)
@@ -353,9 +353,9 @@ internal TestJobStreamsOperations(AutomationClient client)
353353
}
354354
if (runbookName != null)
355355
{
356-
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z]*-*[a-zA-Z0-9]*$"))
356+
if (!System.Text.RegularExpressions.Regex.IsMatch(runbookName, "^[a-zA-Z][a-zA-Z-_0-9]*$"))
357357
{
358-
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z]*-*[a-zA-Z0-9]*$");
358+
throw new ValidationException(ValidationRules.Pattern, "runbookName", "^[a-zA-Z][a-zA-Z-_0-9]*$");
359359
}
360360
}
361361
string apiVersion = "2022-08-08";

src/Automation/Automation.Sdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ input-file:
4747
- https://github.com/Azure/azure-rest-api-specs/blob/main/specification/automation/resource-manager/Microsoft.Automation/stable/2022-08-08/softwareUpdateConfigurationMachineRun.json
4848
- https://github.com/Azure/azure-rest-api-specs/blob/main/specification/automation/resource-manager/Microsoft.Automation/stable/2022-08-08/account.json
4949
- https://github.com/Azure/azure-rest-api-specs/blob/main/specification/automation/resource-manager/Microsoft.Automation/stable/2015-10-31/webhook.json
50-
- https://github.com/Azure/azure-rest-api-specs/blob/main/specification/automation/resource-manager/Microsoft.Automation/stable/2022-08-08/runbook.json
50+
- https://github.com/sushil490023/azure-rest-api-specs/blob/feature-FixAutomation/specification/automation/resource-manager/Microsoft.Automation/stable/2022-08-08/runbook.json
5151
- https://github.com/Azure/azure-rest-api-specs/blob/main/specification/automation/resource-manager/Microsoft.Automation/stable/2022-08-08/hybridRunbookWorker.json
5252
- https://github.com/Azure/azure-rest-api-specs/blob/main/specification/automation/resource-manager/Microsoft.Automation/stable/2022-08-08/hybridRunbookWorkerGroup.json
5353
- https://github.com/Azure/azure-rest-api-specs/blob/main/specification/automation/resource-manager/Microsoft.Automation/stable/2022-08-08/python3package.json

src/Automation/Automation.Test/ScenarioTests/RunbookJobTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,14 @@ public void TestCreateJobAndGetOutputPowerShellScript()
6060
string runbookPath = Path.Combine("ScenarioTests", "Resources", "RB-PowerShellScriptTutorial.ps1");
6161
TestRunner.RunTestScript(string.Format("Test-CreateJobAndGetOutputPowerShellScript -Name TestRunbook-PSScript-JobAndOutput -RunbookPath {0}", runbookPath));
6262
}
63+
64+
[Fact]
65+
[Trait(Category.Service, Category.Automation)]
66+
[Trait(Category.AcceptanceType, Category.CheckIn)]
67+
public void TestRunBookNamePattern()
68+
{
69+
string runbookPath = Path.Combine("ScenarioTests", "Resources", "RB-PowerShellScriptTutorial.ps1");
70+
TestRunner.RunTestScript(string.Format("Test-RunBookNamePattern -RunbookPath {0}", runbookPath));
71+
}
6372
}
6473
}

src/Automation/Automation.Test/ScenarioTests/RunbookJobTests.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,67 @@ function Test-CreateJobAndGetOutputPowerShellScript
284284

285285
Write-Output "Remove runbook - success."
286286
}
287+
288+
289+
<#
290+
.SYNOPSIS
291+
Start Job of PowerShell Script runbook, get output
292+
and get Output records (both success & failure records).
293+
#>
294+
function Test-RunBookNamePattern
295+
{
296+
param(
297+
[string] $RunbookPath
298+
)
299+
300+
Assert-True {AutomationAccountExistsFn} "Automation Account does not exist."
301+
302+
$desc = 'PowerShell Script runbook'
303+
$tags = @{'TagKey1'='TagValue1'}
304+
305+
$validRBNames = @('TestRunbook-PowerShellScript','testRunbook-PowerShell-Script','TestRunbook-PowerShell_Script','TestRunbook_PowerShell_Script','TestRunbook_3powerShell-1script')
306+
$inValidRBNames = @('1TestRunbook-PowerShellScript','_testRunbook-PowerShell-Script','-TestRunbook-PowerShell_Script',';TestRunbook_PowerShell_Script' )
307+
308+
foreach($rbName in $validRBNames)
309+
{
310+
Write-Host "Creating Runbook : " $rbName
311+
$runbook = Import-AzAutomationRunbook `
312+
-Path $RunbookPath `
313+
-Description $desc `
314+
-Name $rbName `
315+
-Type PowerShell `
316+
-ResourceGroup $resourceGroupName `
317+
-Tags $tags `
318+
-LogProgress $false `
319+
-LogVerbose $false `
320+
-AutomationAccountName $automationAccountName `
321+
-Published
322+
Assert-NotNull $runbook "Import-AzAutomationRunbook failed to import PowerShell Script runbook $Name."
323+
324+
# Remove the runbook
325+
Remove-AzAutomationRunbook -Name $rbName -ResourceGroupName $resourceGroupName -AutomationAccountName $automationAccountName -Force
326+
327+
Write-Output "Remove created runbook."
328+
329+
}
330+
331+
foreach($rbName in $inValidRBNames)
332+
{
333+
Write-Host "Creating Runbook : " $rbName
334+
335+
Assert-Throws {Import-AzAutomationRunbook `
336+
-Path $RunbookPath `
337+
-Description $desc `
338+
-Name $rbName `
339+
-Type PowerShell `
340+
-ResourceGroup $resourceGroupName `
341+
-Tags $tags `
342+
-LogProgress $false `
343+
-LogVerbose $false `
344+
-AutomationAccountName $automationAccountName `
345+
-Published
346+
}
347+
348+
}
349+
350+
}

0 commit comments

Comments
 (0)