From efc90a8fd471ada4b5de71331935e2c46a35b4b1 Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Thu, 17 Jul 2014 13:09:12 +0200 Subject: [PATCH] Extend cinder::setup_test_volume to use cinder provided path cinder::setup_test_volume should now support RHEL6 and RHEL7 and also Fedora systems. It should use cinder provided path and not file in /tmp and it should set correct permissions to it. Change-Id: Iee783a3445c97b6559d63d0d501b12028b7b2b26 --- manifests/setup_test_volume.pp | 30 +++++++++++++------ manifests/type_set.pp | 2 +- spec/classes/cinder_setup_test_volume_spec.rb | 15 +++++++--- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/manifests/setup_test_volume.pp b/manifests/setup_test_volume.pp index f8a2452d..e747e101 100644 --- a/manifests/setup_test_volume.pp +++ b/manifests/setup_test_volume.pp @@ -13,33 +13,45 @@ # [*loopback_device*] # Loop device name. Defaults to '/dev/loop2'. # +# [*volume_path*] +# Volume image location. Defaults to '/var/lib/cinder'. class cinder::setup_test_volume( $volume_name = 'cinder-volumes', + $volume_path = '/var/lib/cinder', $size = '4G', $loopback_device = '/dev/loop2' ) { - Exec { - cwd => '/tmp/', - } - package { 'lvm2': ensure => present, } ~> - exec { "/bin/dd if=/dev/zero of=${volume_name} bs=1 count=0 seek=${size}": - unless => "/sbin/vgdisplay ${volume_name}" + file { $volume_path: + ensure => directory, + owner => 'cinder', + group => 'cinder', + require => Package['cinder'], } ~> - exec { "/sbin/losetup ${loopback_device} ${volume_name}": + exec { "create_${volume_path}/${volume_name}": + command => "dd if=/dev/zero of=\"${volume_path}/${volume_name}\" bs=1 count=0 seek=${size}", + path => ['/bin','/usr/bin','/sbin','/usr/sbin'], + unless => "stat ${volume_path}/${volume_name}", + } ~> + + exec { "losetup ${loopback_device} ${volume_path}/${volume_name}": + path => ['/bin','/usr/bin','/sbin','/usr/sbin'], refreshonly => true, } ~> - exec { "/sbin/pvcreate ${loopback_device}": + exec { "pvcreate ${loopback_device}": + path => ['/bin','/usr/bin','/sbin','/usr/sbin'], + unless => "pvdisplay | grep ${volume_name}", refreshonly => true, } ~> - exec { "/sbin/vgcreate ${volume_name} ${loopback_device}": + exec { "vgcreate ${volume_name} ${loopback_device}": + path => ['/bin','/usr/bin','/sbin','/usr/sbin'], refreshonly => true, } diff --git a/manifests/type_set.pp b/manifests/type_set.pp index dc798815..acbe7fda 100644 --- a/manifests/type_set.pp +++ b/manifests/type_set.pp @@ -56,7 +56,7 @@ define cinder::type_set ( } exec {"cinder type-key ${type} set ${key}=${name}": - path => '/usr/bin', + path => ['/usr/bin', '/bin'], command => "cinder type-key ${type} set ${key}=${name}", environment => concat($cinder_env, $region_env), require => Package['python-cinderclient'] diff --git a/spec/classes/cinder_setup_test_volume_spec.rb b/spec/classes/cinder_setup_test_volume_spec.rb index 42209548..678e196c 100644 --- a/spec/classes/cinder_setup_test_volume_spec.rb +++ b/spec/classes/cinder_setup_test_volume_spec.rb @@ -6,10 +6,17 @@ describe 'cinder::setup_test_volume' do :ensure => 'present' ) } + it { should contain_file('/var/lib/cinder').with( + :ensure => 'directory', + :require => 'Package[cinder]' + ) } + it 'should contain volume creation execs' do - should contain_exec('/bin/dd if=/dev/zero of=cinder-volumes bs=1 count=0 seek=4G') - should contain_exec('/sbin/losetup /dev/loop2 cinder-volumes') - should contain_exec('/sbin/pvcreate /dev/loop2') - should contain_exec('/sbin/vgcreate cinder-volumes /dev/loop2') + should contain_exec('create_/var/lib/cinder/cinder-volumes').with( + :command => 'dd if=/dev/zero of="/var/lib/cinder/cinder-volumes" bs=1 count=0 seek=4G' + ) + should contain_exec('losetup /dev/loop2 /var/lib/cinder/cinder-volumes') + should contain_exec('pvcreate /dev/loop2') + should contain_exec('vgcreate cinder-volumes /dev/loop2') end end