[jira] [Commented] (AIRFLOW-2863) GKEClusterHook catches wrong exception

2018-08-07 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-2863?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16571966#comment-16571966
 ] 

ASF GitHub Bot commented on AIRFLOW-2863:
-

feng-tao closed pull request #3711: [AIRFLOW-2863] Fix GKEClusterHook catching 
wrong exception
URL: https://github.com/apache/incubator-airflow/pull/3711
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/airflow/contrib/hooks/gcp_container_hook.py 
b/airflow/contrib/hooks/gcp_container_hook.py
index d36d796d76..227cd3d124 100644
--- a/airflow/contrib/hooks/gcp_container_hook.py
+++ b/airflow/contrib/hooks/gcp_container_hook.py
@@ -23,7 +23,7 @@
 from airflow import AirflowException, version
 from airflow.hooks.base_hook import BaseHook
 
-from google.api_core.exceptions import AlreadyExists
+from google.api_core.exceptions import AlreadyExists, NotFound
 from google.api_core.gapic_v1.method import DEFAULT
 from google.cloud import container_v1, exceptions
 from google.cloud.container_v1.gapic.enums import Operation
@@ -141,7 +141,7 @@ def delete_cluster(self, name, retry=DEFAULT, 
timeout=DEFAULT):
 op = self.wait_for_operation(op)
 # Returns server-defined url for the resource
 return op.self_link
-except exceptions.NotFound as error:
+except NotFound as error:
 self.log.info('Assuming Success: ' + error.message)
 
 def create_cluster(self, cluster, retry=DEFAULT, timeout=DEFAULT):
diff --git a/tests/contrib/hooks/test_gcp_container_hook.py 
b/tests/contrib/hooks/test_gcp_container_hook.py
index f3705ea4ce..6e13461395 100644
--- a/tests/contrib/hooks/test_gcp_container_hook.py
+++ b/tests/contrib/hooks/test_gcp_container_hook.py
@@ -61,6 +61,22 @@ def test_delete_cluster(self, wait_mock, convert_mock):
 wait_mock.assert_called_with(client_delete.return_value)
 convert_mock.assert_not_called()
 
+@mock.patch(
+"airflow.contrib.hooks.gcp_container_hook.GKEClusterHook.log")
+
@mock.patch("airflow.contrib.hooks.gcp_container_hook.GKEClusterHook._dict_to_proto")
+@mock.patch(
+
"airflow.contrib.hooks.gcp_container_hook.GKEClusterHook.wait_for_operation")
+def test_delete_cluster_not_found(self, wait_mock, convert_mock, log_mock):
+from google.api_core.exceptions import NotFound
+# To force an error
+message = 'Not Found'
+self.gke_hook.client.delete_cluster.side_effect = 
NotFound(message=message)
+
+self.gke_hook.delete_cluster(None)
+wait_mock.assert_not_called()
+convert_mock.assert_not_called()
+log_mock.info.assert_any_call("Assuming Success: " + message)
+
 
@mock.patch("airflow.contrib.hooks.gcp_container_hook.GKEClusterHook._dict_to_proto")
 @mock.patch(
 
"airflow.contrib.hooks.gcp_container_hook.GKEClusterHook.wait_for_operation")
@@ -107,7 +123,7 @@ def test_create_cluster_proto(self, wait_mock, 
convert_mock):
 
@mock.patch("airflow.contrib.hooks.gcp_container_hook.GKEClusterHook._dict_to_proto")
 @mock.patch(
 
"airflow.contrib.hooks.gcp_container_hook.GKEClusterHook.wait_for_operation")
-def test_delete_cluster_dict(self, wait_mock, convert_mock):
+def test_create_cluster_dict(self, wait_mock, convert_mock):
 mock_cluster_dict = {'name': CLUSTER_NAME}
 retry_mock, timeout_mock = mock.Mock(), mock.Mock()
 
@@ -135,6 +151,22 @@ def test_create_cluster_error(self, wait_mock, 
convert_mock):
 wait_mock.assert_not_called()
 convert_mock.assert_not_called()
 
