diff --git a/docs/v3/openapi.json b/docs/v3/openapi.json index f2a5e9a4c..0c1d6b33a 100644 --- a/docs/v3/openapi.json +++ b/docs/v3/openapi.json @@ -2338,6 +2338,14 @@ "type": "string" } }, + { + "name": "filter[arch]", + "in": "query", + "description": "Filter", + "schema": { + "type": "string" + } + }, { "name": "filter[os]", "in": "query", @@ -4153,6 +4161,14 @@ "type": "string" } }, + { + "name": "filter[arch]", + "in": "query", + "description": "Filter", + "schema": { + "type": "string" + } + }, { "name": "tags", "in": "query", @@ -5377,6 +5393,14 @@ "type": "string" } }, + { + "name": "filter[arch]", + "in": "query", + "description": "Filter", + "schema": { + "type": "string" + } + }, { "name": "filter[os]", "in": "query", @@ -8192,6 +8216,9 @@ "applicable_rhsa_count": { "type": "integer" }, + "arch": { + "type": "string" + }, "baseline_id": { "type": "integer" }, @@ -8338,6 +8365,9 @@ "applicable_rhsa_count": { "type": "integer" }, + "arch": { + "type": "string" + }, "baseline_id": { "type": "integer" }, @@ -8448,6 +8478,9 @@ "applicable_rhsa_count": { "type": "integer" }, + "arch": { + "type": "string" + }, "baseline_id": { "type": "integer" }, diff --git a/manager/controllers/common_attributes.go b/manager/controllers/common_attributes.go index 83a9b56d9..20e589a32 100644 --- a/manager/controllers/common_attributes.go +++ b/manager/controllers/common_attributes.go @@ -78,6 +78,10 @@ type SystemBuiltPkgcache struct { BuiltPkgcache bool `json:"built_pkgcache" csv:"built_pkgcache" query:"sp.built_pkgcache" gorm:"column:built_pkgcache"` } +type SystemArch struct { + Arch string `json:"arch" csv:"arch" query:"sp.arch" gorm:"column:arch"` +} + // nolint: lll type InstallableAdvisories struct { InstallableRhsaCount int `json:"installable_rhsa_count" csv:"installable_rhsa_count" query:"sp.installable_advisory_sec_count_cache" gorm:"column:installable_rhsa_count"` diff --git a/manager/controllers/systems.go b/manager/controllers/systems.go index 112a4ee44..e09fd1fa9 100644 --- a/manager/controllers/systems.go +++ b/manager/controllers/systems.go @@ -95,6 +95,7 @@ type SystemItemAttributes struct { BaselineIDAttr TemplateAttibutes SystemGroups + SystemArch } // nolint: lll @@ -235,6 +236,7 @@ func systemsCommon(c *gin.Context) (*gorm.DB, *ListMeta, []string, error) { // @Param filter[baseline_name] query string false "Filter" // @Param filter[satellite_managed] query string false "Filter" // @Param filter[built_pkgcache] query string false "Filter" +// @Param filter[arch] query string false "Filter" // @Param filter[os] query string false "Filter OS version" // @Param filter[osname] query string false "Filter OS name" // @Param filter[osmajor] query string false "Filter OS major version" @@ -319,6 +321,7 @@ func SystemsListHandler(c *gin.Context) { // @Param filter[osminor] query string false "Filter OS minor version" // @Param filter[satellite_managed] query string false "Filter" // @Param filter[built_pkgcache] query string false "Filter" +// @Param filter[arch] query string false "Filter" // @Param tags query []string false "Tag filter" // @Param filter[group_name] query []string false "Filter systems by inventory groups" // @Param filter[system_profile][sap_system] query string false "Filter only SAP systems" diff --git a/manager/controllers/systems_export.go b/manager/controllers/systems_export.go index 8d030676a..82f5ae5c3 100644 --- a/manager/controllers/systems_export.go +++ b/manager/controllers/systems_export.go @@ -42,6 +42,7 @@ import ( // @Param filter[system_profile][mssql] query string false "Filter systems by mssql version" // @Param filter[system_profile][mssql][version] query string false "Filter systems by mssql version" // @Param filter[baseline_name] query string false "Filter" +// @Param filter[arch] query string false "Filter" // @Param filter[os] query string false "Filter OS version" // @Param filter[osname] query string false "Filter OS name" // @Param filter[osmajor] query string false "Filter OS major version" diff --git a/manager/controllers/systems_export_test.go b/manager/controllers/systems_export_test.go index 2498d06d2..22e03e9e6 100644 --- a/manager/controllers/systems_export_test.go +++ b/manager/controllers/systems_export_test.go @@ -18,7 +18,7 @@ var SystemCsvHeader = "id,display_name,os,rhsm,tags,last_evaluation," + "satellite_managed,built_pkgcache,packages_installable,packages_applicable," + "installable_rhsa_count,installable_rhba_count,installable_rhea_count,installable_other_count," + "applicable_rhsa_count,applicable_rhba_count,applicable_rhea_count,applicable_other_count," + - "baseline_id,template_name,template_id,groups" + "baseline_id,template_name,template_id,groups,arch" func makeRequest(t *testing.T, path string, contentType string) *httptest.ResponseRecorder { core.SetupTest(t) @@ -60,7 +60,7 @@ func TestSystemsExportCSV(t *testing.T) { "\"[{'key':'k1','namespace':'ns1','value':'val1'},{'key':'k2','namespace':'ns1','value':'val2'}]\","+ "2018-09-22T16:00:00Z,2,2,1,0,0,baseline_1-1,"+ "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,"+ - "false,false,false,0,0,2,2,1,0,2,3,3,3,1,temp1-1,1,\"[{'id':'inventory-group-1','name':'group1'}]\"", + "false,false,false,0,0,2,2,1,0,2,3,3,3,1,temp1-1,1,\"[{'id':'inventory-group-1','name':'group1'}]\",x86_64", lines[1]) } @@ -136,3 +136,15 @@ func TestSystemsExportFilterPartialOS(t *testing.T) { assert.Equal(t, "RHEL 8.1", o.OS) } } + +func TestSystemsExportArchFilter(t *testing.T) { + w := makeRequest(t, "/?filter[arch]=x86_64", "application/json") + + var output []SystemDBLookup + CheckResponse(t, w, http.StatusOK, &output) + + assert.Equal(t, 8, len(output)) + for _, o := range output { + assert.Equal(t, "x86_64", o.Arch) + } +} diff --git a/manager/controllers/systems_ids_test.go b/manager/controllers/systems_ids_test.go index 34d9c75bb..8c4d630d2 100644 --- a/manager/controllers/systems_ids_test.go +++ b/manager/controllers/systems_ids_test.go @@ -167,6 +167,16 @@ func TestSystemsIDsOrderOS(t *testing.T) { assert.Equal(t, output.Data[7].ID, outputIDs.IDs[7]) } +func TestSystemsIDsFilterArch(t *testing.T) { + output := testSystems(t, `?filter[arch]=x86_64`, 1) + outputIDs := testSystemsIDs(t, `?filter[arch]=x86_64`, 1) + assert.Equal(t, 8, len(outputIDs.Data)) + assert.Equal(t, 8, len(output.Data)) + for i, d := range outputIDs.Data { + assert.Equal(t, output.Data[i].ID, d.ID) + } +} + func testSystemsIDs(t *testing.T, queryString string, account int) IDsSatelliteManagedResponse { core.SetupTest(t) w := CreateRequestRouterWithAccount("GET", "/", "", queryString, nil, "", SystemsListIDsHandler, account) diff --git a/manager/controllers/systems_test.go b/manager/controllers/systems_test.go index 0fb0d121a..80e8b7ab0 100644 --- a/manager/controllers/systems_test.go +++ b/manager/controllers/systems_test.go @@ -35,6 +35,7 @@ func TestSystemsDefault(t *testing.T) { assert.Equal(t, int64(1), output.Data[0].Attributes.BaselineID) assert.False(t, output.Data[0].Attributes.SatelliteManaged) assert.False(t, output.Data[0].Attributes.BuiltPkgcache) + assert.Equal(t, "x86_64", output.Data[0].Attributes.Arch) // links assert.Equal(t, "/?offset=0&limit=20&filter[stale]=eq:false&sort=-last_upload", output.Links.First) @@ -235,6 +236,14 @@ func TestSystemsOrderOS(t *testing.T) { assert.Equal(t, "RHEL 8.x", output.Data[8].Attributes.OS) // yes, we should be robust against this } +func TestSystemsFilterArch(t *testing.T) { + output := testSystems(t, `?filter[arch]=x86_64`, 1) + assert.Equal(t, 8, len(output.Data)) + for _, d := range output.Data { + assert.Equal(t, "x86_64", d.Attributes.Arch) + } +} + func testSystems(t *testing.T, queryString string, account int) SystemsResponse { core.SetupTest(t) w := CreateRequestRouterWithAccount("GET", "/", "", queryString, nil, "", SystemsListHandler, account)