예제 #1
0
 def __init__(self,
              args,
              bufsize=0,
              executable=None,
              stdin=None,
              stdout=subprocess.PIPE,
              stderr=subprocess.PIPE,
              preexec_fn=None,
              close_fds=False,
              shell=True,
              cwd=None,
              env=None,
              universal_newlines=False,
              startupinfo=None,
              creationflags=0,
              use_exceptions=True):
     """
     Overrides Popen constructor with defaults more appropriate for
     Uge usage.
     """
     subprocess.Popen.__init__(self, args, bufsize, executable, stdin,
                               stdout, stderr, preexec_fn, close_fds, shell,
                               cwd, env, universal_newlines, startupinfo,
                               creationflags)
     self.logger = LogManager.get_instance().get_logger(
         self.__class__.__name__)
     self.stdout_ = None
     self.stderr_ = None
     self.args_ = args
     self.use_exceptions = use_exceptions
예제 #2
0
 def __init__(self, sge_root, sge_cell, sge_qmaster_port, sge_execd_port):
     self.logger = LogManager.get_instance().get_logger(self.__class__.__name__)
     self.env_dict = {
         'SGE_ROOT' : sge_root,
         'SGE_CELL' : sge_cell,
         'SGE_QMASTER_PORT' : str(sge_qmaster_port),
         'SGE_EXECD_PORT' : str(sge_execd_port),
         'SGE_SINGLE_LINE' : '1',
     }
     self.uge_version = None
     self.__configure()
예제 #3
0
    def parse_args(self, usage=None):
        """ 
        Parse command arguments. 

        :param usage: Command usage.
        :type usage: str
        """
        if usage:
            self.parser.usage = usage

        try:
            (self.options, self.args) = self.parser.parse_args()
        except SystemExit as rc:
            sys.stdout.flush()
            sys.stderr.flush()
            os._exit(int(str(rc)))

        if self.valid_arg_count < len(self.args):
            # Postitional args are not enabled and we have some
            msg = "Invalid Argument(s):"
            for arg in self.args[self.valid_arg_count:]:
                msg += " " + arg
            raise InvalidArgument(msg)

        opt_dict = self.options.__dict__
        if opt_dict.get('cmd_version'):
            print('%s version: %s' % (os.path.basename(
                sys.argv[0]), ConfigManager.get_instance().get_version()))
            os._exit(0)

        # Log level.
        console_log_level = opt_dict.get('console_log_level', None)
        if console_log_level:
            LogManager.get_instance().set_console_log_level(console_log_level)

        # Check input arguments.
        self.check_input_args()
        return (self.options, self.args)
예제 #4
0
    def __init__(self, valid_arg_count=0):
        """ 
        Class constructor.

        :param valid_arg_count: Number of allowed positional arguments (default: 0).
        :type valid_arg_count: int
        """
        self.logger = LogManager.get_instance().get_logger(
            self.__class__.__name__)
        self.parser = OptionParser(add_help_option=False)
        self.options = {}
        self.args = []
        self.valid_arg_count = valid_arg_count
        self.option_group_dict = {}

        common_group = 'Common Options'
        self.add_option_group(common_group, None)

        self.add_option_to_group(common_group,
                                 '-h',
                                 '--help',
                                 action='help',
                                 help='Show this help message and exit.')
        self.add_option_to_group(common_group,
                                 '-?',
                                 '',
                                 action='help',
                                 help='Show this help message and exit.')

        self.add_option_to_group(common_group,
                                 '-v',
                                 '',
                                 action='store_true',
                                 dest='cmd_version',
                                 default=False,
                                 help='Print version and exit.')

        self.add_option_to_group(
            common_group,
            '-d',
            '--debug',
            dest='console_log_level',
            help=
            'Set debug level; valid values are: critical, error, warning, info, debug'
        )
예제 #5
0
from .utils import generate_random_string
from .utils import create_config_file
from .utils import load_values

from uge.api.qconf_api import QconfApi
from uge.config.config_manager import ConfigManager
from uge.log.log_manager import LogManager
from uge.exceptions.object_not_found import ObjectNotFound
from uge.exceptions.object_already_exists import ObjectAlreadyExists

create_config_file()
API = QconfApi()
HOST_GROUP_NAME = '@%s' % generate_random_string(6)
CONFIG_MANAGER = ConfigManager.get_instance()
HOST_NAME = CONFIG_MANAGER['host']
LOG_MANAGER = LogManager.get_instance()
VALUES_DICT = load_values('test_values.json')
print(VALUES_DICT)


@needs_uge
def test_generate_hgrp():
    hgrp = API.generate_hgrp(HOST_GROUP_NAME)
    assert (hgrp.data['group_name'] == HOST_GROUP_NAME)


def test_list_hgrps():
    hgrpl = API.list_hgrps()
    assert (hgrpl is not None)

