Skip to content

Commit

Permalink
Move tests outside ot coffea_casa (no intention to add them as a part…
Browse files Browse the repository at this point in the history
… of distribution)
  • Loading branch information
oshadura committed Aug 17, 2020
1 parent f36f589 commit c9957e2
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/ca.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIUHfc6OUT6HK590ABdtsRzglDZsfowDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMDA1MjUxNDQ5MzlaFw0zMDA1
MjMxNDQ5MzlaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggIiMA0GCSqGSIb3DQEB
AQUAA4ICDwAwggIKAoICAQCb5PcZthd/Ssv4JpsxGUww9KsA+HknTQVAWUN85bC4
BxLS8IKaE302yGBg8MK9w0z+qTOoMFNMqoo+Yqp7sDGbV/4U9qVPuJfbxddLPyQU
QenGXsyAMLEmVXCmQHXlcZCsIlY0je6c7o2bJw2oJPPktjMRNfHI+lWtzhMVOhWz
nKRMwikfaV80Vn80Jx7zY2A2kcsoGL16Y/GLp4AAhEGWtn3GFJDCCWpJM4fBeChZ
6wOxP/KnNsJZ2PeHb+yTXT347ZFRdKHB6DNDmiWk48BrPgwemKdePt+7YN1UmV88
YCl54BecgGiu3Iav0gqCHv2JIDZtyUtfBA/rPXsUmRbus0ZW9ASCnVEbt9FtHQZ+
e/BmLL6WDg58lGE4TeI+EaK1FqxbVEB3K5idrForTZvadKzf2licSpRP+wlRruhZ
k85lT50aY5tvQIPq+FnX2mQwosMln0hIPXvgqXDMNrSCzUZ9aCLL6PWx+wqLHq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 52 additions & 0 deletions tests/key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
-----BEGIN PRIVATE KEY-----
MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCb5PcZthd/Ssv4
JpsxGUww9KsA+HknTQVAWUN85bC4BxLS8IKaE302yGBg8MK9w0z+qTOoMFNMqoo+
Yqp7sDGbV/4U9qVPuJfbxddLPyQUQenGXsyAMLEmVXCmQHXlcZCsIlY0je6c7o2b
Jw2oJPPktjMRNfHI+lWtzhMVOhWznKRMwikfaV80Vn80Jx7zY2A2kcsoGL16Y/GL
p4AAhEGWtn3GFJDCCWpJM4fBeChZ6wOxP/KnNsJZ2PeHb+yTXT347ZFRdKHB6DND
miWk48BrPgwemKdePt+7YN1UmV88YCl54BecgGiu3Iav0gqCHv2JIDZtyUtfBA/r
PXsUmRbus0ZW9ASCnVEbt9FtHQZ+e/BmLL6WDg58lGE4TeI+EaK1FqxbVEB3K5id
rForTZvadKzf2licSpRP+wlRruhZk85lT50aY5tvQIPq+FnX2mQwosMln0hIPXvg
qXDMNrSCzUZ9aCLL6PWx+wqLHq9pdU/2upPM9AEiPh1M9nEXL+FdbQMB6wNbpo/L
3yTfQ1pL3Z33KLDC9OfWCGymgarL1uxeUbt6XeCB7Exb+1fT73RtjeO2QFTZrCjK
fxR3vKIBA0/2qb0DfktAasekyx3UTC2ZhT/wNP4LBP/l1Oasn47e6EPs2slZLPHZ
XfbdElsBGcGPDwh38RjSVq+fzm7bbwIDAQABAoICAHFc4ddfk9yr3oEYSdg9Zitf
cA6noSpUFtKBVtM3D/fypNyhqscyDubMdVFpIqPtpkq1bewLIDfq99Z/1ytUp+4n
4YsLBJFhUYSubG26f5j/iWkIPLunLNsMXHt4+oKbv7F80qUq5O5Xhr/heUvhez3A
xIfqa2VTrQRTi4rvDyLqcIuk0VSXQnUDxUJ+hEJG7IsiH9KLkxWyIc8FQc6eXjej
gviMset3/0M15q1onCcvACNftiukZVYCsZVabXW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s1Zsa8Er0JUNPxqJzmlJ
Q2ypwp0CapUz0d43a47/izrjAtXzug==
-----END PRIVATE KEY-----
117 changes: 117 additions & 0 deletions tests/test_coffeacasa.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import os
import sys
import socket
import pytest
from distributed.security import Security
from distributed import Client
from coffea_casa import CoffeaCasaCluster

os.environ["HOST_IP"] = socket.gethostbyname(socket.gethostname())


def test_header():
with CoffeaCasaCluster(cores=1,
memory="100MB",
disk="100MB",
worker_image="coffeateam/coffea-casa:latest"
) as cluster:
job_script = cluster.job_script()
print("HTCondor Job script:", job_script)
print("Scheduler specs:", cluster.scheduler_spec)
kwargs = CoffeaCasaCluster._modify_job_kwargs({})
print("CoffeaCasaCluster arguments:", kwargs)
assert cluster._dummy_job.job_header_dict["MY.DaskWorkerCores"] == 1
assert cluster._dummy_job.job_header_dict["MY.DaskWorkerDisk"] == 100000000
assert cluster._dummy_job.job_header_dict["MY.DaskWorkerMemory"] == 100000000


