FAM-690 Added tests

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

Branch: refs/heads/trunk
Commit: 4ab938a19c24c964306e097e373fdb1a69136d3b
Parents: 5352e71
Author: mermoldy <s.ba...@scalr.com>
Authored: Thu Mar 9 20:33:26 2017 +0200
Committer: Anthony Shaw <anthonys...@apache.org>
Committed: Fri Aug 11 14:59:31 2017 +1000

----------------------------------------------------------------------
 libcloud/compute/drivers/azure_arm.py           |  33 +-
 ...99999999999_providers_Microsoft_Compute.json |   2 +-
 ...99999_providers_Microsoft_Compute_disks.json |  65 ++++
 ...9_providers_Microsoft_Compute_snapshots.json |  75 ++++
 ...iders_Microsoft_Compute_virtualMachines.json |  52 +++
 ...ers_Microsoft_Compute_disks_test_disk_1.json |  22 ++
 ...Microsoft_Compute_snapshots_test_snap_1.json |  20 ++
 ...oft_Compute_virtualMachines_test_node_1.json |  48 +++
 ...irtualMachines_test_node_1_InstanceView.json |  27 ++
 ...twork_networkInterfaces_test_node_1_nic.json |  38 +++
 ...11111_providers_Microsoft_Compute_disks.json |  22 ++
 ...1_providers_Microsoft_Compute_snapshots.json |  38 +++
 libcloud/test/compute/test_azure_arm.py         | 342 ++++++++++++++++++-
 13 files changed, 752 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/compute/drivers/azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/compute/drivers/azure_arm.py 
b/libcloud/compute/drivers/azure_arm.py
index 3326a74..b85eb77 100644
--- a/libcloud/compute/drivers/azure_arm.py
+++ b/libcloud/compute/drivers/azure_arm.py
@@ -492,7 +492,7 @@ class AzureNodeDriver(NodeDriver):
             automatically manage the availability of disks to provide data
             redundancy and fault tolerance, without creating and managing
             storage accounts on your own. Managed disks may not be available
-            in all regions.
+            in all regions (default False).
         :type ex_use_managed_disks: ``bool``
 
         :param ex_storage_account_type: The Storage Account type,
@@ -772,21 +772,20 @@ class AzureNodeDriver(NodeDriver):
         """
         Create a new volume.
 
-        :param size: Size of volume in gigabytes (required)
+        :param size: Size of volume in gigabytes.
         :type size: ``int``
 
-        :param name: Name of the volume to be created
+        :param name: Name of the volume to be created.
         :type name: ``str``
 
-        :param location: Which data center to create a volume in.
+        :param location: Which data center to create a volume in. (required)
         :type location: :class:`NodeLocation`
 
-        :param snapshot: Snapshot from which to create the new
-            volume.  (optional)
+        :param snapshot: Snapshot from which to create the new volume.
         :type snapshot: :class:`VolumeSnapshot`
 
         :param ex_resource_group: The name of resource group in which to
-            create the volume.
+            create the volume. (required)
         :type ex_resource_group: ``str``
 
         :param ex_tags: Optional tags to associate with this resource.
@@ -872,7 +871,7 @@ class AzureNodeDriver(NodeDriver):
         )
         return [self._to_volume(volume) for volume in response.object['value']]
 
-    def attach_volume(self, node, volume, device=None, ex_lun=None):
+    def attach_volume(self, node, volume, ex_lun=None, **ex_kwargs):
         """
         Attach a managed volume to node.
 
@@ -882,9 +881,6 @@ class AzureNodeDriver(NodeDriver):
         :param volume: A volume to attach.
         :type volume: :class:`StorageVolume`
 
-        :param device: A node device to attach volume(not supported by Azure).
-        :type device: ``str``
-
         :param ex_lun: Specifies the logical unit number (LUN) location for
             the data drive in the virtual machine. Each data disk must have
             a unique LUN.
@@ -989,14 +985,14 @@ class AzureNodeDriver(NodeDriver):
         :param volume: Instance of ``StorageVolume``.
         :type volume: :class`StorageVolume`
 
-        :param name: Name of snapshot (optional).
+        :param name: Name of snapshot. (required)
         :type name: ``str``
 
-        :param location: Which data center to create a volume in.
+        :param location: Which data center to create a volume in. (required)
         :type location: :class:`NodeLocation`
 
         :param ex_resource_group: The name of resource group in which to
