-
Notifications
You must be signed in to change notification settings - Fork 23
PyPIM integration #237
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
PyPIM integration #237
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
34e4f40
PyPIM integration
plule-ansys d9e6330
flake8
plule-ansys 88ba411
restore input_ip and input_port to limit the impact
plule-ansys 1ef4cab
flake8
plule-ansys c478407
restore the variables names as before
plule-ansys f975aa8
Merge branch 'master' into feat/pim
PProfizi 6433bcf
Move the PIM tests in their own module
plule-ansys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -4,4 +4,5 @@ pytest-rerunfailures | |
matplotlib==3.2 | ||
vtk<9.1.0 | ||
pyvista>=0.24.0 | ||
ansys-platform-instancemanagement~=1.0 | ||
coverage |
This file contains hidden or 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,72 @@ | ||
import sys | ||
from unittest.mock import create_autospec | ||
|
||
import ansys.platform.instancemanagement as pypim | ||
import grpc | ||
import pytest | ||
from ansys.dpf import core | ||
from ansys.dpf.core import server | ||
from ansys.dpf.core.server import DpfServer, __ansys_version__ | ||
|
||
|
||
def test_start_remote(monkeypatch): | ||
# Test for the Product Instance Management API integration | ||
|
||
# Start a local DPF server and create a mock PyPIM pretending it is starting it | ||
local_server = core.start_local_server(as_global=False) | ||
server_address = local_server._address | ||
mock_instance = pypim.Instance( | ||
definition_name="definitions/fake-dpf", | ||
name="instances/fake-dpf", | ||
ready=True, | ||
status_message=None, | ||
services={"grpc": pypim.Service(uri=server_address, headers={})}, | ||
) | ||
# Mock the wait_for_ready method so that it immediately returns | ||
mock_instance.wait_for_ready = create_autospec(mock_instance.wait_for_ready) | ||
# Mock the deletion method | ||
mock_instance.delete = create_autospec(mock_instance.delete) | ||
|
||
# Mock the PyPIM client, so that on the "create_instance" call it returns the mock instance | ||
# Note: the host and port here will not be used. | ||
mock_client = pypim.Client(channel=grpc.insecure_channel("localhost:12345")) | ||
mock_client.create_instance = create_autospec( | ||
mock_client.create_instance, return_value=mock_instance | ||
) | ||
|
||
# Mock the general pypim connection and configuration check method to expose the mock client. | ||
mock_connect = create_autospec(pypim.connect, return_value=mock_client) | ||
monkeypatch.setattr(pypim, "connect", mock_connect) | ||
monkeypatch.setenv("ANSYS_PLATFORM_INSTANCEMANAGEMENT_CONFIG", "/fake/config.json") | ||
|
||
# Call the generic startup sequence with no indication on how to launch it | ||
server = DpfServer(as_global=False) | ||
|
||
# It detected the environment and connected to pypim | ||
assert mock_connect.called | ||
|
||
# It created a remote instance through PyPIM | ||
mock_client.create_instance.assert_called_with( | ||
product_name="dpf", product_version=__ansys_version__ | ||
) | ||
|
||
# It waited for this instance to be ready | ||
assert mock_instance.wait_for_ready.called | ||
|
||
# It connected using the address provided by PyPIM | ||
assert server._address == server_address | ||
|
||
# Stop the server | ||
server.shutdown() | ||
|
||
# The delete instance is called | ||
assert mock_instance.delete.called | ||
|
||
|
||
def test_start_remote_failed(monkeypatch): | ||
# Verifies that the error includes the package name to install when using | ||
# launch_remote_dpf() without the requirements installed. | ||
monkeypatch.setitem(sys.modules, "ansys.platform.instancemanagement", None) | ||
with pytest.raises(ImportError) as exc: | ||
server.launch_remote_dpf() | ||
assert "ansys-platform-instancemanagement" in str(exc) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.