Ejemplo n.º 1
0
 def test_build(self):
   config = AgentConfig("", "")
   config.set('agent', 'prefix', 'tmp')
   config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache")
   config.set('agent', 'tolerate_download_failures', "true")
   dummy_controller = MagicMock()
   actionQueue = ActionQueue(config, dummy_controller)
   heartbeat = Heartbeat(actionQueue, config)
   result = heartbeat.build(100)
   print "Heartbeat: " + str(result)
   self.assertEquals(result['hostname'] != '', True,
                     "hostname should not be empty")
   self.assertEquals(result['responseId'], 100)
   self.assertEquals(result['componentStatus'] is not None, True,
                     "Heartbeat should contain componentStatus")
   self.assertEquals(result['reports'] is not None, True,
                     "Heartbeat should contain reports")
   self.assertEquals(result['timestamp'] >= 1353679373880L, True)
   self.assertEquals(len(result['nodeStatus']), 2)
   self.assertEquals(result['nodeStatus']['cause'], "NONE")
   self.assertEquals(result['nodeStatus']['status'], "HEALTHY")
   # result may or may NOT have an agentEnv structure in it
   self.assertEquals((len(result) is 6) or (len(result) is 7), True)
   self.assertEquals(not heartbeat.reports, True,
                     "Heartbeat should not contain task in progress")
Ejemplo n.º 2
0
 def test_build(self):
     config = AgentConfig("", "")
     config.set('agent', 'prefix', 'tmp')
     dummy_controller = MagicMock()
     actionQueue = ActionQueue(config, dummy_controller)
     heartbeat = Heartbeat(actionQueue, config)
     result = heartbeat.build({}, 100)
     print "Heartbeat: " + str(result)
     self.assertEquals(result['hostname'] != '', True,
                       "hostname should not be empty")
     self.assertEquals(result['responseId'], 100)
     self.assertEquals('componentStatus' not in result, True,
                       "Heartbeat should contain componentStatus")
     self.assertEquals(result['reports'] is not None, True,
                       "Heartbeat should contain reports")
     self.assertEquals(result['timestamp'] >= 1353679373880L, True)
     self.assertEquals(len(result['nodeStatus']), 2)
     self.assertEquals(result['nodeStatus']['cause'], "NONE")
     self.assertEquals(result['nodeStatus']['status'], "HEALTHY")
     # result may or may NOT have an agentEnv structure in it
     self.assertEquals((len(result) is 4) or (len(result) is 5), True)
     self.assertEquals(not heartbeat.reports, True,
                       "Heartbeat should not contain task in progress")
Ejemplo n.º 3
0
  def test_build_long_result(self, result_mock):
    config = AgentConfig("", "")
    config.set('agent', 'prefix', 'tmp')
    config.set('agent', 'cache_dir', "/var/lib/ambari-agent/cache")
    config.set('agent', 'tolerate_download_failures', "true")
    dummy_controller = MagicMock()
    actionQueue = ActionQueue(config, dummy_controller)
    result_mock.return_value = {
      'reports': [{'status': 'IN_PROGRESS',
                   'stderr': 'Read from /tmp/errors-3.txt',
                   'stdout': 'Read from /tmp/output-3.txt',
                   'clusterName': u'cc',
                   'roleCommand': u'INSTALL',
                   'serviceName': u'HDFS',
                   'role': u'DATANODE',
                   'actionId': '1-1',
                   'taskId': 3,
                   'exitCode': 777},

                  {'status': 'COMPLETED',
                   'stderr': 'stderr',
                   'stdout': 'out',
                   'clusterName': 'clusterName',
                   'roleCommand': 'UPGRADE',
                   'serviceName': 'serviceName',
                   'role': 'role',
                   'actionId': 17,
                   'taskId': 'taskId',
                   'exitCode': 0},

                  {'status': 'FAILED',
                   'stderr': 'stderr',
                   'stdout': 'out',
                   'clusterName': u'cc',
                   'roleCommand': u'INSTALL',
                   'serviceName': u'HDFS',
                   'role': u'DATANODE',
                   'actionId': '1-1',
                   'taskId': 3,
                   'exitCode': 13},

                  {'status': 'COMPLETED',
                   'stderr': 'stderr',
                   'stdout': 'out',
                   'clusterName': u'cc',
                   'configurationTags': {'global': {'tag': 'v1'}},
                   'roleCommand': u'INSTALL',
                   'serviceName': u'HDFS',
                   'role': u'DATANODE',
                   'actionId': '1-1',
                   'taskId': 3,
                   'exitCode': 0}

      ],
      'componentStatus': [
        {'status': 'HEALTHY', 'componentName': 'DATANODE'},
        {'status': 'UNHEALTHY', 'componentName': 'NAMENODE'},
      ],
    }
    heartbeat = Heartbeat(actionQueue, config)
    hb = heartbeat.build(10)
    hb['hostname'] = 'hostname'
    hb['timestamp'] = 'timestamp'
    expected = {'nodeStatus':
                  {'status': 'HEALTHY',
                   'cause': 'NONE'},
                'timestamp': 'timestamp', 'hostname': 'hostname',
                'responseId': 10, 'reports': [
      {'status': 'IN_PROGRESS', 'roleCommand': u'INSTALL',
       'serviceName': u'HDFS', 'role': u'DATANODE', 'actionId': '1-1',
       'stderr': 'Read from /tmp/errors-3.txt',
       'stdout': 'Read from /tmp/output-3.txt', 'clusterName': u'cc',
       'taskId': 3, 'exitCode': 777},
      {'status': 'COMPLETED', 'roleCommand': 'UPGRADE',
       'serviceName': 'serviceName', 'role': 'role', 'actionId': 17,
       'stderr': 'stderr', 'stdout': 'out', 'clusterName': 'clusterName',
       'taskId': 'taskId', 'exitCode': 0},
      {'status': 'FAILED', 'roleCommand': u'INSTALL', 'serviceName': u'HDFS',
       'role': u'DATANODE', 'actionId': '1-1', 'stderr': 'stderr',
       'stdout': 'out', 'clusterName': u'cc', 'taskId': 3, 'exitCode': 13},
      {'status': 'COMPLETED', 'stdout': 'out',
       'configurationTags': {'global': {'tag': 'v1'}}, 'taskId': 3,
       'exitCode': 0, 'roleCommand': u'INSTALL', 'clusterName': u'cc',
       'serviceName': u'HDFS', 'role': u'DATANODE', 'actionId': '1-1',
       'stderr': 'stderr'}], 'componentStatus': [
      {'status': 'HEALTHY', 'componentName': 'DATANODE'},
      {'status': 'UNHEALTHY', 'componentName': 'NAMENODE'}]}
    self.assertEquals(hb, expected)
