fog-kubevirt 1.2.4 → 1.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ require_relative './shared_context'
2
+
3
+ describe Fog::Kubevirt::Compute do
4
+ before :all do
5
+ conn = KubevirtConnection.new()
6
+ @client = conn.client.pvcs
7
+ end
8
+
9
+ it 'CRD pvc' do
10
+ pvc = {
11
+ :name => 'test-pvc',
12
+ :namespace => 'default',
13
+ :storage_class => '',
14
+ :access_modes => ['ReadWriteOnce'],
15
+ :requests => { storage: "1Gi" }
16
+ }
17
+ @client.create(pvc)
18
+
19
+ created = @client.get(pvc[:name])
20
+ assert_equal(created.name, pvc[:name])
21
+ assert_equal(created.requests, pvc[:requests])
22
+
23
+ @client.delete(pvc[:name])
24
+
25
+ begin
26
+ @client.get('no_pvc')
27
+ fail "pvc should not exist"
28
+ rescue ::Fog::Kubevirt::Errors::ClientError
29
+ # expected
30
+ end
31
+ end
32
+
33
+ it 'deletes non-existing pvc' do
34
+ begin
35
+ @client.delete('not_there')
36
+ rescue ::Fog::Kubevirt::Errors::ClientError
37
+ # it ignores non-existing object
38
+ fail "pvc should not exist"
39
+ end
40
+ end
41
+
42
+ it 'fails with wrong size format' do
43
+ pvc = {
44
+ :name => 'test-pvc',
45
+ :namespace => 'default',
46
+ :storage_class => '',
47
+ :access_modes => ['ReadWriteOnce'],
48
+ :requests => { storage: "X" }
49
+ }
50
+ begin
51
+ @client.create(pvc)
52
+ fail "requested size is not correct"
53
+ rescue ::Fog::Kubevirt::Errors::ValidationError
54
+ # expected
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,22 @@
1
+ require 'minitest/autorun'
2
+ require 'fog/core'
3
+ require 'fog/kubevirt'
4
+
5
+ class KubevirtConnection
6
+
7
+ def initialize(options={})
8
+ @host = ENV.key?('KUBE_HOST') ? ENV['KUBE_HOST'] : options[:host]
9
+ @port = ENV.key?('KUBE_PORT') ? ENV['KUBE_PORT'] : options[:port]
10
+ @token = ENV.key?('KUBE_TOKEN') ? ENV['KUBE_TOKEN'] : options[:token]
11
+ end
12
+
13
+ def client
14
+ if !ENV.key?('KUBECONFIG')
15
+ return Fog::Kubevirt::Compute.new(:kubevirt_hostname => @host,
16
+ :kubevirt_port => @port,
17
+ :kubevirt_token => @token)
18
+ else
19
+ return Fog::Kubevirt::Compute.new(:kubevirt_token => nil)
20
+ end
21
+ end
22
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative './spec_helper'
2
2
  require_relative './shared_context'
3
3
 
4
4
  require 'fog/kubevirt/compute/compute'
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative './spec_helper'
2
2
  require_relative './shared_context'
3
3
 
4
4
  require 'fog/kubevirt'
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative './spec_helper'
2
2
  require_relative './shared_context'
3
3
 
4
4
  require 'fog/kubevirt/compute/compute'
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative './spec_helper'
2
2
  require_relative './shared_context'
3
3
 
4
4
  require 'fog/kubevirt'
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative './spec_helper'
2
2
  require_relative './shared_context'
3
3
 
4
4
  require 'fog/kubevirt/compute/compute'
@@ -0,0 +1,34 @@
1
+ require_relative './spec_helper'
2
+ require_relative './shared_context'
3
+
4
+ describe Fog::Compute do
5
+ before :all do
6
+ vcr = KubevirtVCR.new(
7
+ vcr_directory: 'spec/fixtures/kubevirt/server',
8
+ :service_class => Fog::Kubevirt::Compute
9
+ )
10
+ @service = vcr.service
11
+ end
12
+
13
+ it 'fetches, starts, stops and destroy server' do
14
+ VCR.use_cassette('server_ops') do
15
+ server = @service.servers.get('vm-cirros')
16
+ assert(server)
17
+
18
+ server.stop
19
+ server = @service.servers.get('vm-cirros')
20
+ assert(server)
21
+
22
+ server.start
23
+ # no validation - this operation takes too long
24
+
25
+ server.destroy
26
+ begin
27
+ server = @service.servers.get('vm-cirros')
28
+ fail "server should not exist"
29
+ rescue Fog::Kubevirt::Errors::ClientError
30
+ # expected
31
+ end
32
+ end
33
+ end
34
+ end
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative './spec_helper'
2
2
  require_relative './shared_context'
3
3
 
4
4
  require 'fog/kubevirt'
