Skip to content

Commit

Permalink
Replace node with self in all the node_methods libs: prod
Browse files Browse the repository at this point in the history
Differential Revision: D63281936

fbshipit-source-id: 1cc2414aadb09ac7b7650e147cf34d0f921b61a4
  • Loading branch information
Olivier Raginel authored and facebook-github-bot committed Jan 15, 2025
1 parent fe32c9c commit d3f443e
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions cookbooks/fb_helpers/libraries/node_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,43 +368,43 @@ def macos?
alias macosx? macos?

def macos10?
macos? && node['platform_version'].start_with?('10.')
macos? && self['platform_version'].start_with?('10.')
end

def macos11?
macos? && node['platform_version'].start_with?('11.')
macos? && self['platform_version'].start_with?('11.')
end

def macos12?
macos? && node['platform_version'].start_with?('12.')
macos? && self['platform_version'].start_with?('12.')
end

def macos13?
macos? && node['platform_version'].start_with?('13.')
macos? && self['platform_version'].start_with?('13.')
end

def macos14?
macos? && node['platform_version'].start_with?('14.')
macos? && self['platform_version'].start_with?('14.')
end

def macos15?
macos? && node['platform_version'].start_with?('15.')
macos? && self['platform_version'].start_with?('15.')
end

def mac_mini_2018?
macos? && node['hardware']['machine_model'] == 'Macmini8,1'
macos? && self['hardware']['machine_model'] == 'Macmini8,1'
end

def mac_mini_2020?
macos? && node['hardware']['machine_model'] == 'Macmini9,1'
macos? && self['hardware']['machine_model'] == 'Macmini9,1'
end

def windows?
self['platform_family'] == 'windows'
end

def windows_desktop?
windows? && node['kernel']['product_type'] == 'Workstation'
windows? && self['kernel']['product_type'] == 'Workstation'
end

def windows8?
Expand All @@ -428,7 +428,7 @@ def windows10_or_newer?
end

def windows_server?
windows? && node['kernel']['product_type'] == 'Server'
windows? && self['kernel']['product_type'] == 'Server'
end

def windows2008?
Expand Down Expand Up @@ -647,7 +647,7 @@ def in_aws_account?(*accts)

def ohai_fs_ver
@ohai_fs_ver ||=
node['filesystem2'] ? 'filesystem2' : 'filesystem'
self['filesystem2'] ? 'filesystem2' : 'filesystem'
end

# Take a string representing a mount point, and return the
Expand Down Expand Up @@ -773,15 +773,15 @@ def efi?

def coreboot?
File.directory?('/sys/firmware/vpd') ||
node['dmi']['bios']['vendor'] == 'coreboot'
self['dmi']['bios']['vendor'] == 'coreboot'
end

def aarch64?
node['kernel']['machine'] == 'aarch64'
self['kernel']['machine'] == 'aarch64'
end

def x64?
node['kernel']['machine'] == 'x86_64'
self['kernel']['machine'] == 'x86_64'
end

def cgroup_mounted?
Expand All @@ -803,12 +803,12 @@ def cgroup2?
def get_flexible_shard(shard_size)
@flexible_shard_value ||= {}
@flexible_shard_value[shard_size] ||=
if node['shard_seed']
node['shard_seed'] % shard_size
if self['shard_seed']
self['shard_seed'] % shard_size
else
# backwards compat for Facebook until
# https://github.com/chef/ohai/pull/877 is out
node['fb']['shard_seed'] % shard_size
self['fb']['shard_seed'] % shard_size
end
@flexible_shard_value[shard_size]
end
Expand Down Expand Up @@ -951,7 +951,7 @@ def rollout_shard(start_date)
def firstboot_os?
# this has to work even when we fail early on so we can call this from
# broken runs in handlers
node['fb_init']['firstboot_os']
self['fb_init']['firstboot_os']
rescue StandardError
prefix = macos? ? '/var/root' : '/root'
File.exist?(File.join(prefix, 'firstboot_os'))
Expand All @@ -960,7 +960,7 @@ def firstboot_os?
def firstboot_tier?
# this has to work even when we fail early on so we can call this from
# broken runs in handlers
node['fb_init']['firstboot_tier']
self['fb_init']['firstboot_tier']
rescue StandardError
prefix = macos? ? '/var/root' : '/root'
File.exist?(File.join(prefix, 'firstboot_tier'))
Expand All @@ -973,11 +973,11 @@ def firstboot_any_phase?
# is this device a SSD? If it's not rotational, then it's SSD
# expects a short device name, e.g. 'sda', not '/dev/sda', not '/dev/sda3'
def device_ssd?(device)
unless node['block_device'][device]
unless self['block_device'][device]
fail "fb_helpers: Device '#{device}' passed to node.device_ssd? " +
"doesn't appear to be a block device!"
end
node['block_device'][device]['rotational'] == '0'
self['block_device'][device]['rotational'] == '0'
end

