Skip to content

Release 19 feb #308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 18, 2024
Merged
35 changes: 25 additions & 10 deletions commands/build_info.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const request = require("request");
const https = require('https');
const axios = require('axios');
const constants = require("./utils/constants.js");
const process = require("process");

Expand Down Expand Up @@ -40,6 +41,7 @@ function get_build_info(args) {
}
}
let options = {
method: 'get',
url: constants[env].BUILD_BASE_URL + args.buildId,
auth: {
username: username,
Expand All @@ -55,25 +57,38 @@ function get_build_info(args) {
return;
} else {
if (args["reject_unauthorized"] == "false") {
options["rejectUnauthorized"] = false;
options.httpsAgent = new https.Agent({ rejectUnauthorized: false });
console.log("Setting rejectUnauthorized to false for web requests");
}
}
}

request.get(options, (err, res, body) => {
if (err) {
reject(err);
axios(options)
.then(response => {
if (response.data.status == "success") {
resolve(response.data.data);
} else {
if (res.statusCode == "401") {
resolve(response.data.message);
}
})
.catch(error => {
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
if (error.response.status == 401) {
resolve("Unauthorized");
} else if (JSON.parse(body).status == "success") {
resolve(JSON.parse(body).data);
} else {
resolve(JSON.parse(body).message);
console.log(error.response.data);
}
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
// http.ClientRequest in node.js
console.log(error.cause);
} else {
reject(error);
}
});
})
});
}

