Skip to content

Commit

Permalink
Merge branch 'fix-azure-list-nodes' of https://github.com/jan-mue/lib…
Browse files Browse the repository at this point in the history
…cloud into jan-mue-fix-azure-list-nodes
  • Loading branch information
Kami committed Jul 31, 2023
2 parents aa9a947 + b8e836c commit c906009
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 10 deletions.
18 changes: 12 additions & 6 deletions libcloud/compute/drivers/azure_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import binascii

from libcloud.utils import iso8601
from libcloud.utils.py3 import basestring
from libcloud.utils.py3 import basestring, urlparse, parse_qs
from libcloud.common.types import LibcloudError
from libcloud.compute.base import (
Node,
Expand Down Expand Up @@ -468,11 +468,17 @@ def list_nodes(self, ex_resource_group=None, ex_fetch_nic=True, ex_fetch_power_s
action = "/subscriptions/%s/providers/Microsoft.Compute/" "virtualMachines" % (
self.subscription_id
)
r = self.connection.request(action, params={"api-version": VM_API_VERSION})
return [
self._to_node(n, fetch_nic=ex_fetch_nic, fetch_power_state=ex_fetch_power_state)
for n in r.object["value"]
]
params = {"api-version": VM_API_VERSION}
nodes = []
while True:
r = self.connection.request(action, params=params)
nodes.extend(self._to_node(n, fetch_nic=ex_fetch_nic, fetch_power_state=ex_fetch_power_state) for n in r.object["value"])
if not r.object.get("nextLink"):
break
parsed_next_link = urlparse.urlparse(r.object["nextLink"])
params.update({k: v[0] for k, v in parse_qs(parsed_next_link.query).items()})
action = parsed_next_link.path
return nodes

def create_node(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,6 @@
"id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Compute/virtualMachines/test-node-1",
"name": "test-node-1"
}
]
],
"nextLink": "https://management.azure.com:443/subscriptions/99999999-9999-9999-9999-999999999999/providers/Microsoft.Compute/virtualMachines?api-version=2021-11-01&$skiptoken=1!/Subscriptions/99999999-9999-9999-9999-999999999999/ResourceGroups/000000/VMs/DDFEBF64-E92B-4A50-9949-6E44BFC61D4G"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"value": [
{
"properties": {
"vmId": "DDFEBF64-E92B-4A50-9949-6E44BFC61D4G",
"additionalCapabilities": {
"ultraSSDEnabled": "False",
"hibernationEnabled": "False"
},
"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-2"
}
},
"dataDisks": []
},
"osProfile": {
"computerName": "test-node-2",
"adminUsername": "user",
"linuxConfiguration": {
"disablePasswordAuthentication": false
},
"secrets": []
},
"networkProfile": {
"networkInterfaces": [
{
"id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/networkInterfaces/test-node-2-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-2",
"name": "test-node-2"
}
]
}
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "test-node-2-nic",
"id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/networkInterfaces/test-node-2-nic",
"etag": "W/\"5E19562E-8E84-493D-A29E-A84F5AC21D77\"",
"location": "eastus",
"tags": {},
"properties": {
"provisioningState": "Succeeded",
"resourceGuid": "AD512C3D-9A7B-4012-8C5D-227A9EA5E6F5",
"ipConfigurations": [
{
"name": "myip1",
"id": "/subscriptions/99999999-9999-9999-9999-999999999999/resourceGroups/000000/providers/Microsoft.Network/networkInterfaces/test-node-2-nic/ipConfigurations/myip2",
"etag": "W/\"5E19562E-8E84-493D-A29E-A84F5AC21D77\"",
"properties": {
"provisioningState": "Succeeded",
"privateIPAddress": "10.0.0.2",
"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-2"
}
},
"type": "Microsoft.Network/networkInterfaces"
}
21 changes: 18 additions & 3 deletions libcloud/test/compute/test_azure_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from unittest import mock

from libcloud.test import MockHttp, LibcloudTestCase, unittest
from libcloud.utils.py3 import httplib
from libcloud.utils.py3 import httplib, urlparse, parse_qs, urlunquote
from libcloud.common.types import LibcloudError
from libcloud.compute.base import NodeSize, NodeLocation, StorageVolume, VolumeSnapshot
from libcloud.compute.types import Provider, NodeState, StorageVolumeState, VolumeSnapshotState
Expand Down Expand Up @@ -444,13 +444,18 @@ def error(e, **kwargs):
def test_list_nodes(self, fps_mock):
nodes = self.driver.list_nodes()

self.assertEqual(len(nodes), 1)
self.assertEqual(len(nodes), 2)

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, [])

self.assertEqual(nodes[1].name, "test-node-2")
self.assertEqual(nodes[1].state, NodeState.UPDATING)
self.assertEqual(nodes[1].private_ips, ["10.0.0.2"])
self.assertEqual(nodes[1].public_ips, [])

fps_mock.assert_called()

@mock.patch(
Expand All @@ -460,13 +465,18 @@ def test_list_nodes(self, fps_mock):
def test_list_nodes__no_fetch_power_state(self, fps_mock):
nodes = self.driver.list_nodes(ex_fetch_power_state=False)

self.assertEqual(len(nodes), 1)
self.assertEqual(len(nodes), 2)

self.assertEqual(nodes[0].name, "test-node-1")
self.assertNotEqual(nodes[0].state, NodeState.UPDATING)
self.assertEqual(nodes[0].private_ips, ["10.0.0.1"])
self.assertEqual(nodes[0].public_ips, [])

self.assertEqual(nodes[1].name, "test-node-2")
self.assertNotEqual(nodes[1].state, NodeState.UPDATING)
self.assertEqual(nodes[1].private_ips, ["10.0.0.2"])
self.assertEqual(nodes[1].public_ips, [])

fps_mock.assert_not_called()

def test_create_volume(self):
Expand Down Expand Up @@ -813,6 +823,11 @@ def fn(method, url, body, headers):
"99999999_9999_9999_9999_999999999999",
AzureNodeDriverTests.SUBSCRIPTION_ID,
)
unquoted_url = urlunquote(url)
if "$skiptoken=" in unquoted_url:
parsed_url = urlparse.urlparse(unquoted_url)
params = parse_qs(parsed_url.query)
file_name += "_" + params["$skiptoken"][0].split("!")[0]
fixture = self.fixtures.load(file_name + ".json")

if method in ("POST", "PUT"):
Expand Down

0 comments on commit c906009

Please sign in to comment.