Added internal IP tests and updated fixtures Signed-off-by: Quentin Pradet <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/libcloud/repo Commit: http://git-wip-us.apache.org/repos/asf/libcloud/commit/ad392c08 Tree: http://git-wip-us.apache.org/repos/asf/libcloud/tree/ad392c08 Diff: http://git-wip-us.apache.org/repos/asf/libcloud/diff/ad392c08 Branch: refs/heads/trunk Commit: ad392c08855c284eaf2643ab60436e914f356c8a Parents: 718fd95 Author: Gareth Mcfarlane <[email protected]> Authored: Fri Oct 27 15:42:16 2017 +1100 Committer: Quentin Pradet <[email protected]> Committed: Tue Oct 31 08:25:19 2017 +0400 ---------------------------------------------------------------------- ...regions_us-central1_addresses_testaddress.json | 11 +++++++++++ libcloud/test/compute/test_gce.py | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/libcloud/blob/ad392c08/libcloud/test/compute/fixtures/gce/regions_us-central1_addresses_testaddress.json ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/fixtures/gce/regions_us-central1_addresses_testaddress.json b/libcloud/test/compute/fixtures/gce/regions_us-central1_addresses_testaddress.json new file mode 100644 index 0000000..d52a59d --- /dev/null +++ b/libcloud/test/compute/fixtures/gce/regions_us-central1_addresses_testaddress.json @@ -0,0 +1,11 @@ +{ + "address": "173.255.114.104", + "creationTimestamp": "2013-06-04T16:28:43.764-07:00", + "description": "", + "id": "11879548153827627972", + "kind": "compute#address", + "name": "testaddress", + "region": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/v1/projects/project_name/regions/us-central1/addresses/testaddress", + "status": "RESERVED" +} http://git-wip-us.apache.org/repos/asf/libcloud/blob/ad392c08/libcloud/test/compute/test_gce.py ---------------------------------------------------------------------- diff --git a/libcloud/test/compute/test_gce.py b/libcloud/test/compute/test_gce.py index 5d1613c..0e54a76 100644 --- a/libcloud/test/compute/test_gce.py +++ b/libcloud/test/compute/test_gce.py @@ -15,6 +15,7 @@ """ Tests for Google Compute Engine Driver """ + import datetime import mock import sys @@ -166,6 +167,7 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin): def test_build_network_gce_struct(self): network = self.driver.ex_get_network('lcnetwork') address = self.driver.ex_get_address('lcaddress') + internalip = self.driver.ex_get_address('testaddress') subnetwork_name = 'cf-972cf02e6ad49112' subnetwork = self.driver.ex_get_subnetwork(subnetwork_name) d = self.driver._build_network_gce_struct(network, subnetwork, address) @@ -173,7 +175,16 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin): self.assertTrue('subnetwork' in d) self.assertTrue('kind' in d and d['kind'] == 'compute#instanceNetworkInterface') - + self.assertEqual(d['accessConfigs'][0]['natIP'], address.address) + # test with internal IP + d = self.driver._build_network_gce_struct(network, subnetwork, address, + internal_ip=internalip) + self.assertTrue('network' in d) + self.assertTrue('subnetwork' in d) + self.assertTrue('kind' in d and + d['kind'] == 'compute#instanceNetworkInterface') + self.assertEqual(d['accessConfigs'][0]['natIP'], address.address) + self.assertEqual(d['networkIP'], internalip) network = self.driver.ex_get_network('default') d = self.driver._build_network_gce_struct(network) self.assertTrue('network' in d) @@ -2900,6 +2911,11 @@ class GCEMockHttp(MockHttp): 'regions_us-central1_addresses_lcaddress.json') return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK]) + def _regions_us_central1_addresses_testaddress(self, method, url, body, + headers): + body = self.fixtures.load('regions_us-central1_addresses_testaddress.json') + return (httplib.OK, body, self.json_hdr, httplib.responses[httplib.OK]) + def _regions_us_central1_forwardingRules(self, method, url, body, headers): if method == 'POST': body = self.fixtures.load(
