Skip to content

Commit

Permalink
RHINENG-11299: arch attribute and filter for /systems
Browse files Browse the repository at this point in the history
  • Loading branch information
psegedy committed Jul 10, 2024
1 parent f24bea5 commit 384f621
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 2 deletions.
33 changes: 33 additions & 0 deletions docs/v3/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,14 @@
"type": "string"
}
},
{
"name": "filter[arch]",
"in": "query",
"description": "Filter",
"schema": {
"type": "string"
}
},
{
"name": "filter[os]",
"in": "query",
Expand Down Expand Up @@ -4153,6 +4161,14 @@
"type": "string"
}
},
{
"name": "filter[arch]",
"in": "query",
"description": "Filter",
"schema": {
"type": "string"
}
},
{
"name": "tags",
"in": "query",
Expand Down Expand Up @@ -5377,6 +5393,14 @@
"type": "string"
}
},
{
"name": "filter[arch]",
"in": "query",
"description": "Filter",
"schema": {
"type": "string"
}
},
{
"name": "filter[os]",
"in": "query",
Expand Down Expand Up @@ -8192,6 +8216,9 @@
"applicable_rhsa_count": {
"type": "integer"
},
"arch": {
"type": "string"
},
"baseline_id": {
"type": "integer"
},
Expand Down Expand Up @@ -8338,6 +8365,9 @@
"applicable_rhsa_count": {
"type": "integer"
},
"arch": {
"type": "string"
},
"baseline_id": {
"type": "integer"
},
Expand Down Expand Up @@ -8448,6 +8478,9 @@
"applicable_rhsa_count": {
"type": "integer"
},
"arch": {
"type": "string"
},
"baseline_id": {
"type": "integer"
},
Expand Down
4 changes: 4 additions & 0 deletions manager/controllers/common_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 3 additions & 0 deletions manager/controllers/systems.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type SystemItemAttributes struct {
BaselineIDAttr
TemplateAttibutes
SystemGroups
SystemArch
}

// nolint: lll
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions manager/controllers/systems_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
16 changes: 14 additions & 2 deletions manager/controllers/systems_export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
}

Expand Down Expand Up @@ -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)
}
}
10 changes: 10 additions & 0 deletions manager/controllers/systems_ids_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions manager/controllers/systems_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 384f621

Please sign in to comment.