+@mock.patch(
+"airflow.contrib.hooks.gcp_container_hook.GKEClusterHook.log")
+
@mock.patch("airflow.contrib.hooks.gcp_container_hook.GKEClusterHook._dict_to_proto")
+@mock.patch(
+
"airflow.contrib.hooks.gcp_container_hook.GKEClusterHook.wait_for_operation")
+def test_create_cluster_already_exists(self, wait_mock, convert_mock, 
log_mock):
+from google.api_core.exceptions import AlreadyExists
+# To force an error
+message = 'Already Exists'
+self.gke_hook.client.create_cluster.side_effect = 
AlreadyExists(message=message)
+
+self.gke_hook.create_cluster({})
+wait_mock.assert_not_called()
+self.assertEquals(convert_mock.call_count, 1)
+log_mock.info.assert_any_call("Assuming Success: " + message)
+
 
 class GKEClusterHookGetTest(unittest.TestCase):
 def setUp(self):


 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this 

[jira] [Commented] (AIRFLOW-2863) GKEClusterHook catches wrong exception

2018-08-07 Thread ASF subversion and git services (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-2863?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16571967#comment-16571967
 ] 

ASF subversion and git services commented on AIRFLOW-2863:
--

Commit 142a9425db3675fc433b0dbbb637f53638e70a8a in incubator-airflow's branch 
refs/heads/master from [~noremac201]
[ https://gitbox.apache.org/repos/asf?p=incubator-airflow.git;h=142a942 ]

[AIRFLOW-2863] Fix GKEClusterHook catching wrong exception (#3711)



> GKEClusterHook catches wrong exception
> --
>
> Key: AIRFLOW-2863
> URL: https://issues.apache.org/jira/browse/AIRFLOW-2863
> Project: Apache Airflow
>  Issue Type: Bug
>Reporter: Cameron Moberg
>Assignee: Cameron Moberg
>Priority: Minor
>
> Instead of successfully catching the error and reporting success, it reports 
> a failure, since it catches the wrong error.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (AIRFLOW-2863) GKEClusterHook catches wrong exception

2018-08-06 Thread ASF GitHub Bot (JIRA)


[ 
https://issues.apache.org/jira/browse/AIRFLOW-2863?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16570683#comment-16570683
 ] 

ASF GitHub Bot commented on AIRFLOW-2863:
-

Noremac201 opened a new pull request #3711: [AIRFLOW-2863] Fix GKEClusterHook 
catching wrong exception
URL: https://github.com/apache/incubator-airflow/pull/3711
 
 
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [x] My PR addresses the following [Airflow 
Jira](https://issues.apache.org/jira/browse/AIRFLOW/) issues and references 
them in the PR title.
   
 - https://issues.apache.org/jira/browse/AIRFLOW-2863
   
   ### Description
   
   - [x] Here are some details about my PR, including screenshots of any UI 
changes:
   
   GKEClusterHook was catching the wrong exception than it was expecting, and 
therefore would fail instead of succeeding. This fixes that.
   
   ### Tests
   -`test_create_cluster_already_exists`
   -`test_cluter_delete_not_found`
   ### Commits
   
   - [x] My commits all reference Jira issues in their subject lines, and I 
have squashed multiple commits if they address the same issue. In addition, my 
commits follow the guidelines from "[How to write a good git commit 
message](http://chris.beams.io/posts/git-commit/)":
 1. Subject is separated from body by a blank line
 1. Subject is limited to 50 characters (not including Jira issue reference)
 1. Subject does not end with a period
 1. Subject uses the imperative mood ("add", not "adding")
 1. Body wraps at 72 characters
 1. Body explains "what" and "why", not "how"
   
   ### Code Quality
   
   - [x] Passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
   


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> GKEClusterHook catches wrong exception
> --
>
> Key: AIRFLOW-2863
> URL: https://issues.apache.org/jira/browse/AIRFLOW-2863
> Project: Apache Airflow
>  Issue Type: Bug
>Reporter: Cameron Moberg
>Assignee: Cameron Moberg
>Priority: Minor
>
> Instead of successfully catching the error and reporting success, it reports 
> a failure, since it catches the wrong error.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)