beaker-vcloud 1.1.0 → 2.1.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,15 +1,49 @@
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.1.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-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fakefs
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '13.2'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 13.2.1
37
+ type: :development
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '13.2'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 13.2.1
13
47
  - !ruby/object:Gem::Dependency
14
48
  name: rspec
15
49
  requirement: !ruby/object:Gem::Requirement
@@ -28,86 +62,98 @@ dependencies:
28
62
  name: rspec-its
29
63
  requirement: !ruby/object:Gem::Requirement
30
64
  requirements:
31
- - - ">="
65
+ - - "~>"
32
66
  - !ruby/object:Gem::Version
33
- version: '0'
67
+ version: '1.3'
34
68
  type: :development
35
69
  prerelease: false
36
70
  version_requirements: !ruby/object:Gem::Requirement
37
71
  requirements:
38
- - - ">="
72
+ - - "~>"
39
73
  - !ruby/object:Gem::Version
40
- version: '0'
74
+ version: '1.3'
41
75
  - !ruby/object:Gem::Dependency
42
- name: fakefs
76
+ name: voxpupuli-rubocop
43
77
  requirement: !ruby/object:Gem::Requirement
44
78
  requirements:
45
79
  - - "~>"
46
80
  - !ruby/object:Gem::Version
47
- version: '0.6'
81
+ version: 2.7.0
48
82
  type: :development
49
83
  prerelease: false
50
84
  version_requirements: !ruby/object:Gem::Requirement
51
85
  requirements:
52
86
  - - "~>"
53
87
  - !ruby/object:Gem::Version
54
- version: '0.6'
88
+ version: 2.7.0
55
89
  - !ruby/object:Gem::Dependency
56
- name: rake
90
+ name: beaker
57
91
  requirement: !ruby/object:Gem::Requirement
58
92
  requirements:
59
93
  - - ">="
60
94
  - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
95
+ version: '5.8'
96
+ - - "<"
97
+ - !ruby/object:Gem::Version
98
+ version: '7'
99
+ type: :runtime
63
100
  prerelease: false
64
101
  version_requirements: !ruby/object:Gem::Requirement
65
102
  requirements:
66
103
  - - ">="
67
104
  - !ruby/object:Gem::Version
68
- version: '0'
105
+ version: '5.8'
106
+ - - "<"
107
+ - !ruby/object:Gem::Version
108
+ version: '7'
69
109
  - !ruby/object:Gem::Dependency
70
- name: stringify-hash
110
+ name: beaker-vmware
71
111
  requirement: !ruby/object:Gem::Requirement
72
112
  requirements:
73
113
  - - "~>"
74
114
  - !ruby/object:Gem::Version
75
- version: 0.0.0
115
+ version: '2.1'
76
116
  type: :runtime
77
117
  prerelease: false
78
118
  version_requirements: !ruby/object:Gem::Requirement
79
119
  requirements:
80
120
  - - "~>"
81
121
  - !ruby/object:Gem::Version
82
- version: 0.0.0
122
+ version: '2.1'
83
123
  - !ruby/object:Gem::Dependency
84
- name: rbvmomi
124
+ name: rbvmomi2
85
125
  requirement: !ruby/object:Gem::Requirement
86
126
  requirements:
87
127
  - - "~>"
88
128
  - !ruby/object:Gem::Version
89
- version: '1.9'
129
+ version: '3.7'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 3.7.1
90
133
  type: :runtime
91
134
  prerelease: false
92
135
  version_requirements: !ruby/object:Gem::Requirement
93
136
  requirements:
94
137
  - - "~>"
95
138
  - !ruby/object:Gem::Version
96
- version: '1.9'
139
+ version: '3.7'
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ version: 3.7.1
97
143
  - !ruby/object:Gem::Dependency
98
- name: beaker-vmware
144
+ name: stringify-hash
99
145
  requirement: !ruby/object:Gem::Requirement
100
146
  requirements:
101
- - - ">="
147
+ - - "~>"
102
148
  - !ruby/object:Gem::Version
103
- version: '0'
149
+ version: 0.0.0
104
150
  type: :runtime
105
151
  prerelease: false
106
152
  version_requirements: !ruby/object:Gem::Requirement
107
153
  requirements:
108
- - - ">="
154
+ - - "~>"
109
155
  - !ruby/object:Gem::Version
110
- version: '0'
156
+ version: 0.0.0
111
157
  description: For use for the Beaker acceptance testing tool
112
158
  email:
113
159
  - voxpupuli@groups.io
@@ -120,6 +166,8 @@ files:
120
166
  - ".github/workflows/release.yml"
121
167
  - ".github/workflows/test.yml"
122
168
  - ".gitignore"
169
+ - ".rubocop.yml"
170
+ - ".rubocop_todo.yml"
123
171
  - ".simplecov"
124
172
  - CHANGELOG.md
125
173
  - Gemfile
@@ -131,10 +179,12 @@ files:
131
179
  - lib/beaker-vcloud/version.rb
132
180
  - lib/beaker/hypervisor/vcloud.rb
133
181
  - spec/beaker/hypervisor/vcloud_spec.rb
182
+ - spec/mock_vsphere.rb
183
+ - spec/mock_vsphere_helper.rb
134
184
  - spec/spec_helper.rb
135
185
  homepage: https://github.com/voxpupuli/beaker-vcloud
136
186
  licenses:
137
- - Apache2
187
+ - Apache-2.0
138
188
  metadata: {}
139
189
  post_install_message:
140
190
  rdoc_options: []
@@ -144,14 +194,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
144
194
  requirements:
145
195
  - - ">="
146
196
  - !ruby/object:Gem::Version
147
- version: '0'
197
+ version: '2.7'
148
198
  required_rubygems_version: !ruby/object:Gem::Requirement
149
199
  requirements:
150
200
  - - ">="
151
201
  - !ruby/object:Gem::Version
152
202
  version: '0'
153
203
  requirements: []
154
- rubygems_version: 3.2.22
204
+ rubygems_version: 3.5.9
155
205
  signing_key:
156
206
  specification_version: 4
157
207
  summary: Beaker DSL Extension Helpers!