Esempio n. 1
0
 def test_list_boot_images_finds_boot_image(self):
     params = make_boot_image_storage_params()
     self.make_image_dir(params, self.tftproot)
     purposes = ['install', 'commissioning', 'xinstall']
     make_osystem(self, params['osystem'], purposes)
     self.assertItemsEqual(
         [make_image(params, purpose) for purpose in purposes],
         list_boot_images(self.tftproot))
Esempio n. 2
0
 def test_list_boot_images_finds_boot_image(self):
     params = make_boot_image_storage_params()
     self.make_image_dir(params, self.tftproot)
     purposes = ["install", "commissioning", "xinstall"]
     make_osystem(self, params["osystem"], purposes)
     self.assertItemsEqual(
         [make_image(params, purpose) for purpose in purposes],
         list_boot_images(self.tftproot),
     )
Esempio n. 3
0
 def test_validation_allows_any_uploaded_name_slash_with_supported_os(self):
     osystem = factory.make_name('osystem')
     make_osystem(self, osystem)
     name = '%s/%s' % (osystem, factory.make_name('release'))
     arch = '%s/%s' % (
         factory.make_name('arch'), factory.make_name('subarch'))
     resource = BootResource(
         rtype=BOOT_RESOURCE_TYPE.UPLOADED, name=name, architecture=arch)
     resource.save()
Esempio n. 4
0
 def test_list_boot_images_enumerates_boot_images(self):
     purposes = ['install', 'commissioning', 'xinstall']
     params = [make_boot_image_storage_params() for counter in range(3)]
     for param in params:
         self.make_image_dir(param, self.tftproot)
         make_osystem(self, param['osystem'], purposes)
     self.assertItemsEqual([
         make_image(param, purpose) for param in params
         for purpose in purposes
     ], list_boot_images(self.tftproot))
Esempio n. 5
0
 def test_validation_allows_any_uploaded_name_slash_with_supported_os(self):
     osystem = factory.make_name("osystem")
     make_osystem(self, osystem)
     name = "%s/%s" % (osystem, factory.make_name("release"))
     arch = "%s/%s" % (
         factory.make_name("arch"),
         factory.make_name("subarch"),
     )
     resource = BootResource(
         rtype=BOOT_RESOURCE_TYPE.UPLOADED, name=name, architecture=arch
     )
     resource.save()
Esempio n. 6
0
 def test_list_boot_images_merges_maas_meta_data(self):
     params = make_boot_image_storage_params()
     self.make_image_dir(params, self.tftproot)
     # The required metadata is called "subarches" in maas.meta
     metadata = dict(subarches=factory.make_name("subarches"))
     self.make_meta_file(params, metadata, self.tftproot)
     purposes = ['install', 'commissioning', 'xinstall']
     make_osystem(self, params['osystem'], purposes)
     # The API requires "supported_subarches".
     expected_metadata = dict(supported_subarches=metadata["subarches"])
     self.assertItemsEqual([
         make_image(params, purpose, expected_metadata)
         for purpose in purposes
     ], list_boot_images(self.tftproot))
Esempio n. 7
0
    def test_compose_preseed_with_osystem_compose_preseed(self):
        os_name = factory.make_name("os")
        osystem = make_osystem(self, os_name, [BOOT_IMAGE_PURPOSE.XINSTALL])
        compose_preseed_orig = osystem.compose_preseed
        compose_preseed_mock = self.patch(osystem, "compose_preseed")
        compose_preseed_mock.side_effect = compose_preseed_orig

        rack_controller = factory.make_RackController(url="")
        node = factory.make_Node(interface=True,
                                 osystem=os_name,
                                 status=NODE_STATUS.READY)
        nic = node.get_boot_interface()
        nic.vlan.dhcp_on = True
        nic.vlan.primary_rack = rack_controller
        nic.vlan.save()
        self.useFixture(RunningClusterRPCFixture())
        token = NodeKey.objects.get_token_for_node(node)
        request = make_HttpRequest()
        expected_url = request.build_absolute_uri(reverse("curtin-metadata"))
        compose_preseed(request, PRESEED_TYPE.CURTIN, node)
        self.assertThat(
            compose_preseed_mock,
            MockCalledOnceWith(
                PRESEED_TYPE.CURTIN,
                (node.system_id, node.hostname),
                (token.consumer.key, token.key, token.secret),
                expected_url,
            ),
        )
