Skip to content

Commit 92a8670

Browse files
authored
Add IPv6 support (#845)
* Introduce RQD_USE_IPV6_AS_HOSTNAME to get IPv6 address * Increase hostname length to 45 * Fix IPv4-mapped IPv6 ddress handling in getHostNameFromFQDN * Add tests for IPv6 address * Bump version to 0.5 for the database schema change
1 parent dff882c commit 92a8670

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

cuebot/src/main/java/com/imageworks/spcue/dao/postgres/HostDaoJdbc.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -658,6 +658,10 @@ private String getHostNameFromFQDN(String fqdn, Boolean useLongNames) {
658658
if (ipMatcher.matches()){
659659
hostName = fqdn;
660660
}
661+
else if (fqdn.contains(":")) {
662+
// looks like IPv6 address.
663+
hostName = fqdn;
664+
}
661665
else if (useLongNames) {
662666
hostName = fqdn;
663667
Pattern domainPattern = Pattern.compile(
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Increase the length of hostnames for IPv6 address.
2+
3+
ALTER TABLE "host" ALTER COLUMN "str_name" TYPE VARCHAR(45);
4+
ALTER TABLE "host_tag" ALTER COLUMN "str_tag" TYPE VARCHAR(45);

cuebot/src/test/java/com/imageworks/spcue/test/dao/postgres/HostDaoTests.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,45 @@ public void testInsertHostFQDN4() {
203203
assertEquals(TEST_HOST_NEW, hostDetail.name);
204204
}
205205

206+
@Test
207+
@Transactional
208+
@Rollback(true)
209+
public void testInsertHostIPv61() {
210+
String TEST_HOST_NEW = "::1";
211+
hostDao.insertRenderHost(buildRenderHost(TEST_HOST_NEW),
212+
hostManager.getDefaultAllocationDetail(),
213+
false);
214+
215+
HostEntity hostDetail = hostDao.findHostDetail(TEST_HOST_NEW);
216+
assertEquals(TEST_HOST_NEW, hostDetail.name);
217+
}
218+
219+
@Test
220+
@Transactional
221+
@Rollback(true)
222+
public void testInsertHostIPv62() {
223+
String TEST_HOST_NEW = "ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:ABCD";
224+
hostDao.insertRenderHost(buildRenderHost(TEST_HOST_NEW),
225+
hostManager.getDefaultAllocationDetail(),
226+
false);
227+
228+
HostEntity hostDetail = hostDao.findHostDetail(TEST_HOST_NEW);
229+
assertEquals(TEST_HOST_NEW, hostDetail.name);
230+
}
231+
232+
@Test
233+
@Transactional
234+
@Rollback(true)
235+
public void testInsertHostIPv63() {
236+
String TEST_HOST_NEW = "ABCD:ABCD:ABCD:ABCD:ABCD:ABCD:192.168.100.180";
237+
hostDao.insertRenderHost(buildRenderHost(TEST_HOST_NEW),
238+
hostManager.getDefaultAllocationDetail(),
239+
false);
240+
241+
HostEntity hostDetail = hostDao.findHostDetail(TEST_HOST_NEW);
242+
assertEquals(TEST_HOST_NEW, hostDetail.name);
243+
}
244+
206245
@Test
207246
@Transactional
208247
@Rollback(true)

rqd/rqd/rqconstants.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
RQD_RETRY_STARTUP_CONNECT_DELAY = 30
6767
RQD_RETRY_CRITICAL_REPORT_DELAY = 30
6868
RQD_USE_IP_AS_HOSTNAME = True
69+
RQD_USE_IPV6_AS_HOSTNAME = False
6970
RQD_BECOME_JOB_USER = True
7071
RQD_CREATE_USER_IF_NOT_EXISTS = True
7172
RQD_TAGS = ''
@@ -187,6 +188,8 @@
187188
LOAD_MODIFIER = config.getint(__section, "LOAD_MODIFIER")
188189
if config.has_option(__section, "RQD_USE_IP_AS_HOSTNAME"):
189190
RQD_USE_IP_AS_HOSTNAME = config.getboolean(__section, "RQD_USE_IP_AS_HOSTNAME")
191+
if config.has_option(__section, "RQD_USE_IPV6_AS_HOSTNAME"):
192+
RQD_USE_IPV6_AS_HOSTNAME = config.getboolean(__section, "RQD_USE_IPV6_AS_HOSTNAME")
190193
if config.has_option(__section, "RQD_BECOME_JOB_USER"):
191194
RQD_BECOME_JOB_USER = config.getboolean(__section, "RQD_BECOME_JOB_USER")
192195
if config.has_option(__section, "RQD_TAGS"):

rqd/rqd/rqutil.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,19 @@ def checkAndCreateUser(username):
143143

144144
def getHostIp():
145145
"""Returns the machine's local ip address"""
146-
return socket.gethostbyname(socket.gethostname())
146+
if rqd.rqconstants.RQD_USE_IPV6_AS_HOSTNAME:
147+
return socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET6)[0][4][0]
148+
else:
149+
return socket.gethostbyname(socket.gethostname())
147150

148151

149152
def getHostname():
150153
"""Returns the machine's fully qualified domain name"""
151154
try:
152155
if rqd.rqconstants.OVERRIDE_HOSTNAME:
153156
return rqd.rqconstants.OVERRIDE_HOSTNAME
154-
elif rqd.rqconstants.RQD_USE_IP_AS_HOSTNAME:
157+
elif rqd.rqconstants.RQD_USE_IP_AS_HOSTNAME or \
158+
rqd.rqconstants.RQD_USE_IPV6_AS_HOSTNAME:
155159
return getHostIp()
156160
else:
157161
return socket.gethostbyaddr(socket.gethostname())[0].split('.')[0]

0 commit comments

Comments
 (0)