Skip to content

Commit

Permalink
[sonic-installer] Hyphens instead of underscores in command and subco…
Browse files Browse the repository at this point in the history
…mmands (sonic-net#983)

Replace underscores with hyphens in all sonic-installer subcommands as well as the root command itself.

- Install two entry points for sonic-installer: `sonic-installer` and `sonic_installer`. This allows for backward compatibility and time for users to transition from using the underscore versions to the hyphenated versions.
- Replace underscores with hyphens in the following subcommands:
    ```
    set-default
    set-next-boot
    binary-version
    upgrade-docker
    rollback-docker
    ```
    - Also add aliases from the underscore versions of these subcommnds to the new hyphenated subcommands to allow for backward compatibility and time for users to transition from using the underscore versions to the hyphenated versions.

- Print deprecation warnings to stderr if issued command line contains any deprecated versions with underscores
- Bonus: Addition of the AliasedGroup base class also adds support for abbreviated subcommands
- Fixed some style issues which did not align with PEP8 standards
- Eliminate duplicate code by adding DOCKER_CONTAINER_LIST; Remove unknown 'amon' container from the list
  • Loading branch information
jleveque committed Jul 14, 2020
1 parent da27247 commit a23479e
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 67 deletions.
8 changes: 8 additions & 0 deletions data/etc/bash_completion.d/sonic-installer
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
_sonic_installer_completion() {
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_SONIC_INSTALLER_COMPLETE=complete $1 ) )
return 0
}

