-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for non-interactive Dockerfile, and fix failing/stalling te…
…sts.
- Loading branch information
Showing
14 changed files
with
272 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2024 The MathWorks, Inc. | ||
|
||
name: Build and Test the "Non-Interactive" Dockerfile | ||
|
||
# Trigger this workflow either manually or when a new change is pushed to the | ||
# repo (except .md files) | ||
on: | ||
workflow_dispatch: | ||
push: | ||
# Trigger the workflow when the Dockerfile or any file under tests/ is modified | ||
paths: | ||
- "alternates/non-interactive/Dockerfile" | ||
- "tests/**" | ||
- "!tests/**.md" | ||
schedule: | ||
# Run at 00:00 on every Monday (1st Day of the Week) | ||
- cron: "0 0 * * 1" | ||
|
||
env: | ||
IMAGE_BASE_NAME: matlab-non-interactive | ||
ALT_PATH: alternates/non-interactive | ||
|
||
jobs: | ||
build-test-image: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
matlab-release: [r2024a, r2023b, r2023a, r2022b, r2022a, r2021b, r2021a, r2020b] | ||
|
||
steps: | ||
- name: Checkout repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build image locally | ||
uses: docker/build-push-action@v4 | ||
with: | ||
platforms: linux/amd64 | ||
context: ${{ env.ALT_PATH }} | ||
load: true | ||
build-args: | | ||
MATLAB_RELEASE=${{ matrix.matlab-release }} | ||
tags: | | ||
${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }} | ||
- name: Set up Python 3 | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install test dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
if [ -f tests/requirements.txt ]; then pip install -r tests/requirements.txt; fi | ||
- name: Test container | ||
working-directory: tests | ||
env: | ||
IMAGE_NAME: ${{ env.IMAGE_BASE_NAME }}:${{ matrix.matlab-release }} | ||
BATCH_TOKEN: ${{ secrets.MATLAB_BATCH_TOKEN_EXPIRES_03_2025 }} | ||
run: | | ||
python -m unittest ${{ env.ALT_PATH }}/test_matlabbatch.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# Copyright 2024 The MathWorks, Inc. | ||
|
||
""" | ||
Test class to validate the "non-interactive" Dockerfile. | ||
This test suite require a valid batch licensing token. | ||
""" | ||
|
||
from utils import base, helpers | ||
import docker | ||
import os | ||
import unittest | ||
|
||
################################################################################ | ||
|
||
|
||
class TestMatlabBatch(base.TestCase): | ||
"""Extend the test methods of the base TestCase class.""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Run the container""" | ||
cls.client = docker.from_env() | ||
image_name = helpers.get_image_name() | ||
cls.container = cls.client.containers.run( | ||
image=image_name, | ||
detach=True, | ||
stdin_open=True, | ||
environment = {"MLM_LICENSE_TOKEN": os.getenv("BATCH_TOKEN")}, | ||
) | ||
cls.expected_ddux_force_enable = "true" | ||
cls.expected_ddux_tags = [ | ||
"MATLAB:BATCHLICENSING:DOCKERFILE:V1", | ||
] | ||
cls.install_dirname = "mpm" | ||
cls.release_tag = helpers.get_release_tag(image_name) | ||
super().setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Stop and remove the container""" | ||
cls.container.stop() | ||
cls.container.remove() | ||
cls.client.close() | ||
|
||
############################################################################ | ||
|
||
def test_matlabbatch_runs(self): | ||
"""Test that matlab-batch runs successfully and that the matlab release is the correct one.""" | ||
matlabbatch_cmd = 'matlab-batch "disp(version(\'-release\'))"' | ||
cmd_output = self.host.run(matlabbatch_cmd) | ||
self.assertTrue( | ||
cmd_output.succeeded, | ||
f"Unable to run matlab-batch correctly: {cmd_output.stdout}", | ||
) | ||
expectedRelease=self.release_tag.strip().lstrip("Rr") | ||
self.assertRegex(cmd_output.stdout, expectedRelease) | ||
|
||
def test_matlabbatch_version(self): | ||
"""Test the version of matlab-batch installed in the container""" | ||
readme_filepath = "../alternates/non-interactive/MATLAB-BATCH.md" | ||
expected_version = helpers.get_changelog_mb_version(readme_filepath) | ||
expected_output = f"matlab-batch {expected_version} (glnxa64)" | ||
version_cmd = f"matlab-batch -version" | ||
self.assertEqual( | ||
expected_output, | ||
self.host.check_output(version_cmd), | ||
"Mismatching versions of matlab-batch in changelog", | ||
) | ||
|
||
|
||
################################################################################ | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Copyright 2022-2023 The MathWorks, Inc. | ||
# Copyright 2022-2024 The MathWorks, Inc. | ||
|
||
docker>=6.1.2 | ||
pytest-testinfra>=8.1.0 | ||
docker | ||
markdown-it-py | ||
pytest-testinfra |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.