Skip to content

Commit 18e1fde

Browse files
committed
(PUP-3631) Allow bff security update packages with nim package provider
This commit adapts the regular expression used in the `nim` package provider to allow packages with `S` (security update) in their header to be installed instead of throwing error as previously with `Unable to parse output from nimclient showres: line does not match expected package header format` as message.
1 parent 2fde3e6 commit 18e1fde

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

lib/puppet/provider/package/nim.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,20 +154,25 @@ def install(useversion = true)
154154
# I spent a lot of time trying to figure out a solution that didn't
155155
# require parsing the `nimclient -o showres` output and was unable to
156156
# do so.
157-
self::HEADER_LINE_REGEX = /^([^\s]+)\s+[^@]+@@(I|R):(\1)\s+[^\s]+$/
158-
self::PACKAGE_LINE_REGEX = /^.*@@(I|R):(.*)$/
157+
self::HEADER_LINE_REGEX = /^([^\s]+)\s+[^@]+@@(I|R|S):(\1)\s+[^\s]+$/
158+
self::PACKAGE_LINE_REGEX = /^.*@@(I|R|S):(.*)$/
159159
self::RPM_PACKAGE_REGEX = /^(.*)-(.*-\d+) \2$/
160160
self::INSTALLP_PACKAGE_REGEX = /^(.*) (.*)$/
161161

162162
# Here is some sample output that shows what the above regexes will be up
163163
# against:
164-
# FOR AN INSTALLP PACKAGE:
164+
# FOR AN INSTALLP(bff) PACKAGE:
165165
#
166166
# mypackage.foo ALL @@I:mypackage.foo _all_filesets
167-
# @ 1.2.3.1 MyPackage Runtime Environment @@I:mypackage.foo 1.2.3.1
168167
# + 1.2.3.4 MyPackage Runtime Environment @@I:mypackage.foo 1.2.3.4
169168
# + 1.2.3.8 MyPackage Runtime Environment @@I:mypackage.foo 1.2.3.8
170169
#
170+
# FOR AN INSTALLP(bff) PACKAGE with security update:
171+
#
172+
# bos.net ALL @@S:bos.net _all_filesets
173+
# + 7.2.0.1 TCP/IP ntp Applications @@S:bos.net.tcp.ntp 7.2.0.1
174+
# + 7.2.0.2 TCP/IP ntp Applications @@S:bos.net.tcp.ntp 7.2.0.2
175+
#
171176
# FOR AN RPM PACKAGE:
172177
#
173178
# mypackage.foo ALL @@R:mypackage.foo _all_filesets
@@ -243,7 +248,7 @@ def parse_showres_package_line(line)
243248
package_string = match.captures[1]
244249

245250
case package_type_flag
246-
when "I"
251+
when "I","S"
247252
parse_installp_package_string(package_string)
248253
when "R"
249254
parse_rpm_package_string(package_string)

spec/unit/provider/package/nim_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,27 @@
220220
it "should return :installp for installp/bff packages" do
221221
expect(subject.send(:determine_package_type, bff_showres_output, 'mypackage.foo', '1.2.3.4')).to eq(:installp)
222222
end
223+
224+
it "should return :installp for security updates" do
225+
nimclient_showres_output = <<END
226+
bos.net ALL @@S:bos.net _all_filesets
227+
+ 7.2.0.1 TCP/IP ntp Applications @@S:bos.net.tcp.ntp 7.2.0.1
228+
+ 7.2.0.2 TCP/IP ntp Applications @@S:bos.net.tcp.ntp 7.2.0.2
229+
230+
END
231+
expect(subject.send(:determine_package_type, nimclient_showres_output, 'bos.net.tcp.ntp', '7.2.0.2')).to eq(:installp)
232+
end
233+
234+
it "should raise error when invalid header format is given" do
235+
nimclient_showres_output = <<END
236+
bos.net ALL @@INVALID_TYPE:bos.net _all_filesets
237+
+ 7.2.0.1 TCP/IP ntp Applications @@INVALID_TYPE:bos.net.tcp.ntp 7.2.0.1
238+
+ 7.2.0.2 TCP/IP ntp Applications @@INVALID_TYPE:bos.net.tcp.ntp 7.2.0.2
239+
240+
END
241+
expect{ subject.send(:determine_package_type, nimclient_showres_output, 'bos.net.tcp.ntp', '7.2.0.2') }.to raise_error(
242+
Puppet::Error, /Unable to parse output from nimclient showres: line does not match expected package header format/)
243+
end
223244
end
224245
end
225246
end

0 commit comments

Comments
 (0)