brooklyn-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdowner <...@git.apache.org>
Subject [GitHub] incubator-brooklyn pull request: Fix: no-hostname, and cluster.rep...
Date Fri, 27 Feb 2015 10:58:04 GMT
Github user rdowner commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/525#discussion_r25499681
  
    --- Diff: core/src/test/java/brooklyn/util/ssh/BashCommandsIntegrationTest.java ---
    @@ -361,6 +363,99 @@ public void testWaitForPortFreeWhenFreedAfterStart() throws Exception
{
                 serverSocket.close();
             }
         }
    +
    +    
    +    // Disabled by default because of risk of overriding /etc/hosts in really bad way
if doesn't work properly!
    +    // As a manual visual inspection test, consider first manually creating /etc/hostsname
and /etc/sysconfig/network
    +    // so that it looks like debian+ubuntu / CentOS/RHEL.
    +    @Test(groups={"Integration"}, enabled=false)
    +    public void testSetHostnameUnqualified() throws Exception {
    +        runSetHostname("br-"+Identifiers.makeRandomId(8).toLowerCase(), null, false);
    +    }
    +
    +    @Test(groups={"Integration"}, enabled=false)
    +    public void testSetHostnameQualified() throws Exception {
    +        runSetHostname("br-"+Identifiers.makeRandomId(8).toLowerCase()+".brooklyn.incubator.apache.org",
null, false);
    +    }
    +
    +    @Test(groups={"Integration"}, enabled=false)
    +    public void testSetHostnameNullDomain() throws Exception {
    +        runSetHostname("br-"+Identifiers.makeRandomId(8).toLowerCase(), null, true);
    +    }
    +
    +    @Test(groups={"Integration"}, enabled=false)
    +    public void testSetHostnameNonNullDomain() throws Exception {
    +        runSetHostname("br-"+Identifiers.makeRandomId(8).toLowerCase(), "brooklyn.incubator.apache.org",
true);
    +    }
    +
    +    protected void runSetHostname(String newHostname, String newDomain, boolean includeDomain)
throws Exception {
    +        String fqdn = (includeDomain && Strings.isNonBlank(newDomain)) ? newHostname
+ "." + newDomain : newHostname;
    +        
    +        LocalManagementContextForTests mgmt = new LocalManagementContextForTests();
    +        SshMachineLocation loc = mgmt.getLocationManager().createLocation(LocalhostMachineProvisioningLocation.spec()).obtain();
    +
    +        execRequiringZeroAndReturningStdout(loc, sudo("cp /etc/hosts /etc/hosts-orig-testSetHostname")).get();
    +        execRequiringZeroAndReturningStdout(loc, BashCommands.ifFileExistsElse0("/etc/hostname",
sudo("cp /etc/hostname /etc/hostname-orig-testSetHostname"))).get();
    +        execRequiringZeroAndReturningStdout(loc, BashCommands.ifFileExistsElse0("/etc/sysconfig/network",
sudo("cp /etc/sysconfig/network /etc/sysconfig/network-orig-testSetHostname"))).get();
    +        
    +        String origHostname = getHostname(loc);
    +        assertTrue(Strings.isNonBlank(origHostname));
    +        
    +        try {
    +            List<String> cmd = (includeDomain) ? BashCommands.setHostname(newHostname,
newDomain) : BashCommands.setHostname(newHostname);
    +            execRequiringZeroAndReturningStdout(loc, cmd).get();
    +            
    +            assertEquals(getHostname(loc), fqdn);
    +            
    +            String result = execRequiringZeroAndReturningStdout(loc, "grep -n "+fqdn+"
/etc/hosts").get();
    +            assertTrue(result.contains("localhost"), "line="+result);
    +            log.info("result="+result);
    --- End diff --
    
    A good test to do would be:
    
    * Executing `hostname` returns the hostname without the domain name
    * Executing `hostname --fqdn` returns the hostname *with* the domain name
    * Executing `ping -c1 -n -q ${ hostname }` return success (rc=0)
    * Executing `ping -c1 -n -q ${ hostname --fqdn }` return success (rc=0)
    
    The last two are probably the most important - it's these kinds of failures that would
also cause an entity to fail to bind.
    
    Unfortunately OSX has slightly different parameters - it's `hostname -s` and `hostname
-f` respectively.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message