[icinga-checkins] icinga.org: icingaweb2-module-director/master: Expressions syntax is now $var$

git at icinga.org git at icinga.org
Tue Oct 25 04:39:55 CEST 2016


Module: icingaweb2-module-director
Branch: master
Commit: 37c91050c7bf2b8436d9e0094bbda61257a64fa7
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=37c91050c7bf2b8436d9e0094bbda61257a64fa7

Author: Corentin Ardeois <cardeois at internap.com>
Date:   Thu Sep  8 11:29:46 2016 -0400

Expressions syntax is now $var$

Instead of $$var$$.
We make sure $$var$$ is left untouched.

refs #11976

---

 library/Director/IcingaConfig/IcingaConfigHelper.php |    2 +-
 .../Director/CustomVariable/CustomVariablesTest.php  |    2 +-
 .../Director/IcingaConfig/IcingaConfigHelperTest.php |   18 ++++++++++--------
 .../library/Director/Objects/IcingaServiceTest.php   |   12 ++++++------
 .../library/Director/Objects/rendered/service3.out   |    8 ++++----
 .../library/Director/Objects/rendered/service4.out   |    6 +++---
 6 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/library/Director/IcingaConfig/IcingaConfigHelper.php b/library/Director/IcingaConfig/IcingaConfigHelper.php
