beaker-vcloud 1.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,284 @@
1
+ class MockRbVmomiSnapshot
2
+ attr_accessor :name, :rootSnapshotList, :childSnapshotList
3
+
4
+ def initialize
5
+ @name = nil
6
+ @rootSnapshotList = []
7
+ @childSnapshotList = []
8
+ end
9
+
10
+ def print_nested_array(arg)
11
+ str = '[ '
12
+ arg.each do |arry|
13
+ if arry.is_a?(Array)
14
+ str += print_nested_array(arry)
15
+ elsif arry.is_a?(MockRbVmomiSnapshot)
16
+ str += arry.to_s + ', '
17
+ end
18
+ end
19
+ str + ' ]'
20
+ end
21
+
22
+ def to_s
23
+ "Snapshot(name: #{@name}, rootSnapshotlist: #{print_nested_array(@rootSnapshotList)}, childSnapshotList: #{print_nested_array(@childSnapshotList)})"
24
+ end
25
+
26
+ def snapshot
27
+ self
28
+ end
29
+ end
30
+
31
+ class MockRbVmomiVM
32
+ attr_accessor :snapshot, :name, :state
33
+
34
+ def info
35
+ self
36
+ end
37
+
38
+ def process_snaphash(snaphash)
39
+ shotlist = []
40
+ snaphash.each do |name, subsnaps|
41
+ new_snap = MockRbVmomiSnapshot.new
42
+ new_snap.name = name
43
+ new_snap.childSnapshotList = process_snaphash(subsnaps) if subsnaps.is_a?(Hash)
44
+ shotlist << new_snap
45
+ end
46
+ shotlist
47
+ end
48
+
49
+ def get_snapshot(name, snaplist = @snapshot.rootSnapshotList)
50
+ snapshot = nil
51
+ snaplist.each do |snap|
52
+ if snap.is_a?(Array)
53
+ snapshot = get_snapshot(snap, name)
54
+ elsif snap.name == name
55
+ snapshot = snap.snapshot
56
+ end
57
+ end
58
+ snapshot
59
+ end
60
+
61
+ def initialize(name, snaphash)
62
+ @name = name
63
+ @snapshot = MockRbVmomiSnapshot.new
64
+ @snapshot.name = name
65
+ @snapshot.rootSnapshotList = process_snaphash(snaphash)
66
+ end
67
+ end
68
+
69
+ class MockRbVmomiConnection
70
+ class CustomizationSpecManager
71
+ class CustomizationSpec
72
+ def spec
73
+ true
74
+ end
75
+ end
76
+
77
+ def initialize
78
+ @customizationspec = CustomizationSpec.new
79
+ end
80
+
81
+ def GetCustomizationSpec(_arg)
82
+ @customizationspec
83
+ end
84
+ end
85
+
86
+ class PropertyCollector
87
+ class Result
88
+ def initialize(name, object)
89
+ @name = name
90
+ @object = object
91
+ end
92
+
93
+ def val
94
+ @name
95
+ end
96
+
97
+ def obj
98
+ @object
99
+ end
100
+
101
+ def propSet
102
+ [self]
103
+ end
104
+ end
105
+
106
+ class ResultContainer
107
+ attr_accessor :token
108
+
109
+ def initialize
110
+ @results = []
111
+ end
112
+
113
+ def objects
114
+ @results
115
+ end
116
+
117
+ def add_object(obj)
118
+ @results << obj
119
+ end
120
+ end
121
+
122
+ def initialize
123
+ @results = ResultContainer.new
124
+ end
125
+
126
+ def RetrievePropertiesEx(_hash)
127
+ @results.token = true
128
+ @results
129
+ end
130
+
131
+ def ContinueRetrievePropertiesEx(_token)
132
+ @results.token = false
133
+ @results
134
+ end
135
+
136
+ def add_result(name, object)
137
+ @results.add_object(Result.new(name, object))
138
+ end
139
+
140
+ def WaitForUpdates(_arg)
141
+ result = OpenStruct.new
142
+ result.version = 'version'
143
+ result
144
+ end
145
+
146
+ def CreateFilter(_arg)
147
+ filter = OpenStruct.new
148
+ filter.DestroyPropertyFilter = true
149
+ filter
150
+ end
151
+ end
152
+
153
+ class ServiceInstance
154
+ class Datacenter
155
+ attr_accessor :vmFolder, :hostFolder
156
+
157
+ def initialize
158
+ @vmFolder = MockRbVmomi::VIM::Folder.new
159
+ @vmFolder.name = '/root'
160
+ end
161
+
162
+ def find_datastore(_arg)
163
+ true
164
+ end
165
+ end
166
+
167
+ def initialize
168
+ @datacenter = Datacenter.new
169
+ end
170
+
171
+ def find_datacenter(_dc)
172
+ @datacenter
173
+ end
174
+ end
175
+
176
+ class ServiceManager
177
+ class ViewManager
178
+ def CreateContainerView(hash)
179
+ @view = hash
180
+ end
181
+ end
182
+
183
+ def initialize
184
+ @customizationspecmanager = CustomizationSpecManager.new
185
+ @viewmanager = ViewManager.new
186
+ end
187
+
188
+ def customizationSpecManager
189
+ @customizationspecmanager
190
+ end
191
+
192
+ def viewManager
193
+ @viewmanager
194
+ end
195
+
196
+ def rootFolder
197
+ '/root'
198
+ end
199
+ end
200
+
201
+ def initialize(opts)
202
+ @host = opts[:host]
203
+ @user = opts[:user]
204
+ @password = opts[:password]
205
+ @insecure = opts[:insecure]
206
+ @serviceinstance = ServiceInstance.new
207
+ @servicemanager = ServiceManager.new
208
+ @propertycollector = PropertyCollector.new
209
+ end
210
+
211
+ def serviceInstance
212
+ @serviceinstance
213
+ end
214
+
215
+ def serviceContent
216
+ @servicemanager
217
+ end
218
+
219
+ def propertyCollector
220
+ @propertycollector
221
+ end
222
+
223
+ def set_info(vms)
224
+ vms.each do |vm|
225
+ @propertycollector.add_result(vm.name, vm)
226
+ end
227
+ end
228
+ end
229
+
230
+ class MockRbVmomi
231
+ class VIM
232
+ class Folder
233
+ attr_accessor :name
234
+
235
+ def find
236
+ self
237
+ end
238
+
239
+ def childEntity
240
+ self
241
+ end
242
+
243
+ def resourcePool
244
+ self
245
+ end
246
+
247
+ def traverse(_path, _type = Object, _create = false)
248
+ self
249
+ end
250
+ end
251
+
252
+ class ResourcePool
253
+ attr_accessor :name
254
+
255
+ def find
256
+ self
257
+ end
258
+
259
+ def resourcePool
260
+ self
261
+ end
262
+ end
263
+
264
+ class ClusterComputeResource
265
+ attr_accessor :name
266
+
267
+ def find
268
+ self
269
+ end
270
+
271
+ def resourcePool
272
+ self
273
+ end
274
+ end
275
+
276
+ class TraversalSpec
277
+ def initialize(hash); end
278
+ end
279
+
280
+ def self.connect(opts)
281
+ MockRbVmomiConnection.new(opts)
282
+ end
283
+ end
284
+ end
@@ -0,0 +1,167 @@
1
+ class MockVsphereSnapshot
2
+ attr_accessor :name
3
+
4
+ def RevertToSnapshot_Task
5
+ self
6
+ end
7
+
8
+ def wait_for_completion
9
+ true
10
+ end
11
+ end
12
+
13
+ class MockVsphereVM
14
+ attr_accessor :name, :powerState, :snapshot, :template, :toolsRunningStatus
15
+
16
+ def initialize
17
+ @powerState = 'poweredOff'
18
+ @toolsRunningStatus = 'guestToolsStopped'
19
+ @first = true
20
+ end
21
+
22
+ def runtime
23
+ self
24
+ end
25
+
26
+ attr_reader :powerState
27
+
28
+ def toolsRunningStatus
29
+ prev = @toolsRunningStatus
30
+ @toolsRunningStatus = 'guestToolsRunning'
31
+ prev
32
+ end
33
+
34
+ def PowerOnVM_Task
35
+ @powerState = 'poweredOn'
36
+ self
37
+ end
38
+
39
+ def PowerOffVM_Task
40
+ @powerState = 'poweredOff'
41
+ self
42
+ end
43
+
44
+ def summary
45
+ self
46
+ end
47
+
48
+ def guest
49
+ self
50
+ end
51
+
52
+ def ipAddress
53
+ @toolsRunningStatus = 'guestToolsRunning'
54
+ "#{@name}.ip.address"
55
+ end
56
+
57
+ def CloneVM_Task(opts)
58
+ clone = MockVsphereVM.new
59
+ clone.name = opts[:name]
60
+ clone.snapshot = snapshot
61
+ clone.template = template
62
+ clone.PowerOnVM_Task
63
+ MockVsphereHelper.add_vm(opts[:name], clone)
64
+ clone
65
+ end
66
+
67
+ def wait_for_completion
68
+ true
69
+ end
70
+
71
+ def Destroy_Task
72
+ true
73
+ end
74
+ end
75
+
76
+ class MockVsphereHelper
77
+ @@fog_file = {}
78
+ @@vms = {}
79
+
80
+ def initialize(arg); end
81
+
82
+ def self.add_vm(name, vm)
83
+ @@vms[name] = vm
84
+ end
85
+
86
+ def self.set_config(conf)
87
+ @@fog_file = conf
88
+ end
89
+
90
+ def self.powerOn
91
+ @@vms.each do |_name, vm|
92
+ vm.powerState = 'poweredOn'
93
+ end
94
+ end
95
+
96
+ def self.powerOff
97
+ @@vms.each do |_name, vm|
98
+ vm.powerState = 'poweredOff'
99
+ end
100
+ end
101
+
102
+ def self.set_vms(hosts)
103
+ @@vms = {}
104
+ hosts.each do |host|
105
+ vm = MockVsphereVM.new
106
+ vm.name = host.name
107
+ vm.snapshot = MockVsphereSnapshot.new
108
+ vm.snapshot.name = host[:snapshot]
109
+ @@vms[host.name] = vm
110
+ template = MockVsphereVM.new
111
+ template.name = host[:template]
112
+ template.snapshot = MockVsphereSnapshot.new
113
+ template.snapshot.name = host[:snapshot]
114
+ @@vms[host[:template]] = template
115
+ end
116
+ end
117
+
118
+ def self.load_config(_file)
119
+ @@fog_file
120
+ end
121
+
122
+ def find_vms(keys)
123
+ found = {}
124
+ keys = ([] << keys)
125
+ keys.flatten!
126
+ keys.each do |key|
127
+ found[key] = @@vms[key] if @@vms.has_key?(key)
128
+ end
129
+ found
130
+ end
131
+
132
+ def self.find_vm(key)
133
+ return unless @@vms.has_key?(key)
134
+
135
+ @@vms[key]
136
+ end
137
+
138
+ def find_snapshot(vm, snap)
139
+ return unless @@vms[vm.name].snapshot.name == snap
140
+
141
+ @@vms[vm.name].snapshot
142
+ end
143
+
144
+ def find_customization(_template)
145
+ nil
146
+ end
147
+
148
+ def find_datastore(_dc, datastore)
149
+ datastore
150
+ end
151
+
152
+ def find_pool(_dc, pool)
153
+ pool
154
+ end
155
+
156
+ def find_folder(_dc, folder)
157
+ folder
158
+ end
159
+
160
+ def wait_for_tasks(_tasks, _try, _attempts)
161
+ true
162
+ end
163
+
164
+ def close
165
+ true
166
+ end
167
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,19 +1,23 @@
1
+ require 'beaker'
2
+ require 'mock_vsphere'
3
+ require 'mock_vsphere_helper'
4
+
1
5
  begin
