Exemplo n.º 1
0
 def test_to_dict_with_selections_returns_bootloaders(self):
     keyring_data = b"Some Keyring Data"
     boot_source = factory.make_BootSource(
         keyring_data=keyring_data, keyring_filename=""
     )
     boot_source_selection = factory.make_BootSourceSelection(
         boot_source=boot_source
     )
     bootloaders = []
     for arch in boot_source_selection.arches:
         bootloader_type = factory.make_name("bootloader-type")
         factory.make_BootSourceCache(
             boot_source=boot_source,
             bootloader_type=bootloader_type,
             release=bootloader_type,
             arch=arch,
         )
         bootloaders.append(bootloader_type)
     self.assertItemsEqual(
         [
             selection["release"]
             for selection in boot_source.to_dict()["selections"]
             if "bootloader-type" in selection["release"]
         ],
         bootloaders,
     )
Exemplo n.º 2
0
 def make_boot_source_cache(self):
     # Disable boot sources signals otherwise the test fails due to unrun
     # post-commit tasks at the end of the test.
     self.useFixture(SignalsDisabled("bootsources"))
     ubuntu = UbuntuDistroInfo()
     try:
         ubuntu_rows = ubuntu._rows
     except AttributeError:
         ubuntu_rows = [row.__dict__ for row in ubuntu._releases]
     supported_releases = [
         release
         for release in ubuntu_rows
         if int(release["version"].split(".")[0]) >= 12
     ]
     release = random.choice(supported_releases)
     ga_or_hwe = random.choice(["hwe", "ga"])
     subarch = "%s-%s" % (ga_or_hwe, release["version"].split(" ")[0])
     factory.make_BootSourceCache(
         os="ubuntu",
         arch=factory.make_name("arch"),
         subarch=subarch,
         release=release["series"],
         release_codename=release["codename"],
         release_title=release["version"],
         support_eol=release.get("eol_server", release.get("eol-server")),
     )
     return release
Exemplo n.º 3
0
 def make_boot_source_cache(self):
     # Disable boot sources signals otherwise the test fails due to unrun
     # post-commit tasks at the end of the test.
     self.useFixture(SignalsDisabled("bootsources"))
     ubuntu = UbuntuDistroInfo()
     try:
         ubuntu_rows = ubuntu._rows
     except AttributeError:
         ubuntu_rows = [row.__dict__ for row in ubuntu._releases]
     supported_releases = [
         release for release in ubuntu_rows
         if int(release['version'].split('.')[0]) >= 12
     ]
     release = random.choice(supported_releases)
     ga_or_hwe = random.choice(['hwe', 'ga'])
     subarch = "%s-%s" % (ga_or_hwe, release['version'].split(' ')[0])
     factory.make_BootSourceCache(
         os='ubuntu',
         arch=factory.make_name('arch'),
         subarch=subarch,
         release=release['series'],
         release_codename=release['codename'],
         release_title=release['version'],
         support_eol=release.get('eol_server', release.get('eol-server')),
     )
     return release
Exemplo n.º 4
0
 def test_returns_only_lts(self):
     release = factory.make_name("release")
     name = "ubuntu/%s" % release
     support_eol = factory.make_date().strftime("%Y-%m-%d")
     release_title = "%s LTS" % release
     resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED, name=name
     )
     factory.make_BootSourceCache(
         os="ubuntu",
         release=release,
         release_title=release_title,
         support_eol=support_eol,
     )
     other_release = factory.make_name("release")
     other_name = "ubuntu/%s" % other_release
     other_support_eol = factory.make_date().strftime("%Y-%m-%d")
     factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED, name=other_name
     )
     factory.make_BootSourceCache(
         os="ubuntu",
         release=other_release,
         release_title=other_release,
         support_eol=other_support_eol,
     )
     self.assertEqual(
         [resource],
         BootResource.objects.get_available_commissioning_resources(),
     )
