示例#1
0
 def test_get_by_pxealias_returns_None_if_none_matching(self):
     arch1 = Architecture(
         name="arch1", description="arch1",
         pxealiases=["archibald", "reginald"])
     arch2 = Architecture(name="arch2", description="arch2")
     ArchitectureRegistry.register_item("arch1", arch1)
     ArchitectureRegistry.register_item("arch2", arch2)
     self.assertEqual(
         None, ArchitectureRegistry.get_by_pxealias("stinkywinky"))
示例#2
0
 def test_get_by_pxealias_returns_valid_arch(self):
     arch1 = Architecture(
         name="arch1", description="arch1",
         pxealiases=["archibald", "reginald"])
     arch2 = Architecture(
         name="arch2", description="arch2",
         pxealiases=["fake", "foo"])
     ArchitectureRegistry.register_item("arch1", arch1)
     ArchitectureRegistry.register_item("arch2", arch2)
     self.assertEqual(
         arch1, ArchitectureRegistry.get_by_pxealias("archibald"))
示例#3
0
def make_kernel_parameters(testcase=None, **parms):
    """Make a randomly populated `KernelParameters` instance.

    If testcase is passed, we poke the generated arch/subarch into the
    ArchitectureRegistry and call addCleanup on the testcase to make sure
    it is removed after the test completes.
    """
    # fs_host needs to be an IP address, set it if it was not passed.
    if 'fs_host' not in parms:
        parms.update({'fs_host': factory.make_ip_address()})
    parms.update({
        field: factory.make_name(field)
        for field in KernelParameters._fields if field not in parms
    })
    if not isinstance(parms['http_boot'], bool):
        parms['http_boot'] = True
    params = KernelParameters(**parms)

    if testcase is not None:
        name = "%s/%s" % (params.arch, params.subarch)
        if name in ArchitectureRegistry:
            # It's already there, no need to patch and risk overwriting
            # preset kernel options.
            return params
        resource = Architecture(name, name)
        ArchitectureRegistry.register_item(name, resource)

        testcase.addCleanup(ArchitectureRegistry.unregister_item, name)

    return params