Ejemplo n.º 4
0
 def test_build_long_result(self, result_mock):
     config = AgentConfig("", "")
     config.set('agent', 'prefix', 'tmp')
     dummy_controller = MagicMock()
     actionQueue = ActionQueue(config, dummy_controller)
     result_mock.return_value = {
         'reports': [{
             'status': 'IN_PROGRESS',
             'stderr': 'Read from /tmp/errors-3.txt',
             'stdout': 'Read from /tmp/output-3.txt',
             'clusterName': u'cc',
             'roleCommand': u'INSTALL',
             'serviceName': u'HDFS',
             'role': u'DATANODE',
             'actionId': '1-1',
             'taskId': 3,
             'exitCode': 777
         }, {
             'status': 'COMPLETED',
             'stderr': 'stderr',
             'stdout': 'out',
             'clusterName': 'clusterName',
             'roleCommand': 'UPGRADE',
             'serviceName': 'serviceName',
             'role': 'role',
             'actionId': 17,
             'taskId': 'taskId',
             'exitCode': 0
         }, {
             'status': 'FAILED',
             'stderr': 'stderr',
             'stdout': 'out',
             'clusterName': u'cc',
             'roleCommand': u'INSTALL',
             'serviceName': u'HDFS',
             'role': u'DATANODE',
             'actionId': '1-1',
             'taskId': 3,
             'exitCode': 13
         }, {
             'status': 'COMPLETED',
             'stderr': 'stderr',
             'stdout': 'out',
             'clusterName': u'cc',
             'configurationTags': {
                 'global': {
                     'tag': 'v1'
                 }
             },
             'roleCommand': u'INSTALL',
             'serviceName': u'HDFS',
             'role': u'DATANODE',
             'actionId': '1-1',
             'taskId': 3,
             'exitCode': 0
         }],
         'componentStatus': [
             {
                 'status': 'HEALTHY',
                 'componentName': 'DATANODE',
                 'reportResult': True
             },
             {
                 'status': 'UNHEALTHY',
                 'componentName': 'NAMENODE',
                 'reportResult': True
             },
             {
                 'status': 'UNHEALTHY',
                 'componentName': 'HBASE_MASTER',
                 'reportResult': False
             },
         ],
     }
     heartbeat = Heartbeat(actionQueue, config)
     hb = heartbeat.build({}, 10)
     hb['hostname'] = 'hostname'
     hb['timestamp'] = 'timestamp'
     expected = {
         'nodeStatus': {
             'status': 'HEALTHY',
             'cause': 'NONE'
         },
         'timestamp':
         'timestamp',
         'hostname':
         'hostname',
         'responseId':
         10,
         'reports': [{
             'status': 'IN_PROGRESS',
             'roleCommand': u'INSTALL',
             'serviceName': u'HDFS',
             'role': u'DATANODE',
             'actionId': '1-1',
             'stderr': 'Read from /tmp/errors-3.txt',
             'stdout': 'Read from /tmp/output-3.txt',
             'clusterName': u'cc',
             'taskId': 3,
             'exitCode': 777
         }, {
             'status': 'COMPLETED',
             'roleCommand': 'UPGRADE',
             'serviceName': 'serviceName',
             'role': 'role',
             'actionId': 17,
             'stderr': 'stderr',
             'stdout': 'out',
             'clusterName': 'clusterName',
             'taskId': 'taskId',
             'exitCode': 0
         }, {
             'status': 'FAILED',
             'roleCommand': u'INSTALL',
             'serviceName': u'HDFS',
             'role': u'DATANODE',
             'actionId': '1-1',
             'stderr': 'stderr',
             'stdout': 'out',
             'clusterName': u'cc',
             'taskId': 3,
             'exitCode': 13
         }, {
             'status': 'COMPLETED',
             'stdout': 'out',
             'configurationTags': {
                 'global': {
                     'tag': 'v1'
                 }
             },
             'taskId': 3,
             'exitCode': 0,
             'roleCommand': u'INSTALL',
             'clusterName': u'cc',
             'serviceName': u'HDFS',
             'role': u'DATANODE',
             'actionId': '1-1',
             'stderr': 'stderr'
         }],
         'componentStatus': [{
             'status': 'HEALTHY',
             'componentName': 'DATANODE'
         }, {
             'status': 'UNHEALTHY',
             'componentName': 'NAMENODE'
         }]
     }
     self.assertEquals(hb, expected)