integ/config/facter/debian/patches/0001-Add-personality-and-subfunction.patch
Dan Voiculeasa 28c1af9b87 Add debian package for facter 3.14.12
Facter 3 was rewritten in C++. Looking at the source code there are
big differences. For example ipaddress fact is now collected part of
a networking fact. Porting patch 5 require testing of puppet
modules which are not yet packaged for Debian.

Some Facter 2 modules were removed in Facter 3. Porting patch 1 ,3, 4
may be done at a latter time if the modules from facter 2 are added
back.
Adapted only 0002 patch.

Did build facter 3.14.12-1 + 1 starlingx patch adapted from CentOS7.
Did build an iso.
Tested facter showing personality and subfunction.

Story: 2009101
Task: 43222
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: Id9270ab5c986cb6570346faec8a78893ff0363fb
2021-09-15 12:18:58 +03:00

179 lines
5.3 KiB
Diff

From 2bd09160543d0e170d0ade2f695691a03aa3d5fa Mon Sep 17 00:00:00 2001
From: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Date: Tue, 14 Sep 2021 16:33:23 +0000
Subject: [PATCH] Add personality and subfunction
Adapt 0002-personality.patch from CentOS.
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
---
lib/CMakeLists.txt | 9 ++++++
lib/facter/personality.rb | 21 +++++++++++++
lib/facter/subfunction.rb | 61 ++++++++++++++++++++++++++++++++++++
lib/facter/util/file_read.rb | 37 ++++++++++++++++++++++
4 files changed, 128 insertions(+)
create mode 100644 lib/facter/personality.rb
create mode 100644 lib/facter/subfunction.rb
create mode 100644 lib/facter/util/file_read.rb
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 8dd7063..f7d336a 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -435,6 +435,15 @@ if(RUBY_VENDORDIR)
message(STATUS "\"make install\" will install facter.rb to ${RUBY_VENDORDIR}")
install(FILES ${CMAKE_BINARY_DIR}/lib/facter.rb DESTINATION ${RUBY_VENDORDIR})
+ message(STATUS "\"make install\" will install facter/personality.rb to ${RUBY_VENDORDIR}/facter")
+ install(FILES facter/personality.rb DESTINATION ${RUBY_VENDORDIR}/facter)
+
+ message(STATUS "\"make install\" will install facter/subfunction.rb to ${RUBY_VENDORDIR}/facter")
+ install(FILES facter/subfunction.rb DESTINATION ${RUBY_VENDORDIR}/facter)
+
+ message(STATUS "\"make install\" will install facter/util/file_read.rb to ${RUBY_VENDORDIR}/facter/util")
+ install(FILES facter/util/file_read.rb DESTINATION ${RUBY_VENDORDIR}/facter/util)
+
if (JRUBY_SUPPORT)
message(STATUS "\"make install\" will install facter.jar to ${RUBY_VENDORDIR} to support JRuby")
install(FILES ${CMAKE_BINARY_DIR}/lib/facter.jar DESTINATION ${RUBY_VENDORDIR})
diff --git a/lib/facter/personality.rb b/lib/facter/personality.rb
new file mode 100644
index 0000000..0a4e8cf
--- /dev/null
+++ b/lib/facter/personality.rb
@@ -0,0 +1,21 @@
+#
+# personality.rb
+#
+# This fact gives the personality of this node.
+#
+require 'facter/util/file_read'
+
+Facter.add('personality') do
+ confine :kernel => :linux
+
+ setcode do
+ if release = Facter::Util::FileRead.read('/etc/platform/platform.conf')
+ if match = release.match(/^nodetype\=(.*)/)
+ match[1]
+ end
+ end
+ end
+end
+
+# vim: set ts=2 sw=2 et :
+# encoding: utf-8
diff --git a/lib/facter/subfunction.rb b/lib/facter/subfunction.rb
new file mode 100644
index 0000000..589bcb3
--- /dev/null
+++ b/lib/facter/subfunction.rb
@@ -0,0 +1,61 @@
+#
+# subfunction.rb
+#
+# This fact gives the subfunction of this node.
+#
+require 'facter/util/file_read'
+
+Facter.add('subfunction') do
+ confine :kernel => :linux
+
+ setcode do
+ if release = Facter::Util::FileRead.read('/etc/platform/platform.conf')
+ if match = release.match(/^subfunction\=(.*)/)
+ match[1]
+ end
+ end
+ end
+end
+
+Facter.add('is_worker_subfunction') do
+ confine :kernel => :linux
+
+ setcode do
+ if release = Facter::Util::FileRead.read('/etc/platform/platform.conf')
+ match = release.match(/^subfunction\=.*worker/) ? true : false
+ end
+ end
+end
+
+Facter.add('is_controller_subfunction') do
+ confine :kernel => :linux
+
+ setcode do
+ if release = Facter::Util::FileRead.read('/etc/platform/platform.conf')
+ match = release.match(/^subfunction\=.*controller/) ? true : false
+ end
+ end
+end
+
+Facter.add('is_storage_subfunction') do
+ confine :kernel => :linux
+
+ setcode do
+ if release = Facter::Util::FileRead.read('/etc/platform/platform.conf')
+ match = release.match(/^subfunction\=.*storage/) ? true : false
+ end
+ end
+end
+
+Facter.add('is_lowlatency_subfunction') do
+ confine :kernel => :linux
+
+ setcode do
+ if release = Facter::Util::FileRead.read('/etc/platform/platform.conf')
+ match = release.match(/^subfunction\=.*lowlatency/) ? true : false
+ end
+ end
+end
+
+# vim: set ts=2 sw=2 et :
+# encoding: utf-8
diff --git a/lib/facter/util/file_read.rb b/lib/facter/util/file_read.rb
new file mode 100644
index 0000000..c92185a
--- /dev/null
+++ b/lib/facter/util/file_read.rb
@@ -0,0 +1,37 @@
+module Facter
+module Util
+
+# {Facter::Util::FileRead} is a utility module intended to provide easily
+# mockable methods that delegate to simple file read methods. The intent is to
+# avoid the need to execute the `cat` system command or `File.read` directly in
+# Ruby, as mocking these behaviors can have wide-ranging effects.
+#
+# All Facter facts are encouraged to use this method instead of File.read or
+# Facter::Core::Execution.exec('cat ...')
+#
+# @api public
+module FileRead
+ # read returns the raw content of a file as a string. If the file does not
+ # exist, or the process does not have permission to read the file then nil is
+ # returned.
+ #
+ # @api public
+ #
+ # @param path [String] the path to be read
+ #
+ # @return [String, nil] the raw contents of the file or `nil` if the
+ # file cannot be read because it does not exist or the process does not have
+ # permission to read the file.
+ def self.read(path)
+ File.read(path)
+ rescue Errno::ENOENT, Errno::EACCES => detail
+ Facter.debug "Could not read #{path}: #{detail.message}"
+ nil
+ end
+
+ def self.read_binary(path)
+ File.open(path, "rb") { |contents| contents.read }
+ end
+end
+end
+end
--
2.25.1