ovh-provisioner 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.gitlab-ci.yml +23 -0
  4. data/.rspec +2 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG +7 -0
  7. data/CONTRIBUTING.md +62 -0
  8. data/Gemfile +6 -0
  9. data/LICENSE +202 -0
  10. data/README.md +107 -0
  11. data/Rakefile +24 -0
  12. data/bin/console +32 -0
  13. data/bin/ovh_provisioner +27 -0
  14. data/bin/setup +23 -0
  15. data/lib/ovh/provisioner.rb +43 -0
  16. data/lib/ovh/provisioner/api_list.rb +158 -0
  17. data/lib/ovh/provisioner/api_object/api_object.rb +125 -0
  18. data/lib/ovh/provisioner/api_object/dedicated_server.rb +225 -0
  19. data/lib/ovh/provisioner/api_object/domain_zone.rb +115 -0
  20. data/lib/ovh/provisioner/api_object/ip.rb +83 -0
  21. data/lib/ovh/provisioner/api_object/record.rb +48 -0
  22. data/lib/ovh/provisioner/api_object/vrack.rb +92 -0
  23. data/lib/ovh/provisioner/cli.rb +173 -0
  24. data/lib/ovh/provisioner/cli_domain.rb +138 -0
  25. data/lib/ovh/provisioner/cli_ip.rb +64 -0
  26. data/lib/ovh/provisioner/cli_vrack.rb +71 -0
  27. data/lib/ovh/provisioner/init.rb +77 -0
  28. data/lib/ovh/provisioner/self_cli.rb +81 -0
  29. data/lib/ovh/provisioner/spawner.rb +63 -0
  30. data/lib/ovh/provisioner/version.rb +24 -0
  31. data/ovh-provisioner.gemspec +53 -0
  32. data/spec/config.yml +53 -0
  33. data/spec/helpers/highline_helper.rb +36 -0
  34. data/spec/ovh/provisioner/cli_domain_spec.rb +140 -0
  35. data/spec/ovh/provisioner/cli_ip_spec.rb +90 -0
  36. data/spec/ovh/provisioner/cli_spec.rb +186 -0
  37. data/spec/ovh/provisioner/cli_vrack_spec.rb +83 -0
  38. data/spec/ovh/provisioner/stubs/domain_stubs.rb +204 -0
  39. data/spec/ovh/provisioner/stubs/ip_stubs.rb +152 -0
  40. data/spec/ovh/provisioner/stubs/server_stubs.rb +146 -0
  41. data/spec/ovh/provisioner/stubs/vrack_stubs.rb +87 -0
  42. data/spec/ovh/provisioner_spec.rb +25 -0
  43. data/spec/spec_helper.rb +47 -0
  44. metadata +350 -0
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2015-2016 Sam4Mobile, 2017-2018 Make.org
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require 'spec_helper'
20
+
21
+ # rubocop:disable Metrics/BlockLength
22
+ describe 'ovh-provisioner vrack', :highline do
23
+ context 'list' do
24
+ it 'should output the list of vracks' do
25
+ out = <<-OUTPUT.gsub(/^ /, '')
26
+ vrack:
27
+ avrack: pn-1111
28
+ dedicated_servers:
29
+ test-server-01
30
+ bvrack: pn-2222 - Vrack n°2
31
+ dedicated_servers:
32
+ test-server-02
33
+ tasks:
34
+ init pn-2222.add(test-server-03)
35
+ init pn-2222.remove(test-server-02)
36
+ OUTPUT
37
+ expect { start(self, 'vrack') }.to output(out).to_stdout
38
+ end
39
+ end
40
+
41
+ context 'rm pn-2222 server-02' do
42
+ it 'should ask, then remove test-server-02 from vrack pn-2222' do
43
+ ask = <<-OUTPUT.gsub(/^ /, '')
44
+ You are going to remove those servers from vrack pn-2222(bvrack):
45
+ dedicated_server:
46
+ bvrack:
47
+ test-server-02.afirsttest.com[test-server-02/2]
48
+ test - storage_2016 - bvrack:2.2.2.2 - rescue:centos7_64 - ok
49
+ Rebooting
50
+ Do you want to proceed?
51
+ OUTPUT
52
+ out = <<-OUTPUT.gsub(/^ /, '')
53
+ test-server-02: ok
54
+ init pn-2222.remove(test-server-02)
55
+ OUTPUT
56
+ provide_input('yes')
57
+ expect { start(self, 'vrack') }.to output(out).to_stdout
58
+ expect(consume_output).to eq(ask)
59
+ end
60
+ end
61
+
62
+ context 'add pn-2222 03' do
63
+ it 'should ask, then add test-server-03 in vrack pn-2222' do
64
+ ask = <<-OUTPUT.gsub(/^ /, '')
65
+ You are going to add those servers to vrack pn-2222(bvrack):
66
+ dedicated_server:
67
+ none:
68
+ test-server-03.afirsttest.com[test-server-03/3]
69
+ test - undefined - none:3.3.3.3 - pxe:centos7_64 - ok
70
+ Server is not being installed or reinstalled at the moment
71
+ Do you want to proceed?
72
+ OUTPUT
73
+ out = <<-OUTPUT.gsub(/^ /, '')
74
+ test-server-03: ok
75
+ init pn-2222.add(test-server-03)
76
+ OUTPUT
77
+ provide_input('yes')
78
+ expect { start(self, 'vrack') }.to output(out).to_stdout
79
+ expect(consume_output).to eq(ask)
80
+ end
81
+ end
82
+ end
83
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,204 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2015-2016 Sam4Mobile, 2017-2018 Make.org
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ domains = {
20
+ 'afirsttest.com' => {
21
+ 'lastUpdate' => now,
22
+ 'hasDnsAnycast' => false,
23
+ 'nameServers' => ['somedns.ovh.net', 'somens.ovh.net'],
24
+ 'dnssecSupported' => true
25
+ },
26
+ 'anothertest.com' => {
27
+ 'lastUpdate' => now,
28
+ 'hasDnsAnycast' => false,
29
+ 'nameServers' => ['somedns.ovh.net', 'somens.ovh.net'],
30
+ 'dnssecSupported' => true
31
+ },
32
+ 'sotested.net' => {
33
+ 'lastUpdate' => now,
34
+ 'hasDnsAnycast' => false,
35
+ 'nameServers' => ['somedns.ovh.net', 'somens.ovh.net'],
36
+ 'dnssecSupported' => false
37
+ }
38
+ }
39
+
40
+ dnssecs = {
41
+ 'afirsttest.com' => { 'status' => 'enabled' },
42
+ 'anothertest.com' => { 'status' => 'disabled' },
43
+ 'sotested.net' => { 'status' => 'disabled' }
44
+ }
45
+
46
+ records = {
47
+ 'afirsttest.com' => [1, 2, 4, 7, 9, 10],
48
+ 'anothertest.com' => [3, 5],
49
+ 'sotested.net' => []
50
+ }
51
+
52
+ infos = {
53
+ 1 => {
54
+ 'target' => 'somedns.ovh.net',
55
+ 'ttl' => 0,
56
+ 'zone' => 'afirsttest.com',
57
+ 'fieldType' => 'NS',
58
+ 'id' => 1,
59
+ 'subDomain' => ''
60
+ },
61
+ 2 => {
62
+ 'target' => '1.2.4.5',
63
+ 'ttl' => 1,
64
+ 'zone' => 'afirsttest.com',
65
+ 'fieldType' => 'A',
66
+ 'id' => 2,
67
+ 'subDomain' => 'foo'
68
+ },
69
+ 4 => {
70
+ 'target' => 'some.cname.com.',
71
+ 'ttl' => 2,
72
+ 'zone' => 'afirsttest.com',
73
+ 'fieldType' => 'CNAME',
74
+ 'id' => 4,
75
+ 'subDomain' => 'sub.www'
76
+ },
77
+ 3 => {
78
+ 'target' => 'redirect.something.net',
79
+ 'ttl' => 3,
80
+ 'zone' => 'anothertest.com',
81
+ 'fieldType' => 'MX',
82
+ 'id' => 3,
83
+ 'subDomain' => ''
84
+ },
85
+ 5 => {
86
+ 'target' => '0 0 993 ssl.something.net',
87
+ 'ttl' => 0,
88
+ 'zone' => 'anothertest.com',
89
+ 'fieldType' => 'SRV',
90
+ 'id' => 5,
91
+ 'subDomain' => '_imaps._tcp'
92
+ },
93
+ 7 => {
94
+ 'target' => '7.7.7.7',
95
+ 'ttl' => 2,
96
+ 'zone' => 'afirsttest.com',
97
+ 'fieldType' => 'A',
98
+ 'id' => 7,
99
+ 'subDomain' => 'some.sub'
100
+ },
101
+ 9 => { # Will be deleted by rename
102
+ 'target' => '1.1.1.1',
103
+ 'ttl' => 2,
104
+ 'zone' => 'afirsttest.com',
105
+ 'fieldType' => 'A',
106
+ 'id' => 9,
107
+ 'subDomain' => 'test-server-01'
108
+ },
109
+ 10 => { # use by rename, refuse 03 renaming
110
+ 'target' => 'test-server-03',
111
+ 'ttl' => 0,
112
+ 'zone' => 'afirsttest.com',
113
+ 'fieldType' => 'CNAME',
114
+ 'id' => 10,
115
+ 'subDomain' => 'test-undef-3'
116
+ }
117
+ }
118
+
119
+ body_add_cname = {
120
+ 'fieldType' => 'CNAME',
121
+ 'target' => 'serv.dom.io.',
122
+ 'ttl' => 0,
123
+ 'subDomain' => 'test'
124
+ }
125
+
126
+ body_add_a = body_add_cname.dup
127
+ body_add_a['fieldType'] = 'A'
128
+
129
+ result_add_cname = body_add_cname.dup.merge(
130
+ 'zone' => 'afirsttest.com',
131
+ 'id' => 6
132
+ )
133
+
134
+ result_add_a = {
135
+ 'message' => "Invalid IPv4 #{body_add_a['target']} for "\
136
+ "#{body_add_a['fieldType']} record of "\
137
+ "#{body_add_a['subDomain']}.#{result_add_cname['zone']}"
138
+ }
139
+
140
+ def rename_body(xxx)
141
+ {
142
+ 'fieldType' => 'A',
143
+ 'target' => "#{xxx}.#{xxx}.#{xxx}.#{xxx}",
144
+ 'ttl' => 0,
145
+ 'subDomain' => "test-#{xxx == 1 ? 'comp' : 'sto'}16-#{xxx}"
146
+ }
147
+ end
148
+
149
+ def rename_result(xxx)
150
+ rename_body(xxx).dup.merge(
151
+ 'zone' => 'afirsttest.com',
152
+ 'id' => 8
153
+ )
154
+ end
155
+
156
+ # Stubs
157
+ # rubocop:disable Metrics/BlockLength
158
+ RSpec.configure do |config|
159
+ config.before(:each) do
160
+ url = 'https://api.test.com/1.0/domain/zone'
161
+
162
+ stub_request(:get, "#{url}/")
163
+ .to_return(status: 200, body: domains.keys.to_json, headers: {})
164
+
165
+ domains.each_pair do |domain, general|
166
+ stub_request(:get, "#{url}/#{domain}/")
167
+ .to_return(status: 200, body: general.to_json, headers: {})
168
+
169
+ stub_request(:get, "#{url}/#{domain}/dnssec")
170
+ .to_return(status: 200, body: dnssecs[domain].to_json, headers: {})
171
+
172
+ stub_request(:get, "#{url}/#{domain}/record/")
173
+ .to_return(status: 200, body: records[domain].to_json, headers: {})
174
+
175
+ records[domain].each do |record|
176
+ stub_request(:get, "#{url}/#{domain}/record/#{record}/")
177
+ .to_return(status: 200, body: infos[record].to_json, headers: {})
178
+ end
179
+ end
180
+
181
+ stub_request(:post, "#{url}/afirsttest.com/record")
182
+ .with(body: body_add_cname.to_json)
183
+ .to_return(status: 200, body: result_add_cname.to_json, headers: {})
184
+
185
+ stub_request(:post, "#{url}/afirsttest.com/record")
186
+ .with(body: body_add_a.to_json)
187
+ .to_return(status: 400, body: result_add_a.to_json, headers: {})
188
+
189
+ stub_request(:post, "#{url}/afirsttest.com/refresh")
190
+ .to_return(status: 200, body: 'null', headers: {})
191
+
192
+ %w[4 7 9].each do |id|
193
+ stub_request(:delete, "#{url}/afirsttest.com/record/#{id}")
194
+ .to_return(status: 200, body: 'null', headers: {})
195
+ end
196
+
197
+ (1..2).each do |x|
198
+ stub_request(:post, "#{url}/afirsttest.com/record")
199
+ .with(body: rename_body(x).to_json)
200
+ .to_return(status: 200, body: rename_result(x).to_json, headers: {})
201
+ end
202
+ end
203
+ end
204
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2015-2016 Sam4Mobile, 2017-2018 Make.org
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ ips = (1..3).map do |i|
20
+ {
21
+ "#{i}.#{i}.#{i}.#{i}" => {
22
+ 'organisationId' => i == 3 ? 'test' : nil,
23
+ 'country' => i == 3 ? 'some' : nil,
24
+ 'routedTo' => {
25
+ 'serviceName' => "test-server-0#{i}"
26
+ },
27
+ 'ip' => "#{i}.#{i}.#{i}.#{i}/32",
28
+ 'canBeTerminated' => i == 2,
29
+ 'type' => 'dedicated',
30
+ 'description' => i == 1 ? 'First server' : nil
31
+ }
32
+ }
33
+ end.inject(:merge)
34
+
35
+ reverse = {
36
+ '1.1.1.1' => [
37
+ 200,
38
+ {
39
+ 'ipReverse' => '1.1.1.1',
40
+ 'reverse' => 'test-server-01.test.com.'
41
+ }
42
+ ],
43
+ '2.2.2.2' => [
44
+ 404,
45
+ {
46
+ 'message' => 'The requested object (ipReverse = 2.2.2.2) does not exist'
47
+ }
48
+ ],
49
+ '3.3.3.3' => [
50
+ 404,
51
+ {
52
+ 'message' => 'The requested object (ipReverse = 3.3.3.3) does not exist'
53
+ }
54
+ ]
55
+ }
56
+
57
+ set2 = {
58
+ 'ipReverse' => '2.2.2.2',
59
+ 'reverse' => 'test-server-02.test.com'
60
+ }
61
+
62
+ ret2 = set2.dup
63
+ ret2[reverse] = "#{ret2[reverse]}."
64
+
65
+ set1 = {
66
+ 'ipReverse' => '1.1.1.1',
67
+ 'reverse' => 'test-comp16-1.afirsttest.com'
68
+ }
69
+
70
+ fail1 = {
71
+ 'message' =>
72
+ 'Cannot check if test-comp16-1.afirsttest.com. resolves to 1.1.1.1'
73
+ }
74
+
75
+ set22 = {
76
+ 'ipReverse' => '2.2.2.2',
77
+ 'reverse' => 'test-sto16-2.afirsttest.com'
78
+ }
79
+
80
+ fail22 = {
81
+ 'message' =>
82
+ 'Cannot check if test-sto16-2.afirsttest.com. resolves to 2.2.2.2'
83
+ }
84
+
85
+ set3 = {
86
+ 'ipReverse' => '3.3.3.3',
87
+ 'reverse' => 'invalid-test-03'
88
+ }
89
+
90
+ fail3 = {
91
+ 'message' => 'Cannot check if invalid-test-03. resolves to 3.3.3.3'
92
+ }
93
+
94
+ set32 = {
95
+ 'ipReverse' => '3.3.3.3',
96
+ 'reverse' => 'test-undef-3.afirsttest.com'
97
+ }
98
+
99
+ fail32 = {
100
+ 'message' => "Cannot check if #{set32['reverse']}. resolves to 3.3.3.3"
101
+ }
102
+
103
+ ret32 = set32.dup.merge('reverse' => "#{set32['reverse']}.")
104
+
105
+ # Stubs
106
+ # rubocop:disable Metrics/BlockLength
107
+ RSpec.configure do |config|
108
+ config.before(:each) do
109
+ url = 'https://api.test.com/1.0/ip'
110
+
111
+ stub_request(:get, "#{url}/")
112
+ .to_return(status: 200,
113
+ body: ips.keys.map { |ip| ips[ip]['ip'] }.to_json,
114
+ headers: {})
115
+
116
+ ips.each_pair do |ip, general|
117
+ ip_url = "#{ip}%2F32"
118
+ stub_request(:get, "#{url}/#{ip_url}/")
119
+ .to_return(status: 200, body: general.to_json, headers: {})
120
+
121
+ stub_request(:get, "#{url}/#{ip_url}/reverse/#{ip}")
122
+ .to_return(status: reverse[ip].first,
123
+ body: reverse[ip][-1].to_json,
124
+ headers: {})
125
+ end
126
+
127
+ stub_request(:post, "#{url}/2.2.2.2%2F32/reverse")
128
+ .with(body: set2.to_json)
129
+ .to_return(status: 200, body: ret2.to_json, headers: {})
130
+
131
+ stub_request(:post, "#{url}/1.1.1.1%2F32/reverse")
132
+ .with(body: set1.to_json)
133
+ .to_return(status: 400, body: fail1.to_json, headers: {})
134
+
135
+ stub_request(:post, "#{url}/2.2.2.2%2F32/reverse")
136
+ .with(body: set22.to_json)
137
+ .to_return(status: 400, body: fail22.to_json, headers: {})
138
+
139
+ stub_request(:post, "#{url}/3.3.3.3%2F32/reverse")
140
+ .with(body: set3.to_json)
141
+ .to_return(status: 400, body: fail3.to_json, headers: {})
142
+
143
+ stub_request(:delete, "#{url}/1.1.1.1%2F32/reverse/1.1.1.1")
144
+ .to_return(status: 200, body: nil.to_json, headers: {})
145
+
146
+ stub_request(:post, "#{url}/3.3.3.3%2F32/reverse")
147
+ .with(body: set32.to_json)
148
+ .to_return(status: 400, body: fail32.to_json, headers: {})
149
+ .to_return(status: 200, body: ret32.to_json, headers: {})
150
+ end
151
+ end
152
+ # rubocop:enable Metrics/BlockLength
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2015-2016 Sam4Mobile, 2017-2018 Make.org
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ # General config of servers
20
+ servers = (1..3).map do |i|
21
+ {
22
+ "test-server-0#{i}" => {
23
+ 'datacenter' => "test#{i}",
24
+ 'ip' => "#{i}.#{i}.#{i}.#{i}",
25
+ 'os' => 'centos7_64',
26
+ 'state' => 'ok',
27
+ 'serverId' => i,
28
+ 'bootId' => i,
29
+ 'name' => "test-server-0#{i}",
30
+ 'reverse' => "test-server-0#{i}.afirsttest.com."
31
+ }
32
+ }
33
+ end.inject(:merge)
34
+
35
+ # BootId config
36
+ boots = {
37
+ 1 => { 'bootType' => 'harddisk' },
38
+ 2 => { 'bootType' => 'rescue' },
39
+ 3 => { 'bootType' => 'pxe' }
40
+ }
41
+
42
+ # Hardware profil and flavors
43
+ hardwares = {}
44
+ %w[compute_2016 storage_2016 compute_2016].each_with_index do |flavor, i|
45
+ config = YAML.load_file('spec/config.yml')
46
+ hardwares["test-server-0#{i + 1}"] = config['flavors'][flavor]['hardware']
47
+ end
48
+ # We can get more info, it won't affect the flavor
49
+ hardwares['test-server-02']['motherboard'] = 'X10DRH-iT'
50
+ # If a value is different, it is a different flavor
51
+ hardwares['test-server-03']['memorySize']['value'] = 262_144
52
+
53
+ # Vracks
54
+ vracks = {
55
+ 'test-server-01' => ['pn-1111'],
56
+ 'test-server-02' => ['pn-2222'],
57
+ 'test-server-03' => []
58
+ }
59
+
60
+ # Install status
61
+ idle = OVH::Provisioner::APIObject::DedicatedServer::IDLE
62
+ install_status = {
63
+ 'test-server-01' => [
64
+ 200,
65
+ '{ "progress": [
66
+ {"status": "doing", "comment": "Setting things up"},
67
+ {"status": "to do", "comment": "Rebooting on fresh system"}
68
+ ]
69
+ }'
70
+ ],
71
+ 'test-server-02' => [
72
+ 200,
73
+ '{ "progress": [
74
+ {"status": "done", "comment": "Preparing installation"},
75
+ {"status": "doing", "comment": "Rebooting"}
76
+ ]
77
+ }'
78
+ ],
79
+ 'test-server-03' => [
80
+ 404, "{\"message\": \"#{idle}\"}"
81
+ ]
82
+ }
83
+
84
+ def install_body(server, distrib = nil, ssh = 'testKey')
85
+ details = { 'customHostname' => "#{server}.afirsttest.com" }
86
+ details['useDistribKernel'] = distrib unless distrib.nil?
87
+ details['sshKeyName'] = ssh unless ssh.nil?
88
+ {
89
+ 'templateName' => 'test-template',
90
+ 'details' => details
91
+ }
92
+ end
93
+
94
+ reinstall_answer = <<-JSON.gsub(/^ /, '')
95
+ {
96
+ "taskId": 123,
97
+ "function": "reinstallServer",
98
+ "lastUpdate": "#{now}",
99
+ "comment": "Start dedicated server installation",
100
+ "status": "init",
101
+ "startDate": "#{now}",
102
+ "doneDate": null
103
+ }
104
+ JSON
105
+
106
+ # Stubs
107
+ # rubocop:disable Metrics/BlockLength
108
+ RSpec.configure do |config|
109
+ config.before(:each) do
110
+ url = 'https://api.test.com/1.0/dedicated/server'
111
+
112
+ stub_request(:get, "#{url}/")
113
+ .to_return(status: 200, body: servers.keys.to_json, headers: {})
114
+
115
+ servers.each_pair do |server, general|
116
+ stub_request(:get, "#{url}/#{server}/")
117
+ .to_return(status: 200, body: general.to_json, headers: {})
118
+
119
+ boot_id = general['bootId']
120
+ boot = boots[boot_id].to_json
121
+ stub_request(:get, "#{url}/#{server}/boot/#{boot_id}")
122
+ .to_return(status: 200, body: boot, headers: {})
123
+
124
+ hardware = hardwares[server].to_json
125
+ stub_request(:get, "#{url}/#{server}/specifications/hardware")
126
+ .to_return(status: 200, body: hardware, headers: {})
127
+
128
+ vrack = vracks[server].to_json
129
+ stub_request(:get, "#{url}/#{server}/vrack")
130
+ .to_return(status: 200, body: vrack, headers: {})
131
+
132
+ status, body = install_status[server]
133
+ stub_request(:get, "#{url}/#{server}/install/status")
134
+ .to_return(status: status, body: body, headers: {})
135
+
136
+ stub_request(:post, "#{url}/#{server}/install/start")
137
+ .with(body: install_body(server, false).to_json)
138
+ .to_return(status: 200, body: reinstall_answer, headers: {})
139
+
140
+ stub_request(:post, "#{url}/#{server}/install/start")
141
+ .with(body: install_body(server, true).to_json)
142
+ .to_return(status: 200, body: reinstall_answer, headers: {})
143
+ end
144
+ end
145
+ end
146
+ # rubocop:enable Metrics/BlockLength