Example #1
0
    def setUp(self):
        global last_msm_id
        last_msm_id = None

        self.cfg = {}

        self.debug = False

        self.ip_cache_mocked = False

        def msm_fetch_meta_data(self):
            self.meta_data = deepcopy(MSMS[str(self.id)]["meta_data"])
            return True

        self.mock_msm_fetch_meta_data = mock.patch.object(
            Measurement,
            "_fetch_meta_data",
            autospec=True
        ).start()
        self.mock_msm_fetch_meta_data.side_effect = msm_fetch_meta_data

        def results_get(self):
            global last_msm_id
            last_msm_id = self.msm_id
            return True, deepcopy(MSMS[str(self.msm_id)]["results"])

        self.mock_results_get = mock.patch.object(
            AtlasLatestRequest,
            "get",
            autospec=True
        ).start()
        self.mock_results_get.side_effect = results_get

        def AtlasRequest_get(self, **kwargs):
            if "/api/v2/probes/" in self.url_path:
                return True, deepcopy(MSMS[str(last_msm_id)]["probes"])

        self.mock_probe_request = mock.patch.object(
            AtlasRequest,
            "get",
            autospec=True
        ).start()
        self.mock_probe_request.side_effect = AtlasRequest_get

        # -------------------------------------------------------
        # IP Cache mocking
        # Comment this block to enable IP info gathering when adding
        # new measurements to tests; once completed, replace TS
        # within ip_addr.json and ip_pref.json:
        #    :%s/"TS": \d\+/"TS": 1451606400/g

        self.ip_cache_mocked = True

        def ip_cache_fetch_ip(self, IP):
            return {
                "status": "unknown"
            }

        self.mock_ip_cache_fetch_ip = mock.patch.object(
            IPDetailsCache,
            "FetchIPInfo",
            autospec=True
        ).start()
        self.mock_ip_cache_fetch_ip.side_effect = ip_cache_fetch_ip

        def ip_cache_fetch_ixps(self):
            return ({}, {}, {})

        self.mock_ip_cache_fetch_ixps = mock.patch.object(
            IPDetailsCache,
            "FetchIXPsInfo",
            autospec=True
        ).start()
        self.mock_ip_cache_fetch_ixps.side_effect = ip_cache_fetch_ixps

        def ip_cache_save(self):
            return

        self.mock_ip_cache_save = mock.patch.object(
            IPCache,
            "save",
            autospec=True
        ).start()
        self.mock_ip_cache_save.side_effect = ip_cache_save

        # End of IP Cache mocking
        # -------------------------------------------------------

        self.ip_cache = IPCache()
        self.ip_cache.setup(
            IP_ADDRESSES_CACHE_FILE="tests/data/ip_addr.json",
            IP_PREFIXES_CACHE_FILE="tests/data/ip_pref.json",
            IXP_CACHE_FILE="tests/data/ixps.json",
            lifetime=sys.maxsize,
            use_ixps_info=True
        )
Example #2
0
    def setUp(self):
        global last_msm_id
        last_msm_id = None

        self.cfg = {}

        self.debug = False

        self.ip_cache_mocked = False

        def msm_fetch_meta_data(self):
            self.meta_data = deepcopy(MSMS[str(self.id)]["meta_data"])
            return True

        self.mock_msm_fetch_meta_data = mock.patch.object(
            Measurement, "_fetch_meta_data", autospec=True).start()
        self.mock_msm_fetch_meta_data.side_effect = msm_fetch_meta_data

        def results_get(self):
            global last_msm_id
            last_msm_id = self.msm_id
            return True, deepcopy(MSMS[str(self.msm_id)]["results"])

        self.mock_results_get = mock.patch.object(AtlasLatestRequest,
                                                  "get",
                                                  autospec=True).start()
        self.mock_results_get.side_effect = results_get

        def AtlasRequest_get(self, **kwargs):
            if "/api/v2/probes/" in self.url_path:
                return True, deepcopy(MSMS[str(last_msm_id)]["probes"])

        self.mock_probe_request = mock.patch.object(AtlasRequest,
                                                    "get",
                                                    autospec=True).start()
        self.mock_probe_request.side_effect = AtlasRequest_get

        # -------------------------------------------------------
        # IP Cache mocking
        # Comment this block to enable IP info gathering when adding
        # new measurements to tests; once completed, replace TS
        # within ip_addr.json and ip_pref.json:
        #    :%s/"TS": \d\+/"TS": 1451606400/g

        self.ip_cache_mocked = True

        def ip_cache_fetch_ip(self, IP):
            return {"status": "unknown"}

        self.mock_ip_cache_fetch_ip = mock.patch.object(IPDetailsCache,
                                                        "FetchIPInfo",
                                                        autospec=True).start()
        self.mock_ip_cache_fetch_ip.side_effect = ip_cache_fetch_ip

        def ip_cache_fetch_ixps(self):
            return ({}, {}, {})

        self.mock_ip_cache_fetch_ixps = mock.patch.object(
            IPDetailsCache, "FetchIXPsInfo", autospec=True).start()
        self.mock_ip_cache_fetch_ixps.side_effect = ip_cache_fetch_ixps

        def ip_cache_save(self):
            return

        self.mock_ip_cache_save = mock.patch.object(IPCache,
                                                    "save",
                                                    autospec=True).start()
        self.mock_ip_cache_save.side_effect = ip_cache_save

        # End of IP Cache mocking
        # -------------------------------------------------------

        self.ip_cache = IPCache()
        self.ip_cache.setup(IP_ADDRESSES_CACHE_FILE="tests/data/ip_addr.json",
                            IP_PREFIXES_CACHE_FILE="tests/data/ip_pref.json",
                            IXP_CACHE_FILE="tests/data/ixps.json",
                            lifetime=sys.maxsize,
                            use_ixps_info=True)
