diff --git a/ncm-hostsfile/src/main/pan/components/hostsfile/config-common.pan b/ncm-hostsfile/src/main/pan/components/hostsfile/config-common.pan new file mode 100644 index 0000000000..842a7923b8 --- /dev/null +++ b/ncm-hostsfile/src/main/pan/components/hostsfile/config-common.pan @@ -0,0 +1,33 @@ +# ${license-info} +# ${developer-info} +# ${author-info} +# ${build-info} + +unique template components/${project.artifactId}/config-common; + +include 'components/${project.artifactId}/schema'; + +# Set prefix to root of component configuration. +prefix '/software/components/${project.artifactId}'; + +'version' = '${no-snapshot-version}'; +'active' ?= false; +'dispatch' ?= false; + +# Provide variables which can be used to provide dual stack entries for localhost. +# Specifying aliases for both stacks allows localhost to resolve for both protocols +# while still avoiding duplicate entries. + +final variable HOSTSFILE_LOCALHOST4 = dict( + 'localhost', dict( + 'ipaddr', '127.0.0.1', + 'aliases', 'localhost.localdomain localhost4 localhost4.localdomain4', + ), +); + +final variable HOSTSFILE_LOCALHOST6 = dict( + 'localhost6', dict( + 'ipaddr', '::1', + 'aliases', 'localhost localhost.localdomain localhost6.localdomain6', + ), +); diff --git a/ncm-hostsfile/src/main/pan/components/hostsfile/config-rpm.pan b/ncm-hostsfile/src/main/pan/components/hostsfile/config-rpm.pan new file mode 100644 index 0000000000..ee863fee78 --- /dev/null +++ b/ncm-hostsfile/src/main/pan/components/hostsfile/config-rpm.pan @@ -0,0 +1,8 @@ +# ${license-info} +# ${developer-info} +# ${author-info} +# ${build-info} + +unique template components/${project.artifactId}/config-rpm; + +"/software/packages" = pkg_repl("ncm-${project.artifactId}", "${no-snapshot-version}-${rpm.release}", "noarch"); diff --git a/ncm-hostsfile/src/main/pan/components/hostsfile/config.pan b/ncm-hostsfile/src/main/pan/components/hostsfile/config.pan index 7c948ae8ae..15da84308c 100644 --- a/ncm-hostsfile/src/main/pan/components/hostsfile/config.pan +++ b/ncm-hostsfile/src/main/pan/components/hostsfile/config.pan @@ -7,12 +7,5 @@ unique template components/${project.artifactId}/config; include 'components/${project.artifactId}/schema'; -# Package to install -"/software/packages" = pkg_repl("ncm-${project.artifactId}", "${no-snapshot-version}-${rpm.release}", "noarch"); - -# Set prefix to root of component configuration. -prefix '/software/components/${project.artifactId}'; - -'version' = '${no-snapshot-version}'; -'active' ?= false; -'dispatch' ?= false; +include 'components/${project.artifactId}/config-common'; +include 'components/${project.artifactId}/config-rpm'; diff --git a/ncm-hostsfile/src/test/perl/configure.t b/ncm-hostsfile/src/test/perl/configure.t index cabf74855b..dfe1c38280 100644 --- a/ncm-hostsfile/src/test/perl/configure.t +++ b/ncm-hostsfile/src/test/perl/configure.t @@ -3,9 +3,9 @@ use strict; use warnings; use Readonly; -use Test::More tests => 5; +use Test::More tests => 9; use Test::NoWarnings; -use Test::Quattor qw(ipv4 ms_localhost); +use Test::Quattor qw(ipv4 ipv6 dual_stack_localhost ms_localhost); use NCM::Component::hostsfile; use Test::MockModule; @@ -33,6 +33,18 @@ Readonly my $HOSTSFILE_EXPECTED_IPV4 => 192.168.42.3 priv_3 # NCM Private Three '; +Readonly my $HOSTSFILE_EXPECTED_IPV6 => +'# Generated by Quattor component hostsfile 2.0.0 +127.0.0.1 localhost.localdomain localhost +::1 localhost6 localhost localhost.localdomain localhost6.localdomain6 # NCM +'; + +Readonly my $HOSTSFILE_EXPECTED_DUALSTACK_LOCALHOST => +'# Generated by Quattor component hostsfile 2.0.0 +127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 # NCM +::1 localhost6 localhost localhost.localdomain localhost6.localdomain6 # NCM +'; + Readonly my $HOSTSFILE_EXPECTED_MS_LOCALHOST => '# Generated by Quattor component hostsfile 2.0.0 127.0.0.1 localhost # NCM @@ -61,6 +73,15 @@ $file_contents = ''; is($cmp->Configure($config), 1, 'Component runs correctly with profile (ipv4)'); is($file_contents, $HOSTSFILE_EXPECTED_IPV4, 'Hostsfile updated with correct contents (ipv4)'); +$config = get_config_for_profile('ipv6'); +$file_contents = ''; +is($cmp->Configure($config), 1, 'Component runs correctly with profile (ipv6)'); +is($file_contents, $HOSTSFILE_EXPECTED_IPV6, 'Hostsfile updated with correct contents (ipv6)'); + +$config = get_config_for_profile('dual_stack_localhost'); +$file_contents = ''; +is($cmp->Configure($config), 1, 'Component runs correctly with profile (dual_stack_localhost)'); +is($file_contents, $HOSTSFILE_EXPECTED_DUALSTACK_LOCALHOST, 'Hostsfile updated with correct contents (dual_stack_localhost)'); $config = get_config_for_profile('ms_localhost'); $file_contents = ''; diff --git a/ncm-hostsfile/src/test/resources/dual_stack_localhost.pan b/ncm-hostsfile/src/test/resources/dual_stack_localhost.pan new file mode 100644 index 0000000000..69bdae0c42 --- /dev/null +++ b/ncm-hostsfile/src/test/resources/dual_stack_localhost.pan @@ -0,0 +1,16 @@ +object template dual_stack_localhost; + +include 'components/hostsfile/config-common'; + +prefix '/software/components/hostsfile'; + +'active' = true; +'file' = '/tmp/hosts.local'; +'takeover' = true; +'entries' ?= dict(); + +# IPv4 +'entries' = merge(SELF, HOSTSFILE_LOCALHOST4); + +# IPv6 +'entries' = merge(SELF, HOSTSFILE_LOCALHOST6); diff --git a/ncm-hostsfile/src/test/resources/ipv6.pan b/ncm-hostsfile/src/test/resources/ipv6.pan new file mode 100644 index 0000000000..39ebfc9882 --- /dev/null +++ b/ncm-hostsfile/src/test/resources/ipv6.pan @@ -0,0 +1,11 @@ +object template ipv6; + +include 'components/hostsfile/config-common'; + +prefix '/software/components/hostsfile'; + +'active' = true; +'file' = '/tmp/hosts.local'; +'entries' ?= dict(); + +'entries' = merge(SELF, HOSTSFILE_LOCALHOST6);