Skip to content

Commit e19bfe1

Browse files
author
tphoney
committed
(FM-8455) move beaker tests to litmus
1 parent a96170f commit e19bfe1

File tree

8 files changed

+348
-12
lines changed

8 files changed

+348
-12
lines changed

.fixtures.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
fixtures:
22
repositories:
3-
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib.git"
3+
'facts': 'git://github.com/puppetlabs/puppetlabs-facts.git'
4+
'provision': "git://github.com/puppetlabs/provision.git"
5+
'puppet_agent': 'git://github.com/puppetlabs/puppetlabs-puppet_agent.git'
6+
'stdlib': "https://github.com/puppetlabs/puppetlabs-stdlib.git"
47
forge_modules:
5-
mount_core: "puppetlabs/mount_core"
8+
'mount_core': "puppetlabs/mount_core"
69
symlinks:
7-
"lvm": "#{source_dir}"
10+
'lvm': "#{source_dir}"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ Gemfile.lock
55
.fixtures/modules
66
.fixtures/manifests
77
spec/fixtures
8+
pkg/
9+
inventory.yaml

Gemfile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ group :development, :test do
66
gem 'mocha', "~> 0.10.5", :require => false
77
gem 'puppetlabs_spec_helper', :require => false
88
gem 'puppet-blacksmith', :require => false
9+
gem 'puppet_litmus', :require => false
10+
gem 'parallel', :require => false
11+
gem 'serverspec', :require => false
12+
gem 'pry', :require => false
913
end
1014

1115
if puppetversion = ENV['PUPPET_GEM_VERSION']
@@ -26,12 +30,3 @@ gem 'metadata-json-lint', :require => false if RUBY_VERSION >= '1
2630
if RUBY_VERSION < '2.0'
2731
gem 'mime-types', '<3.0', :require => false
2832
end
29-
30-
group :system_tests do
31-
if beaker_version = ENV['BEAKER_VERSION']
32-
gem 'beaker', *location_for(beaker_version)
33-
end
34-
gem 'beaker-puppet_install_helper', :require => false
35-
gem 'master_manipulator', '~> 1.2', :require => false
36-
end
37-
# vim:ft=ruby

Rakefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'puppetlabs_spec_helper/rake_tasks'
22
require 'puppet_blacksmith/rake_tasks'
33
require 'puppet-lint/tasks/puppet-lint'
4+
require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any?
45
PuppetLint.configuration.send('disable_80chars')
56
PuppetLint.configuration.relative = true
67
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
require 'spec_helper_acceptance'
2+
require 'securerandom'
3+
4+
describe 'create filesystems' do
5+
describe 'create_filesystem_non-existing-format' do
6+
let(:pv) do
7+
'/dev/sdc'
8+
end
9+
let(:vg) do
10+
("VolumeGroup_" + SecureRandom.hex(2))
11+
end
12+
let(:lv) do
13+
("LogicalVolume_" + SecureRandom.hex(3))
14+
end
15+
let(:pp) do
16+
<<-MANIFEST
17+
physical_volume {'#{pv}':
18+
ensure => present,
19+
}
20+
->
21+
volume_group {'#{vg}':
22+
ensure => present,
23+
physical_volumes => '#{pv}',
24+
}
25+
->
26+
logical_volume{'#{lv}':
27+
ensure => present,
28+
volume_group => '#{vg}',
29+
size => '20M',
30+
}
31+
->
32+
filesystem {'Create_filesystem':
33+
name => '/dev/#{vg}/#{lv}',
34+
ensure => present,
35+
fs_type => 'non-existing-format',
36+
}
37+
MANIFEST
38+
end
39+
40+
it 'applies the manifest' do
41+
apply_manifest(pp)
42+
remove_all(pv, vg, lv)
43+
end
44+
end
45+
46+
describe 'create_filesystem_with_ensure_property_ext2' do
47+
let(:pv) do
48+
'/dev/sdc'
49+
end
50+
let(:vg) do
51+
("VolumeGroup_" + SecureRandom.hex(2))
52+
end
53+
let(:lv) do
54+
("LogicalVolume_" + SecureRandom.hex(3))
55+
end
56+
let(:pp) do
57+
<<-MANIFEST
58+
physical_volume {'#{pv}':
59+
ensure => present,
60+
}
61+
->
62+
volume_group {'#{vg}':
63+
ensure => present,
64+
physical_volumes => '#{pv}',
65+
}
66+
->
67+
logical_volume{'#{lv}':
68+
ensure => present,
69+
volume_group => '#{vg}',
70+
size => '20M',
71+
}
72+
->
73+
filesystem {'Create_filesystem':
74+
name => '/dev/#{vg}/#{lv}',
75+
ensure => present,
76+
fs_type => 'ext2',
77+
}
78+
MANIFEST
79+
end
80+
81+
it 'applies the manifest' do
82+
apply_manifest(pp)
83+
expect(run_shell("file -sL /dev/#{vg}/#{lv}").stdout).to match %r{ext2}
84+
remove_all(pv, vg, lv)
85+
end
86+
end
87+
88+
describe 'create_filesystem_with_ensure_property_ext4' do
89+
let(:pv) do
90+
'/dev/sdc'
91+
end
92+
let(:vg) do
93+
("VolumeGroup_" + SecureRandom.hex(2))
94+
end
95+
let(:lv) do
96+
("LogicalVolume_" + SecureRandom.hex(3))
97+
end
98+
let(:pp) do
99+
<<-MANIFEST
100+
physical_volume {'#{pv}':
101+
ensure => present,
102+
}
103+
->
104+
volume_group {'#{vg}':
105+
ensure => present,
106+
physical_volumes => '#{pv}',
107+
}
108+
->
109+
logical_volume{'#{lv}':
110+
ensure => present,
111+
volume_group => '#{vg}',
112+
size => '20M',
113+
}
114+
->
115+
filesystem {'Create_filesystem':
116+
name => '/dev/#{vg}/#{lv}',
117+
ensure => present,
118+
fs_type => 'ext4',
119+
}
120+
MANIFEST
121+
end
122+
123+
it 'applies the manifest' do
124+
apply_manifest(pp)
125+
expect(run_shell("file -sL /dev/#{vg}/#{lv}").stdout).to match %r{ext4}
126+
remove_all(pv, vg, lv)
127+
end
128+
end
129+
130+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'spec_helper_acceptance'
2+
3+
describe 'include the lvm class' do
4+
pp = <<-MANIFEST
5+
include ::lvm
6+
MANIFEST
7+
8+
it 'run the manifest' do
9+
apply_manifest(pp, catch_failures: true)
10+
end
11+
end

