Exemplo n.º 1
0
 def test_drill_down_drops_paths_that_do_not_go_deep_enough(self):
     base_dir = self.make_dir()
     shallow_dir = factory.make_name('shallow')
     os.makedirs(os.path.join(base_dir, shallow_dir))
     deep_dir = factory.make_name('deep')
     subdir = factory.make_name('sub')
     os.makedirs(os.path.join(base_dir, deep_dir, subdir))
     self.assertEqual([[deep_dir, subdir]],
                      drill_down(base_dir, [[shallow_dir], [deep_dir]]))
Exemplo n.º 2
0
 def test_drill_down_ignores_subdir_not_in_path(self):
     base_dir = self.make_dir()
     irrelevant_dir = factory.make_name('irrelevant')
     irrelevant_subdir = factory.make_name('subdir')
     relevant_dir = factory.make_name('relevant')
     relevant_subdir = factory.make_name('subdir')
     os.makedirs(os.path.join(base_dir, irrelevant_dir, irrelevant_subdir))
     os.makedirs(os.path.join(base_dir, relevant_dir, relevant_subdir))
     self.assertEqual([[relevant_dir, relevant_subdir]],
                      drill_down(base_dir, [[relevant_dir]]))
Exemplo n.º 3
0
 def test_drill_down_follows_directory_tree(self):
     base_dir = self.make_dir()
     lower_dir = factory.make_name('lower')
     os.makedirs(os.path.join(base_dir, lower_dir))
     subdirs = [
         factory.make_name('subdir-%d' % counter) for counter in range(3)
     ]
     for subdir in subdirs:
         os.makedirs(os.path.join(base_dir, lower_dir, subdir))
     self.assertItemsEqual([[lower_dir, subdir] for subdir in subdirs],
                           drill_down(base_dir, [[lower_dir]]))
Exemplo n.º 4
0
def migrate_architectures_into_ubuntu_directory():
    """Upgrade hook: move architecture folders under the ubuntu folder.

    With the support of multiple operating systems the structure of the
    boot resources directory added another level to the hierarchy. Previously
    the hierarchy was arch/subarch/release/label, it has now been modified to
    os/arch/subarch/release/label.

    Before multiple operating systems only Ubuntu was supported. Check if
    folders have structure arch/subarch/release/label and move them into
    ubuntu folder. Making the final path ubuntu/arch/subarch/release/label.
    """
    with ClusterConfiguration.open() as config:
        current_dir = config.tftp_root
    if not os.path.isdir(current_dir):
        return
    # If ubuntu folder already exists, then no reason to continue
    if 'ubuntu' in list_subdirs(current_dir):
        return

    # Starting point for iteration: paths that contain only the
    # top-level subdirectory of tftproot, i.e. the architecture name.
    potential_arches = list_subdirs(current_dir)
    paths = [[subdir] for subdir in potential_arches]

    # Extend paths deeper into the filesystem, through the levels that
    # represent sub-architecture, release, and label.
    # Any directory that doesn't extend this deep isn't a boot image.
    for level in ['subarch', 'release', 'label']:
        paths = drill_down(current_dir, paths)
    paths = filter_out_directories_with_extra_levels(paths)

    # Extract the only top directories (arch) from the paths, as we only need
    # its name to move into the new 'ubuntu' folder.
    arches = {arch for arch, _, _, _ in paths}
    if len(arches) == 0:
        return

    # Create the ubuntu directory and move the archiecture folders under that
    # directory.
    ubuntu_dir = os.path.join(current_dir, 'ubuntu')
    os.mkdir(ubuntu_dir)
    for arch in arches:
        shutil.move(os.path.join(current_dir, arch), ubuntu_dir)

    # Re-write the maas.tgt to point to the new location for the ubuntu boot
    # resources.
    write_targets_conf(current_dir)
    update_targets_conf(current_dir)