diff options
author | Alex Shatov <alexs@att.com> | 2018-12-06 10:16:43 -0500 |
---|---|---|
committer | Alex Shatov <alexs@att.com> | 2018-12-06 10:16:43 -0500 |
commit | ca00a932eae5e706f01519612fce1015c9ff9d58 (patch) | |
tree | 796210ad1dfb8e4e717c06264f01fb64faa0fda6 /tests | |
parent | 84d5646b3f0250079c386ed2e1eb9fd7d551004e (diff) |
3.1.0/5.1.0 - check for finished deployment
- external version 3.1.0
- internal version 5.1.0 for code change - no API change
- check for finished deployment creation - success or failure
- stop querying cloudify manager on failed deployment creation
- use optional $CONSUL_URL to get url of consul
- improved info used for audit and logging and responses
- added more unit tests
unit test coverage summary
Statements : 80.99% ( 946/1168 )
Branches : 58.22% ( 294/505 )
Functions : 81.28% ( 165/203 )
Lines : 81.53% ( 936/1148 )
Change-Id: I831cd0db0d2e148e6da4c9190495aacf72e2d39c
Signed-off-by: Alex Shatov <alexs@att.com>
Issue-ID: DCAEGEN2-929
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_dcae-deployments.js | 71 | ||||
-rw-r--r-- | tests/test_policy.js | 34 |
2 files changed, 98 insertions, 7 deletions
diff --git a/tests/test_dcae-deployments.js b/tests/test_dcae-deployments.js index 367a38d..7bf9831 100644 --- a/tests/test_dcae-deployments.js +++ b/tests/test_dcae-deployments.js @@ -174,19 +174,19 @@ const Cloudify = { "blueprint_id": blueprint_id || deployment_id }; }, - resp_dep_creation: function(deployment_id) { + resp_dep_creation: function(deployment_id, execution_id, status) { return { "items": [ { - "status": "terminated", - "id": "ee6b0d21-0257-46a3-bb83-6f61f9ab5f99" + "status": (status || "terminated"), + "id": (execution_id || "ee6b0d21-0257-46a3-bb83-6f61f9ab5f99") } ], "metadata": { "pagination": { "total": 1, "offset": 0, - "size": 10000 + "size": 1000 } } }; @@ -385,6 +385,66 @@ function test_put_dcae_deployments_missing_input_error(dh_server) { }); } +function test_put_dcae_deployments_creation_failed(dh_server) { + const req_path = "/dcae-deployments/" + DEPLOYMENT_ID_JFL_1; + const message = create_main_message(INV_EXISTING_SERVICE_TYPE, true); + const test_txt = "fail deployment-creation PUT " + req_path + ": " + JSON.stringify(message); + const execution_id = "execution_" + DEPLOYMENT_ID_JFL_1; + describe(test_txt, () => { + it('fail deployment-creation', function(done) { + const action_timer = new utils.ActionTimer(); + console.log(action_timer.step, test_txt); + + nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL_1) + .reply(404, function(uri) { + console.log(action_timer.step, "get", dh.INVENTORY_URL, uri); + return JSON.stringify(Inventory.resp_not_found_service(DEPLOYMENT_ID_JFL_1)); + }); + nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICE_TYPES + INV_EXISTING_SERVICE_TYPE) + .reply(200, function(uri) { + console.log(action_timer.step, "get", dh.INVENTORY_URL, uri); + return JSON.stringify(Inventory.resp_existing_blueprint(INV_EXISTING_SERVICE_TYPE)); + }); + nock(dh.INVENTORY_URL).put(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL_1) + .reply(200, function(uri, requestBody) { + console.log(action_timer.step, "put", dh.INVENTORY_URL, uri, JSON.stringify(requestBody)); + return JSON.stringify(Inventory.resp_put_service(DEPLOYMENT_ID_JFL_1, INV_EXISTING_SERVICE_TYPE)); + }); + + nock(dh.CLOUDIFY_URL).put("/api/v2.1/blueprints/" + DEPLOYMENT_ID_JFL_1) + .reply(200, function(uri, requestBody) { + console.log(action_timer.step, "put", dh.CLOUDIFY_URL, uri, JSON.stringify(requestBody)); + return JSON.stringify(Cloudify.resp_blueprint(DEPLOYMENT_ID_JFL_1)); + }); + + nock(dh.CLOUDIFY_URL).put("/api/v2.1/deployments/" + DEPLOYMENT_ID_JFL_1) + .reply(201, function(uri, requestBody) { + console.log(action_timer.step, "put", dh.CLOUDIFY_URL, uri, JSON.stringify(requestBody)); + return JSON.stringify(Cloudify.resp_deploy(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1, message.inputs)); + }); + + nock(dh.CLOUDIFY_URL).get("/api/v2.1/executions?deployment_id=" + DEPLOYMENT_ID_JFL_1 + "&workflow_id=create_deployment_environment&_include=id,status") + .reply(200, function(uri) { + console.log(action_timer.step, "get", dh.CLOUDIFY_URL, uri); + return JSON.stringify(Cloudify.resp_dep_creation(DEPLOYMENT_ID_JFL_1, execution_id, "failed")); + }); + + chai.request(dh_server.app).put(req_path) + .set('content-type', 'application/json') + .send(message) + .end(function(err, res) { + console.log(action_timer.step, "res for", test_txt, res.text); + expect(res).to.have.status(500); + expect(res.body).to.have.property('message'); + expect(res.body.message).to.be.equal( + 'Status 502 from CM API -- error code: UNKNOWN -- message: deployment_id(' + + DEPLOYMENT_ID_JFL_1 + '): deployment creation failed -- no error information'); + done(); + }); + }).timeout(50000); + }); +} + function test_put_dcae_deployments_success(dh_server) { const req_path = "/dcae-deployments/" + DEPLOYMENT_ID_JFL_1; const message = create_main_message(INV_EXISTING_SERVICE_TYPE, true); @@ -426,7 +486,7 @@ function test_put_dcae_deployments_success(dh_server) { nock(dh.CLOUDIFY_URL).get("/api/v2.1/executions?deployment_id=" + DEPLOYMENT_ID_JFL_1 + "&workflow_id=create_deployment_environment&_include=id,status") .reply(200, function(uri) { console.log(action_timer.step, "get", dh.CLOUDIFY_URL, uri); - return JSON.stringify(Cloudify.resp_dep_creation(DEPLOYMENT_ID_JFL_1)); + return JSON.stringify(Cloudify.resp_dep_creation(DEPLOYMENT_ID_JFL_1, execution_id)); }); nock(dh.CLOUDIFY_URL).post("/api/v2.1/executions") @@ -651,6 +711,7 @@ dh.add_tests([ test_put_dcae_deployments_missing_input_error, test_get_dcae_deployments_operation, test_get_dcae_deployments_service_type_deployed, + test_put_dcae_deployments_creation_failed, test_put_dcae_deployments_success, test_delete_dcae_deployments_success ]); diff --git a/tests/test_policy.js b/tests/test_policy.js index bc424e0..32e5ed4 100644 --- a/tests/test_policy.js +++ b/tests/test_policy.js @@ -211,7 +211,13 @@ const cloudify_node_instances = [ ]; function nock_cfy_node_instances(action_timer) { - nock(dh.CLOUDIFY_URL).get(CFY_API_NODE_INSTANCES).query(true) + // "/node-instances?_include=id,deployment_id,runtime_properties&_size=1000&_offset=0" + nock(dh.CLOUDIFY_URL).get(CFY_API_NODE_INSTANCES) + .query(params => { + console.log(action_timer.step, "get", dh.CLOUDIFY_URL, CFY_API_NODE_INSTANCES, JSON.stringify(params)); + return !!(params._include === "id,deployment_id,runtime_properties" + && params._size === "1000" && params._offset === "0"); + }) .reply(200, function(uri) { console.log(action_timer.step, "get", dh.CLOUDIFY_URL, uri); return JSON.stringify({ @@ -221,6 +227,29 @@ function nock_cfy_node_instances(action_timer) { }); } +function test_get_policy(dh_server) { + const req_path = "/policy"; + const test_txt = "GET " + req_path; + describe(test_txt, () => { + it('GET all the policies and policy-filters from cloudify', function() { + const action_timer = new utils.ActionTimer(); + console.log(action_timer.step, test_txt); + nock_cfy_node_instances(action_timer); + + return chai.request(dh_server.app).get(req_path) + .then(function(res) { + console.log(action_timer.step, "res for", test_txt, res.text); + expect(res).to.have.status(200); + expect(res).to.be.json; + }) + .catch(function(err) { + console.error(action_timer.step, "err for", test_txt, err); + throw err; + }); + }); + }); +} + function test_get_policy_components(dh_server) { const req_path = "/policy/components"; const test_txt = "GET " + req_path; @@ -309,7 +338,7 @@ function test_put_policy_catch_up(dh_server) { return JSON.stringify(resp_to_exe); }); - for (var extra_i = 1; extra_i <= 100000; extra_i++) { + for (var extra_i = 1; extra_i <= 10000; extra_i++) { const policy_id = "extra_" + extra_i; message.latest_policies[policy_id] = create_policy(policy_id, extra_i); } @@ -474,6 +503,7 @@ function test_fail_404_cfy_policy_catch_up(dh_server) { } dh.add_tests([ + test_get_policy, test_get_policy_components, test_put_policy_catch_up, test_fail_cfy_policy_catch_up, |