Skip to content

Commit a3b660f

Browse files
authored
Merge pull request #67 from baby-gnu/feature/support-centos-8
Feature/support centos 8
2 parents 3947d6c + 54c82bb commit a3b660f

File tree

4 files changed

+126
-73
lines changed

4 files changed

+126
-73
lines changed

libvirt/osfingermap.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ Ubuntu-14.04:
3030
Ubuntu-16.04:
3131
libvirt_pkg: libvirt-bin
3232
libvirt_service: libvirt-bin
33+
34+
## os: CentOS
35+
CentOS Linux-7:
36+
python2_pkg: libvirt-python
37+
python3_pkg: ~

libvirt/osmap.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ Fedora:
1515
python3_pkg: python3-libvirt
1616

1717
CentOS:
18-
python3_pkg: ~
18+
python2_pkg: ~
19+
python3_pkg: python3-libvirt

test/integration/share/libraries/libvirt.rb

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class LibvirtResource < Inspec.resource(1)
1616
attr_reader :packages
1717

1818
def initialize
19-
@packages = build_packages
19+
@packages = inspec.libvirt_packages.packages
2020
end
2121

2222
def daemon_config_dir
@@ -34,75 +34,4 @@ def daemon_config_dir
3434
def daemon_config_file
3535
inspec.file(File.join(daemon_config_dir, 'libvirtd'))
3636
end
37-
38-
def build_packages
39-
# defaults.yaml
40-
packages = build_default_packages
41-
42-
packages.merge!(build_overwrite_packages)
43-
end
44-
45-
def build_overwrite_packages
46-
# osfamily.yaml / osmap.yaml
47-
case inspec.os[:family]
48-
when 'debian'
49-
build_debian_packages
50-
51-
when 'fedora'
52-
build_fedora_packages
53-
54-
when 'suse'
55-
build_suse_packages
56-
57-
else
58-
{}
59-
end
60-
end
61-
62-
def build_default_packages
63-
{
64-
'libvirt' => ['libvirt'],
65-
'qemu' => ['qemu-kvm'],
66-
'extra' => ['libguestfs'],
67-
'python' => if inspec.salt_minion.python3?
68-
['libvirt-python3']
69-
else
70-
['libvirt-python']
71-
end
72-
}
73-
end
74-
75-
def build_debian_packages
76-
{
77-
'libvirt' => ['libvirt-daemon-system'],
78-
'extra' => %w[libguestfs0 libguestfs-tools gnutls-bin virt-top],
79-
'python' => if inspec.salt_minion.python3?
80-
['python3-libvirt']
81-
else
82-
['python-libvirt']
83-
end
84-
}
85-
end
86-
87-
def build_fedora_packages
88-
{
89-
'python' => if inspec.salt_minion.python3?
90-
['python3-libvirt']
91-
else
92-
['python2-libvirt']
93-
end
94-
}
95-
end
96-
97-
def build_suse_packages
98-
{
99-
'libvirt' => ['libvirt-daemon-qemu'],
100-
'extra' => ['libguestfs0'],
101-
'python' => if inspec.salt_minion.python3?
102-
['python3-libvirt-python']
103-
else
104-
['python2-libvirt-python']
105-
end
106-
}
107-
end
10837
end
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# frozen_string_literal: true
2+
3+
# libvirt.rb -- Libvirt InSpec resources
4+
# Author: Daniel Dehennin <[email protected]>
5+
# Copyright (C) 2019 Pole de Competences Logiciels Libres <[email protected]>
6+
7+
class LibvirtPackagesResource < Inspec.resource(1)
8+
name 'libvirt_packages'
9+
10+
supports platform_name: 'debian'
11+
supports platform_name: 'ubuntu'
12+
supports platform_name: 'centos'
13+
supports platform_name: 'fedora'
14+
supports platform_name: 'opensuse'
15+
16+
attr_reader :packages
17+
18+
def initialize
19+
@packages = build_packages
20+
end
21+
22+
def build_packages
23+
# defaults.yaml
24+
packages = build_default_packages
25+
26+
packages.merge!(build_os_family_packages)
27+
packages.merge!(build_os_name_packages)
28+
end
29+
30+
def build_os_family_packages
31+
# osfamily.yaml / osmap.yaml
32+
case inspec.os[:family]
33+
when 'debian'
34+
build_debian_packages
35+
36+
when 'fedora'
37+
build_fedora_packages
38+
39+
when 'suse'
40+
build_suse_packages
41+
42+
else
43+
{}
44+
end
45+
end
46+
47+
def build_os_name_packages
48+
# osfamily.yaml / osmap.yaml
49+
case inspec.os[:name]
50+
when 'centos'
51+
build_centos_packages
52+
53+
else
54+
{}
55+
end
56+
end
57+
58+
def build_default_packages
59+
{
60+
'libvirt' => ['libvirt'],
61+
'qemu' => ['qemu-kvm'],
62+
'extra' => ['libguestfs'],
63+
'python' => if inspec.salt_minion.python3?
64+
['libvirt-python3']
65+
else
66+
['libvirt-python']
67+
end
68+
}
69+
end
70+
71+
def build_debian_packages
72+
{
73+
'libvirt' => ['libvirt-daemon-system'],
74+
'extra' => %w[libguestfs0 libguestfs-tools gnutls-bin virt-top],
75+
'python' => if inspec.salt_minion.python3?
76+
['python3-libvirt']
77+
else
78+
['python-libvirt']
79+
end
80+
}
81+
end
82+
83+
def build_fedora_packages
84+
{
85+
'python' => if inspec.salt_minion.python3?
86+
['python3-libvirt']
87+
else
88+
['python2-libvirt']
89+
end
90+
}
91+
end
92+
93+
def build_suse_packages
94+
{
95+
'libvirt' => ['libvirt-daemon-qemu'],
96+
'extra' => ['libguestfs0'],
97+
'python' => if inspec.salt_minion.python3?
98+
['python3-libvirt-python']
99+
else
100+
['python2-libvirt-python']
101+
end
102+
}
103+
end
104+
105+
def build_centos_packages
106+
case inspec.os[:release]
107+
when /^7/
108+
if inspec.salt_minion.python3?
109+
{ 'python' => [] }
110+
else
111+
{ 'python' => ['libvirt-python'] }
112+
end
113+
else
114+
# Only python3 since CentOS 8
115+
{ 'python' => ['python3-libvirt'] }
116+
end
117+
end
118+
end

0 commit comments

Comments
 (0)