From c5dd250bfaa4e41f85e694c3e695e4a1c23aced1 Mon Sep 17 00:00:00 2001 From: Jeremy Miller Date: Sat, 15 Sep 2018 17:50:56 -0500 Subject: [PATCH 1/2] add fixed ipv4 --- lib/kitchen/driver/openstack.rb | 13 ++++++- spec/kitchen/driver/openstack_spec.rb | 54 ++++++++++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/lib/kitchen/driver/openstack.rb b/lib/kitchen/driver/openstack.rb index aa2c737c..80aeb4d1 100755 --- a/lib/kitchen/driver/openstack.rb +++ b/lib/kitchen/driver/openstack.rb @@ -61,6 +61,7 @@ class Openstack < Kitchen::Driver::Base default_config :read_timeout, 60 default_config :write_timeout, 60 default_config :metadata, nil + default_config :fixed_ip_v4, nil # Set the proper server name in the config def config_server_name @@ -179,12 +180,20 @@ def create_server if config[:network_id] networks = [].concat([config[:network_id]]) server_def[:nics] = networks.flatten.map do |net_id| - { "net_id" => net_id } + if config[:fixed_ip_v4] + { "net_id" => net_id, :v4_fixed_ip => config[:fixed_ip_v4] } + else + { "net_id" => net_id } + end end elsif config[:network_ref] networks = [].concat([config[:network_ref]]) server_def[:nics] = networks.flatten.map do |net| - { "net_id" => find_network(net).id } + if config[:fixed_ip_v4] + { "net_id" => find_network(net).id, :v4_fixed_ip => config[:fixed_ip_v4] } + else + { "net_id" => find_network(net).id } + end end end diff --git a/spec/kitchen/driver/openstack_spec.rb b/spec/kitchen/driver/openstack_spec.rb index 11127bfa..140119f2 100755 --- a/spec/kitchen/driver/openstack_spec.rb +++ b/spec/kitchen/driver/openstack_spec.rb @@ -658,7 +658,7 @@ end end - context "network specifies network_id" do + context "network specifies network_id no fixed ipv4" do let(:config) do { server_name: "hello", @@ -681,6 +681,30 @@ end end + context "network specifies network_id with fixed ipv4" do + let(:config) do + { + server_name: "hello", + image_ref: "111", + flavor_ref: "1", + network_id: "0922b7aa-0a2f-4e68-8ff7-2886c4fc472d", + fixed_ip_v4: "192.168.1.100", + } + end + + it "exact id match" do + networks = [ + { "net_id" => "0922b7aa-0a2f-4e68-8ff7-2886c4fc472d", :v4_fixed_ip => "192.168.1.100" }, + ] + expect(servers).to receive(:create).with(name: "hello", + image_ref: "111", + flavor_ref: "1", + availability_zone: nil, + nics: networks) + driver.send(:create_server) + end + end + context "network_id and network_ref specified" do let(:config) do { @@ -723,7 +747,7 @@ end end - context "network specifies name" do + context "network specifies name and no fixed ipv4" do let(:config) do { server_name: "hello", @@ -748,6 +772,32 @@ end end + context "network specifies name and fixed ipv4" do + let(:config) do + { + server_name: "hello", + image_ref: "111", + flavor_ref: "1", + network_ref: "vlan1", + fixed_ip_v4: "192.168.1.100", + } + end + + it "exact id match" do + networks = [ + { "net_id" => "1", :v4_fixed_ip => "192.168.1.100" }, + ] + expect(servers).to receive(:create).with( + name: "hello", + image_ref: "111", + flavor_ref: "1", + availability_zone: nil, + nics: networks + ) + driver.send(:create_server) + end + end + context "multiple networks specifies id" do let(:config) do { From c1f8d1cd996a3d4c17c4d583f6ad933d74a6e7d7 Mon Sep 17 00:00:00 2001 From: Jeremy Miller Date: Sat, 15 Sep 2018 17:58:55 -0500 Subject: [PATCH 2/2] updated readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index e47d0ed1..f8efdb0c 100644 --- a/README.md +++ b/README.md @@ -341,6 +341,10 @@ assuming that test network is configured as private. If true use IPv6 addresses to for SSH connections. If false, the default, use IPv4 addresses for SSH connections. +### fixed_ip_v4 + +You can use this to set a fixed IPv4 IP address for your instance. + ### network\_ref The `network_ref` option can be specified as an exact id, an exact name,