From 1014f789696b485506a8ccb39a92e8b6afb179d1 Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Wed, 14 Jun 2023 13:47:43 +0200 Subject: [PATCH 01/10] Fixes #36547 - Fix parsing of Ubuntu version in fact parsers --- app/models/operatingsystem.rb | 6 +++++- .../operating_system_parser.rb | 8 +++++++- app/services/foreman_chef/fact_parser.rb | 2 ++ app/services/katello/rhsm_fact_parser.rb | 8 +++++++- app/services/puppet_fact_parser.rb | 19 ++++++++++++++++--- .../20230719080900_fix_ubuntu_versions.rb | 13 +++++++++++++ 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20230719080900_fix_ubuntu_versions.rb diff --git a/app/models/operatingsystem.rb b/app/models/operatingsystem.rb index 0d97e87e290..9fa3f911e4b 100644 --- a/app/models/operatingsystem.rb +++ b/app/models/operatingsystem.rb @@ -170,7 +170,11 @@ def self.find_by_to_label(str) os = find_by_description(str.to_s) return os if os a = str.split(" ") - b = a[1].split('.') if a[1] + if a[0] =~ /ubuntu/i + b = a[1], nil if a[1] + else + b = a[1].split('.') if a[1] + end cond = {:name => a[0]} cond[:major] = b[0] if b && b[0] cond[:minor] = b[1] if b && b[1] diff --git a/app/services/foreman_ansible/operating_system_parser.rb b/app/services/foreman_ansible/operating_system_parser.rb index 529af5884d7..fc0acb062bc 100644 --- a/app/services/foreman_ansible/operating_system_parser.rb +++ b/app/services/foreman_ansible/operating_system_parser.rb @@ -55,6 +55,8 @@ def os_major (facts[:ansible_distribution_major_version][%r{\/sid}i] || facts[:ansible_distribution_major_version] == 'n/a') debian_os_major_sid + elsif os_name == 'Ubuntu' + facts[:ansible_distribution_major_version] else facts[:ansible_distribution_major_version] || facts[:ansible_lsb] && facts[:ansible_lsb]['major_release'] || @@ -68,8 +70,12 @@ def os_release end def os_minor - _, minor = os_release&.split('.', 2) || + if os_name == 'Ubuntu' + minor = nil + else + _, minor = os_release&.split('.', 2) || (facts[:version].split('R') if os_name == 'junos') + end # Until Foreman supports os.minor as something that's not a number, # we should remove the extra dots in the version. E.g: # '6.1.7601.65536' becomes '6.1.760165536' diff --git a/app/services/foreman_chef/fact_parser.rb b/app/services/foreman_chef/fact_parser.rb index b9a30e869c2..d370c86dc03 100644 --- a/app/services/foreman_chef/fact_parser.rb +++ b/app/services/foreman_chef/fact_parser.rb @@ -9,6 +9,8 @@ def operatingsystem # if we have no release information we can't assign OS properly (e.g. missing redhat-lsb) if release.nil? major, minor = 1, nil + elsif os_name == 'Ubuntu' + major, minor = release, nil else major, minor = release.split('.') end diff --git a/app/services/katello/rhsm_fact_parser.rb b/app/services/katello/rhsm_fact_parser.rb index 9ae57a25720..512797918b7 100644 --- a/app/services/katello/rhsm_fact_parser.rb +++ b/app/services/katello/rhsm_fact_parser.rb @@ -55,7 +55,13 @@ def operatingsystem return nil if name.nil? || version.nil? os_name = distribution_to_puppet_os(name) - major, minor = version.split('.') + version_splits = version.split('.') + if name =~ /ubuntu/i + major = "#{version_splits[0]}.#{version_splits[1]}" + minor = version_splits[2] if version_splits.length == 3 + else + major, minor = version_splits + end unless facts['ignore_os'] os_attributes = {:major => major, :minor => minor || '', :name => os_name} diff --git a/app/services/puppet_fact_parser.rb b/app/services/puppet_fact_parser.rb index b9fa40704ad..3a3a63bd675 100644 --- a/app/services/puppet_fact_parser.rb +++ b/app/services/puppet_fact_parser.rb @@ -5,9 +5,14 @@ def operatingsystem orel = os_release.dup if orel.present? - major, minor = orel.split('.', 2) - major = major.to_s.gsub(/\D/, '') - minor = minor.to_s.gsub(/[^\d\.]/, '') + if os_name =~ /ubuntu/i + major = os_major_version + minor = os_minor_version + else + major, minor = orel.split('.') + major = major.to_s.gsub(/\D/, '') + minor = minor.to_s.gsub(/[^\d\.]/, '') + end args = {:name => os_name, :major => major, :minor => minor} os = Operatingsystem.find_or_initialize_by(args) if os_name[/debian|ubuntu/i] || os.family == 'Debian' @@ -227,6 +232,14 @@ def os_name raise(::Foreman::Exception.new("invalid facts, missing operating system value")) end + def os_major_version + facts.dig(:os, :release, :major) + end + + def os_minor_version + facts.dig(:os, :release, :minor) + end + def os_release case os_name when /(windows)/i diff --git a/db/migrate/20230719080900_fix_ubuntu_versions.rb b/db/migrate/20230719080900_fix_ubuntu_versions.rb new file mode 100644 index 00000000000..f58a4a32cff --- /dev/null +++ b/db/migrate/20230719080900_fix_ubuntu_versions.rb @@ -0,0 +1,13 @@ +class FixUbuntuVersions < ActiveRecord::Migration[6.0] + def up + # For every Ubuntu operating system with a set minor version we + # * Check if there is already an operating system present with the same major and minor version combined in the major field + # * If not, we update the version + Operatingsystem.where('name ~* :name', name: 'ubuntu') + .merge(Operatingsystem.where.not(minor: [nil, ''])).each do |os| + if !Operatingsystem.where('name ~* :name', name: 'ubuntu').merge(Operatingsystem.where(major: "#{os.major}.#{os.minor}")).merge(Operatingsystem.where(minor: [nil, ''])).first + os.update(major: "#{os.major}.#{os.minor}", minor: nil) + end + end +end + From a6f1683db23ebd4d2d4b5ea1406b6b2f81e06ce9 Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Wed, 4 Oct 2023 11:55:52 +0200 Subject: [PATCH 02/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- app/services/katello/rhsm_fact_parser.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/services/katello/rhsm_fact_parser.rb b/app/services/katello/rhsm_fact_parser.rb index 512797918b7..dff37384aa4 100644 --- a/app/services/katello/rhsm_fact_parser.rb +++ b/app/services/katello/rhsm_fact_parser.rb @@ -55,12 +55,11 @@ def operatingsystem return nil if name.nil? || version.nil? os_name = distribution_to_puppet_os(name) - version_splits = version.split('.') - if name =~ /ubuntu/i - major = "#{version_splits[0]}.#{version_splits[1]}" - minor = version_splits[2] if version_splits.length == 3 + if os_name == 'Ubuntu' + x, y, minor = version.split('.', 3) + major = "#{x}.#{y}" else - major, minor = version_splits + major, minor = version.split('.', 2) end unless facts['ignore_os'] os_attributes = {:major => major, :minor => minor || '', :name => os_name} From 70a3d3898e34a3d3ec9958acd0ec31920e427561 Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Wed, 4 Oct 2023 12:05:40 +0200 Subject: [PATCH 03/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- app/models/operatingsystem.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/models/operatingsystem.rb b/app/models/operatingsystem.rb index 9fa3f911e4b..5fcd1304a66 100644 --- a/app/models/operatingsystem.rb +++ b/app/models/operatingsystem.rb @@ -170,8 +170,11 @@ def self.find_by_to_label(str) os = find_by_description(str.to_s) return os if os a = str.split(" ") - if a[0] =~ /ubuntu/i - b = a[1], nil if a[1] + if a[0] == 'Ubuntu' + if a[1] + x, y, minor = a[1].split('.', 3) + b = ["#{x}.#{y}", minor] + end else b = a[1].split('.') if a[1] end From cfbab69276851db146b55144bca118b5b50880ce Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Wed, 4 Oct 2023 12:08:27 +0200 Subject: [PATCH 04/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- app/services/foreman_ansible/operating_system_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/foreman_ansible/operating_system_parser.rb b/app/services/foreman_ansible/operating_system_parser.rb index fc0acb062bc..2431368c57c 100644 --- a/app/services/foreman_ansible/operating_system_parser.rb +++ b/app/services/foreman_ansible/operating_system_parser.rb @@ -71,7 +71,7 @@ def os_release def os_minor if os_name == 'Ubuntu' - minor = nil + _, _, minor = os_release&.split('.', 3) else _, minor = os_release&.split('.', 2) || (facts[:version].split('R') if os_name == 'junos') From ce5e657d114322aef55df60f211059234e9203fb Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Wed, 4 Oct 2023 13:38:42 +0200 Subject: [PATCH 05/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- db/migrate/20230719080900_fix_ubuntu_versions.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/db/migrate/20230719080900_fix_ubuntu_versions.rb b/db/migrate/20230719080900_fix_ubuntu_versions.rb index f58a4a32cff..786c0a9680b 100644 --- a/db/migrate/20230719080900_fix_ubuntu_versions.rb +++ b/db/migrate/20230719080900_fix_ubuntu_versions.rb @@ -3,11 +3,10 @@ def up # For every Ubuntu operating system with a set minor version we # * Check if there is already an operating system present with the same major and minor version combined in the major field # * If not, we update the version - Operatingsystem.where('name ~* :name', name: 'ubuntu') - .merge(Operatingsystem.where.not(minor: [nil, ''])).each do |os| - if !Operatingsystem.where('name ~* :name', name: 'ubuntu').merge(Operatingsystem.where(major: "#{os.major}.#{os.minor}")).merge(Operatingsystem.where(minor: [nil, ''])).first + Operatingsystem.where(name: 'Ubuntu').where.not(minor: [nil, '']).each do |os| + unless Operatingsystem.find_by(name: 'Ubuntu', major: "#{os.major}.#{os.minor}", minor: [nil, '']) os.update(major: "#{os.major}.#{os.minor}", minor: nil) end end + end end - From f9a7d1df1a5ddcde1b1d0b6faeb317ff3bf6ae27 Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Wed, 20 Dec 2023 12:16:52 +0100 Subject: [PATCH 06/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- app/services/puppet_fact_parser.rb | 2 +- .../puppet_ubuntu_22_04_3_facter_2.5.json | 117 +++++++++ .../puppet_ubuntu_22_04_3_facter_4.1.json | 231 ++++++++++++++++++ test/unit/puppet_fact_parser_test.rb | 22 ++ 4 files changed, 371 insertions(+), 1 deletion(-) create mode 100644 test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_2.5.json create mode 100644 test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_4.1.json diff --git a/app/services/puppet_fact_parser.rb b/app/services/puppet_fact_parser.rb index 3a3a63bd675..bfe69865148 100644 --- a/app/services/puppet_fact_parser.rb +++ b/app/services/puppet_fact_parser.rb @@ -9,7 +9,7 @@ def operatingsystem major = os_major_version minor = os_minor_version else - major, minor = orel.split('.') + major, minor = orel.split('.', 2) major = major.to_s.gsub(/\D/, '') minor = minor.to_s.gsub(/[^\d\.]/, '') end diff --git a/test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_2.5.json b/test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_2.5.json new file mode 100644 index 00000000000..b675cf72d5f --- /dev/null +++ b/test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_2.5.json @@ -0,0 +1,117 @@ +{ + "architecture": "x86_64", + "kernel": "Linux", + "blockdevice_vda_size": 7516192768, + "blockdevice_vda_vendor": "0x1af4", + "blockdevices": "vda", + "virtual": "kvm", + "is_virtual": true, + "hardwaremodel": "x86_64", + "operatingsystem": "Ubuntu", + "os": { + "name": "Ubuntu", + "family": "Debian", + "release": { + "major": "22.04", + "full": "22.04" + } + }, + "facterversion": "2.5.7", + "filesystems": "ext2,ext3,ext4,xfs", + "fqdn": "stream", + "gid": "root", + "hardwareisa": "x86_64", + "hostname": "stream", + "id": "root", + "interfaces": "", + "ipaddress": "192.168.122.29", + "kernelmajversion": "4.18", + "kernelrelease": "4.18.0-193.6.3.el8_2.x86_64", + "kernelversion": "4.18.0", + "bios_vendor": "SeaBIOS", + "bios_version": "1.14.0-1.fc33", + "bios_release_date": "04/01/2014", + "manufacturer": "QEMU", + "productname": "Standard PC (Q35 + ICH9, 2009)", + "serialnumber": "Not Specified", + "uuid": "1ddbeb7e-aea3-4ae3-8a57-61867d346372", + "type": "Other", + "memorysize": "1.78 GB", + "memoryfree": "1.44 GB", + "swapsize": "615.00 MB", + "swapfree": "609.23 MB", + "swapsize_mb": "615.00", + "swapfree_mb": "609.23", + "memorysize_mb": "1826.77", + "memoryfree_mb": "1477.75", + "operatingsystemmajrelease": "8", + "operatingsystemrelease": "8.3.2011", + "osfamily": "Debian", + "partitions": { + "vda4": { + "uuid": "4fd120e4-1f6d-46b3-a404-5569ef6af1f9", + "size": "11316608", + "mount": "/", + "label": "primary", + "filesystem": "xfs" + }, + "vda2": { + "uuid": "0b3df967-65cc-4a48-8b98-f7f0badc0d91", + "size": "2097152", + "mount": "/boot", + "label": "primary", + "filesystem": "ext4" + }, + "vda3": { + "uuid": "40f14688-2619-4046-a9eb-b7333fff1b84", + "size": "1259520", + "label": "primary", + "filesystem": "swap" + }, + "vda1": { + "size": "2048", + "label": "primary" + } + }, + "path": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin", + "physicalprocessorcount": 2, + "processors": { + "models": [ + "Intel Core Processor (Skylake, IBRS)", + "Intel Core Processor (Skylake, IBRS)" + ], + "count": 2, + "physicalcount": 2 + }, + "processor0": "Intel Core Processor (Skylake, IBRS)", + "processor1": "Intel Core Processor (Skylake, IBRS)", + "processorcount": 2, + "ps": "ps -ef", + "rubyplatform": "x86_64-linux", + "rubysitedir": "/usr/local/share/ruby/site_ruby", + "rubyversion": "2.7.1", + "selinux": true, + "selinux_enforced": true, + "selinux_policyversion": "31", + "selinux_current_mode": "enforcing", + "selinux_config_mode": "enforcing", + "selinux_config_policy": "targeted", + "sshrsakey": "AAAAB3NzaC1yc2EAAAADAQABAAABgQDSOlxRR5iy0VM5BVl2JiFvUvv5UMAUMPkNxKuo89U/jG1X3N9pqxSpgwy4VnzAJTMXTUObCnSTueiVjj0HHz6UMuRxIe4MYb2XFNrdQUV3BPKvbP3NG02bBGRhH35mr0g9Yd9Rc1Ayf5gTlfGkbOh4JbjPygQ9ub/5gUnEbFOS4x39U3wnZV4z/1s0RwWtzdLe8kj36/gvoYaBdrsDNtFQjEGWSHhjiwXf0wOvOVt+OKY77Z1+pM6CcqQVR75VcT52P/y5UEIREo7CP0eHxjD5JAcm7fWJrxeHFH3Cv1dh9I/J9b5k3WGFciqsv5zebx4MMq64poKbmyFyR+R1ixKM9laoaUiTC5N3ajM54kSb5wREIiMMFpPo7ArfXnIbjOsHidnmXvMfOwTLwwymBoKsWNR2LIf3u/mBOdBC2PtrYz9nL6pi5Lb2OOpa0S+LQFxWulFPWvTN83Mqlcr8qScJqPfgwlM6pIco6blJwe078N5ldXdeaj54I0RQ4XYChhE=", + "sshfp_rsa": "SSHFP 1 1 0f2ab3941f9c7a54211076bc27dee370e10698b0\nSSHFP 1 2 c45674d9bc1091ac4cc9150fd517b0b895650fa590e41e288cc07f2699dfb9e1", + "sshecdsakey": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEBFrxBiebSB+0M1LGyX3H3ZHd676wnGGfYjexjSvopznvfkb0PdNSLUvHpc1gU/yPBx7HP/pdGvdDWnwvoNkLY=", + "sshfp_ecdsa": "SSHFP 3 1 1896eda9c97def529c64f97ebcdb5aee32e25285\nSSHFP 3 2 6932a390ad20961350b2ab36861b18ec2ce2644d433bc54f432600421f58bcd1", + "sshed25519key": "AAAAC3NzaC1lZDI1NTE5AAAAIFu6kGHnNmCA56gkfRAyAxZZEdwF5mCD6aRb0PznE++s", + "sshfp_ed25519": "SSHFP 4 1 43113e7fca870374e8a5f9981e4bf6f97a7bc59a\nSSHFP 4 2 d17bfb375bc87e76dcc937708974cd3f7a361843625f67c485426ad4c9bf441f", + "system_uptime": { + "seconds": 1311, + "hours": 0, + "days": 0, + "uptime": "0:21 hours" + }, + "timezone": "EDT", + "uniqueid": "a8c01d7a", + "uptime": "0:21 hours", + "uptime_days": 0, + "uptime_hours": 0, + "uptime_seconds": 1311 +} diff --git a/test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_4.1.json b/test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_4.1.json new file mode 100644 index 00000000000..88529b9c92c --- /dev/null +++ b/test/static_fixtures/facts/puppet_ubuntu_22_04_3_facter_4.1.json @@ -0,0 +1,231 @@ +{ + "disks": { + "vda": { + "size": "7.00 GiB", + "size_bytes": 7516192768, + "type": "hdd", + "vendor": "0x1af4" + } + }, + "dmi": { + "bios": { + "release_date": "04/01/2014", + "vendor": "SeaBIOS", + "version": "1.14.0-1.fc33" + }, + "chassis": { + "type": "Other" + }, + "manufacturer": "QEMU", + "product": { + "name": "Standard PC (Q35 + ICH9, 2009)", + "uuid": "1ddbeb7e-aea3-4ae3-8a57-61867d346372" + } + }, + "facterversion": "4.1.0", + "filesystems": "ext2,ext3,ext4,xfs", + "fips_enabled": false, + "hypervisors": { + "kvm": { + } + }, + "identity": { + "gid": 0, + "group": "root", + "privileged": true, + "uid": 0, + "user": "root" + }, + "is_virtual": true, + "kernel": "Linux", + "kernelmajversion": "4.18", + "kernelrelease": "4.18.0-193.6.3.el8_2.x86_64", + "kernelversion": "4.18.0", + "load_averages": { + "15m": 0.31, + "1m": 0.2, + "5m": 0.36 + }, + "memory": { + "swap": { + "available": "609.23 MiB", + "available_bytes": 638828544, + "capacity": "0.94%", + "total": "615.00 MiB", + "total_bytes": 644870144, + "used": "5.76 MiB", + "used_bytes": 6041600 + }, + "system": { + "available": "1.33 GiB", + "available_bytes": 1428824064, + "capacity": "25.41%", + "total": "1.78 GiB", + "total_bytes": 1915502592, + "used": "464.13 MiB", + "used_bytes": 486678528 + } + }, + "networking": { + "fqdn": "stream", + "hostname": "stream", + "interfaces": { + "enp1s0": { + "bindings": [ + { + "address": "192.168.122.29", + "netmask": "255.255.255.0", + "network": "192.168.122.0" + } + ], + "bindings6": [ + { + "address": "fe80::5054:ff:fe85:821", + "netmask": "ffff:ffff:ffff:ffff::", + "network": "fe80::", + "scope6": "link" + } + ], + "ip": "192.168.122.29", + "ip6": "fe80::5054:ff:fe85:821", + "mac": "52:54:00:85:08:21", + "mtu": 1500, + "netmask": "255.255.255.0", + "netmask6": "ffff:ffff:ffff:ffff::", + "network": "192.168.122.0", + "network6": "fe80::", + "scope6": "link" + }, + "lo": { + "bindings": [ + { + "address": "127.0.0.1", + "netmask": "255.0.0.0", + "network": "127.0.0.0" + } + ], + "bindings6": [ + { + "address": "::1", + "netmask": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", + "network": "::1", + "scope6": "host" + } + ], + "ip": "127.0.0.1", + "ip6": "::1", + "mtu": 65536, + "netmask": "255.0.0.0", + "netmask6": "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff", + "network": "127.0.0.0", + "network6": "::1", + "scope6": "host" + } + }, + "ip": "192.168.122.29", + "ip6": "fe80::5054:ff:fe85:821", + "mac": "52:54:00:85:08:21", + "mtu": 1500, + "netmask": "255.255.255.0", + "netmask6": "ffff:ffff:ffff:ffff::", + "network": "192.168.122.0", + "network6": "fe80::", + "primary": "enp1s0", + "scope6": "link" + }, + "os": { + "architecture": "amd64", + "family": "Debian", + "hardware": "x86_64", + "name": "Ubuntu", + "release": { + "full": "22.04", + "major": "22.04" + }, + "selinux": { + "enabled": false + } + }, + "partitions": { + "/dev/vda1": { + "partlabel": "primary", + "partuuid": "d4ceee7d-f2a8-41cc-9a1f-941b15f6d988", + "size": "1.00 MiB", + "size_bytes": 1048576 + }, + "/dev/vda2": { + "filesystem": "ext4", + "partlabel": "primary", + "partuuid": "268627c0-d337-45e0-8b78-3b4516743e37", + "size": "1.00 GiB", + "size_bytes": 1073741824, + "uuid": "0b3df967-65cc-4a48-8b98-f7f0badc0d91" + }, + "/dev/vda3": { + "filesystem": "swap", + "partlabel": "primary", + "partuuid": "c30f23cb-3504-4020-81b6-1da9d9413a5b", + "size": "615.00 MiB", + "size_bytes": 644874240, + "uuid": "40f14688-2619-4046-a9eb-b7333fff1b84" + }, + "/dev/vda4": { + "filesystem": "xfs", + "partlabel": "primary", + "partuuid": "81a2926c-2b51-4bc8-8ba9-f0af2a91fe85", + "size": "5.40 GiB", + "size_bytes": 5794103296, + "uuid": "4fd120e4-1f6d-46b3-a404-5569ef6af1f9" + } + }, + "path": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin", + "processors": { + "count": 2, + "isa": "x86_64", + "models": [ + "Intel Core Processor (Skylake, IBRS)", + "Intel Core Processor (Skylake, IBRS)" + ], + "physicalcount": 2, + "speed": "3.00 GHz" + }, + "ruby": { + "platform": "x86_64-linux", + "sitedir": "/usr/local/share/ruby/site_ruby", + "version": "2.7.1" + }, + "ssh": { + "ecdsa": { + "fingerprints": { + "sha1": "SSHFP 3 1 1896eda9c97def529c64f97ebcdb5aee32e25285", + "sha256": "SSHFP 3 2 6932a390ad20961350b2ab36861b18ec2ce2644d433bc54f432600421f58bcd1" + }, + "key": "AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBEBFrxBiebSB+0M1LGyX3H3ZHd676wnGGfYjexjSvopznvfkb0PdNSLUvHpc1gU/yPBx7HP/pdGvdDWnwvoNkLY=", + "type": "ecdsa-sha2-nistp256" + }, + "ed25519": { + "fingerprints": { + "sha1": "SSHFP 4 1 43113e7fca870374e8a5f9981e4bf6f97a7bc59a", + "sha256": "SSHFP 4 2 d17bfb375bc87e76dcc937708974cd3f7a361843625f67c485426ad4c9bf441f" + }, + "key": "AAAAC3NzaC1lZDI1NTE5AAAAIFu6kGHnNmCA56gkfRAyAxZZEdwF5mCD6aRb0PznE++s", + "type": "ssh-ed25519" + }, + "rsa": { + "fingerprints": { + "sha1": "SSHFP 1 1 0f2ab3941f9c7a54211076bc27dee370e10698b0", + "sha256": "SSHFP 1 2 c45674d9bc1091ac4cc9150fd517b0b895650fa590e41e288cc07f2699dfb9e1" + }, + "key": "AAAAB3NzaC1yc2EAAAADAQABAAABgQDSOlxRR5iy0VM5BVl2JiFvUvv5UMAUMPkNxKuo89U/jG1X3N9pqxSpgwy4VnzAJTMXTUObCnSTueiVjj0HHz6UMuRxIe4MYb2XFNrdQUV3BPKvbP3NG02bBGRhH35mr0g9Yd9Rc1Ayf5gTlfGkbOh4JbjPygQ9ub/5gUnEbFOS4x39U3wnZV4z/1s0RwWtzdLe8kj36/gvoYaBdrsDNtFQjEGWSHhjiwXf0wOvOVt+OKY77Z1+pM6CcqQVR75VcT52P/y5UEIREo7CP0eHxjD5JAcm7fWJrxeHFH3Cv1dh9I/J9b5k3WGFciqsv5zebx4MMq64poKbmyFyR+R1ixKM9laoaUiTC5N3ajM54kSb5wREIiMMFpPo7ArfXnIbjOsHidnmXvMfOwTLwwymBoKsWNR2LIf3u/mBOdBC2PtrYz9nL6pi5Lb2OOpa0S+LQFxWulFPWvTN83Mqlcr8qScJqPfgwlM6pIco6blJwe078N5ldXdeaj54I0RQ4XYChhE=", + "type": "ssh-rsa" + } + }, + "system_uptime": { + "days": 0, + "hours": 0, + "seconds": 679, + "uptime": "0:11 hours" + }, + "timezone": "EDT", + "virtual": "kvm" +} diff --git a/test/unit/puppet_fact_parser_test.rb b/test/unit/puppet_fact_parser_test.rb index 939b64d2ec9..3abee2fc0c3 100644 --- a/test/unit/puppet_fact_parser_test.rb +++ b/test/unit/puppet_fact_parser_test.rb @@ -236,6 +236,20 @@ def setup assert_equal '8', os.major assert_equal '3.2011', os.minor end + + test "should correctly identify Ubuntu 22.04.3 by facter 2.5" do + parser = PuppetFactParser.new(ubuntu_22_04_3_facts_facter_2) + os = parser.operatingsystem + assert_equal 'Ubuntu', os.name + assert_equal '22.04', os.major + end + + test "should correctly identify Ubuntu 22.04.3 by facter 4.1" do + parser = PuppetFactParser.new(ubuntu_22_04_3_facts_facter_4) + os = parser.operatingsystem + assert_equal 'Ubuntu', os.name + assert_equal '22.04', os.major + end end describe "#facterversion" do @@ -870,6 +884,14 @@ def centos_8_facts_facter_4 read_json_fixture('facts/puppet_centos_8_facter_4.1.json') end + def ubuntu_22_04_3_facts_facter_2 + read_json_fixture('facts/puppet_ubuntu_22_04_3_facter_2.5.json') + end + + def ubuntu_22_04_3_facts_facter_4 + read_json_fixture('facts/puppet_ubuntu_22_04_3_facter_4.1.json') + end + def debian_facts read_json_fixture('facts/facts_debian.json')['facts'] end From 143637a41378a10a53d131226b96a4ea0c7f2ed6 Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Tue, 19 Dec 2023 11:59:48 +0100 Subject: [PATCH 07/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- db/migrate/20230719080900_fix_ubuntu_versions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/db/migrate/20230719080900_fix_ubuntu_versions.rb b/db/migrate/20230719080900_fix_ubuntu_versions.rb index 786c0a9680b..1a3c0fcc8dd 100644 --- a/db/migrate/20230719080900_fix_ubuntu_versions.rb +++ b/db/migrate/20230719080900_fix_ubuntu_versions.rb @@ -3,7 +3,7 @@ def up # For every Ubuntu operating system with a set minor version we # * Check if there is already an operating system present with the same major and minor version combined in the major field # * If not, we update the version - Operatingsystem.where(name: 'Ubuntu').where.not(minor: [nil, '']).each do |os| + Operatingsystem.where(name: 'Ubuntu').where('major ~* ?', '^\d*$').where.not(minor: [nil, '']).each do |os| unless Operatingsystem.find_by(name: 'Ubuntu', major: "#{os.major}.#{os.minor}", minor: [nil, '']) os.update(major: "#{os.major}.#{os.minor}", minor: nil) end From d314942f17235274bee07ac1e98a5c8384671faa Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Tue, 19 Dec 2023 14:42:01 +0100 Subject: [PATCH 08/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- db/migrate/20230719080900_fix_ubuntu_versions.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/db/migrate/20230719080900_fix_ubuntu_versions.rb b/db/migrate/20230719080900_fix_ubuntu_versions.rb index 1a3c0fcc8dd..a98691b7e80 100644 --- a/db/migrate/20230719080900_fix_ubuntu_versions.rb +++ b/db/migrate/20230719080900_fix_ubuntu_versions.rb @@ -3,10 +3,11 @@ def up # For every Ubuntu operating system with a set minor version we # * Check if there is already an operating system present with the same major and minor version combined in the major field # * If not, we update the version - Operatingsystem.where(name: 'Ubuntu').where('major ~* ?', '^\d*$').where.not(minor: [nil, '']).each do |os| - unless Operatingsystem.find_by(name: 'Ubuntu', major: "#{os.major}.#{os.minor}", minor: [nil, '']) - os.update(major: "#{os.major}.#{os.minor}", minor: nil) - end - end + Operatingsystem.where(name: 'Ubuntu') + .where('operatingsystems.major ~* ?', '^\d*$') + .where.not(minor: [nil, '']) + .where('o3.id IS NULL') + .joins("left outer join operatingsystems o3 on o3.major like concat(operatingsystems.major, '.', operatingsystems.minor)") + .update_all('major = concat(operatingsystems.major, \'.\', operatingsystems.minor), minor = \'\'') end end From 5f0cdeff7247ea43dec9fbfb2350fd22236b9d0c Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Tue, 5 Dec 2023 13:51:28 +0100 Subject: [PATCH 09/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- app/models/operatingsystem.rb | 25 +++++++++++-------- .../controllers/unattended_controller_test.rb | 12 ++++----- test/fixtures/operatingsystems.yml | 20 +++++++++++---- test/fixtures/os_default_templates.yml | 6 ++--- test/fixtures/templates.yml | 6 ++--- test/models/operatingsystem_test.rb | 20 ++++++++++++--- 6 files changed, 58 insertions(+), 31 deletions(-) diff --git a/app/models/operatingsystem.rb b/app/models/operatingsystem.rb index 5fcd1304a66..6787c7945e5 100644 --- a/app/models/operatingsystem.rb +++ b/app/models/operatingsystem.rb @@ -169,18 +169,23 @@ def to_s def self.find_by_to_label(str) os = find_by_description(str.to_s) return os if os - a = str.split(" ") - if a[0] == 'Ubuntu' - if a[1] - x, y, minor = a[1].split('.', 3) - b = ["#{x}.#{y}", minor] + + name, version = str.split(" ") + + cond = {:name => name} + + if version + if name == 'Ubuntu' + x, y, minor = version.split('.', 3) + major = "#{x}.#{y}" + else + major, minor = version.split('.') end - else - b = a[1].split('.') if a[1] + + cond[:major] = major if major + cond[:minor] = minor if minor end - cond = {:name => a[0]} - cond[:major] = b[0] if b && b[0] - cond[:minor] = b[1] if b && b[1] + find_by(cond) end diff --git a/test/controllers/unattended_controller_test.rb b/test/controllers/unattended_controller_test.rb index 077e8e9731c..e42489eb546 100644 --- a/test/controllers/unattended_controller_test.rb +++ b/test/controllers/unattended_controller_test.rb @@ -253,13 +253,13 @@ class UnattendedControllerTest < ActionController::TestCase test "should get a kickstart if MAC is provided with two hosts with same MAC" do ptable_ubuntu = FactoryBot.create(:ptable, :ubuntu, :name => 'ubuntu default', :layout => 'd-i partman-auto/disk string /dev/sda\nd-i partman-auto/method string regular...', - :operatingsystem_ids => [operatingsystems(:ubuntu1010).id]) + :operatingsystem_ids => [operatingsystems(:ubuntu2204).id]) # explicitly create host1 with tomorrow's created_at so it's guaranteed to be newer than rh_host host1 = FactoryBot.create(:host, :managed, :with_dhcp_orchestration, :build => true, :name => "host2_same_mac", :created_at => Time.now.tomorrow, :mac => @rh_host.mac, - :operatingsystem => operatingsystems(:ubuntu1010), + :operatingsystem => operatingsystems(:ubuntu2204), :ptable => ptable_ubuntu, :medium => media(:ubuntu), :architecture => architectures(:x86_64), @@ -279,9 +279,9 @@ class UnattendedControllerTest < ActionController::TestCase setup do ptable_ubuntu = FactoryBot.create(:ptable, :ubuntu, :name => 'ubuntu default', :layout => 'd-i partman-auto/disk string /dev/sda\nd-i partman-auto/method string regular...', - :operatingsystem_ids => [operatingsystems(:ubuntu1010).id]) + :operatingsystem_ids => [operatingsystems(:ubuntu2204).id]) @ub_host = FactoryBot.create(:host, :managed, :with_dhcp_orchestration, :build => true, - :operatingsystem => operatingsystems(:ubuntu1010), + :operatingsystem => operatingsystems(:ubuntu2204), :ptable => ptable_ubuntu, :medium => media(:ubuntu), :architecture => architectures(:x86_64), @@ -525,9 +525,9 @@ class UnattendedControllerTest < ActionController::TestCase setup do ptable_ubuntu = FactoryBot.create(:ptable, :ubuntu, :name => 'ubuntu default', :layout => 'd-i partman-auto/disk string /dev/sda\nd-i partman-auto/method string regular...', - :operatingsystem_ids => [operatingsystems(:ubuntu1010).id]) + :operatingsystem_ids => [operatingsystems(:ubuntu2204).id]) @host_with_template_subnet = FactoryBot.create(:host, :managed, :with_dhcp_orchestration, :with_templates_subnet, :build => true, - :operatingsystem => operatingsystems(:ubuntu1010), + :operatingsystem => operatingsystems(:ubuntu2204), :ptable => ptable_ubuntu, :medium => media(:ubuntu), :architecture => architectures(:x86_64) diff --git a/test/fixtures/operatingsystems.yml b/test/fixtures/operatingsystems.yml index 6fac9ba24a9..1ca20d2293f 100644 --- a/test/fixtures/operatingsystems.yml +++ b/test/fixtures/operatingsystems.yml @@ -18,15 +18,25 @@ redhat: media: one title: 'RHEL 6.1' -ubuntu1010: +debian12: + name: Debian + major: 12 + minor: '' + release_name: rn12 + type: Debian + media: debian + architectures: x86_64 + title: 'Debian 12' + +ubuntu2204: name: Ubuntu - major: 10 - minor: 10 - release_name: rn10 + major: 22.04 + minor: 3 + release_name: rn22_04 type: Debian media: ubuntu architectures: x86_64 - title: 'Ubuntu 10.10' + title: 'Ubuntu 22.04.3' ubuntu1210: name: Ubuntu diff --git a/test/fixtures/os_default_templates.yml b/test/fixtures/os_default_templates.yml index 27d8ae8d191..685b12c7d64 100644 --- a/test/fixtures/os_default_templates.yml +++ b/test/fixtures/os_default_templates.yml @@ -32,17 +32,17 @@ six: seven: provisioning_template: mystring2 template_kind: provision - operatingsystem: ubuntu1010 + operatingsystem: ubuntu2204 eight: provisioning_template: pxekickstart template_kind: PXELinux - operatingsystem: ubuntu1010 + operatingsystem: ubuntu2204 nine: provisioning_template: myfinish template_kind: finish - operatingsystem: ubuntu1010 + operatingsystem: ubuntu2204 ten: provisioning_template: pxeautoyast diff --git a/test/fixtures/templates.yml b/test/fixtures/templates.yml index 96103a95b46..976d467830d 100644 --- a/test/fixtures/templates.yml +++ b/test/fixtures/templates.yml @@ -19,7 +19,7 @@ mystring2: name: MyString2 template: provision script <%%= foreman_url("finish") %> static:<%%= @static.inspect %> template_kind: provision - operatingsystems: centos5_3, redhat, ubuntu1010 + operatingsystems: centos5_3, redhat, ubuntu2204 locked: false type: ProvisioningTemplate @@ -27,7 +27,7 @@ myfinish: name: MyFinish template: finish for <%%= @host.name %> template_kind: finish - operatingsystems: centos5_3, redhat, ubuntu1010 + operatingsystems: centos5_3, redhat, ubuntu2204 locked: false type: ProvisioningTemplate @@ -35,7 +35,7 @@ pxekickstart: name: centos5_3_pxelinux template: default linux~label linux~kernel <%%= @kernel %>~append initrd=<%%= @initrd %> ks=<%%= foreman_url("kickstart")%> ksdevice=bootif network kssendmac template_kind: pxelinux - operatingsystems: centos5_3, redhat, ubuntu1010 + operatingsystems: centos5_3, redhat, ubuntu2204 locked: false type: ProvisioningTemplate diff --git a/test/models/operatingsystem_test.rb b/test/models/operatingsystem_test.rb index 0a08f3ff838..47f399186cd 100644 --- a/test/models/operatingsystem_test.rb +++ b/test/models/operatingsystem_test.rb @@ -56,6 +56,18 @@ class OperatingsystemTest < ActiveSupport::TestCase assert operating_system.to_s == operating_system.to_label end + test "should find Debian by fullname string" do + str = "Debian 12" + os = Operatingsystem.find_by_to_label(str) + assert_equal str, os.fullname + end + + test "should find Ubuntu by fullname string" do + str = "Ubuntu 22.04.3" + os = Operatingsystem.find_by_to_label(str) + assert_equal str, os.fullname + end + test "should find by fullname string" do str = "Redhat 6.1" os = Operatingsystem.find_by_to_label(str) @@ -91,19 +103,19 @@ class OperatingsystemTest < ActiveSupport::TestCase test "should add os association by passing os labels (description or fullname) of operatingsystems" do medium = media(:one) - medium.operatingsystem_names = ["centos 5.3", "RHEL 6.1", "Ubuntu 10.10"] + medium.operatingsystem_names = ["centos 5.3", "RHEL 6.1", "Ubuntu 22.04.3"] assert_equal 3, medium.operatingsystem_ids.count assert_equal 3, medium.operatingsystem_names.count - assert_equal ["RHEL 6.1", "Ubuntu 10.10", "centos 5.3"], medium.operatingsystem_names.sort + assert_equal ["RHEL 6.1", "Ubuntu 22.04.3", "centos 5.3"], medium.operatingsystem_names.sort end test "should add os association by passing os fullname even if description exists" do medium = media(:one) # pass Redhat 6.1 rather than RHEL 6.1 - medium.operatingsystem_names = ["centos 5.3", "Redhat 6.1", "Ubuntu 10.10"] + medium.operatingsystem_names = ["centos 5.3", "Redhat 6.1", "Ubuntu 22.04.3"] assert_equal 3, medium.operatingsystem_ids.count assert_equal 3, medium.operatingsystem_names.count - assert_equal ["RHEL 6.1", "Ubuntu 10.10", "centos 5.3"], medium.operatingsystem_names.sort + assert_equal ["RHEL 6.1", "Ubuntu 22.04.3", "centos 5.3"], medium.operatingsystem_names.sort end test "should delete os associations by passing os labels (description or fullname) of operatingsystems" do From 5d5acd962b54283f1014a57ebce1b7091c2d11de Mon Sep 17 00:00:00 2001 From: Markus Reisner Date: Wed, 3 Jan 2024 09:43:27 +0100 Subject: [PATCH 10/10] Refs #36547 - Fix parsing of Ubuntu version in fact parsers --- test/unit/katello/rhsm_fact_parser_test.rb | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/test/unit/katello/rhsm_fact_parser_test.rb b/test/unit/katello/rhsm_fact_parser_test.rb index d3bfa304b12..2cf08502cfe 100644 --- a/test/unit/katello/rhsm_fact_parser_test.rb +++ b/test/unit/katello/rhsm_fact_parser_test.rb @@ -127,14 +127,26 @@ def test_operatingsystem_debian def test_operatingsystem_ubuntu @facts['distribution.name'] = 'Ubuntu GNU/Linux' - @facts['distribution.version'] = '19.04' - @facts['distribution.id'] = 'Disco Dingo' + @facts['distribution.version'] = '22.04' + @facts['distribution.id'] = 'Jammy Jellyfish' - assert_equal parser.operatingsystem.release_name, 'disco' + assert_equal parser.operatingsystem.release_name, 'jammy' assert_equal parser.operatingsystem.name, 'Ubuntu' assert_equal parser.operatingsystem.type, 'Debian' - assert_equal parser.operatingsystem.major, '19' - assert_equal parser.operatingsystem.minor, '04' + assert_equal parser.operatingsystem.major, '22.04' + assert_equal parser.operatingsystem.minor, '' + end + + def test_operatingsystem_ubuntu_with_minor + @facts['distribution.name'] = 'Ubuntu GNU/Linux' + @facts['distribution.version'] = '22.04.3' + @facts['distribution.id'] = 'Jammy Jellyfish' + + assert_equal parser.operatingsystem.release_name, 'jammy' + assert_equal parser.operatingsystem.name, 'Ubuntu' + assert_equal parser.operatingsystem.type, 'Debian' + assert_equal parser.operatingsystem.major, '22.04' + assert_equal parser.operatingsystem.minor, '3' end def test_operatingsystem_release