diff --git a/lib/chef/knife/openstack_server_create.rb b/lib/chef/knife/openstack_server_create.rb index 48f89ef4..3b6085a2 100644 --- a/lib/chef/knife/openstack_server_create.rb +++ b/lib/chef/knife/openstack_server_create.rb @@ -129,8 +129,10 @@ def before_bootstrap # Use SSH password either specified from command line or from openstack server instance config[:ssh_password] = locate_config_value(:ssh_password) || server.password unless config[:openstack_ssh_key_id] - # private_network means bootstrap_network = 'private' - config[:bootstrap_network] = 'private' if config[:private_network] + # The bootstrap network is always initialised to 'public' when a network name isn't specified. Therefore, + # only set the bootstrap network to 'private' if still initialised to public and nothing was specified for + # the private network name. + config[:bootstrap_network] = 'private' if (config[:private_network] && config[:bootstrap_network] == 'public') # Which IP address to bootstrap unless config[:network] # --no-network diff --git a/spec/unit/openstack_server_create_spec.rb b/spec/unit/openstack_server_create_spec.rb index 627ec27b..e44c9c01 100644 --- a/spec/unit/openstack_server_create_spec.rb +++ b/spec/unit/openstack_server_create_spec.rb @@ -300,6 +300,21 @@ @instance.before_bootstrap expect(@instance.config[:ssh_password]).to be == server_password end + + it "configures the default private bootstrap network to use 'private'" do + allow(@instance.server).to receive(:addresses).and_return({"private"=>[{"version"=>4, "addr"=>"127.0.0.1"}]}) + @instance.config[:private_network] = true + @instance.before_bootstrap + expect(@instance.config[:bootstrap_network]).to be == 'private' + end + + it "configures the bootstrap to use alternate private network" do + allow(@instance.server).to receive(:addresses).and_return({"secure"=>[{"version"=>4, "addr"=>"127.0.0.1"}]}) + @instance.config[:bootstrap_network] = 'secure' + @instance.config[:private_network] = true + @instance.before_bootstrap + expect(@instance.config[:bootstrap_network]).to be == 'secure' + end end describe "#post_connection_validations" do