コード例 #1
0
ファイル: test_aimdns_manual.py プロジェクト: alhazred/caiman
    def test_find(self):
        '''Test AImDNS().find() returns True when service is found and False
           when not found
        '''
        mdns = aimdns.AImDNS()
        mdns.timeout = 2
        # negative test
        assert mdns.find(servicename=self.bogus_find_svc) == False, \
               "Found bogus service: %s!" % self.bogussvc

        # start-up service for a positive test
        # pylint: disable-msg=W0212
        bogosvc = self.BogusService(self.bogus_find_svc, common.REGTYPE,
                                    mdns.domain)
        # pylint: enable-msg=W0212
        assert mdns.find(self.bogus_find_svc) == True, \
               "Failed to find unique service: %s!" % self.bogussvc
        del (bogosvc)
コード例 #2
0
    def __init__(self, name="_default", timeout=5, domain="local"):
        """ Method:    __init__

            Parameters:
                name - name of the service instance
                timeout - max time to lookup the service
                domain - .local for multicast DNS

            Returns:
                True..service found, False..service not found
        """
        self.name = name
        self.domain = domain
        self.found = False
        self.svc_info = self.svc_txt_rec = None
        self.mdns = aimdns.AImDNS()
        self.mdns.timeout = timeout

        return
コード例 #3
0
    def test_interfaces(self):
        '''Verify a unique service shows up for all interfaces listed
        when doing an AImDNS().browse()
        '''
        def _in_network(inter_ipv4, networks):
            '''Ensures that the interface's address is in networks
            '''
            # iterate over the network list
            for network in networks:
                # check if the interface's IPv4 address is in the network
                if common.compare_ipv4(inter_ipv4, network):
                    return True
            return False

        # services dictionary looks like:
        #{'e1000g0': [
        #    {'domain': u'local', 'hosttarget': u'jumprope.local.',
        #     'comments': 'aiwebserver=10.10.44.5:46501',
        #     'servicename': u'install_test_ai_x86',
        #     'flags': True, 'port': 46501},
        #    {'domain': u'local', 'hosttarget': u'jumprope.local.',
        #     'comments': 'foo=bar', 'flags': True, 'port': 9999,
        #     'servicename': u'not_likely_to_exist_service'}
        #]}

        mdns = aimdns.AImDNS()
        mdns.timeout = 2

        # start up a service to test browse
        # pylint: disable-msg=W0212
        bogosvc = self.BogusService(self.bogussvc, common.REGTYPE, mdns.domain)
        # pylint: enable-msg=W0212

        assert mdns.browse() == True, "Did not find any services!"
        for interface in mdns.services:
            in_net = _in_network(mdns.interfaces[interface], mdns.networks)
            if (in_net and not mdns.exclude) or (not in_net and mdns.exclude):
                assert any([svc for svc in mdns.services[interface] if
                        svc['servicename'] == self.bogussvc]), \
                        "Unable to find unique service on interface: %s" % \
                        interface
        del (bogosvc)
コード例 #4
0
ファイル: aimdns.py プロジェクト: alhazred/caiman
            if mdns.browse():
                mdns.print_services()
            else:
                if options.verbose:
                    print _('No services found')
                else:
                    print _('-:None')
                    return 1
        elif options.service:
            # find a service
            if mdns.find(servicename=options.service):
                mdns.print_services()
            else:
                if options.verbose:
                    print _('Service "%s" not found') % options.service
                else:
                    print _("-:%s") % options.service
                    return 1
    except aimdns.AIMDNSError, err:
        print err
        return 1
    except pyb.BonjourError, err:
        print 'mDNS failure:error code', err.errorCode
        return 1

    return 0

if __name__ == '__main__':
    AIMDNS = aimdns.AImDNS()
    sys.exit(main(AIMDNS))