Class: Serverspec::Type::OctopusDeployWorker
- Inherits:
-
Base
- Object
- Base
- Serverspec::Type::OctopusDeployWorker
- Defined in:
- lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb
Instance Method Summary collapse
- #exists? ⇒ Boolean
- #has_display_name?(name) ⇒ Boolean
- #has_endpoint?(uri) ⇒ Boolean
- #has_policy?(policy_name) ⇒ Boolean
- #in_space?(space_name) ⇒ Boolean
-
#initialize(serverUrl, apiKey, instance, spaceId = 'Spaces-1') ⇒ OctopusDeployWorker
constructor
A new instance of OctopusDeployWorker.
- #listening_worker? ⇒ Boolean
- #online? ⇒ Boolean
- #polling_worker? ⇒ Boolean
- #registered_with_the_server? ⇒ Boolean
Constructor Details
#initialize(serverUrl, apiKey, instance, spaceId = 'Spaces-1') ⇒ OctopusDeployWorker
Returns a new instance of OctopusDeployWorker.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# 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 |
Instance Method Details
#exists? ⇒ Boolean
109 110 111 |
# 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) ⇒ Boolean
85 86 87 88 |
# 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) ⇒ Boolean
90 91 92 93 94 95 |
# 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) ⇒ Boolean
76 77 78 79 80 81 82 83 |
# 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) ⇒ Boolean
66 67 68 69 70 71 72 73 74 |
# 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? ⇒ Boolean
97 98 99 100 101 |
# 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? ⇒ Boolean
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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? ⇒ Boolean
103 104 105 106 107 |
# 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? ⇒ Boolean
48 49 50 |
# File 'lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb', line 48 def registered_with_the_server? !@worker.nil? end |