Example #3
0
class TestBasicUnit(unittest.TestCase):

    def setUp(self):
        global last_msm_id
        last_msm_id = None

        self.cfg = {}

        self.debug = False

        self.ip_cache_mocked = False

        def msm_fetch_meta_data(self):
            self.meta_data = deepcopy(MSMS[str(self.id)]["meta_data"])
            return True

        self.mock_msm_fetch_meta_data = mock.patch.object(
            Measurement,
            "_fetch_meta_data",
            autospec=True
        ).start()
        self.mock_msm_fetch_meta_data.side_effect = msm_fetch_meta_data

        def results_get(self):
            global last_msm_id
            last_msm_id = self.msm_id
            return True, deepcopy(MSMS[str(self.msm_id)]["results"])

        self.mock_results_get = mock.patch.object(
            AtlasLatestRequest,
            "get",
            autospec=True
        ).start()
        self.mock_results_get.side_effect = results_get

        def AtlasRequest_get(self, **kwargs):
            if "/api/v2/probes/" in self.url_path:
                return True, deepcopy(MSMS[str(last_msm_id)]["probes"])

        self.mock_probe_request = mock.patch.object(
            AtlasRequest,
            "get",
            autospec=True
        ).start()
        self.mock_probe_request.side_effect = AtlasRequest_get

        # -------------------------------------------------------
        # IP Cache mocking
        # Comment this block to enable IP info gathering when adding
        # new measurements to tests; once completed, replace TS
        # within ip_addr.json and ip_pref.json:
        #    :%s/"TS": \d\+/"TS": 1451606400/g

        self.ip_cache_mocked = True

        def ip_cache_fetch_ip(self, IP):
            return {
                "status": "unknown"
            }

        self.mock_ip_cache_fetch_ip = mock.patch.object(
            IPDetailsCache,
            "FetchIPInfo",
            autospec=True
        ).start()
        self.mock_ip_cache_fetch_ip.side_effect = ip_cache_fetch_ip

        def ip_cache_fetch_ixps(self):
            return ({}, {}, {})

        self.mock_ip_cache_fetch_ixps = mock.patch.object(
            IPDetailsCache,
            "FetchIXPsInfo",
            autospec=True
        ).start()
        self.mock_ip_cache_fetch_ixps.side_effect = ip_cache_fetch_ixps

        def ip_cache_save(self):
            return

        self.mock_ip_cache_save = mock.patch.object(
            IPCache,
            "save",
            autospec=True
        ).start()
        self.mock_ip_cache_save.side_effect = ip_cache_save

        # End of IP Cache mocking
        # -------------------------------------------------------

        self.ip_cache = IPCache()
        self.ip_cache.setup(
            IP_ADDRESSES_CACHE_FILE="tests/data/ip_addr.json",
            IP_PREFIXES_CACHE_FILE="tests/data/ip_pref.json",
            IXP_CACHE_FILE="tests/data/ixps.json",
            lifetime=sys.maxsize,
            use_ixps_info=True
        )

    def tearDown(self):
        if not self.ip_cache_mocked:
            self.ip_cache.save()
        mock.patch.stopall()

    def check_ip_cache_fetch_cnt(self, ip_cnt=0):
        if self.ip_cache_mocked:
            self.assertEquals(self.mock_ip_cache_fetch_ip.call_count, ip_cnt)
            self.assertEquals(self.mock_ip_cache_fetch_ixps.call_count, 0)

    def create_monitor(self, exp_exc=None, exp_msg=None):
        if exp_exc is None:
            try:
                self.created_monitor = Monitor(self.cfg, self.ip_cache)
                return self.created_monitor
            except Exception as e:
                raise self.failureException(e)
        else:
            with self.assertRaisesRegexp(exp_exc, exp_msg):
                self.created_monitor = Monitor(self.cfg, self.ip_cache)
                return self.created_monitor
