summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAlex Shatov <alexs@att.com>2018-01-24 13:35:28 -0500
committerAlex Shatov <alexs@att.com>2018-01-24 13:35:28 -0500
commit4e30c82b172cf422ab5179e3c566ef01ca14cb3a (patch)
tree0efa3043daeb8001516d671df5d8e1b81ca4b798 /tests
parent70253f7088be04125d9fac8f9bddfaa63778608e (diff)
unit tests coverage 68% and more info in audit
* refactored the unit test - simpler dh server initialization * new unit tests for the dcae-deployments * new unit tests for healthcheck - info * new server_instance_uuid - unique per deployment-handler instance for logging and info * dragging req object over the stack to show req data in logging and audit and metrics * new feature variable collection of policies per component in DCAE Change-Id: I8388d7e5e11e3a6c871cf3d507bd8a07b09add29 Issue-ID: DCAEGEN2-249 Signed-off-by: Alex Shatov <alexs@att.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/mock_deployment_handler.js102
-rw-r--r--tests/mock_utils.js25
-rw-r--r--tests/test_dcae-deployments.js490
-rw-r--r--tests/test_info.js57
-rw-r--r--tests/test_policy.js135
-rw-r--r--tests/test_zzz_run.js21
6 files changed, 724 insertions, 106 deletions
diff --git a/tests/mock_deployment_handler.js b/tests/mock_deployment_handler.js
new file mode 100644
index 0000000..ed0468f
--- /dev/null
+++ b/tests/mock_deployment_handler.js
@@ -0,0 +1,102 @@
+/*
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and limitations under the License.
+*/
+
+/**
+ * mock-deployment_handler - base server for all other tests
+ */
+
+"use strict";
+
+const nock = require('nock');
+const utils = require('./mock_utils');
+
+const MAIN_PATH = './../';
+
+const CONSUL_URL = 'http://consul:8500';
+const MOCK_CLOUDIFY_MANAGER = "mock_cloudify_manager";
+const CLOUDIFY_URL = "http://" + MOCK_CLOUDIFY_MANAGER + ":80";
+
+const MOCK_INVENTORY = "mock_inventory";
+const INVENTORY_URL = "https://" + MOCK_INVENTORY + ":8080";
+
+nock(CONSUL_URL).persist().get('/v1/kv/deployment_handler?raw')
+ .reply(200, {"logLevel": "DEBUG", "cloudify": {"protocol": "http"}});
+
+nock(CONSUL_URL).persist().get('/v1/catalog/service/cloudify_manager')
+ .reply(200, [{
+ "ID":"deadbeef-dead-beef-dead-beefdeadbeef",
+ "Node":"devorcl00",
+ "Address": MOCK_CLOUDIFY_MANAGER,
+ "Datacenter":"rework-central",
+ "TaggedAddresses":{"lan": MOCK_CLOUDIFY_MANAGER,"wan": MOCK_CLOUDIFY_MANAGER},
+ "NodeMeta":{},
+ "ServiceID":"cloudify_manager",
+ "ServiceName":"cloudify_manager",
+ "ServiceTags":["http://" + MOCK_CLOUDIFY_MANAGER + "/api/v2.1"],
+ "ServiceAddress": MOCK_CLOUDIFY_MANAGER,
+ "ServicePort":80,
+ "ServiceEnableTagOverride":false,
+ "CreateIndex":16,
+ "ModifyIndex":16
+ }]);
+
+nock(CONSUL_URL).persist().get('/v1/catalog/service/inventory')
+ .reply(200, [{
+ "ID": "",
+ "Node": "inventory_mock_node",
+ "Address": MOCK_INVENTORY,
+ "Datacenter": "rework-central",
+ "TaggedAddresses": null,
+ "NodeMeta": null,
+ "ServiceID": "inventory",
+ "ServiceName": "inventory",
+ "ServiceTags": [],
+ "ServiceAddress": "",
+ "ServicePort": 8080,
+ "ServiceEnableTagOverride": false,
+ "CreateIndex": 8068,
+ "ModifyIndex": 8068
+ }]);
+
+const tests = [];
+
+const run_dh = function() {
+ describe('run deployment-handler', () => {
+ it('starting deployment-handler server', function() {
+ console.log("starting deployment-handler server");
+ const dh_server = require(MAIN_PATH + 'deployment-handler');
+
+ return utils.sleep(5000).then(function() {
+ console.log("starting tests: count =", tests.length);
+ if (Array.isArray(tests)) {
+ tests.forEach(test => {
+ test(dh_server);
+ });
+ }
+ })
+ .catch(function(e) {
+ const error = "test of deployment-handler exiting due to test problem: " + e.message;
+ console.error(error);
+ throw e;
+ });
+ }).timeout(10000);
+ });
+};
+
+module.exports.INVENTORY_URL = INVENTORY_URL;
+module.exports.CLOUDIFY_URL = CLOUDIFY_URL;
+module.exports.add_tests = function(new_tests) {Array.prototype.push.apply(tests, new_tests);};
+module.exports.run_dh = run_dh; \ No newline at end of file
diff --git a/tests/mock_utils.js b/tests/mock_utils.js
new file mode 100644
index 0000000..2d7d2e5
--- /dev/null
+++ b/tests/mock_utils.js
@@ -0,0 +1,25 @@
+/*
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and limitations under the License.
+*/
+
+"use strict";
+
+module.exports.sleep = function(time) {
+ console.log("sleep for " + time + " msecs...");
+ return new Promise((resolve) => setTimeout(() => {
+ console.log("woke up after " + time + " msecs");
+ resolve();
+ }, time));
+};
diff --git a/tests/test_dcae-deployments.js b/tests/test_dcae-deployments.js
new file mode 100644
index 0000000..2aca4c7
--- /dev/null
+++ b/tests/test_dcae-deployments.js
@@ -0,0 +1,490 @@
+/*
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and limitations under the License.
+*/
+
+/**
+ * handling policy updates
+ */
+
+"use strict";
+
+const nock = require('nock')
+ , chai = require('chai')
+ , chaiHttp = require('chai-http')
+ , expect = chai.expect
+ , assert = chai.assert;
+
+chai.use(chaiHttp);
+
+const dh = require('./mock_deployment_handler');
+const utils = require('./mock_utils');
+
+const INV_PATH_DCAE_SERVICES = "/dcae-services";
+const INV_PATH_DCAE_SERVICE_TYPES = "/dcae-service-types/";
+const INV_PARAM_TYPE_ID = "?typeId=";
+
+const I_DONT_KNOW = "i-dont-know";
+const DEPLOYMENT_ID_JFL = "dep-jfl-000";
+const DEPLOYMENT_ID_JFL_1 = "dep-jfl-001";
+const EXISTING_DEPLOYMENT_ID = "deployment-CL-2229";
+const INV_EXISTING_SERVICE_TYPE = "86615fc1-aed9-4aa2-9e4b-abdaccbe63de";
+
+const Inventory = {
+ resp_empty: {"links":{"previousLink":null,"nextLink":null},"totalCount":0,"items":[]},
+ resp_services: function(deployment_id, service_type, totalCount) {
+ service_type = service_type || "f93264ee-348c-44f6-af3d-15b157bba735";
+ const res = {
+ "links": {
+ "previousLink": null,
+ "nextLink": {
+ "rel": "next",
+ "href": dh.INVENTORY_URL + INV_PATH_DCAE_SERVICES
+ + (service_type && "/" + INV_PARAM_TYPE_ID + service_type + "&offset=25") || "/?offset=25"
+ }
+ },
+ "totalCount": totalCount || 190,
+ "items": []
+ };
+ Array.from(Array(totalCount || 1), (_, idx) => idx).forEach(index => {
+ const dpl_id = deployment_id + ((index && "_" + index) || "");
+ res.items.push({
+ "serviceId": dpl_id,
+ "selfLink": {
+ "rel": "self",
+ "href": dh.INVENTORY_URL + INV_PATH_DCAE_SERVICES + "/" + dpl_id
+ },
+ "created": 1503668339483,
+ "modified": 1503668339483,
+ "typeLink": {
+ "rel": "type",
+ "href": dh.INVENTORY_URL + INV_PATH_DCAE_SERVICE_TYPES + service_type
+ },
+ "vnfId": "dummyVnfId",
+ "vnfLink": null,
+ "vnfType": "dummyVnfType",
+ "vnfLocation": "dummyLocation",
+ "deploymentRef": dpl_id,
+ "components": [{
+ "componentId": "/components/dummy",
+ "componentLink": null,
+ "created": 1489768104449,
+ "modified": 1508260526203,
+ "componentType": "dummyComponent",
+ "componentSource": "DCAEController",
+ "status": null,
+ "location": null,
+ "shareable": 0
+ }]
+ });
+ });
+ return res;
+ },
+ resp_not_found_service: function(service_id) {
+ return {
+ "code": 1,
+ "type": "error",
+ "message": "DCAEService not found: " + service_id
+ };
+ },
+ resp_existing_blueprint: function(service_type) {
+ return {
+ "owner": "dcaeorch",
+ "typeName": "svc-type-000",
+ "typeVersion": 1,
+ "blueprintTemplate": "tosca_definitions_version: cloudify_dsl_1_2\nimports:\n - http://www.getcloudify.org/spec/cloudify/3.3/types.yaml\n - https://nexus01.research.att.com:8443/repository/solutioning01-mte2-raw/type_files/dti_inputs.yaml\nnode_templates:\n type-00:\n type: cloudify.nodes.Root",
+ "serviceIds": null,
+ "vnfTypes": ["TESTVNF000"],
+ "serviceLocations": null,
+ "asdcServiceId": null,
+ "asdcResourceId": null,
+ "asdcServiceURL": null,
+ "typeId": service_type,
+ "selfLink": {
+ "rel": "self",
+ "href": dh.INVENTORY_URL + INV_PATH_DCAE_SERVICE_TYPES + service_type
+ },
+ "created": 1500910967567,
+ "deactivated": null
+ };
+ },
+ resp_put_service: function(deployment_id, service_type) {
+ return {
+ "serviceId": deployment_id,
+ "selfLink": {
+ "rel": "self",
+ "href": dh.INVENTORY_URL + INV_PATH_DCAE_SERVICES + "/" + deployment_id
+ },
+ "created": 1516376798582,
+ "modified": 1516376798582,
+ "typeLink": {
+ "rel": "type",
+ "href": dh.INVENTORY_URL + INV_PATH_DCAE_SERVICE_TYPES + service_type
+ },
+ "vnfId": "dummyVnfId",
+ "vnfLink": null,
+ "vnfType": "dummyVnfType",
+ "vnfLocation": "dummyLocation",
+ "deploymentRef": deployment_id,
+ "components": [{
+ "componentId": "/components/dummy",
+ "componentLink": null,
+ "created": 1489768104449,
+ "modified": 1516376798582,
+ "componentType": "dummy_component",
+ "componentSource": "DCAEController",
+ "status": null,
+ "location": null,
+ "shareable": 0
+ }]
+ };
+ }
+};
+
+const Cloudify = {
+ resp_blueprint: function(deployment_id) {
+ return {
+ "main_file_name": "blueprint.yaml",
+ "description": null,
+ "created_at": "2018-01-19 15:46:47.037084",
+ "updated_at": "2018-01-19 15:46:47.037084",
+ "plan": {},
+ "id": deployment_id
+ };
+ },
+ resp_deploy: function(deployment_id, blueprint_id, inputs) {
+ return {
+ "inputs": (inputs && JSON.parse(JSON.stringify(inputs)) || null),
+ "description": null,
+ "created_at": "2018-01-19 15:46:47.037084",
+ "updated_at": "2018-01-19 15:46:47.037084",
+ "id": deployment_id,
+ "blueprint_id": blueprint_id || deployment_id
+ };
+ },
+ resp_execution: function(deployment_id, blueprint_id, execution_id, terminated, workflow_id) {
+ return {
+ "status": (terminated && "terminated") || "pending",
+ "created_at": "2018-01-19 15:51:21.866227",
+ "workflow_id": workflow_id || "install",
+ "is_system_workflow": false,
+ "parameters": {},
+ "blueprint_id": blueprint_id || deployment_id,
+ "deployment_id": deployment_id,
+ "error": "",
+ "id": execution_id
+ };
+ },
+ resp_outputs: function(deployment_id) {
+ return {"outputs": {}, "deployment_id": deployment_id};
+ }
+};
+
+function test_get_dcae_deployments(dh_server) {
+ const req_path = "/dcae-deployments";
+ const test_txt = "GET " + req_path;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('GET all the dcae-deployments from inventory', function() {
+ const inv_resp = Inventory.resp_services(EXISTING_DEPLOYMENT_ID);
+ nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICES).reply(200, inv_resp);
+
+ return chai.request(dh_server.app).get(req_path)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(200);
+ expect(res).to.be.json;
+
+ assert.containsAllKeys(res.body, {"requestId": "", "deployments": []});
+ assert.isString(res.body.requestId);
+ assert.isArray(res.body.deployments);
+ assert.lengthOf(res.body.deployments, inv_resp.items.length);
+ assert.containsAllKeys(res.body.deployments[0], {"href":null});
+ assert.match(res.body.deployments[0].href,
+ new RegExp("^http:[/][/]127.0.0.1:[0-9]+[/]dcae-deployments[/]" + EXISTING_DEPLOYMENT_ID));
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
+ });
+ });
+ });
+}
+
+function test_get_dcae_deployments_service_type_unknown(dh_server) {
+ const req_path = "/dcae-deployments?serviceTypeId=" + I_DONT_KNOW;
+ const test_txt = "GET " + req_path;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('GET nothing for unknown service-type from inventory', function() {
+ nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICES + INV_PARAM_TYPE_ID + I_DONT_KNOW)
+ .reply(200, Inventory.resp_empty);
+
+ return chai.request(dh_server.app).get(req_path)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(200);
+ expect(res).to.be.json;
+
+ assert.containsAllKeys(res.body, {"requestId": "", "deployments": []});
+ assert.isString(res.body.requestId);
+ assert.isArray(res.body.deployments);
+ assert.lengthOf(res.body.deployments, 0);
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
+ });
+ });
+ });
+}
+
+function create_main_message(service_type_id, include_inputs) {
+ var msg = {"serviceTypeId": service_type_id};
+ if (include_inputs) {
+ msg.inputs= {
+ "dcae_service_location" : "loc00",
+ "dcae_target_type" : "type000",
+ "dcae_target_name" : "target000"
+ };
+ }
+ return msg;
+}
+
+function test_put_dcae_deployments_i_dont_know(dh_server) {
+ const req_path = "/dcae-deployments/" + I_DONT_KNOW;
+ const message = create_main_message(I_DONT_KNOW);
+ const test_txt = "PUT " + req_path + ": " + JSON.stringify(message);
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('Fail to deploy i-dont-know service', function(done) {
+ nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICES + "/" + I_DONT_KNOW)
+ .reply(404, Inventory.resp_not_found_service(I_DONT_KNOW));
+ nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICE_TYPES + I_DONT_KNOW)
+ .reply(404, "<html> <head><title>Error 404 Not Found</title></head><body></body> </html>");
+
+ chai.request(dh_server.app).put(req_path)
+ .set('content-type', 'application/json')
+ .send(message)
+ .end(function(err, res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(404);
+ expect(res.body).to.have.property('message');
+ expect(res.body.message).to.be.equal("No service type with ID " + I_DONT_KNOW);
+ done();
+ });
+ });
+ });
+}
+
+function test_put_dcae_deployments_missing_input_error(dh_server) {
+ const req_path = "/dcae-deployments/" + DEPLOYMENT_ID_JFL;
+ const message = create_main_message(INV_EXISTING_SERVICE_TYPE);
+ const test_txt = "PUT " + req_path + ": " + JSON.stringify(message);
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('Fail to deploy service - missing_input', function(done) {
+ nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL)
+ .reply(404, Inventory.resp_not_found_service(DEPLOYMENT_ID_JFL));
+ nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICE_TYPES + INV_EXISTING_SERVICE_TYPE)
+ .reply(200, Inventory.resp_existing_blueprint(INV_EXISTING_SERVICE_TYPE));
+ nock(dh.INVENTORY_URL).put(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL)
+ .reply(200, Inventory.resp_put_service(DEPLOYMENT_ID_JFL, INV_EXISTING_SERVICE_TYPE));
+ nock(dh.INVENTORY_URL).delete(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL)
+ .reply(200);
+
+ nock(dh.CLOUDIFY_URL).put("/api/v2.1/blueprints/" + DEPLOYMENT_ID_JFL)
+ .reply(200, Cloudify.resp_blueprint(DEPLOYMENT_ID_JFL));
+
+ const depl_rejected = {
+ "message": "Required inputs blah...",
+ "error_code": "missing_required_deployment_input_error",
+ "server_traceback": "Traceback blah..."
+ };
+ nock(dh.CLOUDIFY_URL).put("/api/v2.1/deployments/" + DEPLOYMENT_ID_JFL)
+ .reply(400, depl_rejected);
+
+ chai.request(dh_server.app).put(req_path)
+ .set('content-type', 'application/json')
+ .send(message)
+ .end(function(err, res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(400);
+ expect(res.body).to.have.property('message');
+ expect(res.body.message).to.be.equal("Status 400 from CM API -- error code: " + depl_rejected.error_code + " -- message: " + depl_rejected.message);
+ done();
+ });
+ });
+ });
+}
+
+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);
+ const test_txt = "PUT " + req_path + ": " + JSON.stringify(message);
+ const execution_id = "execution_" + DEPLOYMENT_ID_JFL_1;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('Success deploy service', function() {
+ nock(dh.INVENTORY_URL).get(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL_1)
+ .reply(404, 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, Inventory.resp_existing_blueprint(INV_EXISTING_SERVICE_TYPE));
+ nock(dh.INVENTORY_URL).put(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL_1)
+ .reply(200, 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, Cloudify.resp_blueprint(DEPLOYMENT_ID_JFL_1));
+
+ nock(dh.CLOUDIFY_URL).put("/api/v2.1/deployments/" + DEPLOYMENT_ID_JFL_1)
+ .reply(201, Cloudify.resp_deploy(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1, message.inputs));
+
+ nock(dh.CLOUDIFY_URL).post("/api/v2.1/executions").reply(201,
+ Cloudify.resp_execution(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1, execution_id));
+
+ nock(dh.CLOUDIFY_URL).get("/api/v2.1/executions/" + execution_id).reply(200,
+ Cloudify.resp_execution(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1, execution_id, true));
+
+ nock(dh.CLOUDIFY_URL).get("/api/v2.1/deployments/" + DEPLOYMENT_ID_JFL_1 + "/outputs")
+ .reply(200, Cloudify.resp_outputs(DEPLOYMENT_ID_JFL_1));
+
+ return chai.request(dh_server.app).put(req_path)
+ .set('content-type', 'application/json')
+ .send(message)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(202);
+ expect(res).to.be.json;
+
+ return utils.sleep(10000);
+ })
+ .then(function() {
+ console.log("the end of test");
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
+ });
+ }).timeout(50000);
+ });
+}
+
+function test_get_dcae_deployments_operation(dh_server) {
+ const execution_id = "execution_" + DEPLOYMENT_ID_JFL_1;
+ const req_path = "/dcae-deployments/" + DEPLOYMENT_ID_JFL_1 + "/operation/" + execution_id;
+ const test_txt = "GET " + req_path;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('Get operation execution succeeded', function() {
+ nock(dh.CLOUDIFY_URL).get("/api/v2.1/executions/" + execution_id).reply(200,
+ Cloudify.resp_execution(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1, execution_id, true));
+
+ return chai.request(dh_server.app).get(req_path)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(200);
+ expect(res).to.be.json;
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
+ });
+ });
+ });
+}
+
+function test_get_dcae_deployments_service_type_deployed(dh_server) {
+ const req_path = "/dcae-deployments?serviceTypeId=" + INV_EXISTING_SERVICE_TYPE;
+ const test_txt = "GET " + req_path;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('GET services=deployments of the service-type from inventory', function() {
+ const deployed_count = 10;
+ nock(dh.INVENTORY_URL)
+ .get(INV_PATH_DCAE_SERVICES + INV_PARAM_TYPE_ID + INV_EXISTING_SERVICE_TYPE)
+ .reply(200, Inventory.resp_services(DEPLOYMENT_ID_JFL_1, INV_EXISTING_SERVICE_TYPE, deployed_count));
+
+ return chai.request(dh_server.app).get(req_path)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(200);
+ expect(res).to.be.json;
+
+ assert.containsAllKeys(res.body, {"requestId": "", "deployments": []});
+ assert.isString(res.body.requestId);
+ assert.isArray(res.body.deployments);
+ assert.lengthOf(res.body.deployments, deployed_count);
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
+ });
+ });
+ });
+}
+
+function test_delete_dcae_deployments_success(dh_server) {
+ const req_path = "/dcae-deployments/" + DEPLOYMENT_ID_JFL_1;
+ const test_txt = "DELETE " + req_path;
+ const workflow_id = "uninstall";
+ const execution_id = workflow_id + "_" + DEPLOYMENT_ID_JFL_1;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('Success DELETE service', function() {
+ nock(dh.CLOUDIFY_URL).post("/api/v2.1/executions").reply(201,
+ Cloudify.resp_execution(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1,
+ execution_id, false, workflow_id));
+
+ nock(dh.INVENTORY_URL).delete(INV_PATH_DCAE_SERVICES + "/" + DEPLOYMENT_ID_JFL_1)
+ .reply(200);
+
+ nock(dh.CLOUDIFY_URL).get("/api/v2.1/executions/" + execution_id).reply(200,
+ Cloudify.resp_execution(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1,
+ execution_id, true, workflow_id));
+
+ nock(dh.CLOUDIFY_URL).delete("/api/v2.1/deployments/" + DEPLOYMENT_ID_JFL_1)
+ .reply(201, Cloudify.resp_deploy(DEPLOYMENT_ID_JFL_1, DEPLOYMENT_ID_JFL_1));
+
+ nock(dh.CLOUDIFY_URL).delete("/api/v2.1/blueprints/" + DEPLOYMENT_ID_JFL_1)
+ .reply(200, Cloudify.resp_blueprint(DEPLOYMENT_ID_JFL_1));
+
+ return chai.request(dh_server.app).delete(req_path)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(202);
+ expect(res).to.be.json;
+
+ return utils.sleep(45000);
+ })
+ .then(function() {
+ console.log("the end of test");
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
+ });
+ }).timeout(60000);
+ });
+}
+
+dh.add_tests([
+ test_get_dcae_deployments,
+ test_get_dcae_deployments_service_type_unknown,
+ test_put_dcae_deployments_i_dont_know,
+ test_put_dcae_deployments_missing_input_error,
+ test_get_dcae_deployments_operation,
+ test_get_dcae_deployments_service_type_deployed,
+ test_put_dcae_deployments_success,
+ test_delete_dcae_deployments_success
+]);
diff --git a/tests/test_info.js b/tests/test_info.js
new file mode 100644
index 0000000..b2f8a91
--- /dev/null
+++ b/tests/test_info.js
@@ -0,0 +1,57 @@
+/*
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and limitations under the License.
+*/
+
+/**
+ * handling policy updates
+ */
+
+"use strict";
+
+const chai = require('chai')
+ , chaiHttp = require('chai-http')
+ , expect = chai.expect
+ , assert = chai.assert;
+
+chai.use(chaiHttp);
+
+const dh = require('./mock_deployment_handler');
+
+function test_get_info(dh_server) {
+ const req_path = "/";
+ const test_txt = "GET " + req_path;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('GET info', function() {
+ return chai.request(dh_server.app).get(req_path)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(200);
+ expect(res).to.be.json;
+
+ const info = res.body;
+ const config = process.mainModule.exports.config;
+ assert.include(config, info.server);
+ assert.deepEqual(config.apiLinks, info.links);
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
+ });
+ });
+ });
+}
+
+dh.add_tests([test_get_info]);
diff --git a/tests/test_policy.js b/tests/test_policy.js
index 8161032..597c6df 100644
--- a/tests/test_policy.js
+++ b/tests/test_policy.js
@@ -1,5 +1,5 @@
/*
-Copyright(c) 2017 AT&T Intellectual Property. All rights reserved.
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -20,21 +20,19 @@ See the License for the specific language governing permissions and limitations
"use strict";
-const nock = require('nock');
-const chai = require('chai')
+const nock = require('nock')
+ , chai = require('chai')
, chaiHttp = require('chai-http')
- , expect = chai.expect;
+ , expect = chai.expect
+ , assert = chai.assert;
chai.use(chaiHttp);
-const REQ_ID = "111";
+const dh = require('./mock_deployment_handler');
+
const RUN_TS = new Date();
const RUN_TS_HOURS = RUN_TS.getHours();
-const CONSUL_URL = 'http://consul:8500';
-const TEST_CLOUDIFY_MANAGER = "test_cloudify_manager";
-const CLOUDIFY_URL = "http://" + TEST_CLOUDIFY_MANAGER + ":80";
-
const POLICY_ID = 'policy_id';
const POLICY_VERSION = "policyVersion";
const POLICY_NAME = "policyName";
@@ -80,46 +78,7 @@ function create_policy(policy_id, policy_version=1) {
};
}
-nock(CONSUL_URL).persist().get('/v1/kv/deployment_handler?raw')
- .reply(200, {"logLevel": "DEBUG", "cloudify": {"protocol": "http"}});
-
-nock(CONSUL_URL).persist().get('/v1/catalog/service/cloudify_manager')
- .reply(200, [{
- "ID":"deadbeef-dead-beef-dead-beefdeadbeef",
- "Node":"devorcl00",
- "Address": TEST_CLOUDIFY_MANAGER,
- "Datacenter":"rework-central",
- "TaggedAddresses":{"lan": TEST_CLOUDIFY_MANAGER,"wan": TEST_CLOUDIFY_MANAGER},
- "NodeMeta":{},
- "ServiceID":"cloudify_manager",
- "ServiceName":"cloudify_manager",
- "ServiceTags":["http://" + TEST_CLOUDIFY_MANAGER + "/api/v2.1"],
- "ServiceAddress": TEST_CLOUDIFY_MANAGER,
- "ServicePort":80,
- "ServiceEnableTagOverride":false,
- "CreateIndex":16,
- "ModifyIndex":16
- }]);
-
-nock(CONSUL_URL).persist().get('/v1/catalog/service/inventory')
- .reply(200, [{
- "ID": "",
- "Node": "inventory_test",
- "Address": "inventory",
- "Datacenter": "rework-central",
- "TaggedAddresses": null,
- "NodeMeta": null,
- "ServiceID": "inventory",
- "ServiceName": "inventory",
- "ServiceTags": [],
- "ServiceAddress": "inventory",
- "ServicePort": 8080,
- "ServiceEnableTagOverride": false,
- "CreateIndex": 8068,
- "ModifyIndex": 8068
- }]);
-
-nock(CLOUDIFY_URL).persist().get(/[/]api[/]v2[.]1[/]node-instances/)
+nock(dh.CLOUDIFY_URL).persist().get(/[/]api[/]v2[.]1[/]node-instances/)
.reply(200, {
"items": [
{
@@ -162,63 +121,27 @@ nock(CLOUDIFY_URL).persist().get(/[/]api[/]v2[.]1[/]node-instances/)
"size": 10000
}
}
- });
-
-describe('test policy on deployment-handler', () => {
- it('starting', function() {
- console.log("go testing deployment-handler");
-
- const conf = require('./../lib/config');
- const logging = require('./../lib/logging');
- const log = logging.getLogger();
-
- console.log("started logger");
- log.debug(REQ_ID, "started logger");
-
- console.log("conf.configure");
-
- return conf.configure()
- .then(function(config) {
- logging.setLevel(config.logLevel);
-
- /* Set up exported configuration */
- config.apiLinks = {"test" : true};
- // exports.config = config;
- process.mainModule.exports.config = config;
-
- console.log("got configuration:", JSON.stringify(config));
-
- log.debug(REQ_ID, "Configuration: " + JSON.stringify(config));
-
- const main_app = require('./../deployment-handler');
- console.log("setting main_app...");
- main_app.set_app();
- console.log("set main_app");
-
- const req_path = "/policy/components";
- const test_txt = "GET " + req_path;
- describe(test_txt, () => {
- console.log(test_txt);
- it('GET all the components with policy from cloudify', function() {
- console.log("chai", test_txt);
- return chai.request(main_app.app).get(req_path)
- .then(function(res) {
- console.log("res for", test_txt, JSON.stringify(res.body));
- log.debug(REQ_ID, "received " + JSON.stringify(res.body));
- expect(res).to.have.status(200);
- expect(res).to.be.json;
- })
- .catch(function(err) {
- console.error("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;
+ describe(test_txt, () => {
+ console.log(test_txt);
+ it('GET all the components with policy from cloudify', function() {
+ return chai.request(dh_server.app).get(req_path)
+ .then(function(res) {
+ console.log("res for", test_txt, res.text);
+ expect(res).to.have.status(200);
+ expect(res).to.be.json;
+ })
+ .catch(function(err) {
+ console.error("err for", test_txt, err);
+ throw err;
});
- });
- })
- .catch(function(e) {
- const error = "test of deployment-handler exiting due to startup problem: " + e.message;
- console.error(error);
- throw e;
});
});
-}); \ No newline at end of file
+}
+
+dh.add_tests([test_get_policy_components]);
diff --git a/tests/test_zzz_run.js b/tests/test_zzz_run.js
new file mode 100644
index 0000000..8ae405a
--- /dev/null
+++ b/tests/test_zzz_run.js
@@ -0,0 +1,21 @@
+/*
+Copyright(c) 2018 AT&T Intellectual Property. All rights reserved.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and limitations under the License.
+*/
+
+"use strict";
+
+const dh = require('./mock_deployment_handler');
+
+dh.run_dh();