Пример #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({}))
Пример #2
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)")
Пример #3
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({}))
Пример #4
0
 def test_machine_actions_for_non_admin(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.assertItemsEqual([
         'release', 'mark-broken', 'on', 'deploy', 'mark-fixed',
         'commission', 'abort', 'acquire', 'off', 'rescue-mode',
         'exit-rescue-mode', 'test'
     ], [action['name'] for action in handler.machine_actions({})])
Пример #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")
Пример #6
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]),
     )
Пример #7
0
 def test_region_and_rack_controller_actions_for_admin(self):
     handler = GeneralHandler(factory.make_admin(), {}, None)
     self.assertItemsEqual(
         ["set-zone", "delete", "import-images"],
         [
             action["name"]
             for action in handler.region_and_rack_controller_actions({})
         ],
     )
Пример #8
0
 def test_architectures(self):
     arches = [
         "%s/%s" % (factory.make_name("arch"), factory.make_name("subarch"))
         for _ in range(3)
     ]
     for arch in arches:
         factory.make_usable_boot_resource(architecture=arch)
     handler = GeneralHandler(factory.make_User(), {})
     self.assertEqual(sorted(arches), handler.architectures({}))
Пример #9
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({}), [])
Пример #10
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")
Пример #11
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({}))
Пример #12
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"],
     )
Пример #13
0
 def test_rack_controller_actions_for_admin(self):
     handler = GeneralHandler(factory.make_admin(), {}, None)
     self.assertItemsEqual(
         [
             "delete",
             "import-images",
             "off",
             "on",
             "set-zone",
             "test",
             "override-failed-testing",
         ],
         [action["name"] for action in handler.rack_controller_actions({})],
     )
Пример #14
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")
Пример #15
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({}),
     )
Пример #16
0
 def test_osinfo(self):
     handler = GeneralHandler(factory.make_User(), {})
     osystem = make_osystem_with_releases(self)
     releases = [("%s/%s" % (osystem["name"], release["name"]),
                  release["title"]) for release in osystem["releases"]]
     self.patch(general, "list_osystem_choices").return_value = [
         (osystem["name"], osystem["title"]),
     ]
     self.patch(general, "list_release_choices").return_value = releases
     expected_osinfo = {
         "osystems": [
             (osystem["name"], osystem["title"]),
         ],
         "releases": releases,
         "kernels": {},
         "default_osystem": Config.objects.get_config("default_osystem"),
         "default_release":
         Config.objects.get_config("default_distro_series"),
     }
     self.assertEqual(expected_osinfo, handler.osinfo({}))
Пример #17
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"])
Пример #18
0
 def test_machine_actions_for_non_admin(self):
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.assertItemsEqual(
         [
             "release",
             "mark-broken",
             "on",
             "deploy",
             "mark-fixed",
             "commission",
             "abort",
             "acquire",
             "off",
             "rescue-mode",
             "exit-rescue-mode",
             "lock",
             "tag",
             "test",
             "override-failed-testing",
             "unlock",
         ],
         [action["name"] for action in handler.machine_actions({})],
     )
Пример #19
0
 def test_power_types(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.patch_autospec(
         general,
         "get_all_power_types_from_racks").return_value = sentinel.types
     self.assertEqual(sentinel.types, handler.power_types({}))
Пример #20
0
 def test_version(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.patch_autospec(
         general, "get_maas_version_ui").return_value = sentinel.version
     self.assertEqual(sentinel.version, handler.version({}))
Пример #21
0
 def test_region_and_rack_controller_actions_for_non_admin(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.assertEqual([], handler.region_and_rack_controller_actions({}))
Пример #22
0
 def test_region_and_rack_controller_actions_for_admin(self):
     handler = GeneralHandler(factory.make_admin(), {})
     self.assertItemsEqual(['set-zone', 'delete', 'import-images'], [
         action['name']
         for action in handler.region_and_rack_controller_actions({})
     ])
Пример #23
0
 def test_device_actions_for_non_admin(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.assertEqual([], handler.device_actions({}))
Пример #24
0
 def test_device_actions_for_non_admin(self):
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.assertItemsEqual(
         ["set-zone", "delete"],
         [action["name"] for action in handler.device_actions({})],
     )
Пример #25
0
 def test_machine_actions_for_admin(self):
     handler = GeneralHandler(factory.make_admin(), {})
     actions_expected = self.dehydrate_actions(ACTIONS_DICT,
                                               NODE_TYPE.MACHINE)
     self.assertItemsEqual(actions_expected, handler.machine_actions({}))
Пример #26
0
 def test_navigation_options(self):
     handler = GeneralHandler(factory.make_User(), {}, None)
     self.assertEqual({"rsd": False}, handler.navigation_options({}))
Пример #27
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({}),
     )
Пример #28
0
 def test_known_architectures(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.assertEqual(PackageRepository.objects.get_known_architectures(),
                      handler.known_architectures({}))
Пример #29
0
 def test_components_to_disable(self):
     handler = GeneralHandler(factory.make_User(), {})
     self.assertEqual(PackageRepository.objects.get_components_to_disable(),
                      handler.components_to_disable({}))
Пример #30
0
 def test_device_actions_for_admin(self):
     handler = GeneralHandler(factory.make_admin(), {})
     self.assertItemsEqual(
         ['set-zone', 'delete'],
         [action['name'] for action in handler.device_actions({})])