-            create the snapshot.
+            create the snapshot. (required)
         :type ex_resource_group: ``str``
 
         :param ex_tags: Optional tags to associate with this resource.
@@ -1097,13 +1093,10 @@ class AzureNodeDriver(NodeDriver):
         :param volume_obj: A volume object from an azure response.
         :type volume_obj: ``dict``
 
-        :param name: An optional name for the volume. If not provided
-            then either tag with a key "name" will be used. (optional)
+        :param name: An optional name for the volume.
         :type name: ``str``
 
         :param ex_resource_group: An optional resource group for the volume.
-            If not provided then either tag with a key "resource_group"
-            will be used. (optional)
         :type ex_resource_group: ``str``
 
         :rtype: :class:`StorageVolume`
@@ -1156,7 +1149,7 @@ class AzureNodeDriver(NodeDriver):
             extra=extra
         )
 
-    def _to_snapshot(self, snapshot_obj, name=None,  ex_resource_group=None):
+    def _to_snapshot(self, snapshot_obj, name=None, ex_resource_group=None):
         """
         Parse the JSON element and return a VolumeSnapshot object.
 
@@ -1167,8 +1160,6 @@ class AzureNodeDriver(NodeDriver):
         :type name: ``str``
 
         :param ex_resource_group: An optional resource group for the volume.
-            If not provided then either tag with a key "resource_group"
-            will be used.
         :type ex_resource_group: ``str``
 
         :rtype: :class:`VolumeSnapshot`

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute.json
index 7c4b5cd..f0bbae5 100644
--- 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute.json
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute.json
@@ -197,4 +197,4 @@
     }
   ],
   "registrationState": "Registered"
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_disks.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_disks.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_disks.json
new file mode 100644
index 0000000..849a5a8
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_disks.json
@@ -0,0 +1,65 @@
+{
+  "value": [
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "osType": "Linux",
+        "creationData": {
+          "createOption": "FromImage",
+          "imageReference": {
+            "id": 
"/Subscriptions/99999999-9999-9999-9999-999999999999/Providers/Microsoft.Compute/Locations/eastus/Publishers/OpenLogic/ArtifactTypes/VMImage/Offers/CentOS/Skus/7.3/Versions/latest"
+          }
+        },
+        "diskSizeGB": 31,
+        "timeCreated": "2017-03-09T10:12:37.0256203+00:00",
+        "ownerId": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/REVIZOR/providers/Microsoft.Compute/virtualMachines/test-vm-1",
+        "provisioningState": "Succeeded",
+        "diskState": "Attached"
+      },
+      "type": "Microsoft.Compute/disks",
+      "location": "eastus",
+      "tags": {},
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-disk-1",
+      "name": "test-disk-1"
+    },
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "osType": "Linux",
+        "creationData": {
+          "createOption": "FromImage",
+          "imageReference": {
+            "id": 
"/Subscriptions/99999999-9999-9999-9999-999999999999/Providers/Microsoft.Compute/Locations/eastus/Publishers/OpenLogic/ArtifactTypes/VMImage/Offers/CentOS/Skus/7.3/Versions/latest"
+          }
+        },
+        "diskSizeGB": 31,
+        "timeCreated": "2017-03-09T11:40:37.092158+00:00",
+        "provisioningState": "Updating",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/disks",
+      "location": "eastus",
+      "tags": {},
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-disk-2",
+      "name": "test-disk-2"
+    },
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "osType": "Linux",
+        "creationData": {
+          "createOption": "Empty"
+        },
+        "diskSizeGB": 10,
+        "timeCreated": "2017-03-09T10:08:42.6418313+00:00",
+        "provisioningState": "Succeeded",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/disks",
+      "location": "eastus",
+      "tags": {},
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/disks/test-disk-3",
+      "name": "test-disk-3"
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_snapshots.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_snapshots.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_snapshots.json
new file mode 100644
index 0000000..8fe42b2
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_snapshots.json
@@ -0,0 +1,75 @@
+{
+  "value": [
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "creationData": {
+          "createOption": "Copy",
+          "sourceUri": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-disk-1"
+        },
+        "diskSizeGB": 1,
+        "timeCreated": "2017-03-09T14:28:27.8655868+00:00",
+        "provisioningState": "Creating",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/snapshots",
+      "location": "eastus",
+      "tags": {
+        "test_snap": "test"
+      },
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
+      "name": "test-snap-1"
+    },
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "creationData": {
+          "createOption": "Copy",
+          "sourceUri": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-disk-2"
+        },
+        "diskSizeGB": 2,
+        "timeCreated": "2017-02-02T17:52:40.2213321+00:00",
+        "provisioningState": "Updating",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/snapshots",
+      "location": "eastus",
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-2",
+      "name": "test-snap-2"
+    },
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "creationData": {
+          "createOption": "Copy",
+          "sourceUri": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/disks/test-disk-3"
+        },
+        "diskSizeGB": 2,
+        "timeCreated": "2017-02-02T17:52:44.4557501+00:00",
+        "provisioningState": "Failed",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/snapshots",
+      "location": "eastus",
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/snapshots/test-snap-3",
+      "name": "test-snap-3"
+    },
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "creationData": {
+          "createOption": "Copy",
+          "sourceUri": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/disks/test-disk-4"
+        },
+        "diskSizeGB": 2,
+        "timeCreated": "2017-02-02T17:52:50.0027361+00:00",
+        "provisioningState": "Failed",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/snapshots",
+      "location": "eastus",
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/snapshots/test-snap-4",
+      "name": "test-snap-4"
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_virtualMachines.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_virtualMachines.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_virtualMachines.json
new file mode 100644
index 0000000..8973cf9
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_providers_Microsoft_Compute_virtualMachines.json
@@ -0,0 +1,52 @@
+{
+  "value": [
+    {
+      "properties": {
+        "vmId": "CCEEBF63-E92B-4A50-9949-6E44BFC61D3F",
+        "hardwareProfile": {
+          "vmSize": "Standard_A1"
+        },
+        "storageProfile": {
+          "imageReference": {
+            "publisher": "OpenLogic",
+            "offer": "CentOS",
+            "sku": "7.3",
+            "version": "latest"
+          },
+          "osDisk": {
+            "osType": "Linux",
+            "name": "test-node-disk-1",
+            "createOption": "FromImage",
+            "caching": "ReadWrite",
+            "managedDisk": {
+              "storageAccountType": "Standard_LRS",
+              "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-node-disk-1"
+            }
+          },
+          "dataDisks": []
+        },
+        "osProfile": {
+          "computerName": "test-node-1",
+          "adminUsername": "user",
+          "linuxConfiguration": {
+            "disablePasswordAuthentication": false
+          },
+          "secrets": []
+        },
+        "networkProfile": {
+          "networkInterfaces": [
+            {
+              "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/networkInterfaces/test-node-1-nic"
+            }
+          ]
+        },
+        "provisioningState": "Running"
+      },
+      "type": "Microsoft.Compute/virtualMachines",
+      "location": "eastus",
+      "tags": {},
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/virtualMachines/test-node-1",
+      "name": "test-node-1"
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_disks_test_disk_1.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_disks_test_disk_1.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_disks_test_disk_1.json
new file mode 100644
index 0000000..584b72e
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_disks_test_disk_1.json
@@ -0,0 +1,22 @@
+{
+  "properties": {
+    "accountType": "Standard_LRS",
+    "osType": "Linux",
+    "creationData": {
+      "createOption": "FromImage",
+      "imageReference": {
+        "id": 
"/Subscriptions/99999999-9999-9999-9999-999999999999/Providers/Microsoft.Compute/Locations/eastus/Publishers/OpenLogic/ArtifactTypes/VMImage/Offers/CentOS/Skus/7.3/Versions/latest"
+      }
+    },
+    "diskSizeGB": 31,
+    "timeCreated": "2017-03-09T10:12:37.0256203+00:00",
+    "ownerId": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/REVIZOR/providers/Microsoft.Compute/virtualMachines/test-vm-1",
+    "provisioningState": "Succeeded",
+    "diskState": "Attached"
+  },
+  "type": "Microsoft.Compute/disks",
+  "location": "eastus",
+  "tags": {},
+  "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-disk-1",
+  "name": "test-disk-1"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_snapshots_test_snap_1.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_snapshots_test_snap_1.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_snapshots_test_snap_1.json
new file mode 100644
index 0000000..f83c70d
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_snapshots_test_snap_1.json
@@ -0,0 +1,20 @@
+{
+  "properties": {
+    "accountType": "Standard_LRS",
+    "creationData": {
+      "createOption": "Copy",
+      "sourceUri": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-disk-1"
+    },
+    "diskSizeGB": 1,
+    "timeCreated": "2017-03-09T14:28:27.8655868+00:00",
+    "provisioningState": "Creating",
+    "diskState": "Unattached"
+  },
+  "type": "Microsoft.Compute/snapshots",
+  "location": "eastus",
+  "tags": {
+    "test_snap": "test"
+  },
+  "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/snapshots/test-snap-1",
+  "name": "test-snap-1"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1.json
new file mode 100644
index 0000000..c45d32f
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1.json
@@ -0,0 +1,48 @@
+{
+  "properties": {
+    "vmId": "e717ae77-db36-4225-b12a-68506fe5fc8f",
+    "hardwareProfile": {
+      "vmSize": "Standard_A1"
+    },
+    "storageProfile": {
+      "imageReference": {
+        "publisher": "OpenLogic",
+        "offer": "CentOS",
+        "sku": "7.3",
+        "version": "latest"
+      },
+      "osDisk": {
+        "osType": "Linux",
+        "name": "test-node-disk-1",
+        "createOption": "FromImage",
+        "caching": "ReadWrite",
+        "managedDisk": {
+          "storageAccountType": "Standard_LRS",
+          "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/disks/test-node-disk-1"
+        }
+      },
+      "dataDisks": []
+    },
+    "osProfile": {
+      "computerName": "test-node-1",
+      "adminUsername": "user",
+      "linuxConfiguration": {
+        "disablePasswordAuthentication": false
+      },
+      "secrets": []
+    },
+    "networkProfile": {
+      "networkInterfaces": [
+        {
+          "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/networkInterfaces/test-node-1-nic"
+        }
+      ]
+    },
+    "provisioningState": "Running"
+  },
+  "type": "Microsoft.Compute/virtualMachines",
+  "location": "eastus",
+  "tags": {},
+  "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/virtualMachines/test-node-1",
+  "name": "test-node-1"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1_InstanceView.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1_InstanceView.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1_InstanceView.json
new file mode 100644
index 0000000..0ac000f
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Compute_virtualMachines_test_node_1_InstanceView.json
@@ -0,0 +1,27 @@
+{
+  "vmAgent": {
+    "vmAgentVersion": "2.2.5",
+    "statuses": [
+      {
+        "code": "ProvisioningState/succeeded",
+        "level": "Info",
+        "displayStatus": "Ready",
+        "message": "Guest Agent is running",
+        "time": "2017-03-09T15:11:03+00:00"
+      }
+    ],
+    "extensionHandlers": []
+  },
+  "statuses": [
+    {
+      "code": "ProvisioningState/updating",
+      "level": "Info",
+      "displayStatus": "Updating"
+    },
+    {
+      "code": "PowerState/running",
+      "level": "Info",
+      "displayStatus": "VM running"
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Network_networkInterfaces_test_node_1_nic.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Network_networkInterfaces_test_node_1_nic.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Network_networkInterfaces_test_node_1_nic.json
new file mode 100644
index 0000000..c9cfb05
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_000000_providers_Microsoft_Network_networkInterfaces_test_node_1_nic.json
@@ -0,0 +1,38 @@
+{
+  "name": "test-node-1-nic",
+  "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/networkInterfaces/test-node-1-nic",
+  "etag": "W/\"5E19562E-8E84-493D-A29E-A84F5AC21D76\"",
+  "location": "eastus",
+  "tags": {},
+  "properties": {
+    "provisioningState": "Succeeded",
+    "resourceGuid": "AD512C3D-9A7B-4012-8C5D-227A9EA5E6F4",
+    "ipConfigurations": [
+      {
+        "name": "myip1",
+        "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/networkInterfaces/test-node-1-nic/ipConfigurations/myip1",
+        "etag": "W/\"5E19562E-8E84-493D-A29E-A84F5AC21D76\"",
+        "properties": {
+          "provisioningState": "Succeeded",
+          "privateIPAddress": "10.0.0.1",
+          "privateIPAllocationMethod": "Dynamic",
+          "subnet": {
+            "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/virtualNetworks/000000/subnets/000000"
+          },
+          "primary": true
+        }
+      }
+    ],
+    "dnsSettings": {
+      "dnsServers": [],
+      "appliedDnsServers": []
+    },
+    "macAddress": "11-11-11-11-11-11",
+    "enableIPForwarding": false,
+    "primary": true,
+    "virtualMachine": {
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/virtualMachines/test-node-1"
+    }
+  },
+  "type": "Microsoft.Network/networkInterfaces"
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_disks.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_disks.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_disks.json
new file mode 100644
index 0000000..bd2de1f
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_disks.json
@@ -0,0 +1,22 @@
+{
+  "value": [
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "osType": "Linux",
+        "creationData": {
+          "createOption": "Empty"
+        },
+        "diskSizeGB": 10,
+        "timeCreated": "2017-03-09T10:08:42.6418313+00:00",
+        "provisioningState": "Succeeded",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/disks",
+      "location": "eastus",
+      "tags": {},
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/disks/test-disk-3",
+      "name": "test-disk-3"
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_snapshots.json
----------------------------------------------------------------------
diff --git 
a/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_snapshots.json
 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_snapshots.json
new file mode 100644
index 0000000..b6add16
--- /dev/null
+++ 
b/libcloud/test/compute/fixtures/azure_arm/_subscriptions_99999999_9999_9999_9999_999999999999_resourceGroups_111111_providers_Microsoft_Compute_snapshots.json
@@ -0,0 +1,38 @@
+{
+  "value": [
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "creationData": {
+          "createOption": "Copy",
+          "sourceUri": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/disks/test-disk-3"
+        },
+        "diskSizeGB": 2,
+        "timeCreated": "2017-02-02T17:52:44.4557501+00:00",
+        "provisioningState": "Failed",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/snapshots",
+      "location": "eastus",
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/snapshots/test-snap-3",
+      "name": "test-snap-3"
+    },
+    {
+      "properties": {
+        "accountType": "Standard_LRS",
+        "creationData": {
+          "createOption": "Copy",
+          "sourceUri": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/disks/test-disk-4"
+        },
+        "diskSizeGB": 2,
+        "timeCreated": "2017-02-02T17:52:50.0027361+00:00",
+        "provisioningState": "Failed",
+        "diskState": "Unattached"
+      },
+      "type": "Microsoft.Compute/snapshots",
+      "location": "eastus",
+      "id": 
"/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/111111/providers/Microsoft.Compute/snapshots/test-snap-4",
+      "name": "test-snap-4"
+    }
+  ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/libcloud/blob/4ab938a1/libcloud/test/compute/test_azure_arm.py
----------------------------------------------------------------------
diff --git a/libcloud/test/compute/test_azure_arm.py 
b/libcloud/test/compute/test_azure_arm.py
index c0317c6..38fd484 100644
--- a/libcloud/test/compute/test_azure_arm.py
+++ b/libcloud/test/compute/test_azure_arm.py
@@ -12,13 +12,22 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.import libcloud
+import json
+import sys
+import functools
+from datetime import datetime
 
-from libcloud.test import LibcloudTestCase
-from libcloud.test import MockHttp
+from libcloud.compute.base import (NodeLocation, NodeSize, VolumeSnapshot,
+                                   StorageVolume)
+from libcloud.compute.drivers.azure_arm import AzureImage, NodeAuthPassword
+from libcloud.compute.providers import get_driver
+from libcloud.compute.types import (NodeState, Provider, StorageVolumeState,
+                                    VolumeSnapshotState)
+from libcloud.test import LibcloudTestCase, MockHttp
+from libcloud.test import unittest
 from libcloud.test.file_fixtures import ComputeFileFixtures
+from libcloud.utils.iso8601 import UTC
 from libcloud.utils.py3 import httplib
-from libcloud.compute.types import Provider
-from libcloud.compute.providers import get_driver
 
 
 class AzureNodeDriverTests(LibcloudTestCase):
@@ -50,7 +59,8 @@ class AzureNodeDriverTests(LibcloudTestCase):
                           "Japan West"])
 
     def test_sizes_returned_successfully(self):
-        sizes = 
self.driver.list_sizes(location=self.driver.list_locations()[0])
+        location = self.driver.list_locations()[0]
+        sizes = self.driver.list_sizes(location=location)
         self.assertEqual([l.name for l in sizes],
                          ["Standard_A0",
                           "Standard_A1",
@@ -65,14 +75,326 @@ class AzureNodeDriverTests(LibcloudTestCase):
                               'OfferTerms',
                               'Meters']))
 
+    def test_create_node(self):
+        location = NodeLocation('any_location', '', '', self.driver)
+        size = NodeSize('any_size', '', 0, 0, 0, 0, driver=self.driver)
+        image = AzureImage('1', '1', 'ubuntu', 'pub', location.id, self.driver)
+        auth = NodeAuthPassword('any_password')
+
+        node = self.driver.create_node(
+            'test-node-1',
+            size,
+            image,
+            auth,
+            location=location,
+            ex_resource_group='000000',
+            ex_storage_account='000000',
+            ex_user_name='any_user',
+            ex_network='000000',
+            ex_subnet='000000',
+            ex_use_managed_disks=True
+        )
+        hardware_profile = node.extra['properties']['hardwareProfile']
+        os_profile = node.extra['properties']['osProfile']
+        storage_profile = node.extra['properties']['storageProfile']
+
+        self.assertEqual(node.name, 'test-node-1')
+        self.assertEqual(node.state, NodeState.UPDATING)
+        self.assertEqual(node.private_ips, ['10.0.0.1'])
+        self.assertEqual(node.public_ips, [])
+        self.assertEqual(node.extra['location'], location.id)
+        self.assertEqual(hardware_profile['vmSize'], size.id)
+        self.assertEqual(os_profile['adminUsername'], 'any_user')
+        self.assertEqual(os_profile['adminPassword'], 'any_password')
+        self.assertTrue('managedDisk' in storage_profile['osDisk'])
+        self.assertTrue(storage_profile['imageReference'], {
+            'publisher': image.publisher,
+            'offer': image.offer,
+            'sku': image.sku,
+            'version': image.version
+        })
+
+    def test_list_nodes(self):
+        nodes = self.driver.list_nodes()
+
+        self.assertEqual(len(nodes), 1)
+
+        self.assertEqual(nodes[0].name, 'test-node-1')
+        self.assertEqual(nodes[0].state, NodeState.UPDATING)
+        self.assertEqual(nodes[0].private_ips, ['10.0.0.1'])
+        self.assertEqual(nodes[0].public_ips, [])
+
+    def test_create_volume(self):
+        location = self.driver.list_locations()[-1]
+        volume = self.driver.create_volume(
+            2, 'test-disk-1', location,
+            ex_resource_group='000000',
+            ex_tags={'description': 'MyVolume'}
+        )
+
+        self.assertEqual(volume.size, 2)
+        self.assertEqual(volume.name, 'test-disk-1')
+        self.assertEqual(volume.extra['name'], 'test-disk-1')
+        self.assertEqual(volume.extra['tags'], {'description': 'MyVolume'})
+        self.assertEqual(volume.extra['location'], location.id)
+        self.assertEqual(
+            volume.extra['properties']['creationData']['createOption'],
+            'Empty')
+        self.assertEqual(
+            volume.extra['properties']['provisioningState'],
+            'Succeeded')
+        self.assertEqual(
+            volume.extra['properties']['diskState'],
+            'Attached')
+        self.assertEqual(volume.state, StorageVolumeState.INUSE)
+
+    def test_create_volume__with_snapshot(self):
+        location = self.driver.list_locations()[0]
+        snap_id = (
+            '/subscriptions/99999999-9999-9999-9999-999999999999'
+            '/resourceGroups/000000/providers/Microsoft.Compute'
+            '/snapshots/test-snap-1'
+        )
+        snapshot = VolumeSnapshot(id=snap_id, size=2, driver=self.driver)
+
+        volume = self.driver.create_volume(
+            2, 'test-disk-1', location,
+            snapshot=snapshot,
+            ex_resource_group='000000',
+            ex_tags={'description': 'MyVolume'}
+        )
+
+        self.assertEqual(
+            volume.extra['properties']['creationData']['createOption'],
+            'Copy')
+        self.assertEqual(
+            volume.extra['properties']['creationData']['sourceUri'],
+            snap_id)
+
+    def test_create_volume__required_kw(self):
+        location = self.driver.list_locations()[0]
+        fn = functools.partial(self.driver.create_volume, 2, 'test-disk-1')
+
+        self.assertRaises(ValueError, fn)
+        self.assertRaises(ValueError, fn, location=location)
+        self.assertRaises(ValueError, fn, ex_resource_group='000000')
+
+        ret_value = fn(ex_resource_group='000000', location=location)
+        self.assertTrue(isinstance(ret_value, StorageVolume))
+
+    def test_list_volumes(self):
+        volumes = self.driver.list_volumes()
+
+        self.assertEqual(len(volumes), 3)
+
+        self.assertEqual(volumes[0].name, 'test-disk-1')
+        self.assertEqual(volumes[0].size, 31)
+        self.assertEqual(
+            volumes[0].extra['properties']['provisioningState'],
+            'Succeeded')
+        self.assertEqual(
+            volumes[0].extra['properties']['diskState'],
+            'Attached')
+        self.assertEqual(volumes[0].state, StorageVolumeState.INUSE)
+
+        self.assertEqual(volumes[1].name, 'test-disk-2')
+        self.assertEqual(volumes[1].size, 31)
+        self.assertEqual(
+            volumes[1].extra['properties']['provisioningState'],
+            'Updating')
+        self.assertEqual(
+            volumes[1].extra['properties']['diskState'],
+            'Unattached')
+        self.assertEqual(volumes[1].state, StorageVolumeState.UPDATING)
+
+        self.assertEqual(volumes[2].name, 'test-disk-3')
+        self.assertEqual(volumes[2].size, 10)
+        self.assertEqual(
+            volumes[2].extra['properties']['provisioningState'],
+            'Succeeded')
+        self.assertEqual(
+            volumes[2].extra['properties']['diskState'],
+            'Unattached')
+        self.assertEqual(StorageVolumeState.AVAILABLE, volumes[2].state)
+
+    def test_list_volumes__with_resource_group(self):
+        volumes = self.driver.list_volumes(ex_resource_group='111111')
+
+        self.assertEqual(len(volumes), 1)
+
+        self.assertEqual(volumes[0].name, 'test-disk-3')
+        self.assertEqual(volumes[0].size, 10)
+        self.assertEqual(
+            volumes[0].extra['properties']['provisioningState'],
+            'Succeeded')
+        self.assertEqual(
+            volumes[0].extra['properties']['diskState'],
+            'Unattached')
+        self.assertEqual(volumes[0].state, StorageVolumeState.AVAILABLE)
+
+    def test_attach_volume(self):
+        volumes = self.driver.list_volumes()
+        node = self.driver.list_nodes()[0]
+
+        self.driver.attach_volume(node, volumes[0], ex_lun=0)
+        self.driver.attach_volume(node, volumes[1], ex_lun=15)
+        self.driver.attach_volume(node, volumes[2])
+
+        data_disks = node.extra['properties']['storageProfile']['dataDisks']
+        luns = [disk['lun'] for disk in data_disks]
+        self.assertTrue(len(data_disks), len(volumes))
+        self.assertTrue(set(luns), set([0, 1, 15]))
+
+    def test_detach_volume(self):
+        volumes = self.driver.list_volumes()
+        node = self.driver.list_nodes()[0]
+
+        for volume in volumes:
+            self.driver.attach_volume(node, volume)
+
+        data_disks = node.extra['properties']['storageProfile']['dataDisks']
+        self.assertEqual(len(data_disks), len(volumes))
+
+        for volume in volumes:
+            self.driver.detach_volume(volume, ex_node=node)
+
+        data_disks = node.extra['properties']['storageProfile']['dataDisks']
+        self.assertEqual(len(data_disks), 0)
+
+    def test_destroy_volume(self):
+        volume = self.driver.list_volumes()[0]
+        ret_value = self.driver.destroy_volume(volume)
+        self.assertTrue(ret_value)
+
+    def test_create_volume_snapshot(self):
+        location = self.driver.list_locations()[-1]
+        volume = self.driver.list_volumes()[0]
+
+        snap = self.driver.create_volume_snapshot(
+            volume, 'test-snap-1',
+            location=location,
+            ex_resource_group='000000'
+        )
+        self.assertEqual(snap.name, 'test-snap-1')
+        self.assertEqual(snap.extra['name'], 'test-snap-1')
+        self.assertEqual(snap.size, 1)
+        self.assertEqual(snap.extra['source_id'], volume.id)
+        self.assertEqual(snap.state, VolumeSnapshotState.CREATING)
+        self.assertEqual(snap.extra['location'], location.id)
+        self.assertEqual(
+            snap.extra['properties']['provisioningState'],
+            'Creating')
+        self.assertEqual(
+            snap.extra['properties']['diskState'],
+            'Unattached')
+        # 2017-03-09T14:28:27.8655868+00:00"
+        self.assertEqual(
+            datetime(2017, 3, 9, 14, 28, 27, 865586, tzinfo=UTC),
+            snap.created)
+
+    def test_create_volume_snapshot__required_kw(self):
+        location = self.driver.list_locations()[0]
+        volume = self.driver.list_volumes()[0]
+
+        fn = functools.partial(self.driver.create_volume_snapshot, volume)
+
+        self.assertRaises(ValueError, fn)
+        self.assertRaises(ValueError, fn, name='test-snap-1')
+        self.assertRaises(ValueError, fn, location=location)
+        self.assertRaises(ValueError, fn, ex_resource_group='000000')
+
+        ret_value = fn(
+            name='test-snap-1',
+            ex_resource_group='000000',
+            location=location
+        )
+        self.assertTrue(isinstance(ret_value, VolumeSnapshot))
+
+    def test_list_snapshots(self):
+        snaps = self.driver.list_snapshots()
+        self.assertEqual(len(snaps), 4)
+
+        self.assertEqual(snaps[0].name, 'test-snap-1')
+        self.assertEqual(snaps[0].extra['name'], 'test-snap-1')
+        self.assertEqual(snaps[0].state, VolumeSnapshotState.CREATING)
+        self.assertEqual(
+            snaps[0].extra['source_id'],
+            '/subscriptions/99999999-9999-9999-9999-999999999999'
+            '/resourceGroups/000000/providers/Microsoft.Compute'
+            '/disks/test-disk-1')
+        self.assertEqual(snaps[0].size, 1)
+        self.assertEqual(snaps[0].extra['tags']['test_snap'], 'test')
+        self.assertTrue(isinstance(snaps[3].created, datetime))
+
+        self.assertEqual(snaps[3].name, 'test-snap-4')
+        self.assertEqual(snaps[3].extra['name'], 'test-snap-4')
+        self.assertEqual(snaps[3].state, VolumeSnapshotState.ERROR)
+        self.assertEqual(
+            snaps[3].extra['source_id'],
+            '/subscriptions/99999999-9999-9999-9999-999999999999'
+            '/resourceGroups/111111/providers/Microsoft.Compute'
+            '/disks/test-disk-4')
+        self.assertEqual(snaps[3].size, 2)
+        self.assertTrue(isinstance(snaps[3].created, datetime))
+
+    def test_list_snapshots_in_resource_group(self):
+
+        snaps = self.driver.list_snapshots(ex_resource_group='111111')
+        self.assertEqual(len(snaps), 2)
+
+        self.assertEqual(snaps[0].name, 'test-snap-3')
+        self.assertEqual(snaps[0].extra['name'], 'test-snap-3')
+        self.assertEqual(snaps[0].state, VolumeSnapshotState.ERROR)
+        self.assertEqual(
+            snaps[0].extra['source_id'],
+            '/subscriptions/99999999-9999-9999-9999-999999999999'
+            '/resourceGroups/111111/providers/Microsoft.Compute'
+            '/disks/test-disk-3')
+        self.assertEqual(snaps[0].size, 2)
+        self.assertTrue(isinstance(snaps[0].created, datetime))
+
+    def test_list_volume_snapshots(self):
+        volume = self.driver.list_volumes()[0]
+        self.assertTrue(volume.name == 'test-disk-1')
+
+        snapshots = self.driver.list_volume_snapshots(volume)
+        self.assertEqual(len(snapshots), 1)
+        self.assertEqual(snapshots[0].name, 'test-snap-1')
+        self.assertEqual(volume.id, snapshots[0].extra['source_id'])
+
+    def test_destroy_volume_snapshot(self):
+        snapshot = self.driver.list_snapshots()[0]
+        res_value = snapshot.destroy()
+        self.assertTrue(res_value)
+
 
 class AzureMockHttp(MockHttp):
     fixtures = ComputeFileFixtures('azure_arm')
 
+    def _update(self, fixture, body):
+        for key, value in body.items():
+            if isinstance(value, dict):
+                fixture[key] = self._update(fixture.get(key, {}), value)
+            else:
+                fixture[key] = body[key]
+        return fixture
+
     def __getattr__(self, n):
-        def m(method, url, body, headers):
-            return (httplib.OK,
-                    self.fixtures.load(n + ".json"),
-                    headers,
+        def fn(method, url, body, headers):
+            fixture = self.fixtures.load(n + ".json")
+
+            if method in ('POST', 'PUT'):
+                try:
+                    body = json.loads(body)
+                    fixture_tmp = json.loads(fixture)
+                    fixture_tmp = self._update(fixture_tmp, body)
+                    fixture = json.dumps(fixture_tmp)
+                except ValueError:
+                    pass
+            return (httplib.OK, fixture, headers,
                     httplib.responses[httplib.OK])
-        return m
+        return fn
+
+
+if __name__ == '__main__':
+    sys.exit(unittest.main())

Reply via email to