Browse Source

Prepare for puppet checks in OpenStack infra

Add Gemfile, Rakefile
Adjust .gitignore
Switch to corosync upstream module v0.8.0
Add fuel pacemaker module with disabled rspecs
Fix pre_build_hook
Fix rspecs to match rspec 3.3.0 and new puppets

Change-Id: I731a3fe16babab2db8c3ef1cb088490ef3388c32
Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
master
Bogdan Dobrelya 3 years ago
parent
commit
8c22c0e862

+ 11
- 0
.gitignore View File

@@ -1,5 +1,16 @@
1
+# Plugin
1 2
 deployment_scripts/puppet/modules/corosync
3
+deployment_scripts/puppet/modules/pacemaker
2 4
 deployment_scripts/puppet/modules/stdlib
3 5
 .build
4 6
 tmp
5 7
 *.fp
8
+
9
+# Editors
10
+*.swp
11
+*~
12
+
13
+# Bundle
14
+Gemfile.lock
15
+.bundled_gems
16
+.bundle

+ 33
- 0
Gemfile View File

@@ -0,0 +1,33 @@
1
+source 'https://rubygems.org'
2
+
3
+group :development, :test do
4
+  gem 'puppetlabs_spec_helper',               :require => 'false'
5
+  gem 'rspec', '~>3.3',                       :require => 'false'
6
+  gem 'rspec-puppet', '~> 2.2.0',             :require => 'false'
7
+  gem 'metadata-json-lint',                   :require => 'false'
8
+  gem 'puppet-lint-param-docs',               :require => 'false'
9
+  gem 'puppet-lint-absolute_classname-check', :require => 'false'
10
+  gem 'puppet-lint-absolute_template_path',   :require => 'false'
11
+  gem 'puppet-lint-unquoted_string-check',    :require => 'false'
12
+  gem 'puppet-lint-leading_zero-check',       :require => 'false'
13
+  gem 'puppet-lint-variable_contains_upcase', :require => 'false'
14
+  gem 'puppet-lint-numericvariable',          :require => 'false'
15
+  gem 'puppet_facts',                         :require => 'false'
16
+  gem 'json',                                 :require => 'false'
17
+  gem 'pry',                                  :require => 'false'
18
+  gem 'simplecov',                            :require => 'false'
19
+  gem 'webmock',                              :require => 'false'
20
+  gem 'fakefs',                               :require => 'false'
21
+  gem 'fog-google', '0.1.0',                  :require => 'false' # 0.1.1+ requires ruby 2.0
22
+  gem 'beaker-rspec',                         :require => 'false'
23
+  gem 'beaker-puppet_install_helper',         :require => 'false'
24
+  gem 'puppet-blacksmith',                    :require => 'false'
25
+
26
+end
27
+
28
+if puppetversion = ENV['PUPPET_GEM_VERSION']
29
+  gem 'puppet', puppetversion, :require => false
30
+else
31
+  # TODO(bogdando): remove this version when 4 is supported
32
+  gem 'puppet', '~> 3.8', :require => false
33
+end

+ 183
- 0
Rakefile View File

