Skip to content

Commit

Permalink
Add debug logging to note when a datastore is excluded because it doe…
Browse files Browse the repository at this point in the history
…s not have sdrs enabled

Signed-off-by: Joseph Palermo <[email protected]>
  • Loading branch information
xtreme-nitin-ravindran authored and jpalermo committed Aug 14, 2024
1 parent 41d414c commit 2347d70
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/vsphere_cpi/lib/cloud/vsphere/storage_picker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ def choose_global_datastore_pattern(datacenter, is_persistent)
logger.info("clusters: #{datastore_cluster_list}")

# pick all SDRS-enabled datastore clusters and include their datastores in the set to be used
datastores = datastore_cluster_list.select(&:drs_enabled?).map { |datastore_cluster| datastore_cluster.datastores }.flatten
clusters_with_drs = datastore_cluster_list.select(&:drs_enabled?)
clusters_without_drs = datastore_cluster_list - clusters_with_drs
logger.debug("Datastore Clusters excluded because they do not have DRS enabled: [#{clusters_without_drs.map(&:name).join(', ')}]") unless clusters_without_drs.empty?
datastores = clusters_with_drs.map { |datastore_cluster| datastore_cluster.datastores }.flatten
cluster_datastore_names = datastores.map(&:name)

if cluster_datastore_names.empty?
Expand All @@ -63,6 +66,8 @@ def choose_persistent_pattern(disk_pool)
datastore_names = disk_pool.datastore_names
unless disk_pool.datastore_clusters.empty?
sdrs_enabled_datastore_clusters = disk_pool.datastore_clusters.select(&:drs_enabled?)
clusters_without_drs = disk_pool.datastore_clusters - sdrs_enabled_datastore_clusters
logger.debug("Datastore Clusters excluded because they do not have DRS enabled: [#{clusters_without_drs.map(&:name).join(', ')}]") unless clusters_without_drs.empty?
# pick best sdrs enabled datastore cluster and include its datastores in the set to be used for persistent disk
if sdrs_enabled_datastore_clusters.any?
datastore_cluster = choose_best_from(sdrs_enabled_datastore_clusters)
Expand Down Expand Up @@ -118,6 +123,8 @@ def choose_ephemeral_pattern(global_config, vm_type)
datastore_names = vm_type.datastore_names
unless vm_type.datastore_clusters.empty?
sdrs_enabled_datastore_clusters = vm_type.datastore_clusters.select(&:drs_enabled?)
clusters_without_drs = vm_type.datastore_clusters - sdrs_enabled_datastore_clusters
logger.debug("Datastore Clusters excluded because they do not have DRS enabled: [#{clusters_without_drs.map(&:name).join(', ')}]") unless clusters_without_drs.empty?
datastores = sdrs_enabled_datastore_clusters.map { |datastore_cluster| datastore_cluster.datastores }.flatten
datastore_names.concat(datastores.map(&:name))
end
Expand All @@ -141,4 +148,4 @@ def choose_ephemeral_pattern(global_config, vm_type)
return choose_global_ephemeral_pattern(vm_type.datacenter), nil
end
end
end
end
24 changes: 20 additions & 4 deletions src/vsphere_cpi/spec/unit/cloud/vsphere/storage_picker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ module VSphereCloud
it 'includes a pattern constructed from datastores and datastores from best sdrs enabled datastore cluster' do
expect(subject).to eq('^(ds\-1|ds\-2|sp\-2\-ds\-1)$')
end

it 'logs the datastores excluded because they do not have drs' do
expect(logger).to receive(:debug).with("Datastore Clusters excluded because they do not have DRS enabled: [sp3]")
subject
end
end

context 'and no datastores' do
Expand Down Expand Up @@ -114,11 +119,17 @@ module VSphereCloud
expect(subject).to eq(global_persistent_pattern)
end

context 'with global persistent clusters defined' do
context 'with global persistent cluster pattern defined' do
let(:persistent_cluster_pattern) { 'sp.' }
it 'includes a pattern constructed from datastores from all SDRS-enabled global persistent datastore cluster and the global persistent pattern' do
expect(subject).to eq('^(sp\-1\-ds\-1|sp\-2\-ds\-1)$|global-persistent-ds')
end

it 'logs the datastores excluded because they do not have drs' do
expect(logger).to receive(:debug).with("Datastore Clusters excluded because they do not have DRS enabled: [sp3]")
subject
end

context 'and no global persistent pattern' do
let(:global_persistent_pattern) { nil }
it 'returns a pattern with only the cluster datastores' do
Expand Down Expand Up @@ -197,20 +208,25 @@ module VSphereCloud
it 'includes a pattern constructed from datastores and datastores from all sdrs enabled datastore cluster' do
expect(vm_type).to receive(:storage_policy_name).once
expect(vm_type).to receive(:datastore_names).once
expect(vm_type).to receive(:datastore_clusters).twice
expect(vm_type).to receive(:datastore_clusters).thrice
expect(vm_type).to_not receive(:datacenter)
expect(global_config).to_not receive(:vm_storage_policy_name)
expect(vm_type).to_not receive(:storage_policy_datastores)
expect(subject).to eq(['^(ds\-1|ds\-2|sp\-1\-ds\-1|sp\-2\-ds\-1)$', nil])
end

it 'logs the datastores excluded because they do not have drs' do
expect(logger).to receive(:debug).with("Datastore Clusters excluded because they do not have DRS enabled: [sp3]")
subject
end
end

context 'and no datastores' do
let(:datastore_names) { [] }
it 'includes the datastores from all sdrs enabled datastore cluster' do
expect(vm_type).to receive(:storage_policy_name).once
expect(vm_type).to receive(:datastore_names).once
expect(vm_type).to receive(:datastore_clusters).twice
expect(vm_type).to receive(:datastore_clusters).thrice
expect(vm_type).to_not receive(:datacenter)
expect(global_config).to_not receive(:vm_storage_policy_name)
expect(vm_type).to_not receive(:storage_policy_datastores)
Expand All @@ -224,7 +240,7 @@ module VSphereCloud
it 'should be empty' do
expect(vm_type).to receive(:storage_policy_name).once
expect(vm_type).to receive(:datastore_names).once
expect(vm_type).to receive(:datastore_clusters).thrice
expect(vm_type).to receive(:datastore_clusters).exactly(4).times
expect(vm_type).to_not receive(:datacenter)
expect(global_config).to_not receive(:vm_storage_policy_name)
expect(vm_type).to_not receive(:storage_policy_datastores)
Expand Down

0 comments on commit 2347d70

Please sign in to comment.