Beispiel #1
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')
Beispiel #2
0
    def test_cpu(self):
        """
        Test cpu returns correct name
        """
        hw = HardwareCheck(name='hw', data=self.valid_data)
        client = MagicMock()
        client.info.cpu = MagicMock(return_value=[{
            'modelName': 'model name cpu'
        }])
        cpu = hw._cpu(client)

        assert cpu == 'cpu'
Beispiel #3
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.')