Manage grains using support metadata

Change-Id: I25fb0eb0d4b922b8853eceb0c1c220a4040e1704
diff --git a/linux/files/sphinx.grain b/linux/files/sphinx.grain
deleted file mode 100644
index f439be9..0000000
--- a/linux/files/sphinx.grain
+++ /dev/null
@@ -1,10 +0,0 @@
-{%- set service_grains = {'sphinx': {'doc': {}}} %}
-{%- for service_name, service in pillar.items() %}
-{%- if service.get('_support', {}).get('sphinx', {}).get('enabled', False) %}
-{%- set grains_fragment_file = service_name+'/meta/sphinx.yml' %}
-{%- macro load_grains_file() %}{% include grains_fragment_file %}{% endmacro %}
-{%- set grains_yaml = load_grains_file()|load_yaml %}
-{%- set _dummy = service_grains.sphinx.doc.update({ service_name: grains_yaml.doc }) %}
-{%- endif %}
-{%- endfor %}
-{{ service_grains|yaml(False) }}
\ No newline at end of file
diff --git a/linux/map.jinja b/linux/map.jinja
index 34ec075..5e865fb 100644
--- a/linux/map.jinja
+++ b/linux/map.jinja
@@ -18,7 +18,6 @@
          },
         'selinux': 'permissive',
         'ca_certs_dir': '/usr/local/share/ca-certificates',
-        'doc_validity_pkgs': ['python-yaml'],
     },
     'Debian': {
         'pkgs': ['python-apt', 'apt-transport-https', 'libmnl0'],
@@ -39,7 +38,6 @@
          },
         'selinux': 'permissive',
         'ca_certs_dir': '/usr/local/share/ca-certificates',
-        'doc_validity_pkgs': ['python-yaml'],
     },
     'RedHat': {
         'pkgs': ['policycoreutils', 'policycoreutils-python', 'telnet', 'wget'],
@@ -60,7 +58,6 @@
          },
         'selinux': 'permissive',
         'ca_certs_dir': '/usr/local/share/ca-certificates',
-        'doc_validity_pkgs': ['PyYAML'],
     },
 }, grain='os_family', merge=salt['pillar.get']('linux:system')) %}
 
diff --git a/linux/meta/salt.yml b/linux/meta/salt.yml
index 183994a..0a07522 100644
--- a/linux/meta/salt.yml
+++ b/linux/meta/salt.yml
@@ -1,3 +1,4 @@
+{%- from "linux/map.jinja" import system with context -%}
 orchestrate:
   system:
     priority: 30
@@ -5,4 +6,15 @@
     priority: 40
   storage:
     priority: 50
-
+grain:
+  sphinx:
+    {%- set service_grains = {'sphinx': {'doc': {}}} %}
+    {%- for service_name, service in pillar.items() %}
+      {%- if service.get('_support', {}).get('sphinx', {}).get('enabled', False) %}
+        {%- set grains_fragment_file = service_name+'/meta/sphinx.yml' %}
+        {%- macro load_grains_file() %}{% include grains_fragment_file %}{% endmacro %}
+        {%- set grains_yaml = load_grains_file()|load_yaml %}
+        {%- do service_grains.sphinx.doc.update({ service_name: grains_yaml.doc }) %}
+      {%- endif %}
+    {%- endfor %}
+    {{ service_grains|yaml(False)|indent(4) }}
diff --git a/linux/system/doc.sls b/linux/system/doc.sls
index 64c9d0a..b679c94 100644
--- a/linux/system/doc.sls
+++ b/linux/system/doc.sls
@@ -1,30 +1,10 @@
 {%- from "linux/map.jinja" import system with context %}
 {%- if system.enabled %}
 
-linux_system_doc_grains_dir:
-  file.directory:
-  - name: /etc/salt/grains.d
-  - mode: 700
-  - makedirs: true
-  - user: root
+# This state is obsolete, grains are now managed from salt.minion.grains so we
+# will just include it
 
-linux_system_doc_grain:
-  file.managed:
-  - name: /etc/salt/grains.d/sphinx
-  - source: salt://linux/files/sphinx.grain
-  - template: jinja
-  - mode: 600
-  - require:
-    - file: linux_system_doc_grains_dir
-
-linux_system_doc_validity_check:
-  pkg.installed:
-  - pkgs: {{ system.doc_validity_pkgs }}
-  cmd.wait:
-  - name: python -c "import yaml; stream = file('/etc/salt/grains.d/sphinx', 'r'); yaml.load(stream); stream.close()"
-  - require:
-    - pkg: linux_system_doc_validity_check
-  - watch:
-    - file: linux_system_doc_grain
+include:
+  - salt.minion.grains
 
 {%- endif %}
diff --git a/linux/system/init.sls b/linux/system/init.sls
index 45700f0..3961bca 100644
--- a/linux/system/init.sls
+++ b/linux/system/init.sls
@@ -59,9 +59,6 @@
 {%- if system.console is defined %}
 - linux.system.console
 {%- endif %}
-{%- if system.doc is defined %}
-- linux.system.doc
-{%- endif %}
 {%- if system.limit|length > 0 %}
 - linux.system.limit
 {%- endif %}