Example #1
0
 def get_system_state(self, path, params):
     """Get an overview of the system state"""
     system_state = SystemState()
     self._populate_versions(system_state.versions)
     system_state.peer_controller_url = self._get_peer_controller_url()
     system_state.summary_sources.CopyFrom(self._get_system_summary(path))
     system_state.site_name = self._config.get('site',
                                               {}).get('name', 'unknown')
     system_state.controller_name = self._get_controller_name()
     self._distill_summary(system_state.summary_sources, system_state)
     return system_state
Example #2
0
 def test_config_error_detail(self):
     """Test config detail for config errors"""
     summaries = SystemState.SummarySources()
     self._forchestrator._faucet_events = Mock()
     self._forchestrator._get_controller_state = MagicMock(return_value=(2, 'test_detail'))
     self._forchestrator._forch_config_errors['static_behavior_file'] = 'File error'
     _, detail = self._forchestrator._get_combined_summary(summaries)
     self.assertTrue('forch' in detail)
Example #3
0
 def _get_system_summary(self, path):
     states = SystemState.SummarySources()
     states.cpn_state.CopyFrom(self._cpn_collector.get_cpn_summary())
     states.process_state.CopyFrom(self._local_collector.get_process_summary())
     states.dataplane_state.CopyFrom(self._faucet_collector.get_dataplane_summary())
     states.switch_state.CopyFrom(self._faucet_collector.get_switch_summary())
     states.list_hosts.CopyFrom(self._faucet_collector.get_host_summary())
     url_base = self._extract_url_base(path)
     for field, value in states.ListFields():
         value.detail_url = f'{url_base}/?{field.name}'
     return states
Example #4
0
    def __init__(self, config):
        self._config = config
        self._structural_config_file = None
        self._behavioral_config_file = None
        self._forch_config_dir = None
        self._faucet_config_dir = None
        self._gauge_config_file = None
        self._segments_vlans_file = None
        self._faucet_events = None
        self._start_time = datetime.fromtimestamp(time.time()).isoformat()
        self._faucet_prom_endpoint = None
        self._gauge_prom_endpoint = None
        self._behavioral_config = None

        self._faucet_collector = None
        self._local_collector = None
        self._cpn_collector = None
        self._varz_collector = None

        self._faucetizer = None
        self._authenticator = None
        self._faucetize_scheduler = None
        self._config_file_watcher = None
        self._faucet_state_scheduler = None
        self._gauge_metrics_scheduler = None
        self._device_report_handler = None
        self._port_state_manager = None

        self._initialized = False
        self._active_state = State.initializing
        self._active_state_lock = threading.Lock()

        self._should_enable_faucetizer = False
        self._should_ignore_static_behavior = False
        self._should_ignore_auth_result = False

        self._forch_config_errors = {}
        self._system_errors = {}
        self._faucet_config_summary = SystemState.FaucetConfigSummary()
        self._metrics = None
        self._varz_proxy = None

        self._last_faucet_config_writing_time = None
        self._last_received_faucet_config_hash = None
        self._config_hash_verification_timeout_sec = (
            self._config.event_client.config_hash_verification_timeout_sec
            or _DEFAULT_CONFIG_HASH_VERIFICATION_TIMEOUT_SEC)

        self._states_lock = threading.Lock()
        self._timer_lock = threading.Lock()
        self._logger = get_logger('forch')
Example #5
0
 def _get_faucet_config(self):
     try:
         (new_conf_hashes, _, new_dps, top_conf) = config_parser.dp_parser(
             self._behavioral_config_file, 'fconfig')
         config_hash_info = self._get_faucet_config_hash_info(new_conf_hashes)
         self._faucet_config_summary = SystemState.ConfigSummary()
         for file_name, file_hash in new_conf_hashes.items():
             LOGGER.info('Loaded conf %s as %s', file_name, file_hash)
             self._faucet_config_summary.hashes[file_name] = file_hash
         for warning, message in self._validate_config(top_conf):
             LOGGER.warning('Config warning %s: %s', warning, message)
             self._faucet_config_summary.warnings[warning] = message
         return config_hash_info, new_dps, top_conf
     except Exception as e:
         LOGGER.error('Cannot read faucet config: %s', e)
         raise
Example #6
0
 def get_system_state(self, path, params):
     """Get an overview of the system state"""
     system_state = SystemState()
     self._populate_versions(system_state.versions)
     system_state.peer_controller_url = self._get_peer_controller_url()
     system_state.summary_sources.CopyFrom(self._get_system_summary(path))
     system_state.site_name = self._config.site.name or 'unknown'
     system_state.controller_name = self._get_controller_name()
     system_state.authentication_mode = self._get_sys_auth_mode()
     system_state.config_summary.CopyFrom(self._get_config_summary())
     self._distill_summary(system_state.summary_sources, system_state)
     return system_state
Example #7
0
 def _get_config_summary(self):
     config_summary = SystemState.ConfigSummary()
     config_summary.faucet_config.CopyFrom(self._faucet_config_summary)
     config_summary.forch_config.errors.update(self._forch_config_errors)
     return config_summary