예제 #1
0
  def test_RetryAction(self):
    action={'id' : 'tttt'}
    config = AmbariConfig().getConfig()
    actionQueue = ActionQueue(config)
    path = actionQueue.getInstallFilename(action['id'])
    configFile = {
      "data"       : "test",
      "owner"      : os.getuid(),
      "group"      : os.getgid() ,
      "permission" : 0700,
      "path"       : path,
      "umask"      : 022
    }

    #note that the command in the action is just a listing of the path created
    #we just want to ensure that 'ls' can run on the data file (in the actual world
    #this 'ls' would be a puppet or a chef command that would work on a data
    #file
    badAction = {
      'id' : 'tttt',
      'kind' : 'INSTALL_AND_CONFIG_ACTION',
      'workDirComponent' : 'abc-hdfs',
      'file' : configFile,
      'clusterDefinitionRevision' : 12,
      'command' : ['/bin/ls',"/foo/bar/badPath1234"]
    }
    path=getFilePath(action,path)
    goodAction = {
      'id' : 'tttt',
      'kind' : 'INSTALL_AND_CONFIG_ACTION',
      'workDirComponent' : 'abc-hdfs',
      'file' : configFile,
      'clusterDefinitionRevision' : 12,
      'command' : ['/bin/ls',path]
    }
    actionQueue.start()
    response = {'actions' : [badAction,goodAction]}
    actionQueue.maxRetries = 2
    actionQueue.sleepInterval = 1
    result = actionQueue.put(response)
    results = actionQueue.result()
    sleptCount = 1
    while (len(results) < 2 and sleptCount < 15):
        time.sleep(1)
        sleptCount += 1
        results = actionQueue.result()
    actionQueue.stop()
    actionQueue.join()
    self.assertEqual(len(results), 2, 'Number of results is not 2.')
    result = results[0]
    maxretries = config.get('command', 'maxretries')
    self.assertEqual(int(result['retryActionCount']), 
                     int(maxretries),
                     "Number of retries is %d and not %d" % 
                     (int(result['retryActionCount']), int(str(maxretries))))
    result = results[1]
    self.assertEqual(int(result['retryActionCount']), 
                     1,
                     "Number of retries is %d and not %d" % 
                     (int(result['retryActionCount']), 1))        
예제 #2
0
  def test_installAndConfigAction(self):
    action={'id' : 'tttt'}
    actionQueue = ActionQueue(AmbariConfig().getConfig())
    path = actionQueue.getInstallFilename(action['id'])
    configFile = {
      "data"       : "test",
      "owner"      : os.getuid(),
      "group"      : os.getgid() ,
      "permission" : 0700,
      "path"       : path,
      "umask"      : 022
    }

    #note that the command in the action is just a listing of the path created
    #we just want to ensure that 'ls' can run on the data file (in the actual world
    #this 'ls' would be a puppet or a chef command that would work on a data
    #file
    path=getFilePath(action,path)
    action = { 
      'id' : 'tttt',
      'kind' : 'INSTALL_AND_CONFIG_ACTION',
      'workDirComponent' : 'abc-hdfs',
      'file' : configFile,
      'clusterDefinitionRevision' : 12,
      'command' : ['/bin/ls',path]
    }
    result = { }
    actionQueue = ActionQueue(AmbariConfig().getConfig())
    result = actionQueue.installAndConfigAction(action)
    cmdResult = result['commandResult']
    self.assertEqual(cmdResult['exitCode'], 0, "installAndConfigAction test failed. Returned %d " % cmdResult['exitCode'])
    self.assertEqual(cmdResult['output'], path + "\n", "installAndConfigAction test failed Returned %s " % cmdResult['output'])