Skip to content
This repository has been archived by the owner on Sep 3, 2022. It is now read-only.

Commit

Permalink
Allow trailing slash in gcs dag location
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajiv Bharadwaja committed Nov 10, 2017
1 parent 4d6162d commit 009a5e5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
6 changes: 4 additions & 2 deletions google/datalab/contrib/pipeline/composer/_composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Composer(object):
This object can be used to generate the python airflow spec.
"""

gcs_file_regexp = re.compile('gs://.*[^/]$')
gcs_file_regexp = re.compile('gs://.*')

def __init__(self, zone, environment):
""" Initializes an instance of a Composer object.
Expand Down Expand Up @@ -60,6 +60,8 @@ def gcs_dag_location(self):
'Dag location {0} from Composer environment {1} is in incorrect format'.format(
gcs_dag_location, self._environment))

self._gcs_dag_location = gcs_dag_location + '/'
self._gcs_dag_location = gcs_dag_location
if gcs_dag_location.endswith('/') is False:
self._gcs_dag_location = self._gcs_dag_location + '/'

return self._gcs_dag_location
23 changes: 9 additions & 14 deletions tests/pipeline/composer_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ def test_gcs_dag_location(self, mock_environment_details):
test_composer = Composer('foo_zone', 'foo_environment')
self.assertEqual('gs://foo_bucket/dags/', test_composer.gcs_dag_location)

# Composer returns good result
mock_environment_details.return_value = {
'config': {
'gcsDagLocation': 'gs://foo_bucket'
'gcsDagLocation': 'gs://foo_bucket' # only bucket
}
}
test_composer = Composer('foo_zone', 'foo_environment')
self.assertEqual('gs://foo_bucket/', test_composer.gcs_dag_location)

mock_environment_details.return_value = {
'config': {
'gcsDagLocation': 'gs://foo_bucket/' # with trailing slash
}
}
test_composer = Composer('foo_zone', 'foo_environment')
Expand Down Expand Up @@ -135,15 +142,3 @@ def test_gcs_dag_location(self, mock_environment_details):
('Dag location as://foo_bucket from Composer environment foo_environment is in'
' incorrect format')):
test_composer.gcs_dag_location

mock_environment_details.return_value = {
'config': {
'gcsDagLocation': 'gs://foo_bucket/' # trailing slash should be disallowed
}
}
test_composer = Composer('foo_zone', 'foo_environment')
with self.assertRaisesRegexp(
ValueError,
('Dag location as://foo_bucket from Composer environment foo_environment is in'
' incorrect format')):
test_composer.gcs_dag_location

0 comments on commit 009a5e5

Please sign in to comment.