Commit 695db9d4 authored by Jens Langhammer's avatar Jens Langhammer

Initial version

parents
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/
# Used by dotenv library to load environment variables.
# .env
## Specific to RubyMotion:
.dat*
.repl_history
build/
*.bridgesupport
build-iPhoneOS/
build-iPhoneSimulator/
## Specific to RubyMotion (use of CocoaPods):
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# vendor/Pods/
## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/rdoc/
## Environment normalization:
/.bundle/
/vendor/bundle
/lib/bundler/man/
# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
doc/*
before_script:
- sudo apt-get update >/dev/null
- sudo apt-get -y install rubygems openssh-client bundler >/dev/null
stages:
- test-development
- test-staging
- test-production
test-development:
script:
- "./foreman-ci.rb -e development -p $FOREMAN_PASS --prefix dev"
stage: test
environment: development
test-staging:
script:
- "./foreman-ci.rb -e staging -p $FOREMAN_PASS --prefix sta"
stage: test
environment: staging
test-production:
script:
- "./foreman-ci.rb -e production -p $FOREMAN_PASS --prefix prd"
stage: test
environment: production
GEM
remote: https://rubygems.org/
specs:
apipie-bindings (0.0.18)
json (>= 1.2.1)
oauth
rest-client (>= 1.6.5, < 3.0.0)
domain_name (0.5.20161021)
unf (>= 0.0.5, < 1.0.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
json (2.0.2)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
netrc (0.11.0)
oauth (0.5.1)
rake (11.3.0)
rest-client (2.0.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.2)
PLATFORMS
ruby
DEPENDENCIES
apipie-bindings
rake
---
allowed_runs: 2
foreman:
host: prd-fmas01.war.de.beryju.org
username: admin
domain: war.de.beryju.org
arch: x86_64
os: "Debian 8.6"
proxy: prd-fmas01.war.de.beryju.org
compute: DE-WAR
hostgroup: nix
profile: def
subnet: "war.de.beryju.org IPv4"
#!/usr/bin/ruby
require 'apipie-bindings'
require 'yaml'
require 'logger'
require 'logger/colors'
require 'optparse'
@logger = Logger.new STDOUT
@logger.level = Logger::INFO
@logger.progname = 'foreman-ci'
@config = YAML::load_file('config.yml')
OptionParser.new do |opts|
opts.banner = "Usage: gfbridge.rb [options]"
opts.on('-e', '--environment ENVIRONMENT', 'Foreman Environment') { |v|
@config['foreman']['environment'] = v
}
opts.on('-p', '--password PASSWORD', 'Foreman Password') { |v|
@config['foreman']['password'] = v
}
opts.on('-u', '--username USERNAME', 'Foreman Username') { |v|
@config['foreman']['username'] = v
}
opts.on('--prefix', '--prefix PREFIX', 'Hostname Prefix') { |v|
@config['foreman']['prefix'] = v
}
opts.on("-h", "--help", "Displays help") {
puts opts
exit
}
opts.on("-v", "--verbose", "Enable Verbose mode") {
@logger.level = Logger::DEBUG
}
end.parse!
@foreman = ApipieBindings::API.new(
{ :uri => "https://#{@config['foreman']['host']}/",
:username => @config['foreman']['username'],
:password => @config['foreman']['password'],
:api_version => 2})
def exact_match(name, result)
result['results'].each do |r|
if r['name'] == name or
r['title'] == name
@logger.debug "Found ID '#{r['id']}' for '#{name}'"
return r['id']
end
end
raise "Failed to find #{name}"
end
env_id = exact_match(@config['foreman']['environment'], @foreman.resource(:environments).action(:index).call(:per_page => 200))
domain_id = exact_match(@config['foreman']['domain'], @foreman.resource(:domains).action(:index).call(:per_page => 200))
arch_id = exact_match(@config['foreman']['arch'], @foreman.resource(:architectures).action(:index).call(:per_page => 200))
os_id = exact_match(@config['foreman']['os'], @foreman.resource(:operatingsystems).action(:index).call(:per_page => 200))
proxy_id = exact_match(@config['foreman']['proxy'], @foreman.resource(:smart_proxies).action(:index).call(:per_page => 200))
compute_id = exact_match(@config['foreman']['compute'], @foreman.resource(:compute_resources).action(:index).call(:per_page => 200))
hostgroup_id = exact_match(@config['foreman']['hostgroup'], @foreman.resource(:hostgroups).action(:index).call(:per_page => 200))
profile_id = exact_match(@config['foreman']['profile'], @foreman.resource(:compute_profiles).action(:index).call(:per_page => 200))
subnet_id = exact_match(@config['foreman']['subnet'], @foreman.resource(:subnets).action(:index).call(:per_page => 200))
time = Time.now.strftime("%Y-%m-%d-%H-%M-%S")
name = "#{@config['foreman']['prefix']}-ci-#{time}.#{@config['foreman']['domain']}"
@logger.info "Hostname is '#{name}'"
host = {
'name' => name,
'environment_id' => env_id,
'domain_id' => domain_id,
'architecture_id' => arch_id,
'operatingsystem_id' => os_id,
'puppet_proxy_id' => proxy_id,
'compute_resource_id' => compute_id,
'hostgroup_id' => hostgroup_id,
'compute_profile_id' => profile_id,
'subnet_id' => subnet_id,
'build' => true,
'enabled' => true,
}
host = @foreman.resource(:hosts).action(:create).call(:host => host)
host_id = host['id']
@logger.info "Host ID: '#{host_id}'"
# Manually turn on since it sometimes doesn't automatically
sleep(20)
@foreman.resource(:hosts).action(:power).call(:id => host_id, :power_action => 'on')
@logger.info "Powered on host"
built = 1 # 1 translates to in progress, 0 is installed
install_start = Time.now.getutc
while built == 1 do
built = @foreman.resource(:hosts).action(:show).call(:id => host_id)['build_status']
sleep(5)
end
install_end = Time.now.getutc
@logger.info "Host #{name} is built"
report_count = 0
@logger.info "Waiting for #{@config['allowed_runs']} Reports..."
run_start = Time.now.getutc
while report_count < @config['allowed_runs'] do
report_count = @foreman.resource(:reports).action(:index).call(:search => "host = #{name}")['subtotal']
sleep(30)
end
run_end = Time.now.getutc
@logger.info "Allowed runs reached"
reports = @foreman.resource(:reports).action(:index).call(:search => "host = #{name}")['results']
failed_count = 0
reports.each do |report|
failed_count += report['status']['failed']
end
@logger.info "#{failed_count} failed objects on #{name}"
@foreman.resource(:hosts).action(:destroy).call(:id => host_id)
@logger.info "Deleted Host #{name}"
@logger.info "------------------------------------------"
@logger.info "Results:"
@logger.info "\tHostname:\t\t\t#{name}"
@logger.info "\tInstall Duration:\t\t#{install_end-install_start}s"
@logger.info "\tErrors:\t\t\t#{failed_count}"
exit failed_count
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment