-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
91 additions
and
191 deletions.
There are no files selected for viewing
This file contains 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,83 @@ | ||
import fire | ||
import yaml | ||
|
||
from fedn import APIClient | ||
|
||
|
||
def _download_config(output): | ||
""" Download the client configuration file from the controller. | ||
:param output: The output file path. | ||
:type output: str | ||
""" | ||
client = APIClient(host="localhost", port=8092) | ||
config = client.get_client_config(checksum=True) | ||
with open(output, 'w') as f: | ||
f.write(yaml.dump(config)) | ||
|
||
|
||
def test_api_get_methods(): | ||
client = APIClient(host="localhost", port=8092) | ||
status = client.get_controller_status() | ||
assert status | ||
print("Controller status: ", status, flush=True) | ||
|
||
events = client.get_events() | ||
assert events | ||
print("Events: ", events, flush=True) | ||
|
||
validations = client.list_validations() | ||
assert validations | ||
print("Validations: ", validations, flush=True) | ||
|
||
models = client.get_model_trail() | ||
assert models | ||
print("Models: ", models, flush=True) | ||
|
||
clients = client.list_clients() | ||
assert clients | ||
print("Clients: ", clients, flush=True) | ||
|
||
combiners = client.list_combiners() | ||
assert combiners | ||
print("Combiners: ", combiners, flush=True) | ||
|
||
combiner = client.get_combiner("combiner") | ||
assert combiner | ||
print("Combiner: ", combiner, flush=True) | ||
|
||
first_model = client.get_initial_model() | ||
assert first_model | ||
print("First model: ", first_model, flush=True) | ||
|
||
package = client.get_package() | ||
assert package | ||
print("Package: ", package, flush=True) | ||
|
||
checksum = client.get_package_checksum() | ||
assert checksum | ||
print("Checksum: ", checksum, flush=True) | ||
|
||
rounds = client.list_rounds() | ||
assert rounds | ||
print("Rounds: ", rounds, flush=True) | ||
|
||
round = client.get_round(1) | ||
assert round | ||
print("Round: ", round, flush=True) | ||
|
||
sessions = client.list_sessions() | ||
assert sessions | ||
print("Sessions: ", sessions, flush=True) | ||
|
||
|
||
if __name__ == '__main__': | ||
|
||
client = APIClient(host="localhost", port=8092) | ||
fire.Fire({ | ||
'set_seed': client.set_initial_model, | ||
'set_package': client.set_package, | ||
'start_session': client.start_session, | ||
'get_client_config': _download_config, | ||
'test_api_get_methods': test_api_get_methods, | ||
}) |
This file contains 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 |
---|---|---|
|
@@ -23,34 +23,23 @@ docker-compose \ | |
".$example/bin/python" ../../.ci/tests/examples/wait_for.py combiners | ||
|
||
>&2 echo "Upload compute package" | ||
curl -k -X POST \ | ||
-F [email protected] \ | ||
-F helper="$helper" \ | ||
http://localhost:8090/context | ||
printf '\n' | ||
".$example/bin/python" ../../.ci/tests/examples/api_test.py set_package --path package.tgz --helper "$helper" | ||
|
||
>&2 echo "Upload seed" | ||
curl -k -X POST \ | ||
-F [email protected] \ | ||
http://localhost:8090/models | ||
printf '\n' | ||
".$example/bin/python" ../../.ci/tests/examples/api_test.py set_seed --path seed.npz | ||
|
||
>&2 echo "Wait for clients to connect" | ||
".$example/bin/python" ../../.ci/tests/examples/wait_for.py clients | ||
|
||
>&2 echo "Start round" | ||
curl -k -X POST \ | ||
-F rounds=3 \ | ||
-F validate=True \ | ||
http://localhost:8090/control | ||
printf '\n' | ||
>&2 echo "Start session" | ||
".$example/bin/python" ../../.ci/tests/examples/api_test.py start_session --rounds 3 --helper "$helper" | ||
|
||
>&2 echo "Checking rounds success" | ||
".$example/bin/python" ../../.ci/tests/examples/wait_for.py rounds | ||
|
||
>&2 echo "Test client connection with dowloaded settings" | ||
# Get config | ||
curl -k http://localhost:8090/config/download > ../../client.yaml | ||
".$example/bin/python" ../../.ci/tests/examples/api_test.py get_client_config --output ../../client.yaml | ||
|
||
# Redeploy clients with config | ||
docker-compose \ | ||
|
@@ -62,5 +51,8 @@ docker-compose \ | |
>&2 echo "Wait for clients to reconnect" | ||
".$example/bin/python" ../../.ci/tests/examples/wait_for.py clients | ||
|
||
>&2 echo "Test API GET requests" | ||
".$example/bin/python" ../../.ci/tests/examples/api_test.py test_api_get_methods | ||
|
||
popd | ||
>&2 echo "Test completed successfully" |
This file was deleted.
Oops, something went wrong.