spec/spec_helper_acceptance.rb

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# frozen_string_literal: true
2+
3+
require 'serverspec'
4+
require 'puppet_litmus'
5+
include PuppetLitmus
6+
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
7+
8+
if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
9+
puts 'Running tests against this machine !'
10+
if Gem.win_platform?
11+
set :backend, :cmd
12+
else
13+
set :backend, :exec
14+
end
15+
else
16+
# load inventory
17+
inventory_hash = inventory_hash_from_inventory_file
18+
node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])
19+
20+
if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes')
21+
host = ENV['TARGET_HOST']
22+
set :backend, :docker
23+
set :docker_container, host
24+
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
25+
set :backend, :ssh
26+
options = Net::SSH::Config.for(host)
27+
options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
28+
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
29+
options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil?
30+
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
31+
options[:verify_host_key] = Net::SSH::Verifiers::Null.new unless node_config.dig('ssh', 'host-key-check').nil?
32+
host = if ENV['TARGET_HOST'].include?(':')
33+
ENV['TARGET_HOST'].split(':').first
34+
else
35+
ENV['TARGET_HOST']
36+
end
37+
set :host, options[:host_name] || host
38+
set :ssh_options, options
39+
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
40+
require 'winrm'
41+
42+
set :backend, :winrm
43+
set :os, family: 'windows'
44+
user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
45+
pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
46+
endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"
47+
48+
opts = {
49+
user: user,
50+
password: pass,
51+
endpoint: endpoint,
52+
operation_timeout: 300,
53+
}
54+
55+
winrm = WinRM::Connection.new opts
56+
Specinfra.configuration.winrm = winrm
57+
end
58+
end
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
require 'pry'
2+
# Verify if a physical volume, volume group, logical volume, or filesystem resource type is created
3+
#
4+
# ==== Attributes
5+
#
6+
# * +resource_type+ - resorce type, i.e 'physical_volume', 'volume_group', 'logical_volume', 'filesystem',
7+
# * 'aix_physical_volume', 'aix_volume_group', or 'aix_logical_volume'.
8+
# * +resource_name+ - The name of resource type, i.e '/dev/sdb' for physical volume, vg_1234 for volume group
9+
# * +vg+ - volume group name associated with logical volume (if any)
10+
# * +properties+ - a matching string or regular expression in logical volume properties
11+
# ==== Returns
12+
#
13+
# +nil+
14+
#
15+
# ==== Raises
16+
# assert_match failure message
17+
# ==== Examples
18+
#
19+
# verify_if_created?(agent, 'physical_volume', /dev/sdb', VolumeGroup_123, "Size 7GB")
20+
def verify_if_created?(resource_type, resource_name, vg=nil, properties=nil)
21+
case resource_type
22+
when 'physical_volume'
23+
run_shell("pvdisplay") do |result|
24+
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
25+
end
26+
when 'volume_group'
27+
run_shell("vgdisplay") do |result|
28+
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
29+
end
30+
when 'logical_volume'
31+
raise ArgumentError, 'Missing volume group that the logical volume is associated with' unless vg
32+
run_shell("lvdisplay /dev/#{vg}/#{resource_name}") do |result|
33+
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
34+
if properties
35+
assert_match(/#{properties}/, result.stdout, 'Unexpected error was detected')
36+
end
37+
end
38+
when 'aix_physical_volume'
39+
run_shell("lspv #{resource_name}") do |result|
40+
assert_match(/Physical volume #{resource_name} is not assigned to/, result.stdout, 'Unexpected error was detected')
41+
end
42+
when 'aix_volume_group'
43+
run_shell("lsvg") do |result|
44+
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
45+
end
46+
when 'aix_logical_volume'
47+
raise ArgumentError, 'Missing volume group that the logical volume is associated with' unless vg
48+
run_shell("lslv #{resource_name}") do |result|
49+
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
50+
if properties
51+
assert_match(/#{properties}/, result.stdout, 'Unexpected error was detected')
52+
end
53+
end
54+
end
55+
end
56+
57+
# Clean the box after each test, make sure the newly created logical volumes, volume groups,
58+
# and physical volumes are removed at the end of each test to make the server ready for the
59+
# next test case.
60+
#
61+
# ==== Attributes
62+
#
63+
# * +pv+ - physical volume, can be one volume or an array of multiple volumes
64+
# * +vg+ - volume group, can be one group or an array of multiple volume groups
65+
# * +lv+ - logical volume, can be one volume or an array of multiple volumes
66+
# * +aix+ - if the agent is an AIX server.
67+
#
68+
# ==== Returns
69+
#
70+
# +nil+
71+
#
72+
# ==== Raises
73+
# +nil+
74+
# ==== Examples
75+
#
76+
# remove_all('/dev/sdb', 'VolumeGroup_1234', 'LogicalVolume_fa13')
77+
def remove_all(pv=nil, vg=nil, lv=nil, aix=false)
78+
if aix
79+
run_shell("reducevg -d -f #{vg} #{pv}")
80+
run_shell("rm -rf /dev/#{vg} /dev/#{lv}")
81+
else
82+
if lv
83+
if lv.kind_of?(Array)
84+
lv.each do |logical_volume|
85+
run_shell("umount /dev/#{vg}/#{logical_volume}", expect_failures: true)
86+
run_shell("lvremove /dev/#{vg}/#{logical_volume} --force", expect_failures: true)
87+
end
88+
else
89+
#note: in some test cases, for example, the test case 'create_vg_property_logical_volume'
90+
# the logical volume must be unmount before being able to delete it
91+
run_shell("umount /dev/#{vg}/#{lv}", expect_failures: true)
92+
run_shell("lvremove /dev/#{vg}/#{lv} --force", expect_failures: true)
93+
end
94+
end
95+
96+
if vg
97+
if vg.kind_of?(Array)
98+
vg.each do |volume_group|
99+
run_shell("vgremove /dev/#{volume_group}")
100+
end
101+
else
102+
run_shell("vgremove /dev/#{vg}")
103+
end
104+
end
105+
106+
if pv
107+
if pv.kind_of?(Array)
108+
pv.each do |physical_volume|
109+
run_shell("pvremove #{physical_volume}")
110+
end
111+
else
112+
run_shell("pvremove #{pv}")
113+
end
114+
end
115+
end
116+
end
117+
118+
RSpec.configure do |c|
119+
c.before :suite do
120+
auth_tok = 'pvxejsxwstwhsy0u2tjolfovg9wfzg2e'
121+
fail_test "AUTH_TOKEN must be set" unless auth_tok
122+
machine = ENV['TARGET_HOST']
123+
command = "curl -H X-AUTH-TOKEN:#{auth_tok} -X POST --url vcloud.delivery.puppetlabs.net/api/v1/vm/#{machine}/disk/1"
124+
fdisk = run_shell('fdisk -l').stdout
125+
if fdisk !~ /sdb/
126+
stdout, _stderr, _status = Open3.capture3(command)
127+
sleep(30)
128+
run_shell("echo \"- - -\" >/sys/class/scsi_host/host2/scan")
129+
end
130+
if fdisk !~ /sdc/
131+
stdout, _stderr, _status = Open3.capture3(command)
132+
sleep(30)
133+
run_shell("echo \"- - -\" >/sys/class/scsi_host/host2/scan")
134+
end
135+
end
136+
end

0 commit comments

Comments
 (0)