From bfe139e9654b55d202feb05760e8152925dd8c42 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Thu, 8 Oct 2015 14:40:13 -0700 Subject: [PATCH] Try to use zuul-cloner to prepare fixtures 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: Ie3476db0bcc7f4ab08d64dd63e71958e8b3f5ab2 --- .fixtures.yml | 13 ---- .gitignore | 1 + Gemfile | 1 + Rakefile | 64 +++++++++++++++++++ spec/acceptance/nodesets/default.yml | 5 +- spec/acceptance/nodesets/nodepool-trusty.yml | 2 +- .../nodesets/ubuntu-server-1404-x64.yml | 4 +- 7 files changed, 71 insertions(+), 19 deletions(-) delete mode 100644 .fixtures.yml diff --git a/.fixtures.yml b/.fixtures.yml deleted file mode 100644 index 89c63a4..0000000 --- a/.fixtures.yml +++ /dev/null @@ -1,13 +0,0 @@ -fixtures: - repositories: - 'concat': - 'repo': 'git://github.com/puppetlabs/puppetlabs-concat.git' - 'ref': '1.2.2' - 'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile' - 'keystone': 'git://github.com/openstack/puppet-keystone.git' - 'mysql': 'git://github.com/puppetlabs/puppetlabs-mysql.git' - 'openstacklib': 'git://github.com/openstack/puppet-openstacklib.git' - 'postgresql': 'git://github.com/puppetlabs/puppetlabs-postgresql.git' - 'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git' - symlinks: - zaqar: "#{source_dir}" diff --git a/.gitignore b/.gitignore index 4dd84f0..15c55ef 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ coverage/ .idea/ *.swp *.iml +openstack/ diff --git a/Gemfile b/Gemfile index 6d4ce9a..fc22143 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ end group :system_tests do gem 'beaker-rspec', :require => 'false' gem 'beaker-puppet_install_helper', :require => 'false' + gem 'r10k', :require => 'false' end if facterversion = ENV['FACTER_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index bc08f43..3c3603e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,9 @@ 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] PuppetSyntax.exclude_paths ||= [] PuppetSyntax.exclude_paths << "spec/fixtures/**/*" @@ -19,3 +22,64 @@ desc "Run acceptance tests" RSpec::Core::RakeTask.new(:acceptance) do |t| t.pattern = 'spec/acceptance' end + +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} #{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 diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml index 3bb3e62..486b6a3 100644 --- a/spec/acceptance/nodesets/default.yml +++ b/spec/acceptance/nodesets/default.yml @@ -1,5 +1,5 @@ HOSTS: - ubuntu-server-1404-x64: + ubuntu-server-14.04-amd64: roles: - master platform: ubuntu-14.04-amd64 @@ -7,5 +7,4 @@ HOSTS: box_url: https://vagrantcloud.com/puppetlabs/ubuntu-14.04-64-nocm hypervisor: vagrant CONFIG: - log_level: debug - type: git + type: foss diff --git a/spec/acceptance/nodesets/nodepool-trusty.yml b/spec/acceptance/nodesets/nodepool-trusty.yml index 7f503ca..9fc624e 100644 --- a/spec/acceptance/nodesets/nodepool-trusty.yml +++ b/spec/acceptance/nodesets/nodepool-trusty.yml @@ -1,5 +1,5 @@ HOSTS: - ubuntu-1404-x64: + ubuntu-14.04-amd64: roles: - master platform: ubuntu-14.04-amd64 diff --git a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml index 3bb3e62..8001929 100644 --- a/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml +++ b/spec/acceptance/nodesets/ubuntu-server-1404-x64.yml @@ -1,5 +1,5 @@ HOSTS: - ubuntu-server-1404-x64: + ubuntu-server-14.04-amd64: roles: - master platform: ubuntu-14.04-amd64 @@ -8,4 +8,4 @@ HOSTS: hypervisor: vagrant CONFIG: log_level: debug - type: git + type: foss