2
6
  require 'simplecov'
3
7
  require 'simplecov-console'
4
8
  require 'codecov'
5
9
  rescue LoadError
10
+ # Do nothing if no required gem installed
6
11
  else
7
12
  SimpleCov.start do
8
13
  track_files 'lib/**/*.rb'
9
14
 
10
15
  add_filter '/spec'
11
-
12
- enable_coverage :branch
13
-
14
16
  # do not track vendored files
15
17
  add_filter '/vendor'
16
18
  add_filter '/.vendor'
19
+
20
+ enable_coverage :branch
17
21
  end
18
22
 
19
23
  SimpleCov.formatters = [
@@ -22,9 +26,7 @@ else
22
26
  ]
23
27
  end
24
28
 
25
- require 'rspec/its'
26
- require 'beaker'
27
- require 'beaker/hypervisor/vcloud'
29
+ Dir['./lib/beaker/hypervisor/*.rb'].sort.each { |file| require file }
28
30
 
29
31
  # setup & require beaker's spec_helper.rb
30
32
  beaker_gem_spec = Gem::Specification.find_by_name('beaker')
metadata CHANGED
@@ -1,113 +1,153 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-vcloud
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-09 00:00:00.000000000 Z
11
+ date: 2024-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rspec
14
+ name: fakefs
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '2.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.0'
26
+ version: '2.5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec-its
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.2'
31
34
  - - ">="
