def _set_feature_state(self, package: Package, state: str, block: bool = True): """ Sets the feature state and blocks till operation is finished if block argument is set to True. Args: package: Package object of the feature that will be stopped. state: Feature state to set. block: Whether to block for operation completion. """ if in_chroot(): return # import from here otherwise this import will fail when executing # sonic-package-manager from chroot environment as "config" package # tries accessing database at import time. from config.feature import set_feature_state feature_name = package.manifest['service']['name'] log.info('{} {}'.format( state.replace('ed', 'ing').capitalize(), feature_name)) cfgdb_clients = {'': self.sonic_db.get_running_db_connector()} set_feature_state(cfgdb_clients, feature_name, state, block)
def running_table(cls, table): """ Returns running DB table. """ # In chroot we can connect to a running # DB via TCP socket, we should ignore this case. if in_chroot(): return None if cls._running is None: try: cls._running = swsscommon.DBConnector(CONFIG_DB, 0) except RuntimeError: # Failed to connect to DB. return None return swsscommon.Table(cls._running, table)
def get_running_db_connector(cls): """ Returns running DB connector. """ # In chroot we can connect to a running # DB via TCP socket, we should ignore this case. if in_chroot(): return None if cls._running_db_conn is None: try: cls._running_db_conn = swsscommon.ConfigDBConnector() cls._running_db_conn.connect() except RuntimeError: # Failed to connect to DB. cls._running_db_conn = None return cls._running_db_conn
def _systemctl_action(self, package: Package, action: str): """ Execute systemctl action for a service supporting multi-asic services. """ name = package.manifest['service']['name'] host_service = package.manifest['service']['host-service'] asic_service = package.manifest['service']['asic-service'] single_instance = host_service or (asic_service and not self.is_multi_npu) multi_instance = asic_service and self.is_multi_npu if in_chroot(): return if single_instance: run_command(f'systemctl {action} {name}') if multi_instance: for npu in range(self.num_npus): run_command(f'systemctl {action} {name}@{npu}')
def post_operation_hook(self): if not in_chroot(): run_command('systemctl daemon-reload')
def _post_operation_hook(self): """ Common operations executed after service is created/removed. """ if not in_chroot(): run_command('systemctl daemon-reload')