Skip to content

Commit

Permalink
Use distinct Azure API version for compute/snapshots
Browse files Browse the repository at this point in the history
The compute version was changed as part of PR #688 and Azure
does not increment all APIs at the same time. So there is no API version
that works for both snapshots and the rest of compute.

We may need to break other API components out in the future.

Signed-off-by: Joseph Palermo <[email protected]>
Co-authored-by: Joseph Palermo <[email protected]>
  • Loading branch information
aramprice and jpalermo committed Jan 11, 2024
1 parent e47bb77 commit 7af4245
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 20 deletions.
14 changes: 8 additions & 6 deletions src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class AzureClient # rubocop:todo Metrics/ClassLength
].freeze

REST_API_PROVIDER_COMPUTE = 'Microsoft.Compute'
REST_API_PROVIDER_AND_TYPE_DISK = 'Microsoft.Compute/disks'
REST_API_VIRTUAL_MACHINES = 'virtualMachines'
REST_API_AVAILABILITY_SETS = 'availabilitySets'
REST_API_DISKS = 'disks'
Expand Down Expand Up @@ -2372,11 +2371,14 @@ def request_from_managed_identity_endpoint

def http_url(url, params = {})
unless params.key?('api-version')
resource_provider = nil
resource_provider = if url.include?(REST_API_PROVIDER_AND_TYPE_DISK)
AZURE_RESOURCE_PROVIDER_COMPUTE_DISK
elsif url.include?(REST_API_PROVIDER_COMPUTE)
AZURE_RESOURCE_PROVIDER_COMPUTE
resource_provider = if url.include?(REST_API_PROVIDER_COMPUTE)
if url.include?(REST_API_DISKS)
AZURE_RESOURCE_PROVIDER_COMPUTE_DISK
elsif url.include?(REST_API_SNAPSHOTS)
AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT
else
AZURE_RESOURCE_PROVIDER_COMPUTE
end
elsif url.include?(REST_API_PROVIDER_NETWORK)
AZURE_RESOURCE_PROVIDER_NETWORK
elsif url.include?(REST_API_PROVIDER_STORAGE)
Expand Down
2 changes: 2 additions & 0 deletions src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Bosh::AzureCloud
module Helpers
AZURE_RESOURCE_PROVIDER_COMPUTE = 'crp'
AZURE_RESOURCE_PROVIDER_COMPUTE_DISK = 'diskcrp'
AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT = 'snapshotcrp'
AZURE_RESOURCE_PROVIDER_NETWORK = 'nrp'
AZURE_RESOURCE_PROVIDER_STORAGE = 'srp'
AZURE_RESOURCE_PROVIDER_GROUP = 'rp'
Expand All @@ -18,6 +19,7 @@ module Helpers
API_VERSIONS = {
AZURE_RESOURCE_PROVIDER_COMPUTE => '2021-11-01',
AZURE_RESOURCE_PROVIDER_COMPUTE_DISK => '2023-04-02',
AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT => '2021-04-01',
AZURE_RESOURCE_PROVIDER_NETWORK => '2017-09-01',
AZURE_RESOURCE_PROVIDER_STORAGE => '2017-10-01',
AZURE_RESOURCE_PROVIDER_GROUP => '2016-06-01',
Expand Down
21 changes: 11 additions & 10 deletions src/bosh_azure_cpi/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@
MOCK_REQUEST_ID = '47504c59-37af-42f3-a386-22d0c2c73175'

# Let us keep the least API versions here for unit tests.
AZURE_API_VERSION = '2015-06-15'
AZURE_STACK_API_VERSION = '2015-06-15'
AZURE_CHINA_API_VERSION = '2015-06-15'
AZURE_USGOV_API_VERSION = '2015-06-15'
AZURE_GERMAN_API_VERSION = '2015-06-15'
AZURE_RESOURCE_PROVIDER_COMPUTE = '2021-11-01'
AZURE_RESOURCE_PROVIDER_COMPUTE_DISK = '2023-04-02'
AZURE_RESOURCE_PROVIDER_GROUP = '2016-06-01'
AZURE_RESOURCE_PROVIDER_NETWORK = '2017-09-01'
AZURE_RESOURCE_PROVIDER_STORAGE = '2017-10-01'
AZURE_API_VERSION = '2015-06-15'
AZURE_STACK_API_VERSION = '2015-06-15'
AZURE_CHINA_API_VERSION = '2015-06-15'
AZURE_USGOV_API_VERSION = '2015-06-15'
AZURE_GERMAN_API_VERSION = '2015-06-15'
AZURE_RESOURCE_PROVIDER_COMPUTE = '2021-11-01'
AZURE_RESOURCE_PROVIDER_COMPUTE_DISK = '2023-04-02'
AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT = '2021-04-01'
AZURE_RESOURCE_PROVIDER_GROUP = '2016-06-01'
AZURE_RESOURCE_PROVIDER_NETWORK = '2017-09-01'
AZURE_RESOURCE_PROVIDER_STORAGE = '2017-10-01'

WINDOWS_VM_NAME_LENGTH = 15
AZURE_MAX_RETRY_COUNT = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
let(:subscription_id) { mock_azure_config.subscription_id }
let(:tenant_id) { mock_azure_config.tenant_id }
let(:api_version) { AZURE_API_VERSION }
let(:api_version_compute) { AZURE_RESOURCE_PROVIDER_COMPUTE }
let(:api_version_snapshot) { AZURE_RESOURCE_PROVIDER_COMPUTE_SNAPSHOT }
let(:api_version_disk) { AZURE_RESOURCE_PROVIDER_COMPUTE_DISK }
let(:resource_group) { 'fake-resource-group-name' }
let(:request_id) { 'fake-request-id' }
Expand All @@ -34,7 +34,7 @@
end

describe '#create_managed_snapshot' do
let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_compute}" }
let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_snapshot}" }
let(:disk_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/disks/#{disk_name}?api-version=#{api_version_disk}" }

let(:snapshot_params) do
Expand Down Expand Up @@ -115,7 +115,7 @@
end

describe '#delete_managed_snapshot' do
let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_compute}" }
let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_snapshot}" }

context 'when token is valid, delete operation is accepted and completed' do
it 'should delete the managed snapshot without error' do
Expand All @@ -141,7 +141,7 @@
end

describe '#get_managed_snapshot_by_name' do
let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_compute}" }
let(:snapshot_uri) { "https://management.azure.com/subscriptions/#{subscription_id}/resourceGroups/#{resource_group}/providers/Microsoft.Compute/snapshots/#{snapshot_name}?api-version=#{api_version_snapshot}" }

context 'when response body is null' do
it 'should return nil' do
Expand Down

0 comments on commit 7af4245

Please sign in to comment.