Class: Serverspec::Type::WindowsDSC

Inherits:
Base
  • Object
show all
Defined in:
lib/octopus_serverspec_extensions/type/windows_dsc.rb

Instance Method Summary collapse

Constructor Details

#initializeWindowsDSC

Returns a new instance of WindowsDSC.



7
8
9
# File 'lib/octopus_serverspec_extensions/type/windows_dsc.rb', line 7

def initialize
  @runner = Specinfra::Runner
end

Instance Method Details

#able_to_get_dsc_configuration?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/octopus_serverspec_extensions/type/windows_dsc.rb', line 11

def able_to_get_dsc_configuration?
  command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; $state = ""; do { $state = (Get-DscLocalConfigurationManager).LCMState; write-host "LCM state is $state"; Start-Sleep -Seconds 2; } while ($state -ne "Idle"); try { Get-DSCConfiguration -ErrorAction Stop; write-output "Get-DSCConfiguration succeeded"; $true } catch { write-output "Get-DSCConfiguration failed"; write-output $_; $false }')
  command_result.stdout.gsub(/\n/, '').match /Get-DSCConfiguration succeeded/
end

#has_dsc_configuration_status_of_success?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/octopus_serverspec_extensions/type/windows_dsc.rb', line 21

def has_dsc_configuration_status_of_success?
  command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; try { $statuses = @(Get-DSCConfigurationStatus -ErrorAction Stop -All); $status = $statuses[0].Status; write-host "Get-DSCConfigurationStatus is \'$status\'"; if ($status -eq "Success") { exit 0 } else { exit 1 } } catch { write-output "Get-DSCConfigurationStatus failed"; write-output $_; exit 2; }')
  command_result.stdout.gsub(/\n/, '').match /Get-DSCConfigurationStatus is 'Success'/
end

#has_test_dsc_configuration_return_true?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/octopus_serverspec_extensions/type/windows_dsc.rb', line 16

def has_test_dsc_configuration_return_true?
  command_result = @runner.run_command('$ProgressPreference = "SilentlyContinue"; $state = ""; do { $state = (Get-DscLocalConfigurationManager).LCMState; write-host "LCM state is $state"; Start-Sleep -Seconds 2; } while ($state -ne "Idle"); try { if (-not (Test-DSCConfiguration -ErrorAction Stop)) { write-output "Test-DSCConfiguration returned false"; exit 1 } write-output "Test-DSCConfiguration succeeded"; exit 0 } catch { write-output "Test-DSCConfiguration failed"; write-output $_; exit 2 }')
  command_result.stdout.gsub(/\n/, '').match /Test-DSCConfiguration succeeded/
end

#to_sObject



26
27
28
# File 'lib/octopus_serverspec_extensions/type/windows_dsc.rb', line 26

def to_s
  "Windows DSC"
end