From 396d8399ee79c7630ebfcff1997f044ad4978496 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 27 Aug 2017 18:11:15 +0200 Subject: [PATCH 1/8] gitlab: verbose output --- .gitlab-ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 58ddbb2c..9b0d2613 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -22,7 +22,7 @@ CentOS 7/MySQL: after_script: - mysql -u root -e "DROP DATABASE $DIRECTOR_TESTDB" script: - - phpunit + - phpunit --verbose CentOS 7/PostgreSQL: stage: Unit-Tests with DB @@ -40,7 +40,7 @@ CentOS 7/PostgreSQL: - psql postgres -c "DROP DATABASE $DIRECTOR_TESTDB" - psql postgres -c "DROP USER $DIRECTOR_TESTDB_USER" script: - - phpunit + - phpunit --verbose #CentOS 6/MySQL: # stage: Unit-Tests with DB @@ -70,7 +70,7 @@ Jessie/MySQL: after_script: - mysql -u root -e "DROP DATABASE $DIRECTOR_TESTDB" script: - - phpunit + - phpunit --verbose Jessie/PostgreSQL: stage: Unit-Tests with DB @@ -88,7 +88,7 @@ Jessie/PostgreSQL: - psql postgres -c "DROP DATABASE $DIRECTOR_TESTDB" - psql postgres -c "DROP USER $DIRECTOR_TESTDB_USER" script: - - phpunit + - phpunit --verbose Xenial/MySQL: stage: Unit-Tests with DB @@ -103,7 +103,7 @@ Xenial/MySQL: after_script: - mysql -u root -e "DROP DATABASE $DIRECTOR_TESTDB" script: - - phpunit + - phpunit --verbose Xenial/PostgreSQL: stage: Unit-Tests with DB @@ -121,5 +121,5 @@ Xenial/PostgreSQL: - psql postgres -c "DROP DATABASE $DIRECTOR_TESTDB" - psql postgres -c "DROP USER $DIRECTOR_TESTDB_USER" script: - - phpunit + - phpunit --verbose From 2f1d963c1c0a8a3a0271743942e82f57b0129e6f Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 27 Aug 2017 18:08:18 +0200 Subject: [PATCH 2/8] IcingaObject: ask imports for name list... ...when we already have it available --- library/Director/Objects/IcingaObject.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 29f3c067..9113de31 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -2633,10 +2633,7 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer public function listImportNames() { - if ($this->hasBeenModified() - && $this->imports !== null - && $this->imports()->hasBeenModified() - ) { + if ($this->gotImports()) { return $this->imports()->listImportNames(); } else { return $this->templateTree()->listParentNamesFor($this); From 66850666734f7d99faaa63885d9e285c525efbe6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 27 Aug 2017 18:21:15 +0200 Subject: [PATCH 3/8] IcingaServiceSetTest: enable disabled test --- test/php/library/Director/Objects/IcingaServiceSetTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/php/library/Director/Objects/IcingaServiceSetTest.php b/test/php/library/Director/Objects/IcingaServiceSetTest.php index 4ff670d8..52fae05c 100644 --- a/test/php/library/Director/Objects/IcingaServiceSetTest.php +++ b/test/php/library/Director/Objects/IcingaServiceSetTest.php @@ -64,8 +64,6 @@ class IcingaServiceSetTest extends IcingaObjectTestCase public function testDeletingHostWithSet() { - $this->markTestIncomplete('Host deletion fails / does not cleanup sets!'); - $this->testAddingSetToHost(); $host = $this->loadObject('for_set', 'icinga_host'); From c2afacc11bae95cfd2ebbd070615dbaeac3e4720 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 27 Aug 2017 18:59:32 +0200 Subject: [PATCH 4/8] IcingaServiceSet: createWhere() look for template ...in case no host_id has been set --- library/Director/Objects/IcingaServiceSet.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index 04ccb34b..dd23c753 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -249,6 +249,18 @@ class IcingaServiceSet extends IcingaObject } } + public function createWhere() + { + $where = parent::createWhere(); + if (! $this->hasBeenLoadedFromDb()) { + if (null === $this->get('host_id') && null === $this->get('id')) { + $where .= " AND object_type = 'template'"; + } + } + + return $where; + } + protected function beforeStore() { parent::beforeStore(); From 95a971975dd2a200945e01d9baba661be5a50894 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 27 Aug 2017 19:03:44 +0200 Subject: [PATCH 5/8] IcingaServiceSetTest: do not call another test... ...from a test --- test/php/library/Director/Objects/IcingaServiceSetTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/php/library/Director/Objects/IcingaServiceSetTest.php b/test/php/library/Director/Objects/IcingaServiceSetTest.php index 52fae05c..493dec8c 100644 --- a/test/php/library/Director/Objects/IcingaServiceSetTest.php +++ b/test/php/library/Director/Objects/IcingaServiceSetTest.php @@ -64,7 +64,10 @@ class IcingaServiceSetTest extends IcingaObjectTestCase public function testDeletingHostWithSet() { - $this->testAddingSetToHost(); + $this->createObject('for_set', 'icinga_host', array( + 'object_type' => 'object', + 'address' => '1.2.3.4', + )); $host = $this->loadObject('for_set', 'icinga_host'); $host->delete(); From 20fe291433ba538fa6fe5f6329eb0eebddad6072 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 28 Aug 2017 06:00:23 +0200 Subject: [PATCH 6/8] IcingaServiceSet: do not allow for objects without ...a host --- library/Director/Objects/IcingaServiceSet.php | 6 ++++++ test/php/library/Director/Objects/IcingaServiceSetTest.php | 4 ---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index dd23c753..c934e8e5 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects; use Icinga\Data\Filter\Filter; use Icinga\Exception\IcingaException; +use Icinga\Exception\ProgrammingError; use Icinga\Module\Director\Exception\DuplicateKeyException; use Icinga\Module\Director\IcingaConfig\IcingaConfig; @@ -267,6 +268,11 @@ class IcingaServiceSet extends IcingaObject $name = $this->getObjectName(); + if ($this->isObject() && $this->get('host_id') === null) { + throw new ProgrammingError( + 'A Service Set cannot be an object with no related host' + ); + } // checking if template object_name is unique // TODO: Move to IcingaObject if (! $this->hasBeenLoadedFromDb() && $this->isTemplate() && static::exists($name, $this->connection)) { diff --git a/test/php/library/Director/Objects/IcingaServiceSetTest.php b/test/php/library/Director/Objects/IcingaServiceSetTest.php index 493dec8c..c1cb817d 100644 --- a/test/php/library/Director/Objects/IcingaServiceSetTest.php +++ b/test/php/library/Director/Objects/IcingaServiceSetTest.php @@ -125,16 +125,12 @@ class IcingaServiceSetTest extends IcingaObjectTestCase */ public function testCreatingHostSetWithoutHost() { - $this->markTestIncomplete('Throws no error currently, but will create the object'); - - /* TODO: fix this, it will create an object currently $set = IcingaServiceSet::create(array( 'object_name' => '___TEST__set_BAD2', 'object_type' => 'object', )); $set->store($this->getDb()); - */ } public function testDeletingSet() From 18d171991e2e83e01e4651569573bcfae77368a2 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 28 Aug 2017 06:02:12 +0200 Subject: [PATCH 7/8] IcingaServiceSetTest: IcingaException is enough --- test/php/library/Director/Objects/IcingaServiceSetTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/php/library/Director/Objects/IcingaServiceSetTest.php b/test/php/library/Director/Objects/IcingaServiceSetTest.php index c1cb817d..c7fc05d0 100644 --- a/test/php/library/Director/Objects/IcingaServiceSetTest.php +++ b/test/php/library/Director/Objects/IcingaServiceSetTest.php @@ -107,13 +107,10 @@ class IcingaServiceSetTest extends IcingaObjectTestCase } /** - * @expectedException \Icinga\Exception\ProgrammingError + * @expectedException \Icinga\Exception\IcingaException */ public function testCreatingSetWithoutType() { - // TODO: fix error - $this->markTestIncomplete('Throws a database error, not a proper exception!'); - $set = IcingaServiceSet::create(array( 'object_name' => '___TEST__set_BAD', )); From a3ac1b8eef336b68aff5ce6e358a3ad509878ab0 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sat, 26 Aug 2017 10:51:19 +0200 Subject: [PATCH 8/8] IcingaServiceSet: fix tests --- library/Director/Objects/IcingaServiceSet.php | 6 +++++- test/php/library/Director/Objects/IcingaServiceSetTest.php | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index c934e8e5..faafb44c 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -276,7 +276,11 @@ class IcingaServiceSet extends IcingaObject // checking if template object_name is unique // TODO: Move to IcingaObject if (! $this->hasBeenLoadedFromDb() && $this->isTemplate() && static::exists($name, $this->connection)) { - throw new DuplicateKeyException('%s template "%s" already existing in database!', $this->getType(), $name); + throw new DuplicateKeyException( + '%s template "%s" already existing in database!', + $this->getType(), + $name + ); } } } diff --git a/test/php/library/Director/Objects/IcingaServiceSetTest.php b/test/php/library/Director/Objects/IcingaServiceSetTest.php index c7fc05d0..d4b60de0 100644 --- a/test/php/library/Director/Objects/IcingaServiceSetTest.php +++ b/test/php/library/Director/Objects/IcingaServiceSetTest.php @@ -67,7 +67,7 @@ class IcingaServiceSetTest extends IcingaObjectTestCase $this->createObject('for_set', 'icinga_host', array( 'object_type' => 'object', 'address' => '1.2.3.4', - )); + ), false)->store(); $host = $this->loadObject('for_set', 'icinga_host'); $host->delete();