@@ -0,0 +1,126 @@
1
+ require_relative './spec_helper'
2
+
3
+ describe Fog::Kubevirt::Compute::Shared::UnitConverter do
4
+
5
+ described_class = Fog::Kubevirt::Compute::Shared::UnitConverter
6
+
7
+ describe '.convert' do
8
+ it 'converts correctly units that correspond to powers of 10' do
9
+ assert_equal(described_class.convert('1KB', :b).to_i, 10**3)
10
+ assert_equal(described_class.convert('1MB', :b).to_i, 10**6)
11
+ assert_equal(described_class.convert('1GB', :b).to_i, 10**9)
12
+ assert_equal(described_class.convert('1TB', :b).to_i, 10**12)
13
+ assert_equal(described_class.convert('1PB', :b).to_i, 10**15)
14
+ assert_equal(described_class.convert('1EB', :b).to_i, 10**18)
15
+ assert_equal(described_class.convert('1ZB', :b).to_i, 10**21)
16
+ assert_equal(described_class.convert('1YB', :b).to_i, 10**24)
17
+ end
18
+
19
+ it 'converts correctly units that correspond to powers of 2' do
20
+ assert_equal(described_class.convert('1KiB', :b).to_i, 2**10)
21
+ assert_equal(described_class.convert('1MiB', :b).to_i, 2**20)
22
+ assert_equal(described_class.convert('1GiB', :b).to_i, 2**30)
23
+ assert_equal(described_class.convert('1TiB', :b).to_i, 2**40)
24
+ assert_equal(described_class.convert('1PiB', :b).to_i, 2**50)
25
+ assert_equal(described_class.convert('1EiB', :b).to_i, 2**60)
26
+ assert_equal(described_class.convert('1ZiB', :b).to_i, 2**70)
27
+ assert_equal(described_class.convert('1YiB', :b).to_i, 2**80)
28
+ end
29
+
30
+ it 'converts correclty powers of 10 to powers of 2' do
31
+ assert_equal(described_class.convert('1000KB', :kib).to_i, 976)
32
+ assert_equal(described_class.convert('1000MB', :mib).to_i, 953)
33
+ assert_equal(described_class.convert('1000GB', :gib).to_i, 931)
34
+ assert_equal(described_class.convert('1000TB', :tib).to_i, 909)
35
+ assert_equal(described_class.convert('1000PB', :pib).to_i, 888)
36
+ assert_equal(described_class.convert('1000EB', :eib).to_i, 867)
37
+ assert_equal(described_class.convert('1000ZB', :zib).to_i, 847)
38
+ assert_equal(described_class.convert('1000YB', :yib).to_i, 827)
39
+ end
40
+
41
+ it 'converts correclty powers of 2 to powers of 10' do
42
+ assert_equal(described_class.convert('1000KiB', :kb).to_i, 1024)
43
+ assert_equal(described_class.convert('1000MiB', :mb).to_i, 1048)
44
+ assert_equal(described_class.convert('1000GiB', :gb).to_i, 1073)
45
+ assert_equal(described_class.convert('1000TiB', :tb).to_i, 1099)
46
+ assert_equal(described_class.convert('1000PiB', :pb).to_i, 1125)
47
+ assert_equal(described_class.convert('1000EiB', :eb).to_i, 1152)
48
+ assert_equal(described_class.convert('1000ZiB', :zb).to_i, 1180)
49
+ assert_equal(described_class.convert('1000YiB', :yb).to_i, 1208)
50
+ end
51
+
52
+ it 'converts to smaller powers of 10 correclty' do
53
+ assert_equal(described_class.convert('1KB', 'B').to_i, 10**3)
54
+ assert_equal(described_class.convert('1MB', 'KB').to_i, 10**3)
55
+ assert_equal(described_class.convert('1GB', 'MB').to_i, 10**3)
56
+ assert_equal(described_class.convert('1TB', 'GB').to_i, 10**3)
57
+ assert_equal(described_class.convert('1PB', 'TB').to_i, 10**3)
58
+ assert_equal(described_class.convert('1EB', 'PB').to_i, 10**3)
59
+ assert_equal(described_class.convert('1ZB', 'EB').to_i, 10**3)
60
+ assert_equal(described_class.convert('1YB', 'ZB').to_i, 10**3)
61
+ end
62
+
63
+ it 'converts to smaller powers of 2 correclty' do
64
+ assert_equal(described_class.convert('1KiB', 'B').to_i, 2**10)
65
+ assert_equal(described_class.convert('1MiB', 'KiB').to_i, 2**10)
66
+ assert_equal(described_class.convert('1GiB', 'MiB').to_i, 2**10)
67
+ assert_equal(described_class.convert('1TiB', 'GiB').to_i, 2**10)
68
+ assert_equal(described_class.convert('1PiB', 'TiB').to_i, 2**10)
69
+ assert_equal(described_class.convert('1EiB', 'PiB').to_i, 2**10)
70
+ assert_equal(described_class.convert('1ZiB', 'EiB').to_i, 2**10)
71
+ assert_equal(described_class.convert('1YiB', 'ZiB').to_i, 2**10)
72
+ end
73
+
74
+ it 'converts to larger powers of 10 correclty' do
75
+ assert_equal(described_class.convert('1000b', 'kb').to_i, 1)
76
+ assert_equal(described_class.convert('1000kb', 'mb').to_i, 1)
77
+ assert_equal(described_class.convert('1000mb', 'gb').to_i, 1)
78
+ assert_equal(described_class.convert('1000gb', 'tb').to_i, 1)
79
+ assert_equal(described_class.convert('1000tb', 'pb').to_i, 1)
80
+ assert_equal(described_class.convert('1000pb', 'eb').to_i, 1)
81
+ assert_equal(described_class.convert('1000eb', 'zb').to_i, 1)
82
+ assert_equal(described_class.convert('1000zb', 'yb').to_i, 1)
83
+ end
84
+
85
+ it 'converts to larger powers of 2 correclty' do
86
+ assert_equal(described_class.convert('1024b', 'ki').to_i, 1)
87
+ assert_equal(described_class.convert('1024kib', 'mi').to_i, 1)
88
+ assert_equal(described_class.convert('1024mib', 'gi').to_i, 1)
89
+ assert_equal(described_class.convert('1024gib', 'ti').to_i, 1)
90
+ assert_equal(described_class.convert('1024tib', 'pi').to_i, 1)
91
+ assert_equal(described_class.convert('1024pib', 'ei').to_i, 1)
92
+ assert_equal(described_class.convert('1024eib', 'zi').to_i, 1)
93
+ assert_equal(described_class.convert('1024zib', 'yi').to_i, 1)
94
+ end
95
+
96
+ it 'accepts spaces between the numeric value and the unit suffix' do
97
+ assert_equal(described_class.convert('2 KiB', :b).to_i, 2048)
98
+ end
99
+
100
+ it 'accepts spaces before the numeric value' do
101
+ assert_equal(described_class.convert(' 2KiB', :b).to_i, 2048)
102
+ end
103
+
104
+ it 'accepts spaces after the unit suffix' do
105
+ assert_equal(described_class.convert('2KiB ', :b).to_i, 2048)
106
+ end
107
+
108
+ it 'returns nil if no value is given' do
109
+ assert_nil(described_class.convert(nil, :b))
110
+ end
111
+ end
112
+
113
+ describe '.validate' do
114
+ it 'fails to validate' do
115
+ assert_raises ::Fog::Kubevirt::Errors::ValidationError do
116
+ described_class.validate('X')
117
+ end
118
+ end
119
+
120
+ it 'validates correctly' do
121
+ data = described_class.validate('2Gi')
122
+ assert_equal(data[:value], '2')
123
+ assert_equal(data[:suffix], 'Gi')
124
+ end
125
+ end
126
+ end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative './spec_helper'
2
2
 
