[icinga-checkins] icinga.org: icingaweb2-module-director/master: IcingaCommandArgument: render set_if without format

git at icinga.org git at icinga.org
Tue Oct 11 11:45:27 CEST 2016


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

Author: Thomas Gelf <thomas at gelf.net>
Date:   Tue Oct 11 09:45:11 2016 +0000

IcingaCommandArgument: render set_if without format

Icinga DSL support was introduced in 348cb1aa6 and works fine, but breaks
rendering of legacy arguments with set_if_format = NULL. This should default
to 'string', as we should IMO not force NOT NULL in the DB in this case.

refs #12153
fixes #12886

---

 library/Director/Objects/IcingaCommandArgument.php     |    7 ++++---
 .../php/library/Director/Objects/IcingaCommandTest.php |   16 ++++++++++++++++
 .../php/library/Director/Objects/rendered/command7.out |    9 +++++++++
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/library/Director/Objects/IcingaCommandArgument.php b/library/Director/Objects/IcingaCommandArgument.php
index a6aea23..1f6f380 100644
--- a/library/Director/Objects/IcingaCommandArgument.php
+++ b/library/Director/Objects/IcingaCommandArgument.php
@@ -163,12 +163,13 @@ class IcingaCommandArgument extends IcingaObject
 
         if ($this->set_if) {
             switch ($this->set_if_format) {
-                case 'string':
-                    $data['set_if'] = c::renderString($this->set_if);
-                    break;
                 case 'expression':
                     $data['set_if'] = c::renderExpression($this->set_if);
                     break;
+                case 'string':
+                default:
+                    $data['set_if'] = c::renderString($this->set_if);
+                    break;
             }
         }
 
diff --git a/test/php/library/Director/Objects/IcingaCommandTest.php b/test/php/library/Director/Objects/IcingaCommandTest.php
index f2aa895..8c3dd20 100644
--- a/test/php/library/Director/Objects/IcingaCommandTest.php
+++ b/test/php/library/Director/Objects/IcingaCommandTest.php
@@ -174,6 +174,22 @@ class IcingaCommandTest extends BaseTestCase
         );
     }
 
+    public function testSimpleSetIfIsRendered()
+    {
+        $command = $this->command();
+        $command->command = 'bla';
+        $command->arguments = array(
+            '-a' => (object) array(
+                'set_if' => '$a$',
+            )
+        );
+
+        $this->assertEquals(
+            $this->loadRendered('command7'),
+            (string) $command
+        );
+    }
+
     protected function command()
     {
         return IcingaCommand::create(
diff --git a/test/php/library/Director/Objects/rendered/command7.out b/test/php/library/Director/Objects/rendered/command7.out
new file mode 100644
index 0000000..e422cd3
--- /dev/null
+++ b/test/php/library/Director/Objects/rendered/command7.out
@@ -0,0 +1,9 @@
+object CheckCommand "___TEST___command" {
+    command = [ PluginDir + "/bla" ]
+    arguments = {
+        "-a" = {
+            set_if = "$a$"
+        }
+    }
+}
+



More information about the icinga-checkins mailing list