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

Add sonic_installer utility. #40

Merged
merged 3 commits into from
Apr 27, 2017
Merged

Conversation

marian-pritsak
Copy link
Collaborator

No description provided.

@lguohan
Copy link
Contributor

lguohan commented Apr 24, 2017

@qiluo-msft , can you review this?

@lguohan
Copy link
Contributor

lguohan commented Apr 24, 2017

CodeFlow for GitHub does not download executable files. If you trust this file and would like to run it, please download it yourself through GitHub.

remove the swp file


Refers to: sonic_installer/.main.py.swp:1 in 920d722. [](commit_id = 920d722, deletion_comment = False)


MACHINE_PATH = '/host'
IMAGE_PREFIX = 'SONiC-OS'
IMAGE_DIR_PREFIX = 'image'
Copy link
Contributor

@qiluo-msft qiluo-msft Apr 24, 2017

Choose a reason for hiding this comment

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

To be more strict:
IMAGE_PREFIX = 'SONiC-OS-'
IMAGE_DIR_PREFIX = 'image-' #Closed

Copy link
Collaborator Author

@marian-pritsak marian-pritsak Apr 25, 2017

Choose a reason for hiding this comment

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

Done #Closed

for line in config:
if line.startswith('menuentry'):
image = line.split()[1].strip("'")
if image != 'ONIE':
Copy link
Contributor

@qiluo-msft qiluo-msft Apr 24, 2017

Choose a reason for hiding this comment

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

image != 'ONIE' [](start = 15, length = 15)

check for sonic explicitly? perhaps check IMAGE_PREFIX. #Closed

Copy link
Collaborator Author

@marian-pritsak marian-pritsak Apr 25, 2017

Choose a reason for hiding this comment

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

Done #Closed

config.close()

image_dir = image.replace(IMAGE_PREFIX, IMAGE_DIR_PREFIX)
run_command('rm -rf ' + MACHINE_PATH + '/' + image_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

run_command [](start = 4, length = 11)

shutil.rmtree is safer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In what way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Concatenating command line like 'rm -rf' is always dangerous and error prone. To prevent any usage error or developer extending errors (in future), let's use some API and relying upon it's argument validation.


In reply to: 113193343 [](ancestors = 113193343)

Copy link
Contributor

Choose a reason for hiding this comment

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

I share the concern, but it seems the real danger comes from image_dir validation, if image_dir is null string, we could remove the whole /host/ directory. rmtree won't realy help here.

Copy link
Contributor

Choose a reason for hiding this comment

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

it is better to validate the image_dir, make sure it is not null.

Copy link
Contributor

Choose a reason for hiding this comment

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

image_dir may contain blank, ';', '&&'. For example:

rm -rf /host/image_a /
rm -rf /host/image_a; echo “hello world"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to rmtree

else:
image_path = url

run_command("sh " + image_path)
Copy link
Contributor

@qiluo-msft qiluo-msft Apr 24, 2017

Choose a reason for hiding this comment

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

run_command [](start = 4, length = 11)

Can we remove the explicit "sh"? The image should be executable and the shebang could be arbitrary. #Closed

Copy link
Collaborator Author

@marian-pritsak marian-pritsak Apr 25, 2017

Choose a reason for hiding this comment

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

Done #Closed

Copy link
Contributor

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

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

As comments

import urllib
import subprocess

MACHINE_PATH = '/host'
Copy link
Contributor

Choose a reason for hiding this comment

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

rename to HOST_PATH?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

if line.find(image_dir):
current = image
break
cmdline.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

use m=re.match("loop=(\S+)/fs.squash").
m.group(1) to get the image dir.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

entry_found = True
elif entry_found and line.startswith('}'):
click.echo('FOUND!!!')
entry_found = False
Copy link
Contributor

Choose a reason for hiding this comment

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

can we use regex instead of this simple state machine to find out the menuentry and remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

click.echo('FOUND!!!')
entry_found = False
elif not entry_found:
new_config += line
Copy link
Contributor

Choose a reason for hiding this comment

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

add a comment, # remove menuentry of the image in grub.cfg

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

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.

Looks like you're accidentally trying to commit a swap file. Please remove sonic_installer/.main.py.swp from the commit.

Fix constants
Remove swap file added by mistake

Signed-off-by: marian-pritsak <marianp@mellanox.com>
lguohan pushed a commit to sonic-net/sonic-buildimage that referenced this pull request Apr 25, 2017
Its needed for sonic-net/sonic-utilities#40 for user to set default image for boot.

grub-set-default utility writes to value of saved_entry variable to grubenv.
https://www.gnu.org/software/grub/manual/legacy/Invoking-grub_002dset_002ddefault.html
This patch provides support for grub-set-default to allow user choose a default image to boot from.

Signed-off-by: marian-pritsak <marianp@mellanox.com>
@qiluo-msft
Copy link
Contributor

I confirmed most my comments are resolved. Only one left:
https://github.com/Azure/sonic-utilities/pull/40/files/920d7224ac71107f6eb3497a10397fe7ac9cbbd8#r113525876

Signed-off-by: marian-pritsak <marianp@mellanox.com>
@marian-pritsak
Copy link
Collaborator Author

@qiluo-msft done requested changes, please review

@stcheng stcheng merged commit 790aa83 into sonic-net:master Apr 27, 2017
vdahiya12 pushed a commit to vdahiya12/sonic-utilities that referenced this pull request Jul 23, 2021
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.

5 participants