Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPM-2135: add baseline_id and osversion into /package/systems #1257

Merged
merged 3 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions dev/test_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ INSERT INTO rh_account (id, name, org_id) VALUES
INSERT INTO baseline (id, rh_account_id, name, config, description) VALUES
(1, 1, 'baseline_1-1', '{"to_time": "2010-09-22T00:00:00+00:00"}', 'desc'),
(2, 1, 'baseline_1-2', '{"to_time": "2021-01-01T00:00:00+00:00"}', NULL),
(3, 1, 'baseline_1-3', '{"to_time": "2000-01-01T00:00:00+00:00"}', NULL);
(3, 1, 'baseline_1-3', '{"to_time": "2000-01-01T00:00:00+00:00"}', NULL),
(4, 3, 'baseline_3-4', '{"to_time": "2000-01-01T00:00:00+00:00"}', NULL);

INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, reporter_id, vmaas_json, json_checksum, last_evaluation, last_upload, packages_installed, packages_updatable, third_party, baseline_id, baseline_uptodate) VALUES
(1, '00000000-0000-0000-0000-000000000001','00000000-0000-0000-0000-000000000001', 1, 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', '2020-09-22 12:00:00-04',0,0, true, 1, true),
Expand All @@ -45,6 +46,9 @@ INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, vma
(15, '00000000-0000-0000-0000-000000000015','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-09-22 12:00:00-04', '2018-01-22 12:00:00-04', 0,0,
'{"update_list": {"suricata-6.0.3-2.fc35.i686": {"available_updates": [{"erratum": "RHSA-2021:3801", "basearch": "i686", "releasever": "ser1", "repository": "group_oisf:suricata-6.0", "package": "suricata-6.0.4-2.fc35.i686"}]}}, "basearch": "i686", "releasever": "ser1"}');

INSERT INTO system_platform (id, inventory_id, display_name, rh_account_id, vmaas_json, json_checksum, last_evaluation, last_upload, packages_installed, packages_updatable, yum_updates, baseline_id) VALUES
(16, '00000000-0000-0000-0000-000000000016','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-09-22 12:00:00-04', '2018-01-22 12:00:00-04', 1,0, NULL, 4);

INSERT INTO advisory_metadata (id, name, description, synopsis, summary, solution, advisory_type_id,
public_date, modified_date, url, severity_id, cve_list, release_versions) VALUES
(1, 'RH-1', 'adv-1-des', 'adv-1-syn', 'adv-1-sum', 'adv-1-sol', 1, '2016-09-22 12:00:00-04', '2017-09-22 12:00:00-04', 'url1', NULL, NULL, '["7.0","7Server"]'),
Expand Down Expand Up @@ -155,7 +159,8 @@ INSERT INTO system_package (rh_account_id, system_id, package_id, name_id, updat
(3, 13, 1, 101, null),
(3, 13, 2, 102, '[{"evra": "76.0.1-1.fc31.x86_64", "advisory": "RH-2", "status": "Installable"},{"evra": "77.0.1-1.fc31.x86_64", "advisory": "RH-1", "status": "Applicable"}]'),
(3, 13, 3, 103, null),
(3, 13, 4, 104, null);
(3, 13, 4, 104, null),
(3, 16, 1, 101, '[{"evra": "5.10.13-200.fc31.x86_64", "advisory": "RH-100", "status": "Installable"}]');

INSERT INTO timestamp_kv (name, value) VALUES
('last_eval_repo_based', '2018-04-05T01:23:45+02:00');
Expand Down
8 changes: 4 additions & 4 deletions docs/admin/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
],
"responses": {
"200": {
"description": "",
"description": "OK",
"content": {}
},
"500": {
Expand Down Expand Up @@ -123,7 +123,7 @@
],
"responses": {
"200": {
"description": "",
"description": "OK",
"content": {}
},
"500": {
Expand Down Expand Up @@ -165,7 +165,7 @@
],
"responses": {
"200": {
"description": "",
"description": "OK",
"content": {}
},
"500": {
Expand Down Expand Up @@ -207,7 +207,7 @@
],
"responses": {
"200": {
"description": "",
"description": "OK",
"content": {}
},
"500": {
Expand Down
9 changes: 9 additions & 0 deletions docs/v3/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -6066,6 +6066,9 @@
"available_evra": {
"type": "string"
},
"baseline_id": {
"type": "integer"
},
"baseline_name": {
"type": "string"
},
Expand All @@ -6081,6 +6084,12 @@
"installed_evra": {
"type": "string"
},
"os": {
"type": "string"
},
"rhsm": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
Expand Down
2 changes: 2 additions & 0 deletions manager/controllers/package_systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ type PackageSystemItemV2 struct {
//nolint:lll
type PackageSystemItemV3 struct {
PackageSystemItemCommon
BaselineIDAttr
OSAttributes
UpdateStatus string `json:"update_status" csv:"update_status" query:"update_status(spkg.update_data)" gorm:"column:update_status"`
}

Expand Down
10 changes: 5 additions & 5 deletions manager/controllers/package_systems_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestPackageSystemsExportHandlerJSON(t *testing.T) {

var output []PackageSystemItemV3
CheckResponse(t, w, http.StatusOK, &output)
assert.Equal(t, 2, len(output))
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)
Expand All @@ -35,15 +35,15 @@ func TestPackageSystemsExportHandlerCSV(t *testing.T) {
body := w.Body.String()
lines := strings.Split(body, "\n")

assert.Equal(t, 4, len(lines))
assert.Equal(t, 5, len(lines))
assert.Equal(t, "id,display_name,installed_evra,available_evra,updatable,tags,"+
"baseline_name,baseline_uptodate,update_status", lines[0])
"baseline_name,baseline_uptodate,baseline_id,os,rhsm,update_status", 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,"+
"\"[{'key':'k1','namespace':'ns1','value':'val1'}]\",,,Installable",
"\"[{'key':'k1','namespace':'ns1','value':'val1'}]\",,,0,RHEL 8.1,8.1,Installable",
lines[1])
assert.Equal(t, "00000000-0000-0000-0000-000000000013,00000000-0000-0000-0000-000000000013,"+
"5.6.13-200.fc31.x86_64,,false,\"[{'key':'k1','namespace':'ns1','value':'val1'}]\",,,None", lines[2])
"5.6.13-200.fc31.x86_64,,false,\"[{'key':'k1','namespace':'ns1','value':'val1'}]\",,,0,RHEL 8.2,8.2,None", lines[2])
}

func TestPackageSystemsExportInvalidName(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions manager/controllers/package_systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

func TestPackageSystems(t *testing.T) {
output := testPackageSystems(t, "/kernel/systems?sort=id", 3)
assert.Equal(t, 2, len(output.Data))
assert.Equal(t, 3, len(output.Data))
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)
Expand All @@ -24,7 +24,7 @@ func TestPackageSystems(t *testing.T) {

func TestPackageIDsSystems(t *testing.T) {
output := testPackageIDsSystems(t, "/kernel/systems?sort=id", 3)
assert.Equal(t, 2, len(output.IDs))
assert.Equal(t, 3, len(output.IDs))
assert.Equal(t, "00000000-0000-0000-0000-000000000012", output.IDs[0])
}

Expand Down
2 changes: 1 addition & 1 deletion manager/controllers/packages_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func TestPackageExportCSV(t *testing.T) {
assert.Equal(t, 6, len(lines))
assert.Equal(t, "name,summary,systems_installed,systems_installable,systems_applicable", lines[0])

assert.Equal(t, "kernel,The Linux kernel,2,1,1", lines[1])
assert.Equal(t, "kernel,The Linux kernel,3,2,2", lines[1])
}
2 changes: 1 addition & 1 deletion manager/controllers/packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestPackagesFilterSummary(t *testing.T) {
}

func TestPackagesFilterSAP(t *testing.T) {
output := doTestPackages(t, "/?filter[system_profile][is_sap][eq]=true")
output := doTestPackages(t, "/?filter[system_profile][sap_system]=true")
assert.Equal(t, 4, len(output.Data))
assert.Equal(t, "kernel", output.Data[3].Name)
assert.Equal(t, 2, output.Data[3].SystemsInstalled)
Expand Down
2 changes: 1 addition & 1 deletion manager/controllers/systems_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ func TestMissingAccount(t *testing.T) {
testAccountSystemCounts(t, 0, 0)
testAccountSystemCounts(t, 1, 8)
testAccountSystemCounts(t, 2, 3)
testAccountSystemCounts(t, 3, 4)
testAccountSystemCounts(t, 3, 5)
testAccountSystemCounts(t, 4, 0)
}
2 changes: 1 addition & 1 deletion manager/controllers/systems_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func TestSystemsIDsWorkloads3(t *testing.T) {

func TestSystemsIDsPackagesCount(t *testing.T) {
output := testSystemsIDs(t, "/?sort=-packages_installed,id", 3)
assert.Equal(t, 4, len(output.IDs))
assert.Equal(t, 5, len(output.IDs))
assert.Equal(t, "00000000-0000-0000-0000-000000000012", output.IDs[0])
}

Expand Down
2 changes: 1 addition & 1 deletion manager/controllers/systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestSystemsWorkloads3(t *testing.T) {

func TestSystemsPackagesCount(t *testing.T) {
output := testSystems(t, "/?sort=-packages_installed,id", 3)
assert.Equal(t, 4, len(output.Data))
assert.Equal(t, 5, len(output.Data))
assert.Equal(t, "00000000-0000-0000-0000-000000000012", output.Data[0].ID)
assert.Equal(t, "system", output.Data[0].Type)
assert.Equal(t, "00000000-0000-0000-0000-000000000012", output.Data[0].Attributes.DisplayName)
Expand Down
2 changes: 1 addition & 1 deletion tasks/system_culling/system_culling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func TestMarkSystemsStale(t *testing.T) {
}
nMarked, err := markSystemsStale(database.Db, 500)
assert.Nil(t, err)
assert.Equal(t, 15, nMarked)
assert.Equal(t, 16, nMarked)

assert.NoError(t, database.Db.Find(&systems).Error)
for i, s := range systems {
Expand Down
2 changes: 1 addition & 1 deletion tasks/vmaas_sync/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestSystemsCounts(t *testing.T) {
assert.Equal(t, 2, counts[systemsCntLabels{staleOff, lastUploadLast1D}])
assert.Equal(t, 5, counts[systemsCntLabels{staleOff, lastUploadLast7D}])
assert.Equal(t, 8, counts[systemsCntLabels{staleOff, lastUploadLast30D}])
assert.Equal(t, 15, counts[systemsCntLabels{staleOff, lastUploadAll}])
assert.Equal(t, 16, counts[systemsCntLabels{staleOff, lastUploadAll}])
assert.Equal(t, 0, counts[systemsCntLabels{staleOn, lastUploadLast1D}])
assert.Equal(t, 0, counts[systemsCntLabels{staleOn, lastUploadLast7D}])
assert.Equal(t, 0, counts[systemsCntLabels{staleOn, lastUploadLast30D}])
Expand Down
Loading