@@ -0,0 +1,183 @@
1
+###############################################################################
2
+# Licensed under the Apache License, Version 2.0 (the "License");
3
+# you may not use this file except in compliance with the License.
4
+# You may obtain a copy of the License at
5
+#
6
+# http://www.apache.org/licenses/LICENSE-2.0
7
+#
8
+# Unless required by applicable law or agreed to in writing, software
9
+# distributed under the License is distributed on an "AS IS" BASIS,
10
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+# See the License for the specific language governing permissions and
12
+# limitations under the License.
13
+###############################################################################
14
+#
15
+# Rakefile
16
+#   This file implements the lint and spec tasks for rake so that it will check
17
+#   the plugin's puppet modules in the deployment_scripts/puppet/modules
18
+#   folder by running the respective lint or test tasks for each module.
19
+#   It will then return 0 if there are issues or return 1 if any of the modules
20
+#   fail.
21
+#
22
+# Acknowledgements
23
+#   The Rakefile is based on the work of Alex Schultz <aschultz@mirantis.com>,
24
+#   https://raw.githubusercontent.com/openstack/fuel-library/master/Rakefile
25
+#
26
+require 'puppetlabs_spec_helper/rake_tasks'
27
+require 'puppet-lint/tasks/puppet-lint'
28
+require 'puppet-syntax/tasks/puppet-syntax'
29
+require 'rake'
30
+
31
+MODULES_PATH="./deployment_scripts/puppet/modules"
32
+PuppetSyntax.exclude_paths ||= []
33
+PuppetSyntax.exclude_paths << "spec/fixtures/**/*"
34
+PuppetSyntax.exclude_paths << "pkg/**/*"
35
+PuppetSyntax.exclude_paths << "vendor/**/*"
36
+
37
+# Main task list
38
+task :spec => ["spec:gemfile"]
39
+task :lint => ["lint:manual"]
40
+
41
+namespace :common do
42
+  desc 'Task to generate a list of puppet modules'
43
+  task :modulelist, [:skip_file] do |t,args|
44
+    args.with_defaults(:skip_file => nil)
45
+
46
+    cdir = Dir.pwd
47
+    skip_module_list = []
48
+    $module_directories = []
49
+    # NOTE(bogdando): some dependent modules may have no good tests an we need
50
+    # this file to exclude those
51
+    if not args[:skip_file].nil? and File.exists?(args[:skip_file])
52
+      File.open(args[:skip_file], 'r').each_line { |line|
53
+        skip_module_list << line.chomp
54
+      }
55
+    end
56
+
57
+    Dir.glob("#{MODULES_PATH}/*") do |mod|
58
+      next unless File.directory?(mod)
59
+      if skip_module_list.include?(File.basename(mod))
60
+        $stderr.puts "Skipping tests... modules.disable_rspec includes #{mod}"
61
+        next
62
+      end
63
+      $module_directories << mod
64
+    end
65
+  end
66
+end
67
+
68
+# The spec task to loop through the modules and run the tests
69
+namespace :spec do
70
+  desc 'Run spec tasks via module bundler with Gemfile'
71
+  task :gemfile do |t|
72
+    Rake::Task["common:modulelist"].invoke('./modules.disable_rspec')
73
+    cdir = Dir.pwd
74
+    status = true
75
+
76
+    ENV['GEM_HOME']="#{cdir}/.bundled_gems"
77
+    system("gem install bundler --no-rdoc --no-ri --verbose")
78
+    system("./pre_build_hook")
79
+
80
+    $module_directories.each do |mod|
81
+      next unless File.exists?("#{mod}/Gemfile")
82
+      $stderr.puts '-'*80
83
+      $stderr.puts "Running tests for #{mod}"
84
+      $stderr.puts '-'*80
85
+      Dir.chdir(mod)
86
+      begin
87
+        system("bundle install")
88
+        result = system("bundle exec rake spec")
89
+        if !result
90
+          status = false
91
+          $stderr.puts "!"*80
92
+          $stderr.puts "Unit tests failed for #{mod}"
93
+          $stderr.puts "!"*80
94
+        end
95
+        rescue Exception => e
96
+          $stderr.puts "ERROR: Unable to run tests for #{mod}, #{e.message}"
97
+          status = false
98
+        end
99
+        Dir.chdir(cdir)
100
+    end
101
+    fail unless status
102
+  end
103
+end
104
+
105
+# The lint tasks
106
+namespace :lint do
107
+  desc 'Find all the puppet files and run puppet-lint on them'
108
+  task :manual do |t|
109
+    Rake::Task["common:modulelist"].invoke('./modules.disable_rspec rake-lint')
110
+    # lint checks to skip if no Gemfile or Rakefile
111
+    skip_checks = [ "--no-80chars-check",
112
+        "--no-autoloader_layout-check",
113
+        "--no-nested_classes_or_defines-check",
114
+        "--no-only_variable_string-check",
115
+        "--no-2sp_soft_tabs-check",
116
+        "--no-trailing_whitespace-check",
117
+        "--no-hard_tabs-check",
118
+        "--no-class_inherits_from_params_class-check",
119
+        "--with-filename"]
120
+    cdir = Dir.pwd
121
+    status = true
122
+
123
+    ENV['GEM_HOME']="#{cdir}/.bundled_gems"
124
+    system("gem install bundler --no-rdoc --no-ri --verbose")
125
+
126
+    $module_directories.each do |mod|
127
+      $stderr.puts '-'*80
128
+      $stderr.puts "Running lint for #{mod}"
129
+      $stderr.puts '-'*80
130
+      Dir.chdir(mod)
131
+      begin
132
+        result = true
133
+        Dir.glob("**/**.pp") do |puppet_file|
134
+          result = false unless system("puppet-lint #{skip_checks.join(" ")} #{puppet_file}")
135
+        end
136
+        if !result
137
+          status = false
138
+          $stderr.puts "!"*80
139
+          $stderr.puts "puppet-lint failed for #{mod}"
140
+          $stderr.puts "!"*80
141
+        end
142
+      rescue Exception => e
143
+          $stderr.puts "ERROR: Unable to run lint for #{mod}, #{e.message}"
144
+          status = false
145
+      end
146
+     Dir.chdir(cdir)
147
+    end
148
+    fail unless status
149
+  end
150
+
151
+  desc 'Run lint tasks from modules with an existing Gemfile/Rakefile'
152
+  task :rakefile do |t|
153
+    Rake::Task["common:modulelist"].invoke('./modules.disable_rspec rake-lint')
154
+    cdir = Dir.pwd
155
+    status = true
156
+
157
+    ENV['GEM_HOME']="#{cdir}/.bundled_gems"
158
+    system("gem install bundler --no-rdoc --no-ri --verbose")
159
+
160
+    $module_directories.each do |mod|
161
+      next unless File.exists?("#{mod}/Rakefile")
162
+      $stderr.puts '-'*80
163
+      $stderr.puts "Running lint for #{mod}"
164
+      $stderr.puts '-'*80
165
+      Dir.chdir(mod)
166
+      begin
167
+        result = system("bundle exec rake lint > /dev/null")
168
+        $stderr.puts result
169
+        if !result
170
+          status = false
171
+          $stderr.puts "!"*80
172
+          $stderr.puts "rake lint failed for #{mod}"
173
+          $stderr.puts "!"*80
174
+        end
175
+      rescue Exception => e
176
+        $stderr.puts "ERROR: Unable to run lint for #{mod}, #{e.message}"
177
+        status = false
178
+      end
179
+      Dir.chdir(cdir)
180
+    end
181
+    fail unless status
182
+  end
183
+end