def test_job_script():
with CoffeaCasaCluster(cores=4,
processes=4,
memory="500MB",
disk="500MB",
worker_image="coffeateam/coffea-casa:latest",
env_extra=['export LANG="en_US.utf8"',
'export LC_ALL="en_US.utf8"'],
job_extra={"+Extra": "True"},
) as cluster:
job_script = cluster.job_script()
print("HTCondor Job script:", job_script)
print("Scheduler specs:", cluster.scheduler_spec)
assert "RequestCpus = MY.DaskWorkerCores" in job_script
assert "RequestDisk = floor(MY.DaskWorkerDisk / 1024)" in job_script
assert "RequestMemory = floor(MY.DaskWorkerMemory / 1048576)" in job_script
assert "MY.DaskWorkerCores = 4" in job_script
assert "MY.DaskWorkerDisk = 500000000" in job_script
assert "MY.DaskWorkerMemory = 500000000" in job_script
assert 'MY.JobId = "$(ClusterId).$(ProcId)"' in job_script
assert "LANG=en_US.utf8" in job_script
assert "LC_ALL=en_US.utf8" in job_script
assert "export" not in job_script
assert "+Extra = True" in job_script
assert (
"{} -m distributed.cli.dask_worker tcp://".format(sys.executable)
in job_script
)
assert "--memory-limit 125.00MB" in job_script
assert "--nthreads 1" in job_script
assert "--nprocs 4" in job_script


def test_scheduler():
with CoffeaCasaCluster(cores=1,
memory="100MB",
disk="100MB",
worker_image="coffeateam/coffea-casa:latest",
scheduler_options={
"dashboard_address": 8786,
"port": 8788}
) as cluster:
job_script = cluster.job_script()
print("HTCondor Job script:", job_script)
print("Scheduler specs:", cluster.scheduler_spec)
kwargs = CoffeaCasaCluster._modify_job_kwargs({})
print("CoffeaCasaCluster arguments:", kwargs)
#assert cluster.scheduler_spec["port"] == 8788
expected = os.environ["HOST_IP"]
assert expected in str(cluster.scheduler_spec)
#cluster.scale(1)
#assert expected in str(cluster.worker_spec)


def test_security():
dirname = os.path.dirname(__file__)
key = os.path.join(dirname, "key.pem")
cert = os.path.join(dirname, "ca.pem")
security = Security(
tls_ca_file=cert,
tls_scheduler_key=key,
tls_scheduler_cert=cert,
tls_worker_key=key,
tls_worker_cert=cert,
tls_client_key=key,
tls_client_cert=cert,
require_encryption=True,
)

with CoffeaCasaCluster(cores=1,
memory="100MB",
disk="100MB",
worker_image="coffeateam/coffea-casa:latest",
security=security) as cluster:
job_script = cluster.job_script()
print("HTCondor JobAd script:", job_script)
print("Scheduler specs:", cluster.scheduler_spec)
kwargs = CoffeaCasaCluster._modify_job_kwargs({})
print("CoffeaCasaCluster arguments:", kwargs)
assert cluster.security == 'mioa'
assert cluster.security == security
assert cluster.scheduler_spec["options"]["security"] == security
assert "--tls-key {}".format(key) in job_script
assert "--tls-cert {}".format(cert) in job_script
assert "--tls-ca-file {}".format(cert) in job_script
#cluster.scale(jobs=1)
#with Client(cluster, security=security) as client:
# future = client.submit(lambda x: x + 1, 10)
# result = future.result()
# assert result == 11
48 changes: 48 additions & 0 deletions tests/test_coffeacasa_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
import os
from pathlib import Path
from coffea_casa import CoffeaCasaCluster
from distributed.security import Security

# Security settings for coffea-casa Dask scheduler
SECRETS_DIR = Path('/etc/cmsaf-secrets')
CA_FILE = SECRETS_DIR / "ca.pem"
CERT_FILE = SECRETS_DIR / "hostcert.pem"

@pytest.fixture
def default_modified_kwargs():
return CoffeaCasaCluster._modify_job_kwargs({})


def test_default_dask_container_port(default_modified_kwargs):
assert default_modified_kwargs["job_extra"]["dask_container_port"] == 8787


def test_can_override_dask_container_port():
kwargs = CoffeaCasaCluster._modify_job_kwargs(dict(job_extra={"dask_container_port": 8788}))
assert kwargs["job_extra"]["dask_container_port"] == 8788


def test_default_protocol(default_modified_kwargs):
if CA_FILE.is_file() and CERT_FILE.is_file():
assert default_modified_kwargs["scheduler_options"]["protocol"] == 'tls'
else:
assert default_modified_kwargs["scheduler_options"]["protocol"] == 'tcp'


def test_can_override_security():
dirname = os.path.dirname(__file__)
key = os.path.join(dirname, "key.pem")
cert = os.path.join(dirname, "ca.pem")
security = Security(
tls_ca_file=cert,
tls_scheduler_key=key,
tls_scheduler_cert=cert,
tls_worker_key=key,
tls_worker_cert=cert,
tls_client_key=key,
tls_client_cert=cert,
require_encryption=True)
kwargs = CoffeaCasaCluster._modify_job_kwargs(dict(security=security))
assert kwargs["security"] == security
assert kwargs["scheduler_options"]["protocol"] == 'tls'
7 changes: 7 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import dask
import pytest
import coffea_casa.config


def test_dask_config():
assert dask.config.get('jobqueue.coffea-casa.worker-image') == "coffeateam/coffea-casa:latest"

0 comments on commit c9957e2

Please sign in to comment.