示例#1
0
 def test_disk_exception(self):
     """
     Test disk throws exception when sector test fails
     """
     with pytest.raises(
             j.exceptions.RuntimeError,
             message='Template should raise error if stdout is not test\n'):
         hw = HardwareCheck(name='hw', data=self.valid_data)
         disks = {
             'blockdevices': [{
                 'tran': 'usb'
             }, {
                 'rota': '1',
                 'name': 'hdd',
                 'size': 16,
                 'phy-sec': 2,
             }, {
                 'rota': '0',
                 'name': 'ssd',
                 'size': 16,
                 'phy-sec': 2,
             }]
         }
         client = MagicMock()
         client.disk.list = MagicMock(return_value=disks)
         hw._disk(client)
示例#2
0
    def test_disk(self):
        """
        test disk returns correct count
        """
        hw = HardwareCheck(name='hw', data=self.valid_data)
        disks = {
            'blockdevices': [{
                'tran': 'usb'
            }, {
                'rota': '1',
                'name': 'hdd',
                'size': 16,
                'phy-sec': 2,
            }, {
                'rota': '0',
                'name': 'ssd',
                'size': 16,
                'phy-sec': 2,
            }]
        }
        client = MagicMock()
        system_get_result = MagicMock(stdout='test\n')
        system = MagicMock()
        system.get = MagicMock(return_value=system_get_result)
        client.system = MagicMock(return_value=system)
        client.disk.list = MagicMock(return_value=disks)
        hdd, ssd = hw._disk(client)

        assert hdd == 1
        assert ssd == 1
示例#3
0
    def test_check_fail(self):
        """
        Test that check fails if any of hardware specs arent supported
        """
        patch('js9.j.clients.zos.get', MagicMock()).start()
        hw = HardwareCheck(name='hw', data=self.valid_data)
        supported = self.valid_data['supported'][0]
        hw._disk = MagicMock(return_value=(supported['hddCount'],
                                           supported['ssdCount']))
        hw._cpu = MagicMock(return_value=supported['cpu'])
        client = MagicMock()
        hw._get_bot_client = MagicMock(return_value=client)

        # check with no supported ram
        hw._ram = MagicMock(return_value=supported['ram'] - 6)
        with pytest.raises(
                j.exceptions.RuntimeError,
                message='Template should raise error if ram is not supported'):
            hw.check('node')
        hw._ram = MagicMock(return_value=supported['ram'])

        # check with no supported cpu
        hw._cpu = MagicMock(return_value='othercpu')
        with pytest.raises(
                j.exceptions.RuntimeError,
                message='Template should raise error if cpu is not supported'):
            hw.check('node')
        hw._cpu = MagicMock(return_value=supported['cpu'])

        # check with no supported hdd
        hw._disk = MagicMock(return_value=(0, supported['ssdCount']))
        with pytest.raises(
                j.exceptions.RuntimeError,
                message=
                'Template should raise error if hddCount is not supported'):
            hw.check('node')
        hw._disk = MagicMock(return_value=(supported['hddCount'],
                                           supported['ssdCount']))

        # check with no supported ssd
        hw._disk = MagicMock(return_value=(supported['hddCount'], 0))
        with pytest.raises(
                j.exceptions.RuntimeError,
                message=
                'Template should raise error if ssdCount is not supported'):
            hw.check('node')
示例#4
0
    def test_check_succussful(self):
        """
        Test check is successful when hardware is supported
        :return:
        """
        patch('js9.j.clients.zos.get', MagicMock()).start()
        hw = HardwareCheck(name='hw', data=self.valid_data)
        supported = self.valid_data['supported'][0]
        hw._disk = MagicMock(return_value=(supported['hddCount'],
                                           supported['ssdCount']))
        hw._ram = MagicMock(return_value=supported['ram'])
        hw._cpu = MagicMock(return_value=supported['cpu'])
        client = MagicMock()
        hw._get_bot_client = MagicMock(return_value=client)
        hw.check('node')

        client.send_message.assert_called_once_with(
            'chatId',
            'Node with id node has completed the hardwarecheck successfully.')