Use unless to determine whether to create partition

Change-Id: I1c35eb045a46b95f75c7101567d4c4f340b787ab
diff --git a/linux/storage/disk.sls b/linux/storage/disk.sls
index d542a67..c200258 100644
--- a/linux/storage/disk.sls
+++ b/linux/storage/disk.sls
@@ -5,30 +5,32 @@
   pkg.installed
 
 {%- for disk_name, disk in storage.disk.iteritems() %}
+{%- set disk_name = disk.name|default(disk_name) %}
 
-{%- if disk.type is defined %}
 create_disk_label:
   module.run:
   - name: partition.mklabel
-  - device: {{ disk.name|default(disk_name) }}
-  - label_type: {{ disk.get('type', 'gpt') }}
-  - unless: fdisk -l | grep {{ disk.get('type', 'gpt') }}
-{%- endif %}
+  - device: {{ disk_name }}
+  - label_type: {{ disk.get('type', 'dos') }}
+  - unless: "fdisk -l {{ disk_name }} | grep -i 'Disklabel type: {{ disk.get('type', 'dos') }}'"
+  - require:
+    - pkg: parted
 
 {% set end_size = 0 -%}
 
 {%- for partition in disk.get('partitions', []) %}
 
-{%- if not salt['partition.exists'](disk.get('name', disk_name)+'p'~loop.index) %}
-create_partition_{{ disk.name|default(disk_name) }}_{{ loop.index }}:
+create_partition_{{ disk_name }}_{{ loop.index }}:
   module.run:
   - name: partition.mkpart
-  - device: {{ disk.name|default(disk_name) }}
+  - device: {{ disk_name }}
   - part_type: primary
   - fs_type: {{ partition.type }}
   - start: {{ end_size }}MB
   - end: {{ end_size + partition.size }}MB
-{%- endif %}
+  - unless: "blkid {{ disk_name }}{{ loop.index }} {{ disk_name }}p{{ loop.index }}"
+  - require:
+    - module: create_disk_label
 
 {% set end_size = end_size + partition.size -%}