Skip to content

Commit 96d5281

Browse files
author
Shiva Shankar Vaddepally
committed
NSHELP-40733 sslcertfile module – Importing a new SSL certificate fails with duplicate primary key error
1 parent 0e84bac commit 96d5281

2 files changed

Lines changed: 32 additions & 3 deletions

File tree

plugins/module_utils/constants.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,19 @@
135135
'cacheglobal_cachepolicy_binding',
136136
'botglobal_botpolicy_binding',
137137
]
138+
139+
GETALL_ONLY_RESOURCES = [
140+
'appfwlearningdata',
141+
'application',
142+
'bridgetable',
143+
'gslbldnsentry',
144+
'locationfile',
145+
'locationfile6',
146+
'routerdynamicrouting',
147+
'sslcertbundle',
148+
'sslcertfile',
149+
'sslcrlfile',
150+
'ssldhfile',
151+
'sslkeyfile',
152+
'systementitydata'
153+
]

plugins/module_utils/module_executor.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
HTTP_RESOURCE_ALREADY_EXISTS,
3939
NETSCALER_COMMON_ARGUMENTS,
4040
NITRO_ATTRIBUTES_ALIASES,
41+
GETALL_ONLY_RESOURCES,
4142
)
4243
from .decorators import trace
4344
from .logger import log, loglines
@@ -320,7 +321,7 @@ def get_existing_resource(self):
320321
)
321322
if is_exist is False:
322323
return {}
323-
if len(existing_resource) > 1:
324+
if self.resource_name not in GETALL_ONLY_RESOURCES and len(existing_resource) > 1:
324325
msg = (
325326
"ERROR: For resource `%s` Found more than one resource with the same primary key `%s` and resource_module_params %s"
326327
% (
@@ -330,8 +331,20 @@ def get_existing_resource(self):
330331
)
331332
)
332333
self.return_failure(msg)
333-
334-
self.existing_resource = existing_resource[0]
334+
self.existing_resource = existing_resource[0]
335+
else:
336+
for resources in existing_resource:
337+
# Check if all module params match this resource
338+
match_found = True
339+
for key, value in self.resource_module_params.items():
340+
if key in resources and resources[key] != value:
341+
match_found = False
342+
break
343+
344+
# If all parameters match, use this resource
345+
if match_found:
346+
self.existing_resource = resources
347+
break
335348

336349
if self.resource_name in NITRO_ATTRIBUTES_ALIASES:
337350
self.existing_resource = self._add_nitro_attributes_aliases(

0 commit comments

Comments
 (0)