Sha256: 9e996873c72b84508d8a8663e3f7af62bc1083493de35e6a3d085efb869b9a81

Contents?: true

Size: 1.49 KB

Versions: 11

Compression:

Stored size: 1.49 KB

Contents

require 'serverspec'
require 'serverspec/type/base'

module Serverspec::Type
  class WindowsDSC < Base

    def initialize
      @runner = Specinfra::Runner
    end

    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

    def has_applied_dsc_configuration_successfully?
      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

    def to_s
      "Windows DSC"
    end

  end

  def windows_dsc
    WindowsDSC.new
  end
end

include Serverspec::Type

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
octopus-serverspec-extensions-0.17.3 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.17.2 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.17.1 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.17.0 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.15.5 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.15.4 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.15.3 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.15.2 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.15.1 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.15.0 lib/octopus_serverspec_extensions/type/windows_dsc.rb
octopus-serverspec-extensions-0.13.6 lib/octopus_serverspec_extensions/type/windows_dsc.rb