Added testing for guest os features.

Closes #825


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

Branch: refs/heads/trunk
Commit: 370c7495fb42d9eb9fd13197abb37036a942d0ee
Parents: 67368d0
Author: Max Illfelder <[email protected]>
Authored: Tue Jun 28 19:10:55 2016 -0700
Committer: Anthony Shaw <[email protected]>
Committed: Wed Jun 29 14:30:38 2016 +1000

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


http://git-wip-us.apache.org/repos/asf/libcloud/blob/370c7495/libcloud/compute/drivers/gce.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/gce.py b/libcloud/compute/drivers/gce.py
index 61f6e0c..94dc7f6 100644
--- a/libcloud/compute/drivers/gce.py
+++ b/libcloud/compute/drivers/gce.py
@@ -4756,7 +4756,7 @@ class GCENodeDriver(NodeDriver):
         :type   family: ``str``
 
         :param  guest_os_features: The features of the guest operating system.
-        :type   guest_os_features: ``list`` of ``str`` or ``None``
+        :type   guest_os_features: ``list`` of ``dict`` or ``None``
 
         :return:  NodeImage object based on provided information or None if an
                   image with that name is not found.

http://git-wip-us.apache.org/repos/asf/libcloud/blob/370c7495/libcloud/test/compute/test_gce.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_gce.py 
b/libcloud/test/compute/test_gce.py
index 0d8843f..f7c2a0c 100644
--- a/libcloud/test/compute/test_gce.py
+++ b/libcloud/test/compute/test_gce.py
@@ -15,9 +15,10 @@
 """
 Tests for Google Compute Engine Driver
 """
+import datetime
+import mock
 import sys
 import unittest
-import datetime
 
 from libcloud.utils.py3 import httplib
 from libcloud.compute.drivers.gce import (GCENodeDriver, API_VERSION,
@@ -449,13 +450,32 @@ class GCENodeDriverTest(GoogleTestCase, TestCaseMixin):
 
     def test_ex_create_image(self):
         volume = self.driver.ex_get_volume('lcdisk')
-        image = self.driver.ex_create_image('coreos', volume)
+        description = 'CoreOS beta 522.3.0'
+        name = 'coreos'
+        family = 'coreos'
+        guest_os_features = ['VIRTIO_SCSI_MULTIQUEUE']
+        expected_features = [{'type': 'VIRTIO_SCSI_MULTIQUEUE'}]
+        mock_request = mock.Mock()
+        mock_request.side_effect = self.driver.connection.async_request
+        self.driver.connection.async_request = mock_request
+
+        image = self.driver.ex_create_image(
+            name, volume, description=description, family='coreos',
+            guest_os_features=guest_os_features)
         self.assertTrue(isinstance(image, GCENodeImage))
-        self.assertTrue(image.name.startswith('coreos'))
-        self.assertEqual(image.extra['description'], 'CoreOS beta 522.3.0')
-        self.assertEqual(image.extra['family'], 'coreos')
-        self.assertEqual(image.extra['guestOsFeatures'],
-                         [{'type': 'VIRTIO_SCSI_MULTIQUEUE'}])
+        self.assertTrue(image.name.startswith(name))
+        self.assertEqual(image.extra['description'], description)
+        self.assertEqual(image.extra['family'], family)
+        self.assertEqual(image.extra['guestOsFeatures'], expected_features)
+        expected_data = {'description': description,
+                         'family': family,
+                         'guestOsFeatures': expected_features,
+                         'name': name,
+                         'sourceDisk': volume.extra['selfLink'],
+                         'zone': volume.extra['zone'].name}
+        mock_request.assert_called_once_with('/global/images',
+                                             data=expected_data,
+                                             method='POST')
 
     def test_ex_create_firewall(self):
         firewall_name = 'lcfirewall'

Reply via email to