示例#1
0
 def test_load_preseed_template_generic_lookup(self):
     # The template lookup method ends up picking up a template named
     # 'generic' if no more specific template exist.
     content = self.create_template(self.location, GENERIC_FILENAME)
     node = factory.make_node(hostname=factory.getRandomString())
     template = load_preseed_template(node, factory.getRandomString())
     self.assertEqual(content, template.substitute())
示例#2
0
 def test_load_preseed_template_generic_lookup(self):
     # The template lookup method ends up picking up a template named
     # 'generic' if no more specific template exist.
     content = self.create_template(self.location, GENERIC_FILENAME)
     node = factory.make_node(hostname=factory.getRandomString())
     template = load_preseed_template(node, factory.getRandomString())
     self.assertEqual(content, template.substitute())
示例#3
0
 def test_load_preseed_template_with_inherits(self):
     # A preseed file can "inherit" from another file.
     prefix = factory.getRandomString()
     # Create preseed template.
     master_template_name = factory.getRandomString()
     preseed_content = '{{inherit "%s"}}' % master_template_name
     self.create_template(self.location, prefix, preseed_content)
     master_content = self.create_template(
         self.location, master_template_name)
     node = factory.make_node()
     template = load_preseed_template(node, prefix)
     self.assertEqual(master_content, template.substitute())
示例#4
0
 def test_load_preseed_template_prefix_lookup(self):
     # 2nd last in the hierarchy is a template named 'prefix'.
     prefix = factory.getRandomString()
     # Create the generic template.  This one will be ignored due to the
     # presence of a more specific template.
     self.create_template(self.location, GENERIC_FILENAME)
     # Create the 'prefix' template.  This is the one which will be
     # picked up.
     content = self.create_template(self.location, prefix)
     node = factory.make_node(hostname=factory.getRandomString())
     template = load_preseed_template(node, prefix)
     self.assertEqual(content, template.substitute())
示例#5
0
 def test_load_preseed_template_with_inherits(self):
     # A preseed file can "inherit" from another file.
     prefix = factory.getRandomString()
     # Create preseed template.
     master_template_name = factory.getRandomString()
     preseed_content = '{{inherit "%s"}}' % master_template_name
     self.create_template(self.location, prefix, preseed_content)
     master_content = self.create_template(self.location,
                                           master_template_name)
     node = factory.make_node()
     template = load_preseed_template(node, prefix)
     self.assertEqual(master_content, template.substitute())
示例#6
0
 def test_load_preseed_template_prefix_lookup(self):
     # 2nd last in the hierarchy is a template named 'prefix'.
     prefix = factory.getRandomString()
     # Create the generic template.  This one will be ignored due to the
     # presence of a more specific template.
     self.create_template(self.location, GENERIC_FILENAME)
     # Create the 'prefix' template.  This is the one which will be
     # picked up.
     content = self.create_template(self.location, prefix)
     node = factory.make_node(hostname=factory.getRandomString())
     template = load_preseed_template(node, prefix)
     self.assertEqual(content, template.substitute())
示例#7
0
 def test_load_preseed_template_parent_lookup_doesnt_include_default(self):
     # The lookup for parent templates does not include the default
     # 'generic' file.
     prefix = factory.getRandomString()
     # Create 'generic' template.  It won't be used because the
     # lookup for parent templates does not use the 'generic' template.
     self.create_template(self.location, GENERIC_FILENAME)
     unknown_master_template_name = factory.getRandomString()
     # Create preseed template.
     preseed_content = '{{inherit "%s"}}' % unknown_master_template_name
     self.create_template(self.location, prefix, preseed_content)
     node = factory.make_node()
     template = load_preseed_template(node, prefix)
     self.assertRaises(TemplateNotFoundError, template.substitute)
示例#8
0
 def test_load_preseed_template_parent_lookup_doesnt_include_default(self):
     # The lookup for parent templates does not include the default
     # 'generic' file.
     prefix = factory.getRandomString()
     # Create 'generic' template.  It won't be used because the
     # lookup for parent templates does not use the 'generic' template.
     self.create_template(self.location, GENERIC_FILENAME)
     unknown_master_template_name = factory.getRandomString()
     # Create preseed template.
     preseed_content = '{{inherit "%s"}}' % unknown_master_template_name
     self.create_template(self.location, prefix, preseed_content)
     node = factory.make_node()
     template = load_preseed_template(node, prefix)
     self.assertRaises(
         TemplateNotFoundError, template.substitute)
示例#9
0
 def test_load_preseed_template_node_specific_lookup(self):
     # At the top of the lookup hierarchy is a template specific to this
     # node.  It will be used first if it's present.
     prefix = factory.getRandomString()
     release = factory.getRandomString()
     # Create the generic and 'prefix' templates.  They will be ignored
     # due to the presence of a more specific template.
     self.create_template(self.location, GENERIC_FILENAME)
     self.create_template(self.location, prefix)
     node = factory.make_node(hostname=factory.getRandomString())
     node_template_name = "%s_%s_%s_%s" % (
         prefix, node.architecture.replace('/', '_'),
         release, node.hostname)
     # Create the node-specific template.
     content = self.create_template(self.location, node_template_name)
     template = load_preseed_template(node, prefix, release)
     self.assertEqual(content, template.substitute())
示例#10
0
 def test_load_preseed_template_node_specific_lookup(self):
     # At the top of the lookup hierarchy is a template specific to this
     # node.  It will be used first if it's present.
     prefix = factory.getRandomString()
     release = factory.getRandomString()
     # Create the generic and 'prefix' templates.  They will be ignored
     # due to the presence of a more specific template.
     self.create_template(self.location, GENERIC_FILENAME)
     self.create_template(self.location, prefix)
     node = factory.make_node(hostname=factory.getRandomString())
     node_template_name = "%s_%s_%s_%s" % (
         prefix, node.architecture.replace('/',
                                           '_'), release, node.hostname)
     # Create the node-specific template.
     content = self.create_template(self.location, node_template_name)
     template = load_preseed_template(node, prefix, release)
     self.assertEqual(content, template.substitute())
示例#11
0
 def test_load_preseed_template_returns_PreseedTemplate(self):
     name = factory.getRandomString()
     self.create_template(self.location, name)
     node = factory.make_node()
     template = load_preseed_template(node, name)
     self.assertIsInstance(template, PreseedTemplate)
示例#12
0
 def test_load_preseed_template_returns_PreseedTemplate(self):
     name = factory.getRandomString()
     self.create_template(self.location, name)
     node = factory.make_node()
     template = load_preseed_template(node, name)
     self.assertIsInstance(template, PreseedTemplate)