def test_use_with_config(self): # Given a configuration, ConfigFixture can arrange a minimal global # configuration with the additional options merged in. dummy_logfile = factory.make_name("logfile") fixture = ConfigFixture({"logfile": dummy_logfile}) self.assertEqual(dummy_logfile, fixture.config["logfile"]) self.exercise_fixture(fixture)
def test_install_image_installs_alternate_purpose_as_symlink(self): tftp_root = self.make_dir() self.useFixture(ConfigFixture({'tftp': {'root': tftp_root}})) kernel_content = factory.getRandomString() kernel = self.make_file(name='linux', contents=kernel_content) downloaded_image = os.path.dirname(kernel) arch = factory.make_name('arch') subarch = factory.make_name('subarch') release = factory.make_name('release') purpose = factory.make_name('purpose') alternate_purpose = factory.make_name('alt') install_image(downloaded_image, arch, subarch, release, purpose, alternate_purpose=alternate_purpose) main_image = os.path.join(tftp_root, arch, subarch, release, purpose) self.assertThat(os.path.join(main_image, 'linux'), FileContains(kernel_content)) alternate_image = os.path.join(tftp_root, arch, subarch, release, alternate_purpose) self.assertTrue(os.path.islink(os.path.join(alternate_image))) self.assertThat(os.path.join(alternate_image, 'linux'), FileContains(kernel_content))
def test_compose_kernel_command_line_reports_error_about_missing_dir(self): params = make_kernel_parameters(purpose="commissioning") missing_dir = factory.make_name('missing-dir') config = {"boot": {"ephemeral": {"images_directory": missing_dir}}} self.useFixture(ConfigFixture(config)) self.assertRaises(EphemeralImagesDirectoryNotFound, compose_kernel_command_line, params)
def test_creates_parser(self): self.useFixture(ConfigFixture({'boot': {'ephemeral': {}}})) documentation = factory.getRandomString() parser = make_arg_parser(documentation) self.assertIsInstance(parser, ArgumentParser) self.assertEqual(documentation, parser.description)
def test_uses_legacy_config(self): data_dir = self.make_dir() self.useFixture(ConfigFixture({})) install_legacy_config(self, make_legacy_config(data_dir=data_dir)) parser = make_arg_parser(factory.getRandomString()) args = parser.parse_args('') self.assertEqual(data_dir, args.output)
def test_sends_boot_images_to_server(self): self.useFixture(ConfigFixture({'tftp': {'root': self.make_dir()}})) self.set_maas_url() auth.record_api_credentials(':'.join(make_api_credentials())) image = make_boot_image_params() self.patch(tftppath, 'list_boot_images', Mock(return_value=[image])) self.patch(boot_images, "get_cluster_uuid") self.patch(MAASClient, 'post') report_boot_images.delay() args, kwargs = MAASClient.post.call_args self.assertItemsEqual([image], json.loads(kwargs['images']))
def create_ephemeral_info(self, name, arch, release): """Create a pseudo-real ephemeral info file.""" ephemeral_info = """ release=%s stream=ephemeral label=release serial=20120424 arch=%s name=%s """ % (release, arch, name) ephemeral_root = self.make_dir() config = {"boot": {"ephemeral": {"images_directory": ephemeral_root}}} self.useFixture(ConfigFixture(config)) ephemeral_dir = os.path.join(ephemeral_root, release, 'ephemeral', arch, release) os.makedirs(ephemeral_dir) factory.make_file(ephemeral_dir, name='info', contents=ephemeral_info)
def test_does_not_modify_config(self): self.useFixture( ConfigFixture({ 'boot': { 'architectures': [factory.make_name('arch')], 'ephemeral': { 'images_directory': self.make_dir(), 'releases': [factory.make_name('release')], }, }, })) original_boot_config = deepcopy(Config.load_from_cache()['boot']) install_legacy_config(self, make_legacy_config()) make_arg_parser(factory.getRandomString()) self.assertEqual(original_boot_config, Config.load_from_cache()['boot'])
def test_integration(self): tftproot = self.make_dir() config = {"tftp": {"root": tftproot}} config_fixture = ConfigFixture(config) self.useFixture(config_fixture) loader = self.make_file() action = factory.make_name("action") script = MainScript(action) script.register(action, provisioningserver.pxe.install_bootloader) script.execute(("--config-file", config_fixture.filename, action, "--loader", loader)) bootloader_filename = os.path.join( os.path.dirname(compose_bootloader_path()), os.path.basename(loader)) self.assertThat( locate_tftp_path(bootloader_filename, tftproot=tftproot), FileExists())
def test_defaults_to_config(self): images_directory = self.make_dir() arches = [factory.make_name('arch1'), factory.make_name('arch2')] releases = [factory.make_name('rel1'), factory.make_name('rel2')] self.useFixture( ConfigFixture({ 'boot': { 'architectures': arches, 'ephemeral': { 'images_directory': images_directory, 'releases': releases, }, }, })) parser = make_arg_parser(factory.getRandomString()) args = parser.parse_args('') self.assertEqual(images_directory, args.output) self.assertItemsEqual([ compose_filter('arch', arches), compose_filter('release', releases), ], args.filters)
def test_integration(self): tftproot = self.make_dir() config = {"tftp": {"root": tftproot}} config_fixture = ConfigFixture(config) self.useFixture(config_fixture) download_dir = self.make_dir() image_dir = os.path.join(download_dir, 'image') os.makedirs(image_dir) factory.make_file(image_dir, 'kernel') arch, subarch, release, purpose = make_arch_subarch_release_purpose() action = factory.make_name("action") script = MainScript(action) script.register(action, provisioningserver.pxe.install_image) script.execute(("--config-file", config_fixture.filename, action, "--arch", arch, "--subarch", subarch, "--release", release, "--purpose", purpose, "--image", image_dir)) self.assertThat( os.path.join( locate_tftp_path(compose_image_path(arch, subarch, release, purpose), tftproot=tftproot), 'kernel'), FileExists())
def setUp(self): super(TestBootImagesTasks, self).setUp() self.useFixture(ConfigFixture({'tftp': {'root': self.make_dir()}}))
def setUp(self): super(TestImportPXEFiles, self).setUp() self.tftproot = self.make_dir() self.config = {"tftp": {"root": self.tftproot}} self.config_fixture = ConfigFixture(self.config) self.useFixture(self.config_fixture)
def test_use_minimal(self): # With no arguments, ConfigFixture arranges a minimal configuration. fixture = ConfigFixture() self.exercise_fixture(fixture)
def test_get_defaults_ignores_settings(self): self.useFixture(ConfigFixture({'logfile': self.make_file()})) self.assertEqual( self.default_production_config['logfile'], Config.get_defaults()['logfile'])
def patch_config(self, tftp_root): """Set up a fake config, pointing to the given TFTP root directory.""" self.useFixture(ConfigFixture({'tftp': {'root': tftp_root}}))