Skip to content

Commit

Permalink
Fixes NLM workflow file
Browse files Browse the repository at this point in the history
  • Loading branch information
epaganon authored and Prabhakar Kumar committed May 29, 2024
1 parent c402404 commit e15c298
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion network-license-manager/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Copyright 2024 The MathWorks, Inc.

docker
pytest-testinfra
pytest-testinfra
2 changes: 1 addition & 1 deletion network-license-manager/tests/test_nlm_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import utils


IMAGE_NAME = os.getenv('IMAGE_NAME')
IMAGE_NAME = os.getenv("IMAGE_NAME")


class TestNLMImage(unittest.TestCase):
Expand Down
30 changes: 11 additions & 19 deletions network-license-manager/tests/test_nlm_licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()
Expand All @@ -39,7 +38,6 @@ def setUpClass(cls):
type="bind",
)


def setUp(self):
logdir = tempfile.mkdtemp()
self.logs_mount = docker.types.Mount(
Expand All @@ -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],
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ubi-hardening-extras/tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e15c298

Please sign in to comment.