libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From quent...@apache.org
Subject [1/2] libcloud git commit: Use disk size and storage tier also when creating node from template
Date Fri, 06 Oct 2017 18:51:40 GMT
Repository: libcloud
Updated Branches:
  refs/heads/trunk 4fef3b539 -> bba685f23


Use disk size and storage tier also when creating node from template

Closes #1124

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


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

Branch: refs/heads/trunk
Commit: 63eeacd4f7c463bbeb0427d72fb852f3d3404232
Parents: 4fef3b5
Author: Mika Lackman <mika.lackman@upcloud.com>
Authored: Fri Oct 6 17:58:47 2017 +0300
Committer: Quentin Pradet <quentinp@apache.org>
Committed: Fri Oct 6 22:45:33 2017 +0400

----------------------------------------------------------------------
 libcloud/common/upcloud.py            | 29 +++++++++++++------------
 libcloud/test/common/test_upcloud.py  | 35 ++++++++++++++++++++++++++++--
 libcloud/test/compute/test_upcloud.py |  4 ++--
 3 files changed, 50 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/63eeacd4/libcloud/common/upcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/common/upcloud.py b/libcloud/common/upcloud.py
index 64f844e..796fa58 100644
--- a/libcloud/common/upcloud.py
+++ b/libcloud/common/upcloud.py
@@ -230,25 +230,19 @@ class _StorageDevice(object):
             return self._storage_device_for_cdrom_image()
 
     def _storage_device_for_template_image(self):
-        storage_devices = {
-            'storage_device': [{
-                'action': 'clone',
-                'title': self.image.name,
-                'storage': self.image.id
-            }]
+        hdd_device = {
+            'action': 'clone',
+            'storage': self.image.id
         }
-        return storage_devices
+        hdd_device.update(self._common_hdd_device())
+        return {'storage_device': [hdd_device]}
 
     def _storage_device_for_cdrom_image(self):
+        hdd_device = {'action': 'create'}
+        hdd_device.update(self._common_hdd_device())
         storage_devices = {
             'storage_device': [
-                {
-                    'action': 'create',
-                    'title': self.image.name,
-                    'size': self.size.disk,
-                    'tier': self.size.extra['storage_tier']
-
-                },
+                hdd_device,
                 {
                     'action': 'attach',
                     'storage': self.image.id,
@@ -257,3 +251,10 @@ class _StorageDevice(object):
             ]
         }
         return storage_devices
+
+    def _common_hdd_device(self):
+        return {
+            'title': self.image.name,
+            'size': self.size.disk,
+            'tier': self.size.extra.get('storage_tier', 'maxiops')
+        }

http://git-wip-us.apache.org/repos/asf/libcloud/blob/63eeacd4/libcloud/test/common/test_upcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/test/common/test_upcloud.py b/libcloud/test/common/test_upcloud.py
index bfa2b89..6d6ee0f 100644
--- a/libcloud/test/common/test_upcloud.py
+++ b/libcloud/test/common/test_upcloud.py
@@ -18,6 +18,7 @@ import json
 from mock import Mock, call
 
 from libcloud.common.upcloud import UpcloudCreateNodeRequestBody, UpcloudNodeDestroyer, UpcloudNodeOperations
+from libcloud.common.upcloud import _StorageDevice
 from libcloud.common.upcloud import UpcloudTimeoutException
 from libcloud.compute.base import NodeImage, NodeSize, NodeLocation, NodeAuthSSHKey
 from libcloud.test import unittest
@@ -49,7 +50,9 @@ class TestUpcloudCreateNodeRequestBody(unittest.TestCase):
                     'storage_device': [{
                         'action': 'clone',
                         'title': 'Ubuntu Server 16.04 LTS (Xenial Xerus)',
-                        'storage': '01000000-0000-4000-8000-000030060200'
+                        'storage': '01000000-0000-4000-8000-000030060200',
+                        'size': 30,
+                        'tier': 'maxiops',
                     }]
                 },
             }