32
35
  - !ruby/object:Gem::Version
33
- version: '0'
36
+ version: 13.2.1
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '13.2'
38
44
  - - ">="
39
45
  - !ruby/object:Gem::Version
40
- version: '0'
46
+ version: 13.2.1
41
47
  - !ruby/object:Gem::Dependency
42
- name: fakefs
48
+ name: rspec
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - "~>"
46
52
  - !ruby/object:Gem::Version
47
- version: '0.6'
53
+ version: '3.0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
51
57
  requirements:
52
58
  - - "~>"
53
59
  - !ruby/object:Gem::Version
54
- version: '0.6'
60
+ version: '3.0'
55
61
  - !ruby/object:Gem::Dependency
56
- name: rake
62
+ name: rspec-its
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
- - - ">="
65
+ - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '0'
67
+ version: '1.3'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
- - - ">="
72
+ - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '0'
74
+ version: '1.3'
69
75
  - !ruby/object:Gem::Dependency
70
- name: stringify-hash
76
+ name: voxpupuli-rubocop
71
77
  requirement: !ruby/object:Gem::Requirement
72
78
  requirements:
73
79
  - - "~>"
74
80
  - !ruby/object:Gem::Version
75
- version: 0.0.0
76
- type: :runtime
81
+ version: 2.6.0
82
+ type: :development
77
83
  prerelease: false
