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

Split uptodate state #8718

Merged
merged 1 commit into from
Jul 22, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -9332,11 +9332,17 @@ Alternatively, you will want to download <strong>Incremental Channel Conte
<source>Update information about installed software (packages and products)</source>
</trans-unit>
<trans-unit id="internal_state.uptodate" xml:space="preserve">
<source>Update the system, rebooting if required</source>
<source>Update the system</source>
</trans-unit>
<trans-unit id="internal_state.update-salt" xml:space="preserve">
<source>Perform a standalone Salt update</source>
</trans-unit>
<trans-unit id="internal_state.reboot" xml:space="preserve">
<source>Perform a reboot</source>
</trans-unit>
<trans-unit id="internal_state.rebootifneeded" xml:space="preserve">
<source>Perform a reboot, only if required</source>
</trans-unit>
<trans-unit id="internal_state.util_syncbeacons" xml:space="preserve">
<source>Sync Salt beacons to the target system</source>
</trans-unit>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ public int create(User loggedInUser, Map<String, Object> actionProps) {

List<String> states = (List<String>) actionProps.get("states");
Set<RecurringStateConfig> stateConfig = new HashSet<>();
if (states.contains("reboot") && states.contains("rebootifneeded")) {
throw new InvalidArgsException("'reboot' and 'rebootifneeded' cannot be used together.");
}
else if (states.contains("reboot")) {
stateConfig.add(stateConfigFactory.getRecurringState(loggedInUser, "reboot", states.size()));
states.remove("reboot");
}
else if (states.contains("rebootifneeded")) {
stateConfig.add(stateConfigFactory.getRecurringState(loggedInUser, "rebootifneeded", states.size()));
states.remove("rebootifneeded");
}
for (int i = 0; i < states.size(); i++) {
try {
stateConfig.add(stateConfigFactory.getRecurringState(loggedInUser, states.get(i), i + 1L));
Expand Down Expand Up @@ -129,6 +140,17 @@ public int update(User loggedInUser, Map<String, Object> actionProps) {
}

Set<RecurringStateConfig> stateConfig = new HashSet<>();
if (states.contains("reboot") && states.contains("rebootifneeded")) {
throw new InvalidArgsException("'reboot' and 'rebootifneeded' cannot be used together.");
}
else if (states.contains("reboot")) {
stateConfig.add(stateConfigFactory.getRecurringState(loggedInUser, "reboot", states.size()));
states.remove("reboot");
}
else if (states.contains("rebootifneeded")) {
stateConfig.add(stateConfigFactory.getRecurringState(loggedInUser, "rebootifneeded", states.size()));
states.remove("rebootifneeded");
}
for (int i = 0; i < states.size(); i++) {
try {
stateConfig.add(stateConfigFactory.getRecurringState(loggedInUser, states.get(i), i + 1L));
Expand Down
1 change: 1 addition & 0 deletions java/spacewalk-java.changes.parlt.split-uptodate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove reboot from uptodate state, introduce reboot and rebootifneeded states
6 changes: 6 additions & 0 deletions schema/spacewalk/common/data/suseInternalState.sql
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ INSERT INTO suseInternalState (id, name, label)

INSERT INTO suseInternalState (id, name, label)
VALUES (12, 'update-salt', 'Update Salt');

INSERT INTO suseInternalState (id, name, label)
VALUES (13, 'reboot', 'Reboot system');

INSERT INTO suseInternalState (id, name, label)
VALUES (14, 'rebootifneeded', 'Reboot system if needed');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove reboot from uptodate state, introduce reboot and rebootifneeded states
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
INSERT INTO suseInternalState (id, name, label)
SELECT 13, 'reboot', 'Reboot system'
WHERE NOT EXISTS (
SELECT 1 FROM suseInternalState
WHERE id = 13
);

INSERT INTO suseInternalState (id, name, label)
SELECT 14, 'rebootifneeded', 'Reboot system if needed'
WHERE NOT EXISTS (
SELECT 1 FROM suseInternalState
WHERE id = 14
);

3 changes: 3 additions & 0 deletions susemanager-utils/susemanager-sls/salt/reboot.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mgr_reboot:
cmd.run:
- name: shutdown -r +5
18 changes: 18 additions & 0 deletions susemanager-utils/susemanager-sls/salt/rebootifneeded.sls
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{%- if salt['pillar.get']('mgr_reboot_if_needed', True) and salt['pillar.get']('custom_info:mgr_reboot_if_needed', 'true')|lower in ('true', '1', 'yes', 't') %}
mgr_reboot_if_needed:
cmd.run:
- name: shutdown -r +5
{%- if grains['os_family'] == 'RedHat' and grains['osmajorrelease'] >= 8 %}
- onlyif: 'dnf -q needs-restarting -r; [ $? -eq 1 ]'
{%- elif grains['os_family'] == 'RedHat' and grains['osmajorrelease'] >= 7 %}
- onlyif: 'needs-restarting -r; [ $? -eq 1 ]'
{%- elif grains['os_family'] == 'Debian' %}
- onlyif:
- test -e /var/run/reboot-required
{%- elif grains['os_family'] == 'Suse' and grains['osmajorrelease'] <= 12 %}
- onlyif:
- test -e /boot/do_purge_kernels
{%- else %}
- onlyif: 'zypper ps -s; [ $? -eq 102 ] || [ {{ patch_need_reboot }} -eq 0 ]'
{%- endif %}
{%- endif %}
21 changes: 0 additions & 21 deletions susemanager-utils/susemanager-sls/salt/uptodate.sls
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,3 @@ mgr_keep_system_up2date_pkgs:
- require:
- sls: channels
- mgr_keep_system_up2date_updatestack

{%- if salt['pillar.get']('mgr_reboot_if_needed', True) and salt['pillar.get']('custom_info:mgr_reboot_if_needed', 'true')|lower in ('true', '1', 'yes', 't') %}
mgr_reboot_if_needed:
cmd.run:
- name: shutdown -r +5
- require:
- pkg: mgr_keep_system_up2date_pkgs
{%- if grains['os_family'] == 'RedHat' and grains['osmajorrelease'] >= 8 %}
- onlyif: 'dnf -q needs-restarting -r; [ $? -eq 1 ]'
{%- elif grains['os_family'] == 'RedHat' and grains['osmajorrelease'] >= 7 %}
- onlyif: 'needs-restarting -r; [ $? -eq 1 ]'
{%- elif grains['os_family'] == 'Debian' %}
- onlyif:
- test -e /var/run/reboot-required
{%- elif grains['os_family'] == 'Suse' and grains['osmajorrelease'] <= 12 %}
- onlyif:
- test -e /boot/do_purge_kernels
{%- else %}
- onlyif: 'zypper ps -s; [ $? -eq 102 ] || [ {{ patch_need_reboot }} -eq 0 ]'
{%- endif %}
{%- endif %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Remove reboot from uptodate state, introduce reboot and rebootifneeded states

33 changes: 30 additions & 3 deletions web/html/src/components/states-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class StatesPickerState {
changed = new Map();
showSaltState?: any | null = undefined;
rank?: boolean = undefined;
messages: MessageType[] | any;
messages: MessageType[] = [];
}

class StatesPicker extends React.Component<StatesPickerProps, StatesPickerState> {
Expand Down Expand Up @@ -103,12 +103,38 @@ class StatesPicker extends React.Component<StatesPickerProps, StatesPickerState>
};

save = () => {
let messages: MessageType[] = [];
const channels = this.state.assigned;
if (this.props.type === "state" && !channels.length) {
this.setMessages(MessagesUtils.error(t("State configuration must not be empty")));
this.setState({ changed: new Map() });
this.hideRanking();
return;
} else if (
channels.filter((channel) => channel.name.includes("reboot") && channel.type === "internal_state").length > 0
) {
// Put reboot states last
let position = 1;
let counter = 0;
_sortBy(channels, "position").forEach((channel) => {
if (channel.name.includes("reboot") && channel.type === "internal_state") {
if (channel.position !== channels.length) {
channel.position = channels.length;
messages = messages.concat(MessagesUtils.info(t("Reboot state will be put last.")));
}
counter++;
} else {
channel.position = position++;
}
});
if (counter > 1) {
this.setMessages(
MessagesUtils.error(t("'Reboot system' and 'Reboot system if needed' states cannot be used together."))
);
this.setState({ changed: new Map() });
this.hideRanking();
return;
}
}
const request = this.props.saveRequest(channels).then(
(data, textStatus, jqXHR) => {
Expand All @@ -123,6 +149,7 @@ class StatesPicker extends React.Component<StatesPickerProps, StatesPickerState>
}
});

messages = messages.concat(MessagesUtils.info(t("State assignments have been saved.")));
this.setState({
changed: new Map(), // clear changed
// Update the channels with the new data
Expand All @@ -136,7 +163,7 @@ class StatesPicker extends React.Component<StatesPickerProps, StatesPickerState>
results: this.getSortedList(newSearchResults),
},
});
this.setMessages(MessagesUtils.info(t("State assignments have been saved.")));
this.setMessages(messages);
this.hideRanking();
},
(jqXHR, textStatus, errorThrown) => {
Expand Down Expand Up @@ -316,7 +343,7 @@ class StatesPicker extends React.Component<StatesPickerProps, StatesPickerState>
};

clearMessages() {
this.setMessages(null);
this.setMessages([]);
}

getCurrentAssignment = () => {
Expand Down
1 change: 1 addition & 0 deletions web/spacewalk-web.changes.parlt.split-uptodate
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Remove reboot from uptodate state, introduce reboot and rebootifneeded states
Loading