beaker-vmware 1.0.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,24 @@
1
+ require 'beaker'
2
+ require 'mock_fission'
3
+ require 'mock_vsphere'
4
+ require 'mock_vsphere_helper'
5
+
1
6
  begin
2
7
  require 'simplecov'
3
8
  require 'simplecov-console'
4
9
  require 'codecov'
5
10
  rescue LoadError
11
+ # Do nothing if no required gem installed
6
12
  else
7
13
  SimpleCov.start do
8
14
  track_files 'lib/**/*.rb'
9
15
 
10
16
  add_filter '/spec'
11
-
12
- enable_coverage :branch
13
-
14
17
  # do not track vendored files
15
18
  add_filter '/vendor'
16
19
  add_filter '/.vendor'
20
+
21
+ enable_coverage :branch
17
22
  end
18
23
 
19
24
  SimpleCov.formatters = [
@@ -22,10 +27,7 @@ else
22
27
  ]
23
28
  end
24
29
 
25
- require 'rspec/its'
26
- require 'beaker'
27
-
28
- Dir.glob(Dir.pwd + '/lib/beaker/hypervisor/*.rb') {|file| require file}
30
+ Dir['./lib/beaker/hypervisor/*.rb'].sort.each { |file| require file }
29
31
 
30
32
  # setup & require beaker's spec_helper.rb
31
33
  beaker_gem_spec = Gem::Specification.find_by_name('beaker')
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beaker-vmware
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.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: 2023-03-28 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.4'
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.4'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rspec-its
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,21 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: fakefs
42
+ name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.6'
47
+ version: '3.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.6'
54
+ version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: rspec-its
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,61 +67,81 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: yard
70
+ name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.48.1
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.48.1
83
83
  - !ruby/object:Gem::Dependency
84
- name: markdown
84
+ name: rubocop-performance
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '1.10'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '1.10'
97
97
  - !ruby/object:Gem::Dependency
98
- name: thin
98
+ name: rubocop-rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop-rspec
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - ">="
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '1.44'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - ">="
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '1.44'
111
125
  - !ruby/object:Gem::Dependency
112
- name: stringify-hash
126
+ name: beaker
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - "~>"
129
+ - - ">="
116
130
  - !ruby/object:Gem::Version
117
- version: 0.0.0
131
+ version: '4'
132
+ - - "<"
133
+ - !ruby/object:Gem::Version
134
+ version: '6'
118
135
  type: :runtime
119
136
  prerelease: false
120
137
  version_requirements: !ruby/object:Gem::Requirement
121
138
  requirements:
122
- - - "~>"
139
+ - - ">="
123
140
  - !ruby/object:Gem::Version
124
- version: 0.0.0
141
+ version: '4'
142
+ - - "<"
143
+ - !ruby/object:Gem::Version
144
+ version: '6'
125
145
  - !ruby/object:Gem::Dependency
126
146
  name: fission
127
147
  requirement: !ruby/object:Gem::Requirement
@@ -140,16 +160,36 @@ dependencies:
140
160
  name: rbvmomi
141
161
  requirement: !ruby/object:Gem::Requirement
142
162
  requirements:
143
- - - "~>"
163
+ - - ">="
144
164
  - !ruby/object:Gem::Version
145
165
  version: '1.9'
166
+ - - "<"
167
+ - !ruby/object:Gem::Version
168
+ version: '4.0'
146
169
  type: :runtime
147
170
  prerelease: false
148
171
  version_requirements: !ruby/object:Gem::Requirement
149
172
  requirements:
150
- - - "~>"
173
+ - - ">="
151
174
  - !ruby/object:Gem::Version
152
175
  version: '1.9'
176
+ - - "<"
177
+ - !ruby/object:Gem::Version
178
+ version: '4.0'
179
+ - !ruby/object:Gem::Dependency
180
+ name: stringify-hash
181
+ requirement: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - "~>"
184
+ - !ruby/object:Gem::Version
185
+ version: 0.0.0
186
+ type: :runtime
187
+ prerelease: false
188
+ version_requirements: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - "~>"
191
+ - !ruby/object:Gem::Version
192
+ version: 0.0.0
153
193
  description: For use for the Beaker acceptance testing tool
154
194
  email:
155
195
  - voxpupuli@groups.io
@@ -162,6 +202,8 @@ files:
162
202
  - ".github/workflows/release.yml"
163
203
  - ".github/workflows/test.yml"
164
204
  - ".gitignore"
205
+ - ".rubocop.yml"
206
+ - ".rubocop_todo.yml"
165
207
  - ".simplecov"
166
208
  - CHANGELOG.md
167
209
  - Gemfile
@@ -180,6 +222,9 @@ files:
180
222
  - spec/beaker/hypervisor/fusion_spec.rb
181
223
  - spec/beaker/hypervisor/vsphere_helper_spec.rb
182
224
  - spec/beaker/hypervisor/vsphere_spec.rb
225
+ - spec/mock_fission.rb
226
+ - spec/mock_vsphere.rb
227
+ - spec/mock_vsphere_helper.rb
183
228
  - spec/spec_helper.rb
184
229
  - vmware_fusion.md
185
230
  - vsphere.md
@@ -195,14 +240,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
240
  requirements:
196
241
  - - ">="
197
242
  - !ruby/object:Gem::Version
198
- version: '0'
243
+ version: '2.7'
199
244
  required_rubygems_version: !ruby/object:Gem::Requirement
200
245
  requirements:
201
246
  - - ">="
202
247
  - !ruby/object:Gem::Version
203
248
  version: '0'
204
249
  requirements: []
205
- rubygems_version: 3.2.22
250
+ rubygems_version: 3.2.33
206
251
  signing_key:
207
252
  specification_version: 4
208
253
  summary: Beaker DSL Extension Helpers!