3
3
  describe Fog::Kubevirt::Compute do
4
4
  it 'parses vm' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fog-kubevirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Kliczewski
@@ -14,36 +14,36 @@ authors:
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
- date: 2019-04-18 00:00:00.000000000 Z
17
+ date: 2019-04-24 00:00:00.000000000 Z
18
18
  dependencies:
19
19
  - !ruby/object:Gem::Dependency
20
20
  name: minitest
21
21
  requirement: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - ">="
23
+ - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0'
25
+ version: '5.11'
26
26
  type: :development
27
27
  prerelease: false
28
28
  version_requirements: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - ">="
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: '5.11'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rake
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: '12.3'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ">="
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '0'
46
+ version: '12.3'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -62,44 +62,44 @@ dependencies:
62
62
  name: rubocop
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '0.67'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '0.67'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: vcr
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - ">="
79
+ - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: '4.0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - ">="
86
+ - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '0'
88
+ version: '4.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: webmock
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - ">="
93
+ - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '0'
95
+ version: '3.5'
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - ">="
100
+ - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '0'
102
+ version: '3.5'
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: fog-core
105
105
  requirement: !ruby/object:Gem::Requirement
@@ -120,14 +120,14 @@ dependencies:
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: 4.1.2
123
+ version: 4.3.0
124
124
  type: :runtime
125
125
  prerelease: false
126
126
  version_requirements: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: 4.1.2
130
+ version: 4.3.0
131
131
  description: This library can be used as a module for `fog`.
132
132
  email:
133
133
  - piotr.kliczewski@gmail.com
@@ -210,24 +210,29 @@ files:
210
210
  - lib/fog/kubevirt/compute/requests/list_volumes.rb
