diff --git a/setup.py b/setup.py index ebb04e0..63eb1be 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ name="ctm-python-client", packages=find_packages(where="src"), package_dir={"": "src"}, - version="2.2.0", + version="2.2.1", description="Python Workflows for Control-M", long_description=long_description, long_description_content_type='text/markdown', diff --git a/src/aapi/addevents.py b/src/aapi/addevents.py index aea9659..6c95717 100644 --- a/src/aapi/addevents.py +++ b/src/aapi/addevents.py @@ -20,4 +20,5 @@ class AddEvents(AAPIObject): def __attrs_post_init__(self): if self.object_name == attrs.fields_dict(self.__class__)['object_name'].default: - self.object_name = f'{self.object_name}_{random.choices(string.ascii_letters + string.digits, k=8)}' + random_attr = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + self.object_name = f'{self.object_name}_{random_attr}' diff --git a/src/aapi/deleteevents.py b/src/aapi/deleteevents.py index f0b46c0..b2c20f0 100644 --- a/src/aapi/deleteevents.py +++ b/src/aapi/deleteevents.py @@ -20,4 +20,5 @@ class DeleteEvents(AAPIObject): def __attrs_post_init__(self): if self.object_name == attrs.fields_dict(self.__class__)['object_name'].default: - self.object_name = f'{self.object_name}_{random.choices(string.ascii_letters + string.digits, k=8)}' + random_attr = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + self.object_name = f'{self.object_name}_{random_attr}' \ No newline at end of file diff --git a/src/aapi/waitforevents.py b/src/aapi/waitforevents.py index 1aa2732..b498240 100644 --- a/src/aapi/waitforevents.py +++ b/src/aapi/waitforevents.py @@ -20,4 +20,5 @@ class WaitForEvents(AAPIObject): def __attrs_post_init__(self): if self.object_name == attrs.fields_dict(self.__class__)['object_name'].default: - self.object_name = f'{self.object_name}_{random.choices(string.ascii_letters + string.digits, k=8)}' + random_attr = ''.join(random.choices(string.ascii_letters + string.digits, k=8)) + self.object_name = f'{self.object_name}_{random_attr}' diff --git a/src/ctm_python_client/__init__.py b/src/ctm_python_client/__init__.py index 34324de..0d78a08 100644 --- a/src/ctm_python_client/__init__.py +++ b/src/ctm_python_client/__init__.py @@ -1,2 +1,2 @@ -__version__ = '2.2.0' +__version__ = '2.2.1' __author__ = 'BMC Software' \ No newline at end of file diff --git a/src/ctm_python_client/core/workflow.py b/src/ctm_python_client/core/workflow.py index 437f429..fc2c50a 100644 --- a/src/ctm_python_client/core/workflow.py +++ b/src/ctm_python_client/core/workflow.py @@ -208,19 +208,19 @@ def connect(self, srcpath: str, destpath: str, *, inpath: str = None): # support backward compatibility if not obj_src.add_events_list: obj_src.add_events_list.append( - AddEvents('events_to_add', events=[])) + AddEvents(events=[])) obj_src.add_events_list[-1].events.append( ConditionOutAdd(event=event_name)) if not obj_dest.wait_for_events_list: obj_dest.wait_for_events_list.append( - WaitForEvents('events_to_wait', events=[])) + WaitForEvents(events=[])) obj_dest.wait_for_events_list[-1].events.append( ConditionIn(event=event_name)) if not obj_dest.delete_events_list: obj_dest.delete_events_list.append( - DeleteEvents('events_to_delete', events=[])) + DeleteEvents(events=[])) obj_dest.delete_events_list[-1].events.append( ConditionOutDelete(event=event_name)) diff --git a/tests/test_aapi.py b/tests/test_aapi.py index 180e3ae..25904db 100644 --- a/tests/test_aapi.py +++ b/tests/test_aapi.py @@ -35,12 +35,58 @@ def test_json_generation(): def test_copy_workflow(): workflow = Workflow(Environment.create_workbench("refael"), WorkflowDefaults(run_as='workbench'), skip_initial_authentication=True) - workflow.add(aapi.JobCommand('MyFirstJob', command='ls -lt', run_as='workbench'), inpath='MyFirstFolder') + workflow.add(aapi.JobCommand('TestJob', command='ls -lt', run_as='workbench'), inpath='TestFolder') newworkflow = BaseWorkflow() newworkflow.copy_from(workflow=workflow) - assert newworkflow.get("MyFirstFolder").dumps_aapi(indent=2) == workflow.get("MyFirstFolder").dumps_aapi(indent=2) + assert newworkflow.get("TestFolder").dumps_aapi(indent=2) == workflow.get("TestFolder").dumps_aapi(indent=2) - o = json.loads('{\n "Type": "Folder",\n "MyFirstJob": {\n "Type": "Job:Command",\n "RunAs": "workbench",\n "Command": "ls -lt"\n },\n "RunAs": "workbench"\n}') - assert newworkflow.get("MyFirstFolder").as_aapi_dict() == o + o = json.loads('{\n "Type": "Folder",\n "TestJob": {\n "Type": "Job:Command",\n "RunAs": "workbench",\n "Command": "ls -lt"\n },\n "RunAs": "workbench"\n}') + assert newworkflow.get("TestFolder").as_aapi_dict() == o + +def test_connecting_jobs(): + workflow = Workflow(Environment.create_workbench("refael"), WorkflowDefaults(run_as='workbench'), skip_initial_authentication=True) + firstjob = workflow.add( + aapi.JobCommand('JobToConnect1', command="first"), + inpath='TestFolder' + ) + + secondjob = workflow.add( + aapi.JobCommand('JobToConnect2', command="second"), + inpath='TestFolder' + ) + workflow.connect(firstjob, secondjob) + +def test_chaining_jobs(): + workflow = Workflow(Environment.create_workbench("refael"), WorkflowDefaults(run_as='workbench'), skip_initial_authentication=True) + workflow.chain( + [ + aapi.JobCommand('FirstTestJob', "First"), + aapi.JobCommand('SecondTestJob', "Second"), + aapi.JobCommand('ThirdTestJob', "Third", run_as_dummy=True), + ], + inpath='ChainedJobs' + ) + +def test_events(): + job = aapi.JobCommand('Job1', command='echo Hello') + + waitForEventList = aapi.WaitForEvents([aapi.Event(event="wait1"), aapi.Event(event="wait2", date=aapi.Event.Date.AnyDate)]) + job.event_list.append(waitForEventList) + + deleteEventListObject = aapi.DeleteEvents([aapi.EventOutDelete(event="delete")]) + job.event_list.append(deleteEventListObject) + + addEventListObject1 = aapi.AddEvents([aapi.EventOutAdd(event="add1")]) + job.event_list.append(addEventListObject1) + + addEventListObject2 = aapi.AddEvents([aapi.EventOutAdd(event="add2",date=aapi.Event.Date.NoDate)]) + job.add_events_list.append(addEventListObject2) + + assert any(isinstance(obj, aapi.WaitForEvents) and any(event.event == 'wait2' for event in obj.events) for obj in job.event_list) + assert any(isinstance(obj, aapi.DeleteEvents) and any(event.event == 'delete' for event in obj.events) for obj in job.event_list) + assert any(isinstance(obj, aapi.AddEvents) and any(event.event == 'add1' for event in obj.events) for obj in job.event_list) + 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()) diff --git a/tests/test_sanity.py b/tests/test_sanity.py index f6b865f..d78ec43 100644 --- a/tests/test_sanity.py +++ b/tests/test_sanity.py @@ -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.2.0' + assert ctm_python_client.__version__ == '2.2.1'