Exemple #1
0
 def test_bond_options(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.assertEqual({
         "modes": BOND_MODE_CHOICES,
         "lacp_rates": BOND_LACP_RATE_CHOICES,
         "xmit_hash_policies": BOND_XMIT_HASH_POLICY_CHOICES,
         }, handler.bond_options({}))
Exemple #2
0
 def test_hwe_min_kernels(self):
     expected_output = self.make_boot_sources()
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.assertItemsEqual(
         sorted(expected_output, key=lambda choice: choice[0]),
         sorted(handler.min_hwe_kernels({}), key=lambda choice: choice[0]),
     )
Exemple #3
0
 def test_version_extended_info(self):
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.patch_autospec(
         general,
         "get_running_version").return_value = MAASVersion.from_string(
             "1.2.3-456-g.deadbeef")
     self.assertEqual(handler.version({}), "1.2.3 (456-g.deadbeef)")
Exemple #4
0
 def test_random_hostname_checks_hostname_existence(self):
     existing_node = factory.make_Node(hostname="hostname")
     hostnames = [existing_node.hostname, "new-hostname"]
     self.patch(
         petname, "Generate").side_effect = hostnames
     handler = GeneralHandler(factory.make_User(), {})
     self.assertEqual("new-hostname", handler.random_hostname({}))
Exemple #5
0
 def test_version(self):
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.patch_autospec(
         general,
         "get_running_version").return_value = MAASVersion.from_string(
             "1.2.3~rc1")
     self.assertEqual(handler.version({}), "1.2.3~rc1")
Exemple #6
0
 def test_deprecation_notices_snap_not_all_mode(self):
     self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current"))
     snap_common_path = Path(self.make_dir())
     self.useFixture(
         EnvironmentVariable("SNAP_COMMON", str(snap_common_path)))
     snap_common_path.joinpath("snap_mode").write_text(
         "region+rack", "utf-8")
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.assertEqual(handler.deprecation_notices({}), [])
Exemple #7
0
 def test_deprecation_notices_snap_all_mode(self):
     self.useFixture(EnvironmentVariable("SNAP", "/snap/maas/current"))
     snap_common_path = Path(self.make_dir())
     self.useFixture(
         EnvironmentVariable("SNAP_COMMON", str(snap_common_path)))
     snap_common_path.joinpath("snap_mode").write_text("all", "utf-8")
     handler = GeneralHandler(factory.make_User(), {}, None)
     [notice] = handler.deprecation_notices({})
     self.assertEqual(notice["id"], "MD1")
     self.assertEqual(notice["since"], "2.8")
Exemple #8
0
 def test_release_options(self):
     handler = GeneralHandler(factory.make_User(), {})
     erase = factory.pick_bool()
     secure_erase = factory.pick_bool()
     quick_erase = factory.pick_bool()
     Config.objects.set_config('enable_disk_erasing_on_release', erase)
     Config.objects.set_config('disk_erase_with_secure_erase', secure_erase)
     Config.objects.set_config('disk_erase_with_quick_erase', quick_erase)
     self.assertEqual({
         "erase": erase,
         "secure_erase": secure_erase,
         "quick_erase": quick_erase,
     }, handler.release_options({}))
Exemple #9
0
 def test_generate_certificate_with_name(self):
     Config.objects.set_config("maas_name", "mymaas")
     handler = GeneralHandler(factory.make_User(), {}, None)
     result = handler.generate_client_certificate({"object_name": "mypod"})
     self.assertEqual(result["CN"], "mypod@mymaas")
     self.assertTrue(
         result["certificate"].startswith("-----BEGIN CERTIFICATE-----"),
         result["certificate"],
     )
     self.assertTrue(
         result["private_key"].startswith("-----BEGIN PRIVATE KEY-----"),
         result["private_key"],
     )
Exemple #10
0
 def test_target_version_snap_cohort(self):
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0~beta2-123-g.asdf",
                 "revision": "1234",
             },
             channel="3.0/beta",
             cohort="abc",
         ),
     )
     handler = GeneralHandler(factory.make_User(), {}, None)
     result = handler.target_version({})
     self.assertEqual(result["snap_cohort"], "abc")
Exemple #11
0
 def test_known_boot_architectures(self):
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.assertEqual(
         [{
             "name":
             boot_method.name,
             "bios_boot_method":
             boot_method.bios_boot_method,
             "bootloader_arches":
             "/".join(boot_method.bootloader_arches),
             "arch_octet":
             boot_method.arch_octet,
             "protocol": ("http" if boot_method.http_url
                          or boot_method.user_class else "tftp"),
         } for _, boot_method in BootMethodRegistry
          if boot_method.arch_octet or boot_method.user_class],
         handler.known_boot_architectures({}),
     )
Exemple #12
0
 def test_target_version(self):
     controller = factory.make_RackController()
     ControllerInfo.objects.set_versions_info(
         controller,
         SnapVersionsInfo(
             current={
                 "version": "3.0.0~beta2-123-g.asdf",
                 "revision": "1234",
             },
             update={
                 "version": "3.0.0~beta3-456-g.cafe",
                 "revision": "5678",
             },
             channel="3.0/beta",
         ),
     )
     handler = GeneralHandler(factory.make_User(), {}, None)
     result = handler.target_version({})
     self.assertEqual(result["version"], "3.0.0~beta3-456-g.cafe")
     self.assertEqual(result["snap_channel"], "3.0/beta")
     self.assertIsNotNone(result["first_reported"])
Exemple #13
0
 def test_pockets_to_disable(self):
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.assertEqual(
         PackageRepository.objects.get_pockets_to_disable(),
         handler.pockets_to_disable({}),
     )