Exemplo n.º 5
0
 def make_boot_sources(self):
     kernels = []
     ubuntu = UbuntuDistroInfo()
     for row in ubuntu._rows:
         release_year = int(row['version'].split('.')[0])
         if release_year < 12:
             continue
         elif release_year < 16:
             style = row['series'][0]
         else:
             style = row['version']
         for kflavor in [
                 'generic', 'lowlatency', 'edge', 'lowlatency-edge'
         ]:
             if kflavor == 'generic':
                 kernel = "hwe-%s" % style
             else:
                 kernel = "hwe-%s-%s" % (style, kflavor)
             arch = factory.make_name('arch')
             architecture = "%s/%s" % (arch, kernel)
             release = row['series'].split(' ')[0]
             factory.make_usable_boot_resource(
                 name="ubuntu/" + release,
                 kflavor=kflavor,
                 extra={'subarches': kernel},
                 architecture=architecture,
                 rtype=BOOT_RESOURCE_TYPE.SYNCED)
             factory.make_BootSourceCache(os="ubuntu",
                                          arch=arch,
                                          subarch=kernel,
                                          release=release)
             kernels.append((kernel, '%s (%s)' % (release, kernel)))
     return kernels
Exemplo n.º 6
0
 def test_returns_clears_entire_cache(self):
     source = factory.make_BootSource(keyring_data=b"1234")
     factory.make_BootSourceCache(source)
     mock_download = self.patch(bootsources,
                                "download_all_image_descriptions")
     mock_download.return_value = make_boot_image_mapping()
     cache_boot_sources()
     self.assertEqual(0, BootSourceCache.objects.all().count())
Exemplo n.º 7
0
 def test_make_hwe_kernel_ui_text_finds_release_from_bootsourcecache(self):
     self.useFixture(SignalsDisabled("bootsources"))
     release = factory.pick_ubuntu_release()
     kernel = "hwe-" + release[0]
     factory.make_BootSourceCache(os="ubuntu/%s" % release,
                                  subarch=kernel,
                                  release=release)
     self.assertEqual("%s (%s)" % (release, kernel),
                      make_hwe_kernel_ui_text(kernel))
Exemplo n.º 8
0
 def test__commissioning_node_uses_min_hwe_kernel_reports_missing(self):
     factory.make_BootSourceCache(
         release="18.10", subarch="hwe-18.10", release_title="18.10 CC",
         release_codename="CC")
     rack_controller = factory.make_RackController()
     local_ip = factory.make_ip_address()
     remote_ip = factory.make_ip_address()
     node = self.make_node(
         status=NODE_STATUS.COMMISSIONING,
         min_hwe_kernel="hwe-18.10")
     mac = node.get_boot_interface().mac_address
     observed_config = get_config(
         rack_controller.system_id, local_ip, remote_ip, mac=mac)
     self.assertEqual("no-such-kernel", observed_config["subarch"])
Exemplo n.º 9
0
 def test__returns_longest_remaining_supported_lts_first(self):
     trusty_resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED, name="ubuntu/trusty")
     factory.make_BootSourceCache(
         os="ubuntu", release="trusty",
         release_title="14.04 LTS", support_eol="2019-04-17")
     xenial_resource = factory.make_usable_boot_resource(
         rtype=BOOT_RESOURCE_TYPE.SYNCED, name="ubuntu/xenial")
     factory.make_BootSourceCache(
         os="ubuntu", release="xenial",
         release_title="16.04 LTS", support_eol="2021-04-17")
     self.assertEqual(
         [xenial_resource, trusty_resource],
         BootResource.objects.get_available_commissioning_resources())
Exemplo n.º 10
0
    def test_star_values_in_request_validate_against_any_cache(self):
        boot_source = factory.make_BootSource()
        os = factory.make_name('os')
        release = factory.make_name('release')
        factory.make_BootSourceCache(boot_source, os=os, release=release)
        params = {
            'os': os,
            'release': release,
            'arches': ['*'],
            'subarches': ['*'],
            'labels': ['*'],
        }

        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertTrue(form.is_valid(), form._errors)
Exemplo n.º 11
0
    def test_star_values_in_request_validate_against_any_cache(self):
        boot_source = factory.make_BootSource()
        os = factory.make_name("os")
        release = factory.make_name("release")
        factory.make_BootSourceCache(boot_source, os=os, release=release)
        params = {
            "os": os,
            "release": release,
            "arches": ["*"],
            "subarches": ["*"],
            "labels": ["*"],
        }

        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertTrue(form.is_valid(), form._errors)
Exemplo n.º 12
0
    def test_validates_if_boot_source_cache_has_same_os_and_release(self):
        boot_source = factory.make_BootSource()
        boot_cache = factory.make_BootSourceCache(boot_source)

        params = {"os": boot_cache.os, "release": boot_cache.release}
        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertTrue(form.is_valid(), form._errors)
Exemplo n.º 13
0
 def test_get_release_codename_returns_release_codename(self):
     release_codename = factory.make_name("release_codename")
     cache = factory.make_BootSourceCache(release_codename=release_codename)
     self.assertEquals(
         release_codename,
         BootSourceCache.objects.get_release_codename(
             cache.os, cache.release))
Exemplo n.º 14
0
 def test__returns_sources_and_sets_of_releases_and_architectures(self):
     os = factory.make_name('os')
     sources = [
         factory.make_BootSource(keyring_data='1234') for _ in range(2)]
     releases = set()
     arches = set()
     for source in sources:
         for _ in range(3):
             release = factory.make_name('release')
             arch = factory.make_name('arch')
             factory.make_BootSourceCache(
                 source, os=os, release=release, arch=arch)
             releases.add(release)
             arches.add(arch)
     self.assertEqual(
         (sources, releases, arches),
         get_os_info_from_boot_sources(os))
Exemplo n.º 15
0
 def test_commissioningform_contains_real_and_ui_choice(self):
     release = factory.pick_ubuntu_release()
     name = 'ubuntu/%s' % release
     arch = factory.make_name('arch')
     kernel = 'hwe-' + release[0]
     # Disable boot sources signals otherwise the test fails due to unrun
     # post-commit tasks at the end of the test.
     self.useFixture(SignalsDisabled('bootsources'))
     factory.make_BootSourceCache(os=name, subarch=kernel, release=release)
     factory.make_usable_boot_resource(name=name,
                                       architecture='%s/%s' %
                                       (arch, kernel),
                                       rtype=BOOT_RESOURCE_TYPE.SYNCED)
     Config.objects.set_config('commissioning_distro_series', release)
     form = CommissioningForm()
     self.assertItemsEqual([('', '--- No minimum kernel ---'),
                            (kernel, '%s (%s)' % (release, kernel))],
                           form.fields['default_min_hwe_kernel'].choices)
Exemplo n.º 16
0
 def make_boot_sources(self):
     kernels = []
     ubuntu = UbuntuDistroInfo()
     # LP: #1711191 - distro-info 0.16+ no longer returns dictionaries or
     # lists, and it now returns objects instead. As such, we need to
     # handle both cases for backwards compatibility.
     try:
         ubuntu_rows = ubuntu._rows
     except AttributeError:
         ubuntu_rows = [row.__dict__ for row in ubuntu._releases]
     for row in ubuntu_rows:
         release_year = int(row["version"].split(".")[0])
         if release_year < 12:
             continue
         elif release_year < 16:
             style = row["series"][0]
         else:
             style = row["version"]
         for kflavor in [
                 "generic",
                 "lowlatency",
                 "edge",
                 "lowlatency-edge",
         ]:
             if kflavor == "generic":
                 kernel = "hwe-%s" % style
             else:
                 kernel = "hwe-%s-%s" % (style, kflavor)
             arch = factory.make_name("arch")
             architecture = "%s/%s" % (arch, kernel)
             release = row["series"].split(" ")[0]
             factory.make_usable_boot_resource(
                 name="ubuntu/" + release,
                 kflavor=kflavor,
                 extra={"subarches": kernel},
                 architecture=architecture,
                 rtype=BOOT_RESOURCE_TYPE.SYNCED,
             )
             factory.make_BootSourceCache(os="ubuntu",
                                          arch=arch,
                                          subarch=kernel,
                                          release=release)
             kernels.append((kernel, "%s (%s)" % (release, kernel)))
     return kernels
