Skip to content

Commit

Permalink
(FM-8455) move beaker tests to litmus
Browse files Browse the repository at this point in the history
  • Loading branch information
tphoney committed Aug 21, 2019
1 parent a96170f commit e19bfe1
Show file tree
Hide file tree
Showing 8 changed files with 348 additions and 12 deletions.
9 changes: 6 additions & 3 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
fixtures:
repositories:
"stdlib": "https://github.com/puppetlabs/puppetlabs-stdlib.git"
'facts': 'git://github.com/puppetlabs/puppetlabs-facts.git'
'provision': "git://github.com/puppetlabs/provision.git"
'puppet_agent': 'git://github.com/puppetlabs/puppetlabs-puppet_agent.git'
'stdlib': "https://github.com/puppetlabs/puppetlabs-stdlib.git"
forge_modules:
mount_core: "puppetlabs/mount_core"
'mount_core': "puppetlabs/mount_core"
symlinks:
"lvm": "#{source_dir}"
'lvm': "#{source_dir}"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Gemfile.lock
.fixtures/modules
.fixtures/manifests
spec/fixtures
pkg/
inventory.yaml
13 changes: 4 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ group :development, :test do
gem 'mocha', "~> 0.10.5", :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-blacksmith', :require => false
gem 'puppet_litmus', :require => false
gem 'parallel', :require => false
gem 'serverspec', :require => false
gem 'pry', :require => false
end

if puppetversion = ENV['PUPPET_GEM_VERSION']
Expand All @@ -26,12 +30,3 @@ gem 'metadata-json-lint', :require => false if RUBY_VERSION >= '1
if RUBY_VERSION < '2.0'
gem 'mime-types', '<3.0', :require => false
end

group :system_tests do
if beaker_version = ENV['BEAKER_VERSION']
gem 'beaker', *location_for(beaker_version)
end
gem 'beaker-puppet_install_helper', :require => false
gem 'master_manipulator', '~> 1.2', :require => false
end
# vim:ft=ruby
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'puppetlabs_spec_helper/rake_tasks'
require 'puppet_blacksmith/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any?
PuppetLint.configuration.send('disable_80chars')
PuppetLint.configuration.relative = true
PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
Expand Down
130 changes: 130 additions & 0 deletions spec/acceptance/create_filesystem_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
require 'spec_helper_acceptance'
require 'securerandom'

describe 'create filesystems' do
describe 'create_filesystem_non-existing-format' do
let(:pv) do
'/dev/sdc'
end
let(:vg) do
("VolumeGroup_" + SecureRandom.hex(2))
end
let(:lv) do
("LogicalVolume_" + SecureRandom.hex(3))
end
let(:pp) do
<<-MANIFEST
physical_volume {'#{pv}':
ensure => present,
}
->
volume_group {'#{vg}':
ensure => present,
physical_volumes => '#{pv}',
}
->
logical_volume{'#{lv}':
ensure => present,
volume_group => '#{vg}',
size => '20M',
}
->
filesystem {'Create_filesystem':
name => '/dev/#{vg}/#{lv}',
ensure => present,
fs_type => 'non-existing-format',
}
MANIFEST
end

it 'applies the manifest' do
apply_manifest(pp)
remove_all(pv, vg, lv)
end
end

describe 'create_filesystem_with_ensure_property_ext2' do
let(:pv) do
'/dev/sdc'
end
let(:vg) do
("VolumeGroup_" + SecureRandom.hex(2))
end
let(:lv) do
("LogicalVolume_" + SecureRandom.hex(3))
end
let(:pp) do
<<-MANIFEST
physical_volume {'#{pv}':
ensure => present,
}
->
volume_group {'#{vg}':
ensure => present,
physical_volumes => '#{pv}',
}
->
logical_volume{'#{lv}':
ensure => present,
volume_group => '#{vg}',
size => '20M',
}
->
filesystem {'Create_filesystem':
name => '/dev/#{vg}/#{lv}',
ensure => present,
fs_type => 'ext2',
}
MANIFEST
end

it 'applies the manifest' do
apply_manifest(pp)
expect(run_shell("file -sL /dev/#{vg}/#{lv}").stdout).to match %r{ext2}
remove_all(pv, vg, lv)
end
end

