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

fix parsing the output of parted in parted.list_() #23124

Merged
merged 2 commits into from
Apr 28, 2015
Merged

fix parsing the output of parted in parted.list_() #23124

merged 2 commits into from
Apr 28, 2015

Conversation

kevinboulain
Copy link
Contributor

Hi there,

Parsing the output of parted may fail in partition.list (in the code: parted.list_).
Here is an example of such a case:

[INFO    ] Executing command 'parted -m -s /dev/sdb print' in directory '/root'
[DEBUG   ] output: Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 44662784 blocks) or continue with the current setting? 
BYT;
/dev/sdb:31.5GB:scsi:512:512:gpt:ATA VBOX HARDDISK:;
1:1049kB:8589MB:8588MB:btrfs:SRV:;
Traceback (most recent call last):
  File ".../eggs/salt-2014.7.0-py2.7.egg/salt/cli/caller.py", line 129, in call
    ret['return'] = func(*args, **kwargs)
  File ".../eggs/salt-2014.7.0-py2.7.egg/salt/modules/parted.py", line 148, in list_
    'Problem encountered while parsing output from parted')
CommandExecutionError: Problem encountered while parsing output from parted
Error running 'partition.list': Problem encountered while parsing output from parted

At

cols = line.replace(';', '').split(':')
, cols is: ['Warning', ' Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 44662784 blocks) or continue with the current setting? ']

To correct this, I simply changed cmd.run to cmd.run_stdout since the message Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 44662784 blocks) or continue with the current setting? is written on stderr.

The log with the path of this pull request on a test virtual machine:

[INFO    ] Executing command 'parted -m -s /dev/sdb print' in directory '/root'
[DEBUG   ] stdout: BYT;
/dev/sdb:31.5GB:scsi:512:512:gpt:ATA VBOX HARDDISK:;
1:1049kB:8589MB:8588MB:btrfs:SRV:;
[DEBUG   ] stderr: Warning: Not all of the space available to /dev/sdb appears to be used, you can fix the GPT to use all of the space (an extra 44662784 blocks) or continue with the current setting?
['/dev/sdb', '31.5GB', 'scsi', '512', '512', 'gpt', 'ATA VBOX HARDDISK', '']

May be related to #16188 (some other things are bugging me, but I can not directly work around this one).

@jfindlay
Copy link
Contributor

@ether42, thanks for fixing this. In the future, please feel free to submit fixes directly to the oldest, supported, applicable release branches as they are regularly merged forward and this prevents us from needing to backport fixes, see https://docs.saltstack.com/en/latest/topics/development/contributing.html#which-salt-branch.

@jfindlay
Copy link
Contributor

@ether42, would you mind also updating the unit tests? Thanks. Let me know if you need any help figuring them out.

@jfindlay jfindlay added bugfix-bckport will be be back-ported to an older release branch by creating a PR against that branch Minor Change labels Apr 28, 2015
@kevinboulain
Copy link
Contributor Author

Oh yes, sorry for the units tests...
I tested the second commit with python runtests.py --name unit.modules.parted_test, it seems to pass.

I'm also sorry for making this pull request on the develop branch, I'll be more careful if I have to submit another one.

@jfindlay
Copy link
Contributor

@ether42, it is not a problem, backporting is easy. Thanks for fixing this issue.

jfindlay added a commit that referenced this pull request Apr 28, 2015
fix parsing the output of parted in parted.list_()
@jfindlay jfindlay merged commit a1ec423 into saltstack:develop Apr 28, 2015
This was referenced Apr 28, 2015
@rallytime rallytime added ZZZ[Done]-back-ported-bf RETIRED The pull request has been back-ported to an older branch. and removed bugfix-bckport will be be back-ported to an older release branch by creating a PR against that branch labels Apr 28, 2015
jfindlay added a commit that referenced this pull request Apr 28, 2015
jfindlay added a commit that referenced this pull request Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ZZZ[Done]-back-ported-bf RETIRED The pull request has been back-ported to an older branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants