Skip to content

Adding Ubuntu docker image as remote #1636

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 20 commits into from
Nov 22, 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
2 changes: 1 addition & 1 deletion .ci/start_mapdl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ docker run \
-p $PYMAPDL_PORT:50052 \
-p $PYMAPDL_DB_PORT:50055 \
$MAPDL_IMAGE \
-smp > log.txt &
-smp -np 2 > log.txt &
grep -q 'Server listening on' <(timeout 60 tail -f log.txt)
# python -c "from ansys.mapdl.core import launch_mapdl; print(launch_mapdl())"
18 changes: 18 additions & 0 deletions .ci/start_mapdl_ubuntu.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
docker pull $MAPDL_IMAGE
docker run \
--entrypoint "/bin/bash" \
--name mapdl \
--restart always \
--health-cmd="ps aux | grep \"[/]ansys_inc/.*ansys\.e.*grpc\" -q && echo 0 || echo 1" \
--health-interval=0.5s \
--health-retries=4 \
--health-timeout=0.5s \
--health-start-period=10s \
-e ANSYSLMD_LICENSE_FILE=1055@$LICENSE_SERVER \
-e ANSYS_LOCK="OFF" \
-p $PYMAPDL_PORT:50052 \
-p $PYMAPDL_DB_PORT:50055 \
$MAPDL_IMAGE /ansys_inc/v222/ansys/bin/mapdl -grpc -dir /jobs -smp -np 2 > log.txt &
grep -q 'Server listening on' <(timeout 60 tail -f log.txt)
# python -c "from ansys.mapdl.core import launch_mapdl; print(launch_mapdl())"
23 changes: 21 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
mapdl-version: ['v21.1.1', 'v21.2.1', 'v22.1.0', 'v22.2.0']
mapdl-version: ['v21.1.1', 'v21.2.1', 'v22.1.0', 'v22.2.0', 'v22.2-ubuntu']

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -349,10 +349,18 @@ jobs:

- name: Pull, launch, and validate MAPDL service
run: .ci/start_mapdl.sh
if: ${{ !contains( matrix.mapdl-version, 'ubuntu') }}
env:
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
MAPDL_IMAGE: ${{ env.DOCKER_PACKAGE }}:${{ matrix.mapdl-version }}

- name: Pull, launch, and validate Ubuntu MAPDL service from private
run: bash .ci/start_mapdl_ubuntu.sh
if: ${{ contains( matrix.mapdl-version, 'ubuntu') }}
env:
LICENSE_SERVER: ${{ secrets.LICENSE_SERVER }}
MAPDL_IMAGE: ghcr.io/pyansys/mapdl:${{ matrix.mapdl-version }}

- name: Unit Testing Requirements Installation
run: |
pip install -r requirements/requirements_tests.txt
Expand Down Expand Up @@ -395,7 +403,7 @@ jobs:
docker exec mapdl /bin/bash -c "ls -R" > ./logs-${{ matrix.mapdl-version }}/docker_files_structure.txt

- name: Collect MAPDL logs on failure
if: always()
if: ${{ always() && !contains( matrix.mapdl-version, 'ubuntu') }}
run: |
docker exec mapdl /bin/bash -c "mkdir -p /mapdl_logs && echo 'Successfully created directory inside docker container'"
docker exec mapdl /bin/bash -c "if compgen -G 'file*.out' > /dev/null ;then cp -f /file*.out /mapdl_logs && echo 'Successfully copied out files.'; fi"
Expand All @@ -404,6 +412,17 @@ jobs:
docker exec mapdl /bin/bash -c "if compgen -G '*.crash' > /dev/null ;then cp -f /*.crash /mapdl_logs && echo 'Successfully copied crash files.'; fi"
docker cp mapdl:/mapdl_logs/. ./logs-${{ matrix.mapdl-version }}/.


- name: Collect MAPDL logs on failure for ubuntu image
if: ${{ always() && contains( matrix.mapdl-version,'ubuntu') }}
run: |
docker exec mapdl /bin/bash -c "mkdir -p /mapdl_logs && echo 'Successfully created directory inside docker container'"
docker exec mapdl /bin/bash -c "if compgen -G '/jobs/file*.out' > /dev/null ;then cp -f /jobs/file*.out /mapdl_logs && echo 'Successfully copied out files.'; fi"
docker exec mapdl /bin/bash -c "if compgen -G '/jobs/file*.err' > /dev/null ;then cp -f /jobs/file*.err /mapdl_logs && echo 'Successfully copied err files.'; fi"
docker exec mapdl /bin/bash -c "if compgen -G '/jobs/file*.log' > /dev/null ;then cp -f /jobs/file*.log /mapdl_logs && echo 'Successfully copied log files.'; fi"
docker exec mapdl /bin/bash -c "if compgen -G '/jobs/*.crash' > /dev/null ;then cp -f /jobs/*.crash /mapdl_logs && echo 'Successfully copied crash files.'; fi"
docker cp mapdl:/mapdl_logs/. ./logs-${{ matrix.mapdl-version }}/.

- name: Tar logs
if: always()
run: |
Expand Down
32 changes: 21 additions & 11 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,22 @@ def asserting_cdread_cdwrite_tests(mapdl):
return "asdf1234" in mapdl.parameters["T_PAR"]


