Exemplo n.º 1
0
def main(args):
    ctx = FakeNamespace(args)
    if ctx.verbose:
        teuthology.log.setLevel(logging.DEBUG)

    info = {}
    if ctx.archive:
        ctx.config = config_file(ctx.archive + '/config.yaml')
        ifn = os.path.join(ctx.archive, 'info.yaml')
        if os.path.exists(ifn):
            with open(ifn, 'r') as fd:
                info = yaml.safe_load(fd.read())
        if not ctx.pid:
            ctx.pid = info.get('pid')
            if not ctx.pid:
                ctx.pid = int(open(ctx.archive + '/pid').read().rstrip('\n'))
        if not ctx.owner:
            ctx.owner = info.get('owner')
            if not ctx.owner:
                ctx.owner = open(ctx.archive + '/owner').read().rstrip('\n')

    if ctx.targets:
        ctx.config = merge_configs(ctx.targets)

    if ctx.stale:
        stale_nodes = find_stale_locks(ctx.owner)
        targets = dict()
        for node in stale_nodes:
            targets[node['name']] = node['ssh_pub_key']
        ctx.config = dict(targets=targets)

    if ctx.stale_openstack:
        stale_openstack(ctx)
        return

    log.info(
        '\n  '.join(
            ['targets:', ] + yaml.safe_dump(
                ctx.config['targets'],
                default_flow_style=False).splitlines()))

    if ctx.dry_run:
        log.info("Not actually nuking anything since --dry-run was passed")
        return

    if ctx.owner is None:
        ctx.owner = get_user()

    if ctx.pid:
        if ctx.archive:
            log.info('Killing teuthology process at pid %d', ctx.pid)
            os.system('grep -q %s /proc/%d/cmdline && sudo kill -9 %d' % (
                ctx.archive,
                ctx.pid,
                ctx.pid))
        else:
            subprocess.check_call(["kill", "-9", str(ctx.pid)])

    nuke(ctx, ctx.unlock, ctx.synch_clocks, ctx.noipmi, ctx.keep_logs, not ctx.no_reboot)
Exemplo n.º 2
0
 def create_users(self):
     """
     Create a main and an alternative s3 user.
     Configuration is read from a skelethon config file
     s3tests.teuth.config.yaml in the java-s3tests repository
     and missing information is added from the task.
     Existing values are NOT overriden unless they are empty!
     """
     log.info("S3 Tests Java: Creating S3 users...")
     testdir = teuthology.get_testdir(self.ctx)
     for client in self.all_clients:
         endpoint = self.ctx.rgw.role_endpoints.get(client)
         local_user = getpass.getuser()
         remote_user = teuthology.get_test_user()
         os.system("scp {remote}@{host}:{tdir}/s3-tests-java/s3tests.teuth.config.yaml /home/{local}/".format(
             host=endpoint.hostname, tdir=testdir, remote=remote_user, local=local_user))
         s3tests_conf = teuthology.config_file(
             '/home/{local}/s3tests.teuth.config.yaml'.format(local=local_user))
         log.debug("S3 Tests Java: s3tests_conf is {s3cfg}".format(
             s3cfg=s3tests_conf))
         for section, user in self.users.items():
             if section in s3tests_conf:
                 s3_user_id = '{user}.{client}'.format(
                     user=user, client=client)
                 log.debug(
                     'S3 Tests Java: Creating user {s3_user_id}'.format(s3_user_id=s3_user_id))
                 self._config_user(s3tests_conf=s3tests_conf,
                                   section=section, user=s3_user_id, client=client)
                 cluster_name, daemon_type, client_id = teuthology.split_role(
                     client)
                 client_with_id = daemon_type + '.' + client_id
                 args = [
                     'adjust-ulimits',
                     'ceph-coverage',
                     '{tdir}/archive/coverage'.format(tdir=testdir),
                     'radosgw-admin',
                     '-n', client_with_id,
                     'user', 'create',
                     '--uid', s3tests_conf[section]['user_id'],
                     '--display-name', s3tests_conf[section]['display_name'],
                     '--access-key', s3tests_conf[section]['access_key'],
                     '--secret', s3tests_conf[section]['access_secret'],
                     '--email', s3tests_conf[section]['email'],
                     '--cluster', cluster_name,
                 ]
                 log.info('{args}'.format(args=args))
                 self.ctx.cluster.only(client).run(
                     args=args,
                     stdout=BytesIO()
                 )
             else:
                 self.users.pop(section)
         self._write_cfg_file(s3tests_conf, client)
         os.system(
             "rm -rf /home/{local}/s3tests.teuth.config.yaml".format(local=local_user))