launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #12942
[Merge] lp:~rvb/maas/fix-dns-not-installed into lp:maas
Raphaël Badin has proposed merging lp:~rvb/maas/fix-dns-not-installed into lp:maas.
Commit message:
Raise a proper error with a meaningful error message if a DNS config file cannot be written because there is a missing directory (which means the maas-dns package needs to be installed).
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~rvb/maas/fix-dns-not-installed/+merge/128031
Raise a proper error with a meaningful error message if a DNS config file cannot be written because there is a missing directory (which means the maas-dns package needs to be installed).
--
https://code.launchpad.net/~rvb/maas/fix-dns-not-installed/+merge/128031
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~rvb/maas/fix-dns-not-installed into lp:maas.
=== modified file 'src/provisioningserver/dns/config.py'
--- src/provisioningserver/dns/config.py 2012-09-30 22:37:05 +0000
+++ src/provisioningserver/dns/config.py 2012-10-04 14:44:27 +0000
@@ -23,6 +23,7 @@
abstractproperty,
)
from datetime import datetime
+import errno
from itertools import (
chain,
imap,
@@ -48,6 +49,10 @@
MAAS_RNDC_CONF_NAME = 'rndc.conf.maas'
+class DNSConfigDirectoryMissing(Exception):
+ """The directory where the config was about to be written is missing."""
+
+
class DNSConfigFail(Exception):
"""Raised if there's a problem with a DNS config."""
@@ -157,6 +162,25 @@
return {}
def write_config(self, overwrite=True, **kwargs):
+ """Write out this DNS config file.
+
+ This ignores any "No such file or directory" error which would mean
+ that the directory containing the write to be written does not exist.
+ """
+ try:
+ self.inner_write_config(overwrite=overwrite, **kwargs)
+ except OSError as exception:
+ # Only raise a DNSConfigDirectoryMissing exception if this error
+ # is a "No such file or directory" exception.
+ if exception.errno == errno.ENOENT:
+ raise DNSConfigDirectoryMissing(
+ "The directory where the DNS config files should be "
+ "written does not exist. Make sure the 'maas-dns' "
+ "package installed on this region controller.")
+ else:
+ raise
+
+ def inner_write_config(self, overwrite=True, **kwargs):
"""Write out this DNS config file."""
template = self.get_template()
kwargs.update(self.get_context())
@@ -249,7 +273,7 @@
return os.path.join(
self.target_dir, 'zone.%s' % self.zone_name)
- def write_config(self, **kwargs):
+ def inner_write_config(self, **kwargs):
"""Write out the DNS config file for this zone."""
template = self.get_template()
kwargs.update(self.get_context())
=== modified file 'src/provisioningserver/dns/tests/test_config.py'
--- src/provisioningserver/dns/tests/test_config.py 2012-09-30 22:40:33 +0000
+++ src/provisioningserver/dns/tests/test_config.py 2012-10-04 14:44:27 +0000
@@ -12,6 +12,7 @@
__metaclass__ = type
__all__ = []
+import errno
import os.path
import random
@@ -23,6 +24,7 @@
MatchesAll,
)
from maastesting.testcase import TestCase
+from mock import Mock
from netaddr import (
IPAddress,
IPNetwork,
@@ -30,6 +32,7 @@
from provisioningserver.dns import config
from provisioningserver.dns.config import (
DNSConfig,
+ DNSConfigDirectoryMissing,
DNSConfigFail,
DNSForwardZoneConfig,
DNSReverseZoneConfig,
@@ -122,6 +125,20 @@
DNSConfigFail, dnsconfig.render_template, template)
self.assertIn("'test' is not defined", exception.message)
+ def test_write_config_DNSConfigDirectoryMissing_if_dir_missing(self):
+ dnsconfig = DNSConfig()
+ dir_name = self.make_dir()
+ os.rmdir(dir_name)
+ self.patch(DNSConfig, 'target_dir', dir_name)
+ self.assertRaises(DNSConfigDirectoryMissing, dnsconfig.write_config)
+
+ def test_write_config_errors_if_unexpected_exception(self):
+ dnsconfig = DNSConfig()
+ exception = IOError(errno.EBUSY, factory.getRandomString())
+ self.patch(
+ DNSConfig, 'inner_write_config', Mock(side_effect=exception))
+ self.assertRaises(IOError, dnsconfig.write_config)
+
def test_write_config_skips_writing_if_overwrite_false(self):
# If DNSConfig is created with overwrite=False, it won't
# overwrite an existing config file.