+ 3
- 1
deployment_scripts/puppet/modules/pcs_fencing/.fixtures.yml View File

@@ -1,9 +1,11 @@
1 1
 fixtures:
2 2
   repositories:
3 3
     #corosync: 'https://github.com/puppetlabs/puppetlabs-corosync.git'
4
+    #pacemaker: 'https://github.com/puppet-community/puppet-corosync'
4 5
     #stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
5
-      
6
+
6 7
   symlinks:
7 8
     pcs_fencing: "#{source_dir}"
8 9
     corosync: "#{source_dir}/../corosync"
10
+    pacemaker: "#{source_dir}/../pacemaker"
9 11
     stdlib: "#{source_dir}/../stdlib"

+ 4
- 3
deployment_scripts/puppet/modules/pcs_fencing/Gemfile View File

@@ -1,10 +1,11 @@
1 1
 source 'https://rubygems.org'
2 2
 
3 3
 group :development, :test do
4
+  gem 'rspec-puppet',           :require => false
4 5
   gem 'puppetlabs_spec_helper', :require => false
5
-  gem 'puppet-lint', '~> 0.3.2'
6
-  gem 'rake', '10.1.1'
7
-  gem 'rspec', '< 2.99'
6
+  gem 'puppet-lint', '~> 1.1.0'
7
+  gem 'rake', '~> 10.1.0',      :require => false
8
+  gem 'rspec', '~> 3.3.0',       :require => false
8 9
   gem 'json'
9 10
   gem 'webmock'
10 11
 end

+ 0
- 56
deployment_scripts/puppet/modules/pcs_fencing/Gemfile.lock View File

@@ -1,56 +0,0 @@
1
-GEM
2
-  remote: https://rubygems.org/
3
-  specs:
4
-    addressable (2.3.6)
5
-    crack (0.4.2)
6
-      safe_yaml (~> 1.0.0)
7
-    diff-lcs (1.2.5)
8
-    facter (2.3.0)
9
-    hiera (1.3.4)
10
-      json_pure
11
-    json (1.8.1)
12
-    json_pure (1.8.1)
13
-    metaclass (0.0.4)
14
-    mocha (1.1.0)
15
-      metaclass (~> 0.0.1)
16
-    puppet (3.7.3)
17
-      facter (> 1.6, < 3)
18
-      hiera (~> 1.0)
19
-      json_pure
20
-    puppet-lint (0.3.2)
21
-    puppet-syntax (1.3.0)
22
-      rake
23
-    puppetlabs_spec_helper (0.8.2)
24
-      mocha
25
-      puppet-lint
26
-      puppet-syntax
27
-      rake
28
-      rspec
29
-      rspec-puppet
30
-    rake (10.1.1)
31
-    rspec (2.14.1)
32
-      rspec-core (~> 2.14.0)
33
-      rspec-expectations (~> 2.14.0)
34
-      rspec-mocks (~> 2.14.0)
35
-    rspec-core (2.14.8)
36
-    rspec-expectations (2.14.5)
37
-      diff-lcs (>= 1.1.3, < 2.0)
38
-    rspec-mocks (2.14.6)
39
-    rspec-puppet (1.0.1)
40
-      rspec
41
-    safe_yaml (1.0.4)
42
-    webmock (1.20.4)
43
-      addressable (>= 2.3.6)
44
-      crack (>= 0.3.2)
45
-
46
-PLATFORMS
47
-  ruby
48
-
49
-DEPENDENCIES
50
-  json
51
-  puppet
52
-  puppet-lint (~> 0.3.2)
53
-  puppetlabs_spec_helper
54
-  rake (= 10.1.1)
55
-  rspec (< 2.99)
56
-  webmock

+ 1
- 1
deployment_scripts/puppet/modules/pcs_fencing/lib/puppet/type/cs_fencetopo.rb View File

@@ -39,7 +39,7 @@ module Puppet
39 39
     end
40 40
 
41 41
     autorequire(:service) do
42
-      [ 'corosync' ]
42
+      [ 'corosync', 'pacemaker' ]
43 43
     end
44 44
 
45 45
     autorequire(:cs_shadow) do

+ 4
- 4
deployment_scripts/puppet/modules/pcs_fencing/manifests/fencing.pp View File

@@ -52,13 +52,13 @@ define pcs_fencing::fencing (
52 52
     metadata            => $meta,
53 53
   }
54 54
 
55
-  cs_location {"location__prohibit__${res_name}":
55
+  cs_rsc_location {"location__prohibit__${res_name}":
56 56
     node_name  => $::pacemaker_hostname,
57 57
     node_score => '-INFINITY',
58 58
     primitive  => $res_name,
59 59
   }
60 60
 
61
-  cs_location {"location__allow__${res_name}":
61
+  cs_rsc_location {"location__allow__${res_name}":
62 62
     primitive  => $res_name,
63 63
     rules     => [
64 64
       {
@@ -74,7 +74,7 @@ define pcs_fencing::fencing (
74 74
       },
75 75
     ],
76 76
   }
77
-  
77
+
78 78
   Cs_resource[$res_name] ->
79
-  Cs_location<||>
79
+  Cs_rsc_location<||>
80 80
 }

+ 6
- 1
deployment_scripts/puppet/modules/pcs_fencing/spec/classes/fencing_primitives_spec.rb View File

@@ -22,11 +22,16 @@ describe 'pcs_fencing::fencing_primitives' do
22 22
           'fqdn' => 'node-1.foo.bar',
23 23
           'name' => 'node-1',
24 24
           'role' => 'primary-controller'
25
+        },
26
+        {
27
+          'fqdn' => 'node-2.foo.bar',
28
+          'name' => 'node-2',
29
+          'role' => 'controller'
25 30
         }
26 31
       ]
