示例#1
0
def ensure_boot_source_definition():
    """Set default boot source if none is currently defined."""
    if not BootSource.objects.exists():
        source = BootSource.objects.create(
            url=DEFAULT_IMAGES_URL, keyring_filename=DEFAULT_KEYRINGS_PATH)
        # Default is to import newest Ubuntu LTS release, for the current
        # architecture.
        arch = get_architecture()
        # amd64 is the primary architecture for MAAS uses. Make sure its always
        # selected. If MAAS is running on another architecture select that as
        # well.
        if arch in ("", "amd64"):
            arches = ["amd64"]
        else:
            arches = [arch, "amd64"]
        ubuntu = UbuntuOS()
        BootSourceSelection.objects.create(
            boot_source=source,
            os=ubuntu.name,
            release=ubuntu.get_default_commissioning_release(),
            arches=arches,
            subarches=["*"],
            labels=["*"],
        )
        return True
    else:
        # XXX ensure the default keyrings path in the database points to the
        # right file when running in a snap. (see lp:1890468) The
        # DEFAULT_KEYRINGS_PATH points to the right file whether running from
        # deb or snap, but the path stored in the DB might be wrong if a
        # snap-to-deb transition happened with a script without the fix.
        if os.environ.get("SNAP"):
            BootSource.objects.filter(url=DEFAULT_IMAGES_URL).update(
                keyring_filename=DEFAULT_KEYRINGS_PATH)
        return False
示例#2
0
 def test_get_architecture_returns_arch_with_generic(self):
     arch = random.choice(['i386', 'amd64', 'arm64', 'ppc64el'])
     subarch = factory.make_name('subarch')
     self.patch_autospec(refresh, 'call_and_check').return_value = (
         "%s/%s" % (arch, subarch)).encode('utf-8')
     ret_arch = refresh.get_architecture()
     self.assertEquals("%s/generic" % arch, ret_arch)
示例#3
0
def ensure_boot_source_definition():
    """Set default boot source if none is currently defined."""
    if not BootSource.objects.exists():
        source = BootSource.objects.create(
            url=DEFAULT_IMAGES_URL, keyring_filename=DEFAULT_KEYRINGS_PATH
        )
        # Default is to import newest Ubuntu LTS release, for the current
        # architecture.
        arch = get_architecture().split("/")[0]
        # amd64 is the primary architecture for MAAS uses. Make sure its always
        # selected. If MAAS is running on another architecture select that as
        # well.
        if arch in ("", "amd64"):
            arches = ["amd64"]
        else:
            arches = [arch, "amd64"]
        ubuntu = UbuntuOS()
        BootSourceSelection.objects.create(
            boot_source=source,
            os=ubuntu.name,
            release=ubuntu.get_default_commissioning_release(),
            arches=arches,
            subarches=["*"],
            labels=["*"],
        )
        return True
    else:
        return False
示例#4
0
 def test_get_architecture_returns_arch_with_subarch(self):
     arch = factory.make_name('arch')
     subarch = factory.make_name('subarch')
     architecture = "%s/%s" % (arch, subarch)
     self.patch_autospec(refresh, 'call_and_check').return_value = (
         architecture.encode('utf-8'))
     ret_arch = refresh.get_architecture()
     self.assertEquals(architecture, ret_arch)
示例#5
0
 def test_get_architecture_returns_arch_with_generic(self):
     arch = random.choice(["i386", "amd64", "arm64", "ppc64el"])
     subarch = factory.make_name("subarch")
     self.patch_autospec(refresh, "call_and_check").return_value = (
         "%s/%s" % (arch, subarch)
     ).encode("utf-8")
     ret_arch = refresh.get_architecture()
     self.assertEquals("%s/generic" % arch, ret_arch)
示例#6
0
 def test_get_architecture_returns_arch_with_subarch(self):
     arch = factory.make_name("arch")
     subarch = factory.make_name("subarch")
     architecture = "%s/%s" % (arch, subarch)
     self.patch_autospec(
         refresh,
         "call_and_check").return_value = architecture.encode("utf-8")
     ret_arch = refresh.get_architecture()
     self.assertEquals(architecture, ret_arch)
示例#7
0
 def test_get_architecture_from_snap_env(self, mock_get_architectures):
     arch = factory.make_name("arch")
     self.patch(os, "environ", {"SNAP_ARCH": arch})
     ret_arch = refresh.get_architecture()
     self.assertEqual(arch, ret_arch)
     mock_get_architectures.assert_not_called()
示例#8
0
 def test_get_architecture_from_deb(self, mock_get_architectures):
     arch = random.choice(["i386", "amd64", "arm64", "ppc64el"])
     mock_get_architectures.return_value = [arch, "otherarch"]
     ret_arch = refresh.get_architecture()
     self.assertEqual(arch, ret_arch)