diff --git a/install/installation.md b/install/installation.md index 4b5f3807..1c3f9f0e 100644 --- a/install/installation.md +++ b/install/installation.md @@ -178,6 +178,7 @@ sudo python bootstrap_gunicorn.py 4. In case of any gunicorn error try manually running `/etc/init.d/platform start` command and recheck the platform status. ### Setting Up The Bucket + After the completion of the automated installation of the platform, the following folder structure is created in the 'SAMPLE_REPOSITORY' set during installation: - `LogFiles/` - Directory containing log files of the tests completed - `QueuedFiles/` - Directory containing files related to queued samples @@ -198,6 +199,16 @@ The `serve_file_download` function in the `utility.py` file implements the gener For more information about Signed URLs, you can refer to the [official documentation](https://cloud.google.com/storage/docs/access-control/signed-urls). +## Setting up cron job to run tests + +Now the server being running, new tests would be queued and therefore a cron job is to be setup to run those tests. +The file `mod_ci/cron.py` is to be run in periodic intervals. To setup a cron job follow the steps below: +1. Open your terminal and enter the command `sudo crontab -e`. +2. To setup a cron job that runs this file every 10 minutes, append this at the bottom of the file + ``` + */10 * * * * python /var/www/sample-platform/mod_ci/cron.py > /var/www/sample-platform/logs/cron.log 2>&1 + ``` + Change the `/var/www/sample-plaform` directory, if you have installed the platform in a different directory. ## File upload size for HTTP diff --git a/mod_ci/controllers.py b/mod_ci/controllers.py index 9ccfccd7..92f7d747 100755 --- a/mod_ci/controllers.py +++ b/mod_ci/controllers.py @@ -422,6 +422,8 @@ def start_test(compute, app, db, repository: Repository.Repository, test, bot_to if 'error' not in result: db.add(status) db.commit() + else: + log.error(f"Error creating test instance for test {test.id}, result: {result}") def create_instance(compute, project, zone, test, reportURL) -> Dict: diff --git a/run.py b/run.py index 14043646..394531b6 100755 --- a/run.py +++ b/run.py @@ -65,7 +65,7 @@ storage_client_bucket = storage_client.bucket(app.config.get('GCS_BUCKET_NAME', '')) # Save build commit -repo = git.Repo(search_parent_directories=True) +repo = git.Repo(app.config.get('INSTALL_FOLDER', '')) app.config['BUILD_COMMIT'] = repo.head.object.hexsha diff --git a/tests/base.py b/tests/base.py index c070645f..4a311eec 100644 --- a/tests/base.py +++ b/tests/base.py @@ -93,6 +93,7 @@ def generate_signed_url(**kwargs): def load_config(file): """Load start config.""" + from utility import ROOT_DIR key_paths = generate_keys() with open(key_paths['secret_key_path'], 'rb') as secret_key_file: secret_key = secret_key_file.read() @@ -116,7 +117,8 @@ def load_config(file): 'CSRF_SESSION_KEY': secret_csrf, 'ZONE': "test_zone", 'PROJECT_NAME': "test_zone", - 'GCS_SIGNED_URL_EXPIRY_LIMIT': 720 + 'GCS_SIGNED_URL_EXPIRY_LIMIT': 720, + 'INSTALL_FOLDER': ROOT_DIR, } diff --git a/tests/test_ci/test_controllers.py b/tests/test_ci/test_controllers.py index b9734a48..96b1d8cc 100644 --- a/tests/test_ci/test_controllers.py +++ b/tests/test_ci/test_controllers.py @@ -241,7 +241,18 @@ def extractall(*args, **kwargs): customized_test = CustomizedTest(1, 1) g.db.add(customized_test) g.db.commit() + + # Test when gcp create instance fails + mock_wait_for_operation.return_value = 'error occurred' + start_test(mock.ANY, self.app, mock_g.db, repository, test, mock.ANY) + mock_g.db.commit.assert_not_called() + mock_create_instance.reset_mock() + mock_wait_for_operation.reset_mock() + + # Test when gcp create instance is successful + mock_wait_for_operation.return_value = 'success' start_test(mock.ANY, self.app, mock_g.db, repository, test, mock.ANY) + mock_g.db.commit.assert_called_once() mock_create_instance.assert_called_once() mock_wait_for_operation.assert_called_once()