Skip to content

Commit

Permalink
(SIMP-9277) Misc minor fixes (#157)
Browse files Browse the repository at this point in the history
* Bumped the version number
* Checked for GPG commands and provided a notice on failure
* Fixed the nodesets
  • Loading branch information
trevor-vaughan authored Feb 9, 2021
1 parent 7af129a commit e13c48f
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 34 deletions.
6 changes: 4 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ gem 'simp-build-helpers'
gem 'simp-beaker-helpers'
gem 'beaker-puppet_install_helper'
gem 'rake', '>= 12.3.3'
gem 'beaker-docker', :git => 'https://github.com/trevor-vaughan/beaker-docker', :branch => 'support_rootless_podman'
gem 'docker-api', :git => 'https://github.com/trevor-vaughan/docker-api', :branch => 'podman-compat'
# You'll need the following if using podman until they are released upstream
#gem 'beaker-docker', :git => 'https://github.com/trevor-vaughan/beaker-docker', :branch => 'support_rootless_podman'
#gem 'docker-api', :git => 'https://github.com/trevor-vaughan/docker-api', :branch => 'podman-compat'
gem 'beaker-docker'

if puppetversion
gem 'puppet', puppetversion
Expand Down
15 changes: 14 additions & 1 deletion lib/simp/local_gpg_signing_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def initialize(dir = 'dev', opts = {})
# @return [Gem::Version]
def gpg_version
return @gpg_version if @gpg_version

which('gpg', true)
@gpg_version = %x{gpg --version}.lines.first.split(/\s+/).last

unless @gpg_version.nil? || @gpg_version.empty?
Expand Down Expand Up @@ -113,6 +115,8 @@ def gpg_agent_info
def dev_key_days_left
ensure_gpg_directory
days_left = 0

which('gpg', true)
current_key = %x(GPG_AGENT_INFO='' gpg --homedir=#{@dir} --list-keys #{@key_email} 2>/dev/null)
unless current_key.empty?
lasts_until = current_key.lines.first.strip.split("\s").last.delete(']')
Expand Down Expand Up @@ -179,6 +183,10 @@ def ensure_key

generate_key(agent_info[:info])
else
which('gpg', true)
which('gpg-agent', true)
which('gpg-connect-agent', true)

# Start the GPG agent
%x{gpg-agent --homedir=#{Dir.pwd} >&/dev/null || gpg-agent --homedir=#{Dir.pwd} --daemon >&/dev/null}

Expand Down Expand Up @@ -240,6 +248,8 @@ def kill_agent(pid)
# @param gpg_agent_info_str [String] value to set the GPG_AGENT_INFO
# environment variable to use in order to use the correct `gpg-agent`.
def generate_key(gpg_agent_info_str)
which('gpg', true)

puts "Generating new GPG key#{@verbose ? " under '#{@dir}'" : ''}..."
gpg_cmd = %(GPG_AGENT_INFO=#{gpg_agent_info_str} gpg --homedir="#{@dir}")

Expand Down Expand Up @@ -298,13 +308,16 @@ def write_genkey_parameter_file

# Write a local gpg-agent daemon script file
def write_gpg_agent_startup_script
which('gpg-agent', true)
pinentry_cmd = which('pinentry-curses', true)

gpg_agent_script = <<-AGENT_SCRIPT.gsub(%r{^ {20}}, '')
#!/bin/sh
gpg-agent --homedir=#{Dir.pwd} --daemon \
--no-use-standard-socket --sh --batch \
--write-env-file "#{@gpg_agent_env_file}" \
--pinentry-program /usr/bin/pinentry-curses < /dev/null &
--pinentry-program #{pinentry_cmd} < /dev/null &
AGENT_SCRIPT

File.open(@gpg_agent_script, 'w') { |fh| fh.puts(gpg_agent_script) }
Expand Down
19 changes: 13 additions & 6 deletions lib/simp/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,21 @@ def run_pager
exec pager rescue exec "/bin/sh", "-c", pager
end

# Originally snarfed from
# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
def which(cmd)
command = Facter::Core::Execution.which(cmd)
def which(cmd, fail=false)
@which_cache ||= {}

warn "Warning: Command #{cmd} not found on the system." unless command
if @which_cache.has_key?(cmd)
command = @which_cache[cmd]
else
command = Facter::Core::Execution.which(cmd)
@which_cache[cmd] = command
end

msg = "Warning: Command #{cmd} not found on the system."

fail ? raise(msg) : warn(msg) unless command

return command
command
end

def help
Expand Down
2 changes: 1 addition & 1 deletion lib/simp/rake/helpers/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module Simp; end
module Simp::Rake; end

class Simp::Rake::Helpers
VERSION = '5.11.5'
VERSION = '5.11.6'
end
35 changes: 14 additions & 21 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,17 @@ HOSTS:
- build_server
platform: el-7-x86_64
hypervisor: docker
image: centos:7
image: simpproject/simp_build_centos7
docker_cmd: '/usr/sbin/sshd -D -E /var/log/sshd.log'
mount_folders:
folder1:
host_path: ./
container_path: /host_files
docker_preserve_image: true
ssh:
password: root
auth_methods:
- password

el8-build-server:
roles:
- build_server
platform: el-8-x86_64
hypervisor: docker
image: centos:8
image: simpproject/simp_build_centos8
docker_cmd: '["/sbin/init"]'
docker_cap_add:
- AUDIT_WRITE
mount_folders:
folder1:
host_path: ./
container_path: /host_files
docker_preserve_image: true
ssh:
password: root
auth_methods:
- password

CONFIG:
log_level: verbose
Expand All @@ -44,3 +25,15 @@ CONFIG:
<% else -%>
puppet_collection: puppet6
<% end -%>
ssh:
password: root
auth_methods:
- password
docker_cap_add:
- AUDIT_WRITE
docker_preserve_image: true
mount_folders:
host_files:
host_path: ./
container_path: /host_files
opts: 'z'
19 changes: 16 additions & 3 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
require 'beaker-rspec'
require 'tmpdir'
require 'yaml'
require 'simp/beaker_helpers'
include Simp::BeakerHelpers
require 'tmpdir'
require 'pry' if ENV['PRY'] == 'yes'

require 'acceptance/support/simp_rake_helpers'
$LOAD_PATH.unshift(File.expand_path('../acceptance/support',__FILE__))

unless ENV['BEAKER_provision'] == 'no'
hosts.each do |host|
# Install Puppet
if host.is_pe?
install_pe
else
install_puppet
end
end
end


RSpec.configure do |c|
# provide helper methods to individual examples AND example groups
c.include Simp::BeakerHelpers::SimpRakeHelpers
c.extend Simp::BeakerHelpers::SimpRakeHelpers

# ensure that environment OS is ready on each host
fix_errata_on hosts

# Readable test descriptions
c.formatter = :documentation

# Configure all nodes in nodeset
c.before :suite do
end
end

0 comments on commit e13c48f

Please sign in to comment.