Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASM-9277 Do not #read a closed file handle, File.read instead #88

Merged
merged 1 commit into from Mar 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/asm/firmware.rb
Expand Up @@ -211,14 +211,16 @@ def update_idrac_firmware(firmware_list, force_restart, wsman)
def gets_install_uri_job(firmware, wsman)
config_file = create_xml_config_file(firmware["instance_id"], firmware["uri_path"])
resp = wsman.install_from_uri(:input_file => config_file.path)

if resp[:return_value] == "4096"
job_id = resp[:job]
logger.debug("InstallFromURI started")
logger.debug("JOB_ID: #{job_id}")
else
logger.debug("Error installing From URI config: #{config_file.read}")
logger.debug("Error installing From URI config: %s" % File.read(config_file.path))
raise("Problem running InstallFromURI: #{resp[:message]}")
end

job_id
end

Expand Down Expand Up @@ -336,9 +338,9 @@ def setup_job_queue(config_file, wsman)
#
# this creates a temporary file to be used for the SetupJobQueue wsman call
#
# @param [Array<string>] job_ids job ids to be scheduled
# @param [String] reboot_id the reboot job
# @return [File] the xml file object
# @param job_ids [Array<String>] job ids to be scheduled
# @param reboot_id [String] the reboot job
# @return [Tempfile] the xml file object
def create_job_queue_config(job_ids, reboot_id=nil)
template = <<-EOF
<p:SetupJobQueue_INPUT xmlns:p="http://schemas.dell.com/wbem/wscim/1/cim-schema/2/DCIM_JobService"><% job_ids.each do |job_id| %>
Expand All @@ -359,8 +361,8 @@ def create_job_queue_config(job_ids, reboot_id=nil)
# Used to create an XML file:
#
# @param instance_id [String] job_id
# @return [void]
# Path specifies moount path
# @param path [String] specifies moount path
# @return [Tempfile]
def create_xml_config_file(instance_id, path)
template = <<-EOF
<p:InstallFromURI_INPUT xmlns:p="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/root/dcim/DCIM_SoftwareInstallationService">
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/asm/firmware_spec.rb
Expand Up @@ -222,7 +222,7 @@
it "should raise an error when install_from_uri job fails" do
data = {:name => "xyz", :description => "test file"}.to_json
data.stubs(:path).returns("/tmp")
data.stubs(:read).returns("tmp")
File.stubs(:read).with("/tmp").returns("tmp")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logankimmel you do kind of test the unhappy path but stub too much so the problem got hidden :) not really always a good way to stub these file things so it is what it is.

firmware_obj.stubs(:create_xml_config_file).returns(data)
wsman.stubs(:install_from_uri).returns(failed_return)
expect do
Expand Down