libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject [libcloud] 06/14: [ovh] Tests!
Date Sun, 04 Oct 2020 15:39:25 GMT
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 41aa722259050bb6bba911c21dc3f07863ffe07a
Author: Dan Hunsaker <danhunsaker@gmail.com>
AuthorDate: Tue Sep 22 16:38:04 2020 -0600

    [ovh] Tests!
    
    Plus a tiny bit of code cleanup, and use a non-deprecated endpoint.
---
 libcloud/compute/drivers/ovh.py                          | 16 ++++++++++------
 libcloud/test/common/test_ovh.py                         |  2 +-
 libcloud/test/compute/fixtures/ovh/flavor_get.json       |  2 +-
 .../test/compute/fixtures/ovh/flavor_get_detail.json     |  2 +-
 libcloud/test/compute/fixtures/ovh/pricing_get.json      |  1 +
 libcloud/test/compute/test_ovh.py                        |  7 +++++++
 6 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/libcloud/compute/drivers/ovh.py b/libcloud/compute/drivers/ovh.py
index 7e7fcd8..d59890e 100644
--- a/libcloud/compute/drivers/ovh.py
+++ b/libcloud/compute/drivers/ovh.py
@@ -44,7 +44,8 @@ class OvhNodeDriver(NodeDriver):
     VOLUME_STATE_MAP = OpenStackNodeDriver.VOLUME_STATE_MAP
     SNAPSHOT_STATE_MAP = OpenStackNodeDriver.SNAPSHOT_STATE_MAP
 