Example #4
0
class TestBasicUnit(unittest.TestCase):
    def setUp(self):
        global last_msm_id
        last_msm_id = None

        self.cfg = {}

        self.debug = False

        self.ip_cache_mocked = False

        def msm_fetch_meta_data(self):
            self.meta_data = deepcopy(MSMS[str(self.id)]["meta_data"])
            return True

        self.mock_msm_fetch_meta_data = mock.patch.object(
            Measurement, "_fetch_meta_data", autospec=True).start()
        self.mock_msm_fetch_meta_data.side_effect = msm_fetch_meta_data

        def results_get(self):
            global last_msm_id
            last_msm_id = self.msm_id
            return True, deepcopy(MSMS[str(self.msm_id)]["results"])

        self.mock_results_get = mock.patch.object(AtlasLatestRequest,
                                                  "get",
                                                  autospec=True).start()
        self.mock_results_get.side_effect = results_get

        def AtlasRequest_get(self, **kwargs):
            if "/api/v2/probes/" in self.url_path:
                return True, deepcopy(MSMS[str(last_msm_id)]["probes"])

        self.mock_probe_request = mock.patch.object(AtlasRequest,
                                                    "get",
                                                    autospec=True).start()
        self.mock_probe_request.side_effect = AtlasRequest_get

        # -------------------------------------------------------
        # IP Cache mocking
        # Comment this block to enable IP info gathering when adding
        # new measurements to tests; once completed, replace TS
        # within ip_addr.json and ip_pref.json:
        #    :%s/"TS": \d\+/"TS": 1451606400/g

        self.ip_cache_mocked = True

        def ip_cache_fetch_ip(self, IP):
            return {"status": "unknown"}

        self.mock_ip_cache_fetch_ip = mock.patch.object(IPDetailsCache,
                                                        "FetchIPInfo",
                                                        autospec=True).start()
        self.mock_ip_cache_fetch_ip.side_effect = ip_cache_fetch_ip

        def ip_cache_fetch_ixps(self):
            return ({}, {}, {})

        self.mock_ip_cache_fetch_ixps = mock.patch.object(
            IPDetailsCache, "FetchIXPsInfo", autospec=True).start()
        self.mock_ip_cache_fetch_ixps.side_effect = ip_cache_fetch_ixps

        def ip_cache_save(self):
            return

        self.mock_ip_cache_save = mock.patch.object(IPCache,
                                                    "save",
                                                    autospec=True).start()
        self.mock_ip_cache_save.side_effect = ip_cache_save

        # End of IP Cache mocking
        # -------------------------------------------------------

        self.ip_cache = IPCache()
        self.ip_cache.setup(IP_ADDRESSES_CACHE_FILE="tests/data/ip_addr.json",
                            IP_PREFIXES_CACHE_FILE="tests/data/ip_pref.json",
                            IXP_CACHE_FILE="tests/data/ixps.json",
                            lifetime=sys.maxsize,
                            use_ixps_info=True)

    def tearDown(self):
        if not self.ip_cache_mocked:
            self.ip_cache.save()
        mock.patch.stopall()

    def check_ip_cache_fetch_cnt(self, ip_cnt=0):
        if self.ip_cache_mocked:
            self.assertEquals(self.mock_ip_cache_fetch_ip.call_count, ip_cnt)
            self.assertEquals(self.mock_ip_cache_fetch_ixps.call_count, 0)

    def create_monitor(self, exp_exc=None, exp_msg=None):
        if exp_exc is None:
            try:
                self.created_monitor = Monitor(self.cfg, self.ip_cache)
                return self.created_monitor
            except Exception as e:
                raise self.failureException(e)
        else:
            with self.assertRaisesRegexp(exp_exc, exp_msg):
                self.created_monitor = Monitor(self.cfg, self.ip_cache)
                return self.created_monitor