def _tearDownClass(cls): MockedEnv.stopall() if "TRAVIS" not in os.environ: cls.info("{}: dumping rs config...".format(cls.SHORT_DESCR)) cls.dump_rs_config() if "BUILD_ONLY" in os.environ or \ (cls.SKIP_ON_TRAVIS and "TRAVIS" in os.environ): cls.debug("Skipping stopping instances") return if "TRAVIS" not in os.environ: cls.info("{}: dumping routes...".format(cls.SHORT_DESCR)) cls.dump_routes() if cls._do_not_stop_instances(): cls.debug("Skipping stopping instances") return cls.info("{}: stopping instances...".format(cls.SHORT_DESCR)) for instance in cls.INSTANCES: cls.debug("Stopping instance '{}'...".format(instance.name)) instance.stop()
def _setUp(self, *patches): # We need to clear the global list of hosts that timed out # before a test case is run, since it could contain hosts # added during the execution of previous test cases. TIMEDOUT_IRR_HOSTS.clear() # Don't use the MockedEnv 'irr=True' argument, because here # the IRRDBInfo's _run_cmd method needs to be mocked in a # different way, to introduce a fake timeout. MockedEnv(base_dir=os.path.dirname(__file__), default=False) self.temp_dir = tempfile.mkdtemp(suffix="arouteserver_unittest") def _fail_query(cmd): if self.HOSTS_TO_FAIL == "one": # Fail only for the first host in the list. if self.FIRST_HOST not in cmd: return elif self.HOSTS_TO_FAIL == "all": pass else: raise ValueError("HOSTS_TO_FAIL unknown " + self.HOSTS_TO_FAIL) if self.TYPE_OF_ERROR == "timeout": raise subprocess.TimeoutExpired(cmd, 1) elif self.TYPE_OF_ERROR == "failure": raise RuntimeError("fake failure") else: raise ValueError("TYPE_OF_ERROR unknown " + self.TYPE_OF_ERROR) def _mock_ASSet_run_cmd(self, cmd): _fail_query(cmd) return json.dumps({"asn_list": [10, 20, 30]}).encode() def _mock_RSet_run_cmd(self, cmd): _fail_query(cmd) if "AS-FAKE1" in cmd: return json.dumps({ "prefix_list": [{ "prefix": "192.168.0.0/16" }, { "prefix": "192.168.1.0/24" }] }).encode() else: return json.dumps({"prefix_list": []}).encode() mock_ASSet_run_cmd = mock.patch.object(ASSet, "_run_cmd", autospec=True).start() mock_ASSet_run_cmd.side_effect = _mock_ASSet_run_cmd mock_RSet_run_cmd = mock.patch.object(RSet, "_run_cmd", autospec=True).start() mock_RSet_run_cmd.side_effect = _mock_RSet_run_cmd
def _setUpClass(cls): for prefix_name in cls.DATA: prefix = cls.DATA[prefix_name] net = IPNetwork(prefix) if "/" in prefix else IPAddress(prefix) if str(net) != prefix: raise ValueError( "Prefix '{}' is not represented in its canonical form: " "'{}' used, '{}' expected.".format(prefix_name, prefix, str(net))) cls.info("{}: setting instances up...".format(cls.SHORT_DESCR)) MockedEnv(cls, base_dir=cls._get_module_dir(), peering_db=cls.MOCK_PEERING_DB, ripe_rpki_cache=cls.MOCK_RIPE_RPKI_CACHE, irrdb=cls.MOCK_IRRDB, rttgetter=cls.MOCK_RTTGETTER, arin_db_dump=cls.MOCK_ARIN_DB_DUMP) cls.rs_cfg_file_path = None try: cls._setup_instances() except: cls.tearDownClass() raise if "BUILD_ONLY" in os.environ or \ (cls.SKIP_ON_TRAVIS and "TRAVIS" in os.environ): cls.debug("Skipping starting instances") return try: for instance in cls.INSTANCES: instance.set_var_dir("{}/var".format(cls._get_module_dir())) if cls._do_not_stop_instances() and instance.is_running(): cls.debug( "Instance '{}' already running, reloading config". format(instance.name)) if not instance.reload_config(): raise InstanceError( "An error occurred while reloading '{}' configuration." .format(instance.name)) continue cls.debug("Starting instance '{}'...".format(instance.name)) instance.start() except Exception as e: try: cls.tearDownClass() except: pass raise e
def setup_builder(self, cls, general, ip_ver=None): tpl_dir = "bird" if cls is BIRDConfigBuilder else "openbgpd" MockedEnv(base_dir=os.path.dirname(__file__), default=True) self.builder = cls(template_dir="templates/{}/".format(tpl_dir), template_name="main.j2", cfg_general=self.write_file("general.yml", general), cfg_clients=self.write_clients(), cfg_bogons="config.d/bogons.yml", cache_dir=self.temp_dir, cache_expiry=120, ip_ver=ip_ver)
def tearDown(self): MockedEnv.stopall() shutil.rmtree(self.temp_dir, ignore_errors=True)
def setUp(self, *patches): MockedEnv(base_dir=os.path.dirname(__file__), default=False, irr=True, peering_db=True) self.temp_dir = tempfile.mkdtemp(suffix="arouteserver_unittest")
def tearDownClass(cls): MockedEnv.stopall()
def setUpClass(cls): MockedEnv(default=False, peering_db=True, base_dir=os.path.dirname(__file__))