Browse Source

Use puppet-openstack_spec_helper for Rakefile & spec_helper_acceptance

Use common code in puppet-openstack_spec_helper in Rakefile and
spec_helper_acceptance.

Change-Id: Ia9279876369e1ae1d0062eae4b103fca5256c452
tags/8.0.0b1
Emilien Macchi 3 years ago
parent
commit
67bd15682e
2 changed files with 2 additions and 141 deletions
  1. 1
    85
      Rakefile
  2. 1
    56
      spec/spec_helper_acceptance.rb

+ 1
- 85
Rakefile View File

@@ -1,85 +1 @@
1
-require 'puppetlabs_spec_helper/rake_tasks'
2
-require 'puppet-lint/tasks/puppet-lint'
3
-require 'puppet-syntax/tasks/puppet-syntax'
4
-require 'json'
5
-
6
-modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1]
7
-
8
-PuppetSyntax.exclude_paths ||= []
9
-PuppetSyntax.exclude_paths << "spec/fixtures/**/*"
10
-PuppetSyntax.exclude_paths << "pkg/**/*"
11
-PuppetSyntax.exclude_paths << "vendor/**/*"
12
-
13
-Rake::Task[:lint].clear
14
-PuppetLint::RakeTask.new :lint do |config|
15
-  config.ignore_paths = ["spec/**/*.pp", "vendor/**/*.pp"]
16
-  config.fail_on_warnings = true
17
-  config.log_format = '%{path}:%{linenumber}:%{KIND}: %{message}'
18
-  config.disable_checks = ["80chars", "class_inherits_from_params_class", "only_variable_string"]
19
-end
20
-
21
-desc "Run acceptance tests"
22
-RSpec::Core::RakeTask.new(:acceptance) do |t|
23
-  t.pattern = 'spec/acceptance'
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
1
+require 'puppet-openstack_spec_helper/rake_tasks'

+ 1
- 56
spec/spec_helper_acceptance.rb View File

@@ -1,56 +1 @@
1
-require 'beaker-rspec'
2
-require 'beaker/puppet_install_helper'
3
-
4
-run_puppet_install_helper
5
-
6
-RSpec.configure do |c|
7
-  # Project root
8
-  proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
9
-  modname = JSON.parse(open('metadata.json').read)['name'].split('-')[1]
10
-
11
-  # Readable test descriptions
12
-  c.formatter = :documentation
13
-
14
-  # Configure all nodes in nodeset
15
-  c.before :suite do
16
-    # Install module and dependencies
17
-    hosts.each do |host|
18
-
19
-      # install git
20
-      install_package host, 'git'
21
-
22
-      zuul_ref = ENV['ZUUL_REF']
23
-      zuul_branch = ENV['ZUUL_BRANCH']
24
-      zuul_url = ENV['ZUUL_URL']
25
-
26
-      repo = 'openstack/puppet-openstack-integration'
27
-
28
-      # Start out with clean moduledir, don't trust r10k to purge it
29
-      on host, "rm -rf /etc/puppet/modules/*"
30
-      # Install dependent modules via git or zuul
31
-      r = on host, "test -e /usr/zuul-env/bin/zuul-cloner", { :acceptable_exit_codes => [0,1] }
32
-      if r.exit_code == 0
33
-        zuul_clone_cmd = '/usr/zuul-env/bin/zuul-cloner '
34
-        zuul_clone_cmd += '--cache-dir /opt/git '
35
-        zuul_clone_cmd += "--zuul-ref #{zuul_ref} "
36
-        zuul_clone_cmd += "--zuul-branch #{zuul_branch} "
37
-        zuul_clone_cmd += "--zuul-url #{zuul_url} "
38
-        zuul_clone_cmd += "git://git.openstack.org #{repo}"
39
-        on host, zuul_clone_cmd
40
-      else
41
-        on host, "git clone https://git.openstack.org/#{repo} #{repo}"
42
-      end
43
-
44
-      on host, "ZUUL_REF=#{zuul_ref} ZUUL_BRANCH=#{zuul_branch} ZUUL_URL=#{zuul_url} bash #{repo}/install_modules.sh"
45
-
46
-      # Install the module being tested
47
-      on host, "rm -fr /etc/puppet/modules/#{modname}"
48
-      puppet_module_install(:source => proj_root, :module_name => modname)
49
-
50
-      on host, "rm -fr #{repo}"
51
-
52
-      # List modules installed to help with debugging
53
-      on host, puppet('module','list'), { :acceptable_exit_codes => 0 }
54
-    end
55
-  end
56
-end
1
+require 'puppet-openstack_spec_helper/beaker_spec_helper'

Loading…
Cancel
Save