index 14b8c5d..edc113b 100644
--- a/library/Director/IcingaConfig/IcingaConfigHelper.php
+++ b/library/Director/IcingaConfig/IcingaConfigHelper.php
@@ -263,7 +263,7 @@ class IcingaConfigHelper
     }
 
     private static function renderStringWithVariables($string) {
-        $string = preg_replace('/\$\$([\w\.]+)\$\$/', '" + ${1} + "', $string);
+        $string = preg_replace('/(?<!\$)\$([\w\.]+)\$(?!\$)/', '" + ${1} + "', $string);
         $string = '"' . $string . '"';
         if (substr($string, 0, 5) === '"" + ') {
             $string = substr($string, 5);
diff --git a/test/php/library/Director/CustomVariable/CustomVariablesTest.php b/test/php/library/Director/CustomVariable/CustomVariablesTest.php
index 8963c51..ba1e25a 100644
--- a/test/php/library/Director/CustomVariable/CustomVariablesTest.php
+++ b/test/php/library/Director/CustomVariable/CustomVariablesTest.php
@@ -48,7 +48,7 @@ class CustomVariablesTest extends BaseTestCase
     {
         $vars = $this->newVars();
         $vars->bla = 'da';
-        $vars->abc = '$$val$$';
+        $vars->abc = '$val$';
         $expected = $this->indentVarsList(array(
             'vars.abc = val',
             'vars.bla = "da"'
diff --git a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php
index f2e709b..ff2b861 100644
--- a/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php
+++ b/test/php/library/Director/IcingaConfig/IcingaConfigHelperTest.php
@@ -83,19 +83,21 @@ class IcingaConfigHelperTest extends BaseTestCase
 
     public function testRenderStringWithVariables()
     {
-        $this->assertEquals(c::renderString('Before $$var$$', true), '"Before " + var');
-        $this->assertEquals(c::renderString('$$var$$ After', true), 'var + " After"');
-        $this->assertEquals(c::renderString('$$var$$', true), 'var');
+        $this->assertEquals(c::renderString('Before $var$', true), '"Before " + var');
+        $this->assertEquals(c::renderString('$var$ After', true), 'var + " After"');
+        $this->assertEquals(c::renderString('$var$', true), 'var');
+        $this->assertEquals(c::renderString('$$var$$', true), '"$$var$$"');
+        $this->assertEquals(c::renderString('Before $$var$$ After', true), '"Before $$var$$ After"');
         $this->assertEquals(
-            c::renderString('Before $$name$$ $$name$$ After', true),
+            c::renderString('Before $name$ $name$ After', true),
             '"Before " + name + " " + name + " After"');
         $this->assertEquals(
-            c::renderString('Before $$var1$$ $$var2$$ After', true),
+            c::renderString('Before $var1$ $var2$ After', true),
             '"Before " + var1 + " " + var2 + " After"');
-        $this->assertEquals(c::renderString('$$host.vars.custom$$', true), 'host.vars.custom');
-        $this->assertEquals(c::renderString('$$var"$$', true), '"$$var\"$$"');
+        $this->assertEquals(c::renderString('$host.vars.custom$', true), 'host.vars.custom');
+        $this->assertEquals(c::renderString('$var"$', true), '"$var\"$"');
         $this->assertEquals(
-            c::renderString('\tI am\rrendering\nproperly\fand I $$support$$ "multiple" $$variables$$\$', true),
+            c::renderString('\tI am\rrendering\nproperly\fand I $support$ "multiple" $variables$\$', true),
             '"\\\\tI am\\\\rrendering\\\\nproperly\\\\fand I " + support + " \"multiple\" " + variables + "\\\\$"');
     }
 }
diff --git a/test/php/library/Director/Objects/IcingaServiceTest.php b/test/php/library/Director/Objects/IcingaServiceTest.php
index a682140..efbc18c 100644
--- a/test/php/library/Director/Objects/IcingaServiceTest.php
+++ b/test/php/library/Director/Objects/IcingaServiceTest.php
@@ -242,13 +242,13 @@ class IcingaServiceTest extends BaseTestCase
 
         $db = $this->getDb();
 
-        $service = $this->service('___TEST___service_$$not_replaced$$');
+        $service = $this->service('___TEST___service_$not_replaced$');
         $service->object_type = 'apply';
-        $service->display_name = 'Service: $$replaced$$';
+        $service->display_name = 'Service: $host.vars.replaced$';
         $service->assignments = array(
             'host.address="127.*"',
         );
-        $service->{'vars.custom_var'} = '$$replaced$$';
+        $service->{'vars.custom_var'} = '$host.vars.replaced$';
         $service->store($db);
 
         $service = IcingaService::loadWithAutoIncId($service->id, $db);
@@ -266,10 +266,10 @@ class IcingaServiceTest extends BaseTestCase
 
         $db = $this->getDb();
 
-        $service = $this->service('___TEST___service_$$not_replaced$$');
+        $service = $this->service('___TEST___service_$not_replaced$');
         $service->object_type = 'object';
-        $service->display_name = 'Service: $$not_replaced$$';
-        $service->{'vars.custom_var'} = '$$not_replaced$$';
+        $service->display_name = 'Service: $host.vars.not_replaced$';
+        $service->{'vars.custom_var'} = '$host.vars.not_replaced$';
         $service->store($db);
 
         $service = IcingaService::loadWithAutoIncId($service->id, $db);
diff --git a/test/php/library/Director/Objects/rendered/service3.out b/test/php/library/Director/Objects/rendered/service3.out
index 2023ef8..ad39128 100644
--- a/test/php/library/Director/Objects/rendered/service3.out
+++ b/test/php/library/Director/Objects/rendered/service3.out
@@ -1,6 +1,6 @@
-apply Service "___TEST___service_$$not_replaced$$" {
-    display_name = "Service: " + replaced
-    vars.custom_var = replaced
+apply Service "___TEST___service_$not_replaced$" {
+    display_name = "Service: " + host.vars.replaced
+    vars.custom_var = host.vars.replaced
     vars.test1 = "string"
     vars.test2 = 17
     vars.test3 = false
@@ -11,6 +11,6 @@ apply Service "___TEST___service_$$not_replaced$$" {
 
     assign where match("127.*", host.address)
 
-    import "host var overrides (Director)"
+    import DirectorOverrideTemplate
 }
 
diff --git a/test/php/library/Director/Objects/rendered/service4.out b/test/php/library/Director/Objects/rendered/service4.out
index 1b607a5..ef87fc8 100644
--- a/test/php/library/Director/Objects/rendered/service4.out
+++ b/test/php/library/Director/Objects/rendered/service4.out
@@ -1,6 +1,6 @@
-object Service "___TEST___service_$$not_replaced$$" {
-    display_name = "Service: $$not_replaced$$"
-    vars.custom_var = "$$not_replaced$$"
+object Service "___TEST___service_$not_replaced$" {
+    display_name = "Service: $host.vars.not_replaced$"
+    vars.custom_var = "$host.vars.not_replaced$"
     vars.test1 = "string"
     vars.test2 = 17
     vars.test3 = false



More information about the icinga-checkins mailing list