def warns_in_cdread_error_log(mapdl):
def warns_in_cdread_error_log(mapdl, tmpdir):
"""Check for specific warns in the error log associated with using /INPUT with CDB files
instead of CDREAD command."""
error_files = [
each for each in os.listdir(mapdl.directory) if each.endswith(".err")
]
if mapdl._local:
pth = mapdl.directory

else:
list_files = mapdl.list_files()
error_files = [each for each in list_files if each.endswith(".err")]
pth = str(tmpdir.mkdir(random_string()))

for each_file in error_files:
mapdl.download(each_file, pth)

list_files = os.listdir(pth)
error_files = [each for each in list_files if each.endswith(".err")]

# "S 1", "1 H" and "5 H Ansys" are character at the end of lines in the CDB_FILE variable.
# They are allowed in the CDREAD command, but it gives warnings in the /INPUT command.
Expand All @@ -130,7 +140,7 @@ def warns_in_cdread_error_log(mapdl):

warns = []
for each in error_files:
with open(os.path.join(mapdl.directory, each), errors="ignore") as fid:
with open(os.path.join(pth, each), errors="ignore") as fid:
error_log = "".join(fid.readlines())
warns.append(
(warn_cdread_1 in error_log)
Expand Down Expand Up @@ -991,19 +1001,19 @@ def test_cdread_in_python_directory(mapdl, cleared, tmpdir):
"COMB", "model", "cdb"
) # 'COMB' is needed since we use the CDB with the strange line endings.
assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(
mapdl
mapdl, tmpdir
)

clearing_cdread_cdwrite_tests(mapdl)
mapdl.cdread("COMB", "model.cdb")
assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(
mapdl
mapdl, tmpdir
)

clearing_cdread_cdwrite_tests(mapdl)
mapdl.cdread("COMB", "model")
assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(
mapdl
mapdl, tmpdir
)

finally:
Expand All @@ -1014,21 +1024,21 @@ def test_cdread_in_python_directory(mapdl, cleared, tmpdir):
fullpath = str(tmpdir.join("model.cdb"))
mapdl.cdread("COMB", fullpath)
assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(
mapdl
mapdl, tmpdir
)

clearing_cdread_cdwrite_tests(mapdl)
fullpath = str(tmpdir.join("model"))
mapdl.cdread("COMB", fullpath, "cdb")
assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(
mapdl
mapdl, tmpdir
)

clearing_cdread_cdwrite_tests(mapdl)
fullpath = str(tmpdir.join("model"))
mapdl.cdread("COMB", fullpath)
assert asserting_cdread_cdwrite_tests(mapdl) and not warns_in_cdread_error_log(
mapdl
mapdl, tmpdir
)


Expand Down
50 changes: 30 additions & 20 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ def test_load_file_local(mapdl, tmpdir, file_):

In CICD it seems we cannot write to the root folder '/'.
Hence we cannot really test the files are being uploaded.
So the assert in the '/' directory are commented.
"""
old_state = mapdl._local
mapdl._local = True
# first cleaning
mapdl.slashdelete(file_)

if file_ == "dumdum.dummy":
# Upload from a different folder
file_path = str(tmpdir.mkdir("tmpdir").join(file_))
else:
file_path = file_
Expand All @@ -200,47 +200,57 @@ def test_load_file_local(mapdl, tmpdir, file_):
fid.write("empty")

assert os.path.exists(file_path)
if mapdl.directory != "/":
assert not os.path.exists(os.path.join(mapdl.directory, file_))

if mapdl._local:
pth = os.path.join(mapdl.directory, file_)
assert not os.path.exists(pth)
else:
assert file_ not in mapdl.list_files()

load_file(mapdl, file_path)

# File is in both, the python working directory and MAPDL directory
assert os.path.exists(file_path)

if mapdl.directory != "/":
assert os.path.exists(os.path.join(mapdl.directory, file_))

with pytest.warns(UserWarning, match=f"The file '{file_}' is present in both,"):
load_file(mapdl, file_path)
if mapdl._local:
pth = os.path.join(mapdl.directory, file_)
assert os.path.exists(pth)

with open(os.path.join(mapdl.directory, file_), "r") as fid:
assert "empty" in fid.read()

else:
assert file_ in mapdl.list_files()
mapdl.download(file_)
assert os.path.exists(file_)

with open(os.path.join(file_), "r") as fid:
assert "empty" in fid.read()

with pytest.warns(UserWarning, match=f"The file '{file_}' is present in both,"):
load_file(mapdl, file_path)

# checking the overwriting with local
# Changing local file first
with open(file_path, "w") as fid:
fid.write("not that empty")

load_file(mapdl, file_path, priority_mapdl_file=False)

if mapdl.directory != "/":
if mapdl._local:
with open(os.path.join(mapdl.directory, file_), "r") as fid:
assert "not that empty" in fid.read()
else:
mapdl.download(file_)
with open(os.path.join(file_), "r") as fid:
assert "empty" in fid.read()

# File is in the MAPDL working directory
os.remove(file_path) # removing local file

assert not os.path.exists(file_path)

if mapdl.directory != "/":
assert os.path.exists(os.path.join(mapdl.directory, file_))

load_file(mapdl, file_path)

mapdl._local = old_state
if mapdl.directory != "/":
os.remove(os.path.join(mapdl.directory, file_))
mapdl.slashdelete(file_)
assert file_ not in mapdl.list_files()


def test_plain_report():
Expand Down