IcingaServiceSet: do not allow for objects without

...a host
This commit is contained in:
Thomas Gelf 2017-08-28 06:00:23 +02:00
parent 95a971975d
commit 20fe291433
2 changed files with 6 additions and 4 deletions

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects;
use Icinga\Data\Filter\Filter; use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException; use Icinga\Exception\IcingaException;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\Exception\DuplicateKeyException; use Icinga\Module\Director\Exception\DuplicateKeyException;
use Icinga\Module\Director\IcingaConfig\IcingaConfig; use Icinga\Module\Director\IcingaConfig\IcingaConfig;
@ -267,6 +268,11 @@ class IcingaServiceSet extends IcingaObject
$name = $this->getObjectName(); $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 // checking if template object_name is unique
// TODO: Move to IcingaObject // TODO: Move to IcingaObject
if (! $this->hasBeenLoadedFromDb() && $this->isTemplate() && static::exists($name, $this->connection)) { if (! $this->hasBeenLoadedFromDb() && $this->isTemplate() && static::exists($name, $this->connection)) {

View File

@ -125,16 +125,12 @@ class IcingaServiceSetTest extends IcingaObjectTestCase
*/ */
public function testCreatingHostSetWithoutHost() 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( $set = IcingaServiceSet::create(array(
'object_name' => '___TEST__set_BAD2', 'object_name' => '___TEST__set_BAD2',
'object_type' => 'object', 'object_type' => 'object',
)); ));
$set->store($this->getDb()); $set->store($this->getDb());
*/
} }
public function testDeletingSet() public function testDeletingSet()