Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Travis test fixes #234

Merged
merged 3 commits into from
Dec 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 28 additions & 35 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,23 @@ Config.prototype.clearHostnameCache = function clearHostnameCache() {
this.getHostnameSafe = getHostnameSafe
}

Config.prototype.getIPAddresses = function getIPAddresses() {
var addresses = {}
var interfaces = os.networkInterfaces()

for (var interfaceKey in interfaces) {
if (interfaceKey.match(/^lo/)) continue

var interfaceDescriptions = interfaces[interfaceKey]
for (var i = 0; i < interfaceDescriptions.length; i++) {
var description = interfaceDescriptions[i]
var family = description.family.toLowerCase()
addresses[family] = description.address
}
}
return addresses
}

function getHostnameSafe() {
var _hostname
this.getHostnameSafe = function getCachedHostname() {
Expand All @@ -787,45 +804,21 @@ function getHostnameSafe() {
_hostname = os.hostname()
return _hostname
} catch (e) {
var interfaces = os.networkInterfaces()
var ipv4Address
var ipv6Address

for (var interfaceKey in interfaces) {
if (interfaceKey.match(/^lo/)) continue

var interfaceDescriptions = interfaces[interfaceKey]
for (var i = 0; i < interfaceDescriptions.length; i++) {
var description = interfaceDescriptions[i]
var family = description.family.toLowerCase()

if (family === 'ipv6') {
ipv6Address = description.address
if (this.process_host.ipv_preference === '6') {
_hostname = ipv6Address
return _hostname
}
} else if (family === 'ipv4') {
ipv4Address = description.address
if (this.process_host.ipv_preference !== '6') {
_hostname = ipv4Address
return _hostname
}
}
}
}
if (ipv4Address) {
var addresses = this.getIPAddresses()

if (this.process_host.ipv_preference === '6' && addresses.ipv6) {
_hostname = addresses.ipv6
} else if (addresses.ipv4) {
logger.info('Defaulting to ipv4 address for host name')
_hostname = ipv4Address
return _hostname
} else if (ipv6Address) {
_hostname = addresses.ipv4
} else if (addresses.ipv6) {
logger.info('Defaulting to ipv6 address for host name')
_hostname = ipv6Address
return _hostname
_hostname = addresses.ipv6
} else {
logger.info('No hostname, ipv4, or ipv6 address found for machine')
_hostname = 'UNKNOWN_BOX'
}

logger.info('No hostname, ipv4, or ipv6 address found for machine')
_hostname = 'UNKNOWN_BOX'
return _hostname
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/integration/core/dns.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,15 @@ test('reverse', function(t) {
helper.runInTransaction(agent, function() {
dns.reverse('127.0.0.1', function(err, names) {
t.notOk(err, 'should not error')
t.deepEqual(names, [])
if (process.env.TRAVIS && names.length > 0) {
t.deepEqual(names, [
"nettuno",
"travis",
"vagrant"
])
} else {
t.deepEqual(names, [])
}
verifySegments(t, agent, 'dns.reverse')
})
})
Expand Down
26 changes: 20 additions & 6 deletions test/unit/facts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ describe('display_host', function () {
done()
})
})
it("should be ipv4 when ipv_preference === '4' and os.hostname() not available",
it(
"should be ipv4 when ipv_preference === '4' and os.hostname() not available",
function(done) {
agent.config.process_host.ipv_preference = '4'
var ipv4Pattern = /((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])/
Expand All @@ -306,18 +307,26 @@ describe('display_host', function () {
expect(factsed.display_host).match(ipv4Pattern)
done()
})
})
it("should be ipv6 when ipv_preference === '6' and os.hostname() not available",
}
)
it(
"should be ipv6 when ipv_preference === '6' and os.hostname() not available",
function(done) {
if (!agent.config.getIPAddresses().ipv6) {
console.log('this machine does not have an ipv6 address, skipping')
return done()
}
agent.config.process_host.ipv_preference = '6'
var ipv6Pattern = /(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))/

facts(agent, function getFacts(factsed) {
expect(factsed.display_host).match(ipv6Pattern)
done()
})
})
it("should be ipv4 when invalid ipv_preference and os.hostname() not available",
}
)
it(
"should be ipv4 when invalid ipv_preference and os.hostname() not available",
function badIpPref(done) {
agent.config.process_host.ipv_preference = '9'
var ipv4Pattern = /((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])/
Expand All @@ -326,10 +335,15 @@ describe('display_host', function () {
expect(factsed.display_host).match(ipv4Pattern)
done()
})
})
}
)
describe("When os.networkInterfaces()", function netInterface() {
it("returns no ipv4, hostname should be ipv6 if possible",
function noip4(done) {
if (!agent.config.getIPAddresses().ipv6) {
console.log('this machine does not have an ipv6 address, skipping')
return done()
}
var mockedNI = {lo: [], en0: [{
address: 'fe80::a00:27ff:fe4e:66a1',
netmask: 'ffff:ffff:ffff:ffff::',
Expand Down
4 changes: 2 additions & 2 deletions test/unit/sampler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe("environmental sampler", function () {

var stats = agent.metrics.getOrCreateMetric('CPU/User Time')
expect(stats.callCount).equal(1)
expect(stats.total).equal(8)
expect(stats.total).equal(numCpus)
}
})

Expand All @@ -83,7 +83,7 @@ describe("environmental sampler", function () {

var stats = agent.metrics.getOrCreateMetric('CPU/System Time')
expect(stats.callCount).equal(1)
expect(stats.total).equal(8)
expect(stats.total).equal(numCpus)
}
})

Expand Down