Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Sep 3, 2024
1 parent d2e2b5d commit d92448d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package nextflow.cloud.azure.config

import groovy.transform.CompileStatic
import nextflow.SysEnv
import nextflow.cloud.azure.nio.AzFileSystemProvider

/**
Expand All @@ -26,18 +27,15 @@ import nextflow.cloud.azure.nio.AzFileSystemProvider
@CompileStatic
class AzActiveDirectoryOpts {

private Map<String, String> sysEnv

String servicePrincipalId
String servicePrincipalSecret
String tenantId

AzActiveDirectoryOpts(Map config, Map<String, String> env = null) {
assert config != null
this.sysEnv = env == null ? new HashMap<String, String>(System.getenv()) : env
this.servicePrincipalId = config.servicePrincipalId ?: sysEnv.get('AZURE_CLIENT_ID')
this.servicePrincipalSecret = config.servicePrincipalSecret ?: sysEnv.get('AZURE_CLIENT_SECRET')
this.tenantId = config.tenantId ?: sysEnv.get('AZURE_TENANT_ID')
this.servicePrincipalId = config.servicePrincipalId ?: SysEnv.get('AZURE_CLIENT_ID')
this.servicePrincipalSecret = config.servicePrincipalSecret ?: SysEnv.get('AZURE_CLIENT_SECRET')
this.tenantId = config.tenantId ?: SysEnv.get('AZURE_TENANT_ID')
}

Map<String, Object> getEnv() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package nextflow.cloud.azure.config


import groovy.transform.CompileStatic
import nextflow.SysEnv

/**
* Model Azure Batch registry config settings from nextflow config file
Expand All @@ -27,8 +27,6 @@ import groovy.transform.CompileStatic
@CompileStatic
class AzRegistryOpts {

private Map<String,String> sysEnv

String server
String userName
String password
Expand All @@ -37,12 +35,11 @@ class AzRegistryOpts {
this(Collections.emptyMap())
}

AzRegistryOpts(Map config, Map<String,String> env=null) {
AzRegistryOpts(Map config, Map<String,String> env=SysEnv.get()) {
assert config!=null
this.sysEnv = env==null ? new HashMap<String,String>(System.getenv()) : env
this.server = config.server ?: 'docker.io'
this.userName = config.userName ?: sysEnv.get('AZURE_REGISTRY_USER_NAME')
this.password = config.password ?: sysEnv.get('AZURE_REGISTRY_PASSWORD')
this.userName = config.userName ?: env.get('AZURE_REGISTRY_USER_NAME')
this.password = config.password ?: env.get('AZURE_REGISTRY_PASSWORD')
}

boolean isConfigured() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package nextflow.cloud.azure.config

import groovy.transform.CompileStatic
import nextflow.SysEnv
import nextflow.cloud.azure.batch.AzHelper
import nextflow.cloud.azure.nio.AzFileSystemProvider
import nextflow.util.Duration
Expand All @@ -28,20 +29,18 @@ import nextflow.util.Duration
@CompileStatic
class AzStorageOpts {

private Map<String,String> sysEnv
String accountKey
String accountName
String sasToken
Duration tokenDuration
Map<String,AzFileShareOpts> fileShares


AzStorageOpts(Map config, Map<String,String> env=null) {
AzStorageOpts(Map config, Map<String,String> env=SysEnv.get()) {
assert config!=null
this.sysEnv = env==null ? new HashMap<String,String>(System.getenv()) : env
this.accountKey = config.accountKey ?: sysEnv.get('AZURE_STORAGE_ACCOUNT_KEY')
this.accountName = config.accountName ?: sysEnv.get('AZURE_STORAGE_ACCOUNT_NAME')
this.sasToken = config.sasToken ?: sysEnv.get('AZURE_STORAGE_SAS_TOKEN')
this.accountKey = config.accountKey ?: env.get('AZURE_STORAGE_ACCOUNT_KEY')
this.accountName = config.accountName ?: env.get('AZURE_STORAGE_ACCOUNT_NAME')
this.sasToken = config.sasToken ?: env.get('AZURE_STORAGE_SAS_TOKEN')
this.tokenDuration = (config.tokenDuration as Duration) ?: Duration.of('48h')
this.fileShares = parseFileShares(config.fileShares instanceof Map ? config.fileShares as Map<String, Map>
: Collections.<String,Map> emptyMap())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.azure.identity.ManagedIdentityCredential
import com.google.common.hash.HashCode
import nextflow.Global
import nextflow.Session
import nextflow.SysEnv
import nextflow.cloud.azure.config.AzConfig
import nextflow.cloud.azure.config.AzManagedIdentityOpts
import nextflow.cloud.azure.config.AzPoolOpts
Expand All @@ -31,6 +32,14 @@ class AzBatchServiceTest extends Specification {

static long _1GB = 1024 * 1024 * 1024

def setup() {
SysEnv.push([:]) // <-- clear the system host env
}

def cleanup() {
SysEnv.pop() // <-- restore the system host env
}

def 'should make job id'() {
given:
def task = Mock(TaskRun) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package nextflow.cloud.azure.fusion

import nextflow.Global
import nextflow.Session
import nextflow.SysEnv
import nextflow.fusion.FusionConfig
import spock.lang.Specification

Expand All @@ -28,6 +29,14 @@ import spock.lang.Specification
*/
class AzFusionEnvTest extends Specification {

def setup() {
SysEnv.push([:]) // <-- clear the system host env
}

def cleanup() {
SysEnv.pop() // <-- restore the system host env
}

def 'should return empty env'() {
given:
def provider = new AzFusionEnv()
Expand All @@ -50,8 +59,6 @@ class AzFusionEnvTest extends Specification {
then:
env == [AZURE_STORAGE_ACCOUNT: 'x1']

cleanup:
Global.session = null
}

def 'should return env environment with SAS token config'() {
Expand All @@ -67,8 +74,6 @@ class AzFusionEnvTest extends Specification {
then:
env == [AZURE_STORAGE_ACCOUNT: 'x1', AZURE_STORAGE_SAS_TOKEN: 'y1']

cleanup:
Global.session = null
}

def 'should throw an exception when missing Azure Storage account name'() {
Expand All @@ -81,8 +86,6 @@ class AzFusionEnvTest extends Specification {
def env = new AzFusionEnv().getEnvironment('az', Mock(FusionConfig))
then:
thrown(IllegalArgumentException)
cleanup:
Global.session = null
}

def 'should throw an exception when both account key and SAS token are present'() {
Expand All @@ -95,7 +98,5 @@ class AzFusionEnvTest extends Specification {
def env = new AzFusionEnv().getEnvironment('az', Mock(FusionConfig))
then:
thrown(IllegalArgumentException)
cleanup:
Global.session = null
}
}

0 comments on commit d92448d

Please sign in to comment.