def test_can_create_selection(self): boot_source = BootSource(url="http://example.com", keyring_filename="/path/to/something") boot_source.save() selection = BootSourceSelection(boot_source=boot_source, os="ubuntu", release="trusty", arches=["i386"], subarches=["generic"], labels=["release"]) selection.save() self.assertEqual( ("ubuntu", "trusty", ["i386"], ["generic"], ["release"]), ( selection.os, selection.release, selection.arches, selection.subarches, selection.labels, ))
def get_bootsource(self, params, from_db=False): source_type = params.get("source_type", "custom") if source_type == "maas.io": url = DEFAULT_IMAGES_URL keyring_filename = DEFAULT_KEYRINGS_PATH keyring_data = b"" elif source_type == "custom": url = params["url"] keyring_filename = params.get("keyring_filename", "") keyring_data = params.get("keyring_data", "").encode("utf-8") if keyring_filename == "" and keyring_data == b"": keyring_filename = DEFAULT_KEYRINGS_PATH else: raise HandlerError("Unknown source_type: %s" % source_type) if from_db: source, created = BootSource.objects.get_or_create( url=url, defaults={ "keyring_filename": keyring_filename, "keyring_data": keyring_data, }, ) if not created: source.keyring_filename = keyring_filename source.keyring_data = keyring_data source.save() else: # This was a new source, make sure its the only source in the # database. This is because the UI only supports handling one # source at a time. BootSource.objects.exclude(id=source.id).delete() return source else: return BootSource( url=url, keyring_filename=keyring_filename, keyring_data=keyring_data, )
def get_bootsource(self, params, from_db=False): source_type = params.get('source_type', 'custom') if source_type == 'maas.io': url = DEFAULT_IMAGES_URL keyring_filename = DEFAULT_KEYRINGS_PATH keyring_data = b'' elif source_type == 'custom': url = params['url'] keyring_filename = params.get('keyring_filename', '') keyring_data = params.get('keyring_data', '').encode('utf-8') if keyring_filename == '' and keyring_data == b'': keyring_filename = DEFAULT_KEYRINGS_PATH else: raise HandlerError('Unknown source_type: %s' % source_type) if from_db: source, created = BootSource.objects.get_or_create( url=url, defaults={ 'keyring_filename': keyring_filename, 'keyring_data': keyring_data }) if not created: source.keyring_filename = keyring_filename source.keyring_data = keyring_data source.save() else: # This was a new source, make sure its the only source in the # database. This is because the UI only supports handling one # source at a time. BootSource.objects.exclude(id=source.id).delete() return source else: return BootSource( url=url, keyring_filename=keyring_filename, keyring_data=keyring_data, )