Skip to content

Commit b87c75f

Browse files
committed
Release 0.2.3
1 parent fca8417 commit b87c75f

File tree

5 files changed

+34
-35
lines changed

5 files changed

+34
-35
lines changed

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
cff-version: "1.1.0"
22
message: "If you use this software, please cite it using these metadata."
33
title: ElasticBLAST
4-
version: "0.2.2"
5-
date-released: 2022-02-09
4+
version: "0.2.3"
5+
date-released: 2022-02-16
66
license: "NCBI Public Domain"
77
repository-code: "https://github.com/ncbi/elastic-blast/"
88
authors:

src/elastic_blast/elb_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@
8787
from .util import validate_gke_cluster_name, ElbSupportedPrograms
8888
from .util import get_query_batch_size
8989
from .util import UserReportError, safe_exec
90-
from .util import gcp_get_regions
90+
from .util import gcp_get_regions, sanitize_for_k8s
9191
from .gcp_traits import get_machine_properties as gcp_get_machine_properties
9292
from .aws_traits import get_machine_properties as aws_get_machine_properties
9393
from .aws_traits import get_regions as aws_get_regions
@@ -989,7 +989,7 @@ def get_max_number_of_concurrent_blast_jobs(self) -> int:
989989

990990
def generate_cluster_name(results: CloudURI) -> str:
991991
""" Returns the default cluster name """
992-
username = sanitize_gcp_label(getpass.getuser().lower())
992+
username = sanitize_for_k8s(sanitize_gcp_label(getpass.getuser().lower()))
993993
return f'elasticblast-{username}-{results.md5}'
994994

995995

src/elastic_blast/util.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -397,18 +397,6 @@ def sanitize_for_k8s(input_string: str) -> str:
397397
return re.sub(r'_', '-', input_string.lower(), flags=re.ASCII)
398398

399399

400-
def sanitize_gcp_labels(input_label: str) -> str:
401-
""" Changes the input_label so that it is composed of valid GCP label characters"""
402-
return re.sub(r'\W', '-', input_label.lower(), flags=re.ASCII)[:GCP_MAX_LABEL_LENGTH]
403-
404-
405-
def sanitize_aws_tag(input_label: str) -> str:
406-
""" Changes the input_label so that it is composed of valid AWS tag characters"""
407-
# NB: this AWS sanitizer is a bit more restrictive - it replaces '=' to
408-
# simplify dataflow for GCP
409-
return re.sub(r'[^\w_\.:/+@]', '-', input_label.strip(), flags=re.ASCII)[:AWS_MAX_TAG_LENGTH]
410-
411-
412400
def sanitize_aws_batch_job_name(input_name: str) -> str:
413401
""" Changes the input_name so that it is composed of valid AWS Batch job name characters"""
414402
return re.sub(r'[\W\-]', '-', input_name.strip(), flags=re.ASCII)[:AWS_MAX_JOBNAME_LENGTH]

tests/elb_config/test_elb_config.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import configparser
3030
from dataclasses import dataclass, fields
3131
from unittest.mock import MagicMock, patch
32-
import math
33-
from elastic_blast.constants import CSP
32+
import math, getpass
33+
from elastic_blast.constants import CSP, GCP_MAX_LABEL_LENGTH, AWS_MAX_TAG_LENGTH
3434
from elastic_blast.constants import CFG_CLOUD_PROVIDER
3535
from elastic_blast.constants import CFG_CP_GCP_PROJECT, CFG_CP_GCP_REGION, CFG_CP_GCP_ZONE
3636
from elastic_blast.constants import CFG_CP_GCP_NETWORK, CFG_CP_GCP_SUBNETWORK
@@ -67,6 +67,7 @@
6767
from elastic_blast.elb_config import CloudURI, GCPString, AWSRegion
6868
from elastic_blast.elb_config import GCPConfig, AWSConfig, BlastConfig, ClusterConfig
6969
from elastic_blast.elb_config import ElasticBlastConfig, get_instance_props
70+
from elastic_blast.elb_config import sanitize_gcp_label, sanitize_aws_tag
7071
from elastic_blast.constants import ElbCommand
7172
from elastic_blast.util import UserReportError, get_query_batch_size, ElbSupportedPrograms
7273
from elastic_blast.gcp_traits import get_machine_properties as gcp_get_machine_properties
@@ -638,6 +639,15 @@ def test_clusterconfig_from_configparser_errors():
638639
assert [message for message in errors if key in message and 'invalid value' in message and confpars[CFG_BLAST][key] in message]
639640

640641

642+
@patch(target='getpass.getuser', new=MagicMock(return_value='a-user-name_with_underscore'))
643+
def test_clusterconfig_username_with_underscore():
644+
"""Test that a username with an underscore is properly amended before
645+
becoming part of a cluster name"""
646+
assert '_' in getpass.getuser()
647+
cfg = ClusterConfig(CloudURI('gs://some-bucket'))
648+
assert '_' not in cfg.name
649+
650+
641651
TEST_MACHINE_TYPE = 'test-machine-type'
642652

643653
@patch(target='elastic_blast.tuner.aws_get_machine_properties', new=MagicMock(return_value=InstanceProperties(32, 120)))
@@ -1707,3 +1717,20 @@ def test_mt_mode_and_batch_len_user_selected(gke_mock):
17071717
assert cfg.blast.user_provided_batch_len
17081718

17091719

1720+
def test_sanitize_gcp_label():
1721+
assert 'harry-potter' == sanitize_gcp_label('Harry.Potter')
1722+
assert 'macbook-pro-home' == sanitize_gcp_label('MacBook-Pro.Home')
1723+
label = sanitize_gcp_label('gs://tomcat-test/tc-elb-int-swissprot-psiblast-multi-node-sync-351')
1724+
assert len(label) <= GCP_MAX_LABEL_LENGTH
1725+
assert 'gs---tomcat-test-tc-elb-int-swissprot-psiblast-multi-node-sync-' == label
1726+
1727+
1728+
def test_sanitize_gcp_user_name():
1729+
assert 'user-name' == sanitize_gcp_label('user.name')
1730+
1731+
1732+
def test_sanitize_aws_tag():
1733+
assert 's3://abra-Cada-bra+-@.-' == sanitize_aws_tag('s3://abra;Cada#bra+-@.=')
1734+
label = sanitize_aws_tag('s3://tomcat-test/tc-elb-int-swissprot-psiblast-multi-node-sync-351')
1735+
assert len(label) <= AWS_MAX_TAG_LENGTH
1736+
assert 's3://tomcat-test/tc-elb-int-swissprot-psiblast-multi-node-sync-351' == label

tests/util/test_util.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,11 @@
3131

3232
from elastic_blast import util
3333
from elastic_blast.constants import ELB_DFLT_GCP_MACHINE_TYPE
34-
from elastic_blast.constants import GCP_MAX_LABEL_LENGTH, AWS_MAX_TAG_LENGTH
3534
from elastic_blast.constants import ElbCommand, MolType
3635
from elastic_blast.util import get_query_batch_size
3736
from elastic_blast.util import convert_memory_to_mb, get_blastdb_size, sanitize_aws_batch_job_name
3837
from elastic_blast.util import safe_exec, SafeExecError, convert_disk_size_to_gb
39-
from elastic_blast.util import sanitize_gcp_labels, sanitize_for_k8s, sanitize_aws_tag
38+
from elastic_blast.util import sanitize_for_k8s
4039
from elastic_blast.util import validate_gcp_string, convert_labels_to_aws_tags
4140
from elastic_blast.util import validate_gcp_disk_name, gcp_get_regions
4241
from elastic_blast.gcp_traits import get_machine_properties
@@ -139,33 +138,18 @@ def test_get_blastdb_size_invalid_database(self):
139138
with self.assertRaises(ValueError):
140139
get_blastdb_size(cfg.blast.db, cfg.cluster.db_source)
141140

142-
def test_sanitize_gcp_labels(self):
143-
self.assertEqual('harry-potter', sanitize_gcp_labels('Harry.Potter'))
144-
self.assertEqual('macbook-pro-home', sanitize_gcp_labels('MacBook-Pro.Home'))
145-
label = sanitize_gcp_labels('gs://tomcat-test/tc-elb-int-swissprot-psiblast-multi-node-sync-351')
146-
self.assertLessEqual(len(label), GCP_MAX_LABEL_LENGTH)
147-
self.assertEqual('gs---tomcat-test-tc-elb-int-swissprot-psiblast-multi-node-sync-', label)
148-
149141
def test_sanitize_for_k8s(self):
150142
self.assertEqual('ref-viruses-rep-genomes', sanitize_for_k8s('ref_viruses_rep_genomes'))
151143
self.assertEqual('betacoronavirus', sanitize_for_k8s('Betacoronavirus'))
152144
self.assertEqual('16s-ribosomal-rna', sanitize_for_k8s('16S_ribosomal_RNA'))
153145
self.assertEqual('gcf-000001405.38-top-level', sanitize_for_k8s('GCF_000001405.38_top_level'))
154146

155-
def test_sanitize_aws_tag(self):
156-
self.assertEqual('s3://abra-Cada-bra+-@.-', sanitize_aws_tag('s3://abra;Cada#bra+-@.='))
157-
label = sanitize_aws_tag('s3://tomcat-test/tc-elb-int-swissprot-psiblast-multi-node-sync-351')
158-
self.assertLessEqual(len(label), AWS_MAX_TAG_LENGTH)
159-
self.assertEqual('s3://tomcat-test/tc-elb-int-swissprot-psiblast-multi-node-sync-351', label)
160-
161147
def test_sanitize_aws_batch_job_name(self):
162148
self.assertEqual('GCF_000001405-38_top_level', sanitize_aws_batch_job_name('GCF_000001405.38_top_level '))
163149

164150
def test_sanitize_aws_user_name(self):
165151
self.assertEqual('user-name', sanitize_aws_batch_job_name('user.name'))
166152

167-
def test_sanitize_gcp_user_name(self):
168-
self.assertEqual('user-name', sanitize_gcp_labels('user.name'))
169153

170154
@patch(target='elastic_blast.elb_config.get_db_metadata', new=MagicMock(return_value=DB_METADATA))
171155
def create_config_for_db(dbname):

0 commit comments

Comments
 (0)