IcingaService: make sure to have a db connection

...when rendering, as we require settings
This commit is contained in:
Thomas Gelf 2016-09-08 13:30:37 +00:00
parent 31b716a7db
commit 999019ba16
2 changed files with 24 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace Icinga\Module\Director\Objects;
use Icinga\Exception\ProgrammingError;
use Icinga\Module\Director\IcingaConfig\IcingaConfigHelper as c;
class IcingaService extends IcingaObject
@ -167,6 +168,12 @@ class IcingaService extends IcingaObject
protected function renderImportHostVarOverrides()
{
if (! $this->connection) {
throw new ProgrammingError(
'Cannot render services without an assigned DB connection'
);
}
return sprintf(
"\n import \"%s\"\n",
$this->connection->settings()->override_services_templatename

View File

@ -62,7 +62,16 @@ class IcingaServiceTest extends BaseTestCase
public function testAcceptsAndRendersFlatAssignRules()
{
if ($this->skipForMissingDb()) {
return;
}
$db = $this->getDb();
$service = $this->service();
// Service apply rule rendering requires access to settings:
$service->setConnection($db);
$service->object_type = 'apply';
$service->assignments = array(
'host.address="127.*"',
@ -82,7 +91,15 @@ class IcingaServiceTest extends BaseTestCase
public function testAcceptsAndRendersStructuredAssignRules()
{
if ($this->skipForMissingDb()) {
return;
}
$db = $this->getDb();
$service = $this->service();
// Service apply rule rendering requires access to settings:
$service->setConnection($db);
$service->object_type = 'apply';
$service->assignments = array(
'host.address="127.*"',