def test_invalid(self):
     self.testfile.write('103 23605.0 Foo ::\n')
     self.testfile.flush()
     events = list(self.reader)
     #print "LastEvent", events[-1]
     self.assertEqual(
         classad.Function("isError", events[-1]['value']).eval(), True)
Exemple #2
0
 def test_function(self):
     expr = classad.Function("strcat", "hello", " ", "world")
     self.assertTrue(isinstance(expr, classad.ExprTree))
     self.assertEquals(expr.eval(), "hello world")
     expr = classad.Function("regexp", ".*")
     self.assertEquals(expr.eval(), classad.Value.Error)
  def _create_classad(self, app_name, app_version, cmd, args, cpu, memory):
    """_create_classad() creates a classad for submission to the
    htcondor cluster, utilizing HMDC custom ClassAds.

    :param app_name: application name
    :type app_name: ``str``
    :param app_version: application version
    :type app_version: ``str``
    :param cmd: command to run
    :type cmd: ``str``
    :param args: args to pass to cmd
    :type args: ``list``
    :param memory: memory to reserve for job
    :type memory: ``int``
    :returns: classad object
    :rtype: ``classad.ClassAd``

    :Example:

    >>> from hmdccondor import HMDCCondor
    >>> HMDCCondor()._create_classad('shell', '2.1.32',
      '/usr/bin/gnome-terminal', [], 1, 2048)

    """
    dt = datetime.utcnow().strftime("%Y%m%d%s")

    _out = "{0}_{1}".format(app_name, app_version)

    home = pwd.getpwnam(pwd.getpwuid(os.getuid())[0]).pw_dir
    job_dir_base= "{0}/.HMDC/jobs/interactive".format(home)
    job_dir = classad.Function('strcat', job_dir_base, '/', _out, '_', classad.ExprTree('ClusterId'), '_', dt)

    out = classad.Function('strcat', job_dir_base, '/', _out, '_', classad.ExprTree('ClusterId'), '_', dt, '/out.txt')
    err = classad.Function('strcat', job_dir_base, '/', _out, '_', classad.ExprTree('ClusterId'), '_', dt, '/err.txt')

    _email = self._get_email_for_classad()

    _classad = classad.ClassAd({
      'AcctGroup': 'group_interactive',
      'AcctGroupUser': pwd.getpwuid(os.getuid())[0],
      'AccountingGroup': "group_interactive.{0}".format(pwd.getpwuid(os.getuid())[0]),
      'HMDCNewSubmit': True,
      'HMDCApplicationName': app_name,
      'HMDCApplicationVersion': app_version,
      'HMDCInteractive': True,
      'HMDCUseXpra': True,
      'JobLeaseDuration': 1200,
      'LocalJobDir': job_dir,
      'DebugPrepareJobHook': True,
      'Cmd': cmd,
      'Args': args if args else False,
      'RequestCpus': cpu,
      'RequestMemory': memory,
      'ShouldTransferFiles': 'NO',
      'TransferExecutable': False,
      'TransferIn': False,
      'Out': out,
      'Err': err,
      'Entitlements': self._get_entitlements(),
      'Environment': self._get_environment(),
      'JobNotification': 1,
      'NotifyUser': _email,
      'Email': _email,
      'FileSystemDomain': CONSTANTS.FILESYSTEM_DOMAIN
      })

    rcelog('info', "Generated classad for submission. ClassAd printed below.")
    rcelog('info', _classad)

    return _classad
def test_function():
    expr = classad.Function("strcat", "hello", " ", "world")

    assert expr.eval() == "hello world"