describe 'create_filesystem_with_ensure_property_ext4' do
let(:pv) do
'/dev/sdc'
end
let(:vg) do
("VolumeGroup_" + SecureRandom.hex(2))
end
let(:lv) do
("LogicalVolume_" + SecureRandom.hex(3))
end
let(:pp) do
<<-MANIFEST
physical_volume {'#{pv}':
ensure => present,
}
->
volume_group {'#{vg}':
ensure => present,
physical_volumes => '#{pv}',
}
->
logical_volume{'#{lv}':
ensure => present,
volume_group => '#{vg}',
size => '20M',
}
->
filesystem {'Create_filesystem':
name => '/dev/#{vg}/#{lv}',
ensure => present,
fs_type => 'ext4',
}
MANIFEST
end

it 'applies the manifest' do
apply_manifest(pp)
expect(run_shell("file -sL /dev/#{vg}/#{lv}").stdout).to match %r{ext4}
remove_all(pv, vg, lv)
end
end

end
11 changes: 11 additions & 0 deletions spec/acceptance/include_class_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper_acceptance'

describe 'include the lvm class' do
pp = <<-MANIFEST
include ::lvm
MANIFEST

it 'run the manifest' do
apply_manifest(pp, catch_failures: true)
end
end
58 changes: 58 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

require 'serverspec'
require 'puppet_litmus'
include PuppetLitmus
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))

if ENV['TARGET_HOST'].nil? || ENV['TARGET_HOST'] == 'localhost'
puts 'Running tests against this machine !'
if Gem.win_platform?
set :backend, :cmd
else
set :backend, :exec
end
else
# load inventory
inventory_hash = inventory_hash_from_inventory_file
node_config = config_from_node(inventory_hash, ENV['TARGET_HOST'])

if target_in_group(inventory_hash, ENV['TARGET_HOST'], 'docker_nodes')
host = ENV['TARGET_HOST']
set :backend, :docker
set :docker_container, host
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'ssh_nodes')
set :backend, :ssh
options = Net::SSH::Config.for(host)
options[:user] = node_config.dig('ssh', 'user') unless node_config.dig('ssh', 'user').nil?
options[:port] = node_config.dig('ssh', 'port') unless node_config.dig('ssh', 'port').nil?
options[:keys] = node_config.dig('ssh', 'private-key') unless node_config.dig('ssh', 'private-key').nil?
options[:password] = node_config.dig('ssh', 'password') unless node_config.dig('ssh', 'password').nil?
options[:verify_host_key] = Net::SSH::Verifiers::Null.new unless node_config.dig('ssh', 'host-key-check').nil?
host = if ENV['TARGET_HOST'].include?(':')
ENV['TARGET_HOST'].split(':').first
else
ENV['TARGET_HOST']
end
set :host, options[:host_name] || host
set :ssh_options, options
elsif target_in_group(inventory_hash, ENV['TARGET_HOST'], 'winrm_nodes')
require 'winrm'

set :backend, :winrm
set :os, family: 'windows'
user = node_config.dig('winrm', 'user') unless node_config.dig('winrm', 'user').nil?
pass = node_config.dig('winrm', 'password') unless node_config.dig('winrm', 'password').nil?
endpoint = "http://#{ENV['TARGET_HOST']}:5985/wsman"

opts = {
user: user,
password: pass,
endpoint: endpoint,
operation_timeout: 300,
}

