mirror of
https://github.com/apache/cloudstack.git
synced 2025-11-03 04:12:31 +01:00
70 lines
2.2 KiB
Ruby
70 lines
2.2 KiB
Ruby
# Licensed to the Apache Software Foundation (ASF) under one
|
|
# or more contributor license agreements. See the NOTICE file
|
|
# distributed with this work for additional information
|
|
# regarding copyright ownership. The ASF licenses this file
|
|
# to you under the Apache License, Version 2.0 (the
|
|
# "License"); you may not use this file except in compliance
|
|
# with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing,
|
|
# software distributed under the License is distributed on an
|
|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
# KIND, either express or implied. See the License for the
|
|
# specific language governing permissions and limitations
|
|
# under the License.
|
|
|
|
require 'serverspec'
|
|
require 'pathname'
|
|
require 'net/ssh'
|
|
require 'pp'
|
|
|
|
include SpecInfra::Helper::Ssh
|
|
include SpecInfra::Helper::DetectOS
|
|
|
|
#RSpec.configure do |c|
|
|
# c.before :all do
|
|
# c.path = '/sbin:/usr/sbin'
|
|
# end
|
|
#end
|
|
|
|
RSpec.configure do |c|
|
|
if ENV['ASK_SUDO_PASSWORD']
|
|
require 'highline/import'
|
|
c.sudo_password = ask('Enter sudo password: ') { |q| q.echo = false }
|
|
else
|
|
c.sudo_password = ENV['SUDO_PASSWORD']
|
|
end
|
|
c.before :all do
|
|
block = self.class.metadata[:example_group_block]
|
|
if RUBY_VERSION.start_with?('1.8')
|
|
file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
|
|
else
|
|
file = block.source_location.first
|
|
end
|
|
host = File.basename(Pathname.new(file).dirname)
|
|
if c.host != host
|
|
c.ssh.close if c.ssh
|
|
c.host = host
|
|
options = Net::SSH::Config.for(c.host)
|
|
user = options[:user] || Etc.getlogin
|
|
config = `vagrant ssh-config default`
|
|
if config != ''
|
|
config.each_line do |line|
|
|
if match = /HostName (.*)/.match(line)
|
|
host = match[1]
|
|
elsif match = /User (.*)/.match(line)
|
|
user = match[1]
|
|
elsif match = /IdentityFile (.*)/.match(line)
|
|
options[:keys] = [match[1].gsub(/"/,'')]
|
|
elsif match = /Port (.*)/.match(line)
|
|
options[:port] = match[1]
|
|
end
|
|
end
|
|
end
|
|
c.ssh = Net::SSH.start(host, user, options)
|
|
end
|
|
end
|
|
end
|