27 32
     }
28 33
   end
29
-  let(:names) { [ 'node-1.foo.bar' ] }
34
+  let(:names) { [ 'node-1.foo.bar', 'node-2.foo.bar' ] }
30 35
   let(:facts) {{ :osfamily => 'RedHat' }}
31 36
 
32 37
   context 'then configuring fencing' do

+ 8
- 10
deployment_scripts/puppet/modules/pcs_fencing/spec/defines/fencing_spec.rb View File

@@ -35,14 +35,12 @@ describe 'pcs_fencing::fencing', :type => :define do
35 35
     {
36 36
       :primitive => res_name,
37 37
       :rules => [
38
-        {
39
-          'score'   => '100',
40
-          'boolean' => '',
41
-          'expressions' => [
42
-            {'attribute'=>"#uname",'operation'=>'ne','value'=>node}
43
-          ]
44
-        }
45
-      ]
38
+        ["score", "100"],
39
+        ["boolean", ""],
40
+        ["expressions", [
41
+          {"attribute"=>"#uname",
42
+           "operation"=>"ne",
43
+           "value"=>"node-1"}]]] 
46 44
     }
47 45
   end
48 46
   let(:facts) {{ :osfamily => 'Debian' }}
@@ -67,7 +65,7 @@ describe 'pcs_fencing::fencing', :type => :define do
67 65
       )
68 66
     end
69 67
     it 'should create a prohibit location' do
