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

[hostcfgd] Enable/disable the container service only when the feature state was changed. #5689

Merged
merged 3 commits into from
Oct 23, 2020
Merged

Conversation

yozhao101
Copy link
Contributor

Signed-off-by: Yong Zhao yozhao@microsoft.com

- Why I did it
If we ran the CLI commands sudo config feature autorestart snmp disabled/enabled or sudo config feature autorestart swss disabled/enabled, then SNMP container will be stopped and started. This behavior was not expected since we updated the
auto_restart field not update state field in FEATURE table. The reason behind this issue is that either state field or auto_restart field was updated, the function update_feature_state(...) will be invoked which then starts snmp.timer service.
The snmp.timer service will first stop snmp.service and later start snmp.service.

In order to solve this issue, the function update_feature_state(...) will be only invoked if state field in FEATURE table was
updated.

- How I did it
When the demon hostcfgd was activated, all the values of state field in FEATURE table of each container will be
cached. Each time the function feature_state_handler(...) is invoked, it will determine whether the state field of a
container was changed or not. If it was changed, function update_feature_state(...) will be invoked and the cached
value will also be updated. Otherwise, nothing will be done.

- How to verify it
We can run the CLI commands sudo config feature autorestart snmp disabled/enabled or sudo config feature autorestart swss disabled/enabled to check whether SNMP container is stopped and started. We also can run the CLI commands sudo config feature state snmp disabled/enabled or sudo config feature state swss disabled/enabled to check whether the container is stopped and restarted.

- Which release branch to backport (provide reason below if selected)

  • 201811
  • [x ] 201911
  • 202006

- Description for the changelog

- A picture of a cute animal (not mandatory but encouraged)

the 'AutoRestart' field of swss/snmp container, snmp container will be
stopped and started.

Signed-off-by: Yong Zhao <yozhao@microsoft.com>
Signed-off-by: Yong Zhao <yozhao@microsoft.com>
Copy link
Contributor

@jleveque jleveque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title is a bit lengthy yet does not accurately describe the change being made. It instead describes one side effect of the change. The title, which will subsequently become the commit message, should summarize the actual change being made. "[hostcfgd] Fix the SNMP container stopped and started if 'AutoRestart' state of snmp/swss was changed" does not summarize the change; SNMP/SwSS should not be mentioned in the title -- it can be mentioned in the description. The actual change here is to invoke systemd commands only if the feature state has changed from its previous state, and not if other data in the FEATURE table has changed. Please try to condense what I wrote above down into a succinct and brief title.

files/image_config/hostcfgd/hostcfgd Outdated Show resolved Hide resolved
yxieca
yxieca previously approved these changes Oct 21, 2020
@yozhao101 yozhao101 changed the title [hostcfgd] Fix the SNMP container stopped and started if 'AutoRestart' state of snmp/swss was changed [hostcfgd] Enable/disable the container service only when the feature state was changed. Oct 21, 2020
Signed-off-by: Yong Zhao <yozhao@microsoft.com>
@lguohan
Copy link
Collaborator

lguohan commented Oct 22, 2020

retest vsimage please

@lguohan lguohan merged commit af97e23 into sonic-net:master Oct 23, 2020
abdosi pushed a commit that referenced this pull request Oct 23, 2020
… state was changed. (#5689)

**- Why I did it**
If we ran the CLI commands `sudo config feature autorestart snmp disabled/enabled` or `sudo config feature autorestart swss disabled/enabled`, then SNMP container will be stopped and started. This behavior was not expected since we updated the `auto_restart` field not update `state` field in `FEATURE` table. The reason behind this issue is that either `state` field or `auto_restart` field was updated, the function `update_feature_state(...)` will be invoked which then starts snmp.timer service.
The snmp.timer service will first stop snmp.service and later start snmp.service. 

In order to solve this issue, the function `update_feature_state(...)` will be only invoked if `state` field in `FEATURE` table was
updated.

**- How I did it**
When the demon `hostcfgd` was activated, all the values of `state` field in `FEATURE` table of each container will be
cached. Each time the function `feature_state_handler(...)` is invoked, it will determine whether the `state` field of a
container was changed or not. If it was changed, function `update_feature_state(...)` will be invoked and the cached
value will also be updated. Otherwise, nothing will be done.

**- How to verify it**
We can run the CLI commands `sudo config feature autorestart snmp disabled/enabled` or `sudo config feature autorestart swss disabled/enabled` to check whether SNMP container is stopped and started. We also can run the CLI commands  `sudo config feature state snmp disabled/enabled` or `sudo config feature state swss disabled/enabled` to check whether the container is stopped and restarted.

Signed-off-by: Yong Zhao <yozhao@microsoft.com>
@lguohan lguohan linked an issue Oct 28, 2020 that may be closed by this pull request
santhosh-kt pushed a commit to santhosh-kt/sonic-buildimage that referenced this pull request Feb 25, 2021
… state was changed. (sonic-net#5689)

**- Why I did it**
If we ran the CLI commands `sudo config feature autorestart snmp disabled/enabled` or `sudo config feature autorestart swss disabled/enabled`, then SNMP container will be stopped and started. This behavior was not expected since we updated the `auto_restart` field not update `state` field in `FEATURE` table. The reason behind this issue is that either `state` field or `auto_restart` field was updated, the function `update_feature_state(...)` will be invoked which then starts snmp.timer service.
The snmp.timer service will first stop snmp.service and later start snmp.service. 

In order to solve this issue, the function `update_feature_state(...)` will be only invoked if `state` field in `FEATURE` table was
updated.

**- How I did it**
When the demon `hostcfgd` was activated, all the values of `state` field in `FEATURE` table of each container will be
cached. Each time the function `feature_state_handler(...)` is invoked, it will determine whether the `state` field of a
container was changed or not. If it was changed, function `update_feature_state(...)` will be invoked and the cached
value will also be updated. Otherwise, nothing will be done.

**- How to verify it**
We can run the CLI commands `sudo config feature autorestart snmp disabled/enabled` or `sudo config feature autorestart swss disabled/enabled` to check whether SNMP container is stopped and started. We also can run the CLI commands  `sudo config feature state snmp disabled/enabled` or `sudo config feature state swss disabled/enabled` to check whether the container is stopped and restarted.

Signed-off-by: Yong Zhao <yozhao@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Toggling autorestart feature crashes SNMP
5 participants