Skip to content

Commit

Permalink
CASMTRIAGE-5124 patch activity doesn't truly work like patch activity (
Browse files Browse the repository at this point in the history
…Cray-HPE#168)

* CASMTRIAGE-5124 patch activity doesn't truly work like patch activity

* CASMTRIAGE-5124 update .version

* CASMTRIAGE-5124 update stale API doc
  • Loading branch information
atifsyedali authored Apr 3, 2023
1 parent b52a361 commit 503f03c
Show file tree
Hide file tree
Showing 12 changed files with 113 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.8
0.10.9
2 changes: 1 addition & 1 deletion charts/v1.0/cray-nls/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

apiVersion: v2
name: "cray-nls"
version: 1.4.61-debug3
version: 1.4.65-debug1
description: "Kubernetes resources for cray-nls"
home: "https://github.com/Cray-HPE/cray-nls-charts"
sources:
Expand Down
2 changes: 1 addition & 1 deletion charts/v1.0/cray-nls/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ cray-service:
name: "cray-nls"
image:
repository: artifactory.algol60.net/csm-docker/stable/cray-nls
tag: 0.10.6-debug3
tag: 0.10.9-debug1
resources:
limits:
cpu: 1
Expand Down
11 changes: 9 additions & 2 deletions docs/IUF_docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions docs/IUF_swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions docs/NLS_docs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions docs/NLS_swagger.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions src/api/models/iuf/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ type CreateActivityRequest struct {
} // @name Activity.CreateActivityRequest

type PatchActivityRequest struct {
InputParameters InputParameters `json:"input_parameters"`
SiteParameters SiteParameters `json:"site_parameters"`
ActivityState ActivityState `json:"activity_state" enums:"paused,in_progress,debug,blocked,wait_for_admin"` // State of activity
InputParameters InputParametersPatch `json:"input_parameters"`
SiteParameters SiteParameters `json:"site_parameters"`
ActivityState ActivityState `json:"activity_state" enums:"paused,in_progress,debug,blocked,wait_for_admin"` // State of activity
} // @name Activity.PatchActivityRequest

