Skip to content

Fixing licensing in docker building cicd #1521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def pytest_configure(config):

# determine if we can launch an instance of MAPDL locally
# start with ``False`` and always assume the remote case
local = [False]
LOCAL = [False]

# check if the user wants to permit pytest to start MAPDL
START_INSTANCE = get_start_instance()
Expand Down Expand Up @@ -250,7 +250,7 @@ def mapdl_corba(request):
mapdl.prep7()


@pytest.fixture(scope="session", params=local)
@pytest.fixture(scope="session", params=LOCAL)
def mapdl(request, tmpdir_factory):
# don't use the default run location as tests run multiple unit testings
run_path = str(tmpdir_factory.mktemp("ansys"))
Expand Down
51 changes: 27 additions & 24 deletions tests/test_licensing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
import time
import types

from conftest import LOCAL as IS_LOCAL
import pytest

from ansys.mapdl.core import errors, launch_mapdl, licensing
from ansys.mapdl.core.launcher import check_valid_ansys, get_start_instance
from ansys.mapdl.core.misc import threaded

try:
LIC_INSTALLED = os.path.isfile(licensing.get_ansys_license_utility_path())
except:
LIC_INSTALLED = None

skip_no_lic_bin = pytest.mark.skipif(
not (LIC_INSTALLED and IS_LOCAL),
reason="Requires being in 'local' mode and have license utilities binaries.",
)

skip_launch_mapdl = pytest.mark.skipif(
not get_start_instance() and check_valid_ansys(),
reason="Must be able to launch MAPDL locally",
Expand All @@ -29,33 +40,33 @@
"""

MSG_LIC_DENIED = """
2021/09/06 22:39:38 DENIED ansys 21.2 (2021.0512) 1/0/0/0 1/1/1/1 10268:FEAT_ANSYS:gayuso@AAPDDqVK5WqNLrt.win.ansys.com:winx64 7368:192.168.18.10
2021/09/06 22:39:38 DENIED ansys 21.2 (2021.0512) 1/0/0/0 1/1/1/1 1026:FEAT_ANSYS:user@machine.win.ansys.com:winx64 0000:1.1.1.1
Request name ansys does not exist in the licensing pool.
Cannot connect to license server system.
The license server manager (lmgrd) has not been started yet,
the wrong port@host or license file is being used, or the
port or hostname in the license file has been changed.
Feature: ansys
Server name: 192.168.18.10
License path: 1055@AAPDDqVK5WqNLrt;
Server nam0000 1.1.1.1
License path: 1055@machine;
FlexNet Licensing error:-15,578. System Error: 10049 "WinSock: Invalid address"
"""
MSG_LIC_CHECKOUT = """
2021/09/06 22:39:38 CHECKOUT ansys 21.2 (2021.0512) 1/0/0/0 1/1/1/1 10268:FEAT_ANSYS:gayuso@AAPDDqVK5WqNLrt.win.ansys.com:winx64 7368:192.168.18.10
2021/09/06 22:39:38 CHECKOUT ansys 21.2 (2021.0512) 1/0/0/0 1/1/1/1 1026:FEAT_ANSYS:user@machine.win.ansys.com:winx64 0000:1.1.1.1
Request name ansys does not exist in the licensing pool.
Cannot connect to license server system.
The license server manager (lmgrd) has not been started yet,
the wrong port@host or license file is being used, or the
port or hostname in the license file has been changed.
Feature: ansys
Server name: 192.168.18.10
License path: 1055@AAPDDqVK5WqNLrt;
Server nam0000 1.1.1.1
License path: 1055@machine;
FlexNet Licensing error:-15,578. System Error: 10049 "WinSock: Invalid address"
"""


# TEST-NET-3 (not quite a black hole, but set aside by RFC 5737)
test_net_3 = "203.0.113.0"
TEST_NET_3 = "203.0.113.0"

PATH = os.path.dirname(os.path.abspath(__file__))
SAMPLE_LOG_PATH = os.path.join(PATH, "test_files", "sample_lic_log.log")
Expand All @@ -71,16 +82,6 @@ def write_log(path):
time.sleep(0.01)


try:
LIC_INSTALLED = os.path.isfile(licensing.get_ansys_license_utility_path())
except:
LIC_INSTALLED = None

skip_no_lic_bin = pytest.mark.skipif(
not LIC_INSTALLED, reason="Requires local license utilities binaries"
)


@pytest.fixture(scope="module")
def license_checker():
return licensing.LicenseChecker()
Expand All @@ -104,7 +105,7 @@ def test__checkout_wrong_license(license_checker):

@skip_no_lic_bin
def test__checkout_license_fail(license_checker):
output = license_checker._checkout_license("meba", test_net_3, 1055)
output = license_checker._checkout_license("meba", TEST_NET_3, 1055)
assert "CHECKOUT FAILED" in output


Expand All @@ -121,7 +122,7 @@ def test__check_mech_license_available_specified_license(license_checker):
@skip_no_lic_bin
def test_check_mech_license_available_fail(license_checker):
with pytest.raises(errors.LicenseServerConnectionError):
license_checker._check_mech_license_available(test_net_3)
license_checker._check_mech_license_available(TEST_NET_3)


def test_get_ansys_license_debug_file_tail_timeout(license_checker):
Expand Down Expand Up @@ -166,7 +167,7 @@ def test_license_checker(tmpdir, license_checker):
@skip_no_lic_bin
def test_check_license_file(tmpdir):
timeout = 15
checker = licensing.LicenseChecker(verbose=True, timeout=timeout)
checker = licensing.LicenseChecker(timeout=timeout)
# start the license check in the background
checker.start(checkout_license=False)

Expand Down Expand Up @@ -278,8 +279,9 @@ def test_stop_license_checker():
license_checker.start()
time.sleep(1)

license_checker.stop = True
time.sleep(1) # giving some time to reach end of the file.
license_checker.stop = True # Overwriting the connect attribute
# so the thread is killed right after.
time.sleep(2)
assert not license_checker._lic_file_thread.is_alive()


Expand All @@ -289,8 +291,9 @@ def test_is_connected_license_checker():
license_checker.start()
time.sleep(1)

license_checker.is_connected = True
time.sleep(1) # giving some time to reach end of the file.
license_checker.is_connected = True # Overwriting the connect attribute
# so the thread is killed right after.
time.sleep(2)
assert not license_checker._lic_file_thread.is_alive()


Expand Down