diff --git a/server/core/config_runtime.cc b/server/core/config_runtime.cc index ac0c1e627..83882fcd0 100644 --- a/server/core/config_runtime.cc +++ b/server/core/config_runtime.cc @@ -1385,7 +1385,8 @@ SERVER* runtime_create_server_from_json(json_t* json) bool server_to_object_relations(SERVER* server, json_t* old_json, json_t* new_json) { - if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS) == NULL) + if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_SERVICES) == NULL && + mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_MONITORS) == NULL) { /** No change to relationships */ return true; @@ -1633,7 +1634,7 @@ MXS_MONITOR* runtime_create_monitor_from_json(json_t* json) bool object_to_server_relations(const char* target, json_t* old_json, json_t* new_json) { - if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS) == NULL) + if (mxs_json_pointer(new_json, MXS_JSON_PTR_RELATIONSHIPS_SERVERS) == NULL) { /** No change to relationships */ return true; diff --git a/server/core/test/rest-api/test/monitor.js b/server/core/test/rest-api/test/monitor.js index 4c3b41909..16963a129 100644 --- a/server/core/test/rest-api/test/monitor.js +++ b/server/core/test/rest-api/test/monitor.js @@ -57,6 +57,15 @@ describe("Monitor Relationships", function() { }) }); + it("missing relationships are not removed", function() { + var mon = {data: {relationships: {}}} + return request.patch(base_url + "/monitors/MariaDB-Monitor", {json: mon}) + .then(() => request.get(base_url + "/monitors/MariaDB-Monitor", { json: true })) + .then((res) => { + res.data.relationships.should.have.keys("servers") + }) + }); + it("remove relationships from old monitor", function() { var mon = {data: {relationships: {servers: {data: null}}}} return request.patch(base_url + "/monitors/MariaDB-Monitor", {json: mon}) diff --git a/server/core/test/rest-api/test/server.js b/server/core/test/rest-api/test/server.js index 5ed501358..36bc95ec7 100644 --- a/server/core/test/rest-api/test/server.js +++ b/server/core/test/rest-api/test/server.js @@ -101,6 +101,20 @@ describe("Server Relationships", function() { rel_server.data.relationships["monitors"] = null return request.patch(base_url + "/servers/" + rel_server.data.id, {json: rel_server}) .should.be.rejected + .then(() => request.get(base_url + "/servers/" + rel_server.data.id, {json: true})) + .then((res) => { + res.data.relationships.should.have.keys("services") + }) + }); + + it("missing relationships are not removed", function() { + rel_server.data.relationships = {} + return request.patch(base_url + "/servers/" + rel_server.data.id, {json: rel_server}) + .should.be.fulfilled + .then(() => request.get(base_url + "/servers/" + rel_server.data.id, {json: true})) + .then((res) => { + res.data.relationships.should.have.keys("services") + }) }); it("remove relationships", function() { @@ -108,6 +122,11 @@ describe("Server Relationships", function() { rel_server.data.relationships["monitors"] = {data: null} return request.patch(base_url + "/servers/" + rel_server.data.id, {json: rel_server}) .should.be.fulfilled + .then(() => request.get(base_url + "/servers/" + rel_server.data.id, {json: true})) + .then((res) => { + res.data.relationships.should.not.have.keys("services") + res.data.relationships.should.not.have.keys("monitors") + }) }); it("destroy server", function() { diff --git a/server/core/test/rest-api/test/service.js b/server/core/test/rest-api/test/service.js index 7df8de961..661295d90 100644 --- a/server/core/test/rest-api/test/service.js +++ b/server/core/test/rest-api/test/service.js @@ -20,12 +20,27 @@ describe("Service", function() { }); - it("remove service relationship", function() { + it("missing relationships are not removed", function() { return request.get(base_url + "/services/RW-Split-Router") .then(function(resp) { var svc = JSON.parse(resp) delete svc.data.relationships["servers"] - delete svc.data.relationships["servers"] + return request.patch(base_url + "/services/RW-Split-Router", {json: svc}) + }) + .then(function(resp) { + return request.get(base_url + "/services/RW-Split-Router") + }) + .then(function(resp) { + var svc = JSON.parse(resp) + svc.data.relationships.should.not.be.empty + }) + }); + + it("remove service relationship", function() { + return request.get(base_url + "/services/RW-Split-Router") + .then(function(resp) { + var svc = JSON.parse(resp) + svc.data.relationships.servers.data = null return request.patch(base_url + "/services/RW-Split-Router", {json: svc}) }) .then(function(resp) { diff --git a/test/run_npm_test.sh b/test/run_npm_test.sh index ba6f91baa..ba44fbffb 100755 --- a/test/run_npm_test.sh +++ b/test/run_npm_test.sh @@ -27,6 +27,9 @@ cp -t $testdir -r $srcdir/test/* # Copy test sources to test workspace cp -t $testdir -r $testsrc/* +# Required by MaxCtrl (not super pretty) +cp -t $testdir/.. $srcdir/VERSION*.cmake + # Copy required docker-compose files to the MaxScale directory and bring MariaDB # servers up. This is an asynchronous process. cd $maxscaledir