type ActivityState string
Expand Down
19 changes: 17 additions & 2 deletions src/api/models/iuf/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ type Product struct {
type InputParameters struct {
MediaDir string `json:"media_dir"` // Location of media
SiteParameters string `json:"site_parameters"` // DEPRECATED: use site_parameters at the top level of the activity or session resource. The inline contents of the site_parameters.yaml file.
LimitManagementNodes []string `json:"limit_management_nodes"` // Each item is the xname of a management node
LimitManagedNodes []string `json:"limit_managed_nodes"` // Each item is the xname of a managed node
LimitManagementNodes []string `json:"limit_management_nodes"` // Must in the form <role>_<subrole>. E.g. Management_Master, Management_Worker, Management_Storage
LimitManagedNodes []string `json:"limit_managed_nodes"` // Anything accepted by BOS v2 as the value to a session's limit parameter.
ManagedRolloutStrategy EManagedRolloutStrategy `json:"managed_rollout_strategy" enums:"reboot,stage"` // Whether to use a reboot or staged rollout strategy for managed nodes. Refer to BOS v2 for more details.
ConcurrentManagementRolloutPercentage int64 `json:"concurrent_management_rollout_percentage"` // The percentage of management nodes to reboot in parallel before moving on to the next set of management nodes to reboot.
MediaHost string `json:"media_host"` // A string containing the hostname of where the media is located
Expand All @@ -48,6 +48,21 @@ type InputParameters struct {
Force bool `json:"force"` // Force re-execution of stage operations
} // @name InputParameters

type InputParametersPatch struct {
MediaDir *string `json:"media_dir"` // Location of media
SiteParameters *string `json:"site_parameters"` // DEPRECATED: use site_parameters at the top level of the activity or session resource. The inline contents of the site_parameters.yaml file.
LimitManagementNodes *[]string `json:"limit_management_nodes"` // Must in the form <role>_<subrole>. E.g. Management_Master, Management_Worker, Management_Storage
LimitManagedNodes *[]string `json:"limit_managed_nodes"` // Anything accepted by BOS v2 as the value to a session's limit parameter.
ManagedRolloutStrategy *EManagedRolloutStrategy `json:"managed_rollout_strategy" enums:"reboot,stage"` // Whether to use a reboot or staged rollout strategy for managed nodes. Refer to BOS v2 for more details.
ConcurrentManagementRolloutPercentage *int64 `json:"concurrent_management_rollout_percentage"` // The percentage of management nodes to reboot in parallel before moving on to the next set of management nodes to reboot.
MediaHost *string `json:"media_host"` // A string containing the hostname of where the media is located
Concurrency *int64 `json:"concurrency"` // An integer defining how many products / operations can we concurrently execute.
BootprepConfigManaged *string `json:"bootprep_config_managed"` // The path to the bootprep config file for managed nodes, relative to the media_dir
BootprepConfigManagement *string `json:"bootprep_config_management"` // The path to the bootprep config file for management nodes, relative to the media_dir
Stages *[]string `json:"stages"` // Stages to execute
Force *bool `json:"force"` // Force re-execution of stage operations
} // @name InputParameters

type EManagedRolloutStrategy string

const (
Expand Down
47 changes: 41 additions & 6 deletions src/api/services/iuf/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,49 @@ func (s iufService) GetActivity(name string) (iuf.Activity, error) {
func (s iufService) PatchActivity(activity iuf.Activity, patchParams iuf.PatchActivityRequest) (iuf.Activity, error) {
s.logger.Infof("Called: PatchActivity(activity: %v, patchParams: %v)", activity, patchParams)

if patchParams.InputParameters.MediaDir != "" {
// input parameters exists
activity.InputParameters = patchParams.InputParameters
if patchParams.InputParameters.MediaDir != nil {
activity.InputParameters.MediaDir = *(patchParams.InputParameters.MediaDir)
}
if patchParams.InputParameters.SiteParameters != nil {
activity.InputParameters.SiteParameters = *(patchParams.InputParameters.SiteParameters)
}
if patchParams.InputParameters.LimitManagementNodes != nil {
activity.InputParameters.LimitManagementNodes = *(patchParams.InputParameters.LimitManagementNodes)
}
if patchParams.InputParameters.LimitManagedNodes != nil {
activity.InputParameters.LimitManagedNodes = *(patchParams.InputParameters.LimitManagedNodes)
}
if patchParams.InputParameters.ManagedRolloutStrategy != nil {
activity.InputParameters.ManagedRolloutStrategy = *(patchParams.InputParameters.ManagedRolloutStrategy)
}
if patchParams.InputParameters.ConcurrentManagementRolloutPercentage != nil {
activity.InputParameters.ConcurrentManagementRolloutPercentage = *(patchParams.InputParameters.ConcurrentManagementRolloutPercentage)
}
if patchParams.InputParameters.MediaHost != nil {
activity.InputParameters.MediaHost = *(patchParams.InputParameters.MediaHost)
}
if patchParams.InputParameters.Concurrency != nil {
activity.InputParameters.Concurrency = *(patchParams.InputParameters.Concurrency)
}
if patchParams.InputParameters.BootprepConfigManaged != nil {
activity.InputParameters.BootprepConfigManaged = *(patchParams.InputParameters.BootprepConfigManaged)
}
if patchParams.InputParameters.BootprepConfigManagement != nil {
activity.InputParameters.BootprepConfigManagement = *(patchParams.InputParameters.BootprepConfigManagement)
}
if patchParams.InputParameters.Stages != nil {
activity.InputParameters.Stages = *(patchParams.InputParameters.Stages)
}
if patchParams.InputParameters.Force != nil {
activity.InputParameters.Force = *(patchParams.InputParameters.Force)
}

// patch site parameters
if len(patchParams.SiteParameters.Products) > 0 || len(patchParams.SiteParameters.Global) > 0 {
activity.SiteParameters = patchParams.SiteParameters
// patch site parameters...all or nothing for Products and Global attributes
if len(patchParams.SiteParameters.Products) > 0 {
activity.SiteParameters.Products = patchParams.SiteParameters.Products
}
if len(patchParams.SiteParameters.Global) > 0 {
activity.SiteParameters.Global = patchParams.SiteParameters.Global
}

// only allow patching activity state in a limited way.
Expand Down
7 changes: 5 additions & 2 deletions src/api/services/iuf/activities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,23 @@ func TestPatchActivity(t *testing.T) {
Name: "test",
InputParameters: iuf.InputParameters{
MediaDir: "/a/b/c",
BootprepConfigManagement: "BootprepConfigManagement",
SiteParameters: "deprecated_field",
LimitManagementNodes: []string{"Management_Master"},
BootprepConfigManagement: "BootprepConfigManagement",
},
},
expectActivity: iuf.Activity{
Name: "test",
InputParameters: iuf.InputParameters{
MediaDir: "/a/b/c",
SiteParameters: "deprecated_field",
LimitManagementNodes: []string{"Management_Worker"},
BootprepConfigManagement: "BootprepConfigManagement",
BootprepConfigManaged: "BootprepConfigManaged",
Force: true,
},
},
req: toPatchRequest(`{"input_parameters": {"media_dir": "/a/b/c", "force": true, "bootprep_config_management": "BootprepConfigManagement", "bootprep_config_managed": "BootprepConfigManaged"}}`),
req: toPatchRequest(`{"input_parameters": {"limit_management_nodes": ["Management_Worker"], "force": true, "bootprep_config_managed": "BootprepConfigManaged"}}`),
wantErr: false,
},
{
Expand Down
15 changes: 14 additions & 1 deletion src/api/services/iuf/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,23 @@ func (s iufService) HistoryRunAction(activityName string, req iuf.HistoryRunActi
return iuf.Session{}, err
}

inputParamsForPatch := iuf.InputParametersPatch{}
jsonInputParams, err := json.Marshal(req.InputParameters)
if err != nil {
s.logger.Errorf("HistoryRunAction.4: for activity %s, error while parsing input parameters: %#v", activityName, req.InputParameters)
return iuf.Session{}, err
}
err = json.Unmarshal(jsonInputParams, &inputParamsForPatch)
if err != nil {
s.logger.Errorf("HistoryRunAction.5: for activity %s, error while parsing input parameters: %#v", activityName, req.InputParameters)
return iuf.Session{}, err
}

activity, err = s.PatchActivity(activity, iuf.PatchActivityRequest{
InputParameters: req.InputParameters,
InputParameters: inputParamsForPatch,
SiteParameters: req.SiteParameters,
})

if err != nil {
s.logger.Error(err)
return iuf.Session{}, err
Expand Down

0 comments on commit 503f03c

Please sign in to comment.