Exemplo n.º 17
0
 def test_to_dict_with_selections_returns_bootloaders(self):
     keyring_data = b'Some Keyring Data'
     boot_source = factory.make_BootSource(keyring_data=keyring_data,
                                           keyring_filename='')
     boot_source_selection = factory.make_BootSourceSelection(
         boot_source=boot_source)
     bootloaders = []
     for arch in boot_source_selection.arches:
         bootloader_type = factory.make_name('bootloader-type')
         factory.make_BootSourceCache(boot_source=boot_source,
                                      bootloader_type=bootloader_type,
                                      release=bootloader_type,
                                      arch=arch)
         bootloaders.append(bootloader_type)
     self.assertItemsEqual([
         selection['release']
         for selection in boot_source.to_dict()['selections']
         if 'bootloader-type' in selection['release']
     ], bootloaders)
Exemplo n.º 18
0
    def test_rejects_if_boot_source_cache_does_not_have_label(self):
        boot_source = factory.make_BootSource()
        os = factory.make_name('os')
        release = factory.make_name('release')
        factory.make_BootSourceCache(boot_source, os=os, release=release)

        params = {
            'os': os,
            'release': release,
            'labels': [factory.make_name('label')],
        }

        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(
            {
                "labels":
                ["No available images to download for %s" % params['labels']]
            }, form._errors)
Exemplo n.º 19
0
    def test_rejects_if_boot_source_cache_does_not_have_arch(self):
        boot_source = factory.make_BootSource()
        os = factory.make_name("os")
        release = factory.make_name("release")
        factory.make_BootSourceCache(boot_source, os=os, release=release)

        params = {
            "os": os,
            "release": release,
            "arches": [factory.make_name("arch")],
        }

        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(
            {
                "arches":
                ["No available images to download for %s" % params["arches"]]
            },
            form._errors,
        )
Exemplo n.º 20
0
 def test_commissioningform_contains_real_and_ui_choice(self):
     release = factory.pick_ubuntu_release()
     name = "ubuntu/%s" % release
     arch = factory.make_name("arch")
     kernel = "hwe-" + release[0]
     # Disable boot sources signals otherwise the test fails due to unrun
     # post-commit tasks at the end of the test.
     self.useFixture(SignalsDisabled("bootsources"))
     factory.make_BootSourceCache(os=name, subarch=kernel, release=release)
     factory.make_usable_boot_resource(
         name=name,
         architecture="%s/%s" % (arch, kernel),
         rtype=BOOT_RESOURCE_TYPE.SYNCED,
     )
     Config.objects.set_config("commissioning_distro_series", release)
     form = CommissioningForm()
     self.assertItemsEqual(
         [
             ("", "--- No minimum kernel ---"),
             (kernel, "%s (%s)" % (release, kernel)),
         ],
         form.fields["default_min_hwe_kernel"].choices,
     )
Exemplo n.º 21
0
 def test_prevents_reserved_name(self):
     bsc = factory.make_BootSourceCache()
     upload_type, filetype = self.pick_filetype()
     size = random.randint(1024, 2048)
     content = factory.make_string(size).encode("utf-8")
     upload_name = factory.make_name("filename")
     uploaded_file = SimpleUploadedFile(content=content, name=upload_name)
     data = {
         "name": "%s/%s" % (bsc.os, bsc.release),
         "title": factory.make_name("title"),
         "architecture": make_usable_architecture(self),
         "filetype": upload_type,
     }
     form = BootResourceForm(data=data, files={"content": uploaded_file})
     self.assertFalse(form.is_valid())
