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

Fixed partition names with spaces effectively containing only the first word. #48032

Merged
merged 2 commits into from Aug 18, 2018

Conversation

Projects
None yet
3 participants
@zer0def
Copy link
Contributor

commented Jun 8, 2018

What does this PR do?

Fixes a case when attempts to set a partition name containing a space end up setting it to the first word.

Previous Behavior

$ salt 'minion1' partition.name /dev/vdc 1 'my partition'
minion1:
    - Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
    - Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
    - interactive mode.
    - OPTIONs:
    -   -h, --help                      displays this help message
    -   -l, --list                      lists partition layout on all block devices
    -   -m, --machine                   displays machine parseable output
    -   -s, --script                    never prompts for user intervention
    -   -v, --version                   displays the version
    -   -a, --align=[none|cyl|min|opt]  alignment for new partitions
    - COMMANDs:
    -   align-check TYPE N                        check partition N for TYPE(min|opt) alignment
    -   help [COMMAND]                           print general help, or help on COMMAND
    -   mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
    -   mkpart PART-TYPE [FS-TYPE] START END     make a partition
    -   name NUMBER NAME                         name partition NUMBER as NAME
    -   print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
    -   quit                                     exit program
    -   rescue START END                         rescue a lost partition near START and END
    -   rm NUMBER                                delete partition NUMBER
    -   select DEVICE                            choose the device to edit
    -   disk_set FLAG STATE                      change the FLAG on selected device
    -   disk_toggle [FLAG]                       toggle the state of FLAG on selected device
    -   set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
    -   toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
    -   unit UNIT                                set the default unit to UNIT
    -   version                                  display the version number and copyright information of GNU Parted
    - Report bugs to bug-parted@gnu.org
$ salt 'minion1' cmd.run 'parted -s /dev/vdc print'
minion1:
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdc: 5369MB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name  Flags
     1      1049kB  99.6MB  98.6MB  xfs          my

New Behavior

$ salt 'minion1' partition.name /dev/vdc 1 'my partition'
minion1:
$ salt 'minion1' cmd.run 'parted -s /dev/vdc print'
minion1:
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdc: 5369MB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name          Flags
     1      1049kB  99.6MB  98.6MB  xfs          my partition

Tests written?

No

Commits signed with GPG?

No

@@ -528,7 +528,7 @@ def name(device, partition, name):
'Invalid characters passed to partition.name'
)

cmd = 'parted -m -s {0} name {1} {2}'.format(device, partition, name)
cmd = '''parted -m -s {0} name {1} "'{2}'"'''.format(device, partition, name)

This comment has been minimized.

Copy link
@cachedout

cachedout Jun 8, 2018

Collaborator

This is syntactically valid but hard to read IMHO. What about

'parted -m -s {0} name {1} \"{2}\"'?

This comment has been minimized.

Copy link
@zer0def

zer0def Jun 8, 2018

Author Contributor

Thing here is that I deliberately use two different quoting marks to fool Parted into doing actual intent and I agree readability leaves a lot to expect. Interleaved examples follow

$ parted /dev/vdb name 1 'my partition'; parted /dev/vdb print
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
interactive mode.

OPTIONs:
  -h, --help                      displays this help message
  -l, --list                      lists partition layout on all block devices
  -m, --machine                   displays machine parseable output
  -s, --script                    never prompts for user intervention
  -v, --version                   displays the version
  -a, --align=[none|cyl|min|opt]  alignment for new partitions

COMMANDs:
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted

Report bugs to bug-parted@gnu.org
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  99.6MB  98.6MB               my

$ parted /dev/vdb name 1 '"my partition"'; parted /dev/vdb print
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name          Flags
 1      1049kB  99.6MB  98.6MB               my partition

$ parted /dev/vdb name 1 "my partition"; parted /dev/vdb print
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
interactive mode.

OPTIONs:
  -h, --help                      displays this help message
  -l, --list                      lists partition layout on all block devices
  -m, --machine                   displays machine parseable output
  -s, --script                    never prompts for user intervention
  -v, --version                   displays the version
  -a, --align=[none|cyl|min|opt]  alignment for new partitions

COMMANDs:
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted

Report bugs to bug-parted@gnu.org
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  99.6MB  98.6MB               my

$ parted /dev/vdb name 1 "'my partition'"; parted /dev/vdb print
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name          Flags
 1      1049kB  99.6MB  98.6MB               my partition
$ parted /dev/vdb name 1 \"my partition\"; parted /dev/vdb print
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
interactive mode.

OPTIONs:
  -h, --help                      displays this help message
  -l, --list                      lists partition layout on all block devices
  -m, --machine                   displays machine parseable output
  -s, --script                    never prompts for user intervention
  -v, --version                   displays the version
  -a, --align=[none|cyl|min|opt]  alignment for new partitions

COMMANDs:
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted

Report bugs to bug-parted@gnu.org
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  99.6MB  98.6MB               my

$ parted /dev/vdb name 1 \'my partition\'; parted /dev/vdb print
Usage: parted [OPTION]... [DEVICE [COMMAND [PARAMETERS]...]...]
Apply COMMANDs with PARAMETERS to DEVICE.  If no COMMAND(s) are given, run in
interactive mode.

OPTIONs:
  -h, --help                      displays this help message
  -l, --list                      lists partition layout on all block devices
  -m, --machine                   displays machine parseable output
  -s, --script                    never prompts for user intervention
  -v, --version                   displays the version
  -a, --align=[none|cyl|min|opt]  alignment for new partitions

COMMANDs:
  align-check TYPE N                        check partition N for TYPE(min|opt) alignment
  help [COMMAND]                           print general help, or help on COMMAND
  mklabel,mktable LABEL-TYPE               create a new disklabel (partition table)
  mkpart PART-TYPE [FS-TYPE] START END     make a partition
  name NUMBER NAME                         name partition NUMBER as NAME
  print [devices|free|list,all|NUMBER]     display the partition table, available devices, free space, all found partitions, or a particular partition
  quit                                     exit program
  rescue START END                         rescue a lost partition near START and END
  rm NUMBER                                delete partition NUMBER
  select DEVICE                            choose the device to edit
  disk_set FLAG STATE                      change the FLAG on selected device
  disk_toggle [FLAG]                       toggle the state of FLAG on selected device
  set NUMBER FLAG STATE                    change the FLAG on partition NUMBER
  toggle [NUMBER [FLAG]]                   toggle the state of FLAG on partition NUMBER
  unit UNIT                                set the default unit to UNIT
  version                                  display the version number and copyright information of GNU Parted

Report bugs to bug-parted@gnu.org
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 5369MB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
 1      1049kB  99.6MB  98.6MB               my

@rallytime rallytime requested a review from cachedout Jul 3, 2018

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Jul 27, 2018

@cachedout Can you respond to the comment/question above when you have a moment?

@cachedout cachedout merged commit 5aa282e into saltstack:2017.7 Aug 18, 2018

7 of 8 checks passed

jenkins/pr/py3-centos-7 The py3-centos-7 job has failed
Details
WIP ready for review
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint The lint job has passed
Details
jenkins/pr/py2-centos-7 The py2-centos-7 job has passed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has passed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.