Beispiel #1
0
def test_blastconfig():
    """Test BlastConfig defaults"""
    PROGRAM = 'blastn'
    DB = 'test-db'
    QUERIES = 'test-queries'

    cloud_provider = GCPConfig(project='test-project',
                               region='test-region',
                               zone='test-zone')
    machine_type = 'n1-standard-32'

    cfg = BlastConfig(program=PROGRAM,
                      db=DB,
                      queries_arg=QUERIES,
                      cloud_provider=cloud_provider,
                      machine_type=machine_type)

    assert cfg.program == PROGRAM
    assert cfg.db == DB
    assert cfg.queries_arg == QUERIES
    assert cfg.db_source.name == cloud_provider.cloud.name
    assert cfg.batch_len == get_query_batch_size(cfg.program)
    assert not cfg.queries
    assert cfg.options == f'-outfmt {ELB_DFLT_OUTFMT}'
    assert cfg.mem_request
    assert cfg.mem_limit
    assert not cfg.taxidlist
    assert cfg.db_mem_margin == ELB_BLASTDB_MEMORY_MARGIN
Beispiel #2
0
def test_gcpconfig_from_configparser():
    """Test GCPConfig initialized from a ConfigParser object"""
    PROJECT = 'test-project'
    REGION = 'test-region'
    ZONE = 'test-zone'
    NETWORK = 'network'
    SUBNET = 'subnet'

    confpars = configparser.ConfigParser()
    confpars[CFG_CLOUD_PROVIDER] = {
        CFG_CP_GCP_PROJECT: PROJECT,
        CFG_CP_GCP_REGION: REGION,
        CFG_CP_GCP_ZONE: ZONE,
        CFG_CP_GCP_NETWORK: NETWORK,
        CFG_CP_GCP_SUBNETWORK: SUBNET
    }

    cfg = GCPConfig.create_from_cfg(confpars)
    assert cfg.cloud == CSP.GCP
    assert cfg.project == PROJECT
    assert cfg.region == REGION
    assert cfg.zone == ZONE
    assert cfg.network == NETWORK
    assert cfg.subnet == SUBNET
    errors = []
    cfg.validate(errors, ElbCommand.SUBMIT)
    assert not errors
Beispiel #3
0
def test_gcpconfig():
    """Test GCPConfig defaults"""
    PROJECT = 'test-project'
    REGION = 'test-region'
    ZONE = 'test-zone'

    cfg = GCPConfig(project=PROJECT, region=REGION, zone=ZONE)

    assert cfg.cloud == CSP.GCP
    assert cfg.project == PROJECT
    assert cfg.region == REGION
    assert cfg.zone == ZONE
    assert not cfg.network
    assert not cfg.subnet
    errors = []
    cfg.validate(errors, ElbCommand.SUBMIT)
    assert not errors
Beispiel #4
0
def test_gcpconfig_from_configparser_missing():
    """Test missing required parameters are reported when initializing
    GCPConfig from a ConfigParser object"""
    REQUIRED_PARAMS = [CFG_CP_GCP_PROJECT, CFG_CP_GCP_REGION, CFG_CP_GCP_ZONE]
    with pytest.raises(ValueError) as err:
        cfg = GCPConfig.create_from_cfg(configparser.ConfigParser())

    for param in REQUIRED_PARAMS:
        assert 'Missing ' + param in str(err.value)
Beispiel #5
0
def test_clusterconfig_validation():
    """Test ClusterConfig validation"""
    cfg = ClusterConfig(cloud_provider=GCPConfig(project='test-project',
                                                 region='test-region',
                                                 zone='test-zone'),
                        results=CloudURI('gs://test-results'),
                        min_nodes=5)
    errors = []
    cfg.validate(errors, ElbCommand.SUBMIT)
    assert errors
    assert [
        message for message in errors if 'min-nodes and max-nodes' in message
    ]
Beispiel #6
0
def test_blastconfig_validation():
    """Test BlastConfig validation"""
    BAD_URI = 'gs://@BadURI!'
    cfg = BlastConfig(program='blastn',
                      db='test-db',
                      queries_arg=BAD_URI,
                      cloud_provider=GCPConfig(project='test-project',
                                               region='test-region',
                                               zone='test-zone'),
                      machine_type='n1-standard-32')
    errors = []
    cfg.validate(errors, ElbCommand.SUBMIT)
    assert errors
    assert [message for message in errors if BAD_URI in message]
Beispiel #7
0
def test_gcpconfig_validation():
    """Test GCPConfig validation"""
    cfg = GCPConfig(project='test-project',
                    region='test-region',
                    zone='test-zone')

    cfg.network = 'some-network'
    errors = []
    cfg.validate(errors, ElbCommand.SUBMIT)
    assert errors
    assert [
        message for message in errors
        if 'gcp-network and gcp-subnetwork' in message
    ]

    cfg.network = None
    cfg.subnet = 'subnet'
    errors = []
    cfg.validate(errors, ElbCommand.SUBMIT)
    assert errors
    assert [
        message for message in errors
        if 'gcp-network and gcp-subnetwork' in message
    ]
Beispiel #8
0
def test_gcpconfig_from_configparser_errors():
    """Test that incorrect parameter values in ConfigParser are properly
    reported"""
    confpars = configparser.ConfigParser()
    confpars[CFG_CLOUD_PROVIDER] = {
        CFG_CP_GCP_PROJECT: 'inval!d-PROJECT',
        CFG_CP_GCP_REGION: 'invalie-rEg!on',
        CFG_CP_GCP_ZONE: 'inavlid-zone-@#$'
    }

    with pytest.raises(ValueError) as err:
        cfg = GCPConfig.create_from_cfg(confpars)

    # test that each invalid parameter value is reported
    errors = str(err.value).split('\n')
    for key in confpars[CFG_CLOUD_PROVIDER]:
        assert [
            message for message in errors
            if key in message and 'invalid value' in message
            and confpars[CFG_CLOUD_PROVIDER][key] in message
        ]
Beispiel #9
0
def test_clusterconfig_gcp():
    """Test ClusterConfig defaults for GCP"""
    RESULTS = CloudURI('gs://test-results')
    gcp_cfg = GCPConfig(project='test-project',
                        region='test-region',
                        zone='test-zone')
    cfg = ClusterConfig(cloud_provider=gcp_cfg, results=RESULTS)
    assert cfg.name.startswith('elasticblast')
    assert cfg.machine_type == ELB_DFLT_GCP_MACHINE_TYPE
    assert cfg.pd_size == ELB_DFLT_GCP_PD_SIZE
    assert cfg.num_cpus == get_instance_props(gcp_cfg,
                                              cfg.machine_type).ncpus - 1
    assert cfg.num_nodes == ELB_DFLT_NUM_NODES
    assert cfg.results == RESULTS
    assert not cfg.min_nodes
    assert not cfg.max_nodes
    assert not cfg.use_preemptible
    assert not cfg.iops
    assert not cfg.labels
    assert not cfg.use_local_ssd
    assert not cfg.enable_stackdriver
    errors = []
    cfg.validate(errors, ElbCommand.SUBMIT)
    assert not errors