Update process: check sanity of customer repository: are etc/ and

opt/directories contained? If not, remove the repository and clone it
again. This is done without checking the ISMAS-WAIT-button.
This commit is contained in:
Gerhard Hoffmann 2023-10-19 13:41:44 +02:00
parent 4469a23f9c
commit 4bb8e241b6

View File

@ -237,150 +237,184 @@ void Worker::privateUpdate() {
emit disableExit(); emit disableExit();
m_returnCode = -1; m_returnCode = -1;
QDir customerRepository(m_customerRepository); QDir customerRepository(m_customerRepository);
if (!customerRepository.exists()) { QDir customerRepositoryEtc(QDir::cleanPath(m_customerRepository + QDir::separator() + "etc/"));
emit appendText("\nInitializing customer environment ...");
startProgressLoop();
if (m_gc.gitCloneAndCheckoutBranch()) {
stopProgressLoop();
emit replaceLast("Initializing customer environment", UPDATE_STEP_DONE);
setProgress(5); Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 1: CHECK SANITY OF CUSTOMER REPOSITORY %1...")
.arg(m_customerRepository));
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_SUCCESS, bool initialClone = false; // the customer repository is cloned without
QString("CLONED AND CHECKED OUT: ") + m_customerRepository); // checking the ISMAS-trigger (WAIT-)button.
// but if there was a sane repository
// available, then the trigger-button must
// have been activated in ISMAS.
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, bool continueUpdate = true; // check if git-clone command has timed-out,
QString("#M=APISM#C=CMD_EVENT#J=") + // resulting in a corrupted git-repository, which
m_ismasClient.cloneAndCheckoutCustomerRepository( // does not contain an ./etc-directory
m_updateStatus.m_statusDescription)); if (isRepositoryCorrupted()) {
QString s("CORRUPTED CUSTOMER REPOSITORY. REPAIRING...");
setProgress(10); if ((continueUpdate = repairCorruptedRepository()) == true) {
Utils::printUpdateStatusMsg(
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, QStringList() << s <<
QString("#M=APISM#C=CMD_EVENT#J=") + QString("CORRUPTED CUSTOMER REPOSITORY. REPAIRING...DONE"));
m_ismasClient.updateOfPSASucceeded(""));
setProgress(100);
m_ismasClient.setProgressInPercent(100);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
} else { } else {
stopProgressLoop(); Utils::printUpdateStatusMsg(
setProgress(0); QStringList() << s <<
QString("CORRUPTED CUSTOMER REPOSITORY. REPAIRING...FAIL"));
emit replaceLast("Initializing customer environment", UPDATE_STEP_FAIL);
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CLONE_AND_CHECKOUT_FAILURE,
QString("CLONE OR CHECKOUT FAILED: ") + m_customerRepository);
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.errorGitClone(100, m_updateStatus.m_statusDescription));
m_returnCode = -3;
} }
} else { }
if (updateTriggerSet(5)) {
if (customerEnvironment(30)) {
m_ismasClient.setProgressInPercent(50);
if (filesToUpdate()) {
// send message to ISMAS about files which have been
// checked in into git repository
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
QString("Files to update: ") + m_filesToUpdate.join(','));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
if (updateFiles(60)) {
m_ismasClient.setProgressInPercent(70);
if (syncCustomerRepositoryAndFS()) {
m_ismasClient.setProgressInPercent(80);
if (sendIsmasLastVersionNotification()) {
m_ismasClient.setProgressInPercent(90);
sentIsmasLastVersionNotification = true;
if (saveLogFile()) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
// mark update as activated -> this resets the WAIT button if (continueUpdate) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
m_returnCode = 0; Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 1: CHECKED SANITY OF CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 2: FETCH CUSTOMER REPOSITORY %1...")
.arg(m_customerRepository));
if ((continueUpdate = customerRepository.exists()) == false) {
emit appendText("\nInitializing customer environment ...");
startProgressLoop();
for (int i = 0; i < 5; ++i) { // try to checkout git repository
setProgress(i); // and switch to branch
if (m_gc.gitCloneAndCheckoutBranch()) {
if (!isRepositoryCorrupted()) {
emit replaceLast("Initializing customer environment", UPDATE_STEP_DONE);
m_returnCode = sendCloneAndCheckoutSuccess();
continueUpdate = true;
initialClone = true;
Utils::printInfoMsg("INITIAL CLONE DONE");
break;
}
}
QThread::sleep(1); // maybe git needs more time
}
if (continueUpdate == false) {
emit replaceLast("Initializing customer environment", UPDATE_STEP_FAIL);
m_returnCode = sendCloneAndCheckoutFailure();
}
}
}
if (continueUpdate) { // repository is neither not existent nor
// corrupted. check now if the ISMAS-trigger
// (WAIT-BUTTON) is activated even in case of
// initial checkout
if (!initialClone) {
Utils::printUpdateStatusMsg(
QStringList()
<< QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
.arg(m_customerRepository)
<< QString("STEP 3: CHECK ISMAS-UPDATE-TRIGGER FOR WAIT-STATUS..."));
//if ((continueUpdate = updateTriggerSet(10)) == false) {
// m_returnCode = sendIsmasTriggerFailure();
//}
if (updateTriggerSet(10)) {
if (customerEnvironment(30)) {
m_ismasClient.setProgressInPercent(50);
if (filesToUpdate()) {
// send message to ISMAS about files which have been
// checked in into git repository
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECK_FILES_TO_UPDATE_SUCCESS,
QString("Files to update: ") + m_filesToUpdate.join(','));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAContinues("CHECK-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription));
if (updateFiles(60)) {
m_ismasClient.setProgressInPercent(70);
if (syncCustomerRepositoryAndFS()) {
m_ismasClient.setProgressInPercent(80);
if (sendIsmasLastVersionNotification()) {
m_ismasClient.setProgressInPercent(90);
sentIsmasLastVersionNotification = true;
if (saveLogFile()) {
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSASucceeded(""));
// mark update as activated -> this resets the WAIT button
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAActivated());
m_returnCode = 0;
} else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED,
QString("Saving log files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"SAVE-LOG-FILES",
m_updateStatus.m_statusDescription));
m_returnCode = -11;
}
} else { } else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::SAVE_LOG_FILES_FAILED, m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED,
QString("Saving log files failed")); QString("Sending ISMAS last version failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"SAVE-LOG-FILES", "ISMAS-SEND-LAST-VERSION",
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
m_returnCode = -11; m_returnCode = -10;
} }
} else { } else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_SEND_LAST_VERSION_FAILED, m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE,
QString("Sending ISMAS last version failed")); QString("Syncing files to update failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"ISMAS-SEND-LAST-VERSION", "RSYNC-UPDATE-FILES",
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
m_returnCode = -10; m_returnCode = -9;
} }
} else { } else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::RSYNC_UPDATES_FAILURE, m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED,
QString("Syncing files to update failed")); QString("Updating files failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"RSYNC-UPDATE-FILES", "UPDATE-FILES",
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
m_returnCode = -9; m_returnCode = -8;
} }
} else { } else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::PSA_UPDATE_FILES_FAILED, m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
QString("Updating files failed")); QString("No files to update"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"UPDATE-FILES", "FETCH-FILES-TO-UPDATE",
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
m_returnCode = -8; m_returnCode = -7;
} }
} else { } else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE, m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE,
QString("No files to update")); QString("Configuring customer environment failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") + QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR, m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"FETCH-FILES-TO-UPDATE", "GIT-CHECKOUT-BRANCH",
m_updateStatus.m_statusDescription)); m_updateStatus.m_statusDescription));
m_returnCode = -7; m_returnCode = -6;
} }
} else { } else {
m_updateStatus = UpdateStatus(UPDATE_STATUS::GIT_CHECKOUT_BRANCH_FAILURE, m_returnCode = sendIsmasTriggerFailure();
QString("Configuring customer environment failed"));
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT,
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"GIT-CHECKOUT-BRANCH",
m_updateStatus.m_statusDescription));
m_returnCode = -6;
} }
} else { } else { // initialClone
m_updateStatus = UpdateStatus(UPDATE_STATUS::ISMAS_UPDATE_TRIGGER_SET_FAILURE, Utils::printUpdateStatusMsg(
QString("ISMAS update trigger wrong")); QString("STEP 2: FETCHED CUSTOMER REPOSITORY %1 DONE")
IsmasClient::sendRequestReceiveResponse(IsmasClient::APISM::DB_PORT, .arg(m_customerRepository));
QString("#M=APISM#C=CMD_EVENT#J=") +
m_ismasClient.updateOfPSAFailed(IsmasClient::RESULT_CODE::INSTALL_ERROR,
"CHECK-UPDATE-TRIGGER",
m_updateStatus.m_statusDescription));
m_returnCode = -5;
} }
} }