def root_compressed?
Expand Down Expand Up @@ -1061,35 +1061,35 @@ def rpm_version(name)
end

def selinux_mode
node['selinux']['status']['current_mode'] || 'unknown'
self['selinux']['status']['current_mode'] || 'unknown'
end

def selinux_policy
node['selinux']['status']['loaded_policy_name']
self['selinux']['status']['loaded_policy_name']
end

def selinux_enabled?
node['selinux']['status']['selinux_status'] == 'enabled'
self['selinux']['status']['selinux_status'] == 'enabled'
end

def host_chef_base_path
if node.windows?
if self.windows?
File.join('C:', 'chef')
else
File.join('/var', 'chef')
end
end

def solo_chef_base_path
if node.windows?
if self.windows?
File.join('C:', 'chef', 'solo')
else
File.join('/opt', 'chef-solo')
end
end

def chef_base_path
if node.solo?
if self.solo?
self.solo_chef_base_path
else
self.host_chef_base_path
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def attr_lookup(path, delim: '/', default: nil)
end

def default_package_manager
cls = Chef::ResourceResolver.resolve(:package, :node => node)
cls = Chef::ResourceResolver.resolve(:package, :node => self)
if cls
m = cls.to_s.match(/Chef::Resource::(\w+)Package/)
if m[1]
Expand All @@ -1163,7 +1163,7 @@ def eth_is_affinitized?
# mlx is special cased because of their device naming convention
r = /^(eth(.*[Rr]x|\d+-\d+)|mlx4-\d+@.*|mlx5_comp\d+@.*)/

irqs = node['interrupts']['irq'].select do |_irq, v|
irqs = self['interrupts']['irq'].select do |_irq, v|
v['device'] && r.match?(v['device']) &&
v['type'] && v['type'].end_with?('MSI')
end
Expand All @@ -1174,7 +1174,7 @@ def eth_is_affinitized?
)
return true
end
default_affinity = node['interrupts']['smp_affinity_by_cpu']
default_affinity = self['interrupts']['smp_affinity_by_cpu']
# When all interrupts are affinitized, smp_affinity will be different
# from the default one, and won't be global. Global technically says
# that interrupts can be processed on all CPUs, but in reality what's
Expand Down Expand Up @@ -1203,7 +1203,7 @@ def eth_is_affinitized?
end

def validate_and_fail_on_dynamic_addresses
node['network']['interfaces'].each do |if_str, if_data|
self['network']['interfaces'].each do |if_str, if_data|
next unless if_data['addresses']

if_data['addresses'].each do |addr_str, addr_data|
Expand All @@ -1218,23 +1218,23 @@ def validate_and_fail_on_dynamic_addresses
end

def nw_changes_allowed?
method = node['fb_helpers']['network_changes_allowed_method']
method = self['fb_helpers']['network_changes_allowed_method']
if method
return method.call(node)
return method.call(self)
else
return @nw_changes_allowed unless @nw_changes_allowed.nil?

@nw_changes_allowed = node.firstboot_any_phase? ||
@nw_changes_allowed = self.firstboot_any_phase? ||
::File.exist?(::FB::Helpers::NW_CHANGES_ALLOWED)
end
end

# We can change interface configs if nw_changes_allowed? or we are operating
# on a DSR VIP
def interface_change_allowed?(interface)
method = node['fb_helpers']['interface_change_allowed_method']
method = self['fb_helpers']['interface_change_allowed_method']
if method
return method.call(node, interface)
return method.call(self, interface)
else
return self.nw_changes_allowed? ||
['ip6tnl0', 'tunlany0', 'tunl0'].include?(interface) ||
Expand All @@ -1243,9 +1243,9 @@ def interface_change_allowed?(interface)
end

def interface_start_allowed?(interface)
method = node['fb_helpers']['interface_start_allowed_method']
method = self['fb_helpers']['interface_start_allowed_method']
if method
return method.call(node, interface)
return method.call(self, interface)
else
return self.interface_change_allowed?(interface)
end
Expand All @@ -1255,7 +1255,7 @@ def interface_start_allowed?(interface)
# provisioning or upon boot
def disruptable?
@disruptable ||=
node.firstboot_any_phase? || ENV['CHEF_BOOT_SERVICE'] == 'true'
self.firstboot_any_phase? || ENV['CHEF_BOOT_SERVICE'] == 'true'
end
end
end

0 comments on commit d3f443e

Please sign in to comment.