Exemple #1
0
 def test_interpolates_parameters(self):
     param_name = factory.make_name('param', sep='_')
     param_value = factory.make_string()
     self.assertEqual(
         "X %s Y" % param_value,
         render_dns_template(
             self.make_file(contents="X {{%s}} Y" % param_name),
             {param_name: param_value}))
Exemple #2
0
 def test_combines_parameter_dicts(self):
     self.assertEqual(
         "aaa bbb",
         render_dns_template(
             self.make_file(contents="{{one}} {{two}}"),
             {"one": "aaa"},
             {"two": "bbb"},
         ),
     )
Exemple #3
0
 def test_takes_latest_value_of_redefined_parameter(self):
     self.assertEqual(
         "last",
         render_dns_template(
             self.make_file(contents="{{var}}"),
             {"var": "first"},
             {"var": "middle"},
             {"var": "last"},
         ),
     )
Exemple #4
0
    def write_zone_file(cls, output_file, *parameters):
        """Write a zone file based on the zone file template.

        There is a subtlety with zone files: their filesystem timestamp must
        increase with every rewrite.  Some filesystems (ext3?) only seem to
        support a resolution of one second, and so this method may set an
        unexpected modification time in order to maintain that property.
        """
        if not isinstance(output_file, list):
            output_file = [output_file]
        for outfile in output_file:
            content = render_dns_template(cls.template_file_name, *parameters)
            with report_missing_config_dir():
                incremental_write(content.encode("utf-8"), outfile, mode=0o644)
        pass
Exemple #5
0
 def test_renders_template(self):
     template_text = "X %d Y" % random.randint(1, 10000)
     self.assertEqual(
         template_text,
         render_dns_template(self.make_file(contents=template_text)),
     )
Exemple #6
0
 def test_takes_latest_value_of_redefined_parameter(self):
     self.assertEqual(
         "last",
         render_dns_template(self.make_file(contents='{{var}}'),
                             {'var': 'first'}, {'var': 'middle'},
                             {'var': 'last'}))
Exemple #7
0
 def test_combines_parameter_dicts(self):
     self.assertEqual(
         "aaa bbb",
         render_dns_template(self.make_file(contents='{{one}} {{two}}'),
                             {'one': 'aaa'}, {'two': 'bbb'}))