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

Handle undef value in lvm::logical_volume #105

Merged
merged 1 commit into from Apr 23, 2015

Conversation

riton
Copy link
Contributor

@riton riton commented Apr 22, 2015

When an undef value is passed as lvm::logical_volume name, mkfs is called with unwanted command line like

Error: Execution of 'mkfs.ext4 /dev/rootvg/' returned 1: mke2fs 1.42.9 (28-Dec-2013)
/dev/rootvg/ is not a block special device.
Proceed anyway? (y,n)
Error: /Stage[main]/Main/Lvm::Logical_volume[undef]/Filesystem[/dev/rootvg/]/ensure: change from absent to present failed: Execution of 'mkfs.ext4 /dev/rootvg/' returned 1: mke2fs 1.42.9 (28-Dec-2013)
/dev/rootvg/ is not a block special device.
Proceed anyway? (y,n)

This does not break anything, but we're here protected by mkfs that asks for confirmation (this fails in batch mode).

This patch only introduces a stupid test to check that $name isn't  undef.

My software versions:

  • CentOS 7
  • puppet v3.7.2
  • ruby 2.0.0p353

* when an undef value was passed as lvm::logical_volume name, mkfs was called with unwanted command line like

```
Error: Execution of 'mkfs.ext4 /dev/rootvg/' returned 1: mke2fs 1.42.9 (28-Dec-2013)
/dev/rootvg/ is not a block special device.
Proceed anyway? (y,n)
Error: /Stage[main]/Main/Lvm::Logical_volume[undef]/Filesystem[/dev/rootvg/]/ensure: change from absent to present failed: Execution of 'mkfs.ext4 /dev/rootvg/' returned 1: mke2fs 1.42.9 (28-Dec-2013)
/dev/rootvg/ is not a block special device.
Proceed anyway? (y,n)
```
@bmjen
Copy link
Contributor

bmjen commented Apr 22, 2015

Thanks @riton! Is it possible to get a sample manifest that would produce this error?

@underscorgan
Copy link
Contributor

@riton I don't understand how this error could possibly happen, name is required :\

@riton
Copy link
Contributor Author

riton commented Apr 23, 2015

I know that nameis required. I found this error with a manifest like:

class myclass($lv_name)
{
    ::lvm::logical_volume { $lvname:
        ensure            => present,
        volume_group      => 'rootvg',
        size              => '1G',
        fs_type           => 'ext4',
        mountpath         => '/tmp',
        mountpath_require => false
    }
}
class { '::myclass': lv_name => 'foo' }

A simple typo in my variable name ($lvname instead of $lv_name) scares me when I saw that mkfs was called on /dev/${vg_name}/.

This could also happen if someone does not do proper user input validation in its manifest like in:

class myclass2($lv_name = undef) 
{
    ::lvm::logical_volume { $lv_name:
      [...]
     }
}
class { '::myclass2': }

I know that this is not supposed to happen, but considering that the final process is mkfs and that it can possibly break things on the system, I think it's worth a simple test for undefined value.

@bmjen
Copy link
Contributor

bmjen commented Apr 23, 2015

@riton You are correct, a situation like the one you listed could definitely pass through an undef $name. I will merge.

bmjen added a commit that referenced this pull request Apr 23, 2015
Handle undef value in lvm::logical_volume
@bmjen bmjen merged commit 2c1fbbe into puppetlabs:master Apr 23, 2015
@underscorgan
Copy link
Contributor

o.O

Good catch, @riton !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants