def test_job_create(): si = Site() si.name = 'test' si.description = 'test' si.full_clean() si.save() with pytest.raises(Exception) as execinfo: createJob('create', si, TestUser()) assert str(execinfo.value.code) == 'INVALID_TARGET'
def doJob( self, user, name ): """ This will submit a job to run the specified script. """ from contractor.Foreman.lib import createJob if name in ( 'create', 'destroy' ): raise ValueError( 'Invalid Job Name' ) return createJob( name, self, user )
def doJob( self, user, name ): from contractor.Foreman.lib import createJob if name in ( 'create', 'destroy' ): raise ValueError( 'Invalid Job Name' ) return createJob( name, self, user )
def doDestroy( self, user ): from contractor.Foreman.lib import createJob return createJob( 'destroy', self, user )
def doCreate( self, user ): from contractor.Foreman.lib import createJob return createJob( 'create', self, user )
def doDestroy( self, user ): """ This will submit a job to run the destroy script. """ from contractor.Foreman.lib import createJob return createJob( 'destroy', self, user )
def doCreate( self, user ): """ This will submit a job to run the create script. """ from contractor.Foreman.lib import createJob return createJob( 'create', self, user )
def test_can_start_destroy(mocker): mocker.patch('contractor.Building.models.Foundation._canSetState', fake_canSetState) # disable the job checking mocker.patch('contractor.Building.models.Structure._canSetState', fake_canSetState) mocker.patch('contractor.Building.models.Dependency._canSetState', fake_canSetState) si = Site() si.name = 'test' si.description = 'test' si.full_clean() si.save() fb = FoundationBluePrint(name='fdnb1', description='Foundation BluePrint 1') fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() f = Foundation() f.locator = 'test' f.site = si f.blueprint = fb f.full_clean() f.save() f.setBuilt() createJob('destroy', f, TestUser()) assert f.foundationjob.can_start is True sb = StructureBluePrint(name='strb1', description='Structure BluePrint 1') sb.full_clean() sb.save() sb.foundation_blueprint_list.add(fb) s = Structure() s.foundation = f s.hostname = 'test' s.site = si s.blueprint = sb s.full_clean() s.save() s.setBuilt() createJob('destroy', s, TestUser()) assert f.foundationjob.can_start is False assert s.structurejob.can_start is True d = Dependency() d.structure = s d.link = 'soft' d.full_clean() d.save() d.setBuilt() createJob('destroy', d, TestUser()) assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is True d2 = Dependency() d2.dependency = d d2.link = 'soft' d2.full_clean() d2.save() d2.setBuilt() createJob('destroy', d2, TestUser()) assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is True d2.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is True assert d2.dependencyjob.can_start is False d.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False s.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False f.setDestroyed() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False d2.setDestroyed() d.setBuilt() s.setBuilt() f.setBuilt() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is True assert d2.dependencyjob.can_start is False d = Dependency.objects.get(pk=d.pk) d.foundation = f d.full_clean() d.save() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False f.setDestroyed() s.setBuilt( ) # setting foundation to destoyed, destroys the structure, which destroys the dependency d.setBuilt() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False f.setBuilt() assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False assert d2.dependencyjob.can_start is False d2.dependencyjob.delete() d2.setDestroyed() f = Foundation.objects.get(pk=f.pk) s = Structure.objects.get(pk=s.pk) d = Dependency.objects.get(pk=d.pk) assert f.foundationjob.can_start is False assert s.structurejob.can_start is False assert d.dependencyjob.can_start is False d.dependencyjob.delete() d.setDestroyed() f = Foundation.objects.get(pk=f.pk) s = Structure.objects.get(pk=s.pk) assert f.foundationjob.can_start is False assert s.structurejob.can_start is True s.structurejob.delete() s.setDestroyed() f = Foundation.objects.get(pk=f.pk) assert f.foundationjob.can_start is True s.delete() # setting foundation.structure to None f = Foundation.objects.get(pk=f.pk) assert f.foundationjob.can_start is True
def test_dependency_job_create(): si = Site() si.name = 'test' si.description = 'test' si.full_clean() si.save() fb = FoundationBluePrint(name='fdnb1', description='Foundation BluePrint 1') fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() f = Foundation() f.locator = 'test' f.site = si f.blueprint = fb f.full_clean() f.save() sb = StructureBluePrint(name='strb1', description='Structure BluePrint 1') sb.full_clean() sb.save() sb.foundation_blueprint_list.add(fb) s = Structure() s.foundation = f s.hostname = 'test' s.site = si s.blueprint = sb s.full_clean() s.save() f.setBuilt() d = Dependency() d.structure = s d.link = 'soft' d.full_clean() d.save() with pytest.raises(Exception) as execinfo: createJob('destroy', d, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(Exception) as execinfo: createJob('other', d, TestUser()) assert str(execinfo.value.code) == 'INVALID_SCRIPT' assert createJob('create', d, TestUser()) is not None assert d.state == 'planned' with pytest.raises(Exception) as execinfo: createJob('create', d, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.setBuilt() d.dependencyjob.delete() d = Dependency.objects.get(pk=d.pk) with pytest.raises(Exception) as execinfo: createJob('destroy', d, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' d.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', d, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' assert d.state == 'built' assert createJob('destroy', d, TestUser()) is not None assert d.state == 'built' with pytest.raises(Exception) as execinfo: createJob('destroy', d, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' d.dependencyjob.delete() d = Dependency.objects.get(pk=d.pk) # test job type checking d.setDestroyed() s.setDestroyed() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk) assert createJob('create', s, TestUser()) is not None assert createJob('create', d, TestUser()) is not None d.dependencyjob.delete() s.structurejob.delete() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk) d.setDestroyed() s.setBuilt() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk) assert createJob('other', s, TestUser()) is not None with pytest.raises(ValueError) as execinfo: createJob('create', d, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk) d.setBuilt() s.setBuilt() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk) assert createJob('destroy', s, TestUser()) is not None assert createJob('destroy', d, TestUser()) is not None d.dependencyjob.delete() s.structurejob.delete() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk) d.setBuilt() s.setBuilt() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk) assert createJob('other', s, TestUser()) is not None with pytest.raises(ValueError) as execinfo: createJob('destroy', d, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() d = Dependency.objects.get(pk=d.pk) s = Structure.objects.get(pk=s.pk)
def test_structure_job_create(): # TODO: test structures with dependency si = Site() si.name = 'test' si.description = 'test' si.full_clean() si.save() fb = FoundationBluePrint(name='fdnb1', description='Foundation BluePrint 1') fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() f = Foundation() f.locator = 'test' f.site = si f.blueprint = fb f.full_clean() f.save() sb = StructureBluePrint(name='strb1', description='Structure BluePrint 1') sb.full_clean() sb.save() sb.foundation_blueprint_list.add(fb) s = Structure() s.foundation = f s.hostname = 'test' s.site = si s.blueprint = sb s.full_clean() s.save() with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(Exception) as execinfo: createJob('other', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' assert createJob('create', s, TestUser()) is not None assert s.state == 'planned' with pytest.raises(Exception) as execinfo: createJob('create', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() s = Structure.objects.get(pk=s.pk) f.setBuilt() with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(Exception) as execinfo: createJob('other', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', s, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' assert s.state == 'built' assert createJob('other', s, TestUser()) is not None assert s.state == 'built' with pytest.raises(Exception) as execinfo: createJob('other', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() s = Structure.objects.get(pk=s.pk) assert createJob('destroy', s, TestUser()) is not None assert s.state == 'built' with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' s.structurejob.delete() s = Structure.objects.get(pk=s.pk) f.setLocated() with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' # test job type checking s.setDestroyed() f.setDestroyed() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('create', f, TestUser()) is not None assert createJob('create', s, TestUser()) is not None s.structurejob.delete() f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) s.setDestroyed() f.setBuilt() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('other', f, TestUser()) is not None with pytest.raises(Exception) as execinfo: createJob('create', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) s.setBuilt() f.setBuilt() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('destroy', f, TestUser()) is not None assert createJob('destroy', s, TestUser()) is not None s.structurejob.delete() f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) s.setBuilt() f.setBuilt() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk) assert createJob('other', f, TestUser()) is not None with pytest.raises(Exception) as execinfo: createJob('destroy', s, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() s = Structure.objects.get(pk=s.pk) f = Foundation.objects.get(pk=f.pk)
def test_foundation_with_structure_job_create(): si = Site() si.name = 'test' si.description = 'test' si.full_clean() si.save() fb = FoundationBluePrint(name='fdnb1', description='Foundation BluePrint 1') fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() f = Foundation() f.locator = 'test' f.site = si f.blueprint = fb f.full_clean() f.save() sb = StructureBluePrint(name='strb1', description='Structure BluePrint 1') sb.full_clean() sb.save() sb.foundation_blueprint_list.add(fb) s = Structure() s.foundation = f s.hostname = 'test' s.site = si s.blueprint = sb s.full_clean() s.save() f.setDestroyed() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' f.setDestroyed() s.setBuilt() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() s.setBuilt() assert createJob('create', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setBuilt() s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' s.setDestroyed() f.setBuilt() assert createJob('destroy', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' f.setDestroyed() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' s.setBuilt() f.setBuilt() assert createJob('destroy', f, TestUser()) is not None f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' f.setDestroyed() s.setBuilt() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT'
def test_foundation_job_create( ): # TODO: should also do tests depending on a Dependency si = Site() si.name = 'test' si.description = 'test' si.full_clean() si.save() fb = FoundationBluePrint(name='fdnb1', description='Foundation BluePrint 1') fb.foundation_type_list = ['Unknown'] fb.full_clean() fb.save() f = Foundation() f.locator = 'test' f.site = si f.blueprint = fb f.full_clean() f.save() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(Exception) as execinfo: createJob('other', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' assert createJob('create', f, TestUser()) is not None assert f.state == 'planned' with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setLocated() with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' with pytest.raises(ValueError) as execinfo: createJob('other', f, TestUser()) assert str(execinfo.value.code) == 'NOT_BUILT' assert createJob('create', f, TestUser()) is not None assert f.state == 'located' with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) f.setBuilt() with pytest.raises(Exception) as execinfo: createJob('create', f, TestUser()) assert str(execinfo.value.code) == 'ALLREADY_BUILT' assert f.state == 'built' assert createJob('other', f, TestUser()) is not None assert f.state == 'built' with pytest.raises(Exception) as execinfo: createJob('other', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk) assert createJob('destroy', f, TestUser()) is not None assert f.state == 'built' with pytest.raises(Exception) as execinfo: createJob('destroy', f, TestUser()) assert str(execinfo.value.code) == 'JOB_EXISTS' f.foundationjob.delete() f = Foundation.objects.get(pk=f.pk)