예제 #6
0
 def __init__(self, qconf_executor):
     self.logger = LogManager.get_instance().get_logger(self.__class__.__name__)
     self.qconf_executor = qconf_executor
예제 #7
0
 def __init__(self, qconf_executor):
     self.logger = LogManager.get_instance().get_logger(
         self.__class__.__name__)
     self.qconf_executor = qconf_executor
     self.object_dump_ignored_key_list = []
예제 #8
0
 def get_logger(cls):
     if not cls.logger:
         cls.logger = LogManager.get_instance().get_logger(cls.__name__)
     return cls.logger
예제 #9
0
        :param name: ar id.
        :type name: str

        :raises ObjectNotFound: in case advance reservation object with a given name does not exist.
        :raises QmasterUnreachable: in case UGE Qmaster cannot be reached.
        :raises AdvanceReservationException: for any other errors.

        >>> api.delete_ar('123')
        """
        return self.qrdel_executor.delete_ar(name)


#############################################################################
# Testing.
if __name__ == '__main__':
    lm = LogManager.get_instance()
    lm.set_console_log_level('trace')
    api = AdvanceReservationApi()
    print(api.get_uge_version())
    ar_id1 = api.request_ar('-d 3600 -fr y')
    ar1 = api.get_ar(ar_id1)
    print('AR 1: ', ar1)
    ar_id2 = api.request_ar('-cal_week mon-fri=8-16=on')
    ar2 = api.get_ar(ar_id2)
    print('AR 2: ', ar2)
    ar_summary = api.get_ar_summary()
    print('AR SUMMARY: ', ar_summary)
    print('AR LIST: ', api.get_ar_list())
    print(api.delete_ar(ar_id1))
    print(api.delete_ar(ar_id2))
예제 #10
0
class QconfCli(object):
    """ Base qconf command line interface class. """
    __metaclass__ = abc.ABCMeta

    def __init__(self, valid_arg_count=0):
        """ 
        Class constructor.

        :param valid_arg_count: Number of allowed positional arguments (default: 0).
        :type valid_arg_count: int
        """
        self.logger = LogManager.get_instance().get_logger(
            self.__class__.__name__)
        self.parser = OptionParser(add_help_option=False)
        self.options = {}
        self.args = []
        self.valid_arg_count = valid_arg_count
        self.option_group_dict = {}

        common_group = 'Common Options'
        self.add_option_group(common_group, None)

        self.add_option_to_group(common_group,
                                 '-h',
                                 '--help',
                                 action='help',
                                 help='Show this help message and exit.')
        self.add_option_to_group(common_group,
                                 '-?',
                                 '',
                                 action='help',
                                 help='Show this help message and exit.')

        self.add_option_to_group(common_group,
                                 '-v',
                                 '',
                                 action='store_true',
                                 dest='cmd_version',
                                 default=False,
                                 help='Print version and exit.')

        self.add_option_to_group(
            common_group,
            '-d',
            '--debug',
            dest='console_log_level',
            help=
            'Set debug level; valid values are: critical, error, warning, info, debug'
        )

    def add_option(self, *args, **kwargs):
        """ 
        Add CLI option. 
        """
        self.parser.add_option(*args, **kwargs)

    def add_option_to_group(self, group_name, *args, **kwargs):
        """
        Add option to the given group.
        Group should be created using add_option_group().

        :param group_name: Group name.
        :type group_name: str
        """
        group = self.option_group_dict.get(group_name)
        group.add_option(*args, **kwargs)

    def add_option_group(self, group_name, desc):
        """ 
        Add option group. 

        :param group_name: Group name.
        :type group_name: str
        """
        group = OptionGroup(self.parser, group_name, desc)
        self.parser.add_option_group(group)
        self.option_group_dict[group_name] = group

    def parse_args(self, usage=None):
        """ 
        Parse command arguments. 

        :param usage: Command usage.
        :type usage: str
        """
        if usage:
            self.parser.usage = usage

        try:
            (self.options, self.args) = self.parser.parse_args()
        except SystemExit, rc:
            sys.stdout.flush()
            sys.stderr.flush()
            os._exit(int(str(rc)))

        if self.valid_arg_count < len(self.args):
            # Postitional args are not enabled and we have some
            msg = "Invalid Argument(s):"
            for arg in self.args[self.valid_arg_count:]:
                msg += " " + arg
            raise InvalidArgument(msg)

        opt_dict = self.options.__dict__
        if opt_dict.get('cmd_version'):
            print '%s version: %s' % (os.path.basename(
                sys.argv[0]), ConfigManager.get_instance().get_version())
            os._exit(0)

        # Log level.
        console_log_level = opt_dict.get('console_log_level', None)
        if console_log_level:
            LogManager.get_instance().set_console_log_level(console_log_level)

        # Check input arguments.
        self.check_input_args()
        return (self.options, self.args)