MXS-1999: Fix removal of undefined relationships
If a relationship isn't defined, it should not be removed. Only if a relationship is change to a null relationship, should it be removed. Also fixed the maxctrl test suite to verify that both it and the REST API tests pass.
This commit is contained in:
parent
4fd4d6bb01
commit
446116a8bb
@ -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;
|
||||
|
@ -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})
|
||||
|
@ -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() {
|
||||
|
@ -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) {
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user