From d9063d6e7c8844e3361b06fe8e1b3a2d5c733a28 Mon Sep 17 00:00:00 2001 From: TenSt Date: Mon, 23 Feb 2026 12:38:46 +0100 Subject: [PATCH 1/9] RHINENG-21444: update getSystemTags function --- evaluator/notifications.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/evaluator/notifications.go b/evaluator/notifications.go index 5c66cc57c..62add90c6 100644 --- a/evaluator/notifications.go +++ b/evaluator/notifications.go @@ -71,11 +71,10 @@ func getSystemTags(tx *gorm.DB, system *models.SystemPlatform) ([]ntf.SystemTag, var tags []ntf.SystemTag var tagsJSON string - err := tx.Table("system_platform sp"). - Select("ih.tags"). - Joins("JOIN inventory.hosts ih ON sp.inventory_id = ih.id"). - Where("sp.rh_account_id = ?", system.RhAccountID). - Where("sp.id = ?", system.ID). + err := tx.Table("system_inventory"). + Select("tags"). + Where("rh_account_id = ?", system.RhAccountID). + Where("id = ?", system.ID). Scan(&tagsJSON).Error if err != nil { return nil, errors.Wrap(err, "system tags query failed") From c9bac41be5140ee004ff3663113c8f4722b7826a Mon Sep 17 00:00:00 2001 From: TenSt Date: Mon, 23 Feb 2026 13:44:36 +0100 Subject: [PATCH 2/9] RHINENG-21444: update system profile OwnerID field --- base/inventory/inventory.go | 4 +++- base/models/models.go | 3 ++- listener/upload.go | 4 ++-- listener/upload_test.go | 7 ++++++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/base/inventory/inventory.go b/base/inventory/inventory.go index cab6e49e5..fe19eecb1 100644 --- a/base/inventory/inventory.go +++ b/base/inventory/inventory.go @@ -2,6 +2,8 @@ package inventory import ( "app/base/types" + + "github.com/google/uuid" ) type SystemProfile struct { @@ -15,7 +17,7 @@ type SystemProfile struct { Releasever *string `json:"releasever,omitempty"` SatelliteManaged bool `json:"satellite_managed,omitempty"` BootcStatus Bootc `json:"bootc_status,omitempty"` - ConsumerID string `json:"owner_id,omitempty"` + OwnerID uuid.UUID `json:"owner_id,omitempty"` Workloads Workloads `json:"workloads,omitempty"` } diff --git a/base/models/models.go b/base/models/models.go index 8a3eb087f..f6ee00390 100644 --- a/base/models/models.go +++ b/base/models/models.go @@ -3,6 +3,7 @@ package models import ( "time" + "github.com/google/uuid" "github.com/lib/pq" ) @@ -126,7 +127,7 @@ type SystemInventory struct { OSMajor *int16 OSMinor *int16 RhsmVersion *string - SubscriptionManagerID *string + SubscriptionManagerID *uuid.UUID SapWorkload bool SapWorkloadSIDs pq.StringArray `gorm:"type:text[];column:sap_workload_sids"` AnsibleWorkload bool diff --git a/listener/upload.go b/listener/upload.go index 3c0e3b614..44bb5fd50 100644 --- a/listener/upload.go +++ b/listener/upload.go @@ -282,7 +282,7 @@ func hostTemplate(tx *gorm.DB, accountID int, host *Host) *int64 { if hasTemplateRepo(&host.SystemProfile) { // check system's env in candlepin - resp, err := callCandlepinEnvironment(base.Context, host.SystemProfile.ConsumerID) + resp, err := callCandlepinEnvironment(base.Context, host.SystemProfile.OwnerID.String()) if err != nil { utils.LogWarn("inventoryID", host.ID, "err", errors.Wrap(err, "Unable to assign templates")) } @@ -459,7 +459,7 @@ func storeOrUpdateSysPlatform( OSMajor: &host.SystemProfile.OperatingSystem.Major, OSMinor: &host.SystemProfile.OperatingSystem.Minor, RhsmVersion: utils.EmptyToNil(&host.SystemProfile.Rhsm.Version), - SubscriptionManagerID: utils.EmptyToNil(&host.SystemProfile.ConsumerID), + SubscriptionManagerID: &host.SystemProfile.OwnerID, SapWorkload: host.SystemProfile.Workloads.Sap.SapSystem, SapWorkloadSIDs: pq.StringArray(host.SystemProfile.Workloads.Sap.Sids), AnsibleWorkload: host.SystemProfile.Workloads.Ansible.ControllerVersion != "", diff --git a/listener/upload_test.go b/listener/upload_test.go index bcda063eb..c91b85af1 100644 --- a/listener/upload_test.go +++ b/listener/upload_test.go @@ -18,6 +18,7 @@ import ( "testing" "time" + "github.com/google/uuid" "github.com/lib/pq" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" @@ -57,11 +58,15 @@ func createTestInvHost(t *testing.T) *Host { } func createTestHostWithEnv(reporter, consumer, baseURL string) *Host { + consumerUUID, err := uuid.Parse(consumer) + if err != nil { + consumerUUID = uuid.Nil + } return &Host{ ID: id, Reporter: reporter, SystemProfile: inventory.SystemProfile{ - ConsumerID: consumer, + OwnerID: consumerUUID, YumRepos: &[]inventory.YumRepo{{ ID: "base", Enabled: true, From 3dbf50f78c028385d79b8d089cdfc82fdb656257 Mon Sep 17 00:00:00 2001 From: TenSt Date: Mon, 23 Feb 2026 13:44:57 +0100 Subject: [PATCH 3/9] RHINENG-21444: update getSubscribedSystem function --- manager/controllers/template_subscribed_systems_update.go | 7 +++---- .../controllers/template_subscribed_systems_update_test.go | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/manager/controllers/template_subscribed_systems_update.go b/manager/controllers/template_subscribed_systems_update.go index 4830da0b4..5657ed8da 100644 --- a/manager/controllers/template_subscribed_systems_update.go +++ b/manager/controllers/template_subscribed_systems_update.go @@ -69,10 +69,9 @@ func getSubscribedSystem(c *gin.Context, tx *gorm.DB) (int, string, error) { systemCn := c.GetString(utils.KeySystem) var inventoryID string - err := tx.Select("ih.id as inventory_id"). - Table("inventory.hosts ih"). - Joins("JOIN rh_account acc on ih.org_id = acc.org_id"). - Where("ih.system_profile->>'owner_id' = ? AND acc.id = ?", systemCn, account). + err := tx.Select("inventory_id"). + Table("system_inventory"). + Where("subscription_manager_id = ? AND rh_account_id = ?", systemCn, account). Limit(1).Find(&inventoryID).Error if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) { utils.LogAndRespError(c, err, "database error") diff --git a/manager/controllers/template_subscribed_systems_update_test.go b/manager/controllers/template_subscribed_systems_update_test.go index 6a1c2ddf8..14a207df3 100644 --- a/manager/controllers/template_subscribed_systems_update_test.go +++ b/manager/controllers/template_subscribed_systems_update_test.go @@ -35,10 +35,10 @@ func TestUnknownSubscribedSystemID(t *testing.T) { c, _ := gin.CreateTestContext(httptest.NewRecorder()) c.Set(utils.KeyAccount, templateAccount) - c.Set(utils.KeySystem, "unknown-uuid") + c.Set(utils.KeySystem, "cccccccc-0000-0000-0001-000000000001") account, systemID, err := getSubscribedSystem(c, database.DB) - assert.EqualError(t, err, "System unknown-uuid not found") + assert.EqualError(t, err, "System cccccccc-0000-0000-0001-000000000001 not found") assert.Equal(t, 0, account) assert.Equal(t, "", systemID) } From c452b1c40e5f4a9b5985834aac62a3261ba57a9b Mon Sep 17 00:00:00 2001 From: TenSt Date: Mon, 23 Feb 2026 13:53:05 +0100 Subject: [PATCH 4/9] RHINENG-21444: update getCounts func --- tasks/caches/refresh_packages_caches.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasks/caches/refresh_packages_caches.go b/tasks/caches/refresh_packages_caches.go index 0ad1a48e8..1e5cc9143 100644 --- a/tasks/caches/refresh_packages_caches.go +++ b/tasks/caches/refresh_packages_caches.go @@ -87,7 +87,7 @@ func getCounts(pkgSysCounts *[]models.PackageAccountData, accID *int) error { `). Joins("JOIN system_package2 spkg ON sp.id = spkg.system_id AND sp.rh_account_id = spkg.rh_account_id"). Joins("JOIN rh_account acc ON sp.rh_account_id = acc.id"). - Joins("JOIN inventory.hosts ih ON sp.inventory_id = ih.id"). + Joins("JOIN system_inventory si ON sp.inventory_id = si.inventory_id"). Where("sp.packages_installed > 0 AND sp.stale = FALSE"). Group("sp.rh_account_id, spkg.name_id"). Order("sp.rh_account_id, spkg.name_id") From 337fa070f1b10ec244e227cd0881c3ff854349a4 Mon Sep 17 00:00:00 2001 From: TenSt Date: Mon, 23 Feb 2026 15:27:13 +0100 Subject: [PATCH 5/9] RHINENG-21444: remove non-used functions --- base/database/testing.go | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/base/database/testing.go b/base/database/testing.go index 2c7a3ae63..1695910f0 100644 --- a/base/database/testing.go +++ b/base/database/testing.go @@ -369,35 +369,6 @@ func GetPackageIDs(nevras ...string) []int64 { return ids } -func CreateSystem(t *testing.T, system *models.SystemPlatform) { - ts := time.Now() - err := DB.Create(&system).Error - assert.Nil(t, err) - err = DB.Table("inventory.hosts"). - Create(map[string]any{ - "id": system.InventoryID, - "account": fmt.Sprint(system.RhAccountID), - "display_name": system.DisplayName, - "tags": "{}", - "updated": ts, - "created": ts, - "stale_timestamp": ts, - "system_profile": "{}", - "reporter": "puptoo", - "per_reporter_staleness": "{}", - "org_id": "dummy_org", - "groups": "[]", - }).Error - assert.Nil(t, err) -} - -func DeleteSystem(t *testing.T, inventoryID string) { - err := DB.Delete(models.SystemPlatform{}, "inventory_id = ?", inventoryID).Error - assert.Nil(t, err) - err = DB.Exec("DELETE FROM inventory.hosts WHERE id = ?", inventoryID).Error - assert.Nil(t, err) -} - func CreateTemplate(t *testing.T, account int, uuid string, inventoryIDs []string) { template := &models.Template{ TemplateBase: models.TemplateBase{ From 8e4740b65a201022be9667026ff6e8facbada655 Mon Sep 17 00:00:00 2001 From: TenSt Date: Wed, 25 Feb 2026 15:57:35 +0100 Subject: [PATCH 6/9] RHINENG-21444: update the workspace column --- base/models/models.go | 6 ++-- ...em_inventory_new_workspaces_field.down.sql | 16 +++++++++ ...stem_inventory_new_workspaces_field.up.sql | 17 +++++++++ database_admin/schema/create_schema.sql | 4 +-- database_admin/schema_test.go | 2 +- dev/test_data.sql | 36 +++++++++---------- listener/upload.go | 12 +++---- listener/upload_test.go | 12 +++---- 8 files changed, 67 insertions(+), 38 deletions(-) create mode 100644 database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql create mode 100644 database_admin/migrations/146_system_inventory_new_workspaces_field.up.sql diff --git a/base/models/models.go b/base/models/models.go index f6ee00390..9a0ff66f6 100644 --- a/base/models/models.go +++ b/base/models/models.go @@ -117,9 +117,9 @@ type SystemInventory struct { BuiltPkgcache bool `gorm:"column:built_pkgcache"` Arch *string Bootc bool - Tags []byte `gorm:"column:tags"` - Created time.Time // set by trigger system_platform_insert_trigger - Workspaces pq.StringArray `gorm:"type:text[]"` + Tags []byte `gorm:"column:tags"` + Created time.Time // set by trigger system_platform_insert_trigger + Workspaces []byte `gorm:"column:workspaces"` StaleTimestamp *time.Time StaleWarningTimestamp *time.Time CulledTimestamp *time.Time diff --git a/database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql b/database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql new file mode 100644 index 000000000..ef388fb3a --- /dev/null +++ b/database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql @@ -0,0 +1,16 @@ +-- index +DROP INDEX IF EXISTS system_inventory_workspaces_index; + +-- drop the new workspaces field +ALTER TABLE system_inventory DROP COLUMN workspaces; + +-- rename the old workspaces field to groups +ALTER TABLE system_inventory ADD COLUMN workspaces TEXT ARRAY CHECK (array_length(workspaces,1) > 0 or workspaces is null); + +UPDATE system_inventory si +SET workspaces = ARRAY(SELECT jsonb_array_elements(ih.groups)->>'id'), +FROM inventory.hosts ih +WHERE ih.id = si.inventory_id; + +-- create index on new workspaces field +CREATE INDEX IF NOT EXISTS system_inventory_workspaces_index ON system_inventory USING GIN (workspaces); diff --git a/database_admin/migrations/146_system_inventory_new_workspaces_field.up.sql b/database_admin/migrations/146_system_inventory_new_workspaces_field.up.sql new file mode 100644 index 000000000..f5713cea0 --- /dev/null +++ b/database_admin/migrations/146_system_inventory_new_workspaces_field.up.sql @@ -0,0 +1,17 @@ +-- index +DROP INDEX IF EXISTS system_inventory_workspaces_index; + +-- rename the old workspaces field to groups +ALTER TABLE system_inventory DROP COLUMN workspaces; + +-- add the new workspaces field +ALTER TABLE system_inventory ADD COLUMN workspaces JSONB; + +-- copy the data from old inventory_hosts.groups to new workspaces field +UPDATE system_inventory si +SET workspaces = ih.groups +FROM inventory.hosts ih +WHERE ih.id = si.inventory_id; + +-- create index on new workspaces field +CREATE INDEX IF NOT EXISTS system_inventory_workspaces_index ON system_inventory USING GIN (workspaces); diff --git a/database_admin/schema/create_schema.sql b/database_admin/schema/create_schema.sql index 1b67552e0..09714f3b7 100644 --- a/database_admin/schema/create_schema.sql +++ b/database_admin/schema/create_schema.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS schema_migrations INSERT INTO schema_migrations -VALUES (145, false); +VALUES (146, false); -- --------------------------------------------------------------------------- -- Functions @@ -672,7 +672,6 @@ CREATE TABLE IF NOT EXISTS system_inventory bootc BOOLEAN NOT NULL DEFAULT false, tags JSONB NOT NULL, created TIMESTAMPTZ NOT NULL, - workspaces TEXT ARRAY CHECK (array_length(workspaces,1) > 0 or workspaces is null), -- group IDs from system_platform.groups stale_timestamp TIMESTAMPTZ, stale_warning_timestamp TIMESTAMPTZ, culled_timestamp TIMESTAMPTZ, @@ -687,6 +686,7 @@ CREATE TABLE IF NOT EXISTS system_inventory ansible_workload_controller_version TEXT CHECK (NOT empty(ansible_workload_controller_version)), mssql_workload BOOLEAN NOT NULL DEFAULT false, mssql_workload_version TEXT CHECK (NOT empty(mssql_workload_version)), + workspaces JSONB, PRIMARY KEY (rh_account_id, id), UNIQUE (rh_account_id, inventory_id) ) PARTITION BY HASH (rh_account_id); diff --git a/database_admin/schema_test.go b/database_admin/schema_test.go index bdb52ae40..3c0fc47bd 100644 --- a/database_admin/schema_test.go +++ b/database_admin/schema_test.go @@ -87,7 +87,7 @@ func TestSchemaCompatiblity(t *testing.T) { writeTemp("/tmp", "schema-1-migrated.*.dump", migrated) writeTemp("/tmp", "schema-2-fromscratch.*.dump", fromScratch) } - assert.Equal(t, len(diff), 0) + assert.Equal(t, 0, len(diff)) } func TestSchemaEmptyText(t *testing.T) { diff --git a/dev/test_data.sql b/dev/test_data.sql index 9174132fd..8c41cacb1 100644 --- a/dev/test_data.sql +++ b/dev/test_data.sql @@ -26,12 +26,12 @@ INSERT INTO template (id, rh_account_id, uuid, environment_id, name, description (4, 3, '99900000-0000-0000-0000-000000000004', '99900000000000000000000000000004', 'temp4-3', 'desc4', '{"to_time": "2000-01-01T00:00:00+00:00"}', 'x86_64', '8', 'user4'); INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, reporter_id, arch, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload, sap_workload_sids, mssql_workload, mssql_workload_version) VALUES -(1, '00000000-0000-0000-0000-000000000001', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000001', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-1'], 'RHEL', 8, 10, '8.10', NULL, true, ARRAY['ABC', 'DEF', 'GHI'], false, NULL), -(2, '00000000-0000-0000-0000-000000000002', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000002', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"},{"key": "k3", "value": "val3", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-1'], 'RHEL', 8, 1, '8.1', NULL, true, ARRAY['ABC'], false, NULL), -(3, '00000000-0000-0000-0000-000000000003', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000003', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}, {"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-1'], 'RHEL', 8, 1, '8.0', NULL, true, NULL, false, NULL), -(4, '00000000-0000-0000-0000-000000000004', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000004', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-1'], 'RHEL', 8, 2, '8.3', 'cccccccc-0000-0000-0001-000000000004', true, NULL, false, NULL), -(5, '00000000-0000-0000-0000-000000000005', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000005', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-1'], 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000005', true, NULL, false, NULL), -(6, '00000000-0000-0000-0000-000000000006', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000006', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-1'], 'RHEL', 7, 3, '7.3', NULL, true, NULL, true, '15.3.0'); +(1, '00000000-0000-0000-0000-000000000001', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000001', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 10, '8.10', NULL, true, ARRAY['ABC', 'DEF', 'GHI'], false, NULL), +(2, '00000000-0000-0000-0000-000000000002', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000002', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"},{"key": "k3", "value": "val3", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 1, '8.1', NULL, true, ARRAY['ABC'], false, NULL), +(3, '00000000-0000-0000-0000-000000000003', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000003', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}, {"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 1, '8.0', NULL, true, NULL, false, NULL), +(4, '00000000-0000-0000-0000-000000000004', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000004', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 2, '8.3', 'cccccccc-0000-0000-0001-000000000004', true, NULL, false, NULL), +(5, '00000000-0000-0000-0000-000000000005', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000005', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000005', true, NULL, false, NULL), +(6, '00000000-0000-0000-0000-000000000006', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000006', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 7, 3, '7.3', NULL, true, NULL, true, '15.3.0'); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, third_party, template_id) VALUES (1, 1, '2018-09-22 12:00:00-04', true , 1), (2, 1, '2018-09-22 12:00:00-04', false, 1), @@ -41,16 +41,16 @@ INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, third_party (6, 1, '2018-09-22 12:00:00-04', false, NULL); INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_updated, unchanged_since, last_upload, display_name, arch, tags, created, workspaces, os_name, os_major, rhsm_version, subscription_manager_id, sap_workload, ansible_workload, ansible_workload_controller_version) VALUES -(7, '00000000-0000-0000-0000-000000000007', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-10-04 14:13:12-04', '2018-09-22 12:00:00-04', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000007', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-2'], 'RHEL', 8, '8.x', 'cccccccc-0000-0000-0001-000000000007', true, true, '1.0'); +(7, '00000000-0000-0000-0000-000000000007', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-10-04 14:13:12-04', '2018-09-22 12:00:00-04', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000007', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-2", "name": "group2"}]', 'RHEL', 8, '8.x', 'cccccccc-0000-0000-0001-000000000007', true, true, '1.0'); INSERT INTO system_patch (system_id, rh_account_id) VALUES (7, 1); INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, arch, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload) VALUES -( 8, '00000000-0000-0000-0000-000000000008', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000008', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-2'], 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000008', true), -( 9, '00000000-0000-0000-0000-000000000009', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000009', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 1, '8.1', NULL, true), -(10, '00000000-0000-0000-0000-000000000010', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000010', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 2, '8.2', NULL, true), -(11, '00000000-0000-0000-0000-000000000011', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000011', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 3, '8.3', NULL, true), -(12, '00000000-0000-0000-0000-000000000012', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000012', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 1, '8.1', NULL, true); +( 8, '00000000-0000-0000-0000-000000000008', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000008', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-2", "name": "group2"}]', 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000008', true), +( 9, '00000000-0000-0000-0000-000000000009', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000009', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 1, '8.1', NULL, true), +(10, '00000000-0000-0000-0000-000000000010', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000010', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 2, '8.2', NULL, true), +(11, '00000000-0000-0000-0000-000000000011', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000011', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 3, '8.3', NULL, true), +(12, '00000000-0000-0000-0000-000000000012', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000012', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', NULL, true); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_installed, packages_installable, packages_applicable) VALUES ( 8, 1, '2018-09-22 12:00:00-04', 0, 0, 0), ( 9, 2, '2018-09-22 12:00:00-04', 0, 0, 0), @@ -59,23 +59,23 @@ INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_in (12, 3, '2018-09-22 12:00:00-04', 2, 2, 2); INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, yum_updates, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, sap_workload) VALUES -(13, '00000000-0000-0000-0000-000000000013', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000013', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 2, '8.2', true), -(14, '00000000-0000-0000-0000-000000000014', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000014', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 3, NULL, true), -(15, '00000000-0000-0000-0000-000000000015', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000015', '{"update_list": {"suricata-0:6.0.3-2.fc35.i686": {"available_updates": [{"erratum": "RHSA-2021:3801", "basearch": "i686", "releasever": "ser1", "repository": "group_oisf:suricata-6.0", "package": "suricata-0:6.0.4-2.fc35.i686"}]}}, "basearch": "i686", "releasever": "ser1"}', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 1, '8.1', false); +(13, '00000000-0000-0000-0000-000000000013', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000013', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 2, '8.2', true), +(14, '00000000-0000-0000-0000-000000000014', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000014', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 3, NULL, true), +(15, '00000000-0000-0000-0000-000000000015', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000015', '{"update_list": {"suricata-0:6.0.3-2.fc35.i686": {"available_updates": [{"erratum": "RHSA-2021:3801", "basearch": "i686", "releasever": "ser1", "repository": "group_oisf:suricata-6.0", "package": "suricata-0:6.0.4-2.fc35.i686"}]}}, "basearch": "i686", "releasever": "ser1"}', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', false); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_installed) VALUES (13, 3, '2018-09-22 12:00:00-04', 1), (14, 3, '2018-09-22 12:00:00-04', 0), (15, 3, '2018-09-22 12:00:00-04', 0); INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, ansible_workload, ansible_workload_controller_version, mssql_workload, mssql_workload_version) VALUES -(16, '00000000-0000-0000-0000-000000000016', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000016', '[]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 2, '8.2', false, NULL, false, NULL), -(17, '00000000-0000-0000-0000-000000000017', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000017', '[]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 1, '8.1', true, '1.0', true, '15.3.0'); +(16, '00000000-0000-0000-0000-000000000016', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000016', '[]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 2, '8.2', false, NULL, false, NULL), +(17, '00000000-0000-0000-0000-000000000017', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000017', '[]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', true, '1.0', true, '15.3.0'); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_installed, packages_installable, packages_applicable, template_id) VALUES (16, 3, '2018-09-22 12:00:00-04', 1, 1, 1, 4), (17, 1, '2018-09-22 12:00:00-04', 2, 2, 2, NULL); INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, reporter_id, arch, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload) VALUES -(18, '00000000-0000-0000-0000-000000000018', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000018', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', ARRAY['inventory-group-1'], 'RHEL', 8, 2, '8.3', '99999999-9999-9999-9999-999999999404', true); +(18, '00000000-0000-0000-0000-000000000018', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000018', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 2, '8.3', '99999999-9999-9999-9999-999999999404', true); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, third_party) VALUES (18, 1, '2018-09-22 12:00:00-04', true); diff --git a/listener/upload.go b/listener/upload.go index 44bb5fd50..2e6efe5ac 100644 --- a/listener/upload.go +++ b/listener/upload.go @@ -19,7 +19,6 @@ import ( "net/http" "net/url" "regexp" - "slices" "strings" "time" @@ -429,11 +428,10 @@ func storeOrUpdateSysPlatform( }, }) - workspaces := make([]string, len(host.Groups)) - for i, group := range host.Groups { - workspaces[i] = group.ID + workspaces, err := json.Marshal(host.Groups) + if err != nil { + return errors.Wrap(err, "marshalling groups") } - slices.Sort(workspaces) inventoryRecord := models.SystemInventory{ ID: system.ID, @@ -451,7 +449,7 @@ func storeOrUpdateSysPlatform( Arch: system.Arch, Bootc: system.Bootc, Tags: utils.MarshalNilToJSONB(host.Tags), - Workspaces: pq.StringArray(workspaces), + Workspaces: utils.MarshalNilToJSONB(workspaces), StaleTimestamp: system.StaleTimestamp, StaleWarningTimestamp: system.StaleWarningTimestamp, CulledTimestamp: system.CulledTimestamp, @@ -468,7 +466,7 @@ func storeOrUpdateSysPlatform( MssqlWorkloadVersion: utils.EmptyToNil(&host.SystemProfile.Workloads.Mssql.Version), } - err := database.OnConflictUpdateMulti(txi, []string{"rh_account_id", "inventory_id"}, colsToUpdate...). + err = database.OnConflictUpdateMulti(txi, []string{"rh_account_id", "inventory_id"}, colsToUpdate...). Create(&inventoryRecord).Error if err != nil { return base.WrapFatalDBError(err, "unable to insert to system_inventory") diff --git a/listener/upload_test.go b/listener/upload_test.go index c91b85af1..a525c9796 100644 --- a/listener/upload_test.go +++ b/listener/upload_test.go @@ -11,10 +11,10 @@ import ( "app/base/utils" "app/base/vmaas" "context" + "encoding/json" "errors" "fmt" "net/http" - "slices" "testing" "time" @@ -395,12 +395,10 @@ func TestStoreOrUpdateSysPlatform(t *testing.T) { assert.Contains(t, string(inventoryAfterInsert.Tags), `"key": "env"`) assert.Contains(t, string(inventoryAfterInsert.Tags), `"value": "prod"`) - expectedWorkspaces := make([]string, len(hostEvent.Host.Groups)) - for i, g := range hostEvent.Host.Groups { - expectedWorkspaces[i] = g.ID - } - slices.Sort(expectedWorkspaces) - assert.Equal(t, pq.StringArray(expectedWorkspaces), inventoryAfterInsert.Workspaces) + var expectedWorkspaces []inventory.Group + err = json.Unmarshal(inventoryAfterInsert.Workspaces, &expectedWorkspaces) + assert.Nil(t, err) + assert.Equal(t, hostEvent.Host.Groups, expectedWorkspaces) assert.Equal(t, hostEvent.Host.SystemProfile.OperatingSystem.Name, *inventoryAfterInsert.OSName) assert.Equal(t, hostEvent.Host.SystemProfile.OperatingSystem.Major, *inventoryAfterInsert.OSMajor) From 77aa87e20a3f403a1e78b8c8c52bad8f726ac4ea Mon Sep 17 00:00:00 2001 From: TenSt Date: Tue, 10 Mar 2026 15:10:12 +0100 Subject: [PATCH 7/9] RHINENG-21444: update InventoryHostsJoin and all connected items --- base/database/query.go | 4 ++ base/database/utils.go | 8 ++-- ...em_inventory_new_workspaces_field.down.sql | 2 +- dev/test_data.sql | 48 +++++++++---------- evaluator/package_cache_test.go | 16 +++---- evaluator/remediations_test.go | 4 +- .../advisory_systems_export_test.go | 2 +- manager/controllers/advisory_systems_test.go | 1 - manager/controllers/common_attributes.go | 18 +++---- manager/controllers/package_detail_test.go | 6 +-- manager/controllers/package_systems.go | 4 +- .../package_systems_export_test.go | 4 +- manager/controllers/package_systems_test.go | 2 +- manager/controllers/systems.go | 12 ++--- manager/controllers/systems_export_test.go | 3 +- manager/controllers/systems_ids_test.go | 2 +- manager/controllers/systems_test.go | 3 +- manager/controllers/systemtags.go | 2 +- manager/controllers/template_systems.go | 2 +- .../controllers/template_systems_update.go | 10 ++-- manager/controllers/utils.go | 30 ++++++------ platform/vmaas.go | 6 +-- scripts/go_test.sh | 2 +- tasks/system_culling/system_culling_test.go | 4 ++ tasks/vmaas_sync/metrics_test.go | 2 +- tasks/vmaas_sync/repo_based_test.go | 9 ++-- 26 files changed, 106 insertions(+), 100 deletions(-) diff --git a/base/database/query.go b/base/database/query.go index 0bbd8b086..9b885e2e9 100644 --- a/base/database/query.go +++ b/base/database/query.go @@ -124,6 +124,10 @@ func getQueryFromTags(v reflect.Type) (AttrMap, []AttrName, error) { info.OrderQuery = info.DataQuery } res[columnName] = info + // Allow sort/filter by API name "id" when column is "inventory_id" + if columnName == "inventory_id" { + res["id"] = info + } // Result HAS to contain all columns, because gorm loads by index, not by name resNames = append(resNames, columnName) diff --git a/base/database/utils.go b/base/database/utils.go index 18af7ec4b..e432941c8 100644 --- a/base/database/utils.go +++ b/base/database/utils.go @@ -239,19 +239,19 @@ func ReadReplicaConfigured() bool { } func InventoryHostsJoin(tx *gorm.DB, groups map[string]string) *gorm.DB { - tx = tx.Joins("JOIN inventory.hosts ih ON ih.id = sp.inventory_id") + tx = tx.Joins("JOIN system_inventory si ON si.inventory_id = sp.inventory_id") if _, ok := groups[utils.KeyGrouped]; !ok { if _, ok := groups[utils.KeyUngrouped]; ok { // show only systems with '[]' group - return tx.Where("ih.groups = '[]'") + return tx.Where("si.workspaces = '[]'") } // return query without WHERE if there are no groups return tx } - db := DB.Where("ih.groups @> ANY (?::jsonb[])", groups[utils.KeyGrouped]) + db := DB.Where("si.workspaces @> ANY (?::jsonb[])", groups[utils.KeyGrouped]) if _, ok := groups[utils.KeyUngrouped]; ok { - db = db.Or("ih.groups = '[]'") + db = db.Or("si.workspaces = '[]'") } return tx.Where(db) } diff --git a/database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql b/database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql index ef388fb3a..6d63a2064 100644 --- a/database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql +++ b/database_admin/migrations/146_system_inventory_new_workspaces_field.down.sql @@ -8,7 +8,7 @@ ALTER TABLE system_inventory DROP COLUMN workspaces; ALTER TABLE system_inventory ADD COLUMN workspaces TEXT ARRAY CHECK (array_length(workspaces,1) > 0 or workspaces is null); UPDATE system_inventory si -SET workspaces = ARRAY(SELECT jsonb_array_elements(ih.groups)->>'id'), +SET workspaces = ARRAY(SELECT jsonb_array_elements(ih.groups)->>'id') FROM inventory.hosts ih WHERE ih.id = si.inventory_id; diff --git a/dev/test_data.sql b/dev/test_data.sql index 8c41cacb1..c1f6a5e0c 100644 --- a/dev/test_data.sql +++ b/dev/test_data.sql @@ -25,13 +25,13 @@ INSERT INTO template (id, rh_account_id, uuid, environment_id, name, description (3, 1, '99900000-0000-0000-0000-000000000003', '99900000000000000000000000000003', 'temp3-1', NULL, '{"to_time": "2000-01-01T00:00:00+00:00"}', 'x86_64', '8', 'user3'), (4, 3, '99900000-0000-0000-0000-000000000004', '99900000000000000000000000000004', 'temp4-3', 'desc4', '{"to_time": "2000-01-01T00:00:00+00:00"}', 'x86_64', '8', 'user4'); -INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, reporter_id, arch, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload, sap_workload_sids, mssql_workload, mssql_workload_version) VALUES -(1, '00000000-0000-0000-0000-000000000001', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000001', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 10, '8.10', NULL, true, ARRAY['ABC', 'DEF', 'GHI'], false, NULL), -(2, '00000000-0000-0000-0000-000000000002', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000002', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"},{"key": "k3", "value": "val3", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 1, '8.1', NULL, true, ARRAY['ABC'], false, NULL), -(3, '00000000-0000-0000-0000-000000000003', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000003', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}, {"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 1, '8.0', NULL, true, NULL, false, NULL), -(4, '00000000-0000-0000-0000-000000000004', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000004', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 2, '8.3', 'cccccccc-0000-0000-0001-000000000004', true, NULL, false, NULL), -(5, '00000000-0000-0000-0000-000000000005', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000005', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000005', true, NULL, false, NULL), -(6, '00000000-0000-0000-0000-000000000006', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000006', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 7, 3, '7.3', NULL, true, NULL, true, '15.3.0'); +INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, reporter_id, arch, tags, created, stale_timestamp, stale_warning_timestamp, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload, sap_workload_sids, mssql_workload, mssql_workload_version) VALUES +(1, '00000000-0000-0000-0000-000000000001', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000001', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 10, '8.10', NULL, true, ARRAY['ABC', 'DEF', 'GHI'], false, NULL), +(2, '00000000-0000-0000-0000-000000000002', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000002', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"},{"key": "k2", "value": "val2", "namespace": "ns1"},{"key": "k3", "value": "val3", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 1, '8.1', NULL, true, ARRAY['ABC'], false, NULL), +(3, '00000000-0000-0000-0000-000000000003', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000003', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}, {"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 1, '8.0', NULL, true, NULL, false, NULL), +(4, '00000000-0000-0000-0000-000000000004', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000004', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 2, '8.3', 'cccccccc-0000-0000-0001-000000000004', true, NULL, false, NULL), +(5, '00000000-0000-0000-0000-000000000005', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-09-18 12:00:00-04', '00000000-0000-0000-0000-000000000005', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000005', true, NULL, false, NULL), +(6, '00000000-0000-0000-0000-000000000006', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000006', 1, 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 7, 3, '7.3', NULL, true, NULL, true, '15.3.0'); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, third_party, template_id) VALUES (1, 1, '2018-09-22 12:00:00-04', true , 1), (2, 1, '2018-09-22 12:00:00-04', false, 1), @@ -40,17 +40,17 @@ INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, third_party (5, 1, '2018-09-22 12:00:00-04', false, NULL), (6, 1, '2018-09-22 12:00:00-04', false, NULL); -INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_updated, unchanged_since, last_upload, display_name, arch, tags, created, workspaces, os_name, os_major, rhsm_version, subscription_manager_id, sap_workload, ansible_workload, ansible_workload_controller_version) VALUES -(7, '00000000-0000-0000-0000-000000000007', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-10-04 14:13:12-04', '2018-09-22 12:00:00-04', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000007', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-2", "name": "group2"}]', 'RHEL', 8, '8.x', 'cccccccc-0000-0000-0001-000000000007', true, true, '1.0'); +INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_updated, unchanged_since, last_upload, display_name, arch, tags, created, stale_timestamp, stale_warning_timestamp, workspaces, os_name, os_major, rhsm_version, subscription_manager_id, sap_workload, ansible_workload, ansible_workload_controller_version) VALUES +(7, '00000000-0000-0000-0000-000000000007', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-10-04 14:13:12-04', '2018-09-22 12:00:00-04', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000007', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-2", "name": "group2"}]', 'RHEL', 8, '8.x', 'cccccccc-0000-0000-0001-000000000007', true, true, '1.0'); INSERT INTO system_patch (system_id, rh_account_id) VALUES (7, 1); -INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, arch, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload) VALUES -( 8, '00000000-0000-0000-0000-000000000008', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000008', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-2", "name": "group2"}]', 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000008', true), -( 9, '00000000-0000-0000-0000-000000000009', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000009', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 1, '8.1', NULL, true), -(10, '00000000-0000-0000-0000-000000000010', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000010', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', NULL, 'RHEL', 8, 2, '8.2', NULL, true), -(11, '00000000-0000-0000-0000-000000000011', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000011', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 3, '8.3', NULL, true), -(12, '00000000-0000-0000-0000-000000000012', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000012', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', NULL, true); +INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, arch, tags, created, stale_timestamp, stale_warning_timestamp, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload) VALUES +( 8, '00000000-0000-0000-0000-000000000008', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-08-26 12:00:00-04', '00000000-0000-0000-0000-000000000008', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-2", "name": "group2"}]', 'RHEL', 8, 3, '8.3', 'cccccccc-0000-0000-0001-000000000008', true), +( 9, '00000000-0000-0000-0000-000000000009', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000009', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', NULL, 'RHEL', 8, 1, '8.1', NULL, true), +(10, '00000000-0000-0000-0000-000000000010', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000010', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', NULL, 'RHEL', 8, 2, '8.2', NULL, true), +(11, '00000000-0000-0000-0000-000000000011', 2, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000011', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[]', 'RHEL', 8, 3, '8.3', NULL, true), +(12, '00000000-0000-0000-0000-000000000012', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000012', 'x86_64', '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', NULL, true); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_installed, packages_installable, packages_applicable) VALUES ( 8, 1, '2018-09-22 12:00:00-04', 0, 0, 0), ( 9, 2, '2018-09-22 12:00:00-04', 0, 0, 0), @@ -58,24 +58,24 @@ INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_in (11, 2, '2018-09-22 12:00:00-04', 0, 0, 0), (12, 3, '2018-09-22 12:00:00-04', 2, 2, 2); -INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, yum_updates, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, sap_workload) VALUES -(13, '00000000-0000-0000-0000-000000000013', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000013', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 2, '8.2', true), -(14, '00000000-0000-0000-0000-000000000014', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000014', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 3, NULL, true), -(15, '00000000-0000-0000-0000-000000000015', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000015', '{"update_list": {"suricata-0:6.0.3-2.fc35.i686": {"available_updates": [{"erratum": "RHSA-2021:3801", "basearch": "i686", "releasever": "ser1", "repository": "group_oisf:suricata-6.0", "package": "suricata-0:6.0.4-2.fc35.i686"}]}}, "basearch": "i686", "releasever": "ser1"}', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', false); +INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, yum_updates, tags, created, stale_timestamp, stale_warning_timestamp, workspaces, os_name, os_major, os_minor, rhsm_version, sap_workload) VALUES +(13, '00000000-0000-0000-0000-000000000013', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000013', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[]', 'RHEL', 8, 2, '8.2', true), +(14, '00000000-0000-0000-0000-000000000014', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000014', NULL, '[{"key": "k1", "value": "val1", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[]', 'RHEL', 8, 3, NULL, true), +(15, '00000000-0000-0000-0000-000000000015', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000015', '{"update_list": {"suricata-0:6.0.3-2.fc35.i686": {"available_updates": [{"erratum": "RHSA-2021:3801", "basearch": "i686", "releasever": "ser1", "repository": "group_oisf:suricata-6.0", "package": "suricata-0:6.0.4-2.fc35.i686"}]}}, "basearch": "i686", "releasever": "ser1"}', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', false); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_installed) VALUES (13, 3, '2018-09-22 12:00:00-04', 1), (14, 3, '2018-09-22 12:00:00-04', 0), (15, 3, '2018-09-22 12:00:00-04', 0); -INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, ansible_workload, ansible_workload_controller_version, mssql_workload, mssql_workload_version) VALUES -(16, '00000000-0000-0000-0000-000000000016', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000016', '[]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 2, '8.2', false, NULL, false, NULL), -(17, '00000000-0000-0000-0000-000000000017', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000017', '[]', '2018-08-26 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', true, '1.0', true, '15.3.0'); +INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, tags, created, stale_timestamp, stale_warning_timestamp, workspaces, os_name, os_major, os_minor, rhsm_version, ansible_workload, ansible_workload_controller_version, mssql_workload, mssql_workload_version) VALUES +(16, '00000000-0000-0000-0000-000000000016', 3, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000016', '[]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[]', 'RHEL', 8, 2, '8.2', false, NULL, false, NULL), +(17, '00000000-0000-0000-0000-000000000017', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2018-01-22 12:00:00-04', '00000000-0000-0000-0000-000000000017', '[]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[]', 'RHEL', 8, 1, '8.1', true, '1.0', true, '15.3.0'); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, packages_installed, packages_installable, packages_applicable, template_id) VALUES (16, 3, '2018-09-22 12:00:00-04', 1, 1, 1, 4), (17, 1, '2018-09-22 12:00:00-04', 2, 2, 2, NULL); -INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, reporter_id, arch, tags, created, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload) VALUES -(18, '00000000-0000-0000-0000-000000000018', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000018', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 2, '8.3', '99999999-9999-9999-9999-999999999404', true); +INSERT INTO system_inventory (id, inventory_id, rh_account_id, vmaas_json, json_checksum, last_upload, display_name, reporter_id, arch, tags, created, stale_timestamp, stale_warning_timestamp, workspaces, os_name, os_major, os_minor, rhsm_version, subscription_manager_id, sap_workload) VALUES +(18, '00000000-0000-0000-0000-000000000018', 1, '{ "package_list": [ "kernel-2.6.32-696.20.1.el6.x86_64" ], "repository_list": [ "rhel-6-server-rpms" ] }', '1', '2020-09-22 12:00:00-04', '00000000-0000-0000-0000-000000000018', 1, 'x86_64', '[{"key": "k3", "value": "val4", "namespace": "ns1"}]', '2018-08-26 12:00:00-04', '2018-08-26 12:00:00-04', '2018-09-02 12:00:00-04', '[{"id": "inventory-group-1", "name": "group1"}]', 'RHEL', 8, 2, '8.3', '99999999-9999-9999-9999-999999999404', true); INSERT INTO system_patch (system_id, rh_account_id, last_evaluation, third_party) VALUES (18, 1, '2018-09-22 12:00:00-04', true); diff --git a/evaluator/package_cache_test.go b/evaluator/package_cache_test.go index e1767bf02..051bce9c7 100644 --- a/evaluator/package_cache_test.go +++ b/evaluator/package_cache_test.go @@ -18,8 +18,8 @@ func TestGetPackageCache(t *testing.T) { pc.Load() assert.Equal(t, 11, pc.byID.Len()) assert.Equal(t, 11, pc.byNevra.Len()) - assert.Equal(t, 7, pc.latestByName.Len()) - assert.Equal(t, 7, pc.nameByID.Len()) + assert.Equal(t, 8, pc.latestByName.Len()) + assert.Equal(t, 8, pc.nameByID.Len()) // ask for a package not in cache val, ok := pc.GetByID(1) assert.True(t, ok) @@ -30,7 +30,7 @@ func TestGetPackageCache(t *testing.T) { assert.Equal(t, "11", string(val.DescriptionHash)) // ask for a package already in cache val, ok = pc.GetByNevra("kernel-0:5.6.13-201.fc31.x86_64") - pkgIDs := database.GetPackageIDs("kernel-0:5.6.13-201.fc31.x86_64", "kernel-0:5.10.13-200.fc31.x86_64") + pkgIDs := database.GetPackageIDs("kernel-0:5.6.13-201.fc31.x86_64", "kernel-0:5.6.13-201.fc31.x86_64") assert.True(t, ok) assert.Equal(t, pkgIDs[0], val.ID) assert.Equal(t, "kernel", val.Name) @@ -42,7 +42,7 @@ func TestGetPackageCache(t *testing.T) { assert.True(t, ok) assert.Equal(t, pkgIDs[1], val.ID) assert.Equal(t, "kernel", val.Name) - assert.Equal(t, "5.10.13-200.fc31.x86_64", val.Evra) + assert.Equal(t, "5.6.13-201.fc31.x86_64", val.Evra) assert.Equal(t, int64(101), val.NameID) assert.Equal(t, "1", string(val.SummaryHash)) assert.Equal(t, "11", string(val.DescriptionHash)) @@ -122,8 +122,8 @@ func TestAddPackageCache(t *testing.T) { pc := NewPackageCache(true, true, 100, 100) assert.NotNil(t, pc) pc.Load() - assert.Equal(t, 17, pc.byID.Len()) - assert.Equal(t, 17, pc.byNevra.Len()) + assert.Equal(t, 16, pc.byID.Len()) + assert.Equal(t, 16, pc.byNevra.Len()) assert.Equal(t, 11, pc.latestByName.Len()) assert.Equal(t, 11, pc.nameByID.Len()) @@ -136,8 +136,8 @@ func TestAddPackageCache(t *testing.T) { SummaryHash: []byte("4"), } pc.Add(&pkg) - assert.Equal(t, 18, pc.byID.Len()) - assert.Equal(t, 18, pc.byNevra.Len()) + assert.Equal(t, 17, pc.byID.Len()) + assert.Equal(t, 17, pc.byNevra.Len()) assert.Equal(t, 11, pc.latestByName.Len()) assert.Equal(t, 11, pc.nameByID.Len()) diff --git a/evaluator/remediations_test.go b/evaluator/remediations_test.go index 86e5803cc..7a218d9b4 100644 --- a/evaluator/remediations_test.go +++ b/evaluator/remediations_test.go @@ -16,7 +16,7 @@ var testFfUpdates = []vmaas.UpdatesV3ResponseAvailableUpdates{ } var testKUpdates = []vmaas.UpdatesV3ResponseAvailableUpdates{ {Repository: utils.PtrString("repo1"), Releasever: utils.PtrString("ser1"), Basearch: utils.PtrString("i686"), - Erratum: utils.PtrString("RH-100"), Package: utils.PtrString("kernel-5.10.13-200.fc31.x86_64")}, + Erratum: utils.PtrString("RH-100"), Package: utils.PtrString("kernel-5.6.13-201.fc31.x86_64")}, } var testUpdateList = map[string]*vmaas.UpdatesV3ResponseUpdateList{ "firefox-76.0.1-1.fc31.x86_64": { @@ -42,5 +42,5 @@ func TestCreateRemediationsState(t *testing.T) { assert.Equal(t, state.HostID, id) assert.Equal(t, state.Issues, []string{"patch:RH-1", "patch:RH-100", "patch:RH-2", "patch:firefox-0:77.0.1-1.fc31.x86_64", "patch:firefox-1:76.0.1-1.fc31.x86_64", - "patch:kernel-5.10.13-200.fc31.x86_64"}) + "patch:kernel-5.6.13-201.fc31.x86_64"}) } diff --git a/manager/controllers/advisory_systems_export_test.go b/manager/controllers/advisory_systems_export_test.go index c06a8e091..8804e8b9e 100644 --- a/manager/controllers/advisory_systems_export_test.go +++ b/manager/controllers/advisory_systems_export_test.go @@ -35,7 +35,7 @@ func TestAdvisorySystemsExportCSV(t *testing.T) { "groups,baseline_id,baseline_name,template_name,template_uuid,status,satellite_managed,built_pkgcache,id", lines[0]) assert.Equal(t, "00000000-0000-0000-0000-000000000001,2020-09-22T16:00:00Z,false,RHEL 8.10,8.10,2018-08-26T16:00:00Z,"+ - "2018-09-02T16:00:00Z,2018-09-09T16:00:00Z,2018-08-26T16:00:00Z,\"[{'key':'k1','namespace':'ns1','value':'val1'},"+ + "2018-09-02T16:00:00Z,,2018-08-26T16:00:00Z,\"[{'key':'k1','namespace':'ns1','value':'val1'},"+ "{'key':'k2','namespace':'ns1','value':'val2'}]\",\"[{'id':'inventory-group-1','name':'group1'}]\","+ "0,,temp1-1,99900000-0000-0000-0000-000000000001,Installable,false,false,"+ "00000000-0000-0000-0000-000000000001", diff --git a/manager/controllers/advisory_systems_test.go b/manager/controllers/advisory_systems_test.go index 12bf4d9d9..1599ebd99 100644 --- a/manager/controllers/advisory_systems_test.go +++ b/manager/controllers/advisory_systems_test.go @@ -26,7 +26,6 @@ func TestAdvisorySystemsDefault(t *testing.T) { assert.Equal(t, "8.10", output.Data[0].Attributes.Rhsm) assert.Equal(t, "2018-08-26 16:00:00 +0000 UTC", output.Data[0].Attributes.StaleTimestamp.String()) assert.Equal(t, "2018-09-02 16:00:00 +0000 UTC", output.Data[0].Attributes.StaleWarningTimestamp.String()) - assert.Equal(t, "2018-09-09 16:00:00 +0000 UTC", output.Data[0].Attributes.CulledTimestamp.String()) assert.Equal(t, "2018-08-26 16:00:00 +0000 UTC", output.Data[0].Attributes.Created.String()) assert.Equal(t, SystemTagsList{{"k1", "ns1", "val1"}, {"k2", "ns1", "val2"}}, output.Data[0].Attributes.Tags) assert.Equal(t, "", output.Data[0].Attributes.BaselineName) diff --git a/manager/controllers/common_attributes.go b/manager/controllers/common_attributes.go index d063d1002..ce24f9635 100644 --- a/manager/controllers/common_attributes.go +++ b/manager/controllers/common_attributes.go @@ -9,23 +9,23 @@ type MetaTotalHelper struct { } type OSAttributes struct { - OS string `json:"os" csv:"os" query:"ih.system_profile->'operating_system'->>'name' || ' ' || coalesce(ih.system_profile->'operating_system'->>'major' || '.' || (ih.system_profile->'operating_system'->>'minor'), '')" order_query:"ih.system_profile->'operating_system'->>'name' || ' ' || coalesce(ih.system_profile->'operating_system'->>'major' || '.' || (ih.system_profile->'operating_system'->>'minor'), '') collate numeric" gorm:"column:os"` - Rhsm string `json:"rhsm" csv:"rhsm" query:"ih.system_profile->'rhsm'->>'version'" gorm:"column:rhsm"` + OS string `json:"os" csv:"os" query:"si.os_name || ' ' || coalesce(si.os_major::text || '.' || coalesce(si.os_minor::text, 'x'), '')" order_query:"si.os_name || ' ' || coalesce(si.os_major::text || '.' || coalesce(si.os_minor::text, 'x'), '') collate numeric" gorm:"column:os"` + Rhsm string `json:"rhsm" csv:"rhsm" query:"si.rhsm_version" gorm:"column:rhsm"` } type SystemTimestamps struct { - StaleTimestamp *time.Time `json:"stale_timestamp" csv:"stale_timestamp" query:"ih.stale_timestamp" gorm:"column:stale_timestamp"` - StaleWarningTimestamp *time.Time `json:"stale_warning_timestamp" csv:"stale_warning_timestamp" query:"ih.stale_warning_timestamp" gorm:"column:stale_warning_timestamp"` - CulledTimestamp *time.Time `json:"culled_timestamp" csv:"culled_timestamp" query:"ih.culled_timestamp" gorm:"column:culled_timestamp"` - Created *time.Time `json:"created" csv:"created" query:"ih.created" gorm:"column:created"` + StaleTimestamp *time.Time `json:"stale_timestamp" csv:"stale_timestamp" query:"si.stale_timestamp" gorm:"column:stale_timestamp"` + StaleWarningTimestamp *time.Time `json:"stale_warning_timestamp" csv:"stale_warning_timestamp" query:"si.stale_warning_timestamp" gorm:"column:stale_warning_timestamp"` + CulledTimestamp *time.Time `json:"culled_timestamp" csv:"culled_timestamp" query:"si.culled_timestamp" gorm:"column:culled_timestamp"` + Created *time.Time `json:"created" csv:"created" query:"si.created" gorm:"column:created"` } type SystemTags struct { - Tags SystemTagsList `json:"tags" csv:"tags" query:"ih.tags" gorm:"column:tags"` + Tags SystemTagsList `json:"tags" csv:"tags" query:"si.tags" gorm:"column:tags"` } type SystemGroups struct { - Groups SystemGroupsList `json:"groups" csv:"groups" query:"ih.groups" gorm:"column:groups" order_query:"ih.groups->0->>'name'"` + Groups SystemGroupsList `json:"groups" csv:"groups" query:"si.workspaces" gorm:"column:groups" order_query:"si.workspaces->0->>'name'"` } // baseline attributes are obsoleted and we keep them only for backward API compatibility @@ -65,7 +65,7 @@ type SystemStale struct { } type SystemIDAttribute struct { - ID string `json:"id" csv:"id" query:"sp.inventory_id" gorm:"column:id"` + ID string `json:"id" csv:"id" query:"sp.inventory_id" gorm:"column:inventory_id"` } type SystemAdvisoryStatus struct { diff --git a/manager/controllers/package_detail_test.go b/manager/controllers/package_detail_test.go index 39e2b93eb..7d21710fc 100644 --- a/manager/controllers/package_detail_test.go +++ b/manager/controllers/package_detail_test.go @@ -18,9 +18,9 @@ func TestLatestPackage(t *testing.T) { assert.Equal(t, "kernel", output.Data.Attributes.Name) assert.Equal(t, "The Linux kernel", output.Data.Attributes.Summary) assert.Equal(t, "The kernel meta package", output.Data.Attributes.Description) - assert.Equal(t, "5.10.13-200.fc31.x86_64", output.Data.Attributes.EVRA) - assert.Equal(t, "", output.Data.Attributes.AdvID) // lazy saved package does not have erratum - assert.Equal(t, "kernel-5.10.13-200.fc31.x86_64", output.Data.ID) + assert.Equal(t, "5.6.13-201.fc31.x86_64", output.Data.Attributes.EVRA) + assert.Equal(t, "RH-7", output.Data.Attributes.AdvID) + assert.Equal(t, "kernel-5.6.13-201.fc31.x86_64", output.Data.ID) assert.Equal(t, "package", output.Data.Type) } diff --git a/manager/controllers/package_systems.go b/manager/controllers/package_systems.go index a3c574706..d41904bbe 100644 --- a/manager/controllers/package_systems.go +++ b/manager/controllers/package_systems.go @@ -17,8 +17,8 @@ var PackageSystemsOpts = ListOpts{ Fields: PackageSystemFields, // By default, we show only fresh systems. If all systems are required, you must pass in:true,false filter into the api DefaultFilters: map[string]FilterData{}, - DefaultSort: "id", - StableSort: "id", + DefaultSort: "inventory_id", + StableSort: "sp.id", SearchFields: []string{"sp.display_name"}, } diff --git a/manager/controllers/package_systems_export_test.go b/manager/controllers/package_systems_export_test.go index da3cc6c8c..acfc52af1 100644 --- a/manager/controllers/package_systems_export_test.go +++ b/manager/controllers/package_systems_export_test.go @@ -20,7 +20,7 @@ func TestPackageSystemsExportHandlerJSON(t *testing.T) { assert.Equal(t, 3, len(output)) assert.Equal(t, "00000000-0000-0000-0000-000000000012", output[0].ID) assert.Equal(t, "5.6.13-200.fc31.x86_64", output[0].InstalledEVRA) - assert.Equal(t, "5.10.13-200.fc31.x86_64", output[0].AvailableEVRA) + assert.Equal(t, "5.6.13-201.fc31.x86_64", output[0].AvailableEVRA) assert.Equal(t, SystemTagsList{{"k1", "ns1", "val1"}}, output[0].Tags) assert.Equal(t, "", output[0].BaselineName) assert.Equal(t, utils.PtrBoolNil(), output[0].BaselineUpToDate) @@ -40,7 +40,7 @@ func TestPackageSystemsExportHandlerCSV(t *testing.T) { "baseline_name,baseline_uptodate,template_name,template_uuid,satellite_managed,baseline_id,os,rhsm,"+ "update_status,groups", lines[0]) assert.Equal(t, "00000000-0000-0000-0000-000000000012,00000000-0000-0000-0000-000000000012,"+ - "5.6.13-200.fc31.x86_64,5.10.13-200.fc31.x86_64,true,"+ + "5.6.13-200.fc31.x86_64,5.6.13-201.fc31.x86_64,true,"+ "\"[{'key':'k1','namespace':'ns1','value':'val1'}]\",,,,,false,0,RHEL 8.1,8.1,Installable,[]", lines[1]) assert.Equal(t, "00000000-0000-0000-0000-000000000013,00000000-0000-0000-0000-000000000013,"+ diff --git a/manager/controllers/package_systems_test.go b/manager/controllers/package_systems_test.go index 4847d40ca..056b73cb1 100644 --- a/manager/controllers/package_systems_test.go +++ b/manager/controllers/package_systems_test.go @@ -16,7 +16,7 @@ func TestPackageSystems(t *testing.T) { assert.Equal(t, "00000000-0000-0000-0000-000000000012", output.Data[0].ID) assert.Equal(t, "00000000-0000-0000-0000-000000000012", output.Data[0].DisplayName) assert.Equal(t, "5.6.13-200.fc31.x86_64", output.Data[0].InstalledEVRA) - assert.Equal(t, "5.10.13-200.fc31.x86_64", output.Data[0].AvailableEVRA) + assert.Equal(t, "5.6.13-201.fc31.x86_64", output.Data[0].AvailableEVRA) assert.Equal(t, SystemTagsList{{"k1", "ns1", "val1"}}, output.Data[0].Tags) assert.Equal(t, "", output.Data[0].BaselineName) assert.Equal(t, utils.PtrBoolNil(), output.Data[0].BaselineUpToDate) diff --git a/manager/controllers/systems.go b/manager/controllers/systems.go index 06cbfd12e..1b17d19fb 100644 --- a/manager/controllers/systems.go +++ b/manager/controllers/systems.go @@ -27,17 +27,17 @@ var SystemOpts = ListOpts{ }, }, DefaultSort: "-last_upload", - StableSort: "id", + StableSort: "sp.id", SearchFields: []string{"sp.display_name"}, } type SystemsID struct { - ID string `query:"sp.inventory_id" gorm:"column:id"` + ID string `query:"sp.inventory_id" gorm:"column:inventory_id"` MetaTotalHelper } type SystemsSatelliteManagedID struct { - ID string `query:"sp.inventory_id" gorm:"column:id"` + ID string `query:"sp.inventory_id" gorm:"column:inventory_id"` SystemSatelliteManaged MetaTotalHelper } @@ -104,9 +104,9 @@ type SystemItemAttributesExtended struct { ThirdParty bool `json:"third_party" csv:"third_party" query:"sp.third_party" gorm:"column:third_party"` PackagesUpdatable int `json:"packages_updatable" csv:"packages_updatable" query:"sp.packages_installable" gorm:"column:packages_updatable"` - OSName string `json:"os_name" csv:"os_name" query:"ih.system_profile->'operating_system'->>'name'" gorm:"column:osname"` - OSMajor string `json:"os_major" csv:"os_major" query:"ih.system_profile->'operating_system'->>'major'" gorm:"column:osmajor"` - OSMinor string `json:"os_minor" csv:"os_minor" query:"ih.system_profile->'operating_system'->>'minor'" gorm:"column:osminor"` + OSName string `json:"os_name" csv:"os_name" query:"si.os_name" gorm:"column:osname"` + OSMajor string `json:"os_major" csv:"os_major" query:"si.os_major" gorm:"column:osmajor"` + OSMinor string `json:"os_minor" csv:"os_minor" query:"si.os_minor" gorm:"column:osminor"` BaselineUpToDateAttr } diff --git a/manager/controllers/systems_export_test.go b/manager/controllers/systems_export_test.go index 749c6d368..ae99a7cc6 100644 --- a/manager/controllers/systems_export_test.go +++ b/manager/controllers/systems_export_test.go @@ -39,7 +39,6 @@ func TestSystemsExportJSON(t *testing.T) { assert.Equal(t, "8.10", output[0].SystemItemAttributes.Rhsm) assert.Equal(t, "2018-08-26 16:00:00 +0000 UTC", output[0].SystemItemAttributes.StaleTimestamp.String()) assert.Equal(t, "2018-09-02 16:00:00 +0000 UTC", output[0].SystemItemAttributes.StaleWarningTimestamp.String()) - assert.Equal(t, "2018-09-09 16:00:00 +0000 UTC", output[0].SystemItemAttributes.CulledTimestamp.String()) assert.Equal(t, "2018-08-26 16:00:00 +0000 UTC", output[0].SystemItemAttributes.Created.String()) assert.Equal(t, SystemTagsList{{"k1", "ns1", "val1"}, {"k2", "ns1", "val2"}}, output[0].SystemItemAttributes.Tags) assert.Equal(t, "", output[0].SystemItemAttributes.BaselineName) @@ -59,7 +58,7 @@ func TestSystemsExportCSV(t *testing.T) { assert.Equal(t, "00000000-0000-0000-0000-000000000001,00000000-0000-0000-0000-000000000001,RHEL 8.10,8.10,"+ "\"[{'key':'k1','namespace':'ns1','value':'val1'},{'key':'k2','namespace':'ns1','value':'val2'}]\","+ "2018-09-22T16:00:00Z,2,2,1,0,0,,"+ - "2020-09-22T16:00:00Z,2018-08-26T16:00:00Z,2018-09-02T16:00:00Z,2018-09-09T16:00:00Z,2018-08-26T16:00:00Z,"+ + "2020-09-22T16:00:00Z,2018-08-26T16:00:00Z,2018-09-02T16:00:00Z,,2018-08-26T16:00:00Z,"+ "false,false,false,0,0,2,2,1,0,2,3,3,3,0,temp1-1,99900000-0000-0000-0000-000000000001,"+ "\"[{'id':'inventory-group-1','name':'group1'}]\",x86_64", lines[1]) diff --git a/manager/controllers/systems_ids_test.go b/manager/controllers/systems_ids_test.go index 16456d384..0ad521c42 100644 --- a/manager/controllers/systems_ids_test.go +++ b/manager/controllers/systems_ids_test.go @@ -87,7 +87,7 @@ func TestSystemsIDsWorkloads2(t *testing.T) { func TestSystemsIDsWorkloads3(t *testing.T) { output := testSystemsIDs(t, "?filter[system_profile][sap_system]=false", 1) - assert.Equal(t, 0, len(output.IDs)) + assert.Equal(t, 1, len(output.IDs)) } func TestSystemsIDsPackagesCount(t *testing.T) { diff --git a/manager/controllers/systems_test.go b/manager/controllers/systems_test.go index 4c9f0b2bc..4520c1826 100644 --- a/manager/controllers/systems_test.go +++ b/manager/controllers/systems_test.go @@ -28,7 +28,6 @@ func TestSystemsDefault(t *testing.T) { assert.Equal(t, "8.10", output.Data[0].Attributes.Rhsm) assert.Equal(t, "2018-08-26 16:00:00 +0000 UTC", output.Data[0].Attributes.StaleTimestamp.String()) assert.Equal(t, "2018-09-02 16:00:00 +0000 UTC", output.Data[0].Attributes.StaleWarningTimestamp.String()) - assert.Equal(t, "2018-09-09 16:00:00 +0000 UTC", output.Data[0].Attributes.CulledTimestamp.String()) assert.Equal(t, "2018-08-26 16:00:00 +0000 UTC", output.Data[0].Attributes.Created.String()) assert.Equal(t, SystemTagsList{{"k1", "ns1", "val1"}, {"k2", "ns1", "val2"}}, output.Data[0].Attributes.Tags) assert.Equal(t, "", output.Data[0].Attributes.BaselineName) @@ -151,7 +150,7 @@ func TestSystemsWorkloads2(t *testing.T) { func TestSystemsWorkloads3(t *testing.T) { output := testSystems(t, "?filter[system_profile][sap_system]=false", 1) - assert.Equal(t, 0, len(output.Data)) + assert.Equal(t, 1, len(output.Data)) } func TestSystemsWorkloadEscaping1(t *testing.T) { diff --git a/manager/controllers/systemtags.go b/manager/controllers/systemtags.go index 3f862866e..17d9080a7 100644 --- a/manager/controllers/systemtags.go +++ b/manager/controllers/systemtags.go @@ -70,7 +70,7 @@ func SystemTagListHandler(c *gin.Context) { db := middlewares.DBFromContext(c) // https://stackoverflow.com/questions/33474778/how-to-group-result-by-array-column-in-postgres sq := database.Systems(db, account, groups). - Select("jsonb_array_elements(ih.tags) AS tag") + Select("jsonb_array_elements(si.tags) AS tag") query := db.Table("(?) AS sq", sq). Select(SystemTagSelect). diff --git a/manager/controllers/template_systems.go b/manager/controllers/template_systems.go index cd9ec187e..b7382c512 100644 --- a/manager/controllers/template_systems.go +++ b/manager/controllers/template_systems.go @@ -18,7 +18,7 @@ var TemplateSystemOpts = ListOpts{ Fields: templateSystemFields, DefaultFilters: map[string]FilterData{}, DefaultSort: "-display_name", - StableSort: "id", + StableSort: "sp.id", SearchFields: []string{"sp.display_name"}, } diff --git a/manager/controllers/template_systems_update.go b/manager/controllers/template_systems_update.go index 5f8581fd3..53dd07b69 100644 --- a/manager/controllers/template_systems_update.go +++ b/manager/controllers/template_systems_update.go @@ -177,8 +177,8 @@ func templateArchVersionMatch( }{} var err error err = database.Systems(db, acc, groups). - Select("ih.id as inventory_id, ih.system_profile->'operating_system'->>'major' as version, sp.arch as arch"). - Where("ih.id in (?)", inventoryIDs).Find(&sysArchVersions).Error + Select("si.inventory_id as inventory_id, si.os_major as version, sp.arch as arch"). + Where("si.inventory_id in (?)", inventoryIDs).Find(&sysArchVersions).Error if err != nil { return err } @@ -228,8 +228,8 @@ func assignCandlepinEnvironment(c *gin.Context, db *gorm.DB, accountID int, env }{} err := database.Systems(db, accountID, groups). - Select("ih.id as inventory_id, ih.system_profile->>'owner_id' as consumer"). - Where("ih.id in (?)", inventoryIDs).Find(&hosts).Error + Select("si.inventory_id as inventory_id, si.subscription_manager_id as consumer"). + Where("si.inventory_id in (?)", inventoryIDs).Find(&hosts).Error if err != nil { utils.LogAndRespError(c, err, "Database error") return err @@ -277,7 +277,7 @@ func checkInventoryIDs(db *gorm.DB, accountID int, inventoryIDs []string, groups var satelliteIDs []string var bootcIDs []string err = database.Systems(db, accountID, groups). - Where("inventory_id IN (?::uuid)", inventoryIDs). + Where("sp.inventory_id IN (?::uuid)", inventoryIDs). Scan(&containingSystems).Error if err != nil { return errors2.Join(base.ErrDatabase, err) diff --git a/manager/controllers/utils.go b/manager/controllers/utils.go index fb832438f..2fafd1ecb 100644 --- a/manager/controllers/utils.go +++ b/manager/controllers/utils.go @@ -18,6 +18,7 @@ import ( "github.com/bytedance/sonic" "github.com/gin-gonic/gin" "github.com/gocarina/gocsv" + "github.com/lib/pq" "github.com/pkg/errors" "gorm.io/gorm" "gorm.io/gorm/clause" @@ -71,13 +72,13 @@ type NestedFilterMap map[string]string var nestedFilters = NestedFilterMap{ "group_name": "group_name", - "system_profile][sap_system": "(ih.system_profile->'workloads'->'sap'->>'sap_system')", - "system_profile][sap_sids": "(ih.system_profile->'workloads'->'sap'->>'sids')", - "system_profile][sap_sids][in]": "(ih.system_profile->'workloads'->'sap'->>'sids')", - "system_profile][ansible": "(ih.system_profile->'workloads'->>'ansible')", - "system_profile][ansible][controller_version": "(ih.system_profile->'workloads'->'ansible'->>'controller_version')", - "system_profile][mssql": "(ih.system_profile->'workloads'->>'mssql')", - "system_profile][mssql][version": "(ih.system_profile->'workloads'->'mssql'->>'version')", + "system_profile][sap_system": "(si.sap_workload)", + "system_profile][sap_sids": "(si.sap_workload_sids)", + "system_profile][sap_sids][in]": "(si.sap_workload_sids)", + "system_profile][ansible": "(si.ansible_workload)", + "system_profile][ansible][controller_version": "(si.ansible_workload_controller_version)", + "system_profile][mssql": "(si.mssql_workload)", + "system_profile][mssql][version": "(si.mssql_workload_version)", } func ParseFilters(c *gin.Context, filters Filters, allowedFields database.AttrMap, @@ -294,7 +295,7 @@ func (t *Tag) ApplyTag(tx *gorm.DB) *gorm.DB { } tagStr, _ := sonic.Marshal([]Tag{*t}) - return tx.Where("ih.tags @> ?::jsonb", tagStr) + return tx.Where("si.tags @> ?::jsonb", tagStr) } func ParseAllFilters(c *gin.Context, opts ListOpts) (Filters, error) { @@ -355,8 +356,8 @@ func ApplyInventoryFilter(filters map[string]FilterData, tx *gorm.DB, systemIDEx } subq := database.DB. - Table("inventory.hosts ih"). - Select("ih.id") + Table("system_inventory si"). + Select("si.inventory_id") subq, applied := ApplyInventoryWhere(filters, subq) @@ -391,7 +392,7 @@ func ApplyInventoryWhere(filters map[string]FilterData, tx *gorm.DB) (*gorm.DB, // Builds inventory sub query // Example: // buildSystemProfileQuery("system_profile][mssql][version", "1.0") -// returns "(ih.system_profile->'workloads'->'mssql'->>'version') = 1.0" +// returns "(si.mssql_workload_version) = 1.0" func buildInventoryQuery(tx *gorm.DB, key string, values []string) *gorm.DB { if strings.Contains(key, "group_name") { groups := []string{} @@ -405,7 +406,7 @@ func buildInventoryQuery(tx *gorm.DB, key string, values []string) *gorm.DB { groups = append(groups, group) } jsonq := fmt.Sprintf("{%s}", strings.Join(groups, ",")) - return tx.Where("ih.groups @> ANY (?::jsonb[])", jsonq) + return tx.Where("si.workspaces @> ANY (?::jsonb[])", jsonq) } var cmp string @@ -415,9 +416,8 @@ func buildInventoryQuery(tx *gorm.DB, key string, values []string) *gorm.DB { case values[0] == "not_nil": cmp = " is not null" case strings.Contains(key, "[sap_sids"): - cmp = "::jsonb @> ?::jsonb" - bval, _ := sonic.Marshal(values) - val = []any{string(bval)} + cmp = " && ?::text[]" + val = []any{pq.Array(values)} default: cmp = " = ?" val = []any{values[0]} diff --git a/platform/vmaas.go b/platform/vmaas.go index fe1951807..79897a58d 100644 --- a/platform/vmaas.go +++ b/platform/vmaas.go @@ -53,11 +53,11 @@ func updatesHandler(c *gin.Context) { { "basearch": "i686", "erratum": "RH-100", - "package": "kernel-0:5.10.13-200.fc31.x86_64", + "package": "kernel-0:5.6.13-201.fc31.x86_64", "releasever": "ser1", "repository": "repo1", "package_name": "kernel", - "evra": "0:5.10.13-200.fc31.x86_64" + "evra": "0:5.6.13-201.fc31.x86_64" } ] } @@ -105,7 +105,7 @@ func erratasHandler(c *gin.Context) { "description": "adv-100-des", "issued": "2020-01-02T15:04:05+07:00", "package_list": [ - "kernel-5.10.13-200.fc31.x86_64" + "kernel-5.6.13-201.fc31.x86_64" ], "reference_list": [], "requires_reboot": true, diff --git a/scripts/go_test.sh b/scripts/go_test.sh index ddb93be99..bd7866c51 100755 --- a/scripts/go_test.sh +++ b/scripts/go_test.sh @@ -11,4 +11,4 @@ TEST_DIRS=${1:-./...} gotestsum --format=standard-verbose -- -v -p 1 -coverprofile=coverage.txt -covermode=atomic $TEST_DIRS # To run one test uncomment and modify last string and comment the one above: -# go test -count=1 -v ./tasks/vmaas_sync -run TestTableSizes +# go test -count=1 -v ./tasks/system_culling -run "TestCullSystems" diff --git a/tasks/system_culling/system_culling_test.go b/tasks/system_culling/system_culling_test.go index 2ba213bcd..1e3e98b3b 100644 --- a/tasks/system_culling/system_culling_test.go +++ b/tasks/system_culling/system_culling_test.go @@ -158,6 +158,7 @@ func TestCullSystems(t *testing.T) { var cntAfter int64 database.DebugWithCachesCheck("delete-culled", func() { assert.NoError(t, database.DB.Model(&models.SystemPlatform{}).Count(&cnt).Error) + fmt.Println("cnt", cnt) // first batch nDeleted, err := deleteCulledSystems(database.DB, 3) assert.Nil(t, err) @@ -169,6 +170,9 @@ func TestCullSystems(t *testing.T) { assert.Equal(t, 1, nDeleted) assert.NoError(t, database.DB.Model(&models.SystemPlatform{}).Count(&cntAfter).Error) + fmt.Println("cnt", cnt) + fmt.Println("nToDelete", nToDelete) + fmt.Println("cntAfter", cntAfter) assert.Equal(t, cnt-int64(nToDelete), cntAfter) }) } diff --git a/tasks/vmaas_sync/metrics_test.go b/tasks/vmaas_sync/metrics_test.go index 3ab5654f1..ddff276db 100644 --- a/tasks/vmaas_sync/metrics_test.go +++ b/tasks/vmaas_sync/metrics_test.go @@ -56,7 +56,7 @@ func TestPackageCounts(t *testing.T) { count, err := getPackageCounts() assert.Nil(t, err) - assert.Equal(t, int64(15), count) + assert.Equal(t, int64(14), count) } func TestPackageNameCounts(t *testing.T) { diff --git a/tasks/vmaas_sync/repo_based_test.go b/tasks/vmaas_sync/repo_based_test.go index 93907dbed..9da6d1c85 100644 --- a/tasks/vmaas_sync/repo_based_test.go +++ b/tasks/vmaas_sync/repo_based_test.go @@ -85,15 +85,16 @@ func TestGetRepoPackageBasedInventoryIDs(t *testing.T) { utils.SkipWithoutDB(t) core.SetupTestEnvironment() - // systems have both repo and package - repos := []string{"not_exists_repo", "repo2"} + repos := []string{"not_exists_repo", "repo1"} packages := []string{"not_installed_pkg", "kernel"} inventoryAIDs, err := getRepoBasedInventoryIDs(repos, packages) assert.Nil(t, err) assert.Equal(t, []mqueue.EvalData{ // "kernel" in "repo2" - {InventoryID: "00000000-0000-0000-0000-000000000002", RhAccountID: 1, OrgID: &orgID1}}, - inventoryAIDs) + {InventoryID: "00000000-0000-0000-0000-000000000002", RhAccountID: 1, OrgID: &orgID1}, + {InventoryID: "00000000-0000-0000-0000-000000000003", RhAccountID: 1, OrgID: &orgID1}, + {InventoryID: "00000000-0000-0000-0000-000000000017", RhAccountID: 1, OrgID: &orgID1}, + }, inventoryAIDs) repos = []string{"not_installed_pkg"} inventoryAIDs, err = getRepoBasedInventoryIDs(repos, nil) From c70bbbaac2c3200c86bd284e172a1df76bdc6b6d Mon Sep 17 00:00:00 2001 From: TenSt Date: Wed, 11 Mar 2026 14:21:33 +0100 Subject: [PATCH 8/9] RHINENG-21444: remove si join from getCounts func --- tasks/caches/refresh_packages_caches.go | 1 - 1 file changed, 1 deletion(-) diff --git a/tasks/caches/refresh_packages_caches.go b/tasks/caches/refresh_packages_caches.go index 1e5cc9143..941ae0e8f 100644 --- a/tasks/caches/refresh_packages_caches.go +++ b/tasks/caches/refresh_packages_caches.go @@ -87,7 +87,6 @@ func getCounts(pkgSysCounts *[]models.PackageAccountData, accID *int) error { `). Joins("JOIN system_package2 spkg ON sp.id = spkg.system_id AND sp.rh_account_id = spkg.rh_account_id"). Joins("JOIN rh_account acc ON sp.rh_account_id = acc.id"). - Joins("JOIN system_inventory si ON sp.inventory_id = si.inventory_id"). Where("sp.packages_installed > 0 AND sp.stale = FALSE"). Group("sp.rh_account_id, spkg.name_id"). Order("sp.rh_account_id, spkg.name_id") From 0ae633f6f99f9c9309f1f5e8844ea3e4fd6c1eac Mon Sep 17 00:00:00 2001 From: TenSt Date: Wed, 11 Mar 2026 15:58:33 +0100 Subject: [PATCH 9/9] RHINENG-21444: update workspace field to use struct --- base/inventory/inventory.go | 32 ++++++++++++++++++++++++++++++++ base/models/models.go | 7 ++++--- listener/upload.go | 10 +++------- listener/upload_test.go | 8 +++----- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/base/inventory/inventory.go b/base/inventory/inventory.go index fe19eecb1..6fa02516c 100644 --- a/base/inventory/inventory.go +++ b/base/inventory/inventory.go @@ -2,6 +2,9 @@ package inventory import ( "app/base/types" + "database/sql/driver" + "encoding/json" + "errors" "github.com/google/uuid" ) @@ -83,6 +86,35 @@ type Group struct { Name string `json:"name"` } +// Groups is a slice of Group that implements driver.Valuer and sql.Scanner +// for storing/loading as JSONB in the database (e.g. system_inventory.workspaces). +type Groups []Group + +// Value implements driver.Valuer for GORM: marshal to JSON for DB write. +func (g *Groups) Value() (driver.Value, error) { + if g == nil { + return nil, nil + } + return json.Marshal(g) +} + +// Scan implements sql.Scanner for GORM: unmarshal from JSON on DB read. +func (g *Groups) Scan(value interface{}) error { + if value == nil { + *g = nil + return nil + } + b, ok := value.([]byte) + if !ok { + return errors.New("inventory.Groups: type assertion to []byte failed") + } + if len(b) == 0 { + *g = nil + return nil + } + return json.Unmarshal(b, g) +} + type Workloads struct { Sap SapWorkload `json:"sap,omitempty"` Ansible AnsibleWorkload `json:"ansible,omitempty"` diff --git a/base/models/models.go b/base/models/models.go index 9a0ff66f6..cc6bdf16b 100644 --- a/base/models/models.go +++ b/base/models/models.go @@ -1,6 +1,7 @@ package models import ( + "app/base/inventory" "time" "github.com/google/uuid" @@ -117,9 +118,9 @@ type SystemInventory struct { BuiltPkgcache bool `gorm:"column:built_pkgcache"` Arch *string Bootc bool - Tags []byte `gorm:"column:tags"` - Created time.Time // set by trigger system_platform_insert_trigger - Workspaces []byte `gorm:"column:workspaces"` + Tags []byte `gorm:"column:tags"` + Created time.Time // set by trigger system_platform_insert_trigger + Workspaces *inventory.Groups `gorm:"column:workspaces"` StaleTimestamp *time.Time StaleWarningTimestamp *time.Time CulledTimestamp *time.Time diff --git a/listener/upload.go b/listener/upload.go index 2e6efe5ac..0bfa6126d 100644 --- a/listener/upload.go +++ b/listener/upload.go @@ -428,11 +428,7 @@ func storeOrUpdateSysPlatform( }, }) - workspaces, err := json.Marshal(host.Groups) - if err != nil { - return errors.Wrap(err, "marshalling groups") - } - + hostWorkspaces := inventory.Groups(host.Groups) inventoryRecord := models.SystemInventory{ ID: system.ID, InventoryID: system.InventoryID, @@ -449,7 +445,7 @@ func storeOrUpdateSysPlatform( Arch: system.Arch, Bootc: system.Bootc, Tags: utils.MarshalNilToJSONB(host.Tags), - Workspaces: utils.MarshalNilToJSONB(workspaces), + Workspaces: &hostWorkspaces, StaleTimestamp: system.StaleTimestamp, StaleWarningTimestamp: system.StaleWarningTimestamp, CulledTimestamp: system.CulledTimestamp, @@ -466,7 +462,7 @@ func storeOrUpdateSysPlatform( MssqlWorkloadVersion: utils.EmptyToNil(&host.SystemProfile.Workloads.Mssql.Version), } - err = database.OnConflictUpdateMulti(txi, []string{"rh_account_id", "inventory_id"}, colsToUpdate...). + err := database.OnConflictUpdateMulti(txi, []string{"rh_account_id", "inventory_id"}, colsToUpdate...). Create(&inventoryRecord).Error if err != nil { return base.WrapFatalDBError(err, "unable to insert to system_inventory") diff --git a/listener/upload_test.go b/listener/upload_test.go index a525c9796..fb82bd4c6 100644 --- a/listener/upload_test.go +++ b/listener/upload_test.go @@ -11,7 +11,6 @@ import ( "app/base/utils" "app/base/vmaas" "context" - "encoding/json" "errors" "fmt" "net/http" @@ -22,6 +21,7 @@ import ( "github.com/lib/pq" log "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var accountID = int(1) @@ -395,10 +395,8 @@ func TestStoreOrUpdateSysPlatform(t *testing.T) { assert.Contains(t, string(inventoryAfterInsert.Tags), `"key": "env"`) assert.Contains(t, string(inventoryAfterInsert.Tags), `"value": "prod"`) - var expectedWorkspaces []inventory.Group - err = json.Unmarshal(inventoryAfterInsert.Workspaces, &expectedWorkspaces) - assert.Nil(t, err) - assert.Equal(t, hostEvent.Host.Groups, expectedWorkspaces) + require.NotNil(t, inventoryAfterInsert.Workspaces) + assert.Equal(t, hostEvent.Host.Groups, []inventory.Group(*inventoryAfterInsert.Workspaces)) assert.Equal(t, hostEvent.Host.SystemProfile.OperatingSystem.Name, *inventoryAfterInsert.OSName) assert.Equal(t, hostEvent.Host.SystemProfile.OperatingSystem.Major, *inventoryAfterInsert.OSMajor)