Skip to content

Commit f4f28bf

Browse files
Iustin-Mituangela-cncf
authored andcommitted
Pull request #27: update function based on id
Merge in ISGAPPSEC/cyperf-api-wrapper from bugfix/ISGAPPSEC2-34434-fix-update-function to main Squashed commit of the following: commit 9a3ded61b2726e0b255ccc5ee49a3ca85de112fc Author: iustmitu <iustin.mitu@keysight.com> Date: Fri May 23 13:06:25 2025 +0300 commit after regenerate the wrapper commit 91110c1e966908ed71d194cf08f493f557321353 Author: iustmitu <iustin.mitu@keysight.com> Date: Fri May 23 12:55:26 2025 +0300 sample tests fixed and update function commit bb87904e4e29413059dc9d256c28b72755149cee Author: iustmitu <iustin.mitu@keysight.com> Date: Thu May 22 13:12:39 2025 +0300 remove hassatr() commit e838f0ed10fc089649b8c820f640c9b1b706d124 Author: iustmitu <iustin.mitu@keysight.com> Date: Wed May 21 13:58:14 2025 +0300 fixed some issues commit c465e89fc2ab8a157a0fe2a801893542311a17a9 Author: iustmitu <iustin.mitu@keysight.com> Date: Mon May 19 12:21:09 2025 +0300 fix update function commit 588ee3448f08c80d5c807d1457e00a55a758698e Author: iustmitu <iustin.mitu@keysight.com> Date: Fri May 16 10:57:52 2025 +0300 update function based on id
1 parent b58b303 commit f4f28bf

4 files changed

Lines changed: 40 additions & 13 deletions

File tree

cyperf/dynamic_model_meta.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,41 @@ def refresh(self):
128128

129129
def update(self):
130130
lst = self.__get_base_data()
131-
items_to_add = [item for item in self.data if item not in lst]
132-
items_to_remove = [item for item in lst if item not in self.data]
131+
132+
server_hrefs = {
133+
link.href for item in lst
134+
for link in getattr(item, "links", [])
135+
if getattr(link, "type", None) == "self"
136+
}
137+
138+
local_hrefs = set()
139+
href_to_item = {}
140+
items_to_add = []
141+
142+
for item in self.dyn_data:
143+
link = item.get_self_link()
144+
if link is None or link.href is None:
145+
items_to_add.append(item)
146+
else:
147+
local_hrefs.add(link.href)
148+
href_to_item[link.href] = item
149+
150+
items_to_add.extend(
151+
href_to_item[href] for href in local_hrefs - server_hrefs
152+
)
153+
items_to_remove = [
154+
item for item in lst
155+
for link in getattr(item, "links", [])
156+
if getattr(link, "type", None) == "self" and link.href not in local_hrefs
157+
]
158+
133159
if items_to_add:
134-
try:
160+
for item in items_to_add:
135161
DynamicModel.link_based_request(self, self.link.name, "POST",
136-
body=items_to_add, href=self.link.href)
137-
except ApiException:
138-
for item in items_to_add:
139-
DynamicModel.link_based_request(self, self.link.name, "POST",
140-
body=item, href=self.link.href)
162+
body=item, href=self.link.href)
163+
141164
remove_one_by_one = False
142-
if len(items_to_remove) > 1 and "id" in dir(items_to_remove[0]):
165+
if len(items_to_remove) > 1:
143166
try:
144167
op = DynamicModel.link_based_request(self, self.link.name, "POST",
145168
body=[{"id": item.id} for item in items_to_remove],
@@ -151,9 +174,10 @@ def update(self):
151174
remove_one_by_one = True
152175
else:
153176
remove_one_by_one = True
177+
154178
if remove_one_by_one:
155179
for item in items_to_remove:
156-
DynamicModel.link_based_request(self, self.link.name, "DELETE",
180+
DynamicModel.link_based_request(self, self.link.name, "DELETE",
157181
href=next(link.href for link in item.links if link.rel == "self"))
158182
self.refresh()
159183

cyperf/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,11 @@ def add_apps(self, session, appNames):
198198
if not session.config.config.traffic_profiles:
199199
session.config.config.traffic_profiles.append(cyperf.ApplicationProfile(name="Application Profile"))
200200
session.config.config.traffic_profiles.update()
201+
201202
app_profile = session.config.config.traffic_profiles[0]
202-
app_profile.applications += app_info
203+
for app in app_info:
204+
app_profile.applications.append(app)
205+
203206
app_profile.applications.update()
204207

205208
def add_app(self, session, appName):

samples/sample_create_save_and_export_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# Create a session
4545
session = None
4646
print("Creating empty session...")
47-
api_session_response = api_session_instance.create_sessions(session=sessions)
47+
api_session_response = api_session_instance.create_sessions(sessions=sessions)
4848
session = api_session_response[0]
4949
print("Session created.\n")
5050

samples/sample_load_and_run_precanned_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# Create a session
4545
session = None
4646
print("Creating session from config called 'Not Working From Home Traffic Mix' ...")
47-
api_session_response = api_session_instance.create_sessions(session=sessions)
47+
api_session_response = api_session_instance.create_sessions(sessions=sessions)
4848
session = api_session_response[0]
4949
print("Session created.\n")
5050

0 commit comments

Comments
 (0)