add a new umounted state to tmp_functions and use it in ami_creator_post
authorPaul Tonelli <paul.tonelli@logilab.fr>
Tue, 05 Mar 2013 15:41:49 +0100
changeset 17 05455a83e87e
parent 16 5cb811380247
child 18 4239da26bf7c
add a new umounted state to tmp_functions and use it in ami_creator_post
_states/tmp_func.py
ami_creator_post.sls
ami_creator_pre.sls
--- a/_states/tmp_func.py	Tue Mar 05 15:43:01 2013 +0100
+++ b/_states/tmp_func.py	Tue Mar 05 15:41:49 2013 +0100
@@ -33,4 +33,28 @@
             ret['result'] = False
     return ret
 
+def umounted(name):
+    ret = {'name': name,
+            'changes': {},
+            'result': True,
+            'comment':  ''}
+    if __opts__['test']:
+        ret['result'] = None
+        ret['comment'] = 'Umounted will check that there is nothing mounted in {0}, no recursion'.format(name)
+        return ret
+    active = __salt__['mount.active']()
+    if name in active:
+        for mount in active:
+            if name in mount and str(name) != str(mount) :
+                ret['result'] = False
+                ret['comment'] = 'cannot umount while subdirectory {0} is a mounting point for {1}'.format(name, mount)
+        if ret['result']:
+            output = __salt__['mount.umount'](name)
+            print type(mount)
+            if output == True:
+                ret['changes']['umount'] = 'device {1} has been umounted from {0}'.format(name, active[mount]['device'])
+            else:
+                ret['reslt'] = False
+                ret['comment'] = output
+    return ret
 
--- a/ami_creator_post.sls	Tue Mar 05 15:43:01 2013 +0100
+++ b/ami_creator_post.sls	Tue Mar 05 15:41:49 2013 +0100
@@ -1,6 +1,18 @@
-# /srv/salt/init_machine.sls
-#
-chroot_proc:
+### Salt state to check after modifying chroot ###
+
+### umounts ###
+umount_chroot_proc:
     tmp_func.umounted:
         - name: /mnt/variation/proc
 
+umount_chroot_devpts:
+    tmp_func.umounted:
+        - name: /mnt/variation/dev/pts
+
+umount_chroot_slash:
+    tmp_func.umounted:
+        - name:/mnt/variation
+    require:
+        - umount_chroot_devpts
+        - umount_chroot_proc
+
--- a/ami_creator_pre.sls	Tue Mar 05 15:43:01 2013 +0100
+++ b/ami_creator_pre.sls	Tue Mar 05 15:41:49 2013 +0100
@@ -1,5 +1,4 @@
-# /srv/salt/init_machine.sls
-#
+### Salt state to check before modifying chroot ###
 
 base_pkgs:
     pkg.installed: