Example #1
0
def setup(app):
    global _RUN
    if _RUN:
        return

    # NOTE(sileht): On gnocchi.osci.io, we build a multiversion of the docs
    # all versions are built with the master gnocchi.gendoc sphinx extension.
    # So the hack here run an other python script to generate the rest.rst
    # file of old version of the module.
    # It also drop the database before each run.
    if sys.argv[0].endswith("sphinx-versioning"):
        subprocess.check_call(["dropdb", os.environ['PGDATABASE']])
        subprocess.check_call(["createdb", os.environ['PGDATABASE']])
        from sphinxcontrib.versioning import sphinx_
        version = sphinx_.EventHandlers.CURRENT_VERSION
        with tempfile.NamedTemporaryFile() as f:
            f.write(multiversion_hack % app.confdir)
            f.flush()
            subprocess.check_call(['python', f.name, version])
        _RUN = True
        return

    # TODO(jd) Do not hardcode doc/source
    with open("doc/source/rest.yaml") as f:
        scenarios = ScenarioList(yaml.load(f, Loader=yaml.FullLoader))

    test = test_rest.RestTest()
    test.auth_mode = "basic"
    test.setUpClass()
    test.setUp()
    webapp = test.app

    try:
        for entry in scenarios:
            if 'filter' in entry:
                entry['filter'] = jinja2.Template(
                    entry['filter']).render(scenarios=scenarios)

            template = jinja2.Template(entry['request'])
            fake_file = six.moves.cStringIO()
            content = template.render(scenarios=scenarios)
            if six.PY2:
                content = content.encode('utf-8')
            fake_file.write(content)
            fake_file.seek(0)
            request = webapp.RequestClass.from_file(fake_file)

            # TODO(jd) Fix this lame bug in webob < 1.7
            if (hasattr(webob.request, "http_method_probably_has_body")
                    and request.method == "DELETE"):
                # Webob has a bug it does not read the body for DELETE, l4m3r
                clen = request.content_length
                if clen is None:
                    request.body = fake_file.read()
                else:
                    request.body = fake_file.read(clen)

            LOG.info("Doing request %s: %s", entry['name'],
                     six.text_type(request))
            with webapp.use_admin_user():
                response = webapp.request(request)
            entry['response'] = response
            entry['doc'] = _format_request_reply(request, response)
    finally:
        test.tearDown()
        test.tearDownClass()
    with open("doc/source/rest.j2", "r") as f:
        content = f.read()
        if six.PY2:
            content = content.decode("utf-8")
        template = jinja2.Template(content)
    with open("doc/source/rest.rst", "w") as f:
        content = template.render(scenarios=scenarios)
        if six.PY2:
            content = content.encode("utf-8")
        f.write(content)

    config_output_file = 'doc/source/gnocchi.conf.sample'
    LOG.info("Generating %s", config_output_file)
    generator.main([
        '--config-file',
        '%s/gnocchi-config-generator.conf' % os.path.dirname(__file__),
        '--output-file',
        config_output_file,
    ])

    _RUN = True
Example #2
0
def _setup_test_app():
    t = test_rest.RestTest()
    t.auth_mode = "basic"
    t.setUpClass()
    t.setUp()
    return t.app
Example #3
0
def _setup_test_app():
    t = test_rest.RestTest()
    t.skip_archive_policies_creation = True
    t.auth = True
    t.setUp()
    return t.app
Example #4
0
def _setup_test_app():
    t = test_rest.RestTest()
    t.auth = True
    t.setUpClass()
    t.setUp()
    return t.app