Exemplo n.º 1
0
    def test_fasthash(self):
        (fdesc, tmp_path) = tempfile.mkstemp()
        os.close(fdesc)
        dname, fname = os.path.split(tmp_path)
        file = open(fname, 'w')
        file.write("blah blah hash")
        file.close()
        self.system['local']['imageDir'] = dname
        self.system['ssh']['imageDir'] = dname
        self.system['accesstype'] = 'local'

        hash = transfer.hash_file(fname, self.system)
        gh = 'ff68165577eb209adcfa2f793476a25da637142283409d6f4d8d61ee042c5e63'
        self.assertEquals(hash, gh)
        transfer.remove_file(fname, self.system)
Exemplo n.º 2
0
    def test_fasthash(self):
        (fdesc, tmp_path) = tempfile.mkstemp()
        os.close(fdesc)
        dname, fname = os.path.split(tmp_path)
        file = open(fname, 'w')
        file.write("blah blah hash")
        file.close()
        self.system['local']['imageDir'] = dname
        self.system['ssh']['imageDir'] = dname
        self.system['accesstype'] = 'local'

        hash = transfer.hash_file(fname, self.system)
        gh = 'ff68165577eb209adcfa2f793476a25da637142283409d6f4d8d61ee042c5e63'
        self.assertEquals(hash, gh)
        transfer.remove_file(fname, self.system)
Exemplo n.º 3
0
def img_import(request, updater, testmode=0):
    """
    Task to do the full workflow of copying an image and processing it
    """
    tag = request['tag']
    logging.debug("img_import system=%s tag=%s", request['system'], tag)
    if testmode == 1:
        states = ('HASHING', 'TRANSFER', 'READY')
        for state in states:
            logging.info("Worker: testmode Updating to %s", state)
            updater.update_status(state, state)
            sleep(1)
        ident = '%x' % randint(0, 100000)
        ret = {
            'id': ident,
            'entrypoint': ['./blah'],
            'workdir': '/root',
            'env': ['FOO=bar', 'BAZ=boz']
        }
        state = 'READY'
        updater.update_status(state, state, ret)
        return ret
    try:
        # Step 0 - Check if path is valid
        sysconf = CONFIG['Platforms'][request['system']]
        if not transfer.check_file(request["filepath"], sysconf, logging,
                                   import_image=True):
            raise OSError('Path not valid')
        # Step 1 - Calculate the hash of the file
        logging.debug("starting import hashing")
        updater.update_status('HASHING', 'HASHING')
        request['id'] = transfer.hash_file(request['filepath'], sysconf,
                                           logging)
        # Step 2 - Populate the metadata file
        logging.debug("starting writing metadata")
        if 'meta' not in request:
            raise OSError('Metadata not populated')
        request['meta']['format'] = request['format']
        request['meta']['user'] = request['session']['user']
        if not write_metadata(request):
            logging.info("Writing metadata")
            raise OSError('Metadata creation failed')
        # Step 3 - Copy image and meta file from user space to shifter area
        logging.debug("starting transfer")
        request['imagefile'] = request['id']+'.'+request['format']
        request['meta']['id'] = request['id']
        updater.update_status('TRANSFER', 'TRANSFER')
        if not transfer_image(request, import_image=True):
            logging.warn("Worker: Import copy failed")
            raise OSError("Import copy failed")

        # Done
        updater.update_status('READY', 'Image ready', response=request['meta'])
        cleanup_temporary(request, import_image=True)
        return request['meta']

    except:
        logging.error("ERROR: img_import failed system=%s tag=%s",
                      request['system'], request['tag'])
        print sys.exc_value
        updater.update_status('FAILURE', 'FAILED')

        # TODO: add a debugging flag and only disable cleanup if debugging
        cleanup_temporary(request)
        raise
Exemplo n.º 4
0
def img_import(request, updater, testmode=0):
    """
    Task to do the full workflow of copying an image and processing it
    """
    tag = request['tag']
    logging.debug("img_import system=%s tag=%s", request['system'], tag)
    if testmode == 1:
        states = ('HASHING', 'TRANSFER', 'READY')
        for state in states:
            logging.info("Worker: testmode Updating to %s", state)
            updater.update_status(state, state)
            sleep(1)
        ident = '%x' % randint(0, 100000)
        ret = {
            'id': ident,
            'entrypoint': ['./blah'],
            'workdir': '/root',
            'env': ['FOO=bar', 'BAZ=boz']
        }
        state = 'READY'
        updater.update_status(state, state, ret)
        return ret
    try:
        # Step 0 - Check if path is valid
        sysconf = CONFIG['Platforms'][request['system']]
        if not transfer.check_file(request["filepath"], sysconf, logging,
                                   import_image=True):
            raise OSError('Path not valid')
        # Step 1 - Calculate the hash of the file
        logging.debug("starting import hashing")
        updater.update_status('HASHING', 'HASHING')
        logging.info(request)
        request['id'] = transfer.hash_file(request['filepath'], sysconf,
                                           logging)
        # Step 2 - Populate the metadata file
        logging.debug("starting writing metadata")
        if 'meta' not in request:
            raise OSError('Metadata not populated')
        request['meta']['format'] = request['format']
        request['meta']['user'] = request['session']['user']
        if not write_metadata(request):
            logging.info("Writing metadata")
            raise OSError('Metadata creation failed')
        # Step 3 - Copy image and meta file from user space to shifter area
        logging.debug("starting transfer")
        request['imagefile'] = request['id']+'.'+request['format']
        request['meta']['id'] = request['id']
        updater.update_status('TRANSFER', 'TRANSFER')
        if not transfer_image(request, import_image=True):
            logging.warn("Worker: Import copy failed")
            raise OSError("Import copy failed")

        # Done
        updater.update_status('READY', 'Image ready', response=request['meta'])
        cleanup_temporary(request, import_image=True)
        return request['meta']

    except:
        logging.error("ERROR: img_import failed system=%s tag=%s",
                      request['system'], request['tag'])
        print sys.exc_value
        updater.update_status('FAILURE', 'FAILED')

        # TODO: add a debugging flag and only disable cleanup if debugging
        cleanup_temporary(request)
        raise