211
211
  - lib/fog/kubevirt/compute/requests/update_vm.rb
212
212
  - lib/fog/kubevirt/version.rb
213
- - spec/compute_v1alpha2_spec.rb
214
- - spec/create_vm_spec.rb
215
213
  - spec/fixtures/kubevirt/networkattachmentdefinition/networkattachmentdefinitions_crud.yml
216
214
  - spec/fixtures/kubevirt/persistentvolume/persistent_volumes_crud.yml
217
215
  - spec/fixtures/kubevirt/pvc/pvcs_crud.yml
218
216
  - spec/fixtures/kubevirt/pvc/pvcs_no_selector_crud.yml
217
+ - spec/fixtures/kubevirt/server/server_ops.yml
219
218
  - spec/fixtures/kubevirt/service/services_crud.yml
220
219
  - spec/fixtures/kubevirt/storageclass/storageclasses_crud.yml
221
220
  - spec/fixtures/kubevirt/vm/vm_create_multi.yml
222
221
  - spec/fixtures/kubevirt/vm/vm_create_single.yml
223
- - spec/network_attachment_definition_v1alpha2_spec.rb
224
- - spec/persistent_volumes_v1alpha2_spec.rb
225
- - spec/pvcs_v1alpha2_spec.rb
226
- - spec/shared_context.rb
227
- - spec/spec_helper.rb
228
- - spec/storage_classes_v1_spec.rb
229
- - spec/vm_parse_spec.rb
230
- homepage: https://github.com/pkliczewski/fog-kubevirt
222
+ - spec/integration/pvcs_spec.rb
223
+ - spec/integration/shared_context.rb
224
+ - spec/unit/compute_v1alpha2_spec.rb
225
+ - spec/unit/create_vm_spec.rb
226
+ - spec/unit/network_attachment_definition_v1alpha2_spec.rb
227
+ - spec/unit/persistent_volumes_v1alpha2_spec.rb
228
+ - spec/unit/pvcs_v1alpha2_spec.rb
229
+ - spec/unit/server_v1alpha3_spec.rb
230
+ - spec/unit/shared_context.rb
231
+ - spec/unit/spec_helper.rb
232
+ - spec/unit/storage_classes_v1_spec.rb
233
+ - spec/unit/unit_converter_spec.rb
234
+ - spec/unit/vm_parse_spec.rb
235
+ homepage: https://github.com/fog/fog-kubevirt
231
236
  licenses:
232
237
  - Apache-2.0
233
238
  metadata: {}
@@ -252,20 +257,25 @@ signing_key:
252
257
  specification_version: 4
253
258
  summary: Module for the 'fog' gem to support Kubevirt.
254
259
  test_files:
255
- - spec/compute_v1alpha2_spec.rb
256
- - spec/create_vm_spec.rb
257
260
  - spec/fixtures/kubevirt/networkattachmentdefinition/networkattachmentdefinitions_crud.yml
258
261
  - spec/fixtures/kubevirt/persistentvolume/persistent_volumes_crud.yml
259
262
  - spec/fixtures/kubevirt/pvc/pvcs_crud.yml
260
263
  - spec/fixtures/kubevirt/pvc/pvcs_no_selector_crud.yml
264
+ - spec/fixtures/kubevirt/server/server_ops.yml
261
265
  - spec/fixtures/kubevirt/service/services_crud.yml
262
266
  - spec/fixtures/kubevirt/storageclass/storageclasses_crud.yml
263
267
  - spec/fixtures/kubevirt/vm/vm_create_multi.yml
264
268
  - spec/fixtures/kubevirt/vm/vm_create_single.yml
265
- - spec/network_attachment_definition_v1alpha2_spec.rb
266
- - spec/persistent_volumes_v1alpha2_spec.rb
267
- - spec/pvcs_v1alpha2_spec.rb
268
- - spec/shared_context.rb
269
- - spec/spec_helper.rb
270
- - spec/storage_classes_v1_spec.rb
271
- - spec/vm_parse_spec.rb
269
+ - spec/integration/pvcs_spec.rb
270
+ - spec/integration/shared_context.rb
271
+ - spec/unit/compute_v1alpha2_spec.rb
272
+ - spec/unit/create_vm_spec.rb
273
+ - spec/unit/network_attachment_definition_v1alpha2_spec.rb
274
+ - spec/unit/persistent_volumes_v1alpha2_spec.rb
275
+ - spec/unit/pvcs_v1alpha2_spec.rb
276
+ - spec/unit/server_v1alpha3_spec.rb
277
+ - spec/unit/shared_context.rb
278
+ - spec/unit/spec_helper.rb
279
+ - spec/unit/storage_classes_v1_spec.rb
280
+ - spec/unit/unit_converter_spec.rb
281
+ - spec/unit/vm_parse_spec.rb