octopus-serverspec-extensions 0.18.1 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +14 -14
- data/.rspec +2 -2
- data/.travis.yml +5 -5
- data/Gemfile +4 -4
- data/LICENSE.txt +12 -12
- data/README.md +39 -39
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/docs/authentication.md +45 -45
- data/docs/octopus_deploy_account.md +37 -37
- data/docs/octopus_deploy_doc_template.md +16 -16
- data/docs/octopus_deploy_environment.md +32 -32
- data/docs/octopus_deploy_project_group.md +30 -30
- data/docs/octopus_deploy_smtp_config.md +39 -39
- data/docs/octopus_deploy_space.md +32 -32
- data/docs/octopus_deploy_team.md +25 -25
- data/docs/octopus_deploy_tentacle.md +40 -40
- data/docs/octopus_deploy_upgrade_config.md +33 -33
- data/docs/octopus_deploy_user.md +33 -33
- data/docs/octopus_deploy_worker.md +38 -38
- data/docs/octopus_deploy_worker_pool.md +25 -25
- data/lib/octopus_serverspec_extensions.rb +85 -85
- data/lib/octopus_serverspec_extensions/matcher/allow_dynamic_infrastructure.rb +12 -12
- data/lib/octopus_serverspec_extensions/matcher/have_linux_line_endings.rb +13 -13
- data/lib/octopus_serverspec_extensions/matcher/have_version.rb +36 -36
- data/lib/octopus_serverspec_extensions/matcher/have_windows_line_endings.rb +13 -13
- data/lib/octopus_serverspec_extensions/matcher/run_under_account.rb +17 -17
- data/lib/octopus_serverspec_extensions/matcher/use_guided_failure.rb +12 -12
- data/lib/octopus_serverspec_extensions/type/chocolatey_package.rb +33 -33
- data/lib/octopus_serverspec_extensions/type/java_property_file.rb +28 -28
- data/lib/octopus_serverspec_extensions/type/npm_package.rb +36 -36
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_account.rb +176 -176
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_environment.rb +117 -117
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_project_group.rb +127 -127
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_smtp_config.rb +109 -109
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_space.rb +92 -92
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_team.rb +81 -81
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_tentacle.rb +208 -208
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_upgrade_config.rb +112 -112
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_user.rb +110 -110
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_worker.rb +173 -173
- data/lib/octopus_serverspec_extensions/type/octopus_deploy_worker_pool.rb +88 -88
- data/lib/octopus_serverspec_extensions/type/windows_dsc.rb +37 -37
- data/lib/octopus_serverspec_extensions/type/windows_firewall.rb +32 -32
- data/lib/octopus_serverspec_extensions/type/windows_scheduled_task.rb +33 -33
- data/lib/octopus_serverspec_extensions/version.rb +3 -3
- data/octopus-serverspec-extensions.gemspec +34 -34
- metadata +15 -16
@@ -1,208 +1,208 @@
|
|
1
|
-
require 'serverspec'
|
2
|
-
require 'serverspec/type/base'
|
3
|
-
require 'net/http'
|
4
|
-
require 'json'
|
5
|
-
|
6
|
-
module Serverspec::Type
|
7
|
-
class OctopusDeployTentacle < Base
|
8
|
-
@machine = nil
|
9
|
-
@serverUrl = nil
|
10
|
-
@apiKey = nil
|
11
|
-
@serverSupportsSpaces = nil
|
12
|
-
@spaceId = nil
|
13
|
-
@spaceFragment = ""
|
14
|
-
|
15
|
-
def initialize(serverUrl, apiKey, instance, spaceId = 'Spaces-1')
|
16
|
-
@name = "Octopus Deploy Tentacle #{instance}"
|
17
|
-
@runner = Specinfra::Runner
|
18
|
-
@serverUrl = serverUrl
|
19
|
-
@apiKey = apiKey
|
20
|
-
@spaceId = spaceId
|
21
|
-
|
22
|
-
if (serverUrl.nil?)
|
23
|
-
raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
|
24
|
-
end
|
25
|
-
if (apiKey.nil?)
|
26
|
-
raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
|
27
|
-
end
|
28
|
-
|
29
|
-
if (exists?)
|
30
|
-
thumbprint = `"c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe" show-thumbprint --console --nologo --instance #{instance}`
|
31
|
-
thumbprint = thumbprint.gsub('==== ShowThumbprintCommand starting ====', '').strip
|
32
|
-
thumbprint = thumbprint.gsub('The thumbprint of this Tentacle is: ', '').strip
|
33
|
-
thumbprint = thumbprint.gsub('==== ShowThumbprintCommand completed ====', '').strip
|
34
|
-
thumbprint = thumbprint.gsub('==== ShowThumbprintCommand ====', '').strip
|
35
|
-
|
36
|
-
@serverSupportsSpaces = check_supports_spaces(serverUrl)
|
37
|
-
|
38
|
-
if (@serverSupportsSpaces)
|
39
|
-
@spaceFragment = "#{@spaceId}/"
|
40
|
-
end
|
41
|
-
|
42
|
-
@machine = get_machine_via_api(serverUrl, apiKey, thumbprint)
|
43
|
-
else
|
44
|
-
puts "tentacle.exe does not exist"
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def registered_with_the_server?
|
49
|
-
!@machine.nil?
|
50
|
-
end
|
51
|
-
|
52
|
-
def online?
|
53
|
-
return nil if @machine.nil?
|
54
|
-
@machine = poll_until_machine_has_completed_healthcheck(@serverUrl, @apiKey, @machine["Thumbprint"])
|
55
|
-
status = @machine['Status']
|
56
|
-
if ("#{status}" == "")
|
57
|
-
status = @machine['HealthStatus'] if "#{status}" == ""
|
58
|
-
puts "Expected status 'Healthy|HasWarnings' for Tentacle #{@name}, but got '#{status}'" if (status != "Healthy" && status != "HasWarnings")
|
59
|
-
status == "Healthy" || status == "HasWarnings"
|
60
|
-
else
|
61
|
-
puts "Expected status 'Online|CalamariNeedsUpgrade|NeedsUpgrade' for Tentacle #{@name}, but got '#{status}'" if (status != "Online" && status != "CalamariNeedsUpgrade" && status != "NeedsUpgrade")
|
62
|
-
status == "Online" || status == "CalamariNeedsUpgrade" || status == "NeedsUpgrade"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def in_environment?(environment_name)
|
67
|
-
return false if @machine.nil?
|
68
|
-
url = "#{@serverUrl}/api/#{@spaceFragment}environments/all?api-key=#{@apiKey}"
|
69
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
70
|
-
environments = JSON.parse(resp.body)
|
71
|
-
environment_id = environments.select {|e| e["Name"] == environment_name}.first["Id"]
|
72
|
-
!@machine["EnvironmentIds"].select {|e| e == environment_id}.empty?
|
73
|
-
end
|
74
|
-
|
75
|
-
def in_space?(space_name)
|
76
|
-
return false if @machine.nil?
|
77
|
-
return false if @serverSupportsSpaces
|
78
|
-
url = "#{@serverUrl}/api/spaces/all?api-key=#{@apiKey}"
|
79
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
80
|
-
spaces = JSON.parse(resp.body)
|
81
|
-
space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
|
82
|
-
@machine["SpaceId"] == space_id
|
83
|
-
end
|
84
|
-
|
85
|
-
def has_tenant?(tenant_name)
|
86
|
-
return false if @machine.nil?
|
87
|
-
url = "#{@serverUrl}/api/#{@spaceFragment}tenants/all?api-key=#{@apiKey}"
|
88
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
89
|
-
tenants = JSON.parse(resp.body)
|
90
|
-
tenant_id = tenants.select {|e| e["Name"] == tenant_name}.first["Id"]
|
91
|
-
!@machine["TenantIds"].select {|e| e == tenant_id}.empty?
|
92
|
-
end
|
93
|
-
|
94
|
-
def has_tenant_tag?(tag_set, tag)
|
95
|
-
return false if @machine.nil?
|
96
|
-
tenant_tags = @machine["TenantTags"]
|
97
|
-
!tenant_tags.select {|e| e == "#{tag_set}/#{tag}"}.empty?
|
98
|
-
end
|
99
|
-
|
100
|
-
def has_policy?(policy_name)
|
101
|
-
return false if @machine.nil?
|
102
|
-
url = "#{@serverUrl}/api/#{@spaceFragment}machinepolicies/all?api-key=#{@apiKey}"
|
103
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
104
|
-
policies = JSON.parse(resp.body)
|
105
|
-
policy_id = policies.select {|e| e["Name"] == policy_name}.first["Id"]
|
106
|
-
@machine["MachinePolicyId"] == policy_id
|
107
|
-
end
|
108
|
-
|
109
|
-
def has_role?(role_name)
|
110
|
-
return false if @machine.nil?
|
111
|
-
roles = @machine["Roles"]
|
112
|
-
!roles.select {|e| e == role_name}.empty?
|
113
|
-
end
|
114
|
-
|
115
|
-
def has_display_name?(name)
|
116
|
-
return false if @machine.nil?
|
117
|
-
@machine["Name"] == name
|
118
|
-
end
|
119
|
-
|
120
|
-
def has_endpoint?(uri)
|
121
|
-
return false if @machine.nil?
|
122
|
-
return false if @machine["Uri"].nil? # polling tentacles have null endpoint. catch that.
|
123
|
-
puts "Expected uri '#{uri}' for Tentacle #{@name}, but got '#{@machine["Uri"]}'" unless (@machine["Uri"].casecmp(uri) == 0)
|
124
|
-
@machine["Uri"].casecmp(uri) == 0
|
125
|
-
end
|
126
|
-
|
127
|
-
def has_tenanted_deployment_participation?(mode)
|
128
|
-
return false if @machine.nil?
|
129
|
-
@machine["TenantedDeploymentParticipation"] == mode
|
130
|
-
end
|
131
|
-
|
132
|
-
def listening_tentacle?
|
133
|
-
return false if @machine.nil?
|
134
|
-
puts "Expected CommunicationStyle 'TentaclePassive' for Tentacle #{@name}, but got '#{@machine["Endpoint"]["CommunicationStyle"]}'" if (@machine["Endpoint"]["CommunicationStyle"] != "TentaclePassive")
|
135
|
-
@machine["Endpoint"]["CommunicationStyle"] == "TentaclePassive"
|
136
|
-
end
|
137
|
-
|
138
|
-
def polling_tentacle?
|
139
|
-
return false if @machine.nil?
|
140
|
-
puts "Expected CommunicationStyle 'TentacleActive' for Tentacle #{@name}, but got '#{@machine["Endpoint"]["CommunicationStyle"]}'" if (@machine["Endpoint"]["CommunicationStyle"] != "TentacleActive")
|
141
|
-
@machine["Endpoint"]["CommunicationStyle"] == "TentacleActive"
|
142
|
-
end
|
143
|
-
|
144
|
-
def exists?
|
145
|
-
::File.exists?("c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe")
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def octopus_deploy_tentacle(serverUrl, apiKey, instance)
|
150
|
-
OctopusDeployTentacle.new(serverUrl, apiKey, instance)
|
151
|
-
end
|
152
|
-
|
153
|
-
private
|
154
|
-
|
155
|
-
def check_supports_spaces(serverUrl)
|
156
|
-
begin
|
157
|
-
resp = Net::HTTP.get_response(URI.parse("#{serverUrl}/api/"))
|
158
|
-
body = JSON.parse(resp.body)
|
159
|
-
version = body['Version']
|
160
|
-
return Gem::Version.new(version) > Gem::Version.new('2019.0.0')
|
161
|
-
rescue => e
|
162
|
-
puts "Unable to connect to #{serverUrl}: #{e}"
|
163
|
-
end
|
164
|
-
|
165
|
-
return false
|
166
|
-
end
|
167
|
-
|
168
|
-
def poll_until_machine_has_completed_healthcheck(serverUrl, apiKey, thumbprint)
|
169
|
-
machine = nil
|
170
|
-
url = "#{serverUrl}/api/#{@spaceFragment}machines/all?api-key=#{apiKey}"
|
171
|
-
|
172
|
-
now = Time.now
|
173
|
-
counter = 1
|
174
|
-
loop do
|
175
|
-
machine = get_machine_via_api(serverUrl, apiKey, thumbprint)
|
176
|
-
|
177
|
-
break if machine.nil?
|
178
|
-
break if counter > 10
|
179
|
-
break if !machine_healthcheck_outstanding(machine)
|
180
|
-
puts "Machine health check for #{machine["Name"]} has not yet completed. Waiting 5 seconds to try again."
|
181
|
-
counter += 1
|
182
|
-
sleep 5
|
183
|
-
end
|
184
|
-
|
185
|
-
machine
|
186
|
-
end
|
187
|
-
|
188
|
-
def machine_healthcheck_outstanding(machine)
|
189
|
-
machine["StatusSummary"] == "This machine was recently added. Please perform a health check."
|
190
|
-
end
|
191
|
-
|
192
|
-
def get_machine_via_api(serverUrl, apiKey, thumbprint)
|
193
|
-
machine = nil
|
194
|
-
url = "#{serverUrl}/api/#{@spaceFragment}machines/all?api-key=#{apiKey}"
|
195
|
-
|
196
|
-
begin
|
197
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
198
|
-
body = JSON.parse(resp.body)
|
199
|
-
machine = body.select {|e| e["Thumbprint"] == thumbprint}.first unless body.nil?
|
200
|
-
rescue => e
|
201
|
-
puts "Unable to connect to #{url}: #{e}"
|
202
|
-
end
|
203
|
-
|
204
|
-
machine
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
include Serverspec::Type
|
1
|
+
require 'serverspec'
|
2
|
+
require 'serverspec/type/base'
|
3
|
+
require 'net/http'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Serverspec::Type
|
7
|
+
class OctopusDeployTentacle < Base
|
8
|
+
@machine = nil
|
9
|
+
@serverUrl = nil
|
10
|
+
@apiKey = nil
|
11
|
+
@serverSupportsSpaces = nil
|
12
|
+
@spaceId = nil
|
13
|
+
@spaceFragment = ""
|
14
|
+
|
15
|
+
def initialize(serverUrl, apiKey, instance, spaceId = 'Spaces-1')
|
16
|
+
@name = "Octopus Deploy Tentacle #{instance}"
|
17
|
+
@runner = Specinfra::Runner
|
18
|
+
@serverUrl = serverUrl
|
19
|
+
@apiKey = apiKey
|
20
|
+
@spaceId = spaceId
|
21
|
+
|
22
|
+
if (serverUrl.nil?)
|
23
|
+
raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
|
24
|
+
end
|
25
|
+
if (apiKey.nil?)
|
26
|
+
raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
|
27
|
+
end
|
28
|
+
|
29
|
+
if (exists?)
|
30
|
+
thumbprint = `"c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe" show-thumbprint --console --nologo --instance #{instance}`
|
31
|
+
thumbprint = thumbprint.gsub('==== ShowThumbprintCommand starting ====', '').strip
|
32
|
+
thumbprint = thumbprint.gsub('The thumbprint of this Tentacle is: ', '').strip
|
33
|
+
thumbprint = thumbprint.gsub('==== ShowThumbprintCommand completed ====', '').strip
|
34
|
+
thumbprint = thumbprint.gsub('==== ShowThumbprintCommand ====', '').strip
|
35
|
+
|
36
|
+
@serverSupportsSpaces = check_supports_spaces(serverUrl)
|
37
|
+
|
38
|
+
if (@serverSupportsSpaces)
|
39
|
+
@spaceFragment = "#{@spaceId}/"
|
40
|
+
end
|
41
|
+
|
42
|
+
@machine = get_machine_via_api(serverUrl, apiKey, thumbprint)
|
43
|
+
else
|
44
|
+
puts "tentacle.exe does not exist"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def registered_with_the_server?
|
49
|
+
!@machine.nil?
|
50
|
+
end
|
51
|
+
|
52
|
+
def online?
|
53
|
+
return nil if @machine.nil?
|
54
|
+
@machine = poll_until_machine_has_completed_healthcheck(@serverUrl, @apiKey, @machine["Thumbprint"])
|
55
|
+
status = @machine['Status']
|
56
|
+
if ("#{status}" == "")
|
57
|
+
status = @machine['HealthStatus'] if "#{status}" == ""
|
58
|
+
puts "Expected status 'Healthy|HasWarnings' for Tentacle #{@name}, but got '#{status}'" if (status != "Healthy" && status != "HasWarnings")
|
59
|
+
status == "Healthy" || status == "HasWarnings"
|
60
|
+
else
|
61
|
+
puts "Expected status 'Online|CalamariNeedsUpgrade|NeedsUpgrade' for Tentacle #{@name}, but got '#{status}'" if (status != "Online" && status != "CalamariNeedsUpgrade" && status != "NeedsUpgrade")
|
62
|
+
status == "Online" || status == "CalamariNeedsUpgrade" || status == "NeedsUpgrade"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def in_environment?(environment_name)
|
67
|
+
return false if @machine.nil?
|
68
|
+
url = "#{@serverUrl}/api/#{@spaceFragment}environments/all?api-key=#{@apiKey}"
|
69
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
70
|
+
environments = JSON.parse(resp.body)
|
71
|
+
environment_id = environments.select {|e| e["Name"] == environment_name}.first["Id"]
|
72
|
+
!@machine["EnvironmentIds"].select {|e| e == environment_id}.empty?
|
73
|
+
end
|
74
|
+
|
75
|
+
def in_space?(space_name)
|
76
|
+
return false if @machine.nil?
|
77
|
+
return false if @serverSupportsSpaces
|
78
|
+
url = "#{@serverUrl}/api/spaces/all?api-key=#{@apiKey}"
|
79
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
80
|
+
spaces = JSON.parse(resp.body)
|
81
|
+
space_id = spaces.select {|e| e["Name"] == space_name}.first["Id"]
|
82
|
+
@machine["SpaceId"] == space_id
|
83
|
+
end
|
84
|
+
|
85
|
+
def has_tenant?(tenant_name)
|
86
|
+
return false if @machine.nil?
|
87
|
+
url = "#{@serverUrl}/api/#{@spaceFragment}tenants/all?api-key=#{@apiKey}"
|
88
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
89
|
+
tenants = JSON.parse(resp.body)
|
90
|
+
tenant_id = tenants.select {|e| e["Name"] == tenant_name}.first["Id"]
|
91
|
+
!@machine["TenantIds"].select {|e| e == tenant_id}.empty?
|
92
|
+
end
|
93
|
+
|
94
|
+
def has_tenant_tag?(tag_set, tag)
|
95
|
+
return false if @machine.nil?
|
96
|
+
tenant_tags = @machine["TenantTags"]
|
97
|
+
!tenant_tags.select {|e| e == "#{tag_set}/#{tag}"}.empty?
|
98
|
+
end
|
99
|
+
|
100
|
+
def has_policy?(policy_name)
|
101
|
+
return false if @machine.nil?
|
102
|
+
url = "#{@serverUrl}/api/#{@spaceFragment}machinepolicies/all?api-key=#{@apiKey}"
|
103
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
104
|
+
policies = JSON.parse(resp.body)
|
105
|
+
policy_id = policies.select {|e| e["Name"] == policy_name}.first["Id"]
|
106
|
+
@machine["MachinePolicyId"] == policy_id
|
107
|
+
end
|
108
|
+
|
109
|
+
def has_role?(role_name)
|
110
|
+
return false if @machine.nil?
|
111
|
+
roles = @machine["Roles"]
|
112
|
+
!roles.select {|e| e == role_name}.empty?
|
113
|
+
end
|
114
|
+
|
115
|
+
def has_display_name?(name)
|
116
|
+
return false if @machine.nil?
|
117
|
+
@machine["Name"] == name
|
118
|
+
end
|
119
|
+
|
120
|
+
def has_endpoint?(uri)
|
121
|
+
return false if @machine.nil?
|
122
|
+
return false if @machine["Uri"].nil? # polling tentacles have null endpoint. catch that.
|
123
|
+
puts "Expected uri '#{uri}' for Tentacle #{@name}, but got '#{@machine["Uri"]}'" unless (@machine["Uri"].casecmp(uri) == 0)
|
124
|
+
@machine["Uri"].casecmp(uri) == 0
|
125
|
+
end
|
126
|
+
|
127
|
+
def has_tenanted_deployment_participation?(mode)
|
128
|
+
return false if @machine.nil?
|
129
|
+
@machine["TenantedDeploymentParticipation"] == mode
|
130
|
+
end
|
131
|
+
|
132
|
+
def listening_tentacle?
|
133
|
+
return false if @machine.nil?
|
134
|
+
puts "Expected CommunicationStyle 'TentaclePassive' for Tentacle #{@name}, but got '#{@machine["Endpoint"]["CommunicationStyle"]}'" if (@machine["Endpoint"]["CommunicationStyle"] != "TentaclePassive")
|
135
|
+
@machine["Endpoint"]["CommunicationStyle"] == "TentaclePassive"
|
136
|
+
end
|
137
|
+
|
138
|
+
def polling_tentacle?
|
139
|
+
return false if @machine.nil?
|
140
|
+
puts "Expected CommunicationStyle 'TentacleActive' for Tentacle #{@name}, but got '#{@machine["Endpoint"]["CommunicationStyle"]}'" if (@machine["Endpoint"]["CommunicationStyle"] != "TentacleActive")
|
141
|
+
@machine["Endpoint"]["CommunicationStyle"] == "TentacleActive"
|
142
|
+
end
|
143
|
+
|
144
|
+
def exists?
|
145
|
+
::File.exists?("c:\\program files\\Octopus Deploy\\Tentacle\\Tentacle.exe")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def octopus_deploy_tentacle(serverUrl, apiKey, instance)
|
150
|
+
OctopusDeployTentacle.new(serverUrl, apiKey, instance)
|
151
|
+
end
|
152
|
+
|
153
|
+
private
|
154
|
+
|
155
|
+
def check_supports_spaces(serverUrl)
|
156
|
+
begin
|
157
|
+
resp = Net::HTTP.get_response(URI.parse("#{serverUrl}/api/"))
|
158
|
+
body = JSON.parse(resp.body)
|
159
|
+
version = body['Version']
|
160
|
+
return Gem::Version.new(version) > Gem::Version.new('2019.0.0')
|
161
|
+
rescue => e
|
162
|
+
puts "Unable to connect to #{serverUrl}: #{e}"
|
163
|
+
end
|
164
|
+
|
165
|
+
return false
|
166
|
+
end
|
167
|
+
|
168
|
+
def poll_until_machine_has_completed_healthcheck(serverUrl, apiKey, thumbprint)
|
169
|
+
machine = nil
|
170
|
+
url = "#{serverUrl}/api/#{@spaceFragment}machines/all?api-key=#{apiKey}"
|
171
|
+
|
172
|
+
now = Time.now
|
173
|
+
counter = 1
|
174
|
+
loop do
|
175
|
+
machine = get_machine_via_api(serverUrl, apiKey, thumbprint)
|
176
|
+
|
177
|
+
break if machine.nil?
|
178
|
+
break if counter > 10
|
179
|
+
break if !machine_healthcheck_outstanding(machine)
|
180
|
+
puts "Machine health check for #{machine["Name"]} has not yet completed. Waiting 5 seconds to try again."
|
181
|
+
counter += 1
|
182
|
+
sleep 5
|
183
|
+
end
|
184
|
+
|
185
|
+
machine
|
186
|
+
end
|
187
|
+
|
188
|
+
def machine_healthcheck_outstanding(machine)
|
189
|
+
machine["StatusSummary"] == "This machine was recently added. Please perform a health check."
|
190
|
+
end
|
191
|
+
|
192
|
+
def get_machine_via_api(serverUrl, apiKey, thumbprint)
|
193
|
+
machine = nil
|
194
|
+
url = "#{serverUrl}/api/#{@spaceFragment}machines/all?api-key=#{apiKey}"
|
195
|
+
|
196
|
+
begin
|
197
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
198
|
+
body = JSON.parse(resp.body)
|
199
|
+
machine = body.select {|e| e["Thumbprint"] == thumbprint}.first unless body.nil?
|
200
|
+
rescue => e
|
201
|
+
puts "Unable to connect to #{url}: #{e}"
|
202
|
+
end
|
203
|
+
|
204
|
+
machine
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
include Serverspec::Type
|
@@ -1,112 +1,112 @@
|
|
1
|
-
require 'serverspec/type/base'
|
2
|
-
require 'net/http'
|
3
|
-
require 'json'
|
4
|
-
|
5
|
-
module Serverspec::Type
|
6
|
-
class OctopusDeployUpgradeConfig < Base
|
7
|
-
@serverUrl = nil
|
8
|
-
@apiKey = nil
|
9
|
-
@upgradeConfig = nil
|
10
|
-
|
11
|
-
@NotificationModes = ['AlwaysShow', 'ShowOnlyMajorMinor', 'NeverShow']
|
12
|
-
|
13
|
-
def initialize(*url_and_api_key)
|
14
|
-
serverUrl, apiKey = get_octopus_creds(url_and_api_key)
|
15
|
-
|
16
|
-
@name = "Octopus Deploy Upgrade Config #{serverUrl}"
|
17
|
-
@runner = Specinfra::Runner
|
18
|
-
@serverUrl = serverUrl
|
19
|
-
@apiKey = apiKey
|
20
|
-
|
21
|
-
# is it still nil?
|
22
|
-
if serverUrl.nil?
|
23
|
-
raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
|
24
|
-
end
|
25
|
-
if apiKey.nil?
|
26
|
-
raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
|
27
|
-
end
|
28
|
-
|
29
|
-
@upgradeConfig = get_upgrade_config_via_api(serverUrl, apiKey)
|
30
|
-
end
|
31
|
-
|
32
|
-
def has_notification_mode?(mode)
|
33
|
-
false if @upgradeConfig.nil?
|
34
|
-
@upgradeConfig['NotificationMode'] == mode
|
35
|
-
end
|
36
|
-
|
37
|
-
def never_show_notifications?
|
38
|
-
false if @upgradeConfig.nil?
|
39
|
-
has_notification_mode?('NeverShow')
|
40
|
-
end
|
41
|
-
|
42
|
-
def always_show_notifications?
|
43
|
-
false if @upgradeConfig.nil?
|
44
|
-
has_notification_mode?('AlwaysShow')
|
45
|
-
end
|
46
|
-
|
47
|
-
def show_major_minor_notifications?
|
48
|
-
false if @upgradeConfig.nil?
|
49
|
-
has_notification_mode?('ShowOnlyMajorMinor')
|
50
|
-
end
|
51
|
-
|
52
|
-
def include_statistics?
|
53
|
-
false if @upgradeConfig.nil?
|
54
|
-
@upgradeConfig['IncludeStatistics'] == true
|
55
|
-
end
|
56
|
-
|
57
|
-
def allow_checking?
|
58
|
-
false if @upgradeConfig.nil?
|
59
|
-
@upgradeConfig['AllowChecking'] == true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# module-level constructors/entrypoints
|
64
|
-
|
65
|
-
def octopus_deploy_upgrade_config(*url_and_api_key)
|
66
|
-
serverUrl, apiKey = get_octopus_creds(url_and_api_key)
|
67
|
-
OctopusDeployUpgradeConfig.new(serverUrl, apiKey)
|
68
|
-
end
|
69
|
-
|
70
|
-
def octopus_upgrade_config(*url_and_api_key)
|
71
|
-
serverUrl, apiKey = get_octopus_creds(url_and_api_key)
|
72
|
-
octopus_deploy_upgrade_config(serverUrl, apiKey)
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
def get_upgrade_config_endpoint(serverUrl)
|
78
|
-
endpoint = nil
|
79
|
-
|
80
|
-
url = "#{serverUrl}/api/"
|
81
|
-
|
82
|
-
begin
|
83
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
84
|
-
body = JSON.parse(resp.body)
|
85
|
-
json = body unless body.nil?
|
86
|
-
endpoint = json['Links']['UpgradeConfiguration']
|
87
|
-
rescue => e
|
88
|
-
raise "get_upgrade_config_endpoint: Unable to connect to #{url}: #{e}"
|
89
|
-
end
|
90
|
-
|
91
|
-
endpoint
|
92
|
-
end
|
93
|
-
|
94
|
-
def get_upgrade_config_via_api(serverUrl, apiKey)
|
95
|
-
smtp = nil
|
96
|
-
|
97
|
-
stem = get_upgrade_config_endpoint(serverUrl)
|
98
|
-
url = "#{serverUrl}#{stem}?api-key=#{apiKey}"
|
99
|
-
|
100
|
-
begin
|
101
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
102
|
-
body = JSON.parse(resp.body)
|
103
|
-
smtp = body unless body.nil?
|
104
|
-
rescue => e
|
105
|
-
raise "get_upgrade_config_via_api: Unable to connect to #{url}: #{e}"
|
106
|
-
end
|
107
|
-
|
108
|
-
smtp
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
include Serverspec::Type
|
1
|
+
require 'serverspec/type/base'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Serverspec::Type
|
6
|
+
class OctopusDeployUpgradeConfig < Base
|
7
|
+
@serverUrl = nil
|
8
|
+
@apiKey = nil
|
9
|
+
@upgradeConfig = nil
|
10
|
+
|
11
|
+
@NotificationModes = ['AlwaysShow', 'ShowOnlyMajorMinor', 'NeverShow']
|
12
|
+
|
13
|
+
def initialize(*url_and_api_key)
|
14
|
+
serverUrl, apiKey = get_octopus_creds(url_and_api_key)
|
15
|
+
|
16
|
+
@name = "Octopus Deploy Upgrade Config #{serverUrl}"
|
17
|
+
@runner = Specinfra::Runner
|
18
|
+
@serverUrl = serverUrl
|
19
|
+
@apiKey = apiKey
|
20
|
+
|
21
|
+
# is it still nil?
|
22
|
+
if serverUrl.nil?
|
23
|
+
raise "'serverUrl' was not provided. Unable to connect to Octopus server to validate configuration."
|
24
|
+
end
|
25
|
+
if apiKey.nil?
|
26
|
+
raise "'apiKey' was not provided. Unable to connect to Octopus server to validate configuration."
|
27
|
+
end
|
28
|
+
|
29
|
+
@upgradeConfig = get_upgrade_config_via_api(serverUrl, apiKey)
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_notification_mode?(mode)
|
33
|
+
false if @upgradeConfig.nil?
|
34
|
+
@upgradeConfig['NotificationMode'] == mode
|
35
|
+
end
|
36
|
+
|
37
|
+
def never_show_notifications?
|
38
|
+
false if @upgradeConfig.nil?
|
39
|
+
has_notification_mode?('NeverShow')
|
40
|
+
end
|
41
|
+
|
42
|
+
def always_show_notifications?
|
43
|
+
false if @upgradeConfig.nil?
|
44
|
+
has_notification_mode?('AlwaysShow')
|
45
|
+
end
|
46
|
+
|
47
|
+
def show_major_minor_notifications?
|
48
|
+
false if @upgradeConfig.nil?
|
49
|
+
has_notification_mode?('ShowOnlyMajorMinor')
|
50
|
+
end
|
51
|
+
|
52
|
+
def include_statistics?
|
53
|
+
false if @upgradeConfig.nil?
|
54
|
+
@upgradeConfig['IncludeStatistics'] == true
|
55
|
+
end
|
56
|
+
|
57
|
+
def allow_checking?
|
58
|
+
false if @upgradeConfig.nil?
|
59
|
+
@upgradeConfig['AllowChecking'] == true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# module-level constructors/entrypoints
|
64
|
+
|
65
|
+
def octopus_deploy_upgrade_config(*url_and_api_key)
|
66
|
+
serverUrl, apiKey = get_octopus_creds(url_and_api_key)
|
67
|
+
OctopusDeployUpgradeConfig.new(serverUrl, apiKey)
|
68
|
+
end
|
69
|
+
|
70
|
+
def octopus_upgrade_config(*url_and_api_key)
|
71
|
+
serverUrl, apiKey = get_octopus_creds(url_and_api_key)
|
72
|
+
octopus_deploy_upgrade_config(serverUrl, apiKey)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def get_upgrade_config_endpoint(serverUrl)
|
78
|
+
endpoint = nil
|
79
|
+
|
80
|
+
url = "#{serverUrl}/api/"
|
81
|
+
|
82
|
+
begin
|
83
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
84
|
+
body = JSON.parse(resp.body)
|
85
|
+
json = body unless body.nil?
|
86
|
+
endpoint = json['Links']['UpgradeConfiguration']
|
87
|
+
rescue => e
|
88
|
+
raise "get_upgrade_config_endpoint: Unable to connect to #{url}: #{e}"
|
89
|
+
end
|
90
|
+
|
91
|
+
endpoint
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_upgrade_config_via_api(serverUrl, apiKey)
|
95
|
+
smtp = nil
|
96
|
+
|
97
|
+
stem = get_upgrade_config_endpoint(serverUrl)
|
98
|
+
url = "#{serverUrl}#{stem}?api-key=#{apiKey}"
|
99
|
+
|
100
|
+
begin
|
101
|
+
resp = Net::HTTP.get_response(URI.parse(url))
|
102
|
+
body = JSON.parse(resp.body)
|
103
|
+
smtp = body unless body.nil?
|
104
|
+
rescue => e
|
105
|
+
raise "get_upgrade_config_via_api: Unable to connect to #{url}: #{e}"
|
106
|
+
end
|
107
|
+
|
108
|
+
smtp
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
include Serverspec::Type
|