Skip to content

Commit

Permalink
Merge branch 'improvement/ARSN-9-kmipDeepHealthcheck' into tmp/octopu…
Browse files Browse the repository at this point in the history
…s/w/8.1/improvement/ARSN-9-kmipDeepHealthcheck
  • Loading branch information
bert-e committed Aug 4, 2021
2 parents 8c7907f + 9aa8710 commit dc698f4
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
24 changes: 24 additions & 0 deletions lib/network/kmip/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,30 @@ class Client {
});
}

healthcheck(logger, cb) {
// the bucket does not have to exist, just passing a common bucket name here
this.createBucketKey('kmip-healthcheck-test-bucket', logger, (err, bucketKeyId) => {
if (err) {
logger.error('KMIP::healthcheck: failure to create a test bucket key', {
error: err,
});
return cb(err);
}
logger.debug('KMIP::healthcheck: success creating a test bucket key');
this.destroyBucketKey(bucketKeyId, logger, err => {
if (err) {
logger.error('KMIP::healthcheck: failure to remove the test bucket key', {
bucketKeyId,
error: err,
});
}
});
// no need to have the healthcheck wait until the
// destroyBucketKey() call finishes, as the healthcheck
// already succeeded by creating the bucket key
return cb();
});
}
}

module.exports = Client;
2 changes: 1 addition & 1 deletion lib/network/kmip/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class KMIP {
logger, encodedMessage,
(err, conversation, rawResponse) => {
if (err) {
logger.error('KMIP::request: Failed to encode message',
logger.error('KMIP::request: Failed to send message',
{ error: err });
return cb(err);
}
Expand Down
50 changes: 50 additions & 0 deletions tests/functional/kmip/highlevel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const LoopbackServerChannel =
require('../../utils/kmip/LoopbackServerChannel.js');
const TransportTemplate =
require('../../../lib/network/kmip/transport/TransportTemplate.js');
const TlsTransport =
require('../../../lib/network/kmip/transport/tls.js');
const KMIP = require('../../../lib/network/kmip');
const KMIPClient = require('../../../lib/network/kmip/Client.js');
const {
Expand Down Expand Up @@ -65,4 +67,52 @@ describe('KMIP High Level Driver', () => {
});
});
});
it('should succeed healthcheck with working KMIP client and server', done => {
const options = {
kmip: {
client: {
bucketNameAttributeName: null,
compoundCreateActivate: false,
},
codec: {},
transport: {
pipelineDepth: 8,
tls: {
port: 5696,
},
},
},
};
const kmipClient = new KMIPClient(options, TTLVCodec,
LoopbackServerTransport);
kmipClient.healthcheck(logger, err => {
assert.ifError(err);
done();
});
});

it('should fail healthcheck with KMIP server not running', done => {
const options = {
kmip: {
client: {
bucketNameAttributeName: null,
compoundCreateActivate: false,
},
codec: {},
transport: {
pipelineDepth: 8,
tls: {
port: 5696,
},
},
},
};
const kmipClient = new KMIPClient(options, TTLVCodec, TlsTransport);
kmipClient.healthcheck(logger, err => {
assert(err);
assert(err.InternalError);
assert(err.description.includes('ECONNREFUSED'));
done();
});
});
});

0 comments on commit dc698f4

Please sign in to comment.