Skip to content

Commit

Permalink
chore(test): conditionally exclude block commit api
Browse files Browse the repository at this point in the history
Needed to run the tests against older versions of libvirt, this
also fixes the build on node 0.10.x/0.12.x.
  • Loading branch information
Rush authored and mbroadst committed Aug 23, 2016
1 parent 92302ba commit e699aba
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/domain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ void Domain::Initialize(Handle<Object> exports)
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_CREATE_HALT);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY);
#if LIBVIR_CHECK_VERSION(0,9,10)
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_CREATE_LIVE);
#endif

//virDomainSnapshotDelete
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN);
Expand All @@ -137,6 +139,7 @@ void Domain::Initialize(Handle<Object> exports)
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_AFFECT_LIVE);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_AFFECT_CONFIG);

#ifdef _HAVE_DOMAIN_BLOCKCOMMIT_API
//virDomainBlockCommit
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_BLOCK_COMMIT_SHALLOW);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_BLOCK_COMMIT_DELETE);
Expand All @@ -155,6 +158,7 @@ void Domain::Initialize(Handle<Object> exports)
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_BLOCK_JOB_TYPE_COPY);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT);
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT);
#endif

//virDomainXMLFlags
NODE_DEFINE_CONSTANT(exports, VIR_DOMAIN_XML_SECURE);
Expand Down Expand Up @@ -1524,6 +1528,9 @@ NLV_WORKER_EXECUTE(Domain, SetVcpus)
#include <unistd.h>
NAN_METHOD(Domain::BlockCommit)
{
#ifndef _HAVE_DOMAIN_BLOCKCOMMIT_API
Nan::ThrowTypeError("blockcommit api not supported in this libvirt version");
#else
Nan::HandleScope scope;
if (info.Length() < 5 || !info[0]->IsString() || !info[1]->IsString() || !info[2]->IsString()
|| !info[3]->IsNumber()) {
Expand All @@ -1544,10 +1551,14 @@ NAN_METHOD(Domain::BlockCommit)
}
return onFinished(PrimitiveReturnHandler(true));
});
#endif
}

NAN_METHOD(Domain::BlockJobInfo)
{
#ifndef _HAVE_DOMAIN_BLOCKCOMMIT_API
Nan::ThrowTypeError("blockcommit api not supported in this libvirt version");
#else
Nan::HandleScope scope;
if (info.Length() < 1 || !info[0]->IsString()) {
Nan::ThrowTypeError("you must specify path and optionally flags");
Expand Down Expand Up @@ -1579,10 +1590,14 @@ NAN_METHOD(Domain::BlockJobInfo)
callback->Call(2, argv);
});
});
#endif
}

NAN_METHOD(Domain::BlockJobAbort)
{
#ifndef _HAVE_DOMAIN_BLOCKCOMMIT_API
Nan::ThrowTypeError("blockcommit api not supported in this libvirt version");
#else
if (info.Length() < 1 || !info[0]->IsString()) {
Nan::ThrowTypeError("you must specify path and optionally flags");
return;
Expand All @@ -1600,6 +1615,7 @@ NAN_METHOD(Domain::BlockJobAbort)
}
return onFinished(PrimitiveReturnHandler(true));
});
#endif
}

NAN_METHOD(Domain::SendKeys)
Expand Down
1 change: 1 addition & 0 deletions src/domain.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#if LIBVIR_CHECK_VERSION(0,9,10)
#define _HAVE_DOMAIN_METADATA_API 1
#define _HAVE_DOMAIN_BLOCKCOMMIT_API 1
#endif

namespace NLV {
Expand Down
2 changes: 1 addition & 1 deletion src/nlv_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ NAN_INLINE void AsyncQueueWorker(Nan::AsyncWorker *worker, Local<Object> parent
Nan::AsyncQueueWorker(worker);
}

NAN_INLINE unsigned int GetFlags(v8::Handle<v8::Value> val) {
NAN_INLINE unsigned int GetFlags(v8::Local<v8::Value> val) {
if(val->IsUndefined() || val->IsFunction()) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

using namespace NLV;

void Worker::Queue(v8::Handle<v8::Value> v8_callback, ExecuteHandler handler) {
void Worker::Queue(v8::Local<v8::Value> v8_callback, ExecuteHandler handler) {
if(!v8_callback->IsFunction()) {
Nan::ThrowTypeError("you must specify a function as the callback");;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace NLV {

// TODO: make it a template so that it can accept arbitrary number of arguments
// of objects to make persistent for the duration of the worker run
static void Queue(v8::Handle<v8::Value> v8_callback, ExecuteHandler handler);
static void Queue(v8::Local<v8::Value> v8_callback, ExecuteHandler handler);
};

template<class T>
Expand Down

0 comments on commit e699aba

Please sign in to comment.