示例#1
0
 def test_004(self):
     i = 4
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'],
                           ['raid1', 'raid6', 'raid5', 'raid4'])
     self.assertEqual(
         mdstat_test.get_stats()['arrays'], {
             'md2': {
                 'status': 'active',
                 'available': '2',
                 'used': '2',
                 'components': {
                     'sdb3': '1',
                     'sda3': '0'
                 },
                 'config': 'UU',
                 'type': 'raid1'
             },
             'md3': {
                 'status': 'active',
                 'available': '10',
                 'used': '10',
                 'components': {
                     'sdk1': '8',
                     'sdj1': '7',
                     'sde1': '2',
                     'sdl1': '9',
                     'sdg1': '4',
                     'sdf1': '3',
                     'sdh1': '5',
                     'sdc1': '0',
                     'sdd1': '1',
                     'sdi1': '6'
                 },
                 'config': 'UUUUUUUUUU',
                 'type': 'raid5'
             },
             'md0': {
                 'status': 'active',
                 'available': '2',
                 'used': '2',
                 'components': {
                     'sdb1': '1',
                     'sda1': '0'
                 },
                 'config': 'UU',
                 'type': 'raid1'
             },
             'md1': {
                 'status': 'active',
                 'available': '2',
                 'used': '2',
                 'components': {
                     'sdb2': '1',
                     'sda2': '0'
                 },
                 'config': 'UU',
                 'type': 'raid1'
             }
         })
示例#2
0
    def update(self):
        """Update RAID stats using the input method."""
        # Init new stats
        stats = self.get_init_value()

        if import_error_tag:
            return self.stats

        if self.input_method == 'local':
            # Update stats using the PyMDstat lib (https://github.com/nicolargo/pymdstat)
            try:
                # Just for test
                # mds = MdStat(path='/home/nicolargo/dev/pymdstat/tests/mdstat.10')
                mds = MdStat()
                stats = mds.get_stats()['arrays']
            except Exception as e:
                logger.debug("Can not grab RAID stats (%s)" % e)
                return self.stats

        elif self.input_method == 'snmp':
            # Update stats using SNMP
            # No standard way for the moment...
            pass

        # Update the stats
        self.stats = stats

        return self.stats
示例#3
0
 def test_006(self):
     i = 6
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(
         mdstat_test.get_stats()['personalities'],
         ['linear', 'raid0', 'raid1', 'raid5', 'raid4', 'raid6'])
     self.assertEqual(
         mdstat_test.get_stats()['arrays'], {
             'md0': {
                 'status': 'active',
                 'available': '7',
                 'used': '7',
                 'components': {
                     'sde1': '1',
                     'sdf1': '0',
                     'sdc1': '3',
                     'sdb1': '4',
                     'hdb1': '6',
                     'sdd1': '2',
                     'sda1': '5'
                 },
                 'config': 'UUUUUUU',
                 'type': 'raid6'
             }
         })
示例#4
0
    def update(self):
        """Update RAID stats using the input method."""
        # Init new stats
        stats = self.get_init_value()

        if import_error_tag:
            return self.stats

        if self.input_method == 'local':
            # Update stats using the PyMDstat lib (https://github.com/nicolargo/pymdstat)
            try:
                # Just for test
                # mds = MdStat(path='/home/nicolargo/dev/pymdstat/tests/mdstat.10')
                mds = MdStat()
                stats = mds.get_stats()['arrays']
            except Exception as e:
                logger.debug("Can not grab RAID stats (%s)" % e)
                return self.stats

        elif self.input_method == 'snmp':
            # Update stats using SNMP
            # No standard way for the moment...
            pass

        # Update the stats
        self.stats = stats

        return self.stats
示例#5
0
def soft_raid_status():
"""Function for check status a software raid"""
    mds = MdStat()
    arrays = mds.arrays()
    status = []
    for i in arrays:
        components = (mds.get_stats().get('arrays').get(i).get('components'))
        config = (mds.get_stats().get('arrays').get(i).get('config'))
        result  = (i, components, config)
        status.append(result)
    return status
示例#6
0
 def test_099_model(self):
     i = 4
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.personalities(), ['raid1', 'raid6', 'raid5', 'raid4'])
     self.assertCountEqual(mdstat_test.arrays(), ['md2', 'md3', 'md0', 'md1'])
     self.assertEqual(mdstat_test.type('md3'), 'raid5')
     self.assertEqual(mdstat_test.status('md3'), 'active')
     self.assertEqual(mdstat_test.available('md3'), 10)
     self.assertEqual(mdstat_test.used('md3'), 10)
     self.assertCountEqual(mdstat_test.components('md3'), ['sdk1', 'sdj1', 'sde1', 'sdl1', 'sdg1', 'sdf1', 'sdh1', 'sdc1', 'sdd1', 'sdi1'])
     self.assertEqual(mdstat_test.config('md3'), 'UUUUUUUUUU')
