From 5ffcd54fe306d7278beb9772ea917f7f8fb51e60 Mon Sep 17 00:00:00 2001 From: Joseph Palermo Date: Sun, 4 Dec 2022 13:59:27 -0800 Subject: [PATCH] Remove config disk support Originally added in response to issue #472, which doesn't have a lot of details, but does mention Virtual Machine Scale Sets. This doesn't seem to be a fully implemented feature and there is no recent progress on making a real feature. The config disk code is current breaking due to new api changes introduce as part of PR #674 Rather than fix those failures, it makes more sense to remove an unused feature. --- src/bosh_azure_cpi/.rubocop_todo.yml | 1 - src/bosh_azure_cpi/lib/cloud/azure.rb | 1 - src/bosh_azure_cpi/lib/cloud/azure/cloud.rb | 3 +- .../cloud/azure/disk/config_disk_manager.rb | 109 ---------------- .../lib/cloud/azure/models/config.rb | 12 -- .../lib/cloud/azure/models/disk_id.rb | 2 +- .../lib/cloud/azure/restapi/azure_client.rb | 12 -- .../lib/cloud/azure/utils/bosh_agent_util.rb | 6 +- .../lib/cloud/azure/utils/helpers.rb | 1 - .../lib/cloud/azure/vms/vm_manager.rb | 18 +-- src/bosh_azure_cpi/spec/spec_helper.rb | 5 +- .../create_virtual_machine_spec.rb | 118 ------------------ .../unit/vm_manager/create/shared_stuff.rb | 13 -- .../vm_manager/create/use_config_disk_spec.rb | 93 -------------- 14 files changed, 8 insertions(+), 386 deletions(-) delete mode 100644 src/bosh_azure_cpi/lib/cloud/azure/disk/config_disk_manager.rb delete mode 100644 src/bosh_azure_cpi/spec/unit/vm_manager/create/use_config_disk_spec.rb diff --git a/src/bosh_azure_cpi/.rubocop_todo.yml b/src/bosh_azure_cpi/.rubocop_todo.yml index 1a513116c..784ed7d0d 100644 --- a/src/bosh_azure_cpi/.rubocop_todo.yml +++ b/src/bosh_azure_cpi/.rubocop_todo.yml @@ -451,7 +451,6 @@ Style/OpenStructUse: - 'spec/manual_tests/performance/upload_image.rb' - 'spec/manual_tests/resource_group_name/helpers.rb' - 'spec/unit/bosh_release/jobs/cpi/templates/cpi.json.erb_spec.rb' - - 'spec/unit/vm_manager/create/use_config_disk_spec.rb' # Offense count: 4 # Configuration parameters: AllowedMethods. diff --git a/src/bosh_azure_cpi/lib/cloud/azure.rb b/src/bosh_azure_cpi/lib/cloud/azure.rb index b78ce2aac..a34ee29bc 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure.rb @@ -84,7 +84,6 @@ module AzureCloud; end require 'cloud/azure/disk/vhd_utils' require 'cloud/azure/storage/blob_manager' require 'cloud/azure/disk/disk_manager' -require 'cloud/azure/disk/config_disk_manager' require 'cloud/azure/stemcell/stemcell_manager' require 'cloud/azure/meta_store/meta_store' require 'cloud/azure/meta_store/stemcell_meta' diff --git a/src/bosh_azure_cpi/lib/cloud/azure/cloud.rb b/src/bosh_azure_cpi/lib/cloud/azure/cloud.rb index 3380e9a5d..ef1a7ab4c 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/cloud.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/cloud.rb @@ -838,8 +838,7 @@ def _init_azure @disk_manager2 = Bosh::AzureCloud::DiskManager2.new(@azure_client) @stemcell_manager2 = Bosh::AzureCloud::StemcellManager2.new(@blob_manager, @meta_store, @storage_account_manager, @azure_client) @light_stemcell_manager = Bosh::AzureCloud::LightStemcellManager.new(@blob_manager, @storage_account_manager, @azure_client) - @config_disk_manager = Bosh::AzureCloud::ConfigDiskManager.new(@blob_manager, @disk_manager2, @storage_account_manager) - @vm_manager = Bosh::AzureCloud::VMManager.new(_azure_config, @registry.endpoint, @disk_manager, @disk_manager2, @azure_client, @storage_account_manager, @stemcell_manager, @stemcell_manager2, @light_stemcell_manager, @config_disk_manager) + @vm_manager = Bosh::AzureCloud::VMManager.new(_azure_config, @registry.endpoint, @disk_manager, @disk_manager2, @azure_client, @storage_account_manager, @stemcell_manager, @stemcell_manager2, @light_stemcell_manager) @instance_type_mapper = Bosh::AzureCloud::InstanceTypeMapper.new rescue Net::OpenTimeout => e cloud_error("Please make sure the CPI has proper network access to Azure. #{e.inspect}") # TODO: Will it throw the error when initializing the client and manager diff --git a/src/bosh_azure_cpi/lib/cloud/azure/disk/config_disk_manager.rb b/src/bosh_azure_cpi/lib/cloud/azure/disk/config_disk_manager.rb deleted file mode 100644 index 360bd8a11..000000000 --- a/src/bosh_azure_cpi/lib/cloud/azure/disk/config_disk_manager.rb +++ /dev/null @@ -1,109 +0,0 @@ -# frozen_string_literal: true - -module Bosh::AzureCloud - class ConfigDiskManager - include Helpers - - BOSH_CONFIG_DISK_LABEL = 'azure_cfg_dsk' - CONFIG_DISK_CONTAINER = 'azure-config-disks' - CONFIG_DISK_MOUNT_POINT = 'azure_config_disk_mount' - CONFIG_DISK_FILE_PATH_PREFIX = 'azure_config_disk_image' - CONFIGS_RELATIVE_PATH = 'configs' - CONFIG_DISK_SIZE = 24 # in MB, azure have a requirement for the min size. - MEGA_SIZE = 1024 * 1024 - def initialize(blob_manager, disk_manager2, storage_account_manager) - @blob_manager = blob_manager - @disk_manager2 = disk_manager2 - @storage_account_manager = storage_account_manager - @logger = Bosh::Clouds::Config.logger - end - - # Returns the config disk uri. - def prepare_config_disk(resource_group_name, vm_name, location, metadata_obj, user_data_obj) - _create_config_disk(resource_group_name, vm_name, location, metadata_obj, user_data_obj) - end - - private - - def _create_config_disk(resource_group_name, vm_name, location, meta_data_obj, user_data_obj) - mounted_dir = nil - config_disk_file_path = nil - disk_name = nil - page_blob_created = false - command_runner = CommandRunner.new - umounted = false - begin - config_disk_file = Tempfile.new(CONFIG_DISK_FILE_PATH_PREFIX) - config_disk_file.close - config_disk_file_path = config_disk_file.path - - mk_image_file_cmd = "dd if=/dev/zero of=#{config_disk_file_path} bs=#{MEGA_SIZE} count=#{CONFIG_DISK_SIZE}" - command_runner.run_command(mk_image_file_cmd) - - mkfs_cmd = "mkfs.ext4 -F #{config_disk_file_path} -L #{BOSH_CONFIG_DISK_LABEL}" - command_runner.run_command(mkfs_cmd) - - mounted_dir = Dir.mktmpdir("#{CONFIG_DISK_MOUNT_POINT}#{SecureRandom.uuid}") - - mount_cmd = "sudo -n mount -o loop #{config_disk_file_path} #{mounted_dir}" - command_runner.run_command(mount_cmd) - - user = Etc.getpwuid(Process.uid).name - chmod_cmd = "sudo -n chown #{user} #{mounted_dir}" - command_runner.run_command(chmod_cmd) - - mkdir_cmd = "mkdir -p #{mounted_dir}/#{CONFIGS_RELATIVE_PATH}" - command_runner.run_command(mkdir_cmd) - - meta_data_str = JSON.dump(meta_data_obj) - File.open("#{mounted_dir}/#{CONFIGS_RELATIVE_PATH}/MetaData", 'w') do |file| - file.write(meta_data_str) - end - - user_data_str = JSON.dump(user_data_obj) - File.open("#{mounted_dir}/#{CONFIGS_RELATIVE_PATH}/UserData", 'w') do |file| - file.write(user_data_str) - end - - unmount_cmd = "sudo -n umount #{mounted_dir}" - command_runner.run_command(unmount_cmd) - umounted = true - - disk_name = "#{MANAGED_CONFIG_DISK_PREFIX}-#{vm_name}.vhd" - @blob_manager.create_vhd_page_blob( - @storage_account_manager.default_storage_account_name, - CONFIG_DISK_CONTAINER, - config_disk_file_path, - disk_name, - {} - ) - page_blob_created = true - config_disk_file_uri = @blob_manager.get_blob_uri(@storage_account_manager.default_storage_account_name, CONFIG_DISK_CONTAINER, disk_name) - disk_id = DiskId.create('None', true, disk_name: disk_name, resource_group_name: resource_group_name) - - @disk_manager2.create_disk_from_blob(disk_id, config_disk_file_uri, location, STORAGE_ACCOUNT_TYPE_STANDARD_LRS) - - disk = @disk_manager2.get_data_disk(disk_id) - @logger.info("disk created: #{disk}") - # TODO: defer one task to clean up the config disk. - # we need to acquire the lock for the resources we are operating too. - disk - rescue StandardError => e - cloud_error("Failed to prepare the config disk, Error: #{e.inspect}\n#{e.backtrace.join("\n")}") - ensure - # clean up. - ignore_exception do - unless umounted - unmount_cmd = "sudo -n umount #{mounted_dir}" - command_runner.run_command(unmount_cmd) - end - end - ignore_exception { FileUtils.remove_dir(mounted_dir) unless mounted_dir.nil? } - ignore_exception { FileUtils.rm(config_disk_file_path) unless config_disk_file_path.nil? } - ignore_exception do - @blob_manager.delete_blob(@storage_account_manager.default_storage_account_name, CONFIG_DISK_CONTAINER, disk_name) if page_blob_created - end - end - end - end -end diff --git a/src/bosh_azure_cpi/lib/cloud/azure/models/config.rb b/src/bosh_azure_cpi/lib/cloud/azure/models/config.rb index 2a2c536a0..c3908e2e5 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/models/config.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/models/config.rb @@ -60,15 +60,6 @@ def initialize(azure_stack_config_hash) end end - # TODO: Refactoring: Move class to new file: ConfigDisk - class ConfigDisk - attr_reader :enabled - - def initialize(config_disk_config_hash) - @enabled = config_disk_config_hash['enabled'] - end - end - # TODO: Refactoring: Move class to new file: AzureConfig class AzureConfig include Helpers @@ -84,7 +75,6 @@ class AzureConfig attr_reader :pip_idle_timeout_in_minutes attr_reader :parallel_upload_thread_num attr_reader :ssh_user, :ssh_public_key - attr_reader :config_disk attr_reader :stemcell_api_version attr_reader :use_default_account_for_cleaning @@ -127,8 +117,6 @@ def initialize(azure_config_hash) @ssh_user = azure_config_hash['ssh_user'] @ssh_public_key = azure_config_hash['ssh_public_key'] - @config_disk = ConfigDisk.new(azure_config_hash.fetch('config_disk', 'enabled' => false)) - # Flag to skip looping all storage account in subscription @use_default_account_for_cleaning = false @use_default_account_for_cleaning = azure_config_hash['use_default_account_for_cleaning'] unless azure_config_hash['use_default_account_for_cleaning'].nil? diff --git a/src/bosh_azure_cpi/lib/cloud/azure/models/disk_id.rb b/src/bosh_azure_cpi/lib/cloud/azure/models/disk_id.rb index 8e0748643..e58e76639 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/models/disk_id.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/models/disk_id.rb @@ -57,7 +57,7 @@ def disk_name end def caching - invalid = !disk_name.start_with?(DATA_DISK_PREFIX, MANAGED_DATA_DISK_PREFIX, MANAGED_CONFIG_DISK_PREFIX) + invalid = !disk_name.start_with?(DATA_DISK_PREFIX, MANAGED_DATA_DISK_PREFIX) cloud_error('This function should only be called for data disks') if invalid return _parse_data_disk_caching_plain(@plain_id) unless @plain_id.nil? diff --git a/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb b/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb index 50281de43..35f3c555d 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/restapi/azure_client.rb @@ -435,18 +435,6 @@ def create_virtual_machine(resource_group_name, vm_params, network_interfaces, a end end - unless vm_params[:config_disk].nil? - # append the config disk into the vm. - vm['properties']['storageProfile']['dataDisks'] = [] if vm['properties']['storageProfile']['dataDisks'].nil? - vm['properties']['storageProfile']['dataDisks'].push( - 'lun' => 1, - 'createOption' => 'Attach', - 'managedDisk' => { - 'id' => vm_params[:config_disk][:id].to_s - } - ) - end - unless availability_set.nil? vm['properties']['availabilitySet'] = { 'id' => availability_set[:id] diff --git a/src/bosh_azure_cpi/lib/cloud/azure/utils/bosh_agent_util.rb b/src/bosh_azure_cpi/lib/cloud/azure/utils/bosh_agent_util.rb index d3b202f94..b77288b6a 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/utils/bosh_agent_util.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/utils/bosh_agent_util.rb @@ -46,10 +46,10 @@ def encode_user_data(user_data) Base64.strict_encode64(JSON.dump(user_data)) end - # Obtain the full VM metadata to write in config disk or custom data. + # Obtain the full VM metadata to write custom data. # # As of CPI API version 2, and stemcell API version 2, the registry is bypassed. - # The agent settings are written directly to config disk if used, or the VM's custom data. + # The agent settings are written directly to the VM's custom data. # The stemcell API version is used to determine compatibility with the agent on the stemcell. # An updated agent will read the base metadata, and additionally the agent settings, bypassing the registry. def user_data_obj(registry_endpoint, instance_id, dns, agent_id, network_spec, environment, vm_params, config, computer_name = nil) @@ -88,7 +88,7 @@ def meta_data_obj(instance_id, ssh_public_key) # # Note: # As of CPI API version 2, and stemcell API version 2, the registry is bypassed. - # The agent settings are written directly to config disk if used, or the VM's custom data. + # The agent settings are written directly to the VM's custom data. # # @param [String] agent_id Agent id (will be picked up by agent to # assume its identity diff --git a/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb b/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb index 802e7af5c..541307609 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/utils/helpers.rb @@ -114,7 +114,6 @@ module Helpers DATA_DISK_PREFIX = 'bosh-data' MANAGED_OS_DISK_PREFIX = 'bosh-disk-os' MANAGED_DATA_DISK_PREFIX = 'bosh-disk-data' - MANAGED_CONFIG_DISK_PREFIX = 'bosh-cfg-disk' EPHEMERAL_DISK_POSTFIX = 'ephemeral-disk' STEMCELL_PREFIX = 'bosh-stemcell' LIGHT_STEMCELL_PREFIX = 'bosh-light-stemcell' diff --git a/src/bosh_azure_cpi/lib/cloud/azure/vms/vm_manager.rb b/src/bosh_azure_cpi/lib/cloud/azure/vms/vm_manager.rb index f99f48c72..c71fe1530 100644 --- a/src/bosh_azure_cpi/lib/cloud/azure/vms/vm_manager.rb +++ b/src/bosh_azure_cpi/lib/cloud/azure/vms/vm_manager.rb @@ -4,10 +4,9 @@ module Bosh::AzureCloud class VMManager # rubocop:todo Metrics/ClassLength include Helpers - def initialize(azure_config, registry_endpoint, disk_manager, disk_manager2, azure_client, storage_account_manager, stemcell_manager, stemcell_manager2, light_stemcell_manager, config_disk_manager = nil) + def initialize(azure_config, registry_endpoint, disk_manager, disk_manager2, azure_client, storage_account_manager, stemcell_manager, stemcell_manager2, light_stemcell_manager) @azure_config = azure_config @registry_endpoint = registry_endpoint - @config_disk_manager = config_disk_manager @disk_manager = disk_manager @disk_manager2 = disk_manager2 @azure_client = azure_client @@ -156,16 +155,7 @@ def create(bosh_vm_meta, location, vm_props, disk_cids, network_configurator, en vm_params[:ssh_username] = @azure_config.ssh_user vm_params[:ssh_cert_data] = @azure_config.ssh_public_key user_data = agent_settings.user_data_obj(@registry_endpoint, instance_id.to_s, network_configurator.default_dns, bosh_vm_meta.agent_id, network_spec, env, vm_params, config) - if @azure_config.config_disk.enabled - meta_data_obj = agent_settings.meta_data_obj( - instance_id.to_s, - @azure_config.ssh_public_key - ) - config_disk = @config_disk_manager.prepare_config_disk(resource_group_name, vm_name, location, meta_data_obj, user_data) - vm_params[:config_disk] = config_disk - else - vm_params[:custom_data] = agent_settings.encode_user_data(user_data) - end + vm_params[:custom_data] = agent_settings.encode_user_data(user_data) when 'windows' # Generate secure random strings as username and password for Windows VMs # Users do not use this credential to logon to Windows VMs @@ -211,8 +201,6 @@ def create(bosh_vm_meta, location, vm_props, disk_cids, network_configurator, en ephemeral_disk_name = @disk_manager2.generate_ephemeral_disk_name(vm_name) error_message += "\t Managed Ephemeral Disk: #{ephemeral_disk_name}\n" end - - # TODO: Output message to delete config disk else storage_account_name = instance_id.storage_account_name os_disk_name = @disk_manager.generate_os_disk_name(vm_name) @@ -266,8 +254,6 @@ def create(bosh_vm_meta, location, vm_props, disk_cids, network_configurator, en end ) - # TODO: delete the config disk. - tasks.map(&:wait) tasks.map(&:wait!) rescue StandardError => error diff --git a/src/bosh_azure_cpi/spec/spec_helper.rb b/src/bosh_azure_cpi/spec/spec_helper.rb index 6c8a98d21..327ef8945 100644 --- a/src/bosh_azure_cpi/spec/spec_helper.rb +++ b/src/bosh_azure_cpi/spec/spec_helper.rb @@ -73,10 +73,7 @@ def mock_cloud_options 'default_security_group' => MOCK_DEFAULT_SECURITY_GROUP, 'debug_mode' => false, 'use_managed_disks' => false, - 'request_id' => MOCK_REQUEST_ID, - 'config_disk' => { - 'enabled' => false - } + 'request_id' => MOCK_REQUEST_ID }, 'registry' => { 'endpoint' => 'localhost:42288', diff --git a/src/bosh_azure_cpi/spec/unit/azure_client/create_virtual_machine_spec.rb b/src/bosh_azure_cpi/spec/unit/azure_client/create_virtual_machine_spec.rb index 753c85ac3..3c5627a57 100644 --- a/src/bosh_azure_cpi/spec/unit/azure_client/create_virtual_machine_spec.rb +++ b/src/bosh_azure_cpi/spec/unit/azure_client/create_virtual_machine_spec.rb @@ -1450,124 +1450,6 @@ end.not_to raise_error end end - - context 'when config disk is specified' do - let(:config_disk_id) { 'fake_config_disk_id' } - let(:vm_params_config_disk) do - vm_params_dupped = vm_params.dup - vm_params_dupped[:config_disk] = { id: config_disk_id } - vm_params_dupped - end - - let(:request_body) do - { - name: vm_name, - location: 'b', - type: 'Microsoft.Compute/virtualMachines', - tags: { - foo: 'bar' - }, - properties: { - hardwareProfile: { - vmSize: 'c' - }, - osProfile: { - customData: 'f', - computerName: vm_name, - adminUsername: 'd', - linuxConfiguration: { - disablePasswordAuthentication: 'true', - ssh: { - publicKeys: [ - { - path: '/home/d/.ssh/authorized_keys', - keyData: 'e' - } - ] - } - } - }, - networkProfile: { - networkInterfaces: [ - { - id: 'a', - properties: { - primary: true - } - }, - { - id: 'b', - properties: { - primary: false - } - } - ] - }, - storageProfile: { - osDisk: { - name: 'h', - osType: 'linux', - createOption: 'FromImage', - caching: 'j', - image: { - uri: 'g' - }, - vhd: { - uri: 'i' - }, - diskSizeGB: 'k' - }, - dataDisks: [ - { - name: 'l', - lun: 0, - createOption: 'Empty', - diskSizeGB: 'o', - vhd: { - uri: 'm' - }, - caching: 'n' - }, - { - lun: 1, - createOption: 'Attach', - managedDisk: { - id: config_disk_id - } - } - ] - } - } - } - end - - it 'should raise no error' do - stub_request(:post, token_uri).to_return( - status: 200, - body: { - 'access_token' => valid_access_token, - 'expires_on' => expires_on - }.to_json, - headers: {} - ) - stub_request(:put, vm_uri).with(body: request_body).to_return( - status: 200, - body: '', - headers: { - 'azure-asyncoperation' => operation_status_link - } - ) - stub_request(:get, operation_status_link).to_return( - status: 200, - body: '{"status":"Succeeded"}', - headers: {} - ) - - expect do - azure_client.create_virtual_machine(resource_group, vm_params_config_disk, network_interfaces) - end.not_to raise_error - end - end end context 'when token expired' do diff --git a/src/bosh_azure_cpi/spec/unit/vm_manager/create/shared_stuff.rb b/src/bosh_azure_cpi/spec/unit/vm_manager/create/shared_stuff.rb index 0562a38c2..6b7fd723e 100644 --- a/src/bosh_azure_cpi/spec/unit/vm_manager/create/shared_stuff.rb +++ b/src/bosh_azure_cpi/spec/unit/vm_manager/create/shared_stuff.rb @@ -16,14 +16,6 @@ ) ) end - let(:azure_config_use_config_disk) do - mock_azure_config_merge( - 'use_managed_disks' => true, - 'config_disk' => { - 'enabled' => true - } - ) - end let(:registry_endpoint) { mock_registry.endpoint } let(:disk_manager) { instance_double(Bosh::AzureCloud::DiskManager) } let(:disk_manager2) { instance_double(Bosh::AzureCloud::DiskManager2) } @@ -33,13 +25,10 @@ let(:stemcell_manager2) { instance_double(Bosh::AzureCloud::StemcellManager2) } let(:light_stemcell_manager) { instance_double(Bosh::AzureCloud::LightStemcellManager) } let(:blob_manager) { instance_double(Bosh::AzureCloud::BlobManager) } - let(:config_disk_manager) { Bosh::AzureCloud::ConfigDiskManager.new(blob_manager, disk_manager2, storage_account_manager) } # VM manager for unmanaged disks let(:vm_manager) { Bosh::AzureCloud::VMManager.new(azure_config, registry_endpoint, disk_manager, disk_manager2, azure_client, storage_account_manager, stemcell_manager, stemcell_manager2, light_stemcell_manager) } # VM manager for managed disks let(:vm_manager2) { Bosh::AzureCloud::VMManager.new(azure_config_managed, registry_endpoint, disk_manager, disk_manager2, azure_client, storage_account_manager, stemcell_manager, stemcell_manager2, light_stemcell_manager) } - # VM manager for config disks - let(:vm_manager_config_disk) { Bosh::AzureCloud::VMManager.new(azure_config_use_config_disk, registry_endpoint, disk_manager, disk_manager2, azure_client, storage_account_manager, stemcell_manager, stemcell_manager2, light_stemcell_manager, config_disk_manager) } # Parameters of create let(:instance_id) { instance_double(Bosh::AzureCloud::InstanceId) } let(:location) { 'fake-location' } @@ -81,8 +70,6 @@ .and_return(name: storage_account_name) allow(vm_manager2).to receive(:get_storage_account_from_vm_properties) .and_return(name: storage_account_name) - allow(vm_manager_config_disk).to receive(:get_storage_account_from_vm_properties) - .and_return(name: storage_account_name) end # Stemcell diff --git a/src/bosh_azure_cpi/spec/unit/vm_manager/create/use_config_disk_spec.rb b/src/bosh_azure_cpi/spec/unit/vm_manager/create/use_config_disk_spec.rb deleted file mode 100644 index 11b42fe3c..000000000 --- a/src/bosh_azure_cpi/spec/unit/vm_manager/create/use_config_disk_spec.rb +++ /dev/null @@ -1,93 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' -require 'unit/vm_manager/create/shared_stuff' - -# RSpec::Matchers.define :need_mock_command do -# match { |actual| { actual.include?('mount') || actual.include?('mkfs.ext4') } } -# end -describe Bosh::AzureCloud::VMManager do - include_context 'shared stuff for vm manager' - - describe '#create' do - let(:agent_util) { instance_double(Bosh::AzureCloud::BoshAgentUtil) } - let(:network_spec) { {} } - let(:config) { instance_double(Bosh::AzureCloud::Config) } - let(:command_runner) { Bosh::AzureCloud::CommandRunner.new } - - before do - allow(stemcell_info).to receive(:os_type).and_return('linux') - allow(vm_manager_config_disk).to receive(:_get_stemcell_info).and_return(stemcell_info) - allow(storage_account_manager).to receive(:default_storage_account_name) - .and_return(MOCK_DEFAULT_STORAGE_ACCOUNT_NAME) - allow(Etc).to receive(:getpwuid) - .and_return(OpenStruct.new(name: 'vcap')) - allow(agent_util).to receive(:user_data_obj).and_return({}) - allow(agent_util).to receive(:meta_data_obj).and_return({}) - allow(agent_util).to receive(:encode_user_data).and_return(Base64.strict_encode64(JSON.dump({}))) - end - - context 'when use config disk' do - context 'when everything ok' do - it 'should prepare config disk' do - expect(azure_client).to receive(:create_virtual_machine) - expect(command_runner).to receive(:run_command).with(/sudo -n mount/).once - expect(command_runner).to receive(:run_command).with(/mkfs/).once - expect(command_runner).to receive(:run_command).with(/sudo -n chown/).once - expect(command_runner).to receive(:run_command).with(/sudo -n umount/).once - expect(command_runner).to receive(:run_command).twice.and_call_original - - expect(Bosh::AzureCloud::CommandRunner).to receive(:new).and_return(command_runner) - - expect(blob_manager).to receive(:create_vhd_page_blob) - expect(blob_manager).to receive(:delete_blob) - expect(blob_manager).to receive(:get_blob_uri) - expect(disk_manager2).to receive(:create_disk_from_blob) - expect(disk_manager2).to receive(:get_data_disk) - expect do - vm_manager_config_disk.create(bosh_vm_meta, location, vm_props, disk_cids, network_configurator, env, agent_util, network_spec, config) - end.not_to raise_error - end - end - - context 'when mkfs failed' do - it 'should raise an error and clean up' do - expect(Bosh::AzureCloud::CommandRunner).to receive(:new).and_return(command_runner) - expect(command_runner).to receive(:run_command).with(/mkfs/).and_raise('failed to mkfs') - expect(command_runner).to receive(:run_command).with(/sudo -n umount/).once - expect(command_runner).to receive(:run_command).once.and_call_original - - expect(blob_manager).not_to receive(:create_vhd_page_blob) - expect(blob_manager).not_to receive(:delete_blob) - expect(blob_manager).not_to receive(:get_blob_uri) - expect(disk_manager2).not_to receive(:create_disk_from_blob) - expect(azure_client).to receive(:delete_network_interface).twice - expect do - vm_manager_config_disk.create(bosh_vm_meta, location, vm_props, disk_cids, network_configurator, env, agent_util, network_spec, config) - end.to raise_error Bosh::Clouds::CloudError, /Failed to prepare the config disk/ - end - end - - context 'when create disk failed' do - it 'should raise an error and clean up' do - expect(command_runner).to receive(:run_command).with(/sudo -n mount/).once - expect(command_runner).to receive(:run_command).with(/mkfs/).once - expect(command_runner).to receive(:run_command).with(/sudo -n chown/).once - expect(command_runner).to receive(:run_command).with(/sudo -n umount/).once - expect(command_runner).to receive(:run_command).twice.and_call_original - - expect(Bosh::AzureCloud::CommandRunner).to receive(:new).and_return(command_runner) - - expect(blob_manager).to receive(:create_vhd_page_blob) - expect(blob_manager).to receive(:delete_blob) - expect(blob_manager).to receive(:get_blob_uri) - expect(disk_manager2).to receive(:create_disk_from_blob).and_raise('create disk failed') - expect(azure_client).to receive(:delete_network_interface).twice - expect do - vm_manager_config_disk.create(bosh_vm_meta, location, vm_props, disk_cids, network_configurator, env, agent_util, network_spec, config) - end.to raise_error Bosh::Clouds::CloudError, /Failed to prepare the config disk/ - end - end - end - end -end