winrm = WinRM::Connection.new opts
Specinfra.configuration.winrm = winrm
end
end
136 changes: 136 additions & 0 deletions spec/spec_helper_acceptance_local.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
require 'pry'
# Verify if a physical volume, volume group, logical volume, or filesystem resource type is created
#
# ==== Attributes
#
# * +resource_type+ - resorce type, i.e 'physical_volume', 'volume_group', 'logical_volume', 'filesystem',
# * 'aix_physical_volume', 'aix_volume_group', or 'aix_logical_volume'.
# * +resource_name+ - The name of resource type, i.e '/dev/sdb' for physical volume, vg_1234 for volume group
# * +vg+ - volume group name associated with logical volume (if any)
# * +properties+ - a matching string or regular expression in logical volume properties
# ==== Returns
#
# +nil+
#
# ==== Raises
# assert_match failure message
# ==== Examples
#
# verify_if_created?(agent, 'physical_volume', /dev/sdb', VolumeGroup_123, "Size 7GB")
def verify_if_created?(resource_type, resource_name, vg=nil, properties=nil)
case resource_type
when 'physical_volume'
run_shell("pvdisplay") do |result|
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
end
when 'volume_group'
run_shell("vgdisplay") do |result|
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
end
when 'logical_volume'
raise ArgumentError, 'Missing volume group that the logical volume is associated with' unless vg
run_shell("lvdisplay /dev/#{vg}/#{resource_name}") do |result|
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
if properties
assert_match(/#{properties}/, result.stdout, 'Unexpected error was detected')
end
end
when 'aix_physical_volume'
run_shell("lspv #{resource_name}") do |result|
assert_match(/Physical volume #{resource_name} is not assigned to/, result.stdout, 'Unexpected error was detected')
end
when 'aix_volume_group'
run_shell("lsvg") do |result|
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
end
when 'aix_logical_volume'
raise ArgumentError, 'Missing volume group that the logical volume is associated with' unless vg
run_shell("lslv #{resource_name}") do |result|
assert_match(/#{resource_name}/, result.stdout, 'Unexpected error was detected')
if properties
assert_match(/#{properties}/, result.stdout, 'Unexpected error was detected')
end
end
end
end

# Clean the box after each test, make sure the newly created logical volumes, volume groups,
# and physical volumes are removed at the end of each test to make the server ready for the
# next test case.
#
# ==== Attributes
#
# * +pv+ - physical volume, can be one volume or an array of multiple volumes
# * +vg+ - volume group, can be one group or an array of multiple volume groups
# * +lv+ - logical volume, can be one volume or an array of multiple volumes
# * +aix+ - if the agent is an AIX server.
#
# ==== Returns
#
# +nil+
#
# ==== Raises
# +nil+
# ==== Examples
#
# remove_all('/dev/sdb', 'VolumeGroup_1234', 'LogicalVolume_fa13')
def remove_all(pv=nil, vg=nil, lv=nil, aix=false)
if aix
run_shell("reducevg -d -f #{vg} #{pv}")
run_shell("rm -rf /dev/#{vg} /dev/#{lv}")
else
if lv
if lv.kind_of?(Array)
lv.each do |logical_volume|
run_shell("umount /dev/#{vg}/#{logical_volume}", expect_failures: true)
run_shell("lvremove /dev/#{vg}/#{logical_volume} --force", expect_failures: true)
end
else
#note: in some test cases, for example, the test case 'create_vg_property_logical_volume'
# the logical volume must be unmount before being able to delete it
run_shell("umount /dev/#{vg}/#{lv}", expect_failures: true)
run_shell("lvremove /dev/#{vg}/#{lv} --force", expect_failures: true)
end
end

if vg
if vg.kind_of?(Array)
vg.each do |volume_group|
run_shell("vgremove /dev/#{volume_group}")
end
else
run_shell("vgremove /dev/#{vg}")
end
end

if pv
if pv.kind_of?(Array)
pv.each do |physical_volume|
run_shell("pvremove #{physical_volume}")
end
else
run_shell("pvremove #{pv}")
end
end
end
end

RSpec.configure do |c|
c.before :suite do
auth_tok = 'pvxejsxwstwhsy0u2tjolfovg9wfzg2e'
fail_test "AUTH_TOKEN must be set" unless auth_tok
machine = ENV['TARGET_HOST']
command = "curl -H X-AUTH-TOKEN:#{auth_tok} -X POST --url vcloud.delivery.puppetlabs.net/api/v1/vm/#{machine}/disk/1"
fdisk = run_shell('fdisk -l').stdout
if fdisk !~ /sdb/
stdout, _stderr, _status = Open3.capture3(command)
sleep(30)
run_shell("echo \"- - -\" >/sys/class/scsi_host/host2/scan")
end
if fdisk !~ /sdc/
stdout, _stderr, _status = Open3.capture3(command)
sleep(30)
run_shell("echo \"- - -\" >/sys/class/scsi_host/host2/scan")
end
end
end

0 comments on commit e19bfe1

Please sign in to comment.