示例#7
0
def softwareDetected():
"""Detected software raid and check it"""
    global mds
    mds = MdStat()
    raid = mds.arrays() # Get all arrays
    disk  = [i for i in raid]
    if not disk: # if list is empty return False
       return False
    for i  in disk:
        if mds.config(i) == "chunks":
            continue
        elif mds.config(i) != "UU":
            return False
    else:
        return True
示例#8
0
 def test_099_model(self):
     i = 4
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.personalities(),
                           ['raid1', 'raid6', 'raid5', 'raid4'])
     self.assertCountEqual(mdstat_test.arrays(),
                           ['md2', 'md3', 'md0', 'md1'])
     self.assertEqual(mdstat_test.type('md3'), 'raid5')
     self.assertEqual(mdstat_test.status('md3'), 'active')
     self.assertEqual(mdstat_test.available('md3'), 10)
     self.assertEqual(mdstat_test.used('md3'), 10)
     self.assertCountEqual(mdstat_test.components('md3'), [
         'sdk1', 'sdj1', 'sde1', 'sdl1', 'sdg1', 'sdf1', 'sdh1', 'sdc1',
         'sdd1', 'sdi1'
     ])
     self.assertEqual(mdstat_test.config('md3'), 'UUUUUUUUUU')
示例#9
0
 def test_099_didnotexist(self):
     try:
         mdstat_test = MdStat('/proc/NOmdstat')
     except IOError:
         self.assertTrue(True)
     else:
         self.assertFalse(True)
示例#10
0
 def test_009(self):
     i = 9
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'], [
         'linear', 'multipath', 'raid0', 'raid1', 'raid6', 'raid5', 'raid4',
         'raid10'
     ])
     self.assertEqual(
         mdstat_test.get_stats()['arrays'], {
             'md2': {
                 'status': 'inactive',
                 'available': None,
                 'used': None,
                 'components': {
                     'sdb': '0'
                 },
                 'config': None,
                 'type': None
             },
             'md0': {
                 'status': 'active',
                 'available': '2',
                 'used': '2',
                 'components': {
                     'sde1': '0',
                     'sdf1': '1'
                 },
                 'config': 'UU',
                 'type': 'raid1'
             },
             'md1': {
                 'status': 'active',
                 'available': '2',
                 'used': '2',
                 'components': {
                     'sde2': '0',
                     'sdf2': '1'
                 },
                 'config': 'UU',
                 'type': 'raid1'
             }
         })
示例#11
0
    def update(self):
        """Update RAID stats using the input method."""
        # Reset stats
        self.reset()

        if self.input_method == 'local':
            # Update stats using the PyMDstat lib (https://github.com/nicolargo/pymdstat)
            try:
                mds = MdStat()
                self.stats = mds.get_stats()['arrays']
            except Exception as e:
                logger.debug("Can not grab RAID stats (%s)" % e)
                return self.stats

        elif self.input_method == 'snmp':
            # Update stats using SNMP
            # No standard way for the moment...
            pass

        return self.stats
示例#12
0
    def update(self):
        """Update RAID stats using the input method."""
        # Reset stats
        self.reset()

        if self.input_method == 'local':
            # Update stats using the PyMDstat lib (https://github.com/nicolargo/pymdstat)
            try:
                mds = MdStat()
                self.stats = mds.get_stats()['arrays']
            except Exception as e:
                logger.debug("Can not grab RAID stats (%s)" % e)
                return self.stats

        elif self.input_method == 'snmp':
            # Update stats using SNMP
            # No standard way for the moment...
            pass

        return self.stats
示例#13
0
def check_md_arrays() -> dict:
    """Check state of md arrays.

    Returns:
        dict: State of md arrays

    """
    md_status = {}

    mds = MdStat()
    md_arrays = mds.arrays()
    for md in md_arrays:
        if mds.type(md) == 'raid1':  # we only work with raid1
            # /sys/block/md126/md/array_state
            path_to_md_status = f'/sys/block/{md}/md/array_state'
            with open(path_to_md_status, 'r') as file_handler:
                status = file_handler.readline()
                status = status.strip()
            md_status[md] = status
    return md_status
示例#14
0
 def test_008(self):
     i = 8
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'],
                           ['raid5'])
     self.assertEqual(
         mdstat_test.get_stats()['arrays'], {
             'md0': {
                 'status': 'inactive',
                 'available': '4',
                 'used': '4',
                 'components': {
                     'sdd1': '3',
                     'sdc1': '2',
                     'sda1': '0'
                 },
                 'config': 'UUUU',
                 'type': 'raid5'
             }
         })
示例#15
0
 def test_007(self):
     i = 7
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'],
                           ['raid1'])
     self.assertEqual(
         mdstat_test.get_stats()['arrays'], {
             'md1': {
                 'status': 'active',
                 'available': '6',
                 'used': '4',
                 'components': {
                     'sdc1': '2',
                     'sdb1': '4',
                     'sde1': '6',
                     'sdd1': '3',
                     'sdg1': '1'
                 },
                 'config': '_UUUU_',
                 'type': 'raid1'
             }
         })