-    def __init__(self, key, secret, ex_project_id, ex_consumer_key=None, ex_datacenter=None):
+    def __init__(self, key, secret, ex_project_id, ex_consumer_key=None,
+                 ex_datacenter=None):
         """
         Instantiate the driver with the given API credentials.
 
@@ -68,7 +69,8 @@ class OvhNodeDriver(NodeDriver):
         self.datacenter = ex_datacenter
         self.project_id = ex_project_id
         self.consumer_key = ex_consumer_key
-        NodeDriver.__init__(self, key, secret, ex_consumer_key=ex_consumer_key, ex_datacenter=ex_datacenter)
+        NodeDriver.__init__(self, key, secret, ex_consumer_key=ex_consumer_key,
+                            ex_datacenter=ex_datacenter)
 
     def _get_project_action(self, suffix):
         base_url = '%s/cloud/project/%s/' % (API_ROOT, self.project_id)
@@ -457,11 +459,13 @@ class OvhNodeDriver(NodeDriver):
         response = self.connection.request(action, method='DELETE')
         return response.status == httplib.OK
 
-    def ex_get_pricing(self, size_id):
-        pricing = self.connection.request('%s/cloud/price' % (API_ROOT),
-            params={'flavorId': size_id}).object['instances'][0]
+    def ex_get_pricing(self, size_id, subsidiary='US'):
+        action = '%s/cloud/subsidiaryPrice' % (API_ROOT)
+        params = {'flavorId': size_id, 'ovhSubsidiary': subsidiary}
+        pricing = self.connection.request(action, params=params
+                                          ).object['instances'][0]
         return {'hourly': pricing['price']['value'],
-            'monthly': pricing['monthlyPrice']['value']}
+                'monthly': pricing['monthlyPrice']['value']}
 
     def _to_volume(self, obj):
         extra = obj.copy()
diff --git a/libcloud/test/common/test_ovh.py b/libcloud/test/common/test_ovh.py
index c1662d6..1410e85 100644
--- a/libcloud/test/common/test_ovh.py
+++ b/libcloud/test/common/test_ovh.py
@@ -16,7 +16,7 @@
 import re
 from libcloud.test import MockHttp
 
-FORMAT_URL = re.compile(r'[./?=-]')
+FORMAT_URL = re.compile(r'[./?=&-]')
 
 
 class BaseOvhMockHttp(MockHttp):
diff --git a/libcloud/test/compute/fixtures/ovh/flavor_get.json b/libcloud/test/compute/fixtures/ovh/flavor_get.json
index d81087d..21b28b3 100644
--- a/libcloud/test/compute/fixtures/ovh/flavor_get.json
+++ b/libcloud/test/compute/fixtures/ovh/flavor_get.json
@@ -1 +1 @@
-[{"id":"foo-id","disk":80,"name":"ovh.intel.ha.l","ram":8192,"vcpus":2,"region":"SBG1","type":"ovh.ceph.eg","inboundBandwidth":511,"osType":"Linux"},{"id":"bar-id","disk":80,"name":"ovh.intel.ha.l","ram":8192,"vcpus":2,"region":"SBG1","type":"ovh.ceph.eg",
"outboundBandwidth": 511,"inboundBandwidth": 511,"osType":"Linux"}]
+[{"id":"foo-id","disk":80,"name":"ovh.intel.ha.l","ram":8192,"vcpus":2,"region":"SBG1","type":"ovh.ceph.eg","outboundBandwidth":511,"inboundBandwidth":511,"osType":"Linux"},{"id":"bar-id","disk":80,"name":"ovh.intel.ha.l","ram":8192,"vcpus":2,"region":"SBG1","type":"ovh.ceph.eg","outboundBandwidth":511,"inboundBandwidth":511,"osType":"Linux"}]
diff --git a/libcloud/test/compute/fixtures/ovh/flavor_get_detail.json b/libcloud/test/compute/fixtures/ovh/flavor_get_detail.json
index 9695862..53d27c4 100644
--- a/libcloud/test/compute/fixtures/ovh/flavor_get_detail.json
+++ b/libcloud/test/compute/fixtures/ovh/flavor_get_detail.json
@@ -1 +1 @@
-{"id":"foo-id","disk":80,"name":"ra.intel.ha.l","ram":8192,"vcpus":2,"region":"SBG-1","type":"ra.s"}
+{"id":"foo-id","disk":80,"name":"ra.intel.ha.l","ram":8192,"vcpus":2,"region":"SBG-1","type":"ra.s","outboundBandwidth":511,"inboundBandwidth":511}
diff --git a/libcloud/test/compute/fixtures/ovh/pricing_get.json b/libcloud/test/compute/fixtures/ovh/pricing_get.json
new file mode 100644
index 0000000..83243de
--- /dev/null
+++ b/libcloud/test/compute/fixtures/ovh/pricing_get.json
@@ -0,0 +1 @@
+{"snapshots":[],"bandwidthStorage":[],"storage":[],"archive":[],"volumes":[],"bandwidthArchiveOut":[],"projectCreation":{"currencyCode":"USD","text":"$40USD","value":40},"instances":[{"flavorId":"foo-id","flavorName":"ra.intel.ha.l","region":"SBG-1","price":{"currencyCode":"USD","text":"$40USD","value":40},"monthlyPrice":{"currencyCode":"USD","text":"$40USD","value":40}}],"bandwidthArchiveIn":[]}
diff --git a/libcloud/test/compute/test_ovh.py b/libcloud/test/compute/test_ovh.py
index 77394e5..4e8b1e5 100644
--- a/libcloud/test/compute/test_ovh.py
+++ b/libcloud/test/compute/test_ovh.py
@@ -126,6 +126,10 @@ class OvhMockHttp(BaseOvhMockHttp):
         body = self.fixtures.load('volume_snapshot_get_details.json')
         return (httplib.OK, body, {}, httplib.responses[httplib.OK])
 
+    def _json_1_0_cloud_subsidiaryPrice_flavorId_foo_id_ovhSubsidiary_US_get(self, method,
url, body, headers):
+        body = self.fixtures.load('pricing_get.json')
+        return (httplib.OK, body, {}, httplib.responses[httplib.OK])
+
 
 @patch('libcloud.common.ovh.OvhConnection._timedelta', 42)
 class OvhTests(unittest.TestCase):
@@ -238,5 +242,8 @@ class OvhTests(unittest.TestCase):
         result = self.driver.destroy_volume_snapshot(snapshot)
         self.assertTrue(result)
 
+    def test_get_pricing(self):
+        self.driver.ex_get_pricing('foo-id')
+
 if __name__ == '__main__':
     sys.exit(unittest.main())


Mime
View raw message