Exemplo n.º 1
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)
Exemplo n.º 2
0
 def test_doesnt_move_paths_with_fewer_levels_into_ubuntu_dir(self):
     storage_dir = self.make_dir()
     self.configure_storage(storage_dir)
     arches = [factory.make_name("arch") for _ in range(3)]
     subarches = [factory.make_name("subarch") for _ in range(3)]
     releases = [factory.make_name("release") for _ in range(3)]
     # Labels directory is missing, causing none of the folders to move
     for arch, subarch, release in product(arches, subarches, releases):
         os.makedirs(
             os.path.join(storage_dir, "current", arch, subarch, release)
         )
     move_arch = factory.make_name("arch")
     os.makedirs(
         os.path.join(
             storage_dir,
             "current",
             move_arch,
             factory.make_name("subarch"),
             factory.make_name("release"),
             factory.make_name("label"),
         )
     )
     self.patch(upgrade_cluster, "update_targets_conf")
     upgrade_cluster.migrate_architectures_into_ubuntu_directory(
         self.current_dir
     )
     self.assertItemsEqual(
         [move_arch],
         list_subdirs(os.path.join(storage_dir, "current", "ubuntu")),
     )
Exemplo n.º 3
0
def filter_out_directories_with_extra_levels(paths):
    """Remove paths that contain directories with more levels. We don't want
    to move other operating systems under the ubuntu directory."""
    with ClusterConfiguration.open() as config:
        tftp_root = config.tftp_root
    for arch, subarch, release, label in paths:
        path = os.path.join(tftp_root, arch, subarch, release, label)
        if len(list_subdirs(path)) == 0:
            yield (arch, subarch, release, label)
Exemplo n.º 4
0
 def test_moves_paths_with_correct_levels_into_ubuntu_dir(self):
     storage_dir = self.make_dir()
     self.configure_storage(storage_dir)
     arches = [factory.make_name("arch") for _ in range(3)]
     subarches = [factory.make_name("subarch") for _ in range(3)]
     releases = [factory.make_name("release") for _ in range(3)]
     labels = [factory.make_name("label") for _ in range(3)]
     for arch, subarch, release, label in product(arches, subarches,
                                                  releases, labels):
         os.makedirs(
             os.path.join(storage_dir, "current", arch, subarch, release,
                          label))
     self.patch(upgrade_cluster, "update_targets_conf")
     upgrade_cluster.migrate_architectures_into_ubuntu_directory(
         self.current_dir)
     self.assertItemsEqual(
         arches,
         list_subdirs(os.path.join(storage_dir, "current", "ubuntu")),
     )