diff --git a/.azure-pipelines/live-test.yml b/.azure-pipelines/live-test.yml index 61cc7c56afd9..a28b1f6b312a 100644 --- a/.azure-pipelines/live-test.yml +++ b/.azure-pipelines/live-test.yml @@ -41,13 +41,19 @@ parameters: default: 7.0.x variables: - LiveTestArtifactsName: LiveTestArtifacts - LiveTestDataLocation: $(Pipeline.Workspace)/$(LiveTestArtifactsName) + ArtifactsName: LiveTestArtifacts + DataLocation: $(Pipeline.Workspace)/$(ArtifactsName) EnableTestCoverage: true - TestCoverageLocation: $(LiveTestDataLocation) + TestCoverageLocation: $(DataLocation) + +schedules: +- cron: "0 19 * * *" + displayName: Daily Live Test + branches: + include: + - shared/livetest pr: none -trigger: none jobs: - template: util/live-test-steps.yml diff --git a/.azure-pipelines/util/live-test-steps.yml b/.azure-pipelines/util/live-test-steps.yml index 22d211805e90..8b5cd9b8cfdb 100644 --- a/.azure-pipelines/util/live-test-steps.yml +++ b/.azure-pipelines/util/live-test-steps.yml @@ -6,7 +6,6 @@ parameters: jobs: - job: ${{ parameters.name }} - timeoutInMinutes: 180 pool: vmImage: ${{ parameters.vmImage }} @@ -32,7 +31,7 @@ jobs: pwsh: true targetType: inline script: - New-Item -Name $(LiveTestArtifactsName) -Path $(Pipeline.Workspace) -ItemType Directory -Force + New-Item -Name $(ArtifactsName) -Path $(Pipeline.Workspace) -ItemType Directory -Force - task: DownloadPipelineArtifact@2 condition: and(succeeded(), eq(variables['GalleryName'], 'DailyBuild'), eq(variables['BuildPipelineBuildId'], '')) @@ -65,7 +64,7 @@ jobs: pwsh: true targetType: inline script: | - $azPackagesDir = New-Item -Name AzPackages -Path $(LiveTestDataLocation) -ItemType Directory -Force + $azPackagesDir = New-Item -Name AzPackages -Path $(DataLocation) -ItemType Directory -Force $azPackagesFiles = Join-Path -Path $(Pipeline.Workspace) -ChildPath *.nupkg Move-Item -Path $azPackagesFiles -Destination $azPackagesDir Get-ChildItem -LiteralPath $azPackagesDir @@ -76,7 +75,7 @@ jobs: pwsh: true targetType: filePath filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1 - arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InstallLiveTestAzModules.ps1 -Source $(GalleryName) -AzPackagesLocation (Convert-Path -LiteralPath $(LiveTestDataLocation) | Join-Path -ChildPath AzPackages)' + arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InstallLiveTestAzModules.ps1 -Source $(GalleryName) -AzPackagesLocation (Convert-Path -LiteralPath $(DataLocation) | Join-Path -ChildPath AzPackages)' - task: PowerShell@2 displayName: Connect Azure with live test service principal @@ -92,7 +91,7 @@ jobs: pwsh: true targetType: filePath filePath: ./tools/TestFx/Live/InvokeLiveTestCITask.ps1 - arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 $(Build.BuildId) ${{ parameters.vmImage }} ${{ parameters.psVersion }} $(Build.SourcesDirectory) $(LiveTestDataLocation)' + arguments: -UseWindowsPowerShell ('${{ parameters.psVersion }}' -eq '5.1') -ScriptFile './tools/TestFx/Live/InvokeLiveTestScenarios.ps1 -BuildId $(Build.BuildId) -OSVersion ${{ parameters.vmImage }} -PSVersion ${{ parameters.psVersion }} -RepoLocation $(Build.SourcesDirectory)' failOnStderr: true - task: PowerShell@2 @@ -101,11 +100,11 @@ jobs: pwsh: true targetType: filePath filePath: ./tools/TestFx/Live/SaveLiveTestResult.ps1 - arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) $(LiveTestDatabaseName) $(LiveTestTableName) $(TestCoverageTableName) $(LiveTestDataLocation) + arguments: $(KustoServicePrincipalTenantId) $(KustoServicePrincipalId) $(KustoServicePrincipalSecret) $(KustoClusterName) $(KustoClusterRegion) $(LiveTestDatabaseName) $(LiveTestTableName) $(TestCoverageTableName) $(DataLocation) - task: PublishPipelineArtifact@1 displayName: Publish live test results to pipeline artifact inputs: artifact: livetest-os-${{ parameters.vmImage }}-powershell-${{ parameters.psVersion }} - targetPath: $(LiveTestDataLocation) + targetPath: $(DataLocation) condition: always() diff --git a/src/KeyVault/KeyVault.Test/LiveTests/TestLiveScenarios.ps1 b/src/KeyVault/KeyVault.Test/LiveTests/TestLiveScenarios.ps1 new file mode 100644 index 000000000000..398e355435ad --- /dev/null +++ b/src/KeyVault/KeyVault.Test/LiveTests/TestLiveScenarios.ps1 @@ -0,0 +1,80 @@ +Invoke-LiveTestScenario -Name "Create new standard key vault" -Description "Test creating a new standard key vault with all default values" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $vaultName = New-LiveTestResourceName + $vaultLocation = "westus" + + $actual = New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $vaultLocation + Assert-AreEqual $vaultName $actual.VaultName + Assert-AreEqual $rgName $actual.ResourceGroupName + Assert-AreEqual $vaultLocation $actual.Location + Assert-AreEqual "Standard" $actual.Sku + Assert-AreEqual $false $actual.EnabledForDeployment + Assert-True { $actual.EnableSoftDelete } "By default EnableSoftDelete should be true" + Assert-Null $actual.EnablePurgeProtection "By default EnablePurgeProtection should be null" + Assert-False { $actual.EnableRbacAuthorization } "By default EnableRbacAuthorization should be false" + Assert-AreEqual 90 $actual.SoftDeleteRetentionInDays "By default SoftDeleteRetentionInDays should be 90" +} + +Invoke-LiveTestScenario -Name "Create new premium key vault" -Description "Test creating a new premium key vault with all default values" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $vaultName = New-LiveTestResourceName + $vaultLocation = "eastus" + + $actual = New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $vaultLocation -Sku premium -EnabledForDeployment + Assert-AreEqual $vaultName $actual.VaultName + Assert-AreEqual $rgName $actual.ResourceGroupName + Assert-AreEqual $vaultLocation $actual.Location + Assert-AreEqual "Premium" $actual.Sku + Assert-AreEqual $true $actual.EnabledForDeployment +} + +Invoke-LiveTestScenario -Name "Update key vault" -Description "Test updating properties EnableRbacAuthorization and Tag for existing key vault" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $vaultName = New-LiveTestResourceName + $vaultLocation = "eastus" + + # Update EnableRbacAuthorization + $vault = New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName -Location $vaultLocation + $vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $true + Assert-True { $vault.EnableRbacAuthorization } "EnableRbacAuthorization should be true" + + $vault = $vault | Update-AzKeyVault -EnableRbacAuthorization $false + Assert-False { $vault.EnableRbacAuthorization } "EnableRbacAuthorization should be false" + + # Update Tags + $vault = $vault | Update-AzKeyVault -Tag @{ key = "value" } + Assert-AreEqual 1 $vault.Tags.Count "Tags should contain a key-value pair (key, value)" + Assert-True { $vault.Tags.Contains("key") } "Tags should contain a key-value pair (key, value)" + Assert-AreEqual "value" $vault.Tags["key"] "Tags should contain a key-value pair (key, value)" + + # Clean Tags + $vault = $vault | Update-AzKeyVault -Tag @{} + Assert-AreEqual 0 $vault.Tags.Count "Tags should be empty" +} + +Invoke-LiveTestScenario -Name "Delete key vault" -Description "Test deleting key vault" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $vaultName = New-LiveTestResourceName + $vaultLocation = "westus" + + New-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgname -Location $vaultLocation + Remove-AzKeyVault -VaultName $vaultName -Force + + $deletedVault = Get-AzKeyVault -VaultName $vaultName -ResourceGroupName $rgName + Assert-Null $deletedVault + + # purge deleted vault + Remove-AzKeyVault -VaultName $vaultName -Location $vaultLocation -InRemovedState -Force +} diff --git a/src/Network/Network.Test/LiveTests/TestLiveScenarios.ps1 b/src/Network/Network.Test/LiveTests/TestLiveScenarios.ps1 new file mode 100644 index 000000000000..7b143ae3f4c0 --- /dev/null +++ b/src/Network/Network.Test/LiveTests/TestLiveScenarios.ps1 @@ -0,0 +1,238 @@ +Invoke-LiveTestScenario -Name "Network interface CRUD with public IP address" -Description "Test CRUD for network interface with public IP address" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $location = "westus" + $vnetName = New-LiveTestResourceName + $subnetName = New-LiveTestResourceName + $publicIpName = New-LiveTestResourceName + $domainNameLabel = New-LiveTestResourceName + $nicName = New-LiveTestResourceName + + $subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 + $vnet = New-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet + $publicIp = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $publicIpName -Location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel + + $expectedNic = New-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName -Location $location -Subnet $vnet.Subnets[0] -PublicIpAddress $publicIp + $actualNic = Get-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName + + Assert-AreEqual $expectedNic.ResourceGroupName $actualNic.ResourceGroupName + Assert-AreEqual $expectedNic.Name $actualNic.Name + Assert-AreEqual $expectedNic.Location $actualNic.Location + Assert-NotNull $expectedNic.ResourceGuid + Assert-AreEqual "Succeeded" $expectedNic.ProvisioningState + Assert-AreEqual $expectedNic.IpConfigurations[0].Name $actualNic.IpConfigurations[0].Name + Assert-AreEqual $expectedNic.IpConfigurations[0].PublicIpAddress.Id $actualNic.IpConfigurations[0].PublicIpAddress.Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Subnet.Id $actualNic.IpConfigurations[0].Subnet.Id + Assert-NotNull $expectedNic.IpConfigurations[0].PrivateIpAddress + Assert-AreEqual "Dynamic" $expectedNic.IpConfigurations[0].PrivateIpAllocationMethod + + $actualNicByResourceId = Get-AzNetworkInterface -ResourceId $actualNic.Id + + Assert-AreEqual $expectedNic.ResourceGroupName $actualNicByResourceId.ResourceGroupName + Assert-AreEqual $expectedNic.Name $actualNicByResourceId.Name + Assert-AreEqual $expectedNic.Location $actualNicByResourceId.Location + Assert-NotNull $actualNicByResourceId.ResourceGuid + Assert-AreEqual "Succeeded" $actualNicByResourceId.ProvisioningState + Assert-AreEqual $expectedNic.IpConfigurations[0].Name $actualNicByResourceId.IpConfigurations[0].Name + Assert-AreEqual $expectedNic.IpConfigurations[0].PublicIpAddress.Id $actualNicByResourceId.IpConfigurations[0].PublicIpAddress.Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Subnet.Id $actualNicByResourceId.IpConfigurations[0].Subnet.Id + Assert-NotNull $actualNicByResourceId.IpConfigurations[0].PrivateIpAddress + Assert-AreEqual "Dynamic" $actualNicByResourceId.IpConfigurations[0].PrivateIpAllocationMethod + + $actualPublicIp = Get-AzPublicIpAddress -ResourceGroupName $rgName -Name $publicIpName + Assert-AreEqual $expectedNic.IpConfigurations[0].PublicIpAddress.Id $actualPublicIp.Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Id $actualPublicIp.IpConfiguration.Id + + $actualVnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgName + Assert-AreEqual $expectedNic.IpConfigurations[0].Subnet.Id $actualVnet.Subnets[0].Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Id $actualVnet.Subnets[0].IpConfigurations[0].Id + + $nicList = Get-AzNetworkInterface -ResourceGroupName $rgName + Assert-AreEqual 1 @($nicList).Count + Assert-AreEqual $nicList[0].ResourceGroupName $actualNic.ResourceGroupName + Assert-AreEqual $nicList[0].Name $actualNic.Name + Assert-AreEqual $nicList[0].Location $actualNic.Location + Assert-AreEqual "Succeeded" $nicList[0].ProvisioningState + Assert-AreEqual $actualNic.Etag $nicList[0].Etag + + $job = Remove-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName -PassThru -Force -AsJob + $job | Wait-Job + $deleteResult = $job | Receive-Job + Assert-AreEqual true $deleteResult + + $nicList = Get-AzNetworkInterface -ResourceGroupName $rgName + Assert-AreEqual 0 @($nicList).Count +} + +Invoke-LiveTestScenario -Name "Network interface CRUD without public IP address" -Description "Test CRUD for network interface without public IP address" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $location = "westus" + $vnetName = New-LiveTestResourceName + $subnetName = New-LiveTestResourceName + $nicName = New-LiveTestResourceName + + $subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 + $vnet = New-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet + + $expectedNic = New-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName -Location $location -Subnet $vnet.Subnets[0] + $actualNic = Get-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName + + Assert-AreEqual $expectedNic.ResourceGroupName $actualNic.ResourceGroupName + Assert-AreEqual $expectedNic.Name $actualNic.Name + Assert-AreEqual $expectedNic.Location $actualNic.Location + Assert-AreEqual "Succeeded" $expectedNic.ProvisioningState + Assert-AreEqual $expectedNic.IpConfigurations[0].Name $actualNic.IpConfigurations[0].Name + Assert-Null $expectedNic.IpConfigurations[0].PublicIpAddress.Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Subnet.Id $actualNic.IpConfigurations[0].Subnet.Id + + $actuaVnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgName + Assert-AreEqual $expectedNic.IpConfigurations[0].Subnet.Id $actuaVnet.Subnets[0].Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Id $actuaVnet.Subnets[0].IpConfigurations[0].Id + + $nicList = Get-AzNetworkInterface -ResourceGroupName $rgName + Assert-AreEqual 1 @($nicList).Count + Assert-AreEqual $nicList[0].ResourceGroupName $actualNic.ResourceGroupName + Assert-AreEqual $nicList[0].Name $actualNic.Name + Assert-AreEqual $nicList[0].Location $actualNic.Location + Assert-AreEqual "Succeeded" $nicList[0].ProvisioningState + Assert-AreEqual $expectedNic.Etag $nicList[0].Etag + + # Delete NetworkInterface + $deleteResult = Remove-AzNetworkInterface -ResourceGroupName $rgname -name $nicName -PassThru -Force + Assert-AreEqual true $deleteResult + + $nicList = Get-AzNetworkInterface -ResourceGroupName $rgName + Assert-AreEqual 0 @($nicList).Count +} + +Invoke-LiveTestScenario -Name "Network interface CRUD with IP configuration" -Description "Test CRUD for network interface with IP configuration" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $location = "westus" + $vnetName = New-LiveTestResourceName + $subnetName = New-LiveTestResourceName + $publicIpName = New-LiveTestResourceName + $domainNameLabel = New-LiveTestResourceName + $ipconfig1Name = New-LiveTestResourceName + $ipconfig2Name = New-LiveTestResourceName + $nicName = New-LiveTestResourceName + + $subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 + $vnet = New-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet + + $publicIp = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName -Location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel + $ipconfig1 = New-AzNetworkInterfaceIpConfig -Name $ipconfig1Name -Subnet $vnet.Subnets[0] -PublicIpAddress $publicip + $ipconfig2 = New-AzNetworkInterfaceIpConfig -Name $ipconfig2Name -PrivateIpAddressVersion IPv6 + + $nic = New-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName -Location $location -IpConfiguration $ipconfig1,$ipconfig2 -Tag @{ testtag = "testval" } + + Assert-AreEqual $rgName $nic.ResourceGroupName + Assert-AreEqual $nicName $nic.Name + Assert-NotNull $nic.ResourceGuid + Assert-AreEqual "Succeeded" $nic.ProvisioningState + Assert-AreEqual $nic.IpConfigurations[0].Name $nic.IpConfigurations[0].Name + Assert-AreEqual $nic.IpConfigurations[0].PublicIpAddress.Id $nic.IpConfigurations[0].PublicIpAddress.Id + Assert-AreEqual $nic.IpConfigurations[0].Subnet.Id $nic.IpConfigurations[0].Subnet.Id + Assert-NotNull $nic.IpConfigurations[0].PrivateIpAddress + Assert-AreEqual "Dynamic" $nic.IpConfigurations[0].PrivateIpAllocationMethod + + $publicIp = Get-AzPublicIpAddress -ResourceGroupName $rgName -Name $publicIpName + Assert-AreEqual $nic.IpConfigurations[0].PublicIpAddress.Id $publicIp.Id + Assert-AreEqual $nic.IpConfigurations[0].Id $publicIp.IpConfiguration.Id + + $vnet = Get-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName + Assert-AreEqual $nic.IpConfigurations[0].Subnet.Id $vnet.Subnets[0].Id + Assert-AreEqual $nic.IpConfigurations[0].Id $vnet.Subnets[0].IpConfigurations[0].Id + + Assert-AreEqual 2 @($nic.IpConfigurations).Count + + Assert-AreEqual $ipconfig1Name $nic.IpConfigurations[0].Name + Assert-AreEqual $publicIp.Id $nic.IpConfigurations[0].PublicIpAddress.Id + Assert-AreEqual $vnet.Subnets[0].Id $nic.IpConfigurations[0].Subnet.Id + Assert-NotNull $nic.IpConfigurations[0].PrivateIpAddress + Assert-AreEqual "Dynamic" $nic.IpConfigurations[0].PrivateIpAllocationMethod + Assert-AreEqual $nic.IpConfigurations[0].PrivateIpAddressVersion IPv4 + + Assert-AreEqual $ipconfig2Name $nic.IpConfigurations[1].Name + Assert-Null $nic.IpConfigurations[1].PublicIpAddress + Assert-Null $nic.IpConfigurations[1].Subnet + Assert-AreEqual $nic.IpConfigurations[1].PrivateIpAddressVersion IPv6 + + $deleteResult = Remove-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName -PassThru -Force + Assert-AreEqual true $deleteResult + + $list = Get-AzNetworkInterface -ResourceGroupName $rgname + Assert-AreEqual 0 @($list).Count +} + +Invoke-LiveTestScenario -Name "Network interface CRUD with accelerated networking" -Description "Test CRUD for network interface with accelerated networking" -ScenarioScript ` +{ + param ($rg) + + $rgName = $rg.ResourceGroupName + $location = "westus" + $vnetName = New-LiveTestResourceName + $subnetName = New-LiveTestResourceName + $publicIpName = New-LiveTestResourceName + $domainNameLabel = New-LiveTestResourceName + $nicName = New-LiveTestResourceName + + $subnet = New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.1.0/24 + $vnet = New-AzVirtualNetwork -ResourceGroupName $rgName -Name $vnetName -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $subnet + + $publicIp = New-AzPublicIpAddress -ResourceGroupName $rgName -Name $publicIpName -Location $location -AllocationMethod Dynamic -DomainNameLabel $domainNameLabel + + $expectedNic = New-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName -Location $location -Subnet $vnet.Subnets[0] -PublicIpAddress $publicip -EnableAcceleratedNetworking + $actualNic = Get-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName + + Assert-AreEqual $expectedNic.ResourceGroupName $actualNic.ResourceGroupName + Assert-AreEqual $expectedNic.Name $actualNic.Name + Assert-AreEqual $expectedNic.Location $actualNic.Location + Assert-NotNull $expectedNic.ResourceGuid + Assert-AreEqual "Succeeded" $expectedNic.ProvisioningState + Assert-AreEqual $expectedNic.IpConfigurations[0].Name $actualNic.IpConfigurations[0].Name + Assert-AreEqual $expectedNic.IpConfigurations[0].PublicIpAddress.Id $actualNic.IpConfigurations[0].PublicIpAddress.Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Subnet.Id $actualNic.IpConfigurations[0].Subnet.Id + Assert-NotNull $expectedNic.IpConfigurations[0].PrivateIpAddress + Assert-AreEqual $expectedNic.EnableAcceleratedNetworking $true + Assert-AreEqual "Dynamic" $expectedNic.IpConfigurations[0].PrivateIpAllocationMethod + + $publicIp = Get-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIpName + Assert-AreEqual $expectedNic.IpConfigurations[0].PublicIpAddress.Id $publicIp.Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Id $publicIp.IpConfiguration.Id + + $vnet = Get-AzVirtualNetwork -Name $vnetName -ResourceGroupName $rgname + Assert-AreEqual $expectedNic.IpConfigurations[0].Subnet.Id $vnet.Subnets[0].Id + Assert-AreEqual $expectedNic.IpConfigurations[0].Id $vnet.Subnets[0].IpConfigurations[0].Id + + $nicList = Get-AzNetworkInterface -ResourceGroupName $rgname + Assert-AreEqual 1 @($nicList).Count + Assert-AreEqual $nicList[0].ResourceGroupName $actualNic.ResourceGroupName + Assert-AreEqual $nicList[0].Name $actualNic.Name + Assert-AreEqual $nicList[0].Location $actualNic.Location + Assert-AreEqual "Succeeded" $nicList[0].ProvisioningState + Assert-AreEqual $actualNic.Etag $nicList[0].Etag + + $nicList = Get-AzNetworkInterface -ResourceGroupName "*" -Name "*" + Assert-True { $nicList.Count -ge 0 } + + $nicList = Get-AzNetworkInterface -Name "*" + Assert-True { $nicList.Count -ge 0 } + + $nicList = Get-AzNetworkInterface -ResourceGroupName "*" + Assert-True { $nicList.Count -ge 0 } + + # Delete NetworkInterface + $deleteResult = Remove-AzNetworkInterface -ResourceGroupName $rgName -Name $nicName -PassThru -Force + Assert-AreEqual true $deleteResult + + $nicList = Get-AzNetworkInterface -ResourceGroupName $rgname + Assert-AreEqual 0 @($nicList).Count +} diff --git a/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 b/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 index 9ffe59ff4b63..11a8ce8fc181 100644 --- a/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 +++ b/tools/TestFx/Live/InvokeLiveTestScenarios.ps1 @@ -1,78 +1,120 @@ param ( - [Parameter(Mandatory, Position = 0)] - [ValidateNotNullOrEmpty()] - [string] $BuildId, - - [Parameter(Mandatory, Position = 1)] - [ValidateNotNullOrEmpty()] - [string] $OSVersion, - - [Parameter(Mandatory, Position = 2)] - [ValidateNotNullOrEmpty()] - [string] $PSVersion, - - [Parameter(Mandatory, Position = 3)] + [Parameter(Mandatory)] [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] [string] $RepoLocation, - [Parameter(Mandatory, Position = 4)] - [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] - [string] $DataLocation + [Parameter()] + [switch] $DebugMode ) -function FillLiveTestCoverageAdditionalInfo { - [CmdletBinding()] - param ( - [Parameter(Mandatory)] - [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] - [string] $TestCoverageDataLocation, +dynamicparam { + if (!$DebugMode.IsPresent) { + $dynParams = [Management.Automation.RuntimeDefinedParameterDictionary]::new() + $paramBuildId = [Management.Automation.RuntimeDefinedParameter]::new( + "BuildId", + [string], + [Attribute[]]@( + [Parameter]@{ Mandatory = $true } + [ValidateNotNullOrEmpty]::new() + ) + ) + $paramOSVersion = [Management.Automation.RuntimeDefinedParameter]::new( + "OSVersion", + [string], + [Attribute[]]@( + [Parameter]@{ Mandatory = $true } + [ValidateNotNullOrEmpty]::new() + ) + ) + $paramPSVersion = [Management.Automation.RuntimeDefinedParameter]::new( + "PSVersion", + [string], + [Attribute[]]@( + [Parameter]@{ Mandatory = $true } + [ValidateNotNullOrEmpty]::new() + ) + ) + $dynParams.Add($paramBuildId.Name, $paramBuildId) + $dynParams.Add($paramOSVersion.Name, $paramOSVersion) + $dynParams.Add($paramPSVersion.Name, $paramPSVersion) + $dynParams + } +} - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [string] $BuildId, +process { + function FillLiveTestCoverageAdditionalInfo { + [CmdletBinding()] + param ( + [Parameter(Mandatory)] + [ValidateScript({ Test-Path -LiteralPath $_ -PathType Container })] + [string] $TestCoverageDataLocation, - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [string] $OSVersion, + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $BuildId, - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [string] $PSVersion, + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $OSVersion, - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [string] $ModuleName - ) + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $PSVersion, - $testCoverageUtility = $PSScriptRoot | Split-Path | Join-Path -ChildPath "Coverage" | Join-Path -ChildPath "TestCoverageUtility.psd1" - Import-Module $testCoverageUtility - $module = Get-Module -Name "Az.$ModuleName" -ListAvailable - $moduleDetails = Get-TestCoverageModuleDetails -Module $module + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [string] $ModuleName + ) - $testCoverageRawCsv = Join-Path -Path $TestCoverageDataLocation -ChildPath "TestCoverageAnalysis" | Join-Path -ChildPath "Raw" | Join-Path -ChildPath "Az.$ModuleName.csv" - (Import-Csv -LiteralPath $testCoverageRawCsv) | - Select-Object @{ Name = "BuildId"; Expression = { "$BuildId" } }, ` - @{ Name = "OSVersion"; Expression = { "$OSVersion" } }, ` - @{ Name = "PSVersion"; Expression = { "$PSVersion" } }, ` - @{ Name = "Module"; Expression = { "$ModuleName" } }, ` - "CommandName", @{ Name = "TotalCommands"; Expression = { "$($moduleDetails['TotalCommands'])" } }, ` - "ParameterSetName", @{ Name = "TotalParameterSets"; Expression = { "$($moduleDetails['TotalParameterSets'])" } }, ` - "Parameters", @{ Name = "TotalParameters"; Expression = { "$($moduleDetails['TotalParameters'])" } }, ` - "SourceScript", "LineNumber", "StartDateTime", "EndDateTime", "IsSuccess" | - Export-Csv -LiteralPath $testCoverageRawCsv -Encoding utf8 -NoTypeInformation -Force -} + $testCoverageUtility = $PSScriptRoot | Split-Path | Join-Path -ChildPath "Coverage" | Join-Path -ChildPath "TestCoverageUtility.psd1" + Import-Module $testCoverageUtility + $module = Get-Module -Name "Az.$ModuleName" -ListAvailable + $moduleDetails = Get-TestCoverageModuleDetails -Module $module + + $testCoverageRawCsv = Join-Path -Path $TestCoverageDataLocation -ChildPath "TestCoverageAnalysis" | Join-Path -ChildPath "Raw" | Join-Path -ChildPath "Az.$ModuleName.csv" + (Import-Csv -LiteralPath $testCoverageRawCsv) | + Select-Object @{ Name = "BuildId"; Expression = { "$BuildId" } }, ` + @{ Name = "OSVersion"; Expression = { "$OSVersion" } }, ` + @{ Name = "PSVersion"; Expression = { "$PSVersion" } }, ` + @{ Name = "Module"; Expression = { "$ModuleName" } }, ` + "CommandName", @{ Name = "TotalCommands"; Expression = { "$($moduleDetails['TotalCommands'])" } }, ` + "ParameterSetName", @{ Name = "TotalParameterSets"; Expression = { "$($moduleDetails['TotalParameterSets'])" } }, ` + "Parameters", @{ Name = "TotalParameters"; Expression = { "$($moduleDetails['TotalParameters'])" } }, ` + "SourceScript", "LineNumber", "StartDateTime", "EndDateTime", "IsSuccess" | + Export-Csv -LiteralPath $testCoverageRawCsv -Encoding utf8 -NoTypeInformation -Force + } -$srcDir = Join-Path -Path $RepoLocation -ChildPath "src" -$liveScenarios = Get-ChildItem -LiteralPath $srcDir -Recurse -Directory -Filter "LiveTests" | ForEach-Object { - Get-ChildItem -Path (Join-Path -Path $_.FullName -ChildPath "TestLiveScenarios.ps1") -File -} -$liveScenarios | ForEach-Object { - $moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value if ($PSVersion -eq "latest") { $PSVersion = (Get-Variable -Name PSVersionTable).Value.PSVersion.ToString() } - Import-Module "./tools/TestFx/Assert.ps1" -Force - Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, $BuildId, $OSVersion, $PSVersion, $DataLocation -Force - . $_ - FillLiveTestCoverageAdditionalInfo -TestCoverageDataLocation $DataLocation -BuildId $BuildId -OSVersion $OSVersion -PSVersion $PSVersion -ModuleName $moduleName + $DataLocation = (Get-AzConfig -TestCoverageLocation).Value + + if ($DebugMode.IsPresent) { + $debugDirectory = Join-Path -Path $RepoLocation -ChildPath "artifacts" | Join-Path -ChildPath "Debug" + $accountsModuleDirectory = Join-Path -Path $debugDirectory -ChildPath "Az.Accounts" + Write-Host "Start to import Azure PowerShell modules from artifacts/Debug." -ForegroundColor Green + Write-Host "If you see module import issue, please restart the PowerShell host." -ForegroundColor Magenta + + Write-Host "Importing Az.Accounts." -ForegroundColor Green + Import-Module (Join-Path -Path $accountsModuleDirectory -ChildPath "Az.Accounts.psd1") + Get-ChildItem -LiteralPath $debugDirectory -Directory -Exclude "Az.Accounts" | Get-ChildItem -File -Include "*.psd1" | ForEach-Object { + Write-Host "Importing $_.FullName." -ForegroundColor Green + Import-Module $_.FullName -Force + } + Write-Host "Successfully imported Azure PowerShell modules from artifacts/Debug" -ForegroundColor Green + + $BuildId = "LocalDebug" + $OSVersion = "LocalDebug" + $PSVersion = "LocalDebug" + } + + $srcDir = Join-Path -Path $RepoLocation -ChildPath "src" + $liveScenarios = Get-ChildItem -LiteralPath $srcDir -Recurse -Directory -Filter "LiveTests" | Get-ChildItem -Filter "TestLiveScenarios.ps1" -File + $liveScenarios | ForEach-Object { + $moduleName = [regex]::match($_.FullName, "[\\|\/]src[\\|\/](?[a-zA-Z]+)[\\|\/]").Groups["ModuleName"].Value + Import-Module "./tools/TestFx/Assert.ps1" -Force + Import-Module "./tools/TestFx/Live/LiveTestUtility.psd1" -ArgumentList $moduleName, $BuildId, $OSVersion, $PSVersion, $DataLocation -Force + . $_ + FillLiveTestCoverageAdditionalInfo -TestCoverageDataLocation $DataLocation -BuildId $BuildId -OSVersion $OSVersion -PSVersion $PSVersion -ModuleName $moduleName + } } diff --git a/tools/TestFx/Live/LiveTestUtility.psm1 b/tools/TestFx/Live/LiveTestUtility.psm1 index f5678132f3fe..5e5d7cd5573e 100644 --- a/tools/TestFx/Live/LiveTestUtility.psm1 +++ b/tools/TestFx/Live/LiveTestUtility.psm1 @@ -33,6 +33,8 @@ param ( [string] $DataLocation ) +$ErrorActionPreference = "Stop" + New-Variable -Name ResourceGroupPrefix -Value "azpsliverg" -Scope Script -Option Constant New-Variable -Name ResourcePrefix -Value "azpslive" -Scope Script -Option Constant New-Variable -Name StorageAccountPrefix -Value "azpslivesa" -Scope Script -Option Constant @@ -146,7 +148,7 @@ function Invoke-LiveTestCommand { Write-Host "##[section]Start to execute the command '$Command'" -ForegroundColor Green Write-Host "##[command]The command '$Command' is running" -ForegroundColor Cyan - $cmdResult = Invoke-Expression -Command $Command -ErrorAction Stop + $cmdResult = Invoke-Expression -Command $Command Write-Host "##[section]Successfully executed the command '$Command'" -ForegroundColor Green $cmdResult @@ -231,7 +233,7 @@ function Invoke-LiveTestScenario { do { try { - Invoke-Command -ScriptBlock $ScenarioScript -ArgumentList $snrResourceGroup -ErrorAction Stop + Invoke-Command -ScriptBlock $ScenarioScript -ArgumentList $snrResourceGroup Write-Host "##[section]Successfully executed the live scenario '$Name'." -ForegroundColor Green break }