Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id F0DC6108BE for ; Fri, 27 Feb 2015 10:58:25 +0000 (UTC) Received: (qmail 11183 invoked by uid 500); 27 Feb 2015 10:58:25 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 11145 invoked by uid 500); 27 Feb 2015 10:58:25 -0000 Mailing-List: contact dev-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list dev@brooklyn.incubator.apache.org Received: (qmail 11134 invoked by uid 99); 27 Feb 2015 10:58:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Feb 2015 10:58:25 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED,T_RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 27 Feb 2015 10:58:24 +0000 Received: (qmail 10800 invoked by uid 99); 27 Feb 2015 10:58:04 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 27 Feb 2015 10:58:04 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 14BF1E040E; Fri, 27 Feb 2015 10:58:04 +0000 (UTC) From: rdowner To: dev@brooklyn.incubator.apache.org Reply-To: dev@brooklyn.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-brooklyn pull request: Fix: no-hostname, and cluster.rep... Content-Type: text/plain Message-Id: <20150227105804.14BF1E040E@git1-us-west.apache.org> Date: Fri, 27 Feb 2015 10:58:04 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org 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 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. ---