diff --git a/.github/workflows/build-test-and-publish-network-licensing-manager.yml b/.github/workflows/build-test-and-publish-network-licensing-manager.yml index 8062878..9e4444c 100644 --- a/.github/workflows/build-test-and-publish-network-licensing-manager.yml +++ b/.github/workflows/build-test-and-publish-network-licensing-manager.yml @@ -58,6 +58,7 @@ jobs: python-version: "3.10" - name: Install test dependencies + working-directory: ./network-license-manager/tests run: | python -m pip install --upgrade pip pip install -r requirements.txt diff --git a/network-license-manager/tests/requirements.txt b/network-license-manager/tests/requirements.txt index 19866a6..c99fd80 100644 --- a/network-license-manager/tests/requirements.txt +++ b/network-license-manager/tests/requirements.txt @@ -1,2 +1,4 @@ +# Copyright 2024 The MathWorks, Inc. + docker -pytest-testinfra \ No newline at end of file +pytest-testinfra diff --git a/network-license-manager/tests/test_nlm_image.py b/network-license-manager/tests/test_nlm_image.py index 83c276f..5449fbb 100644 --- a/network-license-manager/tests/test_nlm_image.py +++ b/network-license-manager/tests/test_nlm_image.py @@ -7,7 +7,7 @@ import utils -IMAGE_NAME = os.getenv('IMAGE_NAME') +IMAGE_NAME = os.getenv("IMAGE_NAME") class TestNLMImage(unittest.TestCase): diff --git a/network-license-manager/tests/test_nlm_licensing.py b/network-license-manager/tests/test_nlm_licensing.py index eb8bd78..39e0529 100644 --- a/network-license-manager/tests/test_nlm_licensing.py +++ b/network-license-manager/tests/test_nlm_licensing.py @@ -10,14 +10,14 @@ import tempfile -HOSTNAME = os.getenv('HOSTNAME') -PORT = os.getenv('PORT') -MATLAB_RELEASE = os.getenv('MATLAB_RELEASE') -IMAGE_NAME = os.getenv('IMAGE_NAME') +HOSTNAME = os.getenv("HOSTNAME") +PORT = os.getenv("PORT") +MATLAB_RELEASE = os.getenv("MATLAB_RELEASE") +IMAGE_NAME = os.getenv("IMAGE_NAME") LICENSE_FILE_DIR = str(pathlib.Path(os.getenv("LICENSE_FILE_PATH")).parent) -MATLAB_IMAGE = 'mathworks/matlab' +MATLAB_IMAGE = "mathworks/matlab" class TestNLMLicensing(unittest.TestCase): @@ -26,7 +26,6 @@ class TestNLMLicensing(unittest.TestCase): run the network license manager docker image and use it to license matlab """ - @classmethod def setUpClass(cls): cls.client = docker.from_env() @@ -39,7 +38,6 @@ def setUpClass(cls): type="bind", ) - def setUp(self): logdir = tempfile.mkdtemp() self.logs_mount = docker.types.Mount( @@ -51,13 +49,12 @@ def setUp(self): self.logfilepath = pathlib.Path(self.logs_mount["Source"]) / logfilename self.addCleanup(lambda: self.logfilepath.unlink(missing_ok=True)) - def test_license_manager_is_running(self): """ Test that FlexNet Licensing is started when the container is run and that the docker log is copied to the log file """ - nlm = self.client.containers.run( + nlm = self.client.containers.run( image=IMAGE_NAME, init=True, mounts=[self.license_mount, self.logs_mount], @@ -85,35 +82,32 @@ def test_license_manager_is_running(self): ) self.assertEqual(stat.filemode(self.logfilepath.stat().st_mode), "-rw-rw-rw-") - def test_license_manager_shutdown(self): """ Test that FlexLM is shutdown when the container is stopped """ - nlm = self.client.containers.run( + nlm = self.client.containers.run( image=IMAGE_NAME, init=True, mounts=[self.license_mount, self.logs_mount], hostname=HOSTNAME, detach=True, ) - self.addCleanup(lambda: nlm.remove(force=True)) + self.addCleanup(lambda: nlm.remove()) utils.wait_for_logs(nlm, r"\(MLM\) Listener Thread: running") # Stop the container now NLM is running nlm.stop() - self.addCleanup(lambda: nlm.remove()) # Check FlexLM started and stopped nlm_logs = nlm.logs().decode() + self.assertRegex( nlm_logs, r"\(lmgrd\) FlexNet Licensing \(.*\) started on " + HOSTNAME ) # Check LMGRD shutdown and shutdown occurred only once - self.assertEqual( - nlm_logs.count("Shutdown LMGRD"), 1 - ) + self.assertEqual(nlm_logs.count("License Manager has shut down."), 1) self.assertTrue(self.logfilepath.is_file) with open(str(self.logfilepath), "r") as logfile: @@ -123,7 +117,6 @@ def test_license_manager_shutdown(self): "The docker logs and the log file are not the same", ) - def test_nlm_can_license_matlab(self): """ Test that the network license manager Docker container can be used to license @@ -142,7 +135,7 @@ def test_nlm_can_license_matlab(self): output = self.client.containers.run( image=f"{MATLAB_IMAGE}:{MATLAB_RELEASE}", - environment={"MLM_LICENSE_FILE": f"{PORT}@{HOSTNAME}"}, + environment={"MLM_LICENSE_FILE": f"{PORT}@{HOSTNAME}"}, network_mode=f"container:{nlm.id}", command="-batch pi", auto_remove=True, @@ -152,7 +145,6 @@ def test_nlm_can_license_matlab(self): self.assertIn(f'(MLM) OUT: "MATLAB" matlab@{HOSTNAME}', nlm.logs().decode()) self.assertIn(f'(MLM) IN: "MATLAB" matlab@{HOSTNAME}', nlm.logs().decode()) - def test_no_license(self): """ Test that the container stops if no license is provided diff --git a/ubi-hardening-extras/tests/requirements.txt b/ubi-hardening-extras/tests/requirements.txt index 52b35fc..47049be 100644 --- a/ubi-hardening-extras/tests/requirements.txt +++ b/ubi-hardening-extras/tests/requirements.txt @@ -1,4 +1,4 @@ -# Copyright 2023 The MathWorks, Inc. +# Copyright 2023-2024 The MathWorks, Inc. -docker>=6.1.2 -pytest-testinfra>=9.0 +docker +pytest-testinfra