Example #1
0
 def test_ensure_boot_source_definition_creates_with_default_arch(self):
     BootSource.objects.all().delete()
     mock_get_architecture = self.patch(bootsources, "get_architecture")
     mock_get_architecture.return_value = ""
     created = ensure_boot_source_definition()
     self.assertTrue(
         created,
         "Should have returned True signaling that the "
         "sources where added.",
     )
     sources = BootSource.objects.all()
     self.assertThat(sources, HasLength(1))
     [source] = sources
     self.assertAttributes(
         source,
         {
             "url":
             DEFAULT_IMAGES_URL,
             "keyring_filename":
             ("/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg"),
         },
     )
     selections = BootSourceSelection.objects.filter(boot_source=source)
     by_release = {selection.release: selection for selection in selections}
     self.assertItemsEqual(["bionic"], by_release.keys())
     self.assertAttributes(
         by_release["bionic"],
         {
             "release": "bionic",
             "arches": ["amd64"],
             "subarches": ["*"],
             "labels": ["*"],
         },
     )
Example #2
0
 def test_ensure_boot_source_definition_creates_default_source(self):
     BootSource.objects.all().delete()
     created = ensure_boot_source_definition()
     self.assertTrue(
         created, "Should have returned True signaling that the "
         "sources where added.")
     sources = BootSource.objects.all()
     self.assertThat(sources, HasLength(1))
     [source] = sources
     self.assertAttributes(
         source, {
             'url':
             DEFAULT_IMAGES_URL,
             'keyring_filename':
             ('/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg'),
         })
     selections = BootSourceSelection.objects.filter(boot_source=source)
     by_release = {selection.release: selection for selection in selections}
     self.assertItemsEqual(['bionic'], by_release.keys())
     self.assertAttributes(
         by_release['bionic'], {
             'release': 'bionic',
             'arches': ['amd64'],
             'subarches': ['*'],
             'labels': ['*'],
         })
Example #3
0
 def test_ensure_boot_source_definition_skips_if_already_present(self):
     sources = [factory.make_BootSource() for _ in range(3)]
     created = ensure_boot_source_definition()
     self.assertFalse(
         created, "Should have returned False signaling that the "
         "sources where not added.")
     self.assertItemsEqual(sources, BootSource.objects.all())
Example #4
0
 def test_ensure_boot_source_definition_updates_default_source_snap(self):
     BootSource.objects.all().delete()
     self.assertTrue(ensure_boot_source_definition())
     source = BootSource.objects.first()
     self.assertEqual(
         source.keyring_filename,
         "/usr/share/keyrings/ubuntu-cloudimage-keyring.gpg",
     )
     self.useFixture(
         EnvironmentVariableFixture("SNAP", "/snap/maas/current"))
     self.patch(
         bootsources,
         "DEFAULT_KEYRINGS_PATH",
         "/some/other/path/keyring.gpg",
     )
     self.assertFalse(ensure_boot_source_definition())
     source = reload_object(source)
     self.assertEqual(source.keyring_filename,
                      "/some/other/path/keyring.gpg")