Ejemplo n.º 1
0
 def test_get_include_snippet_returns_snippet(self):
     target_dir = patch_dns_config_path(self)
     snippet = DNSConfig.get_include_snippet()
     self.assertThat(
         snippet,
         MatchesAll(
             Not(StartsWith('\n')), EndsWith('\n'), Contains(target_dir),
             Contains('include "%s/%s"' % (
                 config.get_dns_config_dir(),
                 DNSConfig.target_file_name,
             ))))
Ejemplo n.º 2
0
 def test_get_include_snippet_returns_snippet(self):
     target_dir = self.make_dir()
     self.patch(DNSConfig, 'target_dir', target_dir)
     dnsconfig = DNSConfig()
     snippet = dnsconfig.get_include_snippet()
     self.assertThat(
         snippet,
         MatchesAll(
             Not(StartsWith('\n')),
             EndsWith('\n'),
             Contains(target_dir),
             Contains('include "%s"' % dnsconfig.target_path)))
Ejemplo n.º 3
0
    def handle(self, *args, **options):
        edit = options.get('edit')
        config_path = options.get('config_path')
        include_snippet = DNSConfig.get_include_snippet()

        if edit is True:
            # XXX: GavinPanella: I've not been able to discover what character
            # set BIND expects for its configuration, so I've gone with a safe
            # choice of ASCII. If we find that this fails we can revisit this
            # and experiment to discover a better choice.
            with open(config_path, "a", encoding="ascii") as conf_file:
                conf_file.write(include_snippet)
        else:
            return INCLUDE_SNIPPET_COMMENT + include_snippet
Ejemplo n.º 4
0
def run(args, stdout=sys.stdout, stderr=sys.stderr):
    """Return the named configuration snippet.

    :param args: Parsed output of the arguments added in `add_arguments()`.
    :param stdout: Standard output stream to write to.
    :param stderr: Standard error stream to write to.
    """
    include_snippet = DNSConfig.get_include_snippet()

    if args.edit is True:
        # XXX: GavinPanella: I've not been able to discover what character
        # set BIND expects for its configuration, so I've gone with a safe
        # choice of ASCII. If we find that this fails we can revisit this
        # and experiment to discover a better choice.
        with open(args.config_path, "a", encoding="ascii") as conf_file:
            conf_file.write(include_snippet)
    else:
        stdout.write(INCLUDE_SNIPPET_COMMENT + include_snippet)
        stdout.write("\n")
        stdout.flush()