def test_get_pxe_template_not_found(self): # It is a critical and unrecoverable error if the default PXE template # is not found. self.make_fake_templates_dir() self.assertRaises( AssertionError, config.get_pxe_template, *factory.make_names("purpose", "arch", "subarch"))
def test_get_pxe_template_not_found(self): # It is a critical and unrecoverable error if the default PXE template # is not found. self.patch(config, "gen_pxe_template_filenames").return_value = [] self.assertRaises( AssertionError, config.get_pxe_template, *factory.make_names("purpose", "arch", "subarch"))
def test_get_templates_only_suppresses_ENOENT(self): # The IOError arising from trying to load a template that doesn't # exist is suppressed, but other errors are not. method = FakeBootMethod() from_filename = self.patch(tempita.Template, "from_filename") from_filename.side_effect = IOError() from_filename.side_effect.errno = errno.EACCES self.assertRaises(IOError, method.get_template, *factory.make_names("purpose", "arch", "subarch"))
def test_get_pxe_templates_only_suppresses_ENOENT(self): # The IOError arising from trying to load a template that doesn't # exist is suppressed, but other errors are not. from_filename = self.patch(tempita.Template, "from_filename") from_filename.side_effect = IOError() from_filename.side_effect.errno = errno.EACCES self.assertRaises( IOError, config.get_pxe_template, *factory.make_names("purpose", "arch", "subarch"))
def test_get_pxe_template_gets_default(self): # There will not be a template matching the following purpose, arch, # and subarch, so get_pxe_template() returns the default template. purpose = factory.make_name("purpose") arch, subarch = factory.make_names("arch", "subarch") template = config.get_pxe_template(purpose, arch, subarch) self.assertEqual( path.join(config.template_dir, "config.template"), template.name)
def test_get_template_not_found(self): mock_try_send_rack_event = self.patch(boot, "try_send_rack_event") # It is a critical and unrecoverable error if the default template # is not found. templates_dir = self.make_dir() method = FakeBootMethod() method.get_template_dir = lambda: templates_dir self.assertRaises(AssertionError, method.get_template, *factory.make_names("purpose", "arch", "subarch")) self.assertThat(mock_try_send_rack_event, MockCalledOnce())
def test_gen_template_filenames(self): purpose = factory.make_name("purpose") arch, subarch = factory.make_names("arch", "subarch") expected = [ "config.%s.%s.%s.template" % (purpose, arch, subarch), "config.%s.%s.template" % (purpose, arch), "config.%s.template" % (purpose, ), "config.template", ] observed = gen_template_filenames(purpose, arch, subarch) self.assertSequenceEqual(expected, list(observed))
def test_gen_pxe_template_filenames(self): purpose = factory.make_name("purpose") arch, subarch = factory.make_names("arch", "subarch") expected = [ "config.%s.%s.%s.template" % (purpose, arch, subarch), "config.%s.%s.template" % (purpose, arch), "config.%s.template" % (purpose, ), "config.template", ] observed = config.gen_pxe_template_filenames(purpose, arch, subarch) self.assertSequenceEqual(expected, list(observed))
def test_get_pxe_template_gets_default_if_available(self): # If there is no template matching the purpose, arch, and subarch, # but there is a completely generic template, then get_pxe_template() # falls back to that as the default. templates_dir = self.make_fake_templates_dir() generic_template = factory.make_file(templates_dir, 'config.template') purpose = factory.make_name("purpose") arch, subarch = factory.make_names("arch", "subarch") self.assertEqual( generic_template, config.get_pxe_template(purpose, arch, subarch).name)
def test_get_pxe_template(self): purpose = factory.make_name("purpose") arch, subarch = factory.make_names("arch", "subarch") filename = factory.make_name("filename") # Set up the mocks that we've patched in. gen_filenames = self.patch(config, "gen_pxe_template_filenames") gen_filenames.return_value = [filename] from_filename = self.patch(tempita.Template, "from_filename") from_filename.return_value = mock.sentinel.template # The template returned matches the return value above. template = config.get_pxe_template(purpose, arch, subarch) self.assertEqual(mock.sentinel.template, template) # gen_pxe_template_filenames is called to obtain filenames. gen_filenames.assert_called_once_with(purpose, arch, subarch) # Tempita.from_filename is called with an absolute path derived from # the filename returned from gen_pxe_template_filenames. from_filename.assert_called_once_with( path.join(config.template_dir, filename), encoding="UTF-8")
def test_get_pxe_template(self): purpose = factory.make_name("purpose") arch, subarch = factory.make_names("arch", "subarch") filename = factory.make_name("filename") # Set up the mocks that we've patched in. gen_filenames = self.patch(config, "gen_pxe_template_filenames") gen_filenames.return_value = [filename] from_filename = self.patch(tempita.Template, "from_filename") from_filename.return_value = mock.sentinel.template # The template returned matches the return value above. template = config.get_pxe_template(purpose, arch, subarch) self.assertEqual(mock.sentinel.template, template) # gen_pxe_template_filenames is called to obtain filenames. gen_filenames.assert_called_once_with(purpose, arch, subarch) # Tempita.from_filename is called with an absolute path derived from # the filename returned from gen_pxe_template_filenames. from_filename.assert_called_once_with( locate_config(config.TEMPLATES_DIR, filename), encoding="UTF-8")
def test_get_pxe_template(self): method = FakeBootMethod() purpose = factory.make_name("purpose") arch, subarch = factory.make_names("arch", "subarch") filename = factory.make_name("filename") # Set up the mocks that we've patched in. gen_filenames = self.patch(boot, "gen_template_filenames") gen_filenames.return_value = [filename] from_filename = self.patch(tempita.Template, "from_filename") from_filename.return_value = mock.sentinel.template # The template returned matches the return value above. template = method.get_template(purpose, arch, subarch) self.assertEqual(mock.sentinel.template, template) # gen_pxe_template_filenames is called to obtain filenames. gen_filenames.assert_called_once_with(purpose, arch, subarch) # Tempita.from_filename is called with an absolute path derived from # the filename returned from gen_pxe_template_filenames. from_filename.assert_called_once_with(os.path.join( method.get_template_dir(), filename), encoding="UTF-8")
def test_make_names_calls_make_name_with_each_prefix(self): self.patch(factory, "make_name", lambda prefix: prefix + "-xxx") self.assertSequenceEqual( ["abc-xxx", "def-xxx", "ghi-xxx"], list(factory.make_names("abc", "def", "ghi")), )
def test_make_names_calls_make_name_with_each_prefix(self): self.patch(factory, "make_name", lambda prefix: prefix + "-xxx") self.assertSequenceEqual( ["abc-xxx", "def-xxx", "ghi-xxx"], list(factory.make_names("abc", "def", "ghi")))