예제 #1
0
    def setUp(self):
        self.sitedir = sitedir = tempfile.mkdtemp()
        self.scanroot = scanroot = os.path.join(sitedir, 'scanroot')
        os.mkdir(scanroot)
        os.mkdir(os.path.join(scanroot, 'foo'))
        os.mkdir(os.path.join(scanroot, 'bar'))
        self.siteconf = siteconf = os.path.join(sitedir, 'marv.conf')
        with open(siteconf, 'w') as f:
            f.write(inspect.cleandoc(self.CONFIG))

        prefix = 'test{}_'.format(self.counter.next())
        marv.model._LISTING_PREFIX
        marv.model._LISTING_PREFIX = prefix
        self.site = Site(siteconf)

        app = marv.app.create_app(self.site)
        appctx = app.app_context()
        appctx.push()

        def cleanup():
            appctx.pop()
            db.session.remove()
            del self.site
            for table in [
                    v for k, v in db.metadata.tables.items()
                    if k.startswith(prefix)
            ]:
                db.metadata.remove(table)
            if not KEEP:
                shutil.rmtree(sitedir)
            else:
                print('Keeping {}'.format(sitedir))

        self.cleanup = cleanup
예제 #2
0
def marv_node_run(ctx, all_nodes, all_filesets, changed_config, rerun,
                  dependent, fileset, node, update_detail):
    """Run nodes for filesets"""
    if node and all_nodes:
        ctx.fail('Specified --node with --all or --all-nodes')
    if fileset and all_filesets:
        ctx.fail('Specified --fileset with --all or --all-filesets')
    if not fileset and not all_filesets:
        click.echo('No filesets selected, nothing to be done')
        ctx.exit()
    # if not node and not all_nodes and not update_detail:
    #     click.echo('Neither nodes nor detail update selected, nothing to be done')
    #     ctx.exit()

    app = create_app()
    with app.app_context():
        if 'fileset' in node:
            ctx.fail(
                "Cannot rerun fileset node.\n"
                "Use 'marv fileset discard|scan' to discard and rescan a fileset."
            )
        unknown = set(node) - app.site.nodes.nodes.viewkeys()
        if unknown:
            ctx.fail('Unknown nodes: %s' % ', '.join(sorted(unknown)))
        app.site.node_run(
            nodes=None if all_nodes else node,
            uuids=None if all_filesets else [str(x) for x in fileset],
            changed_config=changed_config,
            rerun=rerun,
            dependent=dependent,
            update_detail=update_detail)
예제 #3
0
def app(site):
    app = marv.app.create_app(site, init=True)
    app.testing = True
    with app.app_context():
        app = app.test_client()
        def get_json(*args, **kw):
            resp = app.get(*args, **kw)
            return json.loads(resp.data)
        app.get_json = get_json
        yield app
예제 #4
0
def marv_node_discard(ctx, all_nodes, all_filesets, update_detail, fileset,
                      node, comments, tags):
    """Discard marv node output"""
    if node and all_nodes:
        ctx.fail('Specified --node with --all or --all-nodes')
    if fileset and all_filesets:
        ctx.fail('Specified --fileset with --all or --all-filesets')
    if not fileset and not all_filesets:
        click.echo('No filesets selected, nothing to discard')
        ctx.exit()
    if not node and not all_nodes:
        click.echo('No nodes selected, nothing to discard')
        ctx.exit()

    if all_filesets:
        click.confirm('Are you sure you want to discard %s for all filesets' %
                      ('all nodes' if all_nodes else ', '.join(sorted(node))),
                      abort=True)

    app = create_app()
    with app.app_context():
        if all_nodes:
            nodes = app.site.nodes.nodes.keys()
            nodes.remove('fileset')
            if comments:
                nodes.append('comments')
            if tags:
                nodes.append('tags')
        else:
            if 'fileset' in node:
                ctx.fail("Refusing to discard fileset node.\n"
                         "Use 'marv fileset discard' to discard a fileset.")
            unknown = set(node) - app.site.nodes.nodes.viewkeys()
            if unknown:
                ctx.fail('Unknown nodes %s' % list(sorted(unknown)))
            nodes = node
        app.site.node_discard(
            nodes=nodes,
            uuids='ALL' if all_filesets else [str(x) for x in fileset],
            update_detail=update_detail)
예제 #5
0
def create_app(push=True, init=None):
    ctx = click.get_current_context()
    siteconf = ctx.obj
    if siteconf is None:
        ctx.fail('Could not find config file: ./marv.conf or /etc/marv/marv.conf.\n'
                 'Change working directory or specify explicitly:\n\n'
                 '  marv --config /path/to/marv.conf\n')
    site = Site(siteconf)
    try:
        app = marv.app.create_app(site, init=init)
    except ConfigError as e:
        click.echo('Error {}'.format(e.args[0]), err=True)
        click.get_current_context().exit(1)
    except OSError as e:
        if e.errno == 13:
            print(e, file=sys.stderr)
            sys.exit(13)
        raise
    if push:
        appctx = app.app_context()
        appctx.push()
        ctx.call_on_close(appctx.pop)
    return app
예제 #6
0
def marv_user_pw(username, password):
    """Change password"""
    app = create_app()
    with app.app_context():
        app.site.user_pw(username, password.encode('utf-8'))
예제 #7
0
def marv_user_rm(username):
    """Remove a user"""
    app = create_app()
    with app.app_context():
        app.site.user_rm(username)
예제 #8
0
def marv_user_add(username, password):
    """Add a user"""
    app = create_app()
    with app.app_context():
        app.site.user_add(username, password.encode('utf-8'))
예제 #9
0
def marv_fileset_scan():
    """Scan for new and changed filesets"""
    app = create_app()
    with app.app_context():
        app.site.scan()
예제 #10
0
def marv_fileset_discard(uuids):
    """Discard everything marv knows about a fileset"""
    app = create_app()
    with app.app_context():
        for uuid in uuids:
            app.site.remove_fileset(uuid)