コード例 #1
0
ファイル: tftp.py プロジェクト: sempervictus/maas
def get_boot_image(params):
    """Get the boot image for the params on this rack controller."""
    # Match on purpose; enlist uses the commissioning purpose.
    purpose = params["purpose"]
    if purpose == "enlist":
        purpose = "commissioning"

    # Get the matching boot images, minus subarchitecture.
    boot_images = list_boot_images()
    boot_images = [
        image
        for image in boot_images
        if (
            image["osystem"] == params["osystem"]
            and image["release"] == params["release"]
            and image["architecture"] == params["arch"]
            and image["purpose"] == purpose
        )
    ]

    # See if exact subarchitecture match.
    for image in boot_images:
        if image["subarchitecture"] == params["subarch"]:
            return image

    # Not exact match check if subarchitecture is in the supported
    # subarchitectures list.
    for image in boot_images:
        subarches = image.get("supported_subarches", "")
        subarches = subarches.split(",")
        if params["subarch"] in subarches:
            return image

    # No matching boot image was found.
    return None
コード例 #2
0
def list_boot_images_for(osystem):
    """List all boot images for the given osystem."""
    # Circular import
    from provisioningserver.rpc.boot_images import list_boot_images
    return [
        image for image in list_boot_images()
        if image['osystem'] == osystem.name
    ]
コード例 #3
0
 def test_calls_list_boot_images_when_cache_is_None(self):
     self.patch(boot_images, "CACHED_BOOT_IMAGES", None)
     mock_list_boot_images = self.patch(tftppath, "list_boot_images")
     list_boot_images()
     self.assertThat(mock_list_boot_images, MockCalledOnceWith(ANY))
コード例 #4
0
 def test_doesnt_call_list_boot_images_when_cache_is_not_None(self):
     fake_boot_images = [factory.make_name("image") for _ in range(3)]
     self.patch(boot_images, "CACHED_BOOT_IMAGES", fake_boot_images)
     mock_list_boot_images = self.patch(tftppath, "list_boot_images")
     self.expectThat(list_boot_images(), Equals(fake_boot_images))
     self.expectThat(mock_list_boot_images, MockNotCalled())
コード例 #5
0
 def test_calls_list_boot_images_with_boot_resource_storage(self):
     self.patch(boot_images, "CACHED_BOOT_IMAGES", None)
     mock_list_boot_images = self.patch(tftppath, "list_boot_images")
     list_boot_images()
     self.assertThat(mock_list_boot_images,
                     MockCalledOnceWith(self.tftp_root))