예제 #1
0
    def test_traffic_directors(self, mock):
        provider = DynProvider('test', 'cust', 'user', 'pass', True)
        # short-circuit session checking
        provider._dyn_sess = True

        # no tds
        mock.side_effect = [{'data': []}]
        self.assertEquals({}, provider.traffic_directors)

        # a supported td and an ingored one
        response = {
            'data': [{
                'active': 'Y',
                'label': 'unit.tests.:A',
                'nodes': [],
                'notifiers': [],
                'pending_change': '',
                'rulesets': [],
                'service_id': '2ERWXQNsb_IKG2YZgYqkPvk0PBM',
                'ttl': '300'
            }, {
                'active': 'Y',
                'label': 'geo.unit.tests.:A',
                'nodes': [],
                'notifiers': [],
                'pending_change': '',
                'rulesets': [],
                'service_id': '3ERWXQNsb_IKG2YZgYqkPvk0PBM',
                'ttl': '300'
            }, {
                'active': 'Y',
                'label': 'something else',
                'nodes': [],
                'notifiers': [],
                'pending_change': '',
                'rulesets': [],
                'service_id': '4ERWXQNsb_IKG2YZgYqkPvk0PBM',
                'ttl': '300'
            }],
            'job_id':
            3376164583,
            'status':
            'success'
        }
        mock.side_effect = [response]
        # first make sure that we get the empty version from cache
        self.assertEquals({}, provider.traffic_directors)
        # reach in and bust the cache
        provider._traffic_directors = None
        tds = provider.traffic_directors
        self.assertEquals(set(['unit.tests.', 'geo.unit.tests.']),
                          set(tds.keys()))
        self.assertEquals(['A'], tds['unit.tests.'].keys())
        self.assertEquals(['A'], tds['geo.unit.tests.'].keys())
예제 #2
0
    def test_traffic_director_monitor(self, mock):
        provider = DynProvider('test', 'cust', 'user', 'pass', True)
        # short-circuit session checking
        provider._dyn_sess = True

        # no monitors, will try and create
        geo_monitor_id = '42x'
        mock.side_effect = [
            self.monitors_response, {
                'data': {
                    'active': 'Y',
                    'dsf_monitor_id': geo_monitor_id,
                    'endpoints': [],
                    'label': 'geo.unit.tests.',
                    'notifier': '',
                    'options': {
                        'expected': '',
                        'header': 'User-Agent: Dyn Monitor',
                        'host': 'geo.unit.tests.',
                        'path': '/_dns',
                        'port': '443',
                        'timeout': '10'
                    },
                    'probe_interval': '60',
                    'protocol': 'HTTPS',
                    'response_count': '2',
                    'retries': '2'
                },
                'job_id':
                3376259461,
                'msgs': [{
                    'ERR_CD': None,
                    'INFO': 'add: Here is the new monitor',
                    'LVL': 'INFO',
                    'SOURCE': 'BLL'
                }],
                'status':
                'success'
            }
        ]

        # ask for a monitor that doesn't exist
        monitor = provider._traffic_director_monitor('geo.unit.tests.')
        self.assertEquals(geo_monitor_id, monitor.dsf_monitor_id)
        # should see a request for the list and a create
        mock.assert_has_calls([
            call('/DSFMonitor/', 'GET', {'detail': 'Y'}),
            call(
                '/DSFMonitor/', 'POST', {
                    'retries': 2,
                    'protocol': 'HTTPS',
                    'response_count': 2,
                    'label': 'geo.unit.tests.',
                    'probe_interval': 60,
                    'active': 'Y',
                    'options': {
                        'path': '/_dns',
                        'host': 'geo.unit.tests',
                        'header': 'User-Agent: Dyn Monitor',
                        'port': 443,
                        'timeout': 10
                    }
                })
        ])
        # created monitor is now cached
        self.assertTrue(
            'geo.unit.tests.' in provider._traffic_director_monitors)
        # pre-existing one is there too
        self.assertTrue('unit.tests.' in provider._traffic_director_monitors)

        # now ask for a monitor that does exist
        mock.reset_mock()
        monitor = provider._traffic_director_monitor('unit.tests.')
        self.assertEquals(self.monitor_id, monitor.dsf_monitor_id)
        # should have resulted in no calls b/c exists & we've cached the list
        mock.assert_not_called()