示例#16
0
 def test_004(self):
     i = 4
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'], ['raid1', 'raid6', 'raid5', 'raid4'])
     self.assertEqual(mdstat_test.get_stats()['arrays'], {'md2': {'status': 'active', 'available': '2', 'used': '2', 'components': {'sdb3': '1', 'sda3': '0'}, 'config': 'UU', 'type': 'raid1'}, 'md3': {'status': 'active', 'available': '10', 'used': '10', 'components': {'sdk1': '8', 'sdj1': '7', 'sde1': '2', 'sdl1': '9', 'sdg1': '4', 'sdf1': '3', 'sdh1': '5', 'sdc1': '0', 'sdd1': '1', 'sdi1': '6'}, 'config': 'UUUUUUUUUU', 'type': 'raid5'}, 'md0': {'status': 'active', 'available': '2', 'used': '2', 'components': {'sdb1': '1', 'sda1': '0'}, 'config': 'UU', 'type': 'raid1'}, 'md1': {'status': 'active', 'available': '2', 'used': '2', 'components': {'sdb2': '1', 'sda2': '0'}, 'config': 'UU', 'type': 'raid1'}})
示例#17
0
 def test_010(self):
     i = 10
     mdstat_test = MdStat('./tests/mdstat.%s' % i)
示例#18
0
 def test_001(self):
     i = 1
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertEqual(mdstat_test.get_stats()['personalities'], [])
     self.assertEqual(mdstat_test.get_stats()['arrays'], {})
示例#19
0
 def test_000_loadall(self):
     for i in range(1, 10):
         mdstat_test = MdStat('./tests/mdstat.0%s' % i)
         # print('%s' % mdstat_test.get_stats())
         self.assertNotEqual(mdstat_test.get_stats(), {})
示例#20
0
def collectMdstat(configobj):
    if(os.path.isfile("/proc/mdstat")):
        mds = MdStat()
        return mds.get_stats()
    else:
        return False
示例#21
0
 def test_001(self):
     i = 1
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertEqual(mdstat_test.get_stats()['personalities'], [])
     self.assertEqual(mdstat_test.get_stats()['arrays'], {})
示例#22
0
 def test_006(self):
     i = 6
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'], ['linear', 'raid0', 'raid1', 'raid5', 'raid4', 'raid6'])
     self.assertEqual(mdstat_test.get_stats()['arrays'], {'md0': {'status': 'active', 'available': '7', 'used': '7', 'components': {'sde1': '1', 'sdf1': '0', 'sdc1': '3', 'sdb1': '4', 'hdb1': '6', 'sdd1': '2', 'sda1': '5'}, 'config': 'UUUUUUU', 'type': 'raid6'}})
示例#23
0
 def test_008(self):
     i = 8
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'], ['raid5'])
     self.assertEqual(mdstat_test.get_stats()['arrays'], {'md0': {'status': 'inactive', 'available': '4', 'used': '4', 'components': {'sdd1': '3', 'sdc1': '2', 'sda1': '0'}, 'config': 'UUUU', 'type': 'raid5'}})
示例#24
0
 def test_007(self):
     i = 7
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'], ['raid1'])
     self.assertEqual(mdstat_test.get_stats()['arrays'], {'md1': {'status': 'active', 'available': '6', 'used': '4', 'components': {'sdc1': '2', 'sdb1': '4', 'sde1': '6', 'sdd1': '3', 'sdg1': '1'}, 'config': '_UUUU_', 'type': 'raid1'}})
示例#25
0
 def test_000_loadall(self):
     for i in range(1, 10):
         mdstat_test = MdStat('./tests/mdstat.0%s' % i)
         # print('%s' % mdstat_test.get_stats())
         self.assertNotEqual(mdstat_test.get_stats(), {})
示例#26
0
 def test_009(self):
     i = 9
     mdstat_test = MdStat('./tests/mdstat.0%s' % i)
     self.assertCountEqual(mdstat_test.get_stats()['personalities'], ['linear', 'multipath', 'raid0', 'raid1', 'raid6', 'raid5', 'raid4', 'raid10'])
     self.assertEqual(mdstat_test.get_stats()['arrays'], {'md2': {'status': 'inactive', 'available': None, 'used': None, 'components': {'sdb': '0'}, 'config': None, 'type': None}, 'md0': {'status': 'active', 'available': '2', 'used': '2', 'components': {'sde1': '0', 'sdf1': '1'}, 'config': 'UU', 'type': 'raid1'}, 'md1': {'status': 'active', 'available': '2', 'used': '2', 'components': {'sde2': '0', 'sdf2': '1'}, 'config': 'UU', 'type': 'raid1'}})
示例#27
0
def collectMdstat(configobj):
    if (os.path.isfile("/proc/mdstat")):
        mds = MdStat()
        return mds.get_stats()
    else:
        return False