Exemplo n.º 1
0
 def test_list_boot_images_passes_on_other_exceptions(self):
     # OSError(EACCESS) is transmogrified, by Python itself, into
     # PermissionError. It's a subclass of OSError.
     error = OSError(errno.EACCES, "Deliberate error for testing.")
     self.patch(tftppath, 'list_subdirs', Mock(side_effect=error))
     with ExpectedException(PermissionError):
         list_boot_images(factory.make_string())
Exemplo n.º 2
0
def reload_boot_images():
    """Update the cached boot images so `list_boot_images` returns the
    most up-to-date boot images list."""
    global CACHED_BOOT_IMAGES
    with ClusterConfiguration.open() as config:
        tftp_root = config.tftp_root
    CACHED_BOOT_IMAGES = tftppath.list_boot_images(tftp_root)
Exemplo n.º 3
0
def compose_targets_conf(snapshot_path):
    """Produce the contents of a snapshot's tgt conf file.

    :param snapshot_path: Filesystem path to a snapshot of current upstream
        boot resources.
    :return: Contents for a `targets.conf` file.
    :rtype: bytes
    """
    # Use a set to make sure we don't register duplicate entries in tgt.
    entries = set()
    for item in list_boot_images(snapshot_path):
        osystem = item['osystem']
        arch = item['architecture']
        subarch = item['subarchitecture']
        release = item['release']
        label = item['label']
        entries.add((osystem, arch, subarch, release, label))
    tgt_entries = []
    for osystem, arch, subarch, release, label in sorted(entries):
        base_path = os.path.join(snapshot_path, osystem, arch, subarch,
                                 release, label)
        root_image = os.path.join(base_path, 'root-image')
        if os.path.isfile(root_image):
            entry = tgt_entry(osystem, arch, subarch, release, label,
                              root_image)
            tgt_entries.append(entry)
        squashfs_image = os.path.join(base_path, 'squashfs')
        if os.path.isfile(squashfs_image):
            entry = tgt_entry(osystem, arch, subarch, release, label,
                              squashfs_image)
            tgt_entries.append(entry)
    text = ''.join(tgt_entries)
    return text.encode('utf-8')
Exemplo n.º 4
0
 def test_list_boot_images_finds_boot_image(self):
     params = make_boot_image_storage_params()
     self.make_image_dir(params, self.tftproot)
     purposes = ['install', 'commissioning', 'xinstall']
     make_osystem(self, params['osystem'], purposes)
     self.assertItemsEqual(
         [make_image(params, purpose) for purpose in purposes],
         list_boot_images(self.tftproot))
Exemplo n.º 5
0
 def test_list_boot_images_finds_boot_image(self):
     params = make_boot_image_storage_params()
     self.make_image_dir(params, self.tftproot)
     purposes = ["install", "commissioning", "xinstall"]
     make_osystem(self, params["osystem"], purposes)
     self.assertItemsEqual(
         [make_image(params, purpose) for purpose in purposes],
         list_boot_images(self.tftproot),
     )
Exemplo n.º 6
0
 def test_list_boot_images_enumerates_boot_images(self):
     purposes = ['install', 'commissioning', 'xinstall']
     params = [make_boot_image_storage_params() for counter in range(3)]
     for param in params:
         self.make_image_dir(param, self.tftproot)
         make_osystem(self, param['osystem'], purposes)
     self.assertItemsEqual([
         make_image(param, purpose) for param in params
         for purpose in purposes
     ], list_boot_images(self.tftproot))
Exemplo n.º 7
0
def list_boot_images():
    """List the boot images that exist on the cluster.

    This return value of this function is cached. This helps reduce the amount
    of IO, as this function is called often. To update the cache call
    `reload_boot_images`.
    """

    global CACHED_BOOT_IMAGES
    if CACHED_BOOT_IMAGES is None:
        with ClusterConfiguration.open() as config:
            tftp_root = config.tftp_root
        CACHED_BOOT_IMAGES = tftppath.list_boot_images(tftp_root)
    return CACHED_BOOT_IMAGES
Exemplo n.º 8
0
 def test_list_boot_images_merges_maas_meta_data(self):
     params = make_boot_image_storage_params()
     self.make_image_dir(params, self.tftproot)
     # The required metadata is called "subarches" in maas.meta
     metadata = dict(subarches=factory.make_name("subarches"))
     self.make_meta_file(params, metadata, self.tftproot)
     purposes = ['install', 'commissioning', 'xinstall']
     make_osystem(self, params['osystem'], purposes)
     # The API requires "supported_subarches".
     expected_metadata = dict(supported_subarches=metadata["subarches"])
     self.assertItemsEqual([
         make_image(params, purpose, expected_metadata)
         for purpose in purposes
     ], list_boot_images(self.tftproot))
Exemplo n.º 9
0
 def test_list_boot_images_empty_on_missing_osystems(self):
     params = [make_boot_image_storage_params() for counter in range(3)]
     for param in params:
         self.make_image_dir(param, self.tftproot)
     self.assertItemsEqual([], list_boot_images(self.tftproot))
Exemplo n.º 10
0
 def test_list_boot_images_copes_with_unexpected_files(self):
     os.makedirs(os.path.join(self.tftproot, factory.make_name('empty')))
     factory.make_file(self.tftproot)
     self.assertEqual([], list_boot_images(self.tftproot))
Exemplo n.º 11
0
 def test_list_boot_images_copes_with_empty_directory(self):
     self.assertEqual([], list_boot_images(self.tftproot))
Exemplo n.º 12
0
 def test_list_boot_images_copes_with_missing_directory(self):
     self.assertEqual([], list_boot_images(factory.make_string()))