Browse Source

Autorequire correct package based on the distro

Some distros (RHEL based) have a single glance package. On those
distros the ensure_package/autorequire stuff doesn't quite work
correctly as per the type code it is assumed two packages 'glance-api'
and 'glance-registry'

This commit makes sure that on RHEL based distros type only autorequire
'openstack-glance' while on other distros it correctly autorequire
'glance-api' and 'glance-registry'

Change-Id: I17c84b2282beadaec80f4db42fa5696b7967159f
Closes-bug: #1493442
Co-Authored-By: Yanis Guenane <yguenane@redhat.com>
tags/7.0.0
Dan Prince 4 years ago
parent
commit
bce0eac01c

+ 8
- 2
lib/puppet/type/glance_api_config.rb View File

@@ -46,8 +46,14 @@ Puppet::Type.newtype(:glance_api_config) do
46 46
     defaultto('<SERVICE DEFAULT>')
47 47
   end
48 48
 
49
-  autorequire(:package) do
50
-    'glance-api'
49
+  if Facter['osfamily'].value == 'Debian'
50
+    autorequire(:package) do
51
+      'glance-api'
52
+    end
53
+  elsif Facter['osfamily'].value == 'RedHat'
54
+    autorequire(:package) do
55
+      'openstack-glance'
56
+    end
51 57
   end
52 58
 
53 59
 end

+ 8
- 2
lib/puppet/type/glance_api_paste_ini.rb View File

@@ -45,8 +45,14 @@ Puppet::Type.newtype(:glance_api_paste_ini) do
45 45
     defaultto('<SERVICE DEFAULT>')
46 46
   end
47 47
 
48
-  autorequire(:package) do
49
-    'glance-api'
48
+  if Facter['osfamily'].value == 'Debian'
49
+    autorequire(:package) do
50
+      'glance-api'
51
+    end
52
+  elsif Facter['osfamily'].value == 'RedHat'
53
+    autorequire(:package) do
54
+      'openstack-glance'
55
+    end
50 56
   end
51 57
 
52 58
 end

+ 8
- 2
lib/puppet/type/glance_cache_config.rb View File

@@ -46,8 +46,14 @@ Puppet::Type.newtype(:glance_cache_config) do
46 46
     defaultto('<SERVICE DEFAULT>')
47 47
   end
48 48
 
49
-  autorequire(:package) do
50
-    'glance-api'
49
+  if Facter['osfamily'].value == 'Debian'
50
+    autorequire(:package) do
51
+      'glance-api'
52
+    end
53
+  elsif Facter['osfamily'].value == 'RedHat'
54
+    autorequire(:package) do
55
+      'openstack-glance'
56
+    end
51 57
   end
52 58
 
53 59
 end

+ 8
- 2
lib/puppet/type/glance_registry_config.rb View File

@@ -46,8 +46,14 @@ Puppet::Type.newtype(:glance_registry_config) do
46 46
     defaultto('<SERVICE DEFAULT>')
47 47
   end
48 48
 
49
-  autorequire(:package) do
50
-    'glance-registry'
49
+  if Facter['osfamily'].value == 'Debian'
50
+    autorequire(:package) do
51
+      'glance-registry'
52
+    end
53
+  elsif Facter['osfamily'].value == 'RedHat'
54
+    autorequire(:package) do
55
+      'openstack-glance'
56
+    end
51 57
   end
52 58
 
53 59
 end

+ 8
- 2
lib/puppet/type/glance_registry_paste_ini.rb View File

@@ -45,8 +45,14 @@ Puppet::Type.newtype(:glance_registry_paste_ini) do
45 45
     defaultto('<SERVICE DEFAULT>')
46 46
   end
47 47
 
48
-  autorequire(:package) do
49
-    'glance-registry'
48
+  if Facter['osfamily'].value == 'Debian'
49
+    autorequire(:package) do
50
+      'glance-registry'
51
+    end
52
+  elsif Facter['osfamily'].value == 'RedHat'
53
+    autorequire(:package) do
54
+      'openstack-glance'
55
+    end
50 56
   end
51 57
 
52 58
 end

+ 2
- 2
manifests/init.pp View File

@@ -23,9 +23,9 @@ class glance(
23 23
   }
24 24
 
