]> review.fuel-infra Code Review - puppet-modules/puppet-ceilometer.git/commitdiff
Try to use zuul-cloner to prepare fixtures
authorEmilien Macchi <emilien@redhat.com>
Thu, 8 Oct 2015 21:37:08 +0000 (14:37 -0700)
committerDenis Egorenko <degorenko@mirantis.com>
Tue, 27 Oct 2015 05:11:01 +0000 (08:11 +0300)
In OpenStack Infra, we would like to run Puppet unit tests that
sometimes depends on other Puppet OpenStack modules.
Example: a patch in puppet-openstacklib that needs to be tested in puppet-nova.

This patch modifies the Rakefile to:
* clean spec_prep and spec_clean Rake tasks
* use openstack/puppet-openstack-integration/install_modules_unit.sh script
  to clone modules.
* do not use .fixtures.yaml file to clone modules and rely on
  zuul-cloner or git.
* Add openstack/ in gitignore so we never commit the
  puppet-openstack-integration repository (can happen when spec_clean
  did not run but you want to submit the patch anyway)
* Allow to run a custom Puppetfile if PUPPETFILE env is exported. It
  will allow people to test the module with the dependencies they like,
  feature we had with .fixtures.yaml.

Also add 'r10k' to Gemfile.

That way, we will be able to use zuul dependencies and run tests accross
modules like we do with functional testing.

Change-Id: I8b884ef477bbc031da6bd3955ed308679e0380f6

.fixtures.yml [deleted file]
.gitignore
Gemfile
Rakefile

diff --git a/.fixtures.yml b/.fixtures.yml
deleted file mode 100644 (file)
index 5e57356..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-fixtures:
-  repositories:
-    'apache': 'git://github.com/puppetlabs/puppetlabs-apache.git'
-    'concat':
-      'repo': 'git://github.com/puppetlabs/puppetlabs-concat.git'
-      'ref': '1.2.1'
-    'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile'
-    'keystone': 'git://github.com/stackforge/puppet-keystone.git'
-    'mysql': 'git://github.com/puppetlabs/puppetlabs-mysql.git'
-    'nova': 'git://github.com/stackforge/puppet-nova.git'
-    'openstacklib': 'git://github.com/stackforge/puppet-openstacklib.git'
-    'postgresql': 'git://github.com/puppetlabs/puppet-postgresql.git'
-    'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
-  symlinks:
-    'ceilometer': "#{source_dir}"
index d4a93a066099f618ad9db187bbe1a9754dc91c1b..0378b653ae07cbbc63e1a717dc50f65e608b401a 100644 (file)
@@ -2,3 +2,4 @@
 spec/fixtures/modules/*
 pkg
 Gemfile.lock
+openstack/
diff --git a/Gemfile b/Gemfile
index 9ea21133312f5d50a3c2277e549303c37035bc13..eed3fb11c742ce4366db8f3e53fed810431f2a3d 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -22,6 +22,10 @@ group :development, :test do
   gem 'webmock'
 end
 
+group :system_tests do
+  gem 'r10k',                         :require => 'false'
+end
+
 if puppetversion = ENV['PUPPET_GEM_VERSION']
   gem 'puppet', puppetversion, :require => false
 else
index bb3e2bbf2cecef36677291c7ac81802fac9fdd92..0b00e732f68946f9c9fc8bbbb84381658b339cc8 100644 (file)
--- a/Rakefile
+++ b/Rakefile
@@ -1,6 +1,8 @@
 require 'puppetlabs_spec_helper/rake_tasks'
 require 'puppet-lint/tasks/puppet-lint'
-require 'puppet-syntax/tasks/puppet-syntax'
+require 'json'
+
+modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1]
 
 PuppetLint.configuration.fail_on_warnings = true
 PuppetLint.configuration.send('disable_80chars')
@@ -10,3 +12,64 @@ PuppetLint.configuration.send('disable_only_variable_string')
 exclude_tests_paths = ['pkg/**/*','vendor/**/*']
 PuppetLint.configuration.ignore_paths = exclude_tests_paths
 PuppetSyntax.exclude_paths = exclude_tests_paths
+
+Rake::Task[:spec_prep].clear
+desc 'Create the fixtures directory'
+task :spec_prep do
+  # Allow to test the module with custom dependencies
+  # like you could do with .fixtures file
+  if ENV['PUPPETFILE']
+    puppetfile = ENV['PUPPETFILE']
+    if ENV['GEM_HOME']
+      gem_home    = ENV['GEM_HOME']
+      gem_bin_dir = "#{gem_home}" + '/bin/'
+    else
+      gem_bin_dir = ''
+    end
+    r10k = ['env']
+    r10k += ["PUPPETFILE=#{puppetfile}"]
+    r10k += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"]
+    r10k += ["#{gem_bin_dir}r10k"]
+    r10k += ['puppetfile', 'install', '-v']
+    sh(*r10k)
+  else
+  # otherwise, use official OpenStack Puppetfile
+    zuul_ref = ENV['ZUUL_REF']
+    zuul_branch = ENV['ZUUL_BRANCH']
+    zuul_url = ENV['ZUUL_URL']
+    repo = 'openstack/puppet-openstack-integration'
+    rm_rf(repo)
+    if File.exists?('/usr/zuul-env/bin/zuul-cloner')
+      zuul_clone_cmd = ['/usr/zuul-env/bin/zuul-cloner']
+      zuul_clone_cmd += ['--cache-dir', '/opt/git']
+      zuul_clone_cmd += ['--zuul-ref', "#{zuul_ref}"]
+      zuul_clone_cmd += ['--zuul-branch', "#{zuul_branch}"]
+      zuul_clone_cmd += ['--zuul-url', "#{zuul_url}"]
+      zuul_clone_cmd += ['git://git.openstack.org', "#{repo}"]
+      sh(*zuul_clone_cmd)
+    else
+      sh("git clone https://git.openstack.org/#{repo} -b stable/kilo #{repo}")
+    end
+    script = ['env']
+    script += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"]
+    script += ["ZUUL_REF=#{zuul_ref}"]
+    script += ["ZUUL_BRANCH=#{zuul_branch}"]
+    script += ["ZUUL_URL=#{zuul_url}"]
+    script += ['bash', "#{repo}/install_modules_unit.sh"]
+    sh(*script)
+  end
+  rm_rf("spec/fixtures/modules/#{modname}")
+  ln_s(Dir.pwd, "spec/fixtures/modules/#{modname}")
+  mkdir_p('spec/fixtures/manifests')
+  touch('spec/fixtures/manifests/site.pp')
+end
+
+Rake::Task[:spec_clean].clear
+desc 'Clean up the fixtures directory'
+task :spec_clean do
+  rm_rf('spec/fixtures/modules')
+  rm_rf('openstack')
+  if File.zero?('spec/fixtures/manifests/site.pp')
+    rm_f('spec/fixtures/manifests/site.pp')
+  end
+end