78
84
  version_requirements: !ruby/object:Gem::Requirement
79
85
  requirements:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
- version: 0.0.0
88
+ version: 2.6.0
83
89
  - !ruby/object:Gem::Dependency
84
- name: rbvmomi
90
+ name: beaker
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - "~>"
88
94
  - !ruby/object:Gem::Version
89
- version: '1.9'
95
+ version: '5.8'
90
96
  type: :runtime
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
100
  - - "~>"
95
101
  - !ruby/object:Gem::Version
96
- version: '1.9'
102
+ version: '5.8'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: beaker-vmware
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '2.1'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '2.1'
117
+ - !ruby/object:Gem::Dependency
118
+ name: rbvmomi2
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3.7'
101
124
  - - ">="
102
125
  - !ruby/object:Gem::Version
103
- version: '0'
126
+ version: 3.7.1
104
127
  type: :runtime
105
128
  prerelease: false
106
129
  version_requirements: !ruby/object:Gem::Requirement
107
130
  requirements:
131
+ - - "~>"
132
+ - !ruby/object:Gem::Version
133
+ version: '3.7'
108
134
  - - ">="
109
135
  - !ruby/object:Gem::Version
110
- version: '0'
136
+ version: 3.7.1
137
+ - !ruby/object:Gem::Dependency
138
+ name: stringify-hash
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: 0.0.0
144
+ type: :runtime
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: 0.0.0
111
151
  description: For use for the Beaker acceptance testing tool
112
152
  email:
113
153
  - voxpupuli@groups.io
@@ -120,6 +160,8 @@ files:
120
160
  - ".github/workflows/release.yml"
121
161
  - ".github/workflows/test.yml"
122
162
  - ".gitignore"
163
+ - ".rubocop.yml"
164
+ - ".rubocop_todo.yml"
123
165
  - ".simplecov"
124
166
  - CHANGELOG.md
125
167
  - Gemfile
@@ -131,10 +173,12 @@ files:
131
173
  - lib/beaker-vcloud/version.rb
132
174
  - lib/beaker/hypervisor/vcloud.rb
133
175
  - spec/beaker/hypervisor/vcloud_spec.rb
176
+ - spec/mock_vsphere.rb
177
+ - spec/mock_vsphere_helper.rb
134
178
  - spec/spec_helper.rb
135
179
  homepage: https://github.com/voxpupuli/beaker-vcloud
136
180
  licenses:
137
- - Apache2
181
+ - Apache-2.0
138
182
  metadata: {}
139
183
  post_install_message:
140
184
  rdoc_options: []
@@ -144,14 +188,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
188
  requirements:
145
189
  - - ">="
146
190
  - !ruby/object:Gem::Version
147
- version: '0'
191
+ version: '2.7'
148
192
  required_rubygems_version: !ruby/object:Gem::Requirement
149
193
  requirements:
150
194
  - - ">="
151
195
  - !ruby/object:Gem::Version
152
196
  version: '0'
153
197
  requirements: []
154
- rubygems_version: 3.2.22
198
+ rubygems_version: 3.2.33
155
199
  signing_key:
156
200
  specification_version: 4
157
201
  summary: Beaker DSL Extension Helpers!