def test_bad_to_good(self):
        logger.debug('test_bad_to_good (2)')
        r = None
        try:
            pathutil.delete_folder(self.repose_config_folder)
            pathutil.create_folder(self.repose_config_folder)
            conf.process_config_set(self.config_common,
                                    params=self.config_params,
                                    destination_path=self.repose_config_folder,
                                    verbose=False)

            conf.process_config_set(self.config_bad,
                                    params=self.config_params,
                                    destination_path=self.repose_config_folder,
                                    verbose=False)
            r = repose.ReposeValve(self.repose_config_folder,
                                   stop_port=self.repose_stop_port)
            time.sleep(self.sleep_time)
            self.assertRaises(requests.ConnectionError, requests.get,
                              self.repose_url)
            conf.process_config_set(self.config_good,
                                    params=self.config_params,
                                    destination_path=self.repose_config_folder,
                                    verbose=False)
            time.sleep(self.sleep_time)
            self.assertEquals(self.get_status_code_from_url(self.repose_url),
                              self.get_good_response())
        finally:
            if r:
                r.stop()
Exemplo n.º 2
0
def process_config_set(config_set_name, destination_path=None,
                       configs_folder=None, params=None, verbose=True):

    if params is None:
        params = {}

    if os.path.isfile(config_set_name):
        # it's a file
        config_xml = et.parse(config_set_name)
        source_context = os.path.dirname(config_set_name)
    else:
        # try a named config set in the configs folder
        if configs_folder is None:
            configs_folder = get_configs_folder()
        if config_set_name not in get_config_sets(configs_folder):
            raise NamedConfigSetNotFoundException(config_set_name)
        filename = pathutil.join(configs_folder, config_set_name,
                                 '.config-set.xml')
        config_xml = et.parse(filename)
        source_context = pathutil.join(configs_folder, config_set_name)

    for folder in config_xml.findall('folder'):
        folder_path = folder.attrib.get('path', '.')
        for f in folder.findall('file'):
            file_source = pathutil.join(source_context, f.attrib['src'])
            file_basename = os.path.basename(file_source)
            if destination_path and folder_path:
                full_dest = pathutil.join(destination_path, folder_path)
            elif destination_path:
                full_dest = destination_path
            elif folder_path:
                full_dest = folder_path
            else:
                full_dest = '.'
            pathutil.create_folder(full_dest)
            file_dest = pathutil.join(full_dest, file_basename)

            if verbose:
                applying = ''
                if len(params) > 0:
                    # TODO: maybe output parameters provided/substituted?
                    applying = ', applying config parameters'

                print ('Copy from "%s" to "%s"%s' %
                       (file_source, file_dest, applying))

            copy_and_apply_params(file_source, file_dest, params, verbose)
def setUpModule():
    logger.debug('setUpModule')
    repose_conf_folder = 'etc/repose'
    pathutil.delete_folder(repose_conf_folder)
    pathutil.create_folder(repose_conf_folder)
    pathutil.create_folder('usr/share/repose/filters')
    pathutil.create_folder('var/log/repose')
    pathutil.create_folder('var/repose')
    #install_repose.get_repose(valve_dest='usr/share/repose',
    #                          ear_dest='usr/share/repose/filters')
    create_mock()
    logger.debug('setUpModule complete')
Exemplo n.º 4
0
 def test_start_missing(self):
     logger.debug('test_start_missing')
     r = None
     try:
         pathutil.delete_folder(self.repose_config_folder)
         pathutil.create_folder(self.repose_config_folder)
         conf.process_config_set(self.config_common,
                                 params=self.config_params,
                                 destination_path=self.repose_config_folder,
                                 verbose=False, configs_folder=configs_folder)
         
         r = repose.ReposeValve(self.repose_config_folder,
                                stop_port=self.repose_stop_port)
         time.sleep(self.sleep_time)
         self.assertEquals(self.get_status_code_from_url(self.repose_url),
                           self.get_good_response())
     finally:
         if r:
             r.stop()
Exemplo n.º 5
0
def setUpModule():
    # Set up folder hierarchy and install repose JAR/EARs if needed
    logger.debug('setUpModule')
    pathutil.create_folder(config_dir)
    pathutil.create_folder(deploy_dir)
    pathutil.create_folder(os.path.dirname(log_file))
    pass
Exemplo n.º 6
0
def download_file(url, filename=None):
    if filename is None:
        filename = url.split('/')[-1]

    pathutil.create_folder(os.path.dirname(filename))

    response = requests.get(url)
    if response.status_code != 200:
        raise ValueError

    blocksize = 4096
    count = 0
    with open('./%s' % filename, 'wb') as f:
        for block in response.iter_content(blocksize):
            f.write(block)
            count += len(block)
            if count > 100000:
                count = 0
                sys.stdout.write('.')
                sys.stdout.flush()
        print
    return filename