Giter Club home page Giter Club logo

Comments (13)

sersut avatar sersut commented on June 15, 2024

Thanks for getting this into here @cixelsyd.

We've seen similar issues where using popen4 is creating some issues on windows. I think the right path here would be to switch using shell_out instead of output_of_command to execute the command.

The conversion should be pretty straightforward. If you'd like to make a shot at this let me know and I'll give you some pointers to get you started.

Thanks again for spending time and working with us on this.

from chef.

cixelsyd avatar cixelsyd commented on June 15, 2024

I'm excited to work with you on this. let me know how I can help!

Steven

mobile

On Jun 24, 2014, at 4:21 PM, Serdar Sutay [email protected] wrote:

Thanks for getting this into here @cixelsyd.

We've seen similar issues where using popen4 is creating some issues on windows. I think the right path here would be to switch using shell_out instead of output_of_command to execute the command.

The conversion should be pretty straightforward. If you'd like to make a shot at this let me know and I'll give you some pointers to get you started.

Thanks again for spending time and working with us on this.


Reply to this email directly or view it on GitHub.

from chef.

sersut avatar sersut commented on June 15, 2024

Awesome @cixelsyd. shell_out() is the Chef's platform independenct command execution system which takes care of a lot of the nasty stuff. We need to replace the output_of_command functions with shell_out calls in the lib/chef/provider/subversion.rb file.

You can see a really good example here: https://github.com/opscode/chef/blob/master/lib/chef/provider/git.rb#L123

LMK if you have any questions or help to move forward and thanks so much for spending your time on this 😄

from chef.

Chucheen avatar Chucheen commented on June 15, 2024

has this been fixed already? or is there any workaround for it? I have this same problem. Thanks in advance!

from chef.

Chucheen avatar Chucheen commented on June 15, 2024

As a workaround for this bug i did the following,

  1. Create a file in libraries folder of a cookbook that is presenting the error or one that you always include in your runlists

  2. Into that file, add the following code:

    class Chef
      module Mixin
    
        module Command
          extend self
    
          def handle_command_failures(status, command_output, opts={})
            unless opts[:ignore_failure]
              opts[:returns] ||= 0
              unless Array([opts[:returns],42]).include?(status.exitstatus)
                # if the log level is not debug, through output of command when we fail
                output = ""
                if Chef::Log.level == :debug || opts[:output_on_failure]
                  output << "\n---- Begin output of #{opts[:command]} ----\n"
                  output << command_output.to_s
                  output << "\n---- End output of #{opts[:command]} ----\n"
                end
                raise Chef::Exceptions::Exec, "#{opts[:command]} returned #{status.exitstatus}, expected #{opts[:returns]}#{output}"
              end
            end
          end
    
          module Windows
            def popen4(cmd, args={}, &b)
    
              # By default, we are waiting before we yield the block.
              args[:waitlast] ||= false
    
              #XXX :user, :group, :environment support?
    
              Open3.popen3(cmd) do |stdin,stdout,stderr,cid|
                if b
                  if args[:waitlast]
                    b[cid, stdin, stdout, stderr]
                    # send EOF so that if the child process is reading from STDIN
                    # it will actually finish up and exit
                    stdin.close_write
                  else
                    o = StringIO.new
                    e = StringIO.new
    
                    stdin.close
    
                    stdout.sync = true
                    stderr.sync = true
    
                    line = stdout.gets(nil)
                    if line
                      o.write(line)
                    end
                    line = stderr.gets(nil)
                    if line
                      e.write(line)
                    end
                    o.rewind
                    e.rewind
                    b[cid, stdin, o, e]
                  end
                else
                  [cid, stdin, stdout, stderr]
                end
              end
    
              `ls` if $?.nil?
              Chef::Log.debug ". : : : $? returned nil for command #{cmd}  : : : ."
              $?
            end
    
          end
    
        end
      end
    end
    

the lines that do the trick are:

unless Array([opts[:returns],42]).include?(status.exitstatus)

and

`ls` if $?.nil?
Chef::Log.debug ". : : : $? returned nil for command #{cmd}  : : : ."

(of course, you can erase the debug printing if you want to)

that way you don't need to fix something for every chef release if it's not fixed yet.

I hope it's useful for someone else.

from chef.

lamont-granquist avatar lamont-granquist commented on June 15, 2024

It'd be better to get a PR that just replaced the commands with mixlib-shellout

from chef.

phang98 avatar phang98 commented on June 15, 2024

Thanks @jgutierrezc. This work very well for me.

from chef.

lamont-granquist avatar lamont-granquist commented on June 15, 2024

Should have been fixed by 7b26c36 and prior commits

from chef.

lamont-granquist avatar lamont-granquist commented on June 15, 2024

(should be fixed in 12.1.0)

from chef.

pburkholder avatar pburkholder commented on June 15, 2024

This code:

subversion 'couchdb' do
  repository 'http://svn.apache.org/repos/asf/couchdb/trunk'
  revision 'HEAD'
  action :sync
end

run with: chef-apply svn.rb -l debug fails at line https://github.com/chef/chef/blob/master/lib/chef/provider/subversion.rb#L133:

status, svn_info, error_message = output_of_command(command, run_options)

because output_of_command is still trying to access status.exitstatus

I'll put this on my work backlog to replace output_of_command with shell_out!, but I'm unlikely to whack this off soon.

EDIT: I forgot to mention: This is a Windows issue

from chef.

gh2k avatar gh2k commented on June 15, 2024

I just ran into this in exactly the way @pburkholder mentioned. Can this issue be reopened?

from chef.

gh2k avatar gh2k commented on June 15, 2024

The above PR fixes this for me.

from chef.

lamont-granquist avatar lamont-granquist commented on June 15, 2024

this looks like it got fixed

from chef.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.