Skip to content

Commit 37a4004

Browse files
committed
Bulletproof novncproxy setting
This patch implements setting correct IP address in case FQDNs have not been correctly set and somebody is trying to deploy multihost OpenStack. Change-Id: Ib24ea4f5cbcb6a44f5d9d8d0a699e163c3b65c25 Fixes: rhbz#1172241
1 parent ed13378 commit 37a4004

7 files changed

Lines changed: 102 additions & 6 deletions

File tree

packstack/plugins/prescript_000.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,8 @@ def discover(config, messages):
698698
# be used for that too).
699699
details = {}
700700
release_regexp = re.compile(r'^(?P<OS>.*) release (?P<release>[\d\.]*)')
701-
for host in filtered_hosts(config):
701+
config['HOST_LIST'] = list(filtered_hosts(config))
702+
for host in config['HOST_LIST']:
702703
details.setdefault(host, {})
703704
server = utils.ScriptRunner(host)
704705
# discover OS and release
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
source 'https://rubygems.org'
2+
3+
group :development, :test do
4+
gem 'puppetlabs_spec_helper', :require => false
5+
gem 'puppet-lint', '~> 0.3.2'
6+
gem 'rake', '10.1.1'
7+
gem 'rspec', '< 2.99'
8+
end
9+
10+
if puppetversion = ENV['PUPPET_GEM_VERSION']
11+
gem 'puppet', puppetversion, :require => false
12+
else
13+
gem 'puppet', :require => false
14+
end
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'puppetlabs_spec_helper/rake_tasks'
2+
require 'puppet-lint/tasks/puppet-lint'
3+
4+
PuppetLint.configuration.fail_on_warnings = true
5+
PuppetLint.configuration.send('disable_80chars')
6+
PuppetLint.configuration.send('disable_class_parameter_defaults')
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
# Function returns host's IP selected from list of IPs
3+
module Puppet::Parser::Functions
4+
newfunction(:choose_my_ip, :type => :rvalue) do |args|
5+
6+
if args.size < 1
7+
raise(
8+
Puppet::ParseError,
9+
"choose_my_ip(): Wrong number of arguments given (#{args.size} for 1)"
10+
)
11+
end
12+
13+
host_list = args[0]
14+
if not host_list.kind_of?(Array)
15+
host_list = [host_list]
16+
end
17+
my_ips = lookupvar('interfaces').split(',').map do |interface|
18+
interface.strip!
19+
lookupvar("ipaddress_#{interface}")
20+
end
21+
22+
result = nil
23+
host_list.each do |ip|
24+
if my_ips.include? ip
25+
result = ip
26+
end
27+
end
28+
result
29+
end
30+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require 'puppetlabs_spec_helper/module_spec_helper'
2+
3+
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
4+
5+
RSpec.configure do |c|
6+
c.alias_it_should_behave_like_to :it_configures, 'configures'
7+
c.alias_it_should_behave_like_to :it_raises, 'raises'
8+
c.module_path = File.join(fixture_path, 'modules')
9+
c.manifest_dir = File.join(fixture_path, 'manifests')
10+
end
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
require 'spec_helper'
3+
4+
describe "choose_my_ip function" do
5+
6+
let :scope do
7+
PuppetlabsSpec::PuppetInternals.scope
8+
end
9+
10+
let :subject do
11+
function_name = Puppet::Parser::Functions.function(:choose_my_ip)
12+
scope.method(function_name)
13+
end
14+
15+
context "basic unit tests" do
16+
before :each do
17+
scope.stubs(:lookupvar).with('interfaces').returns('eth0,eth1,lo')
18+
scope.stubs(:lookupvar).with('ipaddress_eth1').returns('1.2.3.4')
19+
scope.stubs(:lookupvar).with('ipaddress_eth0').returns('2.3.4.5')
20+
scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1')
21+
end
22+
23+
it 'should select correct ip' do
24+
result = subject.call([['1.1.1.1', '2.3.4.5', '3.3.3.3']])
25+
result.should(eq('2.3.4.5'))
26+
end
27+
28+
it "should raise a ParseError if there is less than 1 arguments" do
29+
lambda { scope.function_choose_my_ip([]) }.should(
30+
raise_error(Puppet::ParseError)
31+
)
32+
end
33+
34+
end
35+
36+
end

packstack/puppet/templates/nova_compute.pp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@
3535
default => 'http',
3636
}
3737

38-
if ($::fqdn != '' and $::fqdn != 'localhost') {
39-
$vncproxy_server = $::fqdn
38+
if ($::fqdn == '' or $::fqdn =~ /localhost/) {
39+
# For cases where FQDNs have not been correctly set
40+
$vncproxy_server = choose_my_ip(hiera('HOST_LIST'))
4041
} else {
41-
# Multihost does not work without proper FQDN setup, so we use controller IP,
42-
# because this case can come up only in usecase, which is all-in-one
43-
$vncproxy_server = hiera('CONFIG_CONTROLLER_HOST')
42+
$vncproxy_server = $::fqdn
4443
}
4544

4645
class { 'nova::compute':

0 commit comments

Comments
 (0)