Esempio n. 1
0
    def test_sshshowq(self):
        """Test sshshowq"""


        clusters = {'delcatty': {'path': '/opt/moab/bin/checkjob', 'master': 'master15.delcatty.gent.vsc'}, 'phanpy': {'path': '/opt/moab/bin/checkjob', 'master': 'master17.phanpy.gent.vsc'}, 'raichu': {'path': '/opt/moab/bin/checkjob', 'master': 'master13.raichu.gent.vsc'}, 'golett': {'path': '/opt/moab/bin/checkjob', 'master': 'master19.golett.gent.vsc'}, 'swalot': {'path': '/opt/moab/bin/checkjob', 'master': 'master21.swalot.gent.vsc'}}

        showq = SshShowq(
            'master1',
            'testuser',
            clusters=clusters,
            cache_pickle=True,
            dry_run=True)
        self.assertEqual(showq._command('/opt/moab/bin/checkjob'), ['sudo', 'ssh', 'testuser@master1', '/opt/moab/bin/checkjob'])
        self.assertEquals(showq.info, ShowqInfo)
        self.assertEquals(showq.info(), {})
Esempio n. 2
0
    def test_sshshowq(self):
        """Test sshshowq"""

        clusters = {
            'delcatty': {
                'path': '/opt/moab/bin/checkjob',
                'master': 'master15.delcatty.gent.vsc'
            },
            'phanpy': {
                'path': '/opt/moab/bin/checkjob',
                'master': 'master17.phanpy.gent.vsc'
            },
            'raichu': {
                'path': '/opt/moab/bin/checkjob',
                'master': 'master13.raichu.gent.vsc'
            },
            'golett': {
                'path': '/opt/moab/bin/checkjob',
                'master': 'master19.golett.gent.vsc'
            },
            'swalot': {
                'path': '/opt/moab/bin/checkjob',
                'master': 'master21.swalot.gent.vsc'
            }
        }

        showq = SshShowq('master1',
                         'testuser',
                         clusters=clusters,
                         cache_pickle=True,
                         dry_run=True)
        self.assertEqual(
            showq._command('/opt/moab/bin/checkjob'),
            ['sudo', 'ssh', 'testuser@master1', '/opt/moab/bin/checkjob'])
        self.assertEquals(showq.info, ShowqInfo)
        self.assertEquals(showq.info(), {})
Esempio n. 3
0
def main():
    # Collect all info

    # Note: debug option is provided by generaloption
    # Note: other settings, e.g., ofr each cluster will be obtained from the configuration file
    options = {
        'nagios-check-interval-threshold':
        NAGIOS_CHECK_INTERVAL_THRESHOLD,
        'hosts':
        ('the hosts/clusters that should be contacted for job information',
         None, 'extend', []),
        'information': ('the sort of information to store: user, vo, project',
                        None, 'store', 'user'),
        'location': ('the location for storing the pickle file: delcatty, muk',
                     str, 'store', 'delcatty'),
        'account_page_url':
        ('the URL at which the account page resides', None, 'store', None),
        'access_token':
        ('the token that will allow authentication against the account page',
         None, 'store', None),
        'target_master':
        ('the master used to execute showq commands', None, 'store', None),
        'target_user': ('the user for ssh to the target master', None, 'store',
                        None),
    }

    opts = ExtendedSimpleOption(options)

    try:
        rest_client = AccountpageClient(token=opts.options.access_token)

        gpfs = GpfsOperations()
        storage = VscStorage()
        storage_name = cluster_user_pickle_store_map[opts.options.location]
        login_mount_point = storage[storage_name].login_mount_point
        gpfs_mount_point = storage[storage_name].gpfs_mount_point

        clusters = {}
        for host in opts.options.hosts:
            master = opts.configfile_parser.get(host, "master")
            showq_path = opts.configfile_parser.get(host, "showq_path")
            clusters[host] = {'master': master, 'path': showq_path}

        logger.debug("clusters = %s" % (clusters, ))
        showq = SshShowq(opts.options.target_master,
                         opts.options.target_user,
                         clusters,
                         cache_pickle=True,
                         dry_run=opts.options.dry_run)

        logger.debug("Getting showq information ...")

        (queue_information, _, _) = showq.get_moab_command_information()
        timeinfo = time.time()

        active_users = queue_information.keys()

        logger.debug("Active users: %s" % (active_users))
        logger.debug("Queue information: %s" % (queue_information))

        # We need to determine which users should get an updated pickle. This depends on
        # - the active user set
        # - the information we want to provide on the cluster(set) where this script runs
        # At the same time, we need to determine the job information each user gets to see
        tup = (opts.options.information, active_users, queue_information,
               rest_client)
        (target_users, target_queue_information,
         user_map) = determine_target_information(*tup)

        nagios_user_count = 0
        nagios_no_store = 0

        stats = {}

        for user in target_users:
            try:
                path = get_pickle_path(opts.options.location, user,
                                       rest_client)
                user_queue_information = target_queue_information[user]
                user_queue_information['timeinfo'] = timeinfo
                store_on_gpfs(user, path, "showq",
                              (user_queue_information, user_map[user]), gpfs,
                              login_mount_point, gpfs_mount_point,
                              ".showq.json.gz", opts.options.dry_run)
                nagios_user_count += 1
            except Exception:
                logger.error("Could not store pickle file for user %s" %
                             (user))
                nagios_no_store += 1

        stats["store_users"] = nagios_user_count
        stats["store_fail"] = nagios_no_store
        stats["store_fail_critical"] = STORE_LIMIT_CRITICAL
    except Exception, err:
        logger.exception("critical exception caught: %s" % (err))
        opts.critical("Script failed in a horrible way")
        sys.exit(NAGIOS_EXIT_CRITICAL)