@@ -125,7 +128,9 @@ class TestUpcloudCreateNodeRequestBody(unittest.TestCase):
                 'storage_devices': {
                     'storage_device': [{
                         'action': 'clone',
+                        'size': 30,
                         'title': 'Ubuntu Server 16.04 LTS (Xenial Xerus)',
+                        'tier': 'maxiops',
                         'storage': '01000000-0000-4000-8000-000030060200'
                     }]
                 },
@@ -158,7 +163,9 @@ class TestUpcloudCreateNodeRequestBody(unittest.TestCase):
                     'storage_device': [{
                         'action': 'clone',
                         'title': 'Ubuntu Server 16.04 LTS (Xenial Xerus)',
-                        'storage': '01000000-0000-4000-8000-000030060200'
+                        'storage': '01000000-0000-4000-8000-000030060200',
+                        'tier': 'maxiops',
+                        'size': 30
                     }]
                 },
             }
@@ -166,6 +173,30 @@ class TestUpcloudCreateNodeRequestBody(unittest.TestCase):
         self.assertDictEqual(expected_body, dict_body)
 
 
+class TestStorageDevice(unittest.TestCase):
+
+    def setUp(self):
+        self.image = NodeImage(id='01000000-0000-4000-8000-000030060200',
+                               name='Ubuntu Server 16.04 LTS (Xenial Xerus)',
+                               driver='',
+                               extra={'type': 'template'})
+        self.size = NodeSize(id='1xCPU-1GB', name='1xCPU-1GB', ram=1024, disk=30, bandwidth=2048,
+                             extra={'core_number': 1}, price=None, driver='')
+
+    def test_storage_tier_default_value(self):
+        storagedevice = _StorageDevice(self.image, self.size)
+        d = storagedevice.to_dict()
+
+        self.assertEquals(d['storage_device'][0]['tier'], 'maxiops')
+
+    def test_storage_tier_given(self):
+        self.size.extra['storage_tier'] = 'hdd'
+        storagedevice = _StorageDevice(self.image, self.size)
+        d = storagedevice.to_dict()
+
+        self.assertEquals(d['storage_device'][0]['tier'], 'hdd')
+
+
 class TestUpcloudNodeDestroyer(unittest.TestCase):
 
     def setUp(self):

http://git-wip-us.apache.org/repos/asf/libcloud/blob/63eeacd4/libcloud/test/compute/test_upcloud.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_upcloud.py b/libcloud/test/compute/test_upcloud.py
index 09e453e..951ee29 100644
--- a/libcloud/test/compute/test_upcloud.py
+++ b/libcloud/test/compute/test_upcloud.py
@@ -114,7 +114,7 @@ class UpcloudDriverTests(LibcloudTestCase):
                           driver=self.driver)
         location = NodeLocation(id='fi-hel1', name='Helsinki #1', country='FI', driver=self.driver)
         size = NodeSize(id='1xCPU-1GB', name='1xCPU-1GB', ram=1024, disk=30, bandwidth=2048,
-                        extra={'core_number': 1, 'storage_tier': 'maxiops'}, price=None,
driver=self.driver)
+                        extra={'storage_tier': 'maxiops'}, price=None, driver=self.driver)
         node = self.driver.create_node(name='test_server', size=size, image=image, location=location,
ex_hostname='myhost.somewhere')
 
         self.assertTrue(re.match('^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$',
node.id))
@@ -133,7 +133,7 @@ class UpcloudDriverTests(LibcloudTestCase):
                           driver=self.driver)
         location = NodeLocation(id='fi-hel1', name='Helsinki #1', country='FI', driver=self.driver)
         size = NodeSize(id='1xCPU-1GB', name='1xCPU-1GB', ram=1024, disk=30, bandwidth=2048,
-                        extra={'core_number': 1, 'storage_tier': 'maxiops'}, price=None,
driver=self.driver)
+                        extra={'storage_tier': 'maxiops'}, price=None, driver=self.driver)
 
         auth = NodeAuthSSHKey('publikey')
         node = self.driver.create_node(name='test_server', size=size, image=image, location=location,
auth=auth)


Mime
View raw message