Skip to content

Commit

Permalink
Merge pull request #9031 from lwajswaj/fix/issue_7977
Browse files Browse the repository at this point in the history
Updated Get-AzAutomationJobOutputRecord to handle JSON and Text record values
  • Loading branch information
markcowl authored May 6, 2019
2 parents ad7edaf + 15851a1 commit 44d02ec
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public void TestAutomationStartUnpublishedRunbook()
[Trait(Category.Service, Category.Automation)]
public void TestAutomationRunbookWithParameter()
{
TestRunner.RunTestScript("Test-RunbookWithParameter -runbookPath ScenarioTests\\Resources\\fastJob.ps1 -type 'PowerShell' -parameters @{'nums'='[1,2,3,4,5,6,7]'} -expectedResult 28");
TestRunner.RunTestScript("Test-RunbookWithParameter -runbookPath ScenarioTests\\Resources\\Test-PowershellRunbook.ps1 -type 'PowerShell' -parameters @{'nums'=@(1,2,3,4,5,6,7)} -expectedResult 28");
}

[Fact(Skip = "Need x64 test framework.")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Service, Category.Automation)]
public void TestAutomationPy2RunbookWithParameter()
{
TestRunner.RunTestScript("Test-RunbookWithParameter -runbookPath ScenarioTests\\Resources\\fastJob.py -type 'Python2' -parameters @{'param1'='1';'param2'='2';'param3'='3';'param4'='4';'param5'='5';'param6'='6';'param7'='7'} -expectedResult 28");
TestRunner.RunTestScript("Test-RunbookWithParameter -runbookPath ScenarioTests\\Resources\\TestPythonRunbook.py -type 'Python2' -parameters @{'param1'='1';'param2'='2';'param3'='3';'param4'='4';'param5'='5';'param6'='6';'param7'='7'} -expectedResult 28");
}
}
}
16 changes: 14 additions & 2 deletions src/Automation/Automation.Test/ScenarioTests/AutomationTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,20 @@ function Test-RunbookWithParameter

#Test
$job = $automationAccount | Start-AzAutomationRunbook -Name $runbook.Name -Parameters $parameters
WaitForJobStatus -Id $job.Id -Status "Completed"
$jobOutput = $automationAccount | Get-AzAutomationJobOutput -Id $job.Id -Stream Output
WaitForJobStatus -Id $job.JobId -Status "Completed"
$jobOutput = $automationAccount | Get-AzAutomationJobOutput -Id $job.JobId -Stream Output

[int]$Result = $jobOutput | Select-Object -Last 1 -ExpandProperty Summary
Assert-AreEqual $expectedResult $Result

try {
$jobOutputRecord = $jobOutput | Get-AzAutomationJobOutputRecord -ErrorAction Stop
}
catch {
$jobOutputRecord = $null
}

Assert-NotNull $JobOutputRecord
$automationAccount | Remove-AzAutomationRunbook -Name $runbook.Name -Force
Assert-Throws { $automationAccount | Get-AzAutomationRunbook -Name $runbook.Name}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Param(
[int[]] $nums
)

Write-Output "Starting process"

$sum = ($nums | Measure-Object -Sum).Sum

Write-Output "Process completed"
Write-Output $sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import sys

print("Starting process")

sum = 0
for i in range(1,len(sys.argv)):
sum = sum + int(sys.argv[i])

print ("Process completed")
print(sum)

This file was deleted.

5 changes: 4 additions & 1 deletion src/Automation/Automation/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
- Additional information about change #1
-->
## Upcoming Release

* Updated Get-AzAutomationJobOutputRecord to handle JSON and Text record values.
- Fix for issue https://github.com/Azure/azure-powershell/issues/7977
- Fix for issue https://github.com/Azure/azure-powershell/issues/8600

## Version 1.2.1
* Fixed New-AzAutomationSoftwareUpdateConfiguration cmdlet bug for Inclusions. Now parameter IncludedKbNumber and IncludedPackageNameMask should work.
* Bug fix for azure automation update management dynamic group
Expand Down
22 changes: 15 additions & 7 deletions src/Automation/Automation/Model/JobStreamRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,25 @@ public JobStreamRecord(AutomationManagement.Models.JobStream jobStream, string r
if (kvp.Value != null)
{
object paramValue;
try
{
paramValue = ((object)PowerShellJsonConverter.Deserialize(kvp.Value.ToString()));
}
catch (CmdletInvocationException exception)

if (System.Text.RegularExpressions.Regex.IsMatch(kvp.Value.ToString(), "\\{.*\\:\\{.*\\:.*\\}\\}"))
{
if (!exception.Message.Contains("Invalid JSON primitive"))
throw;
try
{
paramValue = ((object)PowerShellJsonConverter.Deserialize(kvp.Value.ToString()));
}
catch (CmdletInvocationException exception)
{
if (!exception.Message.Contains("Invalid JSON primitive"))
throw;

paramValue = kvp.Value;
}
}
else {
paramValue = kvp.Value;
}

this.Value.Add(kvp.Key, paramValue);
}
}
Expand Down

0 comments on commit 44d02ec

Please sign in to comment.