def _initialize_forchestrator(self): forch_config = dict_proto(yaml.safe_load(self.FORCH_CONFIG), ForchConfig) self._forchestrator = Forchestrator(forch_config) try: self._forchestrator.initialize() except ConnectionRefusedError: print('Ignoring connection error during Forchestrator initialization')
def setup(self, config, *args): """setup fixture for each test method""" forch_config = dict_proto(yaml.safe_load(config), ForchConfig) self._forchestrator = Forchestrator(forch_config) self._forchestrator._faucet_collector = FaucetStateCollector( self._forchestrator._config, is_faucetizer_enabled=True) self._forchestrator._should_enable_faucetizer = True with open(os.path.join(os.environ['FORCH_CONFIG_DIR'], 'faucet.yaml'), 'w') as fd: fd.write('segments_to_vlans:') self._forchestrator._config_file_watcher = FileChangeWatcher( os.environ['FORCH_CONFIG_DIR']) self._forchestrator._calculate_orchestration_config() self._forchestrator._initialize_orchestration()
class ForchestratorEventTestBase(UnitTestBase): """Base class for Forchestrator unit tests""" FORCH_CONFIG = """ site: name: nz-kiwi varz_interface: varz_port: 60000 """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) os.environ['FORCH_LOG'] = _DEFAULT_FORCH_LOG self._forchestrator = None def _setup_env(self): os.environ['FORCH_CONFIG_DIR'] = self._forch_config_dir os.environ['FORCH_CONFIG_FILE'] = os.path.basename( self._forch_config_file) os.environ['FAUCET_CONFIG_DIR'] = self._faucet_config_dir os.environ['FAUCET_CONFIG_FILE'] = os.path.basename( self._behavioral_config_file) os.environ['FAUCET_EVENT_SOCK'] = self._faucet_socket_file os.environ['CONTROLLER_NAME'] = 'ctr1' def _initialize_forchestrator(self): forch_config = dict_proto(yaml.safe_load(self.FORCH_CONFIG), ForchConfig) self._forchestrator = Forchestrator(forch_config) try: self._forchestrator.initialize() except ConnectionRefusedError: print( 'Ignoring connection error during Forchestrator initialization' ) def setUp(self): """setup fixture for each test method""" self._setup_config_files() self._setup_env() self._initialize_forchestrator() def tearDown(self): """cleanup after each test method finishes""" self._cleanup_config_files()
def run_forchestrator(): """main function to start forch""" logger = get_logger(_LOGGER_NAME) logger.info('Starting Forchestrator') config = load_config() if not config: logger.error('Invalid config, exiting.') sys.exit(1) forchestrator = Forchestrator(config) http_server = forch.http_server.HttpServer(forchestrator.get_local_port(), config.http) try: forchestrator.initialize() http_server.map_request('system_state', forchestrator.get_system_state) http_server.map_request('dataplane_state', forchestrator.get_dataplane_state) http_server.map_request('switch_state', forchestrator.get_switch_state) http_server.map_request('cpn_state', forchestrator.get_cpn_state) http_server.map_request('process_state', forchestrator.get_process_state) http_server.map_request('host_path', forchestrator.get_host_path) http_server.map_request('list_hosts', forchestrator.get_list_hosts) http_server.map_request('vrrp_state', forchestrator.get_vrrp_state) http_server.map_request('sys_config', forchestrator.get_sys_config) http_server.map_request('', http_server.static_file('')) except Exception as e: logger.error("Cannot initialize forch: %s", e, exc_info=True) http_server.map_request('', functools.partial(show_error, e)) finally: http_server.start_server() forchestrator.update_initialization_varz() if not forchestrator.main_loop(): try: http_server.join_thread() except KeyboardInterrupt: logger.info('Keyboard interrupt. Exiting.') logger.warning('Exiting program') http_server.stop_server() forchestrator.stop()
def _initialize_forchestrator(self): forch_config = dict_proto(yaml.safe_load(self.FORCH_CONFIG), ForchConfig) self._forchestrator = Forchestrator(forch_config)
class ForchestratorMissingDVAFilesTestCase(unittest.TestCase): """Test case for forchestrator with missing DVA files.""" _DEFAULT_FORCH_LOG = '/tmp/forch.log' FORCH_CONFIG = """ orchestration: %s structural_config_file: faucet.yaml sequester_config: vlan_start: 272 vlan_end: 276 port_description: TAP auto_sequestering: disabled """ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) os.environ['FORCH_LOG'] = self._DEFAULT_FORCH_LOG os.environ['FORCH_CONFIG_DIR'] = tempfile.mkdtemp() self._forchestrator = None @patch.object(Faucetizer, 'flush_behavioral_config', return_value=None) @patch.object(Faucetizer, 'tail_acl_config_valid', return_value=True) def setup(self, config, *args): """setup fixture for each test method""" forch_config = dict_proto(yaml.safe_load(config), ForchConfig) self._forchestrator = Forchestrator(forch_config) self._forchestrator._faucet_collector = FaucetStateCollector( self._forchestrator._config, is_faucetizer_enabled=True) self._forchestrator._should_enable_faucetizer = True with open(os.path.join(os.environ['FORCH_CONFIG_DIR'], 'faucet.yaml'), 'w') as fd: fd.write('segments_to_vlans:') self._forchestrator._config_file_watcher = FileChangeWatcher( os.environ['FORCH_CONFIG_DIR']) self._forchestrator._calculate_orchestration_config() self._forchestrator._initialize_orchestration() @patch.object(Faucetizer, 'reload_segments_to_vlans', return_value=None) def test_missing_static_device_behavior_file(self, *args): """Test a missing static_device_behavior file won't crash forch""" addon = """static_device_behavior: missing_file.yaml segments_vlans_file: segments_vlans.yaml""" self.setup(self.FORCH_CONFIG % addon) self.assertTrue(self._forchestrator._should_ignore_auth_result) self.assertIsNotNone( self._forchestrator._forch_config_errors.get( STATIC_BEHAVIORAL_FILE)) def test_missing_static_device_placement_file(self): """Test a missing static_device_placement file won't crash forch""" addon = """static_device_placement: missing_file.yaml segments_vlans_file: missing_file.yaml""" self.setup(self.FORCH_CONFIG % addon) self.assertTrue(self._forchestrator._should_ignore_auth_result) self.assertIsNotNone( self._forchestrator._forch_config_errors.get( STATIC_PLACEMENT_FILE)) def test_missing_segments_vlan_file(self): """Test a missing segments_vlan file won't crash forch""" addon = """segments_vlans_file: missing_file.yaml""" self.setup(self.FORCH_CONFIG % addon) self.assertTrue(self._forchestrator._should_ignore_auth_result) self.assertTrue(self._forchestrator._should_ignore_static_behavior) self.assertIsNotNone( self._forchestrator._forch_config_errors.get(SEGMENTS_VLANS_FILE))