Skip to content

Commit

Permalink
Merge pull request #1571 from jrha/hostsfile_ipv6
Browse files Browse the repository at this point in the history
ncm-hostsfile: Test IPv6 and dual stack localhosts
  • Loading branch information
stdweird authored Jul 27, 2023
2 parents fcd3abc + 17540f6 commit 64deaed
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 11 deletions.
33 changes: 33 additions & 0 deletions ncm-hostsfile/src/main/pan/components/hostsfile/config-common.pan
Original file line number Diff line number Diff line change
@@ -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',
),
);
Original file line number Diff line number Diff line change
@@ -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");
11 changes: 2 additions & 9 deletions ncm-hostsfile/src/main/pan/components/hostsfile/config.pan
Original file line number Diff line number Diff line change
Expand Up @@ -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';
25 changes: 23 additions & 2 deletions ncm-hostsfile/src/test/perl/configure.t
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = '';
Expand Down
16 changes: 16 additions & 0 deletions ncm-hostsfile/src/test/resources/dual_stack_localhost.pan
Original file line number Diff line number Diff line change
@@ -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);
11 changes: 11 additions & 0 deletions ncm-hostsfile/src/test/resources/ipv6.pan
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 64deaed

Please sign in to comment.