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 2022/03/13 10:42:48 UTC

[libcloud] branch trunk updated (a7eb9fa -> 1211029)

This is an automated email from the ASF dual-hosted git repository.

tomaz pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/libcloud.git.


    from a7eb9fa  Fix formatting in the changes file.
     new 6e79f9a  Retrieve regions & zones lazily, closes #1661
     new 88667ea  Add tests for GCE region & zone related attributes
     new 7dfec75  Merge branch 'gce-lazy-location-retrieval' of https://github.com/dimgal1/libcloud into dimgal1-gce-lazy-location-retrieval
     new 1211029  Add changelog entry.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGES.rst                       | 13 +++++++++
 libcloud/compute/drivers/gce.py   | 40 ++++++++++++++++++++------
 libcloud/test/compute/test_gce.py | 59 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 104 insertions(+), 8 deletions(-)

[libcloud] 02/04: Add tests for GCE region & zone related attributes

Posted by to...@apache.org.
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 88667ea6fe4d4bca612588e4cca064889dd3ae37
Author: Dimitris Galanis <di...@gmail.com>
AuthorDate: Fri Mar 11 12:02:38 2022 +0200

    Add tests for GCE region & zone related attributes
---
 libcloud/test/compute/test_gce.py | 59 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py
index 97b12f9..0062b92 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -2526,6 +2526,65 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
         zone_no_mw = self.driver.ex_get_zone("us-central1-a")
         self.assertIsNone(zone_no_mw.time_until_mw)
 
+    def test_driver_zone_attributes(self):
+        zones = self.driver.ex_list_zones()
+        self.assertEqual(len(self.driver.zone_dict), len(zones))
+        self.assertEqual(len(self.driver.zone_list), len(zones))
+        for zone, fetched_zone in zip(self.driver.zone_list, zones):
+            self.assertEqual(zone.id, fetched_zone.id)
+            self.assertEqual(zone.name, fetched_zone.name)
+            self.assertEqual(zone.status, fetched_zone.status)
+
+    def test_driver_region_attributes(self):
+        regions = self.driver.ex_list_regions()
+        self.assertEqual(len(self.driver.region_dict), len(regions))
+        self.assertEqual(len(self.driver.region_list), len(regions))
+        for region, fetched_region in zip(self.driver.region_list, regions):
+            self.assertEqual(region.id, fetched_region.id)
+            self.assertEqual(region.name, fetched_region.name)
+            self.assertEqual(region.status, fetched_region.status)
+
+
+class GCENodeDriverTest2(GoogleTestCase):
+    """
+    GCE Test Class, test node driver without passing `datacenter` parameter on initialization.
+    """
+
+    def setUp(self):
+        GCEMockHttp.test = self
+        GCENodeDriver.connectionCls.conn_class = GCEMockHttp
+        GoogleBaseAuthConnection.conn_class = GoogleAuthMockHttp
+        GCEMockHttp.type = None
+        kwargs = GCE_KEYWORD_PARAMS.copy()
+        kwargs["auth_type"] = "IA"
+        self.driver = GCENodeDriver(*GCE_PARAMS, **kwargs)
+
+    def test_zone_attributes(self):
+        self.assertIsNone(self.driver._zone_dict)
+        self.assertIsNone(self.driver._zone_list)
+
+        zones = self.driver.ex_list_zones()
+
+        self.assertEqual(len(self.driver.zone_list), len(zones))
+        self.assertEqual(len(self.driver.zone_dict), len(zones))
+        for zone, fetched_zone in zip(self.driver.zone_list, zones):
+            self.assertEqual(zone.id, fetched_zone.id)
+            self.assertEqual(zone.name, fetched_zone.name)
+            self.assertEqual(zone.status, fetched_zone.status)
+
+    def test_region_attributes(self):
+        self.assertIsNone(self.driver._region_dict)
+        self.assertIsNone(self.driver._region_list)
+
+        regions = self.driver.ex_list_regions()
+
+        self.assertEqual(len(self.driver.region_list), len(regions))
+        self.assertEqual(len(self.driver.region_dict), len(regions))
+        for region, fetched_region in zip(self.driver.region_list, regions):
+            self.assertEqual(region.id, fetched_region.id)
+            self.assertEqual(region.name, fetched_region.name)
+            self.assertEqual(region.status, fetched_region.status)
+
 
 class GCEMockHttp(MockHttp, unittest.TestCase):
     fixtures = ComputeFileFixtures("gce")

