summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/puppet_command55
-rwxr-xr-xbin/run_tests35
2 files changed, 64 insertions, 26 deletions
diff --git a/bin/puppet_command b/bin/puppet_command
index a6cd5a69..a9d39066 100755
--- a/bin/puppet_command
+++ b/bin/puppet_command
@@ -7,12 +7,15 @@
# (exit codes, lockfile, multiple manifests, etc)
#
+require 'pty'
+require 'yaml'
+
PUPPET_BIN = '/usr/bin/puppet'
PUPPET_DIRECTORY = '/srv/leap'
PUPPET_PARAMETERS = '--color=false --detailed-exitcodes --libdir=puppet/lib --confdir=puppet'
SITE_MANIFEST = 'puppet/manifests/site.pp'
-SETUP_MANIFEST = 'puppet/manifests/setup.pp'
DEFAULT_TAGS = 'leap_base,leap_service'
+HIERA_FILE = '/etc/leap/hiera.yaml'
def main
process_command_line_arguments
@@ -54,21 +57,37 @@ def apply
end
def set_hostname
- exit_code = puppet_apply(:manifest => SETUP_MANIFEST, :tags => '') do |line|
- # todo: replace setup.pp with https://github.com/lutter/ruby-augeas
- # or try this: http://www.puppetcookbook.com/posts/override-a-facter-fact.html
- if (line !~ /Finished catalog run/ || @verbosity > 2) &&
- (line !~ /dnsdomainname: Name or service not known/) &&
- (line !~ /warning: Could not retrieve fact fqdn/)
- puts line
+ unless File.exists?(HIERA_FILE)
+ puts("ERROR: Cannot set hostname without #{HIERA_FILE}")
+ exit(1)
+ end
+ hostname = YAML.load_file(HIERA_FILE)['name']
+ if hostname.nil? || hostname.empty?
+ puts('ERROR: NAME argument required')
+ exit(1)
+ end
+ current_hostname_file = File.read('/etc/hostname') rescue nil
+ current_hostname = `/bin/hostname`.strip
+
+ # set /etc/hostname
+ if current_hostname_file != hostname
+ File.open('/etc/hostname', 'w', 0611, :encoding => 'ascii') do |f|
+ f.write hostname
+ end
+ if File.read('/etc/hostname') == hostname
+ puts "Set /etc/hostname to #{hostname}"
+ else
+ puts "ERROR: failed to update /etc/hostname"
end
end
- if exit_code == 2
- puts "Hostname updated."
- elsif exit_code == 4 || exit_code == 6
- puts "ERROR: could not update hostname."
- elsif exit_code == 0 && @verbosity > 1
- puts "No change to hostname."
+
+ # call /bin/hostname
+ if current_hostname != hostname
+ if run("/bin/hostname #{hostname}") == 0
+ puts "Set hostname to #{hostname}"
+ else
+ puts "ERROR: failed to call `/bin/hostname #{hostname}`"
+ end
end
end
@@ -157,24 +176,18 @@ end
## this only works under ruby 1.9
##
-require "pty"
-
def run(cmd)
puts cmd if @verbosity >= 3
PTY.spawn("#{cmd}") do |output, input, pid|
begin
while line = output.gets do
yield line
- #$stdout.puts line
- #$stdout.flush
end
rescue Errno::EIO
end
Process.wait(pid) # only works in ruby 1.9, required to capture the exit status.
end
- status = $?.exitstatus
- #yield status if block_given?
- return status
+ return $?.exitstatus
rescue PTY::ChildExited
end
diff --git a/bin/run_tests b/bin/run_tests
index 526aa83a..2ee027f4 100755
--- a/bin/run_tests
+++ b/bin/run_tests
@@ -127,11 +127,22 @@ class LeapTest < MiniTest::Unit::TestCase
if params
uri.query = URI.encode_www_form(params)
end
- response = Net::HTTP.get_response(uri)
- if response.is_a?(Net::HTTPSuccess)
- yield response.body, response, nil
- else
- yield nil, response, nil
+ http = Net::HTTP.new uri.host, uri.port
+ if uri.scheme == 'https'
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ http.use_ssl = true
+ end
+ http.start do |agent|
+ request = Net::HTTP::Get.new uri.request_uri
+ if uri.user
+ request.basic_auth uri.user, uri.password
+ end
+ response = agent.request(request)
+ if response.is_a?(Net::HTTPSuccess)
+ yield response.body, response, nil
+ else
+ yield nil, response, nil
+ end
end
rescue => exc
yield nil, nil, exc
@@ -151,6 +162,20 @@ class LeapTest < MiniTest::Unit::TestCase
end
#
+ # only a warning for now, should be a failure in the future
+ #
+ def assert_auth_fail(url, params)
+ uri = URI(url)
+ get(url, params) do |body, response, error|
+ unless response.code.to_s == "401"
+ warn "Expected a '401 Unauthorized' response, but got #{response.code} instead (GET #{uri.request_uri} with username '#{uri.user}')."
+ return false
+ end
+ end
+ true
+ end
+
+ #
# test if a socket can be connected to
#