Exemplo n.º 22
0
 def make_valid_source_selection_params(self, boot_source=None):
     # Helper that creates a valid BootSourceCache and parameters for
     # a BootSourceSelectionForm that will validate against the
     # cache.
     if boot_source is None:
         boot_source = factory.make_BootSource()
     arch = factory.make_name("arch")
     arch2 = factory.make_name("arch")
     subarch = factory.make_name("subarch")
     subarch2 = factory.make_name("subarch")
     label = factory.make_name("label")
     label2 = factory.make_name("label")
     params = {
         "os": factory.make_name("os"),
         "release": factory.make_name("release"),
         "arches": [arch, arch2],
         "subarches": [subarch, subarch2],
         "labels": [label, label2],
     }
     factory.make_BootSourceCache(
         boot_source=boot_source,
         os=params["os"],
         release=params["release"],
         arch=arch,
         subarch=subarch,
         label=label,
     )
     factory.make_BootSourceCache(
         boot_source=boot_source,
         os=params["os"],
         release=params["release"],
         arch=arch2,
         subarch=subarch2,
         label=label2,
     )
     return params
Exemplo n.º 23
0
 def test_prevents_reserved_name(self):
     bsc = factory.make_BootSourceCache()
     upload_type, filetype = self.pick_filetype()
     size = random.randint(1024, 2048)
     content = factory.make_string(size).encode('utf-8')
     upload_name = factory.make_name('filename')
     uploaded_file = SimpleUploadedFile(content=content, name=upload_name)
     data = {
         'name': '%s/%s' % (bsc.os, bsc.release),
         'title': factory.make_name('title'),
         'architecture': make_usable_architecture(self),
         'filetype': upload_type,
     }
     form = BootResourceForm(data=data, files={'content': uploaded_file})
     self.assertFalse(form.is_valid())
Exemplo n.º 24
0
 def make_valid_source_selection_params(self, boot_source=None):
     # Helper that creates a valid BootSourceCache and parameters for
     # a BootSourceSelectionForm that will validate against the
     # cache.
     if boot_source is None:
         boot_source = factory.make_BootSource()
     arch = factory.make_name('arch')
     arch2 = factory.make_name('arch')
     subarch = factory.make_name('subarch')
     subarch2 = factory.make_name('subarch')
     label = factory.make_name('label')
     label2 = factory.make_name('label')
     params = {
         'os': factory.make_name('os'),
         'release': factory.make_name('release'),
         'arches': [arch, arch2],
         'subarches': [subarch, subarch2],
         'labels': [label, label2],
     }
     factory.make_BootSourceCache(
         boot_source=boot_source,
         os=params['os'],
         release=params['release'],
         arch=arch,
         subarch=subarch,
         label=label,
     )
     factory.make_BootSourceCache(
         boot_source=boot_source,
         os=params['os'],
         release=params['release'],
         arch=arch2,
         subarch=subarch2,
         label=label2,
     )
     return params
Exemplo n.º 25
0
    def test_rejects_if_boot_source_cache_has_different_os(self):
        boot_source = factory.make_BootSource()
        boot_cache = factory.make_BootSourceCache(boot_source)

        params = {"os": factory.make_name("os"), "release": boot_cache.release}
        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(
            {
                "os": [
                    "OS %s with release %s has no available images "
                    "for download" % (params["os"], boot_cache.release)
                ]
            },
            form._errors,
        )
Exemplo n.º 26
0
    def test_rejects_if_boot_source_cache_has_different_release(self):
        boot_source = factory.make_BootSource()
        boot_cache = factory.make_BootSourceCache(boot_source)

        params = {
            'os': boot_cache.os,
            'release': factory.make_name('release'),
        }
        form = BootSourceSelectionForm(boot_source=boot_source, data=params)
        self.assertFalse(form.is_valid())
        self.assertEqual(
            {
                "os": [
                    "OS %s with release %s has no available images "
                    "for download" % (boot_cache.os, params['release'])
                ]
            }, form._errors)
Exemplo n.º 27
0
 def test_returns_empty_sources_and_sets_when_no_os(self):
     factory.make_BootSourceCache()
     self.assertEqual(
         ([], set(), set()),
         get_os_info_from_boot_sources(factory.make_name("os")),
     )
Exemplo n.º 28
0
 def test_get_release_codename_returns_None_for_missing_codename(self):
     cache = factory.make_BootSourceCache()
     self.assertIsNone(
         BootSourceCache.objects.get_release_title(cache.os, cache.release))