Esempio n. 8
0
 def test_compose_preseed_propagates_NoConnectionsAvailable(self):
     # If the region does not have any connections to the node's cluster
     # controller, compose_preseed() simply passes the exception up.
     os_name = factory.make_name('os')
     make_osystem(self, os_name, [BOOT_IMAGE_PURPOSE.XINSTALL])
     make_usable_osystem(self, os_name)
     rack_controller = factory.make_RackController()
     node = factory.make_Node(interface=True,
                              osystem=os_name,
                              status=NODE_STATUS.READY)
     nic = node.get_boot_interface()
     nic.vlan.dhcp_on = True
     nic.vlan.primary_rack = rack_controller
     nic.vlan.save()
     self.assertRaises(NoConnectionsAvailable, compose_preseed,
                       make_HttpRequest(), PRESEED_TYPE.CURTIN, node)
Esempio n. 9
0
 def test_find_image(self):
     osystem = make_osystem(self, factory.make_name("os"))
     tmpdir = self.make_dir()
     arch = factory.make_name("arch")
     subarch = factory.make_name("subarch")
     release = factory.make_name("release")
     label = factory.make_name("label")
     dir_path = os.path.join(tmpdir, osystem.name, arch, subarch, release,
                             label)
     os.makedirs(dir_path)
     if self.fname:
         factory.make_file(dir_path, self.fname)
     self.useFixture(ClusterConfigurationFixture(tftp_root=tmpdir))
     self.assertItemsEqual(
         self.expected,
         osystem._find_image(
             arch,
             subarch,
             release,
             label,
             tgz=self.tgz,
             dd=self.dd,
             squashfs=self.squashfs,
         ),
     )
Esempio n. 10
0
    def test_compose_preseed_with_osystem_compose_preseed(self):
        os_name = factory.make_name('os')
        osystem = make_osystem(self, os_name, [BOOT_IMAGE_PURPOSE.XINSTALL])
        make_usable_osystem(self, os_name)
        compose_preseed_orig = osystem.compose_preseed
        compose_preseed_mock = self.patch(osystem, 'compose_preseed')
        compose_preseed_mock.side_effect = compose_preseed_orig

        rack_controller = factory.make_RackController(url='')
        node = factory.make_Node(interface=True,
                                 osystem=os_name,
                                 status=NODE_STATUS.READY)
        nic = node.get_boot_interface()
        nic.vlan.dhcp_on = True
        nic.vlan.primary_rack = rack_controller
        nic.vlan.save()
        self.useFixture(RunningClusterRPCFixture())
        token = NodeKey.objects.get_token_for_node(node)
        region_ip = factory.make_ip_address()
        expected_url = absolute_reverse('curtin-metadata',
                                        default_region_ip=region_ip)
        compose_preseed(PRESEED_TYPE.CURTIN, node, default_region_ip=region_ip)
        self.assertThat(
            compose_preseed_mock,
            MockCalledOnceWith(PRESEED_TYPE.CURTIN,
                               (node.system_id, node.hostname),
                               (token.consumer.key, token.key, token.secret),
                               expected_url))
Esempio n. 11
0
 def test_returns_empty_release_title_when_None_returned(self):
     os_name = factory.make_name("os")
     purposes = [BOOT_IMAGE_PURPOSE.XINSTALL]
     osystem = make_osystem(self, os_name, purposes)
     release = random.choice(osystem.get_supported_releases())
     self.patch(osystem, "get_release_title").return_value = None
     self.assertEqual("",
                      osystems.get_os_release_title(osystem.name, release))
Esempio n. 12
0
 def make_usable_osystem(self):
     return make_osystem(
         self,
         factory.make_name("os"),
         [
             BOOT_IMAGE_PURPOSE.COMMISSIONING,
             BOOT_IMAGE_PURPOSE.INSTALL,
             BOOT_IMAGE_PURPOSE.XINSTALL,
         ],
     )
Esempio n. 13
0
 def test_rejects_when_validate_license_key_for_raise_no_os(self):
     user = factory.make_User()
     self.client.login(user=user)
     node = factory.make_Node(owner=user)
     osystem = factory.make_name('osystem')
     release = factory.make_name('release')
     distro_series = '%s/%s' % (osystem, release)
     make_osystem(self, osystem, [release])
     factory.make_BootResource(name=distro_series)
     license_key = factory.make_name('key')
     mock_validate_for = self.patch(forms, 'validate_license_key_for')
     mock_validate_for.side_effect = NoSuchOperatingSystem()
     form = MachineForm(data={
         'architecture': make_usable_architecture(self),
         'osystem': osystem,
         'distro_series': distro_series,
         'license_key': license_key,
     },
                        instance=node)
     self.assertFalse(form.is_valid())
     self.assertItemsEqual(['license_key'], form._errors.keys())
Esempio n. 14
0
 def test_validates_key(self):
     os_name = factory.make_name("os")
     purposes = [BOOT_IMAGE_PURPOSE.XINSTALL]
     osystem = make_osystem(self, os_name, purposes)
     release = random.choice(osystem.get_supported_releases())
     os_specific_validate_license_key = self.patch(osystem,
                                                   "validate_license_key")
     osystems.validate_license_key(osystem.name, release, sentinel.key)
     self.assertThat(
         os_specific_validate_license_key,
         MockCalledOnceWith(release, sentinel.key),
     )
Esempio n. 15
0
 def test_rejects_when_validate_license_key_for_raise_no_os(self):
     user = factory.make_User()
     self.client.login(user=user)
     node = factory.make_Node(owner=user)
     osystem = factory.make_name("osystem")
     release = factory.make_name("release")
     distro_series = "%s/%s" % (osystem, release)
     make_osystem(self, osystem, [release])
     factory.make_BootResource(name=distro_series)
     license_key = factory.make_name("key")
     mock_validate_for = self.patch(forms, "validate_license_key_for")
     mock_validate_for.side_effect = NoSuchOperatingSystem()
     form = MachineForm(
         data={
             "architecture": make_usable_architecture(self),
             "osystem": osystem,
             "distro_series": distro_series,
             "license_key": license_key,
         },
         instance=node,
     )
     self.assertFalse(form.is_valid())
     self.assertItemsEqual(["license_key"], form._errors.keys())
Esempio n. 16
0
 def test_get_xinstall_parameters(self):
     # The base OperatingSystems class should only look for root-tgz,
     # child classes can override.
     osystem = make_osystem(self, factory.make_name('os'))
     tmpdir = self.make_dir()
     arch = factory.make_name('arch')
     subarch = factory.make_name('subarch')
     release = factory.make_name('release')
     label = factory.make_name('label')
     dir_path = os.path.join(tmpdir, osystem.name, arch, subarch, release,
                             label)
     os.makedirs(dir_path)
     for fname in ['squashfs', 'root-tgz', 'root-dd']:
         factory.make_file(dir_path, fname)
     self.useFixture(ClusterConfigurationFixture(tftp_root=tmpdir))
     self.assertItemsEqual(
         ('root-tgz', 'tgz'),
         osystem.get_xinstall_parameters(arch, subarch, release, label))
Esempio n. 17
0
 def test_get_xinstall_parameters(self):
     # The base OperatingSystems class should only look for root-tgz,
     # child classes can override.
     osystem = make_osystem(self, factory.make_name("os"))
     tmpdir = self.make_dir()
     arch = factory.make_name("arch")
     subarch = factory.make_name("subarch")
     release = factory.make_name("release")
     label = factory.make_name("label")
     dir_path = os.path.join(tmpdir, osystem.name, arch, subarch, release,
                             label)
     os.makedirs(dir_path)
     for fname in ["squashfs", "root-tgz", "root-dd"]:
         factory.make_file(dir_path, fname)
     self.useFixture(ClusterConfigurationFixture(tftp_root=tmpdir))
     self.assertItemsEqual(
         ("root-tgz", "tgz"),
         osystem.get_xinstall_parameters(arch, subarch, release, label),
     )
Esempio n. 18
0
    def test_compose_preseed_propagates_NoSuchOperatingSystem(self):
        # If the cluster controller replies that the node's OS is not known to
        # it, compose_preseed() simply passes the exception up.
        os_name = factory.make_name('os')
        osystem = make_osystem(self, os_name, [BOOT_IMAGE_PURPOSE.XINSTALL])
        compose_preseed_mock = self.patch(osystem, 'compose_preseed')
        compose_preseed_mock.side_effect = NoSuchOperatingSystem
        rack_controller = factory.make_RackController()
        node = factory.make_Node(interface=True,
                                 osystem=os_name,
                                 status=NODE_STATUS.READY)
        nic = node.get_boot_interface()
        nic.vlan.dhcp_on = True
        nic.vlan.primary_rack = rack_controller
        nic.vlan.save()

        self.useFixture(RunningClusterRPCFixture())
        self.assertRaises(NoSuchOperatingSystem, compose_preseed,
                          make_HttpRequest(), PRESEED_TYPE.CURTIN, node)