CGW: remove 'infra_name' from infra_group API

Remove unused 'infra_name' from NB API requests that
manage infra_group (add/del).
Also change tests / utils and helper scripts to no longer
form kafka msgs with 'infra_name' present.

Signed-off-by: Oleksandr Mazur <oleksandr.mazur@plvision.eu>
This commit is contained in:
Oleksandr Mazur
2024-12-11 18:12:28 +02:00
parent 849511cd5c
commit 3155b8da83
10 changed files with 22 additions and 41 deletions

View File

@@ -479,14 +479,12 @@ impl CGWConnectionServer {
struct InfraGroupCreate {
r#type: String,
infra_group_id: String,
infra_name: String,
uuid: Uuid,
}
#[derive(Debug, Serialize, Deserialize)]
struct InfraGroupCreateToShard {
r#type: String,
infra_group_id: String,
infra_name: String,
infra_shard_id: i32,
uuid: Uuid,
}
@@ -828,7 +826,6 @@ impl CGWConnectionServer {
Ok(_dst_cgw_id) => {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
true,
@@ -844,7 +841,6 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
false,
@@ -879,7 +875,6 @@ impl CGWConnectionServer {
Ok(_dst_cgw_id) => {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
true,
@@ -897,7 +892,6 @@ impl CGWConnectionServer {
if let Ok(resp) = cgw_construct_infra_group_create_response(
gid,
String::default(),
self.local_cgw_id,
uuid,
false,

View File

@@ -38,7 +38,6 @@ type CGWCNCProducerType = FutureProducer;
pub struct InfraGroupCreateResponse {
pub r#type: &'static str,
pub infra_group_id: i32,
pub infra_name: String,
pub reporter_shard_id: i32,
pub uuid: Uuid,
pub success: bool,
@@ -185,7 +184,6 @@ pub struct InfraLeaveMessage {
pub fn cgw_construct_infra_group_create_response(
infra_group_id: i32,
infra_name: String,
reporter_shard_id: i32,
uuid: Uuid,
success: bool,
@@ -194,7 +192,6 @@ pub fn cgw_construct_infra_group_create_response(
let group_create = InfraGroupCreateResponse {
r#type: "infrastructure_group_create_response",
infra_group_id,
infra_name,
reporter_shard_id,
uuid,
success,

View File

@@ -24,7 +24,7 @@ class TestCgwMalformedPackets:
# Create single group
test_context.kafka_producer.conn.send(test_context.default_producer_topic(), \
message.group_create("cgw_default_group_name", uuid_val.int), bytes(str(group_id), encoding="utf-8"))
message.group_create(uuid_val.int), bytes(str(group_id), encoding="utf-8"))
ret_msg = test_context.kafka_consumer.get_result_msg(expected_uuid.int)
if not ret_msg:
print('Failed to receive create group result, was expecting ' + str(uuid_val.int) + ' uuid reply')
@@ -57,7 +57,7 @@ class TestCgwMalformedPackets:
# Create single group
test_context.kafka_producer.conn.send(test_context.default_producer_topic(), \
message.group_create_to_shard(default_shard_id, "cgw_default_group_name", uuid_val.int), bytes(str(group_id), encoding="utf-8"))
message.group_create_to_shard(default_shard_id, uuid_val.int), bytes(str(group_id), encoding="utf-8"))
ret_msg = test_context.kafka_consumer.get_result_msg(expected_uuid.int)
if not ret_msg:
print('Failed to receive create group result, was expecting ' + str(uuid_val.int) + ' uuid reply')

View File

@@ -284,7 +284,7 @@ class TestCgwMultiInstances:
# Create single group
test_context.kafka_producer.conn.send(test_context.default_producer_topic(), \
message.group_create_to_shard(str(group_id), default_shard_id, "cgw_default_group_name", uuid_val.int), bytes(str(group_id), encoding="utf-8"), partition=partitions[0])
message.group_create_to_shard(str(group_id), default_shard_id, uuid_val.int), bytes(str(group_id), encoding="utf-8"), partition=partitions[0])
ret_msg = test_context.kafka_consumer.get_result_msg(uuid_val.int)
if not ret_msg:
print('Failed to receive create group result, was expecting ' + str(uuid_val.int) + ' uuid reply')
@@ -415,7 +415,7 @@ class TestCgwMultiInstances:
# Create single group
test_context.kafka_producer.conn.send(test_context.default_producer_topic(), \
message.group_create_to_shard(str(group_id), shard_id, "cgw_default_group_name", uuid_val.int), bytes(str(group_id), encoding="utf-8"), partition=partitions[0])
message.group_create_to_shard(str(group_id), shard_id, uuid_val.int), bytes(str(group_id), encoding="utf-8"), partition=partitions[0])
ret_msg = test_context.kafka_consumer.get_result_msg(uuid_val.int)
if not ret_msg:
print('Failed to receive create group result, was expecting ' + str(uuid_val.int) + ' uuid reply')
@@ -536,7 +536,7 @@ class TestCgwMultiInstances:
# Create single group
test_context.kafka_producer.conn.send(test_context.default_producer_topic(), \
message.group_create(str(group_id), "cgw_default_group_name", uuid_val.int), bytes(str(group_id), encoding="utf-8"), partition=partitions[0])
message.group_create(str(group_id), uuid_val.int), bytes(str(group_id), encoding="utf-8"), partition=partitions[0])
ret_msg = test_context.kafka_consumer.get_result_msg(uuid_val.int)
if not ret_msg:
print('Failed to receive create group result, was expecting ' + str(uuid_val.int) + ' uuid reply')

View File

@@ -1,12 +1,10 @@
{
"add_group": {
"type": "infrastructure_group_create",
"infra_name": "name",
"uuid": "290d06b6-8eba-11ee-8005-aabbccddeeff"
},
"add_group_to_shard": {
"type": "infrastructure_group_create_to_shard",
"infra_name": "name",
"infra_shard_id": 0,
"uuid": "290d06b6-8eba-11ee-8005-aabbccddeeff"
},
@@ -31,4 +29,4 @@
"uuid": "290d06b6-8eba-11ee-8005-aabbccddeeff",
"timeout": 60
}
}
}

View File

@@ -2,13 +2,11 @@
"add_group": {
"type": "infrastructure_group_create",
"infra_group_id": "key",
"infra_name": "name",
"uuid": "290d06b6-8eba-11ee-8005-aabbccddeeff"
},
"add_group_to_shard": {
"type": "infrastructure_group_create_to_shard",
"infra_group_id": "key",
"infra_name": "name",
"infra_shard_id": 0,
"uuid": "290d06b6-8eba-11ee-8005-aabbccddeeff"
},
@@ -37,4 +35,4 @@
"uuid": "290d06b6-8eba-11ee-8005-aabbccddeeff",
"timeout": 60
}
}
}

View File

@@ -9,4 +9,4 @@
#
# ARGS:
# $1 - group id
./run.sh -s localhost:9092 -c 1 --new-group $1 some_name_0
./run.sh -s localhost:9092 -c 1 --new-group $1

View File

@@ -30,8 +30,8 @@ def time(input: str) -> float:
def parse_args():
parser = argparse.ArgumentParser(description="Creates entries in kafka.")
parser.add_argument("-g", "--new-group", metavar=("GROUP-ID", "NAME"),
nargs=2, action="append",
parser.add_argument("-g", "--new-group", metavar=("GROUP-ID"),
nargs=1, action="append",
help="create a new group")
parser.add_argument("-G", "--rm-group", metavar=("GROUP-ID"),
nargs=1, action="append",
@@ -92,11 +92,11 @@ def parse_args():
send_to_macs=parsed_args.send_to_mac,
)
if parsed_args.new_group is not None:
for group, name in parsed_args.new_group:
for (group,) in parsed_args.new_group:
try:
args.add_groups.append((group, name))
args.add_groups.append(group)
except ValueError:
parser.error(f"--new-group: failed to parse {group} / {name}")
parser.error(f"--new-group: failed to parse {group}")
if parsed_args.rm_group is not None:
for (group,) in parsed_args.rm_group:
args.del_groups.append(group)

View File

@@ -165,7 +165,7 @@ class Producer:
if group is None:
raise Exception('producer: Cannot create new group without group id specified!')
self.conn.send(self.topic, self.message.group_create(group, "cgw_default_group_name", uuid_val),
self.conn.send(self.topic, self.message.group_create(group, uuid_val),
bytes(group, encoding="utf-8"))
self.conn.flush()
@@ -173,14 +173,14 @@ class Producer:
if group is None:
raise Exception('producer: Cannot create new group without group id specified!')
self.conn.send(self.topic, self.message.group_create_to_shard(group, shard_id, "cgw_default_group_name", uuid_val),
self.conn.send(self.topic, self.message.group_create_to_shard(group, shard_id, uuid_val),
bytes(group, encoding="utf-8"))
self.conn.flush()
def handle_group_creation(self, create: List[Tuple[str, str]], delete: List[str]) -> None:
def handle_group_creation(self, create: List[str], delete: List[str]) -> None:
with self as conn:
for group, name in create:
conn.send(self.topic, self.message.group_create(group, name),
for group in create:
conn.send(self.topic, self.message.group_create(group),
bytes(group, encoding="utf-8"))
for group in delete:
conn.send(self.topic, self.message.group_delete(group),

View File

@@ -135,7 +135,6 @@ class Message:
DEV_FROM_GROUP = "del_from_group"
TO_DEVICE = "message_infra"
GROUP_ID = "infra_group_id"
GROUP_NAME = "infra_name"
SHARD_ID = "infra_shard_id"
DEV_LIST = "infra_group_infras"
MAC = "mac"
@@ -153,18 +152,16 @@ class Message:
return str(uuid.UUID(int=uuid_val))
def group_create(self, id: str, name: str, uuid_val: int = None) -> bytes:
def group_create(self, id: str, uuid_val: int = None) -> bytes:
msg = copy.copy(self.templates[self.GROUP_ADD])
msg[self.GROUP_ID] = id
msg[self.GROUP_NAME] = name
msg[self.MSG_UUID] = Message.parse_uuid(uuid_val)
return json.dumps(msg).encode('utf-8')
def group_create_to_shard(self, id: str, shard_id: int, name: str, uuid_val: int = None) -> bytes:
def group_create_to_shard(self, id: str, shard_id: int, uuid_val: int = None) -> bytes:
msg = copy.copy(self.templates[self.GROUP_ADD_TO_SHARD])
msg[self.GROUP_ID] = id
msg[self.SHARD_ID] = shard_id
msg[self.GROUP_NAME] = name
msg[self.MSG_UUID] = Message.parse_uuid(uuid_val)
return json.dumps(msg).encode('utf-8')
@@ -223,7 +220,6 @@ class MalformedMessage:
DEV_TO_GROUP = "add_to_group"
DEV_FROM_GROUP = "del_from_group"
TO_DEVICE = "message_infra"
GROUP_NAME = "infra_name"
SHARD_ID = "infra_shard_id"
DEV_LIST = "infra_group_infras"
MAC = "mac"
@@ -241,16 +237,14 @@ class MalformedMessage:
return str(uuid.UUID(int=uuid_val))
def group_create(self, name: str, uuid_val: int = None) -> bytes:
def group_create(self, uuid_val: int = None) -> bytes:
msg = copy.copy(self.templates[self.GROUP_ADD])
msg[self.GROUP_NAME] = name
msg[self.MSG_UUID] = Message.parse_uuid(uuid_val)
return json.dumps(msg).encode('utf-8')
def group_create_to_shard(self, shard_id: int, name: str, uuid_val: int = None) -> bytes:
def group_create_to_shard(self, shard_id: int, uuid_val: int = None) -> bytes:
msg = copy.copy(self.templates[self.GROUP_ADD_TO_SHARD])
msg[self.SHARD_ID] = shard_id
msg[self.GROUP_NAME] = name
msg[self.MSG_UUID] = Message.parse_uuid(uuid_val)
return json.dumps(msg).encode('utf-8')