Skip to content

Commit

Permalink
daemon: updated all services to use pkill instead of killall, which i…
Browse files Browse the repository at this point in the history
…s deprecated
  • Loading branch information
bharnden committed Dec 14, 2024
1 parent dc88d8e commit 17de618
Show file tree
Hide file tree
Showing 25 changed files with 64 additions and 147 deletions.
4 changes: 1 addition & 3 deletions daemon/core/api/grpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1073,9 +1073,7 @@ def create_service(
recreate: bool = False,
) -> bool:
request = CreateServiceRequest(
service=service.to_proto(),
templates=templates,
recreate=recreate,
service=service.to_proto(), templates=templates, recreate=recreate
)
response = self.stub.CreateService(request)
return response.result
Expand Down
3 changes: 1 addition & 2 deletions daemon/core/api/grpc/grpcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ def get_node_proto(
if not service.custom_templates and not service.custom_config:
continue
service_configs[service.name] = services_pb2.ServiceConfig(
templates=service.custom_templates,
config=service.custom_config,
templates=service.custom_templates, config=service.custom_config
)
return core_pb2.Node(
id=node.id,
Expand Down
18 changes: 4 additions & 14 deletions daemon/core/api/grpc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,7 @@ def GetConfig(
)
services.append(service_proto)
emane_models = [x.name for x in EmaneModelManager.models.values()]
return core_pb2.GetConfigResponse(
services=services,
emane_models=emane_models,
)
return core_pb2.GetConfigResponse(services=services, emane_models=emane_models)

def StartSession(
self, request: core_pb2.StartSessionRequest, context: ServicerContext
Expand Down Expand Up @@ -1305,9 +1302,7 @@ def GetWirelessConfig(
return GetWirelessConfigResponse(config=config_options)

def EmaneEvents(
self,
request_iterator: Iterable[EmaneEventsRequest],
context: ServicerContext,
self, request_iterator: Iterable[EmaneEventsRequest], context: ServicerContext
) -> EmaneEventsResponse:
for request in request_iterator:
session = self.get_session(request.session_id, context)
Expand Down Expand Up @@ -1396,10 +1391,7 @@ def EmaneEvents(
session, node, antenna.iface_id, context
)
session.emane.event_manager.publish_antenna_profile(
nem_id,
antenna.profile,
antenna.azimuth,
antenna.elevation,
nem_id, antenna.profile, antenna.azimuth, antenna.elevation
)
elif request.HasField("fading"):
fading = request.fading
Expand All @@ -1416,9 +1408,7 @@ def EmaneEvents(
return EmaneEventsResponse()

def CreateService(
self,
request: CreateServiceRequest,
context: ServicerContext,
self, request: CreateServiceRequest, context: ServicerContext
) -> CreateServiceResponse:
service = request.service
class_name = f"{service.name.capitalize()}Class"
Expand Down
5 changes: 1 addition & 4 deletions daemon/core/api/grpc/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,7 @@ class CoreConfig:
@classmethod
def from_proto(cls, proto: core_pb2.GetConfigResponse) -> "CoreConfig":
services = [Service.from_proto(x) for x in proto.services]
return CoreConfig(
services=services,
emane_models=list(proto.emane_models),
)
return CoreConfig(services=services, emane_models=list(proto.emane_models))


@dataclass
Expand Down
21 changes: 3 additions & 18 deletions daemon/core/emane/eventmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ def shutdown(self) -> None:
self.nem_service.clear()

def create_service(
self,
nem_id: int,
device: str,
group: str,
port: int,
should_start: bool,
self, nem_id: int, device: str, group: str, port: int, should_start: bool
) -> None:
# initialize emane event services
service = self.services.get(device)
Expand Down Expand Up @@ -159,13 +154,7 @@ def publish_location(
)
args = {k: v for k, v in args.items() if v is not None}
event = LocationEvent()
event.append(
nem_id,
latitude=lat,
longitude=lon,
altitude=alt,
**args,
)
event.append(nem_id, latitude=lat, longitude=lon, altitude=alt, **args)
self._publish_event(nem_id, event, 0)

def publish_locations(
Expand Down Expand Up @@ -226,11 +215,7 @@ def publish_pathloss(
self._publish_event(nem2_id, event)

def publish_antenna_profile(
self,
nem_id: int,
profile: int,
azimuth: float,
elevation: float,
self, nem_id: int, profile: int, azimuth: float, elevation: float
) -> None:
event = AntennaProfileEvent()
event.append(nem_id, profile=profile, azimuth=azimuth, elevation=elevation)
Expand Down
4 changes: 1 addition & 3 deletions daemon/core/emulator/controlnets.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ def add_net(self, _id: int, conf_required: bool = True) -> Optional[CtrlNet]:
:return: control net node
"""
logger.info(
"checking to add control net(%s) conf_required(%s)",
_id,
conf_required,
"checking to add control net(%s) conf_required(%s)", _id, conf_required
)
# check for valid id
if not (0 <= _id <= 3):
Expand Down
6 changes: 1 addition & 5 deletions daemon/core/emulator/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ def _run_callback(state: EventTypes, hook: Callable[[EventTypes], None]) -> None


def _run_script(
state: EventTypes,
directory: Path,
file_name: str,
data: str,
env: dict[str, str],
state: EventTypes, directory: Path, file_name: str, data: str, env: dict[str, str]
) -> None:
"""
Run a script hook.
Expand Down
4 changes: 1 addition & 3 deletions daemon/core/emulator/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,9 +1057,7 @@ def boot_node(self, node: CoreNode) -> None:
:return: nothing
"""
logger.info(
"booting node(%s): services(%s)",
node.name,
", ".join(node.services.keys()),
"booting node(%s): services(%s)", node.name, ", ".join(node.services.keys())
)
self.control_net_manager.setup_ifaces(node)
with self.nodes_lock:
Expand Down
16 changes: 3 additions & 13 deletions daemon/core/gui/coreclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@

GUI_SOURCE: str = "gui"
CPU_USAGE_DELAY: int = 3
MOBILITY_ACTIONS: dict[int, str] = {
7: "PLAY",
8: "STOP",
9: "PAUSE",
}
MOBILITY_ACTIONS: dict[int, str] = {7: "PLAY", 8: "STOP", 9: "PAUSE"}


def to_dict(config: dict[str, ConfigOption]) -> dict[str, str]:
Expand Down Expand Up @@ -176,17 +172,11 @@ def handle_events(self, event: Event) -> None:
if session_event.event <= SessionState.SHUTDOWN.value:
self.session.state = SessionState(session_event.event)
logger.info(
"session(%s) state(%s)",
event.session_id,
self.session.state,
"session(%s) state(%s)", event.session_id, self.session.state
)
elif session_event.event in MOBILITY_ACTIONS:
action = MOBILITY_ACTIONS[session_event.event]
logger.info(
"session(%s) mobility action(%s)",
event.session_id,
action,
)
logger.info("session(%s) mobility action(%s)", event.session_id, action)
node_id = session_event.node_id
dialog = self.mobility_players.get(node_id)
if dialog:
Expand Down
5 changes: 1 addition & 4 deletions daemon/core/gui/dialogs/nodeconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,7 @@ def click_compose(self) -> None:
parent=self,
initialdir=str(Path.home()),
title="Select Compose File",
filetypes=(
("yaml", "*.yml *.yaml ..."),
("All Files", "*"),
),
filetypes=(("yaml", "*.yml *.yaml ..."), ("All Files", "*")),
)
if file_path:
self.compose_file.set(file_path)
Expand Down
4 changes: 1 addition & 3 deletions daemon/core/gui/dialogs/nodeservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,7 @@ def click_configure(self) -> None:
self.draw_current_services()
else:
messagebox.showinfo(
"Service Configuration",
"Select a service to configure",
parent=self,
"Service Configuration", "Select a service to configure", parent=self
)

def draw_current_services(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions daemon/core/gui/graph/edges.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def node_label_positions(
src_x: int, src_y: int, dst_x: int, dst_y: int
) -> tuple[tuple[float, float], tuple[float, float]]:
v_x, v_y = dst_x - src_x, dst_y - src_y
v_len = math.sqrt(v_x**2 + v_y**2)
v_len = math.sqrt(v_x ** 2 + v_y ** 2)
if v_len == 0:
u_x, u_y = 0.0, 0.0
else:
Expand Down Expand Up @@ -147,7 +147,7 @@ def _get_arcpoint(
perp_m = -1 / m
b = mp_y - (perp_m * mp_x)
# get arc x and y
offset = math.sqrt(self.arc**2 / (1 + (1 / m**2)))
offset = math.sqrt(self.arc ** 2 / (1 + (1 / m ** 2)))
arc_x = mp_x
if self.arc >= 0:
arc_x += offset
Expand Down
6 changes: 1 addition & 5 deletions daemon/core/gui/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ def get_index(iface: Interface) -> Optional[int]:

class Subnets:
def __init__(
self,
ip4: IPNetwork,
ip4_mask: int,
ip6: IPNetwork,
ip6_mask: int,
self, ip4: IPNetwork, ip4_mask: int, ip6: IPNetwork, ip6_mask: int
) -> None:
self.ip4 = ip4
self.ip4_mask = ip4_mask
Expand Down
6 changes: 1 addition & 5 deletions daemon/core/gui/nodeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@
NODES: list["NodeDraw"] = []
NETWORK_NODES: list["NodeDraw"] = []
NODE_ICONS = {}
CONTAINER_NODES: set[NodeType] = {
NodeType.DEFAULT,
NodeType.DOCKER,
NodeType.PODMAN,
}
CONTAINER_NODES: set[NodeType] = {NodeType.DEFAULT, NodeType.DOCKER, NodeType.PODMAN}
IMAGE_NODES: set[NodeType] = {NodeType.DOCKER, NodeType.PODMAN}
WIRELESS_NODES: set[NodeType] = {
NodeType.WIRELESS_LAN,
Expand Down
10 changes: 2 additions & 8 deletions daemon/core/location/mobility.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,7 @@ def sendevent(self, model: "WayPointMobility") -> None:
end_time = int(model.endtime)
data = f"start={start_time} end={end_time}"
self.session.broadcast_event(
event_type,
node_id=model.id,
name=f"mobility:{model.name}",
data=data,
event_type, node_id=model.id, name=f"mobility:{model.name}", data=data
)


Expand Down Expand Up @@ -420,10 +417,7 @@ def create_link_data(
iface2=iface2.get_data(),
network_id=self.wlan.id,
options=LinkOptions(
bandwidth=self.bw,
delay=self.delay,
loss=self.loss,
jitter=self.jitter,
bandwidth=self.bw, delay=self.delay, loss=self.loss, jitter=self.jitter
),
color=color,
)
Expand Down
5 changes: 1 addition & 4 deletions daemon/core/nodes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,7 @@ def __init__(
if not services:
services = self.session.service_manager.defaults.get(self.model, [])
logger.info(
"setting node(%s) model(%s) services: %s",
self.name,
self.model,
services,
"setting node(%s) model(%s) services: %s", self.name, self.model, services
)
for name in services:
service_class = self.session.service_manager.get_service(name)
Expand Down
3 changes: 1 addition & 2 deletions daemon/core/nodes/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,7 @@ def startup(self) -> None:
compose_path = self.directory / "docker-compose.yml"
self.host_cmd(f'printf "{rendered}" >> {compose_path}', shell=True)
self.host_cmd(
f"{DOCKER_COMPOSE} up -d {self.compose_name}",
cwd=self.directory,
f"{DOCKER_COMPOSE} up -d {self.compose_name}", cwd=self.directory
)
else:
# setup commands for creating bind/volume mounts
Expand Down
12 changes: 3 additions & 9 deletions daemon/core/scripts/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,13 @@ def main():
help="CORE logging configuration file",
)
parser.add_argument(
"--grpc-port",
dest="grpcport",
help="override grpc port to listen on",
"--grpc-port", dest="grpcport", help="override grpc port to listen on"
)
parser.add_argument(
"--grpc-address",
dest="grpcaddress",
help="override grpc address to listen on",
"--grpc-address", dest="grpcaddress", help="override grpc address to listen on"
)
parser.add_argument(
"--ovs",
action="store_true",
help="enable experimental ovs mode",
"--ovs", action="store_true", help="enable experimental ovs mode"
)
args = parser.parse_args()
# convert ovs to internal format
Expand Down
16 changes: 8 additions & 8 deletions daemon/core/services/defaults/frrservices/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FRRZebra(CoreService):
executables: list[str] = ["zebra"]
startup: list[str] = ["bash frrboot.sh zebra"]
validate: list[str] = ["pidof zebra"]
shutdown: list[str] = ["killall zebra"]
shutdown: list[str] = ["pkill -f zebra"]

def data(self) -> dict[str, Any]:
frr_conf = self.files[0]
Expand Down Expand Up @@ -162,7 +162,7 @@ class FRROspfv2(FrrService, CoreService):
"""

name: str = "FRROSPFv2"
shutdown: list[str] = ["killall ospfd"]
shutdown: list[str] = ["pkill -f ospfd"]
validate: list[str] = ["pidof ospfd"]
ipv4_routing: bool = True

Expand Down Expand Up @@ -214,7 +214,7 @@ class FRROspfv3(FrrService, CoreService):
"""

name: str = "FRROSPFv3"
shutdown: list[str] = ["killall ospf6d"]
shutdown: list[str] = ["pkill -f ospf6d"]
validate: list[str] = ["pidof ospf6d"]
ipv4_routing: bool = True
ipv6_routing: bool = True
Expand Down Expand Up @@ -251,7 +251,7 @@ class FRRBgp(FrrService, CoreService):
"""

name: str = "FRRBGP"
shutdown: list[str] = ["killall bgpd"]
shutdown: list[str] = ["pkill -f bgpd"]
validate: list[str] = ["pidof bgpd"]
custom_needed: bool = True
ipv4_routing: bool = True
Expand Down Expand Up @@ -281,7 +281,7 @@ class FRRRip(FrrService, CoreService):
"""

name: str = "FRRRIP"
shutdown: list[str] = ["killall ripd"]
shutdown: list[str] = ["pkill -f ripd"]
validate: list[str] = ["pidof ripd"]
ipv4_routing: bool = True

Expand All @@ -306,7 +306,7 @@ class FRRRipng(FrrService, CoreService):
"""

name: str = "FRRRIPNG"
shutdown: list[str] = ["killall ripngd"]
shutdown: list[str] = ["pkill -f ripngd"]
validate: list[str] = ["pidof ripngd"]
ipv6_routing: bool = True

Expand All @@ -332,7 +332,7 @@ class FRRBabel(FrrService, CoreService):
"""

name: str = "FRRBabel"
shutdown: list[str] = ["killall babeld"]
shutdown: list[str] = ["pkill -f babeld"]
validate: list[str] = ["pidof babeld"]
ipv6_routing: bool = True

Expand Down Expand Up @@ -372,7 +372,7 @@ class FRRpimd(FrrService, CoreService):
"""

name: str = "FRRpimd"
shutdown: list[str] = ["killall pimd"]
shutdown: list[str] = ["pkill -f pimd"]
validate: list[str] = ["pidof pimd"]
ipv4_routing: bool = True

Expand Down
Loading

0 comments on commit 17de618

Please sign in to comment.