Skip to content

Commit

Permalink
Make el_min_version and and el_max_version use major version for comp…
Browse files Browse the repository at this point in the history
…arison

Differential Revision: D61303063

fbshipit-source-id: e831484b77d1af6c3de12ca226422b47c8afafcd
  • Loading branch information
skywalk7 authored and facebook-github-bot committed Aug 20, 2024
1 parent ee4265e commit f8ce24a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 4 deletions.
4 changes: 2 additions & 2 deletions cookbooks/fb_helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ your node.
Is Redhat Enterprise Linux 10

* `node.rhel_max_version?(v)`
Is Redhat Enterprise Linux with a maximum version number of v
Is Redhat Enterprise Linux with a maximum major version number of v

* `node.rhel_min_version?(v)`
Is Redhat Enterprise Linux with a minimum version number of v
Is Redhat Enterprise Linux with a minimum major version number of v

* `node.rhel?`
Is Redhat Enterprise Linux
Expand Down
4 changes: 2 additions & 2 deletions cookbooks/fb_helpers/libraries/node_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def _self_version

# Is this a RHEL-compatible OS with a minimum major version number of `version`
def el_min_version?(version)
self.rhel_family? && self._self_version >= self._canonical_version(version)
self.rhel_family? && self._self_version[0] >= self._canonical_version(version)[0]
end

# Is this a RHEL-compatible OS with a maximum major version number of `version`
def el_max_version?(version)
self.rhel_family? && self._self_version <= self._canonical_version(version)
self.rhel_family? && self._self_version[0] <= self._canonical_version(version)[0]
end

def rhel_family7?
Expand Down
63 changes: 63 additions & 0 deletions cookbooks/fb_helpers/spec/el_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2
#
# Copyright (c) 2024-present, Meta Platforms, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require './spec/spec_helper'
require_relative '../libraries/fb_helpers'
require_relative '../libraries/node_methods'

describe 'Chef::Node' do
let(:node) { Chef::Node.new }

context 'Chef::Node.el_min_version?' do
before(:each) do
node.default['platform_version'] = '8.2'
node.default['platform_family'] = 'rhel'
end

it 'should report correct version' do
expect(node._self_version).to eq(FB::Version.new('8.2'))
end

it 'should be min 8' do
expect(node.el_min_version?(8)).to eq(true)
end

it 'should not be min 9' do
expect(node.el_min_version?(9)).to eq(false)
end
end

context 'Chef::Node.el_max_version?' do
before(:each) do
node.default['platform_version'] = '9.2'
node.default['platform_family'] = 'rhel'
end

it 'should report correct version' do
expect(node._self_version).to eq(FB::Version.new('9.2'))
end

it 'should be max 9' do
expect(node.el_max_version?(9)).to eq(true)
end

it 'should not be max 8' do
expect(node.el_max_version?(8)).to eq(false)
end
end
end

0 comments on commit f8ce24a

Please sign in to comment.