[libcloud] 04/04: Add changelog entry.

Posted by to...@apache.org.
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 12110292cbf9a1fa7f442421ed7b77b77840070a
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Sun Mar 13 11:31:25 2022 +0100

    Add changelog entry.
---
 CHANGES.rst | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/CHANGES.rst b/CHANGES.rst
index 9fdb466..34a054e 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -1,6 +1,19 @@
 Changelog
 =========
 
+Changes in Apache Libcloud in development
+-----------------------------------------
+
+Compute
+~~~~~~~
+
+- [GCE] Retrieve regions and zones lazily when they are first accessed (via
+  self.zone_{dict,list} and self.region_{dict,list} attribute) instead of
+  retrieving them inside the driver constructor.
+
+  (GITHUB-1661, GITHUB-1661)
+  [Dimitris Galanis - @dimgal1]
+
 Changes in Apache Libcloud 3.5.0
 --------------------------------
 

[libcloud] 01/04: Retrieve regions & zones lazily, closes #1661

Posted by to...@apache.org.
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 6e79f9a3a5edf12e9c345c94cd641fbc4fb8776c
Author: Dimitris Galanis <di...@gmail.com>
AuthorDate: Thu Mar 10 12:40:32 2022 +0200

    Retrieve regions & zones lazily, closes #1661
---
 libcloud/compute/drivers/gce.py | 40 ++++++++++++++++++++++++++++++++--------
 1 file changed, 32 insertions(+), 8 deletions(-)

diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index f084eee..f1b203f 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -2108,19 +2108,17 @@ class GCENodeDriver(NodeDriver):
         # Cache Zone and Region information to reduce API calls and
         # increase speed
         self.base_path = "/compute/%s/projects/%s" % (API_VERSION, self.project)
-        self.zone_list = self.ex_list_zones()
-        self.zone_dict = {}
-        for zone in self.zone_list:
-            self.zone_dict[zone.name] = zone
+
+        self._zone_dict = None
+        self._zone_list = None
+
         if datacenter:
             self.zone = self.ex_get_zone(datacenter)
         else:
             self.zone = None
 
-        self.region_list = self.ex_list_regions()
-        self.region_dict = {}
-        for region in self.region_list:
-            self.region_dict[region.name] = region
+        self._region_dict = None
+        self._region_list = None
 
         if self.zone:
             self.region = self._get_region_from_zone(self.zone)
@@ -2131,6 +2129,32 @@ class GCENodeDriver(NodeDriver):
         # It is populated if the volume name is not found or the dict is empty.
         self._ex_volume_dict = {}
 
+    @property
+    def zone_dict(self):
+        if self._zone_dict is None:
+            zones = self.ex_list_zones()
+            self._zone_dict = {zone.name: zone for zone in zones}
+        return self._zone_dict
+
+    @property
+    def zone_list(self):
+        if self._zone_list is None:
+            self._zone_list = list(self.zone_dict.values())
+        return self._zone_list
+
+    @property
+    def region_dict(self):
+        if self._region_dict is None:
+            regions = self.ex_list_regions()
+            self._region_dict = {region.name: region for region in regions}
+        return self._region_dict
+
+    @property
+    def region_list(self):
+        if self._region_list is None:
+            self._region_list = list(self.region_dict.values())
+        return self._region_list
+
     def ex_add_access_config(self, node, name, nic, nat_ip=None, config_type=None):
         """
         Add a network interface access configuration to a node.

[libcloud] 03/04: Merge branch 'gce-lazy-location-retrieval' of https://github.com/dimgal1/libcloud into dimgal1-gce-lazy-location-retrieval

Posted by to...@apache.org.
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 7dfec7571ae5d88a5476167adc61129be4839767
Merge: a7eb9fa 88667ea
Author: Tomaz Muraus <to...@tomaz.me>
AuthorDate: Sun Mar 13 11:29:25 2022 +0100

    Merge branch 'gce-lazy-location-retrieval' of https://github.com/dimgal1/libcloud into dimgal1-gce-lazy-location-retrieval

 libcloud/compute/drivers/gce.py   | 40 ++++++++++++++++++++------
 libcloud/test/compute/test_gce.py | 59 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+), 8 deletions(-)