Browse Source

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: If983dae0260ea2a1df49b4bdb0ada3c5223012c9
Emilien Macchi 3 years ago
parent
commit
6e52509101
4 changed files with 66 additions and 14 deletions
  1. 0
    14
      .fixtures.yml
  2. 1
    0
      .gitignore
  3. 1
    0
      Gemfile
  4. 64
    0
      Rakefile

+ 0
- 14
.fixtures.yml View File

@@ -1,14 +0,0 @@
1
-fixtures:
2
-  repositories:
3
-    'inifile': 'git://github.com/puppetlabs/puppetlabs-inifile'
4
-    'concat':
5
-      'repo': 'git://github.com/puppetlabs/puppetlabs-concat.git'
6
-      'ref': '1.2.1'
7
-    'keystone': 'git://github.com/openstack/puppet-keystone.git'
8
-    'mysql': 'git://github.com/puppetlabs/puppetlabs-mysql.git'
9
-    'nova': 'git://github.com/openstack/puppet-nova.git'
10
-    'openstacklib': 'git://github.com/openstack/puppet-openstacklib.git'
11
-    'postgresql': 'git://github.com/puppetlabs/puppet-postgresql.git'
12
-    'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib.git'
13
-  symlinks:
14
-    "heat": "#{source_dir}"

+ 1
- 0
.gitignore View File

@@ -8,3 +8,4 @@ coverage/
8 8
 .idea/
9 9
 *.swp
10 10
 *.iml
11
+openstack/

+ 1
- 0
Gemfile View File

@@ -19,6 +19,7 @@ end
19 19
 group :system_tests do
20 20
   gem 'beaker-rspec',                 :require => 'false'
21 21
   gem 'beaker-puppet_install_helper', :require => 'false'
22
+  gem 'r10k',                         :require => 'false'
22 23
 end
23 24
 
24 25
 if facterversion = ENV['FACTER_GEM_VERSION']

+ 64
- 0
Rakefile View File

@@ -1,6 +1,9 @@
1 1
 require 'puppetlabs_spec_helper/rake_tasks'
2 2
 require 'puppet-lint/tasks/puppet-lint'
3 3
 require 'puppet-syntax/tasks/puppet-syntax'
4
+require 'json'
5
+
6
+modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1]
4 7
 
5 8
 PuppetSyntax.exclude_paths ||= []
6 9
 PuppetSyntax.exclude_paths << "spec/fixtures/**/*"
@@ -19,3 +22,64 @@ desc "Run acceptance tests"
19 22
 RSpec::Core::RakeTask.new(:acceptance) do |t|
20 23
   t.pattern = 'spec/acceptance'
21 24
 end
25
+
26
+Rake::Task[:spec_prep].clear
27
+desc 'Create the fixtures directory'
28
+task :spec_prep do
29
+  # Allow to test the module with custom dependencies
30
+  # like you could do with .fixtures file
31
+  if ENV['PUPPETFILE']
32
+    puppetfile = ENV['PUPPETFILE']
33
+    if ENV['GEM_HOME']
34
+      gem_home    = ENV['GEM_HOME']
35
+      gem_bin_dir = "#{gem_home}" + '/bin/'
36
+    else
37
+      gem_bin_dir = ''
38
+    end
39
+    r10k = ['env']
40
+    r10k += ["PUPPETFILE=#{puppetfile}"]
41
+    r10k += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"]
42
+    r10k += ["#{gem_bin_dir}r10k"]
43
+    r10k += ['puppetfile', 'install', '-v']
44
+    sh(*r10k)
45
+  else
46
+  # otherwise, use official OpenStack Puppetfile
47
+    zuul_ref = ENV['ZUUL_REF']
48
+    zuul_branch = ENV['ZUUL_BRANCH']
49
+    zuul_url = ENV['ZUUL_URL']
50
+    repo = 'openstack/puppet-openstack-integration'
51
+    rm_rf(repo)
52
+    if File.exists?('/usr/zuul-env/bin/zuul-cloner')
53
+      zuul_clone_cmd = ['/usr/zuul-env/bin/zuul-cloner']
54
+      zuul_clone_cmd += ['--cache-dir', '/opt/git']
55
+      zuul_clone_cmd += ['--zuul-ref', "#{zuul_ref}"]
56
+      zuul_clone_cmd += ['--zuul-branch', "#{zuul_branch}"]
57
+      zuul_clone_cmd += ['--zuul-url', "#{zuul_url}"]
58
+      zuul_clone_cmd += ['git://git.openstack.org', "#{repo}"]
59
+      sh(*zuul_clone_cmd)
60
+    else
61
+      sh("git clone https://git.openstack.org/#{repo} #{repo}")
62
+    end
63
+    script = ['env']
64
+    script += ["PUPPETFILE_DIR=#{Dir.pwd}/spec/fixtures/modules"]
65
+    script += ["ZUUL_REF=#{zuul_ref}"]
66
+    script += ["ZUUL_BRANCH=#{zuul_branch}"]
67
+    script += ["ZUUL_URL=#{zuul_url}"]
68
+    script += ['bash', "#{repo}/install_modules_unit.sh"]
69
+    sh(*script)
70
+  end
71
+  rm_rf("spec/fixtures/modules/#{modname}")
72
+  ln_s(Dir.pwd, "spec/fixtures/modules/#{modname}")
73
+  mkdir_p('spec/fixtures/manifests')
74
+  touch('spec/fixtures/manifests/site.pp')
75
+end
76
+
77
+Rake::Task[:spec_clean].clear
78
+desc 'Clean up the fixtures directory'
79
+task :spec_clean do
80
+  rm_rf('spec/fixtures/modules')
81
+  rm_rf('openstack')
82
+  if File.zero?('spec/fixtures/manifests/site.pp')
83
+    rm_f('spec/fixtures/manifests/site.pp')
84
+  end
85
+end

Loading…
Cancel
Save