示例#1
0
  def test_linux_flow(self, disk_usage_mock):
    # / OK, /usr/hdp OK
    disk_usage_mock.return_value = \
      alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L)
    res = alert_disk_space.execute()
    self.assertEqual(res, ('OK', ['Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]']))

    # / WARNING, /usr/hdp OK
    disk_usage_mock.return_value = \
      alert_disk_space.DiskInfo(total=21673930752L, used=14521533603L, free=7152397149L)
    res = alert_disk_space.execute()
    self.assertEqual(res, ('WARNING', ['Capacity Used: [67.00%, 14.5 GB], Capacity Total: [21.7 GB]']))

    # / CRITICAL, /usr/hdp OK
    disk_usage_mock.return_value = \
      alert_disk_space.DiskInfo(total=21673930752L, used=20590234214L, free=1083696538)
    res = alert_disk_space.execute()
    self.assertEqual(res, ('CRITICAL', ['Capacity Used: [95.00%, 20.6 GB], Capacity Total: [21.7 GB]']))

    # / < 5GB, /usr/hdp OK
    disk_usage_mock.return_value = \
      alert_disk_space.DiskInfo(total=5418482688L, used=1625544806L, free=3792937882L)
    res = alert_disk_space.execute()
    self.assertEqual(res, ('WARNING', ['Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB]. Free space < 5.0 GB']))

    # / OK, /usr/hdp WARNING
    disk_usage_mock.side_effect = \
      [alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L),
       alert_disk_space.DiskInfo(total=21673930752L, used=14521533603L, free=7152397149L)]
    res = alert_disk_space.execute()
    self.assertEqual(res, ('WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
                                       "Insufficient space at /usr/hdp: Capacity Used: [67.00%, 14.5 GB], Capacity Total: [21.7 GB]"]))

    # / OK, /usr/hdp CRITICAL
    disk_usage_mock.side_effect = \
      [alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L),
       alert_disk_space.DiskInfo(total=21673930752L, used=20590234214L, free=1083696538L)]
    res = alert_disk_space.execute()
    self.assertEqual(res, ('WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
                                       "Insufficient space at /usr/hdp: Capacity Used: [95.00%, 20.6 GB], Capacity Total: [21.7 GB]"]))

    # / OK, /usr/hdp < 5GB
    disk_usage_mock.side_effect = \
      [alert_disk_space.DiskInfo(total=21673930752L, used=5695861760L, free=15978068992L),
       alert_disk_space.DiskInfo(total=5418482688L, used=1625544806L, free=3792937882L)]
    res = alert_disk_space.execute()
    self.assertEqual(res, ('WARNING', ["Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB]. "
                                       "Insufficient space at /usr/hdp: Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB]. Free space < 5.0 GB"]))
示例#2
0
  def test_linux_flow(self, isdir_mock, disk_usage_mock):
    isdir_mock.return_value = False

    # / OK
    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
      total = 21673930752L, used = 5695861760L,
      free = 15978068992L, path="/")

    res = alert_disk_space.execute(configurations={'{{cluster-env/stack_root}}': '/usr/hdp'})
    self.assertEqual(res,
      ('OK', ['Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB], path=/']))

    # / WARNING
    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
      total = 21673930752L, used = 14521533603L,
      free = 7152397149L, path="/")

    res = alert_disk_space.execute(configurations={'{{cluster-env/stack_root}}': '/usr/hdp'})
    self.assertEqual(res, (
      'WARNING',
      ['Capacity Used: [67.00%, 14.5 GB], Capacity Total: [21.7 GB], path=/']))

    # / CRITICAL
    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
      total = 21673930752L, used = 20590234214L,
      free = 1083696538, path="/")

    res = alert_disk_space.execute(configurations={'{{cluster-env/stack_root}}': '/usr/hdp'})
    self.assertEqual(res, ('CRITICAL',
    ['Capacity Used: [95.00%, 20.6 GB], Capacity Total: [21.7 GB], path=/']))

    # / OK but < 5GB
    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
      total = 5418482688L, used = 1625544806L,
      free = 3792937882L, path="/")

    res = alert_disk_space.execute(configurations={'{{cluster-env/stack_root}}': '/usr/hdp'})
    self.assertEqual(res, ('WARNING', [
      'Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB], path=/. Total free space is less than 5.0 GB']))

    # trigger isdir(<stack-root>) to True
    isdir_mock.return_value = True

    # / OK
    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
      total = 21673930752L, used = 5695861760L,
      free = 15978068992L, path="/usr/hdp")

    res = alert_disk_space.execute(configurations={'{{cluster-env/stack_root}}': '/usr/hdp'})
    self.assertEqual(res,
      ('OK', ['Capacity Used: [26.28%, 5.7 GB], Capacity Total: [21.7 GB], path=/usr/hdp']))

    # <stack-root> < 5GB
    disk_usage_mock.return_value = alert_disk_space.DiskInfo(
      total = 5418482688L, used = 1625544806L,
      free = 3792937882L, path="/usr/hdp")

    res = alert_disk_space.execute(configurations={'{{cluster-env/stack_root}}': '/usr/hdp'})
    self.assertEqual(res, (
      'WARNING', ["Capacity Used: [30.00%, 1.6 GB], Capacity Total: [5.4 GB], path=/usr/hdp. Total free space is less than 5.0 GB"]))