You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@libcloud.apache.org by qu...@apache.org on 2018/01/19 20:25:14 UTC

[6/9] libcloud git commit: Add test for shared network and subnetwork

Add test for shared network and subnetwork

Signed-off-by: Quentin Pradet <qu...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/7e1100e3
Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/7e1100e3
Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/7e1100e3

Branch: refs/heads/trunk
Commit: 7e1100e39da6381dc9bad04f5a743d8d325cf902
Parents: dcef9e8
Author: Boris Chazalet <bc...@companywatch.net>
Authored: Fri Jan 19 14:46:17 2018 +0100
Committer: Quentin Pradet <qu...@apache.org>
Committed: Sat Jan 20 00:22:53 2018 +0400

----------------------------------------------------------------------
 .../projects_other_name_global_networks_cf.json | 11 ++++
 ...ts_other_name_global_networks_lcnetwork.json | 10 +++
 ...projects_other_name_regions_us-central1.json | 65 ++++++++++++++++++++
 ...entral1_subnetworks_cf_972cf02e6ad49114.json | 12 ++++
 libcloud/test/compute/test_gce.py               | 29 +++++++++
 5 files changed, 127 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/7e1100e3/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_cf.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_cf.json b/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_cf.json
new file mode 100644
index 0000000..63e99d3
--- /dev/null
+++ b/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_cf.json
@@ -0,0 +1,11 @@
+{
+ "kind": "compute#network",
+ "id": "5125152985904090792",
+ "creationTimestamp": "2016-03-25T05:34:15.077-07:00",
+ "name": "cf",
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/other_name/global/networks/cf",
+ "autoCreateSubnetworks": true,
+ "subnetworks": [
+  "https://www.googleapis.com/compute/v1/projects/other_name/regions/us-central1/subnetworks/cf-972cf02e6ad49114"
+ ]
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7e1100e3/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_lcnetwork.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_lcnetwork.json b/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_lcnetwork.json
new file mode 100644
index 0000000..e48ab34
--- /dev/null
+++ b/libcloud/test/compute/fixtures/gce/projects_other_name_global_networks_lcnetwork.json
@@ -0,0 +1,10 @@
+{
+  "IPv4Range": "10.11.0.0/16",
+  "creationTimestamp": "2013-06-26T10:05:03.500-07:00",
+  "gatewayIPv4": "10.11.0.1",
+  "description": "A custom network",
+  "id": "16211908079305042870",
+  "kind": "compute#network",
+  "name": "lcnetwork",
+  "selfLink": "https://www.googleapis.com/compute/v1/projects/other_name/global/networks/lcnetwork"
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7e1100e3/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1.json b/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1.json
new file mode 100644
index 0000000..1e41eb0
--- /dev/null
+++ b/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1.json
@@ -0,0 +1,65 @@
+{
+ "kind": "compute#region",
+ "id": "1000",
+ "creationTimestamp": "2014-05-30T18:35:16.413-07:00",
+ "name": "us-central1",
+ "description": "us-central1",
+ "status": "UP",
+ "zones": [
+  "https://www.googleapis.com/compute/v1/projects/other_name/zones/us-central1-a",
+  "https://www.googleapis.com/compute/v1/projects/other_name/zones/us-central1-b"
+ ],
+ "quotas": [
+  {
+   "metric": "CPUS",
+   "limit": 1050.0,
+   "usage": 30.0
+  },
+  {
+   "metric": "DISKS_TOTAL_GB",
+   "limit": 20000.0,
+   "usage": 344.0
+  },
+  {
+   "metric": "STATIC_ADDRESSES",
+   "limit": 10.0,
+   "usage": 2.0
+  },
+  {
+   "metric": "IN_USE_ADDRESSES",
+   "limit": 1050.0,
+   "usage": 11.0
+  },
+  {
+   "metric": "SSD_TOTAL_GB",
+   "limit": 2048.0,
+   "usage": 500.0
+  },
+  {
+   "metric": "LOCAL_SSD_TOTAL_GB",
+   "limit": 10240.0,
+   "usage": 0.0
+  },
+  {
+   "metric": "INSTANCE_GROUPS",
+   "limit": 100.0,
+   "usage": 0.0
+  },
+  {
+   "metric": "INSTANCE_GROUP_MANAGERS",
+   "limit": 50.0,
+   "usage": 0.0
+  },
+  {
+   "metric": "INSTANCES",
+   "limit": 10500.0,
+   "usage": 11.0
+  },
+  {
+   "metric": "AUTOSCALERS",
+   "limit": 50.0,
+   "usage": 0.0
+  }
+ ],
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1"
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7e1100e3/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1_subnetworks_cf_972cf02e6ad49114.json
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1_subnetworks_cf_972cf02e6ad49114.json b/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1_subnetworks_cf_972cf02e6ad49114.json
new file mode 100644
index 0000000..56c8e7d
--- /dev/null
+++ b/libcloud/test/compute/fixtures/gce/projects_other_name_regions_us-central1_subnetworks_cf_972cf02e6ad49114.json
@@ -0,0 +1,12 @@
+{
+ "status": "DONE",
+ "kind": "compute#subnetwork",
+ "id": "4297043163355844285",
+ "creationTimestamp": "2016-03-25T05:34:27.209-07:00",
+ "gatewayAddress": "10.128.0.1",
+ "name": "cf-972cf02e6ad49114",
+ "network": "https://www.googleapis.com/compute/v1/projects/other_name/global/networks/cf",
+ "ipCidrRange": "10.128.0.0/20",
+ "region": "https://www.googleapis.com/compute/v1/projects/other_name/regions/us-central1",
+ "selfLink": "https://www.googleapis.com/compute/v1/projects/other_name/regions/us-central1/subnetworks/cf-972cf02e6ad49112"
+}

http://git-wip-us.apache.org/repos/asf/libcloud/blob/7e1100e3/libcloud/test/compute/test_gce.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py
index 2ed4fa0..7ffd3d6 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -562,6 +562,10 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
         subnetwork = self.driver.ex_get_subnetwork(url)
         self.assertEqual(subnetwork.name, name)
         self.assertEqual(subnetwork.region.name, region_name)
+        # test with a subnetwork that is under a different project
+        url_other = 'https://www.googleapis.com/compute/v1/projects/other_name/regions/us-central1/subnetworks/cf-972cf02e6ad49114'
+        subnetwork = self.driver.ex_get_subnetwork(url_other)
+        self.assertEqual(subnetwork.name, "cf-972cf02e6ad49114")
 
     def test_ex_list_networks(self):
         networks = self.driver.ex_list_networks()
@@ -1759,6 +1763,13 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
         self.assertEqual(network.cidr, '10.11.0.0/16')
         self.assertEqual(network.extra['gatewayIPv4'], '10.11.0.1')
         self.assertEqual(network.extra['description'], 'A custom network')
+        # do the same but with a network under a different project
+        url_other = 'https://www.googleapis.com/compute/v1/projects/other_name/global/networks/lcnetwork'
+        network = self.driver.ex_get_network(url_other)
+        self.assertEqual(network.name, network_name)
+        self.assertEqual(network.cidr, '10.11.0.0/16')
+        self.assertEqual(network.extra['gatewayIPv4'], '10.11.0.1')
+        self.assertEqual(network.extra['description'], 'A custom network')
 
     def test_ex_get_node(self):
         node_name = 'node-name'
@@ -2577,6 +2588,24 @@ class GCEMockHttp(MockHttp):
             'regions_us-central1_subnetworks_cf_972cf02e6ad49112.json')
         return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
 
+    def _projects_other_name_regions_us_central1(self, method, url, body, headers):
+        body = self.fixtures.load('projects_other_name_regions_us-central1.json')
+        return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+
+    def _projects_other_name_global_networks_lcnetwork(self, method, url, body, headers):
+        body = self.fixtures.load('projects_other_name_global_networks_lcnetwork.json')
+        return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+
+    def _projects_other_name_global_networks_cf(self, method, url, body, headers):
+        body = self.fixtures.load('projects_other_name_global_networks_cf.json')
+        return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+
+    def _projects_other_name_regions_us_central1_subnetworks_cf_972cf02e6ad49114(
+            self, method, url, body, headers):
+        body = self.fixtures.load(
+            'projects_other_name_regions_us-central1_subnetworks_cf_972cf02e6ad49114.json')
+        return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK])
+
     def _regions_us_central1_operations_operation_regions_us_central1_addresses_lcaddress_delete(
             self, method, url, body, headers):
         body = self.fixtures.load(