fix maas cluster .region binding

  * maas.region state fails as default bind port was 80
    instead of passed one.

PROD-18527

Change-Id: I09eab6cf4541d6d88eec3126c73e9cfe457849d0
diff --git a/.kitchen.yml b/.kitchen.yml
index 9d4e118..4cd5d08 100644
--- a/.kitchen.yml
+++ b/.kitchen.yml
@@ -77,9 +77,9 @@
       #pillars-from-files:
         #maas.sls: tests/pillar/maas_mirror.sls
 
-  #- name: maas_region
-    #provisioner:
-      #pillars-from-files:
-        #maas.sls: tests/pillar/maas_region.sls
+#  - name: maas_region
+#    provisioner:
+#      pillars-from-files:
+#        maas.sls: tests/pillar/maas_region.sls
 
 # vim: ft=yaml sw=2 ts=2 sts=2 tw=125
diff --git a/maas/cluster.sls b/maas/cluster.sls
index ad15c63..bfb584f 100644
--- a/maas/cluster.sls
+++ b/maas/cluster.sls
@@ -40,7 +40,12 @@
 
 /etc/maas/rackd.conf:
   file.line:
-  - content: 'maas_url: http://{{ cluster.region.host }}/MAAS'
+{%- if cluster.region.get('port', False)  %}
+  {%- set maas_url = 'http://' + cluster.region.host|string + ':' + cluster.region.port|string + '/MAAS' -%}
+{%- else %}
+  {%- set maas_url = 'http://' + cluster.region.host|string + '/MAAS' -%}
+{%- endif %}
+  - content: "maas_url: {{ maas_url }}"
   - match: 'maas_url*'
   - mode: replace
   - location: end
diff --git a/tests/pillar/maas_region.sls b/tests/pillar/maas_region.sls
index 607b472..a150389 100644
--- a/tests/pillar/maas_region.sls
+++ b/tests/pillar/maas_region.sls
@@ -3,13 +3,15 @@
     enabled: true
     region:
       host: localhost
+      port: 80
     role: master
     enable_iframe: True
   region:
-    theme: theme
+    enabled: true
     bind:
       host: localhost
       port: 80
+    theme: theme
     admin:
       username: admin
       password: password
@@ -20,5 +22,4 @@
       name: maasdb
       password: password
       username: maas
-    enabled: true
     salt_master_ip: 127.0.0.1