~rvb/maas/transaction-1.7-bug-1409852

« back to all changes in this revision

Viewing changes to src/provisioningserver/import_images/boot_resources.py

merged upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
from provisioningserver.utils.fs import (
38
38
    atomic_write,
39
39
    read_text_file,
 
40
    tempdir,
40
41
    )
41
42
from provisioningserver.utils.shell import call_and_check
42
43
 
226
227
        maaslog.warn("Can't import: no Simplestreams sources selected.")
227
228
        return
228
229
 
229
 
    # We download the keyrings now  because we need them for both
230
 
    # download_all_image_descriptions() and
231
 
    # download_all_boot_resources() later.
232
 
    sources = write_all_keyrings(sources)
233
 
 
234
 
    image_descriptions = download_all_image_descriptions(sources)
235
 
    if image_descriptions.is_empty():
236
 
        maaslog.warn(
237
 
            "No boot resources found.  "
238
 
            "Check sources specification and connectivity.")
239
 
        return
240
 
 
241
 
    storage = provisioningserver.config.BOOT_RESOURCES_STORAGE
242
 
    meta_file_content = image_descriptions.dump_json()
243
 
    if meta_contains(storage, meta_file_content):
244
 
        # The current maas.meta already contains the new config.  No need to
245
 
        # rewrite anything.
246
 
        return
247
 
 
248
 
    product_mapping = map_products(image_descriptions)
249
 
 
250
 
    snapshot_path = download_all_boot_resources(
251
 
        sources, storage, product_mapping)
 
230
    with tempdir('keyrings') as keyrings_path:
 
231
        # We download the keyrings now  because we need them for both
 
232
        # download_all_image_descriptions() and
 
233
        # download_all_boot_resources() later.
 
234
        sources = write_all_keyrings(keyrings_path, sources)
 
235
 
 
236
        image_descriptions = download_all_image_descriptions(sources)
 
237
        if image_descriptions.is_empty():
 
238
            maaslog.warn(
 
239
                "No boot resources found.  "
 
240
                "Check sources specification and connectivity.")
 
241
            return
 
242
 
 
243
        storage = provisioningserver.config.BOOT_RESOURCES_STORAGE
 
244
        meta_file_content = image_descriptions.dump_json()
 
245
        if meta_contains(storage, meta_file_content):
 
246
            # The current maas.meta already contains the new config.  No need
 
247
            # to rewrite anything.
 
248
            return
 
249
 
 
250
        product_mapping = map_products(image_descriptions)
 
251
 
 
252
        snapshot_path = download_all_boot_resources(
 
253
            sources, storage, product_mapping)
252
254
 
253
255
    maaslog.info("Writing metadata and iSCSI targets.")
254
256
    write_snapshot_metadata(snapshot_path, meta_file_content)