def test_run(self, mock_cli):
        mock_cli.run.return_value = CLIResult('', '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'
        s = storcli.Storcli()
        assert s.run('') == ''

        mock_cli.run.return_value = CLIResult('Error', '', 1)

        self.assertRaises(storcli.StorcliException, s.run, *('', ))
    def test_run_json(self, mock_cli):
        with open(os.path.join(os.path.dirname(__file__),
                               '../resources/storcli.json')) as fp:
            json_data = fp.read()

        mock_cli.run.return_value = CLIResult(json_data, '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'
        s = storcli.Storcli()
        assert isinstance(s.run_json('/call show all'), dict)

        mock_cli.run.return_value = CLIResult('not_valid_json', '', 0)

        self.assertRaises(storcli.StorcliException, s.run_json, *('', ))
示例#3
0
    def test_get_system_memory(self, mock_cli, mock_os):
        s = Stress()

        mock_cli.run = mock.Mock(return_value=CLIResult(
            'MemFree:          33554432 kB', '', 0))

        self.assertEqual(s.get_system_memory(), '32G')
示例#4
0
    def test_show_dimmm(self):
        self.mock_cli.run = mock.Mock(return_value=CLIResult(
            self.show_dimm_data, '', 0))
        hpasm = hpasmcli.HPASMCLI()
        details = hpasm.show_dimm()

        self.assertEqual(details[-1]['processor_#'], 2)
    def test_add(self, mock_cli):
        mock_cli.run.return_value = CLIResult('', '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'

        s = storcli.Storcli()
        assert s.add(0, 'r0', '32:0-1') == ''
        assert s.add(0, 'r10', '32:0-3', pdperarray=2) == ''

        self.assertRaises(storcli.StorcliException, s.add, *(0, 'r10', '32:0-3'))

        with open(os.path.join(os.path.dirname(__file__), '../resources/storcli_err.txt')) as fp:
            error_data = fp.read()

        mock_cli.run.return_value = CLIResult(error_data, '', 0)

        self.assertRaises(storcli.StorcliException, s.add, *(0, '', ''))
    def test_controllers(self, mock_cli):
        with open(os.path.join(os.path.dirname(__file__),
                               '../resources/storcli.json')) as fp:
            json_data = fp.read()

        mock_cli.run.return_value = CLIResult(json_data, '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'
        s = storcli.Storcli()
        assert isinstance(s.controllers, list)

        mock_cli.run.return_value = CLIResult('{}', '', 0)

        def _wrapper():
            return s.controllers

        self.assertRaises(storcli.StorcliException, _wrapper)
示例#7
0
    def test_show_power_supply(self):
        self.mock_cli.run = mock.Mock(return_value=CLIResult(
            self.show_power_supply_data, '', 0))

        hpasm = hpasmcli.HPASMCLI()
        power_supplies = hpasm.show_powersupply()
        for ps in power_supplies:
            self.assertEqual(ps['condition'], 'Ok')
示例#8
0
    def test_show_server(self):
        self.mock_cli.run = mock.Mock(return_value=CLIResult(
            self.show_server_data, '', 0))

        hpasm = hpasmcli.HPASMCLI()
        details = hpasm.show_server()

        self.assertEqual(len(details['processors']), 2)
        self.assertEqual(details['system'], 'ProLiant DL380 Gen9')
示例#9
0
    def test_inspect(self, mock_cli, mock_get_configuration):
        driver = MegaRaidSASDriver(['02:00.0'])
        driver.handler = mock.Mock()
        driver.handler.get_adapter_info = mock.Mock()

        mock_cli.run.return_value = CLIResult('', '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'
        mock_get_configuration.return_value = {}

        driver.inspect()

        driver.handler.get_adapter_info.assert_called_with(0)
示例#10
0
    def test_real_init(self, mock_get_configuration, mock_cli):
        """ Tests real class __init__ method

        :param mock_get_configuration:
        :param mock_cli:
        :return:
        """
        mock_cli.run.return_value = CLIResult('', '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'
        mock_get_configuration.return_value = {}

        assert MegaRAIDActions()
示例#11
0
    def test_add_hotspare(self, mock_cli):
        mock_cli.run.return_value = CLIResult('', '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'

        s = storcli.Storcli()
        s.run = mock.Mock()

        s.add_hotspare(0, 32, 10)

        s.run.assert_called_with('/c0/e32/s10 add hotsparedrive')

        s.add_hotspare(0, 32, 10, [0, 1, 2])

        s.run.assert_called_with('/c0/e32/s10 add hotsparedrive DGs=0,1,2')
示例#12
0
    def test_get_enclosures(self, mock_cli):
        mock_cli.run.return_value = CLIResult('', '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'

        s = storcli.Storcli()
        s.run_json = mock.Mock()
        s.run_json.return_value = {
            'Controllers': [{
                'Response Data': 'cheese'
            }]
        }

        self.assertEqual(s.get_enclosures(), ['cheese'])

        s.run_json.assert_called_with('/call/eall show all')

        s.get_enclosures(99)
        s.run_json.assert_called_with('/c99/eall show all')

        s.run_json.return_value = {}

        self.assertRaises(storcli.StorcliException, s.get_enclosures)
示例#13
0
    def test_get_disk_group(self, mock_cli):
        mock_cli.run.return_value = CLIResult('', '', 0)
        mock_cli.find_in_path.return_value = '/sbin/storcli64'

        s = storcli.Storcli()
        s.run_json = mock.Mock()
        s.run_json.return_value = {
            'Controllers': [{
                'Command Status': {
                    'Status': 'Success'
                },
                'Response Data': {
                    'Response Data': {}
                }
            }]
        }

        s.get_disk_group()

        s.run_json.assert_called_with('/call/dall show all')

        s.get_disk_group(99, 100)
        s.run_json.assert_called_with('/c99/d100 show all')
示例#14
0
    def test_kill_all(self, mock_os):
        Stress()
        mock_os.system()

        mock_os.system.assert_called_once_with()
        mock_os.return_value = CLIResult('', '', 0)
示例#15
0
 def test_delete(self, mock_cli):
     mock_cli.run.return_value = CLIResult('', '', 0)
     mock_cli.find_in_path.return_value = '/sbin/storcli64'
     s = storcli.Storcli()
     assert s.delete(0) == ''