Skip to content

Litmus #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
fixtures:
repositories:
stdlib: 'git://github.com/puppetlabs/puppetlabs-stdlib'
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'
symlinks:
local_user: "#{source_dir}"
forge_modules:
Expand Down
12 changes: 7 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ bundler_args: --without system_tests
rvm:
- 2.5.3
stages:
- static
- spec
- unit
- acceptance
-
if: tag =~ ^v\d
Expand All @@ -25,18 +24,21 @@ matrix:
include:
-
env: CHECK="check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop syntax lint metadata_lint"
stage: static
stage: unit
-
env: PUPPET_GEM_VERSION="~> 5.0" CHECK=parallel_spec
rvm: 2.4.5
stage: spec
stage: unit
-
env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
rvm: 2.5.3
stage: spec
stage: unit
-
env: DEPLOY_TO_FORGE=yes
stage: deploy
-
env: PUPPET_GEM_VERSION="~> 6.0" TARGET_HOST=localhost ACCEPTANCE=yes CHECK="litmus:provision_list[travis_centos] litmus:install_agent[puppet6] litmus:install_module litmus:acceptance:parallel"
stage: acceptance
branches:
only:
- master
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ group :development do
gem "json", '= 1.8.1', require: false if Gem::Version.new(RUBY_VERSION.dup) == Gem::Version.new('2.1.9')
gem "json", '= 2.0.4', require: false if Gem::Requirement.create('~> 2.4.2').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup))
gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw]
gem "puppet-module-posix-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby]
gem "puppet-module-posix-dev-r#{minor_version}", '~> 0.3', require: false, platforms: [:ruby]
gem "puppet-module-win-default-r#{minor_version}", '~> 0.3', require: false, platforms: [:mswin, :mingw, :x64_mingw]
Expand Down
13 changes: 11 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ end

def changelog_project
return unless Rake.application.top_level_tasks.include? "changelog"
returnVal = nil || JSON.load(File.read('metadata.json'))['source'].match(%r{.*/([^/]*)})[1]
raise "unable to find the changelog_project in .sync.yml or the name in metadata.json" if returnVal.nil?

returnVal = nil
returnVal ||= begin
metadata_source = JSON.load(File.read('metadata.json'))['source']
metadata_source_match = metadata_source && metadata_source.match(%r{.*\/([^\/]*?)(?:\.git)?\Z})

metadata_source_match && metadata_source_match[1]
end

raise "unable to find the changelog_project in .sync.yml or calculate it from the source in metadata.json" if returnVal.nil?

puts "GitHubChangelogGenerator project:#{returnVal}"
returnVal
end
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"version_requirement": ">=4.6.0 <7.0.0"
}
],
"pdk-version": "1.11.0",
"template-url": "pdk-default#1.11.0",
"template-ref": "1.11.0-0-g67637d4"
"pdk-version": "1.13.0",
"template-url": "pdk-default#1.13.0",
"template-ref": "1.13.0-0-g66e1443"
}
7 changes: 7 additions & 0 deletions provision.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
travis_centos:
provisioner: docker
images: ['centos:6','centos:7']
localhost:
provisioner: docker
images: ['centos:7']
23 changes: 23 additions & 0 deletions spec/acceptance/local_user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'spec_helper_acceptance'

describe 'Local user' do
context 'named rnelson0' do
return unless os[:family] != 'windows'
it do
pp = <<-PUPPETCODE
local_user{ 'rnelson0':
state => present,
groups => ['wheel'],
password => 'asdf',
manage_groups => true,
}
PUPPETCODE

idempotent_apply(pp)
end

describe file('/etc/passwd') do
its(:content) { is_expected.to contain %r{^rnelson0:x} }
end
end
end
5 changes: 5 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
end
end

# read default_facts and merge them over what is provided by facterdb
default_facts.each do |fact, value|
add_custom_fact fact, value
end

RSpec.configure do |c|
c.default_facts = default_facts
c.before :each do
Expand Down
82 changes: 82 additions & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# frozen_string_literal: true

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

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?
# Support both net-ssh 4 and 5.
# rubocop:disable Metrics/BlockNesting
options[:verify_host_key] = if node_config.dig('ssh', 'host-key-check').nil?
# Fall back to SSH behavior. This variable will only be set in net-ssh 5.3+.
if @strict_host_key_checking.nil? || @strict_host_key_checking
Net::SSH::Verifiers::Always.new
else
# SSH's behavior with StrictHostKeyChecking=no: adds new keys to known_hosts.
# If known_hosts points to /dev/null, then equivalent to :never where it
# accepts any key beacuse they're all new.
Net::SSH::Verifiers::AcceptNewOrLocalTunnel.new
end
elsif node_config.dig('ssh', 'host-key-check')
if defined?(Net::SSH::Verifiers::Always)
Net::SSH::Verifiers::Always.new
else
Net::SSH::Verifiers::Secure.new
end
elsif defined?(Net::SSH::Verifiers::Never)
Net::SSH::Verifiers::Never.new
else
Net::SSH::Verifiers::Null.new
end
# rubocop:enable Metrics/BlockNesting
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
set :request_pty, true
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