Skip to content

Commit

Permalink
fix run_as job and sub_folder in folder objs
Browse files Browse the repository at this point in the history
  • Loading branch information
RefaelBeker7 committed Jun 30, 2024
1 parent 9e94d1e commit 286592a
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 9 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
name="ctm-python-client",
packages=find_packages(where="src"),
package_dir={"": "src"},
version="2.3.0",
version="2.3.1",
description="Python Workflows for Control-M",
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down
2 changes: 1 addition & 1 deletion src/ctm_python_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '2.3.0'
__version__ = '2.3.1'
__author__ = 'BMC Software'
18 changes: 12 additions & 6 deletions src/ctm_python_client/core/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,27 @@ def clear_all(self):
self._connections = {}

def _apply_defaults_for_type(self, obj: typing.Any, type_: str):
for field in attrs.fields(WorkflowDefaults):
if type_ in field.metadata.get('applyon') \
and self.defaults.__getattribute__(field.name):
if obj.__getattribute__(field.name) is None:
obj.__setattr__(
field.name, self.defaults.__getattribute__(field.name))
if not obj:
return
else:
for field in attrs.fields(WorkflowDefaults):
if type_ in field.metadata.get('applyon') \
and self.defaults.__getattribute__(field.name):
if obj.__getattribute__(field.name) is None:
obj.__setattr__(
field.name, self.defaults.__getattribute__(field.name))

def _apply_defaults_for_job(self, obj: Job):
self._apply_defaults_for_type(obj, 'Job')

def _apply_defaults_for_folder(self, obj: Folder):
self._apply_defaults_for_type(obj, 'Folder')
list(map(self._apply_defaults_for_SubFolder, obj.sub_folder_list))
list(map(self._apply_defaults_for_job, obj.job_list))

def _apply_defaults_for_SimpleFolder(self, obj: SimpleFolder):
self._apply_defaults_for_type(obj, 'SimpleFolder')
list(map(self._apply_defaults_for_job, obj.job_list))

def _apply_defaults_for_SubFolder(self, obj: SubFolder):
self._apply_defaults_for_type(obj, 'SubFolder')
Expand Down
59 changes: 59 additions & 0 deletions tests/test_aapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,62 @@ def test_events():
assert any(isinstance(obj, aapi.AddEvents) and any(event.event == 'add2' for event in obj.events) for obj in job.add_events_list)

assert json.loads(job.dumps_aapi())

def test_job_in_folder_run_as():
workflow = Workflow(Environment.create_workbench("refael"), WorkflowDefaults(run_as='workbench'), skip_initial_authentication=True)
job_command = aapi.JobCommand('TestJob', command='echo Hello')

sla_job = aapi.JobSLAManagement('ForecastSLA',
service_name='ForecastSLA',
service_priority='1',
job_runs_deviations_tolerance='1',
complete_in=aapi.JobSLAManagement.CompleteIn(time='00:15'),
complete_by=aapi.JobSLAManagement.CompleteBy(
time='21:40', days='3'),
average_run_time_tolerance=aapi.JobSLAManagement.AverageRunTimeTolerance(
average_run_time='15',
units=aapi.JobSLAManagement.AverageRunTimeTolerance.Units.Minutes
))

subfolder = aapi.SubFolder('SubFolder')
folder = aapi.Folder("TestFolder",
sub_folder_list=[subfolder],
job_list=[sla_job, job_command]
)
workflow.add(folder)
# {"TestFolder": {"Type": "Folder", "ForecastSLA": {"Type": "Job:SLAManagement", "RunAs": "workbench", "ServiceName": "ForecastSLA", "ServicePriority": "1", "JobRunsDeviationsTolerance": "1", "AverageRunTimeTolerance": {"AverageRunTime": "15", "Units": "Minutes"}, "CompleteBy": {"Time": "21:40", "Days": "3"}, "CompleteIn": {"Time": "00:15"}}, "TestJob": {"Type": "Job:Command", "RunAs": "workbench", "Command": "echo Hello"}, "RunAs": "workbench", "SubFolder": {"Type": "SubFolder", "RunAs": "workbench"}}}
o = json.loads('''
{
"Type": "Folder",
"ForecastSLA": {
"Type": "Job:SLAManagement",
"RunAs": "workbench",
"ServiceName": "ForecastSLA",
"ServicePriority": "1",
"JobRunsDeviationsTolerance": "1",
"AverageRunTimeTolerance": {
"AverageRunTime": "15",
"Units": "Minutes"
},
"CompleteBy": {
"Time": "21:40",
"Days": "3"
},
"CompleteIn": {
"Time": "00:15"
}
},
"TestJob": {
"Type": "Job:Command",
"RunAs": "workbench",
"Command": "echo Hello"
},
"RunAs": "workbench",
"SubFolder": {
"Type": "SubFolder",
"RunAs": "workbench"
}
}
''')
assert workflow.get("TestFolder").as_aapi_dict() == o

2 changes: 1 addition & 1 deletion tests/test_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ def test_version_author():
import ctm_python_client

assert ctm_python_client.__author__ == 'BMC Software'
assert ctm_python_client.__version__ == '2.3.0'
assert ctm_python_client.__version__ == '2.3.1'


0 comments on commit 286592a

Please sign in to comment.