puppetlabs/packaging — pull request #358 by MosesMendoza (2014-11-15 18:19:37+00:00)
Title: Maint/master/stricter deb shipping

We go back and forth on this, but I've finally found a use case for wanting the stdout from a remote ssh command. Reprepro won't return non-zero when it ignores a deb for inclusion in a repo. With the promotion process, we've been assuming that just checking for an equivalent package in packages.json is a safe check for preventing duplicate package promotions. However, as we've found with trying to get a new PE version pipeline in order, we can't always rely on packages.json to be accurate. When it's not, we've been "successfully" promoting packages, when in fact the debs are completely ignored by reprepro because they already exist in the debian repos. The metadata in packages.json is still updated though, which leads to failed composes because the md5s don't match up between packages.json (has the ignored deb md5) and the real package in the repo (has the pre-existing deb md5).

This PR modifies the remote_ssh_cmd method to use the Open3.capture3 method for executing system calls. This method returns the stdout, stderr, and exit status object for a given system call. We use it to get the output, and exit status, of our ssh command. To return this output, callers of this method add "true" for verbose to the invocation. This will only happen on success - failure will still raise an exception. This is backwards compatible.

This PR then leverages this new facility in remote_ssh_cmd for capturing the output of an ssh command. We do so to scan the output for "Skipping Inclusion" - a string that indicates reprepro has refused to add a deb to the repository because one of the same NVR already exists. When reprepro does this, it exits 0. We were previously not handling this case, assuming success based on the exit code. If reprepro has skipped inclusion, we now fail, as we should.