70
-      should contain_cs_location("location__prohibit__#{res_name}").with(
68
+      should contain_cs_rsc_location("location__prohibit__#{res_name}").with(
71 69
         {
72 70
           'node_name' => location_prohibit_params[:node_name],
73 71
           'node_score' => location_prohibit_params[:score],
@@ -76,7 +74,7 @@ describe 'pcs_fencing::fencing', :type => :define do
76 74
       )
77 75
     end
78 76
     it 'should create an allow location' do
79
-      should contain_cs_location("location__allow__#{res_name}").with(
77
+      should contain_cs_rsc_location("location__allow__#{res_name}").with(
80 78
         {
81 79
           'primitive' => location_allow_params[:primitive],
82 80
           'rules' => location_allow_params[:rules]

+ 5
- 1
deployment_scripts/puppet/modules/pcs_fencing/spec/spec_helper.rb View File

@@ -1 +1,5 @@
1
-require 'puppetlabs_spec_helper/module_spec_helper'
1
+require 'puppetlabs_spec_helper/module_spec_helper'
2
+
3
+RSpec.configure do |config|
4
+  config.expect_with(:rspec) { |c| c.syntax = :should }
5
+end

+ 2
- 2
deployment_scripts/puppet/modules/pcs_fencing/spec/unit/puppet/provider/cs_fencetopo/crm_spec.rb View File

@@ -135,7 +135,7 @@ describe Puppet::Type.type(:cs_fencetopo).provider(:crm) do
135 135
       out=File.open(File.dirname(__FILE__) + '/../../../../fixtures/cib/cib.xml')
136 136
       provider.class.stubs(:dump_cib).returns(out,nil)
137 137
       provider.class.stubs(:exec_withenv).with(' --query --scope fencing-topology', {}).returns(0)
138
-      provider.exists?.should be_true
138
+      provider.exists?.should be_truthy
139 139
     end
140 140
 
141 141
     it 'checks if topology singleton does not exist' do
@@ -143,7 +143,7 @@ describe Puppet::Type.type(:cs_fencetopo).provider(:crm) do
143 143
       out=File.open(File.dirname(__FILE__) + '/../../../../fixtures/cib/cib_no_topo.xml')
144 144
       provider.class.stubs(:dump_cib).returns(out,nil)
145 145
       provider.class.stubs(:exec_withenv).with(' --query --scope fencing-topology', {}).returns(6)
146
-      provider.exists?.should be_false
146
+      provider.exists?.should be_falsey
147 147
     end
148 148
   end
149 149
 end

+ 2
- 2
deployment_scripts/puppet/modules/pcs_fencing/spec/unit/puppet/type/cs_fencetopo_spec.rb View File

@@ -71,7 +71,7 @@ describe Puppet::Type.type(:cs_fencetopo) do
71 71
 
72 72
     [:cib, :name ].each do |param|
73 73
       it "should have a #{param} parameter" do
74
-        subject.validparameter?(param).should be_true
74
+        subject.validparameter?(param).should be_truthy
75 75
       end
76 76
 
77 77
       it "should have documentation for its #{param} parameter" do
@@ -81,7 +81,7 @@ describe Puppet::Type.type(:cs_fencetopo) do
81 81
 
82 82
     [ :nodes, :fence_topology ].each do |prop|
83 83
       it "should have a #{prop} property" do
84
-        subject.validproperty?(prop).should be_true
84
+        subject.validproperty?(prop).should be_truthy
85 85
       end
86 86
 
87 87
       it "should have documentation for its #{prop} property" do

+ 1
- 0
modules.disable_rspec View File

@@ -0,0 +1 @@
1
+pacemaker

+ 15
- 8
pre_build_hook View File

@@ -4,23 +4,30 @@ set -eux
4 4
 
5 5
 ROOT="$(dirname `readlink -f $0`)"
6 6
 MODULES="${ROOT}"/deployment_scripts/puppet/modules/
7
-TMP_DIR="${ROOT}"/tmp
7
+TMP_DIR="${ROOT}"/tmp/
8 8
 mkdir -p "${MODULES}"
9 9
 mkdir -p "${TMP_DIR}"
10 10
 #Puppetlabs/stdlib 4.5.0
11 11
 REPO_PATH='https://github.com/puppetlabs/puppetlabs-stdlib/tarball/80f09623b63cf6946b5913b629911e2c49b5d1dd'
12 12
 
13 13
 wget -qO- "${REPO_PATH}" | \
14
-    tar -C "${MODULES}" -zxvf - \
14
+    tar -C "${TMP_DIR}" -zxvf - \
15 15
     puppetlabs-puppetlabs-stdlib-80f0962 && \
16
-    mv "${MODULES}puppetlabs-puppetlabs-stdlib-80f0962" "${MODULES}stdlib"
16
+    cp -Rf "${TMP_DIR}puppetlabs-puppetlabs-stdlib-80f0962" "${MODULES}stdlib"
17 17
 
18
-#Fuel 5.1.1 puppet-corosync
19
-REPO_PATH='https://github.com/openstack/fuel-library/tarball/a3043477337b4a0a8fd166dc83d6cd5d504f5da8'
20
-MODULES="${ROOT}"/deployment_scripts/puppet/modules/
18
+#Puppet-community/puppet-corosync 0.8.0
19
+REPO_PATH='https://github.com/puppet-community/puppet-corosync/tarball/88e267b00add700aeb0f4dae301bd327a8b18b54'
21 20
 
22 21
 wget -qO- "${REPO_PATH}" | \
23
-    tar -C "${MODULES}" --strip-components=3 -zxvf - \
24
-    openstack-fuel-library-a304347/deployment/puppet/corosync
22
+    tar -C "${TMP_DIR}" -zxvf - \
23
+    puppet-community-puppet-corosync-88e267b && \
24
+    cp -Rf "${TMP_DIR}puppet-community-puppet-corosync-88e267b" "${MODULES}corosync"
25
+
26
+#Fuel 7.0 pacemaker
27
+REPO_PATH='https://github.com/openstack/fuel-library/tarball/5d50055aeca1dd0dc53b43825dc4c8f7780be9dd'
25 28
 
29
+wget -qO- "${REPO_PATH}" | \
30
+    tar -C "${TMP_DIR}" --strip-components=3 -zxvf - \
31
+    openstack-fuel-library-5d50055 && \
32
+    cp -Rf "${TMP_DIR}pacemaker" "${MODULES}pacemaker"
26 33
 

Loading…
Cancel
Save