Adding possibility to switch off hardcoded compute_node_address
parameter or override it.

If customer uses tenant network for compute nodes communication to
controlplane in OC 3.2, compute_node_address may break configuration
of a vrouter and prevent vrouter from start when switching vrouter
from discovery method to static.

Prod-Related: PROD-35730
Change-Id: I1d611b0b014e3fc671477f8131fd7e2990dbb432
diff --git a/README.rst b/README.rst
index 150fdd1..02c4da6 100644
--- a/README.rst
+++ b/README.rst
@@ -1579,6 +1579,27 @@
         nodemgr: 10
       ....
 
+[vRouter conf] compute_node_address
+-----------------------------------
+
+Specify an ip address to override compute_node_address value in vrouter config
+or set to false to unset it.
+Valid only for OpenContrail vRouter 3.2
+
+.. code-block:: yaml
+
+    opencontrail:
+      compute:
+        node_address:
+          value: 192.168.111.5
+
+   .. code-block:: yaml
+
+    opencontrail:
+      compute:
+        node_address:
+          enabled: false
+
 Disable database writes of collector
 ------------------------------------
 
diff --git a/opencontrail/files/3.0/contrail-vrouter-agent.conf b/opencontrail/files/3.0/contrail-vrouter-agent.conf
index 4e5a422..f177d23 100644
--- a/opencontrail/files/3.0/contrail-vrouter-agent.conf
+++ b/opencontrail/files/3.0/contrail-vrouter-agent.conf
@@ -225,11 +225,18 @@
 # this only if vhost interface is un-numbered in host-os. Agent will use one
 # of the compute_node_address to run services that need IP Address in host-os
 # (like metadata...)
-{%- if compute.bind is defined %}
-compute_node_address={{ compute.bind.address }}
-{%- else %}
-compute_node_address={{ compute.interface.address }}
-{%- endif %}
+ {%- if compute.bind is defined %}
+ {%-   set compute_node_address = compute.bind.address %}
+ {%- else %}
+ {%-   set compute_node_address = compute.interface.address %}
+ {%- endif %}
+ {%- if compute.node_address is defined %}
+ {%-   if compute.node_address.get('enabled', True) %}
+ compute_node_address={{ compute.node_address.get('value', compute_node_address) }}
+ {%-   endif %}
+ {%- else %}
+ compute_node_address={{ compute_node_address }}
+ {%- endif %}
 
 # We can have multiple gateway sections with different indices in the
 # following format
diff --git a/tests/pillar/vrouter.sls b/tests/pillar/vrouter.sls
index b3aa040..abfacb1 100644
--- a/tests/pillar/vrouter.sls
+++ b/tests/pillar/vrouter.sls
@@ -24,6 +24,8 @@
   compute:
     version: 4.1
     enabled: True
+    node_address:
+      enabled: false
     collector:
       members:
       - host: 127.0.0.1