def _createTrafo(): """reads command line parameters, makes check and creates replication transformation""" clip = Params() clip.registerSwitches(Script) Script.parseCommandLine() if not clip.checkSettings(Script)['OK']: gLogger.error("ERROR: Missing settings") return 1 for metaValue in clip.metaValues: resCreate = createDataTransformation(flavour=clip.flavour, targetSE=clip.targetSE, sourceSE=clip.sourceSE, metaKey=clip.metaKey, metaValue=metaValue, extraData=clip.extraData, extraname=clip.extraname, groupSize=clip.groupSize, plugin=clip.plugin, enable=clip.enable, ) if not resCreate['OK']: gLogger.error("Failed to create Transformation", resCreate['Message']) return 1 return 0
def _createTrafo(): """reads command line parameters, makes check and creates replication transformation""" clip = Params() clip.registerSwitches(Script) Script.parseCommandLine() if not clip.checkSettings(Script)['OK']: gLogger.error("ERROR: Missing settings") return 1 for metaValue in clip.metaValues: resCreate = createDataTransformation( flavour=clip.flavour, targetSE=clip.targetSE, sourceSE=clip.sourceSE, metaKey=clip.metaKey, metaValue=metaValue, extraData=clip.extraData, extraname=clip.extraname, groupSize=clip.groupSize, plugin=clip.plugin, enable=clip.enable, ) if not resCreate['OK']: gLogger.error("Failed to create Transformation", resCreate['Message']) return 1 return 0
def main(): """reads command line parameters, makes check and creates replication transformation""" from DIRAC import gLogger, exit as dexit from DIRAC.TransformationSystem.Utilities.ReplicationCLIParameters import Params clip = Params() clip.registerSwitches(Script) Script.parseCommandLine() from DIRAC.TransformationSystem.Utilities.ReplicationTransformation import createDataTransformation if not clip.checkSettings(Script)["OK"]: gLogger.error("ERROR: Missing settings") dexit(1) for metaValue in clip.metaValues: resCreate = createDataTransformation( flavour=clip.flavour, targetSE=clip.targetSE, sourceSE=clip.sourceSE, metaKey=clip.metaKey, metaValue=metaValue, extraData=clip.extraData, extraname=clip.extraname, groupSize=clip.groupSize, tGroup=clip.groupName, plugin=clip.plugin, enable=clip.enable, ) if not resCreate["OK"]: gLogger.error("Failed to create Transformation", resCreate["Message"]) dexit(1) dexit(0)
def setUp(self): self.arguments = [] self.sMock = Mock() self.sMock.getPositionalArgs.return_value = self.arguments self.params = Params()
class TestParams(unittest.TestCase): """Test the parameters for the moving creation script""" def setUp(self): self.arguments = [] self.sMock = Mock() self.sMock.getPositionalArgs.return_value = self.arguments self.params = Params() def tearDown(self): pass @patch(GET_PROXY, new=getProxyMock()) @patch(GET_VOMS, new=Mock(return_value='clic')) def test_checkSettings(self): self.arguments = ['12345', "TargetSE"] self.sMock.getPositionalArgs.return_value = self.arguments ret = self.params.checkSettings(self.sMock) self.assertTrue(ret['OK'], ret.get("Message", '')) self.assertEqual(self.params.metaValues, ['12345']) self.assertEqual(self.params.sourceSE, '') self.assertEqual(self.params.targetSE, ["TargetSE"]) @patch(GET_PROXY, new=getProxyMock()) @patch(GET_VOMS, new=Mock(return_value='clic')) def test_setMetadata(self): ret = self.params.setMetadata("Datatype:GEN, Energy: 124") self.assertTrue(ret['OK'], ret.get("Message", '')) self.assertEqual(self.params.extraData, {'Datatype': 'GEN', 'Energy': '124'}) @patch(GET_PROXY, new=getProxyMock()) @patch(GET_VOMS, new=Mock(return_value='clic')) def test_checkSettings_FailArgumentSize(self): self.arguments = ['12345', "TargetSE", 'Foo'] self.sMock.getPositionalArgs.return_value = self.arguments ret = self.params.checkSettings(self.sMock) self.assertFalse(ret['OK'], str(ret)) self.assertTrue(any("ERROR: Wrong number of arguments" in msg for msg in self.params.errorMessages)) @patch(GET_PROXY, new=getProxyMock(False)) @patch(GET_VOMS, new=Mock(return_value='clic')) def test_FailProxy(self): self.arguments = ['12345', "TargetSE"] self.sMock.getPositionalArgs.return_value = self.arguments ret = self.params.checkSettings(self.sMock) self.assertFalse(ret['OK'], str(ret)) self.assertTrue(any("ERROR: No Proxy" in msg for msg in self.params.errorMessages), str(self.params.errorMessages)) @patch(GET_PROXY, new=getProxyMock(True)) @patch(GET_VOMS, new=Mock(return_value='')) def test_FailProxy2(self): self.arguments = ['12345', "TargetSE"] self.sMock.getPositionalArgs.return_value = self.arguments ret = self.params.checkSettings(self.sMock) self.assertFalse(ret['OK'], str(ret)) self.assertTrue(any("ERROR: ProxyGroup" in msg for msg in self.params.errorMessages), str(self.params.errorMessages)) def test_setExtraName(self): ret = self.params.setExtraname("extraName") self.assertTrue(ret['OK'], ret.get('Message', "")) self.assertEqual("extraName", self.params.extraname)