Skip to content

Commit 64eff9e

Browse files
Merge pull request #144 from bheuvel/refactoring/run_terminate_instance
Refactoring run/terminate instance
2 parents a8788b9 + 93c9527 commit 64eff9e

File tree

8 files changed

+616
-506
lines changed

8 files changed

+616
-506
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ Vagrantfile
1414
!example_box/Vagrantfile
1515
coverage/*
1616
vendor/*
17+
18+
# RubyMine
19+
.idea/*

Rakefile

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ task :default => "spec"
2929
namespace :functional_tests do
3030

3131
# Name must match folder beneath functional-tests/
32-
functional_test_names = [
33-
'vmlifecycle',
34-
'rsync',
35-
'networking'
36-
]
32+
functional_test_names = %w(vmlifecycle rsync networking)
33+
separate_test_names = %w(basic)
3734

3835
desc "Check for required enviroment variables for functional testing"
3936
task :check_environment do
@@ -82,4 +79,21 @@ namespace :functional_tests do
8279
end
8380
end
8481
end
82+
83+
separate_test_names.each do |test_dir_name|
84+
desc "Run functional test: #{test_dir_name}"
85+
task test_dir_name => [ :check_environment ] do
86+
Dir.chdir("#{File.expand_path('../', __FILE__)}/functional-tests/#{test_dir_name}/")
87+
Dir.glob("Vagrantfile*", File::FNM_CASEFOLD).each do |vagrant_file|
88+
89+
ENV['TEST_NAME'] = "vagrant_cloudstack_functional_test-#{test_dir_name}"
90+
ENV['VAGRANT_VAGRANTFILE'] = vagrant_file
91+
puts "Running RSpec tests in folder : #{test_dir_name}"
92+
puts "Using Vagrant file : #{ENV['VAGRANT_VAGRANTFILE']}"
93+
Rake::Task[:functionaltest].execute
94+
end
95+
end
96+
end
97+
98+
8599
end
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5+
VAGRANTFILE_API_VERSION = '2'
6+
7+
Vagrant.require_version '>= 1.5.0'
8+
9+
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
10+
11+
config.vm.synced_folder ".", "/vagrant", disabled: true, type: 'rsync' # if Vagrant::Util::Platform.windows?
12+
config.vm.box = ENV['LINUX_TEMPLATE_NAME']
13+
14+
config.vm.provider :cloudstack do |cloudstack, override|
15+
cloudstack.display_name = ENV['TEST_NAME']
16+
17+
cloudstack.host = ENV['CLOUDSTACK_HOST']
18+
cloudstack.path = '/client/api'
19+
cloudstack.port = '8080'
20+
cloudstack.scheme = 'http'
21+
cloudstack.api_key = ENV['CLOUDSTACK_API_KEY']
22+
cloudstack.secret_key = ENV['CLOUDSTACK_SECRET_KEY']
23+
24+
cloudstack.zone_name = ENV['ZONE_NAME']
25+
cloudstack.network_name = ENV['NETWORK_NAME']
26+
cloudstack.service_offering_name = ENV['SERVICE_OFFERING_NAME']
27+
28+
29+
cloudstack.expunge_on_destroy = ENV['CS_EXPUNGE'] == "true"
30+
cloudstack.network_type = "Ignored"
31+
cloudstack.ssh_key = ENV['SSH_KEY'] unless ENV['SSH_KEY'].nil?
32+
cloudstack.ssh_user = ENV['SSH_USER'] unless ENV['SSH_USER'].nil?
33+
34+
cloudstack.security_groups = [{
35+
:name => "Awesome_security_group1",
36+
:description => "Created from the Vagrantfile",
37+
:rules => [{:type => "ingress", :protocol => "TCP", :startport => 23, :endport => 23, :cidrlist => "0.0.0.0/0"}]
38+
},
39+
{
40+
:name => "Awesome_security_group2",
41+
:description => "Created from the Vagrantfile",
42+
:rules => [{:type => "ingress", :protocol => "TCP", :startport => 22, :endport => 22, :cidrlist => "0.0.0.0/0"}]
43+
}]
44+
end
45+
end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
describe 'Basic Network' do
2+
it 'starts Linux VM with security groups' do
3+
expect(`vagrant up`).to include(
4+
'Security Group Awesome_security_group1 created with ID',
5+
'Security Group Awesome_security_group2 created with ID',
6+
'Security Group: Awesome_security_group1 (',
7+
'Security Group: Awesome_security_group2 (',
8+
'Network name or id will be ignored',
9+
'Machine is booted and ready for use!'
10+
)
11+
expect($?.exitstatus).to eq(0)
12+
end
13+
it 'destroys Linux with security groups' do
14+
expect(`vagrant destroy --force`).to include(
15+
'Terminating the instance...',
16+
'Deleted ingress rules',
17+
'Deleted egress rules'
18+
)
19+
expect($?.exitstatus).to eq(0)
20+
end
21+
end

0 commit comments

Comments
 (0)