Expand Down
79 changes: 40 additions & 39 deletions commands/build_stop.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const request = require("request");
const https = require('https');
const axios = require('axios');
const constants = require("./utils/constants.js");
const process = require("process");
const fs = require("fs");
function stop_session(args) {
function stop_build(args) {
return new Promise(function (resolve, reject) {
var username = "";
var access_key = "";
Expand All @@ -25,33 +26,33 @@ function stop_session(args) {
} else {
reject("Access Key not provided");
}
if ("stop_last_session" in args) {
if ("stop_last_build" in args) {
const file_path = "lambdatest_run.json";
if (fs.existsSync(file_path)) {
let lambda_run = fs.readFileSync(file_path);
try {
let lambda_run_obj = JSON.parse(lambda_run);
if (!("session_id" in lambda_run_obj)) {
throw new Error("session_id is missing from the file");
if (!("build_id" in lambda_run_obj)) {
throw new Error("build_id is missing from the file");
}
args.session_id = lambda_run_obj.session_id;
args.build_id = lambda_run_obj.build_id;
} catch (e) {
reject(
"Error!! lambdatest_run.json file is tampered Err: " + e.message
);
}
} else {
reject(
"Error!! Last session details not found, lambdatest_run.json file not present!!"
"Error!! Last Build details not found, lambdatest_run.json file not present!!"
);
}
} else {
if (
!("session_id" in args) ||
args["session_id"] == "" ||
args["session_id"] == undefined
!("build_id" in args) ||
args["build_id"] == "" ||
args["build_id"] == undefined
) {
reject("Error!! Please provide a Session ID");
reject("Error!! Please provide a Build ID");
}
}
var env = "prod";
Expand All @@ -66,7 +67,8 @@ function stop_session(args) {
}

let options = {
url: constants[env].BUILD_STOP_URL + args.session_id,
method: 'put',
url: constants[env].BUILD_STOP_URL + "?buildId=" + args.build_id,
headers: {
Authorization: "Token " + access_key,
Username: username,
Expand All @@ -82,44 +84,43 @@ function stop_session(args) {
return;
} else {
if (args["reject_unauthorized"] == "false") {
options["rejectUnauthorized"] = false;
options.httpsAgent = new https.Agent({ rejectUnauthorized: false });
console.log("Setting rejectUnauthorized to false for web requests");
}
}
}
request.put(options, function (err, resp, body) {
if (err) {
reject(err);

axios(options)
.then(response => {
if(response.data.length == 0){
resolve("No tests to stop in build " + args.build_id);
} else {
try {
responseData = JSON.parse(body);
} catch (e) {
console.log("Error in JSON response", body);
responseData = null;
}
if (resp.statusCode != 200) {
if (responseData && responseData["error"]) {
reject(responseData["error"]);
} else {
console.log(responseData);
reject("error", responseData);
}
} else {
if (responseData.length == 0) {
resolve("No tests to stop in session " + args.session_id);
}
resolve(
"Session Stopped successfully, No. of tests stopped are: " +
responseData.length
);
resolve(
"Build Stopped successfully, No. of tests stopped are: " +
response.data.length
);
}
})
.catch(error => {
if (error.response != null) {
if (error.response.status != 200) {
reject(error.response.data)
}
} else if (error.request) {
// The request was made but no response was received
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of http.ClientRequest in node.js
reject(error.cause);
} else {
reject(error);
}
});
})


});
}

module.exports = function (args) {
stop_session(args)
stop_build(args)
.then(function (resp) {
console.log(resp);
})
Expand Down
82 changes: 58 additions & 24 deletions commands/generate_reports.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const request = require("request");
const https = require('https');
const axios = require('axios');
const constants = require("./utils/constants.js");
const process = require("process");
const build_stats = require("./utils/poller/build_stats.js");
Expand Down Expand Up @@ -27,33 +28,34 @@ function download_artefact(
const stream = fs.createWriteStream(file_path);
stream.end();
let options = {
method: 'get',
url: constants[env].REPORT_URL + test_id,
auth: {
username: username,
password: access_key,
},
gzip: true,
timeout: 120000,
responseType: 'stream'
};
if (rejectUnauthorized == false) {
options["rejectUnauthorized"] = false;
options.httpsAgent = new https.Agent({ rejectUnauthorized: false });
console.log("Setting rejectUnauthorized to false for web requests");
}

request(options, (err, res, body) => {
if (err) {
reject(err);
}
response_code = res.statusCode;
resp = res
}).pipe(
fs
.createWriteStream(file_path, {
axios(options)
.then((response) => {
response_code = response.status;
resp = response;
response.data.pipe(
fs.createWriteStream(file_path, {
overwrite: true,
})
.on("finish", function () {
if (response_code == 200) {
const zip = new StreamZip({ file: file_path });
);

response.data.on('end', function () {
if (response_code == 200) {
const zip = new StreamZip({ file: file_path });
zip.on("ready", () => {
zip.extract(null, old_path, (err, count) => {
zip.close();
Expand All @@ -64,18 +66,41 @@ function download_artefact(
: `Extracted ${count} entries for ` + test_id
);
});
});
} else {
fs.unlinkSync(file_path);
if (resp.body != null) {
const responseObject = JSON.parse(resp.body);
const dataValue = responseObject.data;
})
}
});

})
.catch((error) => {

if (error.response) {
resp = error.response
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
if (error.response.status == 401) {
resolve("Unauthorized");
} else {
fs.unlinkSync(file_path);
if (resp.data != null) {
const responseObject = resp.data;
const dataValue = responseObject.data;
if (dataValue != null) {
reject("Could not download artefacts for test id " + test_id + " with reason " + dataValue);
} else {
reject("Could not download artefacts for test id " + test_id);
}
reject("Could not download artefacts for test id " + test_id);
}
})
);
reject("Could not download artefacts for test id " + test_id);
}
} else if (error.request) {
console.log(error.cause);
} else {
reject(error);
}

});


});
}

Expand Down Expand Up @@ -233,6 +258,15 @@ function generate_report(args) {
});
}

function generate_report_command(args) {
generate_report(args)
.then(function (resp) {})
.catch(function (err) {
console.log("ERR:", err);
});
};

module.exports = {
generate_report:generate_report
generate_report:generate_report,
generate_report_command:generate_report_command
};
6 changes: 6 additions & 0 deletions commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ module.exports = function (args) {
]
) {
process.exit(exit_code);
} else {
process.exit(0);
}
})
.catch(function (error) {
Expand Down Expand Up @@ -151,11 +153,15 @@ module.exports = function (args) {
.then(function (exit_code) {
if (lt_config["run_settings"]["exit-on-failure"]) {
process.exit(exit_code);
} else {
process.exit(0);
}
})
.catch(function (error) {
if (lt_config["run_settings"]["exit-on-failure"]) {
process.exit(1);
} else {
process.exit(0);
}
});
}
Expand Down
Loading