foreman_kubevirt 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/foreman_kubevirt/kubevirt.rb +23 -8
- data/app/views/compute_resources_vms/index/_kubevirt.html.erb +1 -1
- data/app/views/compute_resources_vms/show/_kubevirt.html.erb +1 -2
- data/lib/foreman_kubevirt/engine.rb +1 -0
- data/lib/foreman_kubevirt/version.rb +1 -1
- data/test/models/compute_resources/kubevirt_test.rb +14 -0
- data/test/unit/foreman_kubevirt_test.rb +54 -6
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e0ae0ca0c55da65290264cdf02df32185314908
|
4
|
+
data.tar.gz: 12230c05d0f34969260ad7f3efaefb0486e094b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: baf978d956388d8fccd84cb3e48c110b6a874542736ef6987a27c45732f9e807573ab6f87088b5a32fb46fa304c16e0a0f694965664314d8380a940dd720e4c5
|
7
|
+
data.tar.gz: 46c7b84303561d9a5cc2db9f72d5896775604df20263ce590f3d29f415230903e75b6ab06211478f121c717522fbea7535d9ab984bc41e82c02e57f9ff5260a9
|
@@ -28,6 +28,10 @@ module ForemanKubevirt
|
|
28
28
|
%i[build image new_volume]
|
29
29
|
end
|
30
30
|
|
31
|
+
def user_data_supported?
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
31
35
|
def provided_attributes
|
32
36
|
{ :uuid => :name, :mac => :mac }
|
33
37
|
end
|
@@ -136,18 +140,17 @@ module ForemanKubevirt
|
|
136
140
|
logger.debug("creating VM with the following options: #{options.inspect}")
|
137
141
|
|
138
142
|
volumes = create_volumes_for_vm(options)
|
139
|
-
|
140
|
-
# FIXME: Add cloud-init support
|
141
|
-
# init = { 'userData' => "#!/bin/bash\necho \"fedora\" | passwd fedora --stdin"}
|
142
|
-
|
143
143
|
interfaces, networks = create_network_devices_for_vm(options, volumes)
|
144
|
+
# Add clound init user data
|
145
|
+
user_data = { "userData" => options[:user_data] } if options[:user_data].present?
|
144
146
|
|
145
147
|
begin
|
146
148
|
client.vms.create(:vm_name => options[:name],
|
147
149
|
:cpus => options[:cpu_cores].to_i,
|
148
|
-
:memory_size => options[:memory]
|
150
|
+
:memory_size => convert_memory(options[:memory] + "b", :mi).to_s,
|
151
|
+
:memory_unit => "Mi",
|
149
152
|
:volumes => volumes,
|
150
|
-
|
153
|
+
:cloudinit => user_data,
|
151
154
|
:networks => networks,
|
152
155
|
:interfaces => interfaces)
|
153
156
|
client.servers.get(options[:name])
|
@@ -177,7 +180,7 @@ module ForemanKubevirt
|
|
177
180
|
# return 'false'
|
178
181
|
def vm_instance_defaults
|
179
182
|
{
|
180
|
-
:memory => 1024.megabytes,
|
183
|
+
:memory => 1024.megabytes.to_s,
|
181
184
|
:cpu_cores => '1'
|
182
185
|
}
|
183
186
|
end
|
@@ -260,6 +263,14 @@ module ForemanKubevirt
|
|
260
263
|
64.gigabytes
|
261
264
|
end
|
262
265
|
|
266
|
+
# Converts a given memory to bytes
|
267
|
+
#
|
268
|
+
# @param memory - The memory of the VM to convert
|
269
|
+
#
|
270
|
+
def convert_memory_to_bytes(memory)
|
271
|
+
convert_memory(memory, :b)
|
272
|
+
end
|
273
|
+
|
263
274
|
protected
|
264
275
|
|
265
276
|
def client
|
@@ -304,7 +315,7 @@ module ForemanKubevirt
|
|
304
315
|
|
305
316
|
def verify_booting_from_image_is_possible(volumes)
|
306
317
|
raise ::Foreman::Exception.new N_('It is not possible to set a bootable volume and image based provisioning.') if
|
307
|
-
volumes
|
318
|
+
volumes&.any? { |_, v| v[:bootable] == "true" }
|
308
319
|
end
|
309
320
|
|
310
321
|
def add_volume_for_image_provision(options)
|
@@ -428,5 +439,9 @@ module ForemanKubevirt
|
|
428
439
|
|
429
440
|
[interfaces, networks]
|
430
441
|
end
|
442
|
+
|
443
|
+
def convert_memory(memory, unit)
|
444
|
+
::Fog::Kubevirt::Utils::UnitConverter.convert(memory, unit).to_i
|
445
|
+
end
|
431
446
|
end
|
432
447
|
end
|
@@ -12,7 +12,7 @@
|
|
12
12
|
<tr>
|
13
13
|
<td><%= link_to_if_authorized vm.name, hash_for_compute_resource_vm_path(:compute_resource_id => @compute_resource, :id => vm.identity).merge(:auth_object => @compute_resource, :auth_action => 'view', :authorizer => authorizer) %></td>
|
14
14
|
<td><%= vm.cpu_cores %></td>
|
15
|
-
<td><%= vm.memory %></td>
|
15
|
+
<td><%= number_to_human_size @compute_resource.convert_memory_to_bytes(vm.memory) %></td>
|
16
16
|
<td>
|
17
17
|
<span <%= vm_power_class(vm.ready?) %>>
|
18
18
|
<%= vm_state(vm) %></span>
|
@@ -44,6 +44,7 @@ module ForemanKubevirt
|
|
44
44
|
config.to_prepare do
|
45
45
|
begin
|
46
46
|
require "fog/kubevirt"
|
47
|
+
require "fog/kubevirt/compute/utils/unit_converter"
|
47
48
|
require "fog/kubevirt/compute/models/server"
|
48
49
|
require File.expand_path("../../app/models/concerns/fog_extensions/kubevirt/server", __dir__)
|
49
50
|
|
@@ -66,4 +66,18 @@ class ForemanKubevirtTest < ActiveSupport::TestCase
|
|
66
66
|
record.stubs(:client).returns(client)
|
67
67
|
assert_equal false, record.test_connection
|
68
68
|
end
|
69
|
+
|
70
|
+
test "Verify client raises StandardError exception" do
|
71
|
+
record = new_kubevirt_vcr
|
72
|
+
record.stubs(:client).raises(StandardError.new('test'))
|
73
|
+
record.test_connection
|
74
|
+
assert_equal ['test'], record.errors[:base]
|
75
|
+
end
|
76
|
+
|
77
|
+
test "Verify client raises FingerprintException exception" do
|
78
|
+
record = new_kubevirt_vcr
|
79
|
+
record.stubs(:client).raises(Foreman::FingerprintException.new('test'))
|
80
|
+
record.test_connection
|
81
|
+
assert_includes record.errors[:base][0], "[Foreman::FingerprintException]: test"
|
82
|
+
end
|
69
83
|
end
|
@@ -73,35 +73,49 @@ class ForemanKubevirtTest < ActiveSupport::TestCase
|
|
73
73
|
assert_equal 1, server.interfaces.count
|
74
74
|
end
|
75
75
|
|
76
|
+
test "create_vm image based without additional volumes should pass" do
|
77
|
+
vm_args = IMAGE_BASED_VM_ARGS.deep_dup
|
78
|
+
vm_args.delete("volumes_attributes")
|
79
|
+
|
80
|
+
Fog.mock!
|
81
|
+
compute_resource = new_kubevirt_vcr
|
82
|
+
server = compute_resource.create_vm(vm_args)
|
83
|
+
|
84
|
+
assert_equal "olive-kempter.example.com", server.name
|
85
|
+
end
|
86
|
+
|
76
87
|
test "should fail when creating a VM with_bootable flag and image based" do
|
77
88
|
vm_args = IMAGE_BASED_VM_ARGS.deep_dup
|
78
89
|
vm_args["volumes_attributes"]["0"]["bootable"] = "true"
|
79
90
|
Fog.mock!
|
80
91
|
compute_resource = new_kubevirt_vcr
|
81
|
-
assert_raise(Foreman::Exception) do
|
92
|
+
exception = assert_raise(Foreman::Exception) do
|
82
93
|
compute_resource.create_vm(vm_args)
|
83
94
|
end
|
95
|
+
assert_match(/It is not possible to set a bootable volume and image based provisioning./, exception.message)
|
84
96
|
end
|
85
97
|
|
86
98
|
test "should fail when creating a VM without an image or pvc" do
|
87
99
|
vm_args = IMAGE_BASED_VM_ARGS.deep_dup
|
100
|
+
vm_args["volumes_attributes"] = {}
|
88
101
|
vm_args["image_id"] = nil
|
89
102
|
Fog.mock!
|
90
103
|
compute_resource = new_kubevirt_vcr
|
91
|
-
assert_raise(Foreman::Exception) do
|
104
|
+
exception = assert_raise(Foreman::Exception) do
|
92
105
|
compute_resource.create_vm(vm_args)
|
93
106
|
end
|
107
|
+
assert_match(/VM should be created based on Persistent Volume Claim or Image/, exception.message)
|
94
108
|
end
|
95
109
|
|
96
110
|
test "should fail when creating image-based VM without an image" do
|
97
111
|
vm_args = IMAGE_BASED_VM_ARGS.deep_dup
|
98
|
-
vm_args["volumes_attributes"] = {}
|
99
112
|
vm_args["image_id"] = nil
|
100
113
|
Fog.mock!
|
101
114
|
compute_resource = new_kubevirt_vcr
|
102
|
-
assert_raise(Foreman::Exception) do
|
115
|
+
exception = assert_raise(Foreman::Exception) do
|
103
116
|
compute_resource.create_vm(vm_args)
|
104
117
|
end
|
118
|
+
assert_match(/VM should be created based on an image/, exception.message)
|
105
119
|
end
|
106
120
|
|
107
121
|
test "should fail when creating a VM with PVC and not providing a capacity" do
|
@@ -109,9 +123,10 @@ class ForemanKubevirtTest < ActiveSupport::TestCase
|
|
109
123
|
vm_args["volumes_attributes"]["0"]["capacity"] = nil
|
110
124
|
Fog.mock!
|
111
125
|
compute_resource = new_kubevirt_vcr
|
112
|
-
assert_raise(Foreman::Exception) do
|
126
|
+
exception = assert_raise(Foreman::Exception) do
|
113
127
|
compute_resource.create_vm(vm_args)
|
114
128
|
end
|
129
|
+
assert_match(/Capacity was not found/, exception.message)
|
115
130
|
end
|
116
131
|
|
117
132
|
test "should fail when creating a VM with two bootable PVCs" do
|
@@ -120,8 +135,41 @@ class ForemanKubevirtTest < ActiveSupport::TestCase
|
|
120
135
|
vm_args["volumes_attributes"]["1"]["bootable"] = "true"
|
121
136
|
Fog.mock!
|
122
137
|
compute_resource = new_kubevirt_vcr
|
123
|
-
assert_raise(Foreman::Exception) do
|
138
|
+
exception = assert_raise(Foreman::Exception) do
|
124
139
|
compute_resource.create_vm(vm_args)
|
125
140
|
end
|
141
|
+
assert_match(/Only one volume can be bootable/, exception.message)
|
142
|
+
end
|
143
|
+
|
144
|
+
test "create_vm without CPU should pass" do
|
145
|
+
vm_args = NETWORK_BASED_VM_ARGS.deep_dup
|
146
|
+
vm_args.delete("cpu_cores")
|
147
|
+
Fog.mock!
|
148
|
+
compute_resource = new_kubevirt_vcr
|
149
|
+
server = compute_resource.create_vm(vm_args)
|
150
|
+
|
151
|
+
# verify default CPU value is set
|
152
|
+
assert_equal 1, server.cpu_cores
|
153
|
+
end
|
154
|
+
|
155
|
+
test "create_vm without memory should pass" do
|
156
|
+
vm_args = NETWORK_BASED_VM_ARGS.deep_dup
|
157
|
+
vm_args.delete("memory")
|
158
|
+
Fog.mock!
|
159
|
+
compute_resource = new_kubevirt_vcr
|
160
|
+
server = compute_resource.create_vm(vm_args)
|
161
|
+
|
162
|
+
# verify default memory value is set
|
163
|
+
assert_equal "1024M", server.memory
|
164
|
+
end
|
165
|
+
|
166
|
+
test "converts memory to byte" do
|
167
|
+
Fog.mock!
|
168
|
+
compute_resource = new_kubevirt_vcr
|
169
|
+
assert_equal 1.gigabytes, compute_resource.convert_memory_to_bytes("1Gi")
|
170
|
+
assert_equal 1.megabytes, compute_resource.convert_memory_to_bytes("1Mi")
|
171
|
+
assert_equal 1_000_000_000, compute_resource.convert_memory_to_bytes("1G")
|
172
|
+
assert_equal 1_000_000, compute_resource.convert_memory_to_bytes("1M")
|
173
|
+
assert_equal 0, compute_resource.convert_memory_to_bytes("0b")
|
126
174
|
end
|
127
175
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_kubevirt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Moti Asayag
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '1.
|
47
|
+
version: '1.3'
|
48
48
|
type: :runtime
|
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: '1.
|
54
|
+
version: '1.3'
|
55
55
|
description: Provision and manage Kubevirt Virtual Machines from Foreman.
|
56
56
|
email:
|
57
57
|
- masayag@redhat.com
|