/
proxmox_server_helper_test.rb
149 lines (127 loc) · 5.43 KB
/
proxmox_server_helper_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# frozen_string_literal: true
# Copyright 2018 Tristan Robert
# This file is part of ForemanFogProxmox.
# ForemanFogProxmox is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# ForemanFogProxmox is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with ForemanFogProxmox. If not, see <http://www.gnu.org/licenses/>.
require 'test_plugin_helper'
module ForemanFogProxmox
class ProxmoxServerHelperTest < ActiveSupport::TestCase
include ProxmoxServerHelper
describe 'parse' do
setup { Fog.mock! }
teardown { Fog.unmock! }
let(:host) do
{ 'vmid' => '100',
'name' => 'test',
'node' => 'pve',
'type' => 'qemu',
'config_attributes' => {
'memory' => '536870912',
'min_memory' => '',
'ballon' => '',
'shares' => '',
'cpu_type' => 'kvm64',
'spectre' => '1',
'pcid' => '0',
'cores' => '1',
'sockets' => '1'
},
'volumes_attributes' => {
'0'=> { 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' },
'1'=> { 'controller' => 'virtio', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824', 'cache' => 'none' }
},
'interfaces_attributes' => {
'0' => { 'id' => 'net0', 'model' => 'virtio', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0', 'rate' => nil },
'1' => { 'id' => 'net1', 'model' => 'e1000', 'bridge' => 'vmbr0', 'firewall' => '0', 'link_down' => '0' }
}
}
end
let(:host_delete) do
{ 'vmid' => '100',
'name' => 'test',
'type' => 'qemu',
'cdrom' => 'image',
'cdrom_iso' => 'local-lvm:iso/debian-netinst.iso',
'volumes_attributes' => { '0' => { '_delete' => '1', 'controller' => 'scsi', 'device' => '0', 'storage' => 'local-lvm', 'size' => '1073741824' }},
'interfaces_attributes' => { '0' => { '_delete' => '1', 'id' => 'net0', 'model' => 'virtio' } }
}
end
test '#memory' do
memory = parse_server_memory(host['config_attributes'])
assert memory.has_key?(:memory)
assert_equal 536870912, memory[:memory]
end
test '#cpu' do
cpu = parse_server_cpu(host['config_attributes'])
assert cpu.has_key?(:cpu)
assert_equal 'cputype=kvm64,flags=+spec-ctrl', cpu[:cpu]
end
test '#vm' do
vm = parse_server_vm(host)
assert_equal '1', vm['cores']
assert_equal '1', vm['sockets']
assert_equal 'cputype=kvm64,flags=+spec-ctrl', vm[:cpu]
assert_equal 536870912, vm[:memory]
assert_equal 'local-lvm:1073741824,cache=none', vm[:scsi0]
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', vm[:net0]
assert !vm.has_key?(:config)
assert !vm.has_key?(:node)
end
test '#volume with scsi 1Gb' do
volumes = parse_server_volumes(host['volumes_attributes'])
assert !volumes.empty?
assert volumes.size, 2
assert volume = volumes.first
assert volume.has_key?(:scsi0)
assert_equal 'local-lvm:1073741824,cache=none', volume[:scsi0]
end
test '#volume with virtio 1Gb' do
volumes = parse_server_volumes(host['volumes_attributes'])
assert !volumes.empty?
assert volumes.size, 2
assert volume = volumes[1]
assert volume.has_key?(:virtio0)
assert_equal 'local-lvm:1073741824,cache=none', volume[:virtio0]
end
test '#volume delete scsi0' do
volumes = parse_server_volumes(host_delete['volumes_attributes'])
assert !volumes.empty?
assert_equal volumes.length, 1
assert volume = volumes.first
assert volume.has_key?(:delete)
assert_match(/(net0,){0,1}scsi0(,net0){0,1}/, volume[:delete])
end
test '#interface with model virtio and bridge' do
interface = parse_server_interface(host['interfaces_attributes']['0'])
assert interface.has_key?(:net0)
assert_equal 'model=virtio,bridge=vmbr0,firewall=0,link_down=0', interface[:net0]
end
test '#interface with model e1000 and bridge' do
interface = parse_server_interface(host['interfaces_attributes']['1'])
assert interface.has_key?(:net1)
assert_equal 'model=e1000,bridge=vmbr0,firewall=0,link_down=0', interface[:net1]
end
test '#interface delete net0' do
interface = parse_server_interface(host_delete['interfaces_attributes']['0'])
assert interface.has_key?(:delete)
assert_match(/(scsi0,){0,1}net0(,scsi0){0,1}/, interface[:delete])
assert_equal interface.length, 1
end
test '#interfaces' do
interfaces = parse_server_interfaces(host['interfaces_attributes'])
assert !interfaces.empty?
assert_equal interfaces.length, 2
assert interfaces.include?({ net0: 'model=virtio,bridge=vmbr0,firewall=0,link_down=0'})
assert interfaces.include?({ net1: 'model=e1000,bridge=vmbr0,firewall=0,link_down=0'})
end
end
end
end