diff --git a/packstack/plugins/prescript_000.py b/packstack/plugins/prescript_000.py index 0e0a6268b..0f5a29de8 100644 --- a/packstack/plugins/prescript_000.py +++ b/packstack/plugins/prescript_000.py @@ -698,7 +698,8 @@ def discover(config, messages): # be used for that too). details = {} release_regexp = re.compile(r'^(?P.*) release (?P[\d\.]*)') - for host in filtered_hosts(config): + config['HOST_LIST'] = list(filtered_hosts(config)) + for host in config['HOST_LIST']: details.setdefault(host, {}) server = utils.ScriptRunner(host) # discover OS and release diff --git a/packstack/puppet/modules/packstack/Gemfile b/packstack/puppet/modules/packstack/Gemfile new file mode 100644 index 000000000..5c7ec5e83 --- /dev/null +++ b/packstack/puppet/modules/packstack/Gemfile @@ -0,0 +1,14 @@ +source 'https://rubygems.org' + +group :development, :test do + gem 'puppetlabs_spec_helper', :require => false + gem 'puppet-lint', '~> 0.3.2' + gem 'rake', '10.1.1' + gem 'rspec', '< 2.99' +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end diff --git a/packstack/puppet/modules/packstack/Rakefile b/packstack/puppet/modules/packstack/Rakefile new file mode 100644 index 000000000..4c2b2ed07 --- /dev/null +++ b/packstack/puppet/modules/packstack/Rakefile @@ -0,0 +1,6 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'puppet-lint/tasks/puppet-lint' + +PuppetLint.configuration.fail_on_warnings = true +PuppetLint.configuration.send('disable_80chars') +PuppetLint.configuration.send('disable_class_parameter_defaults') diff --git a/packstack/puppet/modules/packstack/lib/puppet/parser/functions/choose_my_ip.rb b/packstack/puppet/modules/packstack/lib/puppet/parser/functions/choose_my_ip.rb new file mode 100644 index 000000000..20eb5b0ad --- /dev/null +++ b/packstack/puppet/modules/packstack/lib/puppet/parser/functions/choose_my_ip.rb @@ -0,0 +1,30 @@ + +# Function returns host's IP selected from list of IPs +module Puppet::Parser::Functions + newfunction(:choose_my_ip, :type => :rvalue) do |args| + + if args.size < 1 + raise( + Puppet::ParseError, + "choose_my_ip(): Wrong number of arguments given (#{args.size} for 1)" + ) + end + + host_list = args[0] + if not host_list.kind_of?(Array) + host_list = [host_list] + end + my_ips = lookupvar('interfaces').split(',').map do |interface| + interface.strip! + lookupvar("ipaddress_#{interface}") + end + + result = nil + host_list.each do |ip| + if my_ips.include? ip + result = ip + end + end + result + end +end diff --git a/packstack/puppet/modules/packstack/spec/spec_helper.rb b/packstack/puppet/modules/packstack/spec/spec_helper.rb new file mode 100644 index 000000000..7cbc76a1e --- /dev/null +++ b/packstack/puppet/modules/packstack/spec/spec_helper.rb @@ -0,0 +1,10 @@ +require 'puppetlabs_spec_helper/module_spec_helper' + +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) + +RSpec.configure do |c| + c.alias_it_should_behave_like_to :it_configures, 'configures' + c.alias_it_should_behave_like_to :it_raises, 'raises' + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') +end diff --git a/packstack/puppet/modules/packstack/spec/unit/puppet/parser/functions/choose_my_ip_spec.rb b/packstack/puppet/modules/packstack/spec/unit/puppet/parser/functions/choose_my_ip_spec.rb new file mode 100644 index 000000000..2283e509e --- /dev/null +++ b/packstack/puppet/modules/packstack/spec/unit/puppet/parser/functions/choose_my_ip_spec.rb @@ -0,0 +1,36 @@ + +require 'spec_helper' + +describe "choose_my_ip function" do + + let :scope do + PuppetlabsSpec::PuppetInternals.scope + end + + let :subject do + function_name = Puppet::Parser::Functions.function(:choose_my_ip) + scope.method(function_name) + end + + context "basic unit tests" do + before :each do + scope.stubs(:lookupvar).with('interfaces').returns('eth0,eth1,lo') + scope.stubs(:lookupvar).with('ipaddress_eth1').returns('1.2.3.4') + scope.stubs(:lookupvar).with('ipaddress_eth0').returns('2.3.4.5') + scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1') + end + + it 'should select correct ip' do + result = subject.call([['1.1.1.1', '2.3.4.5', '3.3.3.3']]) + result.should(eq('2.3.4.5')) + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_choose_my_ip([]) }.should( + raise_error(Puppet::ParseError) + ) + end + + end + +end diff --git a/packstack/puppet/templates/nova_compute.pp b/packstack/puppet/templates/nova_compute.pp index 6cc4b7941..1d71990bd 100644 --- a/packstack/puppet/templates/nova_compute.pp +++ b/packstack/puppet/templates/nova_compute.pp @@ -35,12 +35,11 @@ $vncproxy_proto = $config_horizon_ssl ? { default => 'http', } -if ($::fqdn != '' and $::fqdn != 'localhost') { - $vncproxy_server = $::fqdn +if ($::fqdn == '' or $::fqdn =~ /localhost/) { + # For cases where FQDNs have not been correctly set + $vncproxy_server = choose_my_ip(hiera('HOST_LIST')) } else { - # Multihost does not work without proper FQDN setup, so we use controller IP, - # because this case can come up only in usecase, which is all-in-one - $vncproxy_server = hiera('CONFIG_CONTROLLER_HOST') + $vncproxy_server = $::fqdn } class { 'nova::compute':