Ejemplo n.º 1
0
def should_be_default_for_arch(newservice):
    '''
    Determine if newservice should be the baseservice of default-<arch>
    (i.e., first service of architecture and aliasable)

    Input: service object for newly created service
    Returns: True if default-<arch> alias should be created
             False otherwise

    '''
    if newservice.image.version < 3:
        return False
    services = config.get_all_service_names()
    make_default = True
    for service in services:
        if service == newservice.name:
            continue
        svc = AIService(service)
        try:
            props = config.get_service_props(service)
            config.verify_key_properties(service, props)
        except config.ServiceCfgError as err:
            # if service is missing keys, print info and skip it
            print >> sys.stderr, err
            continue
        if svc.arch == newservice.arch and svc.image.version >= 3:
            make_default = False
            break

    logging.debug("should_be_default_for_arch service %s, arch=%s, returns %s",
                  newservice.name, newservice.arch, make_default)
    return make_default
    def test_verify_key_properties(self):
        '''test verify_key_properties'''
        # success cases
        props = {
            config.PROP_SERVICE_NAME: 's1',
            config.PROP_STATUS: config.STATUS_ON,
            config.PROP_TXT_RECORD: 'aiwebserver=ais:5555',
            config.PROP_IMAGE_PATH: '/tmp/myimage'
        }
        config.verify_key_properties('s1', props)

        props = {
            config.PROP_SERVICE_NAME: 's1',
            config.PROP_STATUS: config.STATUS_ON,
            config.PROP_TXT_RECORD: 'aiwebserver=ais:5555',
            config.PROP_ALIAS_OF: 'mybasesvc'
        }
        config.verify_key_properties('s1', props)

        # failure cases
        props = {config.PROP_SERVICE_NAME: 's1'}
        self.assertRaises(config.ServiceCfgError, config.verify_key_properties,
                          'not_s1', props)

        props = {
            config.PROP_SERVICE_NAME: 's1',
            config.PROP_TXT_RECORD: 'aiwebserver=ais:5555',
            config.PROP_IMAGE_PATH: '/tmp/myimage'
        }
        self.assertRaises(config.ServiceCfgError, config.verify_key_properties,
                          's1', props)

        props = {
            config.PROP_SERVICE_NAME: 's1',
            config.PROP_STATUS: config.STATUS_ON,
            config.PROP_IMAGE_PATH: '/tmp/myimage'
        }
        self.assertRaises(config.ServiceCfgError, config.verify_key_properties,
                          's1', props)

        props = {
            config.PROP_SERVICE_NAME: 's1',
            config.PROP_STATUS: config.STATUS_ON,
            config.PROP_TXT_RECORD: 'aiwebserver=ais5555',
            config.PROP_IMAGE_PATH: '/tmp/myimage'
        }
        self.assertRaises(config.ServiceCfgError, config.verify_key_properties,
                          's1', props)

        props = {
            config.PROP_SERVICE_NAME: 's1',
            config.PROP_STATUS: config.STATUS_ON,
            config.PROP_TXT_RECORD: 'aiwebserver=ais:5555'
        }
        self.assertRaises(config.ServiceCfgError, config.verify_key_properties,
                          's1', props)
Ejemplo n.º 3
0
def get_local_services(services, sname=None):
    """
    Iterates over the local services on a host creating a dictionary
    with the service name as the key and status, path, architecture,
    and aliasof as the value.  If name is not None then it ensures
    that only the named service is retrieved.

    Args
        services = config.get_all_service_props()
        name = service name

    Returns
        a service dictionary made up of a list of dictionary of services.

        {
        service1:
          [
            {'status':on1, 'path':path1, 'arch':arch1, 'aliasof':aliasof1},
            ...
          ],
        ...
        }

        the width of the longest service name
        the width of the longest aliasof name

    Raises
        None
    """
    width = 0
    aliasofwidth = 1
    sdict = dict()
    for akey in services:
        serv = services[akey]
        servicename = akey
        # ensure that the current service has the keys we need.
        # if not, print error, but continue listing other services
        try:
            config.verify_key_properties(akey, serv)
        except config.ServiceCfgError as err:
            print >> sys.stderr, err
            continue
        try:
            service = AIService(servicename)
        except VersionError as err:
            warn_version(err)
            continue
        if config.PROP_ALIAS_OF in serv:
            image_path = service.image.path
            serv[config.PROP_IMAGE_PATH] = image_path
        
        info = dict()
        # if a service name is passed in then
        # ensure it matches the current name
        if not sname or sname == servicename:
            width = max(len(servicename), width)
            info['status'] = serv[config.PROP_STATUS]
            info['path'] = serv[config.PROP_IMAGE_PATH]
            info['arch'] = which_arch(service)
            if config.PROP_ALIAS_OF in serv:
                # have an alias
                aliasof = serv[config.PROP_ALIAS_OF]
            else:
                aliasof = '-'
            info['aliasof'] = aliasof
            aliasofwidth = max(len(aliasof), aliasofwidth)
            if servicename in sdict:
                slist = sdict[servicename]
                slist.extend([info])
                sdict[servicename] = slist
            else:
                sdict[servicename] = [info]
    
    return sdict, width, aliasofwidth
Ejemplo n.º 4
0
def get_local_services(services, sname=None):
    """
    Iterates over the local services on a host creating a dictionary
    with the service name as the key and status, path, architecture,
    and aliasof as the value.  If name is not None then it ensures
    that only the named service is retrieved.

    Args
        services = config.get_all_service_props()
        name = service name

    Returns
        a service dictionary made up of a list of dictionary of services.

        {
        service1:
          [
            {'status':on1, 'path':path1, 'arch':arch1, 'aliasof':aliasof1},
            ...
          ],
        ...
        }

        the width of the longest service name
        the width of the longest aliasof name

    Raises
        None
    """
    width = 0
    aliasofwidth = 1
    sdict = dict()
    for akey in services:
        serv = services[akey]
        servicename = akey
        # ensure that the current service has the keys we need.
        # if not, print error, but continue listing other services
        try:
            config.verify_key_properties(akey, serv)
        except config.ServiceCfgError as err:
            print >> sys.stderr, err
            continue
        try:
            service = AIService(servicename)
        except VersionError as err:
            warn_version(err)
            continue
        if config.PROP_ALIAS_OF in serv:
            image_path = service.image.path
            serv[config.PROP_IMAGE_PATH] = image_path

        info = dict()
        # if a service name is passed in then
        # ensure it matches the current name
        if not sname or sname == servicename:
            width = max(len(servicename), width)
            info['status'] = serv[config.PROP_STATUS]
            info['path'] = serv[config.PROP_IMAGE_PATH]
            info['arch'] = which_arch(service)
            if config.PROP_ALIAS_OF in serv:
                # have an alias
                aliasof = serv[config.PROP_ALIAS_OF]
            else:
                aliasof = '-'
            info['aliasof'] = aliasof
            aliasofwidth = max(len(aliasof), aliasofwidth)
            if servicename in sdict:
                slist = sdict[servicename]
                slist.extend([info])
                sdict[servicename] = slist
            else:
                sdict[servicename] = [info]

    return sdict, width, aliasofwidth