You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by to...@apache.org on 2019/12/24 19:23:26 UTC
[libcloud] 02/04: Update "ex_list_instancegroups" method in the GCE
driver so it doesn't throw an exception if a response doesn't contain
"zone" attribute.
This is an automated email from the ASF dual-hosted git repository.
tomaz pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git
commit fb9529caa0d40d2a1d2c0d19ac37e113dd0a9feb
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Tue Dec 24 19:43:41 2019 +0100
Update "ex_list_instancegroups" method in the GCE driver so it doesn't
throw an exception if a response doesn't contain "zone" attribute.
Reported by Kartik Subbarao.
Resolves #1346
---
libcloud/compute/drivers/gce.py | 6 ++++-
..._instanceGroups_zone_attribute_not_present.json | 27 ++++++++++++++++++++++
libcloud/test/compute/test_gce.py | 15 ++++++++++++
3 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index 5077653..046854b 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -9223,7 +9223,11 @@ class GCENodeDriver(NodeDriver):
extra['namedPorts'] = instancegroup.get('namedPorts', [])
extra['fingerprint'] = instancegroup.get('fingerprint', None)
- zone = self.ex_get_zone(instancegroup['zone'])
+ zone = instancegroup.get('zone', None)
+ if zone:
+ # Apparently zone attribute is not always present, see
+ # https://github.com/apache/libcloud/issues/1346 for details
+ zone = self.ex_get_zone(zone)
# Note: network/subnetwork will not be available if the Instance Group
# does not contain instances.
diff --git a/libcloud/test/compute/fixtures/gce/zones_us_central1_a_instanceGroups_zone_attribute_not_present.json b/libcloud/test/compute/fixtures/gce/zones_us_central1_a_instanceGroups_zone_attribute_not_present.json
new file mode 100644
index 0000000..39c0a80
--- /dev/null
+++ b/libcloud/test/compute/fixtures/gce/zones_us_central1_a_instanceGroups_zone_attribute_not_present.json
@@ -0,0 +1,27 @@
+{
+ "id": "projects/project_name/zones/us-central1-a/instanceGroups",
+ "items": [
+ {
+ "creationTimestamp": "2016-09-09T13:48:39.700-07:00",
+ "description": "",
+ "fingerprint": "42WmSpB8rSM=",
+ "id": "5837905299775594184",
+ "kind": "compute#instanceGroup",
+ "name": "myname",
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instanceGroups/myname",
+ "size": 0
+ },
+ {
+ "creationTimestamp": "2016-09-09T13:54:30.857-07:00",
+ "description": "",
+ "fingerprint": "42WmSpB8rSM=",
+ "id": "6825641674983513961",
+ "kind": "compute#instanceGroup",
+ "name": "myname2",
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instanceGroups/myname2",
+ "size": 0
+ }
+ ],
+ "kind": "compute#instanceGroupList",
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/zones/us-central1-a/instanceGroups"
+}
diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py
index 48a545e..d7cc306 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -396,6 +396,14 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
self.assertEqual(actual[0].name, 'myname')
self.assertEqual(actual[1].name, 'myname2')
+ def test_ex_list_instancegroups_zone_attribute_not_present_in_response(self):
+ GCEMockHttp.type = 'zone_attribute_not_present'
+ loc = 'us-central1-a'
+ actual = self.driver.ex_list_instancegroups(loc)
+ self.assertTrue(len(actual) == 2)
+ self.assertEqual(actual[0].name, 'myname')
+ self.assertEqual(actual[1].name, 'myname2')
+
def test_ex_instancegroup_list_instances(self):
name = 'myname'
loc = 'us-central1-a'
@@ -3783,6 +3791,13 @@ class GCEMockHttp(MockHttp):
'zones_us_central1_a_instanceGroups.json')
return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+ def _zones_us_central1_a_instanceGroups_zone_attribute_not_present(self, method, url, body, headers):
+ if method == 'GET':
+ # get or list call
+ body = self.fixtures.load(
+ 'zones_us_central1_a_instanceGroups_zone_attribute_not_present.json')
+ return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+
def _zones_us_central1_a_operations_operation_zones_us_central1_a_instanceGroups_myname_insert(
self, method, url, body, headers):
""" Redirects from _zones_us_central1_a_instanceGroups """