Skip to content

Commit a23479e

Browse files
authored
[sonic-installer] Hyphens instead of underscores in command and subcommands (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
1 parent da27247 commit a23479e

File tree

12 files changed

+212
-67
lines changed

12 files changed

+212
-67
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
_sonic_installer_completion() {
2+
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
3+
COMP_CWORD=$COMP_CWORD \
4+
_SONIC_INSTALLER_COMPLETE=complete $1 ) )
5+
return 0
6+
}
7+
8+
complete -F _sonic_installer_completion -o default sonic-installer;

doc/Command-Reference.md

+20-20
Original file line numberDiff line numberDiff line change
@@ -4645,7 +4645,7 @@ Supported options:
46454645
2. -f|--force - install FW regardless the current version
46464646
3. -i|--image - update FW using current/next SONiC image
46474647
4648-
Note: the default option is --image=current (current/next values are taken from `sonic_installer list`)
4648+
Note: the default option is --image=current (current/next values are taken from `sonic-installer list`)
46494649
46504650
### Platform Component Firmware vendor specific behaviour
46514651
@@ -6604,26 +6604,26 @@ Go Back To [Beginning of the document](#) or [Beginning of this section](#waterm
66046604
66056605
## Software Installation and Management
66066606
6607-
SONiC software can be installed in two methods, viz, "using sonic_installer tool", "ONIE Installer".
6607+
SONiC software can be installed in two methods, viz, "using sonic-installer tool", "ONIE Installer".
66086608
66096609
66106610
### SONiC Installer
66116611
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.
66126612
This tool has facility to install an alternate image, list the available images and to set the next reboot image.
66136613
This command requires elevated (root) privileges to run.
66146614
6615-
**sonic_installer list**
6615+
**sonic-installer list**
66166616
66176617
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.
66186618
66196619
- Usage:
66206620
```
6621-
sonic_installer list
6621+
sonic-installer list
66226622
```
66236623
66246624
- Example:
66256625
```
6626-
admin@sonic:~$ sudo sonic_installer list
6626+
admin@sonic:~$ sudo sonic-installer list
66276627
Current: SONiC-OS-HEAD.XXXX
66286628
Next: SONiC-OS-HEAD.XXXX
66296629
Available:
@@ -6633,18 +6633,18 @@ This command displays information about currently installed images. It displays
66336633
66346634
TIP: This output can be obtained without evelated privileges by running the `show boot` command. See [here](#show-system-status) for details.
66356635
6636-
**sonic_installer install**
6636+
**sonic-installer install**
66376637
66386638
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.
66396639
66406640
- Usage:
66416641
```
6642-
sonic_installer install <image_file_path>
6642+
sonic-installer install <image_file_path>
66436643
```
66446644
66456645
- Example:
66466646
```
6647-
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
6647+
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
66486648
New image will be installed, continue? [y/N]: y
66496649
Downloading image...
66506650
...100%, 480 MB, 3357 KB/s, 146 seconds passed
@@ -6676,46 +6676,46 @@ This command is used to install a new image on the alternate image partition. T
66766676
Done
66776677
```
66786678
6679-
**sonic_installer set_default**
6679+
**sonic-installer set_default**
66806680
66816681
This command is be used to change the image which can be loaded by default in all the subsequent reboots.
66826682
66836683
- Usage:
66846684
```
6685-
sonic_installer set_default <image_name>
6685+
sonic-installer set_default <image_name>
66866686
```
66876687
66886688
- Example:
66896689
```
6690-
admin@sonic:~$ sudo sonic_installer set_default SONiC-OS-HEAD.XXXX
6690+
admin@sonic:~$ sudo sonic-installer set_default SONiC-OS-HEAD.XXXX
66916691
```
66926692
6693-
**sonic_installer set_next_boot**
6693+
**sonic-installer set_next_boot**
66946694
66956695
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.
66966696
66976697
- Usage:
66986698
```
6699-
sonic_installer set_next_boot <image_name>
6699+
sonic-installer set_next_boot <image_name>
67006700
```
67016701
67026702
- Example:
67036703
```
6704-
admin@sonic:~$ sudo sonic_installer set_next_boot SONiC-OS-HEAD.XXXX
6704+
admin@sonic:~$ sudo sonic-installer set_next_boot SONiC-OS-HEAD.XXXX
67056705
```
67066706
6707-
**sonic_installer remove**
6707+
**sonic-installer remove**
67086708
67096709
This command is used to remove the unused SONiC image from the disk. Note that it's *not* allowed to remove currently running image.
67106710
67116711
- Usage:
67126712
```
6713-
sonic_installer remove [-y|--yes] <image_name>
6713+
sonic-installer remove [-y|--yes] <image_name>
67146714
```
67156715
67166716
- Example:
67176717
```
6718-
admin@sonic:~$ sudo sonic_installer remove SONiC-OS-HEAD.YYYY
6718+
admin@sonic:~$ sudo sonic-installer remove SONiC-OS-HEAD.YYYY
67196719
Image will be removed, continue? [y/N]: y
67206720
Updating GRUB...
67216721
Done
@@ -6726,18 +6726,18 @@ This command is used to remove the unused SONiC image from the disk. Note that i
67266726
Image removed
67276727
```
67286728
6729-
**sonic_installer cleanup**
6729+
**sonic-installer cleanup**
67306730
67316731
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`
67326732
67336733
- Usage:
67346734
```
6735-
sonic_installer cleanup [-y|--yes]
6735+
sonic-installer cleanup [-y|--yes]
67366736
```
67376737
67386738
- Example:
67396739
```
6740-
admin@sonic:~$ sudo sonic_installer cleanup
6740+
admin@sonic:~$ sudo sonic-installer cleanup
67416741
Remove images which are not current and next, continue? [y/N]: y
67426742
No image(s) to remove
67436743
```

fwutil/lib.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ def __init__(self):
221221
self.overlay_mountpoint = self.OVERLAY_MOUNTPOINT_TEMPLATE.format(image_stem)
222222

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

227227
return output.rstrip(NEWLINE)
228228

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

233233
return output.rstrip(NEWLINE)

scripts/asic_config_check

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function ConfirmASICConfigChecksumsMatch()
7373
# Main starts here
7474
debug "Checking that ASIC configuration has not changed"
7575

76-
CURR_SONIC_IMAGE="$(sonic_installer list | grep "Current: " | cut -f2 -d' ')"
77-
DST_SONIC_IMAGE="$(sonic_installer list | grep "Next: " | cut -f2 -d' ')"
76+
CURR_SONIC_IMAGE="$(sonic-installer list | grep "Current: " | cut -f2 -d' ')"
77+
DST_SONIC_IMAGE="$(sonic-installer list | grep "Next: " | cut -f2 -d' ')"
7878
if [[ "${CURR_SONIC_IMAGE}" == "${DST_SONIC_IMAGE}" ]]; then
7979
debug "ASIC config unchanged, current and destination SONiC version are the same"
8080
exit "${ASIC_CONFIG_UNCHANGED}"

scripts/fast-reboot

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ function teardown_control_plane_assistant()
274274
function setup_reboot_variables()
275275
{
276276
# Kernel and initrd image
277-
NEXT_SONIC_IMAGE=$(sonic_installer list | grep "Next: " | cut -d ' ' -f 2)
277+
NEXT_SONIC_IMAGE=$(sonic-installer list | grep "Next: " | cut -d ' ' -f 2)
278278
IMAGE_PATH="/host/image-${NEXT_SONIC_IMAGE#SONiC-OS-}"
279279
if grep -q aboot_platform= /host/machine.conf; then
280280
KERNEL_IMAGE="$(ls $IMAGE_PATH/boot/vmlinuz-*)"

scripts/reboot

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function show_help_and_exit()
6464

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

scripts/sonic-kdump-config

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ def run_command(cmd, use_shell=False):
7777

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

8686
## Search which SONiC image is the Next image
8787
def get_next_image():
88-
(rc, img, err_str) = run_command("sonic_installer list | grep 'Next: ' | cut -d '-' -f 3-", use_shell=True);
88+
(rc, img, err_str) = run_command("sonic-installer list | grep 'Next: ' | cut -d '-' -f 3-", use_shell=True);
8989
if type(img) == list and len(img) == 1:
9090
return img[0]
9191
print_err("Unable to locate current SONiC image")

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@
135135
'pddf_ledutil = pddf_ledutil.main:cli',
136136
'show = show.main:cli',
137137
'sonic-clear = clear.main:cli',
138-
'sonic_installer = sonic_installer.main:cli',
138+
'sonic-installer = sonic_installer.main:sonic_installer',
139+
'sonic_installer = sonic_installer.main:sonic_installer', # Deprecated
139140
'undebug = undebug.main:cli',
140141
'watchdogutil = watchdogutil.main:watchdogutil',
141142
]

show/main.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2722,7 +2722,7 @@ def ecn():
27222722
@cli.command('boot')
27232723
def boot():
27242724
"""Show boot configuration"""
2725-
cmd = "sudo sonic_installer list"
2725+
cmd = "sudo sonic-installer list"
27262726
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
27272727
click.echo(proc.stdout.read())
27282728

sonic_installer/aliases.ini

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[aliases]
2+
set_default=set-default
3+
set_next_boot=set-next-boot
4+
binary_version=binary-version
5+
upgrade_docker=upgrade-docker
6+
rollback_docker=rollback-docker

sonic_installer/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Module holding common functions and constants used by sonic_installer and its
2+
Module holding common functions and constants used by sonic-installer and its
33
subpackages.
44
"""
55

0 commit comments

Comments
 (0)