Skip to content

Commit

Permalink
Add support for vagrant-cloudstack provider
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelaferreira committed Sep 21, 2015
1 parent cf89394 commit 2058bda
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 1 deletion.
174 changes: 174 additions & 0 deletions spec/kitchen/driver/vagrant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,180 @@ def run_command(_cmd, options = {})
RUBY
end
end

context "for cloudstack provider" do

before { config[:provider] = "cloudstack" }

it "adds a line for each element in :customize" do
config[:customize] = {
:a_key => "some value",
:something => "else"
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
c.vm.provider :cloudstack do |p|
p.a_key = "some value"
p.something = "else"
end
RUBY
end

it "builds an array of hashes for firewall rules in :customize" do
config[:customize] = {
:firewall_rules => [
{
:ipaddress => "A.A.A.A",
:cidrlist => "B.B.B.B/24",
:protocol => "tcp",
:startport => 2222,
:endport => 2222
},
{
:ipaddress => "C.C.C.C",
:cidrlist => "D.D.D.D/32",
:protocol => "tcp",
:startport => 80,
:endport => 81
}
]
}
cmd

expectation = <<-RUBY.gsub(/^ {8}/, "").gsub(/,\n /, ",").chomp
c.vm.provider :cloudstack do |p|
p.firewall_rules = [{:ipaddress=>"A.A.A.A", :cidrlist=>"B.B.B.B/24",
:protocol=>"tcp", :startport=>2222,
:endport=>2222}, {:ipaddress=>"C.C.C.C", :cidrlist=>"D.D.D.D/32",
:protocol=>"tcp", :startport=>80, :endport=>81}]
end
RUBY

expect(vagrantfile).to match(regexify(expectation))
end

it "builds an array for security group ids in :customize" do
config[:customize] = {
:security_group_ids => ["aaaa-bbbb-cccc-dddd",
"1111-2222-3333-4444"]
}
cmd

expectation = <<-RUBY.gsub(/^ {8}/, "").gsub(/,\n /, ",").chomp
c.vm.provider :cloudstack do |p|
p.security_group_ids = ["aaaa-bbbb-cccc-dddd",
"1111-2222-3333-4444"]
end
RUBY

expect(vagrantfile).to match(regexify(expectation))
end

it "builds an array for security group names in :customize" do
config[:customize] = {
:security_group_names => %w[min_fantastiska_security_group
another_security_group]
}
cmd

expectation = <<-RUBY.gsub(/^ {8}/, "").gsub(/,\n /, ",").chomp
c.vm.provider :cloudstack do |p|
p.security_group_names = ["min_fantastiska_security_group",
"another_security_group"]
end
RUBY

expect(vagrantfile).to match(regexify(expectation))
end

it "builds an array of hashes for security groups in :customize" do
config[:customize] = {
:security_groups => [
{
:name => "Awesome_security_group",
:description => "Created from the Vagrantfile",
:rules => [
{
:type => "ingress",
:protocol => "TCP",
:startport => 22,
:endport => 22,
:cidrlist => "0.0.0.0/0"
},
{
:type => "egress",
:protocol => "TCP",
:startport => 81,
:endport => 82,
:cidrlist => "1.2.3.4/24"
}
]
}
]
}
cmd

expectation = <<-RUBY.gsub(/^ {8}/, "").gsub(/,\n /, ",").chomp
c.vm.provider :cloudstack do |p|
p.security_groups = [{:name=>"Awesome_security_group",
:description=>"Created from the Vagrantfile",
:rules=>[{:type=>"ingress", :protocol=>"TCP", :startport=>22,
:endport=>22, :cidrlist=>"0.0.0.0/0"}, {:type=>"egress",
:protocol=>"TCP", :startport=>81, :endport=>82,
:cidrlist=>"1.2.3.4/24"}]}]
end
RUBY

expect(vagrantfile).to match(regexify(expectation))
end

it "builds an array of hashes for static nat in :customize" do
config[:customize] = {
:static_nat => [{ :idaddress => "A.A.A.A" }]
}
cmd

expect(vagrantfile).to match(regexify(<<-RUBY.gsub(/^ {8}/, "").chomp))
c.vm.provider :cloudstack do |p|
p.static_nat = [{:idaddress=>"A.A.A.A"}]
end
RUBY
end

it "builds an array of hashes for port forwarding rules in :customize" do
config[:customize] = {
:port_forwarding_rules => [
{
:ipaddress => "X.X.X.X",
:protocol => "tcp",
:publicport => 22,
:privateport => 22,
:openfirewall => false
},
{
:ipaddress => "X.X.X.X",
:protocol => "tcp",
:publicport => 80,
:privateport => 80,
:openfirewall => false
}
]
}
cmd

expectation = <<-RUBY.gsub(/^ {8}/, "").gsub(/,\n /, ",").chomp
c.vm.provider :cloudstack do |p|
p.port_forwarding_rules = [{:ipaddress=>"X.X.X.X",
:protocol=>"tcp", :publicport=>22, :privateport=>22,
:openfirewall=>false}, {:ipaddress=>"X.X.X.X", :protocol=>"tcp",
:publicport=>80, :privateport=>80, :openfirewall=>false}]
end
RUBY

expect(vagrantfile).to match(regexify(expectation))
end
end
end

def debug_lines
Expand Down
2 changes: 1 addition & 1 deletion templates/Vagrantfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Vagrant.configure("2") do |c|
<% else %>
p.vmx["<%= key %>"] = "<%= value %>"
<% end %>
<% when "openstack" %>
<% when "openstack", "cloudstack" %>
<% if value.is_a? String %>
p.<%= key %> = "<%= value%>"
<% else %>
Expand Down

0 comments on commit 2058bda

Please sign in to comment.