25 25
   if ( $glance::params::api_package_name == $glance::params::registry_package_name ) {
26
-    package { $glance::params::api_package_name :
26
+    package { $::glance::params::api_package_name :
27 27
       ensure => $package_ensure,
28
-      name   => $::glance::params::package_name,
28
+      name   => $::glance::params::api_package_name,
29 29
       tag    => ['openstack', 'glance-package'],
30 30
     }
31 31
   }

+ 30
- 8
spec/unit/type/glance_api_config_spec.rb View File

@@ -3,17 +3,39 @@ require 'puppet/type/glance_api_config'
3 3
 
4 4
 describe 'Puppet::Type.type(:glance_api_config)' do
5 5
   before :each do
6
+    Puppet::Type.rmtype(:glance_api_config)
7
+    Facter.fact(:osfamily).stubs(:value).returns(platform_params[:osfamily])
6 8
     @glance_api_config = Puppet::Type.type(:glance_api_config).new(:name => 'DEFAULT/foo', :value => 'bar')
7 9
   end
8 10
 
9
-  it 'should autorequire the package that install the file' do
10
-    catalog = Puppet::Resource::Catalog.new
11
-    package = Puppet::Type.type(:package).new(:name => 'glance-api')
12
-    catalog.add_resource package, @glance_api_config
13
-    dependency = @glance_api_config.autorequire
14
-    expect(dependency.size).to eq(1)
15
-    expect(dependency[0].target).to eq(@glance_api_config)
16
-    expect(dependency[0].source).to eq(package)
11
+  shared_examples_for 'glance_api_config' do
12
+    it 'should autorequire the package that install the file' do
13
+      catalog = Puppet::Resource::Catalog.new
14
+      package = Puppet::Type.type(:package).new(:name => platform_params[:package_name])
15
+      catalog.add_resource package, @glance_api_config
16
+      dependency = @glance_api_config.autorequire
17
+      expect(dependency.size).to eq(1)
18
+      expect(dependency[0].target).to eq(@glance_api_config)
19
+      expect(dependency[0].source).to eq(package)
20
+    end
21
+  end
22
+
23
+  context 'on Debian platforms' do
24
+    let :platform_params do
25
+      { :package_name => 'glance-api',
26
+        :osfamily     => 'Debian' }
27
+    end
28
+
29
+    it_behaves_like 'glance_api_config'
30
+  end
31
+
32
+  context 'on RedHat platforms' do
33
+    let :platform_params do
34
+      { :package_name => 'openstack-glance',
35
+        :osfamily     => 'RedHat'}
36
+    end
37
+
38
+    it_behaves_like 'glance_api_config'
17 39
   end
18 40
 
19 41
 end

+ 30
- 8
spec/unit/type/glance_cache_config_spec.rb View File

@@ -3,17 +3,39 @@ require 'puppet/type/glance_cache_config'
3 3
 
4 4
 describe 'Puppet::Type.type(:glance_cache_config)' do
5 5
   before :each do
6
+    Puppet::Type.rmtype(:glance_cache_config)
7
+    Facter.fact(:osfamily).stubs(:value).returns(platform_params[:osfamily])
6 8
     @glance_cache_config = Puppet::Type.type(:glance_cache_config).new(:name => 'DEFAULT/foo', :value => 'bar')
7 9
   end
8 10
 
9
-  it 'should autorequire the package that install the file' do
10
-    catalog = Puppet::Resource::Catalog.new
11
-    package = Puppet::Type.type(:package).new(:name => 'glance-api')
12
-    catalog.add_resource package, @glance_cache_config
13
-    dependency = @glance_cache_config.autorequire
14
-    expect(dependency.size).to eq(1)
15
-    expect(dependency[0].target).to eq(@glance_cache_config)
16
-    expect(dependency[0].source).to eq(package)
11
+  shared_examples_for 'glance_cache_config' do
12
+    it 'should autorequire the package that install the file' do
13
+      catalog = Puppet::Resource::Catalog.new
14
+      package = Puppet::Type.type(:package).new(:name => platform_params[:package_name])
15
+      catalog.add_resource package, @glance_cache_config
16
+      dependency = @glance_cache_config.autorequire
17
+      expect(dependency.size).to eq(1)
18
+      expect(dependency[0].target).to eq(@glance_cache_config)
19
+      expect(dependency[0].source).to eq(package)
20
+    end
21
+  end
22
+
23
+  context 'on Debian platforms' do
24
+    let :platform_params do
25
+      { :package_name => 'glance-api',
26
+        :osfamily     => 'Debian' }
27
+    end
28
+
29
+    it_behaves_like 'glance_cache_config'
30
+  end
31
+
32
+  context 'on RedHat platforms' do
33
+    let :platform_params do
34
+      { :package_name => 'openstack-glance',
35
+        :osfamily     => 'RedHat'}
36
+    end
37
+
38
+    it_behaves_like 'glance_cache_config'
17 39
   end
18 40
 
19 41
 end

+ 30
- 8
spec/unit/type/glance_registry_config_spec.rb View File

@@ -3,17 +3,39 @@ require 'puppet/type/glance_registry_config'
3 3
 
4 4
 describe 'Puppet::Type.type(:glance_registry_config)' do
5 5
   before :each do
6
+    Puppet::Type.rmtype(:glance_registry_config)
7
+    Facter.fact(:osfamily).stubs(:value).returns(platform_params[:osfamily])
6 8
     @glance_registry_config = Puppet::Type.type(:glance_registry_config).new(:name => 'DEFAULT/foo', :value => 'bar')
7 9
   end
8 10
 
9
-  it 'should autorequire the package that install the file' do
10
-    catalog = Puppet::Resource::Catalog.new
11
-    package = Puppet::Type.type(:package).new(:name => 'glance-registry')
12
-    catalog.add_resource package, @glance_registry_config
13
-    dependency = @glance_registry_config.autorequire
14
-    expect(dependency.size).to eq(1)
15
-    expect(dependency[0].target).to eq(@glance_registry_config)
16
-    expect(dependency[0].source).to eq(package)
11
+  shared_examples_for 'glance_registry_config' do
12
+    it 'should autorequire the package that install the file' do
13
+      catalog = Puppet::Resource::Catalog.new
14
+      package = Puppet::Type.type(:package).new(:name => platform_params[:package_name])
15
+      catalog.add_resource package, @glance_registry_config
16
+      dependency = @glance_registry_config.autorequire
17
+      expect(dependency.size).to eq(1)
18
+      expect(dependency[0].target).to eq(@glance_registry_config)
19
+      expect(dependency[0].source).to eq(package)
20
+    end
21
+  end
22
+
23
+  context 'on Debian platforms' do
24
+    let :platform_params do
25
+      { :package_name => 'glance-registry',
26
+        :osfamily     => 'Debian' }
27
+    end
28
+
29
+    it_behaves_like 'glance_registry_config'
30
+  end
31
+
32
+  context 'on RedHat platforms' do
33
+    let :platform_params do
34
+      { :package_name => 'openstack-glance',
35
+        :osfamily     => 'RedHat'}
36
+    end
37
+
38
+    it_behaves_like 'glance_registry_config'
17 39
   end
18 40
 
19 41
 end

Loading…
Cancel
Save