Make maas saltstack_repo's logic more general

Change-Id: I71021489b79c27d9b46b796c34ded21c4ee6d734
diff --git a/README.rst b/README.rst
index 4cc62bd..aaef2fa 100644
--- a/README.rst
+++ b/README.rst
@@ -472,8 +472,8 @@
         MA==
         =dtMN
         -----END PGP PUBLIC KEY BLOCK-----
-      saltstack_repo_xenial: "http://${_param:local_repo_url}/ubuntu-xenial stable salt"
-      saltstack_repo_trusty: "http://${_param:local_repo_url}/ubuntu-trusty stable salt"
+      saltstack_repo_xenial: "deb [arch=amd64] http://${_param:local_repo_url}/ubuntu-xenial stable salt"
+      saltstack_repo_trusty: "deb [arch=amd64] http://${_param:local_repo_url}/ubuntu-trusty stable salt"
 
 Single MAAS cluster service [multiple racks]
 
diff --git a/_states/maasng.py b/_states/maasng.py
index 40ec9a4..31f8af6 100644
--- a/_states/maasng.py
+++ b/_states/maasng.py
@@ -567,7 +567,7 @@
 
     if __opts__['test']:
         ret['result'] = None
-        ret['comment'] = 'fabric {0} will be updated for {1}'.format(vlan, name)
+        ret['comment'] = 'fabric {0} will be updated'.format(name)
         return ret
     # All requested subnets
     _r_subnets = __salt__['config.get']('maas').get('region', {}).get('subnets',
diff --git a/maas/files/curtin_userdata_amd64_generic_trusty b/maas/files/curtin_userdata_amd64_generic_trusty
index 1ff17dd..3c817fa 100644
--- a/maas/files/curtin_userdata_amd64_generic_trusty
+++ b/maas/files/curtin_userdata_amd64_generic_trusty
@@ -18,15 +18,18 @@
 late_commands:
   maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
 {% endraw %}
-{%- if not cluster.saltstack_repo_key == 'none' %}
-{% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
+{%- if cluster.get('saltstack_repo_key', False) %}
+  {% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
   apt_00_set_gpg: ["curtin", "in-target", "--", "sh", "-c", "echo '{{salt_repo_key}}' | base64 -d | apt-key add -"]
 {%- endif %}
-  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo 'deb [arch=amd64] {{ cluster.saltstack_repo_trusty }}' >> /etc/apt/sources.list"]
-{% raw %}
+{% if cluster.saltstack_repo_trusty.startswith('deb') %}
+  {%- set saltstack_repo = cluster.saltstack_repo_trusty -%}
+{%- else %}
+  {%- set saltstack_repo = 'deb [arch=amd64]' + cluster.region.host|string + '/MAAS' -%}
+{%- endif %}
+  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo '{{ saltstack_repo }}' >> /etc/apt/sources.list.d/mcp_saltstack.list"]
   apt_03_update: ["curtin", "in-target", "--", "apt-get", "update"]
   salt_01_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "salt-minion"]
-{% endraw %}
   salt_02_hostname_set: ["curtin", "in-target", "--", "echo", "{% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}"]
   salt_03_hostname_get: ["curtin", "in-target", "--", "sh", "-c", "echo 'id: {% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}' >> /etc/salt/minion"]
   salt_04_master: ["curtin", "in-target", "--", "sh", "-c", "echo 'master: {{ salt_master_ip }}' >> /etc/salt/minion"]
@@ -40,4 +43,4 @@
   driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
   driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]
 {{endif}}
-{% endraw %}
\ No newline at end of file
+{% endraw %}
diff --git a/maas/files/curtin_userdata_amd64_generic_xenial b/maas/files/curtin_userdata_amd64_generic_xenial
index 55e0901..6152827 100644
--- a/maas/files/curtin_userdata_amd64_generic_xenial
+++ b/maas/files/curtin_userdata_amd64_generic_xenial
@@ -18,15 +18,18 @@
 late_commands:
   maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
 {% endraw %}
-{%- if not cluster.saltstack_repo_key == 'none' %}
-{% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
+{%- if cluster.get('saltstack_repo_key', False) %}
+  {% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
   apt_00_set_gpg: ["curtin", "in-target", "--", "sh", "-c", "echo '{{salt_repo_key}}' | base64 -d | apt-key add -"]
 {%- endif %}
-  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo 'deb [arch=amd64] {{ cluster.saltstack_repo_xenial }}' >> /etc/apt/sources.list"]
-{% raw %}
+{% if cluster.saltstack_repo_xenial.startswith('deb') %}
+  {%- set saltstack_repo = cluster.saltstack_repo_xenial -%}
+{%- else %}
+  {%- set saltstack_repo = 'deb [arch=amd64]' + cluster.region.host|string + '/MAAS' -%}
+{%- endif %}
+  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo '{{ saltstack_repo }}' >> /etc/apt/sources.list.d/mcp_saltstack.list"]
   apt_03_update: ["curtin", "in-target", "--", "apt-get", "update"]
   salt_01_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "salt-minion"]
-{% endraw %}
   salt_02_hostname_set: ["curtin", "in-target", "--", "echo", "{% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}"]
   salt_03_hostname_get: ["curtin", "in-target", "--", "sh", "-c", "echo 'id: {% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}' >> /etc/salt/minion"]
   salt_04_master: ["curtin", "in-target", "--", "sh", "-c", "echo 'master: {{ salt_master_ip }}' >> /etc/salt/minion"]
@@ -40,4 +43,4 @@
   driver_06_depmod: ["curtin", "in-target", "--", "depmod"]
   driver_07_update_initramfs: ["curtin", "in-target", "--", "update-initramfs", "-u"]
 {{endif}}
-{% endraw %}
\ No newline at end of file
+{% endraw %}
diff --git a/maas/files/curtin_userdata_arm64_generic_xenial b/maas/files/curtin_userdata_arm64_generic_xenial
index 21877b2..a04d575 100644
--- a/maas/files/curtin_userdata_arm64_generic_xenial
+++ b/maas/files/curtin_userdata_arm64_generic_xenial
@@ -18,16 +18,19 @@
 late_commands:
   maas: [wget, '--no-proxy', {{node_disable_pxe_url|escape.json}}, '--post-data', {{node_disable_pxe_data|escape.json}}, '-O', '/dev/null']
 {% endraw %}
-{%- if not cluster.saltstack_repo_key == 'none' %}
-{% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
+{%- if cluster.get('saltstack_repo_key', False) %}
+  {% set salt_repo_key = salt['hashutil.base64_b64encode'](cluster.saltstack_repo_key) %}
   apt_00_set_gpg: ["curtin", "in-target", "--", "sh", "-c", "echo '{{salt_repo_key}}' | base64 -d | apt-key add -"]
 {%- endif %}
+{% if cluster.saltstack_repo_xenial.startswith('deb') %}
+  {%- set saltstack_repo = cluster.saltstack_repo_xenial -%}
+{%- else %}
+  {%- set saltstack_repo = 'deb [arch=amd64]' + cluster.region.host|string + '/MAAS' -%}
+{%- endif %}
 {#- NOTE: Re-use amd64 repos on arm64 since most packages are arch independent #}
-  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo 'deb [arch=amd64] {{ cluster.saltstack_repo_xenial }}' >> /etc/apt/sources.list"]
-{% raw %}
+  apt_01_set_repo: ["curtin", "in-target", "--", "sh", "-c", "echo '{{ saltstack_repo }}' >> /etc/apt/sources.list.d/mcp_saltstack.list"]
   apt_03_update: ["curtin", "in-target", "--", "apt-get", "update"]
-  salt_01_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "python-futures", "salt-minion"]
-{% endraw %}
+  salt_01_install: ["curtin", "in-target", "--", "apt-get", "-y", "install", "salt-minion", "python-futures"]
   salt_02_hostname_set: ["curtin", "in-target", "--", "echo", "{% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}"]
   salt_03_hostname_get: ["curtin", "in-target", "--", "sh", "-c", "echo 'id: {% raw %}{{node.hostname}}{% endraw %}.{{pillar.linux.system.domain}}' >> /etc/salt/minion"]
   salt_04_master: ["curtin", "in-target", "--", "sh", "-c", "echo 'master: {{ salt_master_ip }}' >> /etc/salt/minion"]
diff --git a/metadata/service/cluster/single.yml b/metadata/service/cluster/single.yml
index a307dcc..de8cf8a 100644
--- a/metadata/service/cluster/single.yml
+++ b/metadata/service/cluster/single.yml
@@ -41,5 +41,5 @@
         MA==
         =dtMN
         -----END PGP PUBLIC KEY BLOCK-----
-      saltstack_repo_trusty: "http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/ trusty main"
-      saltstack_repo_xenial: "http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/ xenial main"
+      saltstack_repo_trusty: "deb [arch=amd64] http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/ trusty main"
+      saltstack_repo_xenial: "deb [arch=amd64] http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/ xenial main"
diff --git a/tests/pillar/maas_cluster.sls b/tests/pillar/maas_cluster.sls
index 641cfb6..fedb491 100644
--- a/tests/pillar/maas_cluster.sls
+++ b/tests/pillar/maas_cluster.sls
@@ -37,8 +37,8 @@
       MA==
       =dtMN
       -----END PGP PUBLIC KEY BLOCK-----
-    saltstack_repo_trusty: "http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/ trusty main"
-    saltstack_repo_xenial: "http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/ xenial main"
+    saltstack_repo_trusty: "deb [arch=amd64] http://repo.saltstack.com/apt/ubuntu/14.04/amd64/2016.3/ trusty main"
+    saltstack_repo_xenial: "deb [arch=amd64] http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/ xenial main"
   region:
     theme: mirantis
     bind: