Skip to content

Commit

Permalink
Merge pull request #56 from PlagueHO/Fix-Badges
Browse files Browse the repository at this point in the history
Fix build badges
  • Loading branch information
PlagueHO authored May 9, 2020
2 parents 031692a + b81ccf7 commit d3c43f8
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 103 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- BREAKING CHANGE: Changed resource prefix from MSFT to DSC.
- Updated to use continuous delivery pattern using Azure DevOps - fixes
[Issue #52](https://github.com/dsccommunity/iSCSIDsc/issues/52).
- Update build badges in `README.md` with correct build IDs.
- Removed unused test helper function `New-VDisk`.
- Added test helper function `Assert-CanRunIntegrationTest` to validate if
integration tests can be successfully run on a machine.

## [1.5.0.41] - 2017-09-02

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# iSCSIDsc

[![Build Status](https://dev.azure.com/dsccommunity/iSCSIDsc/_apis/build/status/dsccommunity.iSCSIDsc?branchName=master)](https://dev.azure.com/dsccommunity/iSCSIDsc/_build/latest?definitionId=18&branchName=master)
![Code Coverage](https://img.shields.io/azure-devops/coverage/dsccommunity/iSCSIDsc/18/master)
[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/dsccommunity/iSCSIDsc/18/master)](https://dsccommunity.visualstudio.com/iSCSIDsc/_test/analytics?definitionId=18&contextType=build)
[![Build Status](https://dev.azure.com/dsccommunity/iSCSIDsc/_apis/build/status/dsccommunity.iSCSIDsc?branchName=master)](https://dev.azure.com/dsccommunity/iSCSIDsc/_build/latest?definitionId=36&branchName=master)
![Code Coverage](https://img.shields.io/azure-devops/coverage/dsccommunity/iSCSIDsc/36/master)
[![Azure DevOps tests](https://img.shields.io/azure-devops/tests/dsccommunity/iSCSIDsc/36/master)](https://dsccommunity.visualstudio.com/iSCSIDsc/_test/analytics?definitionId=36&contextType=build)
[![PowerShell Gallery (with prereleases)](https://img.shields.io/powershellgallery/vpre/iSCSIDsc?label=iSCSIDsc%20Preview)](https://www.powershellgallery.com/packages/iSCSIDsc/)
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/iSCSIDsc?label=iSCSIDsc)](https://www.powershellgallery.com/packages/iSCSIDsc/)

Expand Down
16 changes: 8 additions & 8 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ stages:
inputs:
targetType: 'inline'
script: |
Install-WindowsFeature FS-iSCSITarget-Server, ISNS
Start-Service msiscsi
Install-WindowsFeature -Name FS-iSCSITarget-Server, ISNS
Start-Service -Name msiscsi
pwsh: false

- task: PowerShell@2
Expand Down Expand Up @@ -159,8 +159,8 @@ stages:
inputs:
targetType: 'inline'
script: |
Install-WindowsFeature FS-iSCSITarget-Server, ISNS
Start-Service msiscsi
Install-WindowsFeature -Name FS-iSCSITarget-Server, ISNS
Start-Service -Name msiscsi
pwsh: false

- task: PowerShell@2
Expand Down Expand Up @@ -206,8 +206,8 @@ stages:
inputs:
targetType: 'inline'
script: |
Install-WindowsFeature FS-iSCSITarget-Server, ISNS
Start-Service msiscsi
Install-WindowsFeature -Name FS-iSCSITarget-Server, ISNS
Start-Service -Name msiscsi
pwsh: false

- task: PowerShell@2
Expand Down Expand Up @@ -262,8 +262,8 @@ stages:
inputs:
targetType: 'inline'
script: |
Install-WindowsFeature FS-iSCSITarget-Server, ISNS
Start-Service msiscsi
Install-WindowsFeature -Name FS-iSCSITarget-Server, ISNS
Start-Service -Name msiscsi
pwsh: false

- task: PowerShell@2
Expand Down
14 changes: 11 additions & 3 deletions tests/Integration/DSC_iSCSIServerTarget.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,16 @@ $script:testEnvironment = Initialize-TestEnvironment `

Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')

try
{
Assert-CanRunIntegrationTest -Verbose
}
catch
{
Write-Warning -Message $_
return
}

try
{
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).Config.ps1"
Expand All @@ -37,11 +47,9 @@ try
iSNSServer = 'isns.contoso.com'
}

Write-Verbose -Message ("Creating Virtual Disk in {0}" -f $script:virtualDisk.Path) -Verbose
New-iSCSIVirtualDisk `
-Path $script:virtualDisk.Path `
-Size 10GB
Write-Verbose -Message ("Created Virtual Disk in {0}" -f $script:virtualDisk.Path) -Verbose
-Size 104857600
} # BeforeAll


Expand Down
67 changes: 23 additions & 44 deletions tests/Integration/DSC_iSCSIVirtualDisk.Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,25 @@ $script:testEnvironment = Initialize-TestEnvironment `

Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath '..\TestHelpers\CommonTestHelper.psm1')

try
{
Assert-CanRunIntegrationTest -Verbose
}
catch
{
Write-Warning -Message $_
return
}

try
{
$configFile = Join-Path -Path $PSScriptRoot -ChildPath "$($script:dscResourceName).Config.ps1"
. $configFile

# Ensure that the tests can be performed on this computer
$productType = (Get-CimInstance Win32_OperatingSystem).ProductType

Describe 'Environment' {
Context 'Operating System' {
It 'Should be a Server OS' {
$productType | Should -Be 3
}
}
}

if ($productType -ne 3)
{
Break
}

$installed = (Get-WindowsFeature -Name FS-iSCSITarget-Server).Installed

Describe 'Environment' {
Context 'Windows Features' {
It 'Should have the iSCSI Target Feature Installed' {
$installed | Should -Be $true
}
}
}

if ($installed -eq $false)
{
Break
}

Describe "$($script:DSCResourceName)_Integration" {
Context 'When creating a iSCSI Virtual Disk' {
BeforeAll {
$script:virtualDisk = @{
$script:testVirtualDisk = @{
Path = Join-Path -Path $TestDrive -ChildPath 'TestiSCSIVirtualDisk.vhdx'
Ensure = 'Present'
DiskType = 'Dynamic'
Expand All @@ -72,11 +51,11 @@ try
AllNodes = @(
@{
NodeName = 'localhost'
Path = $script:virtualDisk.Path
Ensure = $script:virtualDisk.Ensure
DiskType = $script:virtualDisk.DiskType
SizeBytes = $script:virtualDisk.SizeBytes
Description = $script:virtualDisk.Description
Path = $script:testVirtualDisk.Path
Ensure = $script:testVirtualDisk.Ensure
DiskType = $script:testVirtualDisk.DiskType
SizeBytes = $script:testVirtualDisk.SizeBytes
Description = $script:testVirtualDisk.Description
}
)
}
Expand All @@ -103,19 +82,19 @@ try

It 'Should have set the resource and all the parameters should match' {
# Get the Rule details
$virtualDiskNew = Get-iSCSIVirtualDisk -Path $script:virtualDisk.Path
$virtualDiskNew.Path | Should -Be $script:virtualDisk.Path
$virtualDiskNew.DiskType | Should -Be $script:virtualDisk.DiskType
$virtualDiskNew.Size | Should -Be $script:virtualDisk.SizeBytes
$virtualDiskNew.Description | Should -Be $script:virtualDisk.Description
$virtualDiskNew = Get-iSCSIVirtualDisk -Path $script:testVirtualDisk.Path
$virtualDiskNew.Path | Should -Be $script:testVirtualDisk.Path
$virtualDiskNew.DiskType | Should -Be $script:testVirtualDisk.DiskType
$virtualDiskNew.Size | Should -Be $script:testVirtualDisk.SizeBytes
$virtualDiskNew.Description | Should -Be $script:testVirtualDisk.Description
}

AfterAll {
# Clean up
Remove-iSCSIVirtualDisk `
-Path $script:virtualDisk.Path
-Path $script:testVirtualDisk.Path
Remove-Item `
-Path $script:virtualDisk.Path `
-Path $script:testVirtualDisk.Path `
-Force
} # AfterAll
}
Expand Down
90 changes: 45 additions & 45 deletions tests/TestHelpers/CommonTestHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -83,63 +83,63 @@ function Get-InvalidOperationRecord

<#
.SYNOPSIS
Creates a new VHD using DISKPART.
DISKPART is used because New-VHD is only available if Hyper-V is installed.
Asserts if the system is able to run integration tests.
.PARAMETER Path
The path to the VHD file to create.
.NOTES
When running integrations tests in Azure DevOps agents an exception is thrown
when creating a virtual iSCSI disk on the system:
UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
.PARAMETER SizeInMB
The size of the VHD disk to create.
.PARAMETER Initialize
Should the disk be initialized? This is for testing matching disks by GUID.
This previously did not occur and a solution to this has not been found.
Therefore suppress execution of these tests if the Virtual Disk can not
be created.
#>
function New-VDisk
function Assert-CanRunIntegrationTest
{
[CmdletBinding()]
param
(
[Parameter(Mandatory = $True)]
[String]
$Path,
param ()

[Parameter()]
[Uint32]
$SizeInMB,
# Ensure that the tests can be performed on this computer
Write-Verbose -Message 'Assert operating system is Windows Server'
$productType = (Get-CimInstance Win32_OperatingSystem).ProductType

[Parameter()]
[Switch]
$Initialize
)

$tempScriptPath = Join-Path -Path $ENV:Temp -ChildPath 'DiskPartVdiskScript.txt'
Write-Verbose -Message ('Creating DISKPART script {0}' -f $tempScriptPath)
if ($productType -ne 3)
{
throw 'Integration tests can only be run on Windows Server operating systems'
}

$diskPartScript = "CREATE VDISK FILE=`"$Path`" TYPE=EXPANDABLE MAXIMUM=$SizeInMB"
Write-Verbose -Message 'Assert FS-iSCSITarget-Server feature is installed'
$installed = (Get-WindowsFeature -Name FS-iSCSITarget-Server).Installed

if ($Initialize)
if ($installed -eq $false)
{
# The disk will be initialized with GPT (first blank line required because we're adding to existing string)
$diskPartScript += @"
SELECT VDISK FILE=`"$Path`"
ATTACH VDISK
CONVERT GPT
DETACH VDISK
"@
throw 'Integration tests require FS-iSCSITarget-Server windows feature to be installed'
}

Set-Content `
-Path $tempScriptPath `
-Value $diskPartScript `
-Encoding Ascii
$result = & DISKPART @('/s',$tempScriptPath)
Write-Verbose -Message ($Result | Out-String)
$null = Remove-Item -Path $tempScriptPath -Force
} # end function New-VDisk
$virtualDiskPath = Join-Path -Path $ENV:Temp -ChildPath 'AssertCreateIscsiVirtualDisk.vhdx'

try
{
Write-Verbose -Message 'Assert iSCSI Virtual Disk can be created'
New-iSCSIVirtualDisk `
-Path $virtualDiskPath `
-Size 10MB
}
catch
{
Remove-iSCSIVirtualDisk `
-Path $virtualDiskPath `
-ErrorAction SilentlyContinue
Remove-Item `
-Path $virtualDiskPath `
-Force `
-ErrorAction SilentlyContinue

throw ('Integration tests can only be run if an iSCSI Virtual Disk can be created. Failed with {0}' -f $_)
}
}

Export-ModuleMember -Function `
New-VDisk, `
Get-InvalidArgumentRecord, `
Get-InvalidOperationRecord
Get-InvalidOperationRecord, `
Assert-CanRunIntegrationTest

0 comments on commit d3c43f8

Please sign in to comment.