Skip to content

Commit

Permalink
[IMPROVEMENT] Add documentation to add cron job, nit changes (#863)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarun-Arora authored Aug 29, 2023
1 parent 4a71b6e commit 46fc52b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
11 changes: 11 additions & 0 deletions install/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions mod_ci/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
4 changes: 3 additions & 1 deletion tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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,
}


Expand Down
11 changes: 11 additions & 0 deletions tests/test_ci/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 46fc52b

Please sign in to comment.