class Serverspec::Type::OctopusDeployWorker

Public Class Methods

new(serverUrl, apiKey, instance, spaceId = 'Spaces-1') click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 15
def initialize(serverUrl, apiKey, instance, spaceId = 'Spaces-1')
  @name = "Octopus Deploy Worker #{instance}"
  @runner = Specinfra::Runner
  @serverUrl = serverUrl
  @apiKey = apiKey
  @spaceId = spaceId

  if (serverUrl.nil?)
    raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
  end
  if (apiKey.nil?)
    raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
  end

  if (exists?)
    thumbprint = `"c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe" show-thumbprint --console --nologo --instance #{instance}`
    thumbprint = thumbprint.gsub('==== ShowThumbprintCommand starting ====', '').strip
    thumbprint = thumbprint.gsub('The thumbprint of this Tentacle is: ', '').strip
    thumbprint = thumbprint.gsub('==== ShowThumbprintCommand completed ====', '').strip
    thumbprint = thumbprint.gsub('==== ShowThumbprintCommand ====', '').strip

    @serverSupportsSpaces = check_supports_spaces(serverUrl)

    if (@serverSupportsSpaces)
      @spaceFragment = "#{@spaceId}/"
    end

    @worker = get_worker_via_api(serverUrl, apiKey, thumbprint)
  else
    puts "tentacle.exe does not exist"
  end
end

Public Instance Methods

exists?() click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 109
def exists?
  ::File.exists?("c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe")
end
has_display_name?(name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 85
def has_display_name?(name)
  return false if @worker.nil?
  @worker["Name"] == name
end
has_endpoint?(uri) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 90
def has_endpoint?(uri)
  return false if @worker.nil?
  return false if @worker["Uri"].nil? # polling tentacles have null endpoint. catch that.
  puts "Expected uri '#{uri}' for Worker #{@name}, but got '#{@worker["Uri"]}'" unless (@worker["Uri"].casecmp(uri) == 0)
  @worker["Uri"].casecmp(uri) == 0
end
has_policy?(policy_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 76
def has_policy?(policy_name)
  return false if @worker.nil?
  url = "#{@serverUrl}/api/#{@spaceFragment}machinepolicies/all?api-key=#{@apiKey}"
  resp = Net::HTTP.get_response(URI.parse(url))
  policies = JSON.parse(resp.body)
  policy_id = policies.select {|e| e["Name"] == policy_name}.first["Id"]
  @worker["MachinePolicyId"] == policy_id
end
in_space?(space_name) click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 66
def in_space?(space_name)
  return false if @worker.nil?
  return false if @serverSupportsSpaces
  url = "#{@serverUrl}/api/spaces/all?api-key=#{@apiKey}"
  resp = Net::HTTP.get_response(URI.parse(url))
  spaces = JSON.parse(resp.body)
  space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
  @worker["SpaceId"] == space_id
end
listening_worker?() click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 97
def listening_worker?
  return false if @worker.nil?
  puts "Expected CommunicationStyle 'TentaclePassive' for Tentacle #{@name}, but got '#{@worker["Endpoint"]["CommunicationStyle"]}'" if (@worker["Endpoint"]["CommunicationStyle"] != "TentaclePassive")
  @worker["Endpoint"]["CommunicationStyle"] == "TentaclePassive"
end
online?() click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 52
def online?
  return nil if @worker.nil?
  @worker = poll_until_worker_has_completed_healthcheck(@serverUrl, @apiKey, @worker["Thumbprint"])
  status = @worker['Status']
  if ("#{status}" == "")
    status = @worker['HealthStatus'] if "#{status}" == ""
    puts "Expected status 'Healthy|HasWarnings' for Worker #{@name}, but got '#{status}'" if (status != "Healthy" && status != "HasWarnings")
    status == "Healthy" || status == "HasWarnings"
  else
    puts "Expected status 'Online|CalamariNeedsUpgrade|NeedsUpgrade' for Worker #{@name}, but got '#{status}'" if (status != "Online" && status != "CalamariNeedsUpgrade" && status != "NeedsUpgrade")
    status == "Online" || status == "CalamariNeedsUpgrade" || status == "NeedsUpgrade"
  end
end
polling_worker?() click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 103
def polling_worker?
  return false if @worker.nil?
  puts "Expected CommunicationStyle 'TentacleActive' for Tentacle #{@name}, but got '#{@worker["Endpoint"]["CommunicationStyle"]}'" if (@worker["Endpoint"]["CommunicationStyle"] != "TentacleActive")
  @worker["Endpoint"]["CommunicationStyle"] == "TentacleActive"
end
registered_with_the_server?() click to toggle source
# File lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb, line 48
def registered_with_the_server?
  !@worker.nil?
end