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

Support Reset factory #14105

Merged
merged 12 commits into from
Jul 11, 2023
Merged

Support Reset factory #14105

merged 12 commits into from
Jul 11, 2023

Conversation

Mohammedz93
Copy link
Contributor

@Mohammedz93 Mohammedz93 commented Mar 6, 2023

Why I did it

Support reset factory in Sonic OS
Reset Factory HLD
Sonic-mgmt tests

How I did it

  • Added new script "/usr/bin/reset-factory"
    • It generates a new config_db.json files with factory configurations
    • It clears system files and logs
    • It removes all docker containers on system except database
    • It clears non-default users and restores default users password
  • Dump the default users info to a new file during build "/etc/sonic/default_users.json"
  • Supported new type "Keep-basic" in "config-setup factory"
  • Add new conf file for config-setup "/etc/config-setup/config-setup.conf

How to verify it

  • Run reset-factory script with all types: < none | keep-all-config | only-config | keep-basic >
  • Run config-setup factory with parameters < none | keep-basic >

Description for the changelog

Support reset factory in Sonic OS

Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.

Link to config_db schema for YANG module changes

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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Mar 6, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

@Mohammedz93 Mohammedz93 changed the title Reset factory Support Reset factory Mar 6, 2023
@Mohammedz93 Mohammedz93 closed this Mar 6, 2023
@Mohammedz93 Mohammedz93 reopened this Mar 6, 2023
@liat-grozovik
Copy link
Collaborator

@madhupalu @venkatmahalingam could you please help review the code PR following the HLD review?

@liat-grozovik
Copy link
Collaborator

@Mohammedz93 please check failures and if relevant to the changes you provided. if not, rerun

@Mohammedz93 Mohammedz93 reopened this Mar 21, 2023
@Mohammedz93
Copy link
Contributor Author

@madhupalu @venkatmahalingam could you please review the PR ?

@@ -56,17 +57,31 @@ usage()
EOF
}

# Factory command usage and help
usage_factory()
Copy link
Collaborator

@qiluo-msft qiluo-msft May 15, 2023

Choose a reason for hiding this comment

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

usage_factory

Could you merge this function to above usage()? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comments.

usage_factory() is used for "config-setup factory" help command.
while useage() is used for "config-setup" help command.
Do you mean by merge, to combine the two functions into one function with parameter ?
if so, why do you think it is necessary ?

@qiluo-msft
Copy link
Collaborator

@rajendra-dendukuri Could you help review?

j2 files/build_templates/config-setup.service.j2 | sudo tee $FILESYSTEM_ROOT_USR_LIB_SYSTEMD_SYSTEM/config-setup.service
sudo cp $IMAGE_CONFIGS/config-setup/config-setup $FILESYSTEM_ROOT/usr/bin/config-setup
sudo mkdir -p $FILESYSTEM_ROOT/etc/config-setup
sudo cp $IMAGE_CONFIGS/config-setup/config-setup.conf $FILESYSTEM_ROOT/etc/config-setup/config-setup.conf
Copy link
Collaborator

@qiluo-msft qiluo-msft May 15, 2023

Choose a reason for hiding this comment

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

config-setup.conf

Let's remove all the filename if it is the same as source file. There is extreme corner case that there is a folder with the same name existing before copy, and the behavior is not expected. #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I’m not sure if I am understanding correctly.
What do you mean by removing the filename ?
"/etc/config-setup" is a folder that was first introduced by by feature: SONiC-config-setup
It wasn't used until now but I think that this is correct path for locating the conf file
If the concern is that conf file name and folder name have the same prefix, we can change it to "config_setup.conf"

@liat-grozovik
Copy link
Collaborator

@qiluo-msft kindly reminder to review following comments handling

qiluo-msft
qiluo-msft previously approved these changes May 30, 2023
export password_expire="$( [[ "$CHANGE_DEFAULT_PASSWORD" == "y" ]] && echo true || echo false )"
export username="${USERNAME}"
export password="$(sudo grep ^${USERNAME} $FILESYSTEM_ROOT/etc/shadow | cut -d: -f2)"
j2 files/build_templates/default_users.json.j2 | sudo tee $FILESYSTEM_ROOT/etc/sonic/default_users.json
Copy link
Collaborator

@qiluo-msft qiluo-msft Jul 3, 2023

Choose a reason for hiding this comment

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

default_users.json.j2

Please check my comment on HLD PR: sonic-net/SONiC#1231 (review) #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please see my answer: sonic-net/SONiC#1231 (comment)

@liat-grozovik
Copy link
Collaborator

@dgsudharsan can you please review as well? if all good, I can move on and merge

@dgsudharsan
Copy link
Collaborator

@dgsudharsan can you please review as well? if all good, I can move on and merge

The changes look good. Please proceed with the merge

@qiluo-msft qiluo-msft merged commit 28b9299 into sonic-net:master Jul 11, 2023
sonic-otn pushed a commit to sonic-otn/sonic-buildimage that referenced this pull request Sep 20, 2023
#### Why I did it
Support reset factory in Sonic OS
[Reset Factory HLD](sonic-net/SONiC#1231)
[Sonic-mgmt tests](sonic-net/sonic-mgmt#7652)

#### How I did it
- Added new script "/usr/bin/reset-factory"
   * It generates a new config_db.json files with factory configurations
   * It clears system files and logs
   * It removes all docker containers on system except database
   * It clears non-default users and restores default users password
- Dump the default users info to a new file during build "/etc/sonic/default_users.json"
- Supported new type "Keep-basic" in "config-setup factory"
- Add new conf file for config-setup "/etc/config-setup/config-setup.conf

#### How to verify it
- Run reset-factory script with all types: < none | keep-all-config | only-config | keep-basic >
- Run config-setup factory with parameters < none | keep-basic >

#### Description for the changelog
Support reset factory in Sonic OS

#### Ensure to add label/tag for the feature raised. example - PR#2174 under sonic-utilities repo. where, Generic Config and Update feature has been labelled as GCU.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants