Skip to content

Commit

Permalink
is_service_runner now returns false with dataflow_endpoint=localhost (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kerrydc authored Aug 23, 2023
1 parent 52275eb commit b2d1c60
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
10 changes: 8 additions & 2 deletions sdks/python/apache_beam/options/pipeline_options_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,13 @@ def is_service_runner(self):

dataflow_endpoint = (
self.options.view_as(GoogleCloudOptions).dataflow_endpoint)
is_service_endpoint = (dataflow_endpoint is not None)
return is_service_runner and is_service_endpoint
if dataflow_endpoint is None:
return False
else:
endpoint_parts = urlparse(dataflow_endpoint, allow_fragments=False)
if endpoint_parts.netloc.startswith("localhost"):
return False
return is_service_runner

def is_full_string_match(self, pattern, string):
"""Returns True if the pattern matches the whole string."""
Expand Down Expand Up @@ -404,6 +409,7 @@ def validate_repeatable_argument_passed_as_list(self, view, arg_name):

# Minimally validates the endpoint url. This is not a strict application
# of http://www.faqs.org/rfcs/rfc1738.html.
# If the url matches localhost, set
def validate_endpoint_url(self, endpoint_url):
url_parts = urlparse(endpoint_url, allow_fragments=False)
if not url_parts.scheme or not url_parts.netloc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@ def test_is_service_runner(self):
'options': ['--dataflow_endpoint=https://dataflow.googleapis.com/'],
'expected': False,
},
{
'runner': MockRunners.DataflowRunner(),
'options': [],
'expected': True,
},
{
'runner': MockRunners.DataflowRunner(),
'options': ['--dataflow_endpoint=https://another.service.com'],
Expand All @@ -321,6 +326,11 @@ def test_is_service_runner(self):
'options': ['--dataflow_endpoint=https://dataflow.googleapis.com'],
'expected': True,
},
{
'runner': MockRunners.DataflowRunner(),
'options': ['--dataflow_endpoint=http://localhost:1000'],
'expected': False,
},
{
'runner': MockRunners.DataflowRunner(),
'options': ['--dataflow_endpoint=foo: //dataflow. googleapis. com'],
Expand All @@ -336,7 +346,7 @@ def test_is_service_runner(self):
for case in test_cases:
validator = PipelineOptionsValidator(
PipelineOptions(case['options']), case['runner'])
self.assertEqual(validator.is_service_runner(), case['expected'])
self.assertEqual(validator.is_service_runner(), case['expected'], case)

def test_dataflow_job_file_and_template_location_mutually_exclusive(self):
runner = MockRunners.OtherRunner()
Expand Down

0 comments on commit b2d1c60

Please sign in to comment.