File tree Expand file tree Collapse file tree
lib/puppet/parser/functions
unit/puppet/parser/functions Expand file tree Collapse file tree Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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' )
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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
4645class { 'nova::compute' :
You can’t perform that action at this time.
0 commit comments