Skip to content

Commit

Permalink
Use bosh_ssh instead of ssh
Browse files Browse the repository at this point in the history
- add bosh_ssh, bosh_ssh_sudo in bosh_helper
- change signature of get_disk, get_persistent due to bosh_ssh change
- remove ssh_sudo due to new stemcell supporting sudo without password
- remove some helper functions to make BATs not IS releated
- tag different tests with tag: core,
                                persistent_disk,
                                vip_networking,
                                dynamic_networking,
                                manual_networking,
                                root_partition,
                                changing_static_ip,
                                multiple_manual_networks,
                                network_reconfiguration,
                                raw_ephemeral_storage
  • Loading branch information
kaleo211 authored and lwoydziak committed Jan 12, 2016
1 parent 6f5e0f6 commit dfdd287
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 202 deletions.
38 changes: 26 additions & 12 deletions lib/bat/bosh_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def ssh_options
}
end

def manual_networking?
@env.bat_networking == 'manual'
end

def aws?
@env.bat_infrastructure == 'aws'
end
Expand Down Expand Up @@ -56,8 +52,8 @@ def bosh_tld
info['features']['dns']['extras']['domain_name'] if dns?
end

def persistent_disk(host, user, options = {})
get_disks(host, user, options).each do |disk|
def persistent_disk(job, index)
get_disks(job, index).each do |disk|
values = disk.last
if values[:mountpoint] == '/var/vcap/store'
return values[:blocks]
Expand Down Expand Up @@ -88,11 +84,29 @@ def ssh(host, user, command, options = {})
output
end

def ssh_sudo(host, user, command, options)
if options[:password].nil?
raise 'Need to set sudo :password'
def bosh_ssh(job, index, command, options = {})
private_key = ssh_options[:private_key]

# Try our best to clean out old host fingerprints for director and vms
if File.exist?(File.expand_path('~/.ssh/known_hosts'))
Bosh::Exec.sh("ssh-keygen -R '#{@env.director}'")
Bosh::Exec.sh("ssh-keygen -R '#{static_ip}'")
end

if private_key
bosh_ssh_options = {
gateway_host: @env.director,
gateway_user: 'vcap',
gateway_identity_file: private_key,
}.map { |k, v| "--#{k} '#{v}'" }.join(' ')

# Note gateway_host + ip: ...fingerprint does not match for "micro.ci2.cf-app.com,54.208.15.101" (Net::SSH::HostKeyMismatch)
if File.exist?(File.expand_path('~/.ssh/known_hosts'))
Bosh::Exec.sh("ssh-keygen -R '#{@env.director},#{static_ip}'").output
end
end
ssh(host, user, "echo #{options[:password]} | sudo -p '' -S #{command}", options)

bosh_safe("ssh #{job} #{index} '#{command}' #{bosh_ssh_options}")
end

def tarfile
Expand Down Expand Up @@ -139,11 +153,11 @@ def get_vms
output
end

def get_disks(host, user, options)
def get_disks(job, index)
disks = {}
df_cmd = 'df -x tmpfs -x devtmpfs -x debugfs -l | tail -n +2'

df_output = ssh(host, user, df_cmd, options)
df_output = bosh_ssh(job, index, df_cmd)
df_output.split("\n").each do |line|
fields = line.split(/\s+/)
disks[fields[0]] = {
Expand Down
8 changes: 0 additions & 8 deletions lib/bat/deployment_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,6 @@ def static_ip
static_ips.first
end

def includes_vip?
!!(@spec['properties']['vip'])
end

def vip
@spec['properties']['vip']
end
Expand Down Expand Up @@ -193,10 +189,6 @@ def use_flavor_with_no_ephemeral_disk
@spec['properties']['instance_type'] = @spec['properties']['flavor_with_no_ephemeral_disk']
end

def dynamic_networking?
@spec['properties']['networks'].any? { |n| n['type'] == 'dynamic' }
end

def network_type
@spec['properties'].fetch('network', {}).fetch('type', nil)
end
Expand Down
21 changes: 0 additions & 21 deletions lib/bat/stemcell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ def to_path
path
end

def supports_network_reconfiguration?
!(name =~ /vcloud/ && name =~ /centos/) && name !~ /warden/
end

def sudo_command
if name =~ /centos/
"echo #{ENV['BAT_VCAP_PASSWORD']} | sudo -S -p '' -i"
Expand All @@ -46,23 +42,6 @@ def sudo_command
end
end

def supports_root_partition?
!!(name =~ /openstack/ && name !~ /centos/)
end

def supports_changing_static_ip?(network_type)
# Does not support for openstack dynamic
supports_network_reconfiguration? && !(name =~ /openstack/ && network_type == 'dynamic')
end

def supports_multiple_manual_networks?
(name =~ /openstack/ && name =~ /go_agent/) || (name =~ /vsphere/ && name =~ /go_agent/)
end

def supports_raw_ephemeral_storage?
name =~ /aws/
end

def ==(other)
to_s == other.to_s
end
Expand Down
42 changes: 0 additions & 42 deletions spec/bat/stemcell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,48 +68,6 @@
end
end

describe '#supports_network_reconfiguration?' do
{
# Go agent
'bosh-custom-xen-ubuntu-trusty-go_agent' => true,
'bosh-custom-xen-centos-go_agent' => true,
'bosh-aws-xen-hvm-ubuntu-trusty-go_agent' => true,
'bosh-aws-xen-centos-7-go_agent' => true,
'bosh-vsphere-esxi-ubuntu-trusty-go_agent' => true,
'bosh-vsphere-esxi-centos-go_agent' => true,
'bosh-vcloud-esxi-ubuntu-trusty-go_agent' => true,
'bosh-openstack-kvm-centos-7-go_agent' => true,
'bosh-openstack-kvm-ubuntu-trusty-go_agent' => true,

# Centos currently does not include open-vm-tools
'bosh-vcloud-esxi-centos-go_agent' => false,

# Warden CPI does not support network reconfig
'bosh-warden-boshlite-ubuntu-trusty-go_agent' => false,
'bosh-warden-boshlite-centos-go_agent' => false,

}.each do |stemcell_name, expected|
it "returns #{expected} for #{stemcell_name}" do
stemcell = Bat::Stemcell.new(stemcell_name, nil)
expect(stemcell.supports_network_reconfiguration?).to be(expected)
end
end
end

describe '#supports_root_partition?' do
{
'bosh-openstack-kvm-centos-go_agent' => false,
'bosh-openstack-kvm-ubuntu-trusty-go_agent' => true,
'bosh-vsphere-esxi-ubuntu-trusty-go_agent' => false,
'bosh-vcloud-esxi-ubuntu-trusty-go_agent' => false,
}.each do |stemcell_name, expected|
it "returns #{expected} for #{stemcell_name}" do
stemcell = Bat::Stemcell.new(stemcell_name, nil)
expect(stemcell.supports_root_partition?).to be(expected)
end
end
end

describe '#to_s' do
it 'returns "<name>-<version>"' do
expect(stemcell.to_s).to eq('STEMCELL_NAME-STEMCELL_NAME')
Expand Down
3 changes: 2 additions & 1 deletion spec/system/env_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'system/spec_helper'

describe 'initialization', :skip_task_check do

describe 'initialization', skip_task_check: true, core: true do
describe 'environment requirements' do
it 'should have a readable stemcell' do
expect(File.exist?(@requirements.stemcell.to_path)).to be(true)
Expand Down
43 changes: 11 additions & 32 deletions spec/system/network_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
@requirements.cleanup(deployment)
end

describe 'resolving DNS entries' do
before { skip 'director not configured with dns' unless dns? }

describe 'resolving DNS entries', dns: true do
let(:dns) { Resolv::DNS.new(nameserver: @env.dns_host) }

it 'forward looks up instance' do
Expand All @@ -37,24 +35,17 @@

it 'resolves instance names from deployed VM' do
# Temporarily add to debug why dig is returning 'connection timed out'
resolv_conf = ssh(public_ip, 'vcap', 'cat /etc/resolv.conf', ssh_options)
resolv_conf = bosh_ssh('batlight', 0, 'cat /etc/resolv.conf').output
@logger.info("Contents of resolv.conf '#{resolv_conf}'")

bosh('logs batlight 0 --agent --dir /tmp')

cmd = 'dig +short 0.batlight.static.bat.bosh a 0.batlight.static.bat.microbosh a'
expect(ssh(public_ip, 'vcap', cmd, ssh_options)).to include(public_ip)
expect(bosh_ssh('batlight', 0, cmd).output).to include(public_ip)
end
end

describe 'changing instance DNS' do
before do
skip 'director not configured with dns' unless dns?
unless @requirements.stemcell.supports_network_reconfiguration?
skip "network reconfiguration does not work for #{@requirements.stemcell}"
end
end

describe 'changing instance DNS', dns: true, network_reconfiguration: true do
let(:manifest_with_different_dns) do
# Need to include a valid DNS host so that other tests
# can still use dns resolution on the deployed VM
Expand All @@ -67,40 +58,28 @@
it 'successfully reconfigures VM with new DNS nameservers' do
expect(bosh("deployment #{manifest_with_different_dns.to_path}")).to succeed
expect(bosh('deploy')).to succeed
expect(ssh(public_ip, 'vcap', 'cat /etc/resolv.conf', ssh_options)).to include('127.0.0.5')
expect(bosh_ssh('batlight', 0, 'cat /etc/resolv.conf').output).to include('127.0.0.5')
end
end

context 'when using manual networking' do
before do
skip "not using manual networking" unless manual_networking?
end

it 'changes static IP address' do
unless @requirements.stemcell.supports_changing_static_ip?(network_type)
skip "network reconfiguration does not work for #{@requirements.stemcell}"
end

context 'when using manual networking', manual_networking: true do
it 'changes static IP address', changing_static_ip: true do
use_second_static_ip
deployment = with_deployment
expect(bosh("deployment #{deployment.to_path}")).to succeed
expect(bosh('deploy')).to succeed

expect(ssh(public_ip, 'vcap', 'PATH=/sbin:/usr/sbin:$PATH; ifconfig', ssh_options)).to include(second_static_ip)
expect(bosh_ssh('batlight', 0, 'PATH=/sbin:/usr/sbin:$PATH; ifconfig').output).to include(second_static_ip)
end

it 'deploys multiple manual networks' do
unless @requirements.stemcell.supports_multiple_manual_networks?
skip "multiple manual networks are not supported for #{@requirements.stemcell}"
end

it 'deploys multiple manual networks', multiple_manual_networks: true do
use_multiple_manual_networks
deployment = with_deployment
expect(bosh("deployment #{deployment.to_path}")).to succeed
expect(bosh('deploy')).to succeed

expect(ssh(public_ip, 'vcap', 'PATH=/sbin:/usr/sbin:$PATH; ifconfig', ssh_options)).to include(static_ips[0])
expect(ssh(public_ip, 'vcap', 'PATH=/sbin:/usr/sbin:$PATH; ifconfig', ssh_options)).to include(static_ips[1])
expect(bosh_ssh('batlight', 0, 'PATH=/sbin:/usr/sbin:$PATH; ifconfig').output).to include(static_ips[0])
expect(bosh_ssh('batlight', 0, 'PATH=/sbin:/usr/sbin:$PATH; ifconfig').output).to include(static_ips[1])
end
end
end
10 changes: 4 additions & 6 deletions spec/system/raw_ephemeral_disk_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'system/spec_helper'

describe 'raw_instance_storage' do
describe 'raw_instance_storage', raw_ephemeral_storage: true do
before(:all) do
@requirements.requirement(@requirements.release)
@requirements.requirement(@requirements.stemcell)
Expand All @@ -12,8 +12,6 @@
end

before do
skip 'raw_instance_storage cloud property not supported on this IaaS' unless @requirements.stemcell.supports_raw_ephemeral_storage?

reload_deployment_spec
# using password 'foobar'
use_password('$6$tHAu4zCTso$pAQok0MTHP4newel7KMhTzMI4tQrAWwJ.X./fFAKjbWkCb5sAaavygXAspIGWn8qVD8FeT.Z/XN4dvqKzLHhl0')
Expand All @@ -29,11 +27,11 @@

it 'should attach all available instance disks and label them', ssh: true do
# assumes aws.yml.erb specifies instance_type: m3.medium, which has 1 local disk
expect(labeled_partitions(public_ip)).to eq(["raw-ephemeral-0"])
expect(labeled_partitions()).to eq(["raw-ephemeral-0"])
end

def labeled_partitions(ip)
output = ssh(ip, 'vcap', 'ls /dev/disk/by-partlabel', @our_ssh_options)
def labeled_partitions
output = bosh_ssh('batlight', 0, 'ls /dev/disk/by-partlabel').output
output.lines.map { |line| line.chomp }
end
end
28 changes: 4 additions & 24 deletions spec/system/with_release_stemcell_deployment_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'system/spec_helper'

describe 'with release, stemcell and deployment' do
describe 'with release, stemcell and deployment', core: true do
before(:all) do
@requirements.requirement(@requirements.stemcell)
@requirements.requirement(@requirements.release)
Expand All @@ -20,7 +20,8 @@
describe 'agent' do
it 'should survive agent dying', ssh: true do
Dir.mktmpdir do |tmpdir|
ssh(public_ip, 'vcap', "echo #{@env.vcap_password} | sudo -S pkill -9 agent", ssh_options)
ssh_command="echo #{@env.vcap_password} | sudo -S pkill -9 agent"
expect(bosh_ssh('batlight', 0, ssh_command)).to succeed
wait_for_vm('batlight/0')
expect(bosh_safe("logs batlight 0 --agent --dir #{tmpdir}")).to succeed
end
Expand All @@ -29,28 +30,7 @@

describe 'ssh' do
it 'can bosh ssh into a vm' do
private_key = ssh_options[:private_key]

# Try our best to clean out old host fingerprints for director and vms
if File.exist?(File.expand_path('~/.ssh/known_hosts'))
Bosh::Exec.sh("ssh-keygen -R '#{@env.director}'")
Bosh::Exec.sh("ssh-keygen -R '#{static_ip}'")
end

if private_key
bosh_ssh_options = {
gateway_host: @env.director,
gateway_user: 'vcap',
gateway_identity_file: private_key,
}.map { |k, v| "--#{k} '#{v}'" }.join(' ')

# Note gateway_host + ip: ...fingerprint does not match for "micro.ci2.cf-app.com,54.208.15.101" (Net::SSH::HostKeyMismatch)
if File.exist?(File.expand_path('~/.ssh/known_hosts'))
Bosh::Exec.sh("ssh-keygen -R '#{@env.director},#{static_ip}'")
end
end

expect(bosh_safe("ssh batlight 0 'uname -a' #{bosh_ssh_options}")).to succeed_with /Linux/
expect(bosh_ssh('batlight', 0, "uname -a").output).to match /Linux/
end
end

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'system/spec_helper'

describe 'with release, stemcell and failed deployment' do
describe 'with release, stemcell and failed deployment', core: true do
let(:deployment_manifest_bad) do
use_failing_job
with_deployment
Expand Down
Loading

0 comments on commit dfdd287

Please sign in to comment.