def setUp(self): super(TestDFAServer, self).setUp() # Mocking some modules self.dcnmpatcher = mock.patch(cdr.__name__ + '.DFARESTClient') self.mdcnm = self.dcnmpatcher.start() self.keys_patcher = mock.patch(deh.__name__ + '.EventsHandler') self.mkeys = self.keys_patcher.start() self.inst_api_patcher = mock.patch(dia.__name__ + '.DFAInstanceAPI') self.m_inst_api = self.inst_api_patcher.start() self.module_patcher = mock.patch.dict('sys.modules', {'pika': mock.Mock()}) self.module_patcher.start() from networking_cisco.apps.saf.server import dfa_listen_dcnm as dld from networking_cisco.apps.saf.server import dfa_server as ds self.dld_patcher = mock.patch(dld.__name__ + '.DCNMListener') self.dld = self.dld_patcher.start() ds.DfaServer.__bases__ = (FakeClass.imitate( dfr.DfaFailureRecovery, dbm.DfaDBMixin, fw_native.FwMgr),) ds.DfaServer.get_all_projects.return_value = [] ds.DfaServer.get_all_networks.return_value = [] ds.DfaServer._setup_rpc = mock.Mock() # TODO(padkrish) Have UT for this function. This may mean over-riding # the mocking of get_segmentid_range of DCNM client to return a range. ds.DfaServer.register_segment_dcnm = mock.Mock() # Setting DCNM parameters. config.default_dcnm_opts['dcnm']['dcnm_ip'] = FAKE_DCNM_IP config.default_dcnm_opts['dcnm']['dcnm_user'] = FAKE_DCNM_USERNAME config.default_dcnm_opts['dcnm']['dcnm_password'] = FAKE_DCNM_PASSWD config.default_dcnm_opts['dcnm']['timeout_resp'] = 0.01 config.default_dcnm_opts['dcnm']['segmentation_id_min'] = 10000 config.default_dcnm_opts['dcnm']['segmentation_id_max'] = 20000 config.default_dcnm_opts['dcnm']['orchestrator_id'] = FAKE_ORCH_ID self.cfg = config.CiscoDFAConfig().cfg self.segid = int(self.cfg.dcnm.segmentation_id_min) + 10 self.seg_Drvr = mock.patch( 'networking_cisco.apps.saf.db.dfa_db_models.' 'DfaSegmentTypeDriver').start() self.dfa_server = ds.DfaServer(self.cfg) mock.patch.object(self.dfa_server, '_get_segmentation_id', return_value=12345).start() mock.patch.object(self.dfa_server.seg_drvr, 'allocate_segmentation_id', return_value=12345).start() self.dciid = str(123) self.proj_desc = 'Unit Test Project' projs = [ FakeProject(FAKE_PROJECT_ID, FAKE_PROJECT_NAME, self.dciid, self.proj_desc)] self.dfa_server.get_all_projects.return_value = projs self.dfa_server._load_project_info_cache() self.part_name = self.cfg.dcnm.default_partition_name
def setUp(self): super(TestDFAServer, self).setUp() # Mocking some modules self.dcnmpatcher = mock.patch(cdr.__name__ + '.DFARESTClient') self.mdcnm = self.dcnmpatcher.start() self.addCleanup(self.dcnmpatcher.stop) self.keys_patcher = mock.patch(deh.__name__ + '.EventsHandler') self.mkeys = self.keys_patcher.start() self.addCleanup(self.mkeys.stop) self.inst_api_patcher = mock.patch(dia.__name__ + '.DFAInstanceAPI') self.m_inst_api = self.inst_api_patcher.start() self.addCleanup(self.inst_api_patcher.stop) self.module_patcher = mock.patch.dict('sys.modules', {'pika': mock.Mock()}) self.module_patcher.start() self.addCleanup(self.module_patcher.stop) from networking_cisco.apps.saf.server import dfa_listen_dcnm as dld from networking_cisco.apps.saf.server import dfa_server as ds self.dld_patcher = mock.patch(dld.__name__ + '.DCNMListener') self.dld = self.dld_patcher.start() self.addCleanup(self.dld_patcher.stop) ds.DfaServer.__bases__ = (FakeClass.imitate( dfr.DfaFailureRecovery, dbm.DfaDBMixin),) ds.DfaServer.get_all_projects.return_value = [] ds.DfaServer.get_all_networks.return_value = [] ds.DfaServer._setup_rpc = mock.Mock() # Setting DCNM parameters. config.default_dcnm_opts['dcnm']['dcnm_ip'] = FAKE_DCNM_IP config.default_dcnm_opts['dcnm']['dcnm_user'] = FAKE_DCNM_USERNAME config.default_dcnm_opts['dcnm']['dcnm_password'] = FAKE_DCNM_PASSWD config.default_dcnm_opts['dcnm']['timeout_resp'] = 0.01 config.default_dcnm_opts['dcnm']['segmentation_id_min'] = 10000 config.default_dcnm_opts['dcnm']['segmentation_id_max'] = 20000 self.cfg = config.CiscoDFAConfig().cfg self.segid = int(self.cfg.dcnm.segmentation_id_min) + 10 self.dfa_server = ds.DfaServer(self.cfg) self.dciid = str(123) self.proj_desc = 'Unit Test Project' projs = [ FakeProject(FAKE_PROJECT_ID, FAKE_PROJECT_NAME, self.dciid, self.proj_desc)] self.dfa_server.get_all_projects.return_value = projs self.dfa_server._load_project_info_cache() self.part_name = self.cfg.dcnm.default_partition_name