complete -F _sonic_installer_completion -o default sonic-installer;
40 changes: 20 additions & 20 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -4645,7 +4645,7 @@ Supported options:
2. -f|--force - install FW regardless the current version
3. -i|--image - update FW using current/next SONiC image
Note: the default option is --image=current (current/next values are taken from `sonic_installer list`)
Note: the default option is --image=current (current/next values are taken from `sonic-installer list`)
### Platform Component Firmware vendor specific behaviour
Expand Down Expand Up @@ -6604,26 +6604,26 @@ Go Back To [Beginning of the document](#) or [Beginning of this section](#waterm
## Software Installation and Management
SONiC software can be installed in two methods, viz, "using sonic_installer tool", "ONIE Installer".
SONiC software can be installed in two methods, viz, "using sonic-installer tool", "ONIE Installer".
### SONiC Installer
This is a command line tool available as part of the SONiC software; If the device is already running the SONiC software, this tool can be used to install an alternate image in the partition.
This tool has facility to install an alternate image, list the available images and to set the next reboot image.
This command requires elevated (root) privileges to run.
**sonic_installer list**
**sonic-installer list**
This command displays information about currently installed images. It displays a list of installed images, currently running image and image set to be loaded in next reboot.
- Usage:
```
sonic_installer list
sonic-installer list
```
- Example:
```
admin@sonic:~$ sudo sonic_installer list
admin@sonic:~$ sudo sonic-installer list
Current: SONiC-OS-HEAD.XXXX
Next: SONiC-OS-HEAD.XXXX
Available:
Expand All @@ -6633,18 +6633,18 @@ This command displays information about currently installed images. It displays
TIP: This output can be obtained without evelated privileges by running the `show boot` command. See [here](#show-system-status) for details.
**sonic_installer install**
**sonic-installer install**
This command is used to install a new image on the alternate image partition. This command takes a path to an installable SONiC image or URL and installs the image.
- Usage:
```
sonic_installer install <image_file_path>
sonic-installer install <image_file_path>
```
- Example:
```
admin@sonic:~$ sudo sonic_installer install https://sonic-jenkins.westus.cloudapp.azure.com/job/xxxx/job/buildimage-xxxx-all/xxx/artifact/target/sonic-xxxx.bin
admin@sonic:~$ sudo sonic-installer install https://sonic-jenkins.westus.cloudapp.azure.com/job/xxxx/job/buildimage-xxxx-all/xxx/artifact/target/sonic-xxxx.bin
New image will be installed, continue? [y/N]: y
Downloading image...
...100%, 480 MB, 3357 KB/s, 146 seconds passed
Expand Down Expand Up @@ -6676,46 +6676,46 @@ This command is used to install a new image on the alternate image partition. T
Done
```
**sonic_installer set_default**
**sonic-installer set_default**
This command is be used to change the image which can be loaded by default in all the subsequent reboots.
- Usage:
```
sonic_installer set_default <image_name>
sonic-installer set_default <image_name>
```
- Example:
```
admin@sonic:~$ sudo sonic_installer set_default SONiC-OS-HEAD.XXXX
admin@sonic:~$ sudo sonic-installer set_default SONiC-OS-HEAD.XXXX
```
**sonic_installer set_next_boot**
**sonic-installer set_next_boot**
This command is used to change the image that can be loaded in the *next* reboot only. Note that it will fallback to current image in all other subsequent reboots after the next reboot.
- Usage:
```
sonic_installer set_next_boot <image_name>
sonic-installer set_next_boot <image_name>
```
- Example:
```
admin@sonic:~$ sudo sonic_installer set_next_boot SONiC-OS-HEAD.XXXX
admin@sonic:~$ sudo sonic-installer set_next_boot SONiC-OS-HEAD.XXXX
```
**sonic_installer remove**
**sonic-installer remove**
This command is used to remove the unused SONiC image from the disk. Note that it's *not* allowed to remove currently running image.
- Usage:
```
sonic_installer remove [-y|--yes] <image_name>
sonic-installer remove [-y|--yes] <image_name>
```
- Example:
```
admin@sonic:~$ sudo sonic_installer remove SONiC-OS-HEAD.YYYY
admin@sonic:~$ sudo sonic-installer remove SONiC-OS-HEAD.YYYY
Image will be removed, continue? [y/N]: y
Updating GRUB...
Done
Expand All @@ -6726,18 +6726,18 @@ This command is used to remove the unused SONiC image from the disk. Note that i
Image removed
```
**sonic_installer cleanup**
**sonic-installer cleanup**
This command removes all unused images from the device, leaving only the currently active image and the image which will be booted into next (if different) installed. If there are no images which can be removed, the command will output `No image(s) to remove`
- Usage:
```
sonic_installer cleanup [-y|--yes]
sonic-installer cleanup [-y|--yes]
```
- Example:
```
admin@sonic:~$ sudo sonic_installer cleanup
admin@sonic:~$ sudo sonic-installer cleanup
Remove images which are not current and next, continue? [y/N]: y
No image(s) to remove
```
Expand Down
4 changes: 2 additions & 2 deletions fwutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,13 +221,13 @@ def __init__(self):
self.overlay_mountpoint = self.OVERLAY_MOUNTPOINT_TEMPLATE.format(image_stem)

def get_current_image(self):
cmd = "sonic_installer list | grep 'Current: ' | cut -f2 -d' '"
cmd = "sonic-installer list | grep 'Current: ' | cut -f2 -d' '"
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)

return output.rstrip(NEWLINE)

def get_next_image(self):
cmd = "sonic_installer list | grep 'Next: ' | cut -f2 -d' '"
cmd = "sonic-installer list | grep 'Next: ' | cut -f2 -d' '"
output = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)

return output.rstrip(NEWLINE)
Expand Down
4 changes: 2 additions & 2 deletions scripts/asic_config_check
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ function ConfirmASICConfigChecksumsMatch()
# Main starts here
debug "Checking that ASIC configuration has not changed"

CURR_SONIC_IMAGE="$(sonic_installer list | grep "Current: " | cut -f2 -d' ')"
DST_SONIC_IMAGE="$(sonic_installer list | grep "Next: " | cut -f2 -d' ')"
CURR_SONIC_IMAGE="$(sonic-installer list | grep "Current: " | cut -f2 -d' ')"
DST_SONIC_IMAGE="$(sonic-installer list | grep "Next: " | cut -f2 -d' ')"
if [[ "${CURR_SONIC_IMAGE}" == "${DST_SONIC_IMAGE}" ]]; then
debug "ASIC config unchanged, current and destination SONiC version are the same"
exit "${ASIC_CONFIG_UNCHANGED}"
Expand Down
2 changes: 1 addition & 1 deletion scripts/fast-reboot
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ function teardown_control_plane_assistant()
function setup_reboot_variables()
{
# Kernel and initrd image
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
NEXT_SONIC_IMAGE=$(sonic-installer list | grep "Next: " | cut -d ' ' -f 2)
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
if grep -q aboot_platform= /host/machine.conf; then
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"
Expand Down
2 changes: 1 addition & 1 deletion scripts/reboot
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function show_help_and_exit()

function setup_reboot_variables()
{
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
NEXT_SONIC_IMAGE=$(sonic-installer list | grep "Next: " | cut -d ' ' -f 2)
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/sonic-kdump-config
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ def run_command(cmd, use_shell=False):

## Search which SONiC image is the Current image
def get_current_image():
(rc, img, err_str) = run_command("sonic_installer list | grep 'Current: ' | cut -d '-' -f 3-", use_shell=True);
(rc, img, err_str) = run_command("sonic-installer list | grep 'Current: ' | cut -d '-' -f 3-", use_shell=True);
if type(img) == list and len(img) == 1:
return img[0]
print_err("Unable to locate current SONiC image")
sys.exit(1)

## Search which SONiC image is the Next image
def get_next_image():
(rc, img, err_str) = run_command("sonic_installer list | grep 'Next: ' | cut -d '-' -f 3-", use_shell=True);
(rc, img, err_str) = run_command("sonic-installer list | grep 'Next: ' | cut -d '-' -f 3-", use_shell=True);
if type(img) == list and len(img) == 1:
return img[0]
print_err("Unable to locate current SONiC image")
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@
'pddf_ledutil = pddf_ledutil.main:cli',
'show = show.main:cli',
'sonic-clear = clear.main:cli',
'sonic_installer = sonic_installer.main:cli',
'sonic-installer = sonic_installer.main:sonic_installer',
'sonic_installer = sonic_installer.main:sonic_installer', # Deprecated
'undebug = undebug.main:cli',
'watchdogutil = watchdogutil.main:watchdogutil',
]
Expand Down
2 changes: 1 addition & 1 deletion show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ def ecn():
@cli.command('boot')
def boot():
"""Show boot configuration"""
cmd = "sudo sonic_installer list"
cmd = "sudo sonic-installer list"
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
click.echo(proc.stdout.read())

Expand Down
6 changes: 6 additions & 0 deletions sonic_installer/aliases.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[aliases]
set_default=set-default
set_next_boot=set-next-boot
binary_version=binary-version
upgrade_docker=upgrade-docker
rollback_docker=rollback-docker
2 changes: 1 addition & 1 deletion sonic_installer/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Module holding common functions and constants used by sonic_installer and its
Module holding common functions and constants used by sonic-installer and its
subpackages.
"""

Expand Down
Loading

0 comments on commit a23479e

Please sign in to comment.