Example #1
0
 def test_lookup_withdevices_in_ignorelist(self, mock_parse_ignore_output,
                                           mock_run_command, mock_wok_log,
                                           mock_task_model):
     """
     unit test to validate lookuo() when devices in ignore list
     (_parse_ignore_out returns list of devices)
     mock_run_command: mock of wok.utils.run_command imported
                       in model.cioignore
     mock_wok_log: mock of wok_log of model.cioignore
     mock_parse_ignore_output: mock of _parse_ignore_output()
                               model.cioignore
     mock_task_model: mock of wok.model.tasks imported as TaskModel
                     in model.cioignore
     """
     command = [CIO_IGNORE, '-l']
     mock_run_command.return_value = ['dummy_out', '', 0]
     mock_parse_ignore_output.return_value = ['dev1', '2-20', 3]
     expected_out = {'ignored_devices': ['dev1', '2-20', 3]}
     ciomodel = CIOIgnoreModel()
     actual_out = ciomodel.lookup(None)
     self.assertEqual(actual_out, expected_out)
     mock_run_command.assert_called_once_with(command)
     mock_parse_ignore_output.assert_called_once_with('dummy_out')
     self.assertTrue(mock_wok_log.info.called,
                     msg='Expected call to mock_wok_log.info().'
                     ' Not Called')
 def test_lookup_withdevices_in_ignorelist(self, mock_parse_ignore_output,
                                           mock_run_command, mock_wok_log,
                                           mock_task_model):
     """
     unit test to validate lookuo() when devices in ignore list
     (_parse_ignore_out returns list of devices)
     mock_run_command: mock of wok.utils.run_command imported
                       in model.cioignore
     mock_wok_log: mock of wok_log of model.cioignore
     mock_parse_ignore_output: mock of _parse_ignore_output()
                               model.cioignore
     mock_task_model: mock of wok.model.tasks imported as TaskModel
                     in model.cioignore
     """
     command = [CIO_IGNORE, '-l']
     mock_run_command.return_value = ['dummy_out', '', 0]
     mock_parse_ignore_output.return_value = ['dev1', '2-20', 3]
     expected_out = {'ignored_devices': ['dev1', '2-20', 3]}
     ciomodel = CIOIgnoreModel()
     actual_out = ciomodel.lookup(None)
     self.assertEqual(actual_out, expected_out)
     mock_run_command.assert_called_once_with(command)
     mock_parse_ignore_output.assert_called_once_with('dummy_out')
     self.assertTrue(mock_wok_log.info.called,
                     msg='Expected call to mock_wok_log.info().'
                         ' Not Called')
Example #3
0
    def test_lookup_command_fails(self, mock_parse_ignore_output,
                                  mock_run_command, mock_wok_log,
                                  mock_task_model):
        """
        unit test to validate lookup() when run_command() fails
        (_parse_ignore_out returns list of devices)
        mock_run_command: mock of wok.utils.run_command imported
                          in model.cioignore
        mock_wok_log: mock of wok_log of model.cioignore
        mock_parse_ignore_output: mock of _parse_ignore_output()
                                  model.cioignore
        mock_task_model: mock of wok.model.tasks imported as TaskModel
                        in model.cioignore

        lookup() should raise OperationFailed Exception
        """
        command = [CIO_IGNORE, '-l']
        mock_run_command.return_value = ['', 'dummy_error', 1]
        ciomodel = CIOIgnoreModel()
        self.assertRaises(exception.OperationFailed, ciomodel.lookup, None)
        mock_run_command.assert_called_once_with(command)
        self.assertFalse(mock_parse_ignore_output.called,
                         msg='Unexpected call to mock_parse_ignore_output()')
        mock_wok_log.error.assert_called_once_with('failed to retrieve ignore'
                                                   ' list using \'cio_ignore '
                                                   '-l\'. Error: dummy_error')
Example #4
0
 def test_model_remove_listin(self, mock_task_model, mock_add_task, mock_wok_log):
     """
     unit test to validate remove() action with success scenario
     mock_task_model: mock of wok.model.tasks imported as TaskModel
                     in model.cioignore
     mock_add_task: mock of model.utils.add_task() imported
                    in model.cioignore
     mock_wok_log: mock of wok_log of model.cioignore
     """
     device = ["devce1"]
     taskid = 1
     mock_add_task.return_value = taskid
     mock_task_model.lookup.return_value = "test_task"
     cio_model = CIOIgnoreModel(kargs=None)
     cio_model.remove("", device)
     self.assertTrue(mock_add_task.called, msg="Expected call to mock_add_task(). Not Called")
     self.assertTrue(mock_wok_log.info.called, msg="Expected call to " "mock_wok_log.info(). Not called")
 def test_model_remove_listin(self, mock_task_model, mock_AsyncTask,
                              mock_wok_log):
     """
     unit test to validate remove() action with success scenario
     mock_task_model: mock of wok.model.tasks imported as TaskModel
                     in model.cioignore
     mock_AsyncTask: mock of wok.asynctask.AsyncTask() imported
     mock_wok_log: mock of wok_log of model.cioignore
     """
     device = ['devce1', 'dé']
     mock_AsyncTask.return_value = FakeAsyncTaskObj()
     mock_task_model.lookup.return_value = "test_task"
     cio_model = CIOIgnoreModel(kargs=None)
     cio_model.remove('', device)
     self.assertTrue(mock_AsyncTask.called,
                     msg='Expected call to mock_AsyncTask(). Not Called')
     self.assertTrue(mock_wok_log.info.called, msg='Expected call to '
                     'mock_wok_log.info(). Not called')
Example #6
0
 def test_model_remove_listin(self, mock_task_model, mock_AsyncTask,
                              mock_wok_log):
     """
     unit test to validate remove() action with success scenario
     mock_task_model: mock of wok.model.tasks imported as TaskModel
                     in model.cioignore
     mock_AsyncTask: mock of wok.asynctask.AsyncTask() imported
     mock_wok_log: mock of wok_log of model.cioignore
     """
     device = ['devce1', 'dé']
     mock_AsyncTask.return_value = FakeAsyncTaskObj()
     mock_task_model.lookup.return_value = "test_task"
     cio_model = CIOIgnoreModel(kargs=None)
     cio_model.remove('', device)
     self.assertTrue(mock_AsyncTask.called,
                     msg='Expected call to mock_AsyncTask(). Not Called')
     self.assertTrue(mock_wok_log.info.called,
                     msg='Expected call to '
                     'mock_wok_log.info(). Not called')
Example #7
0
 def test_lookup_nodevice_in_ignorelist(
     self, mock_parse_ignore_output, mock_run_command, mock_wok_log, mock_task_model
 ):
     """
     unit test to validate lookuo() when there is no device in ignore list
     (ie, run_command succeeds and _parse_ignore_out returns empty list)
     mock_run_command: mock of wok.utils.run_command imported
                       in model.cioignore
     mock_wok_log: mock of wok_log of model.cioignore
     mock_parse_ignore_output: mock of _parse_ignore_output()
                               model.cioignore
     mock_task_model: mock of wok.model.tasks imported as TaskModel
                     in model.cioignore
     """
     command = [CIO_IGNORE, "-l"]
     mock_run_command.return_value = ["dummy_out", "", 0]
     mock_parse_ignore_output.return_value = []
     expected_out = {"ignored_devices": []}
     ciomodel = CIOIgnoreModel()
     actual_out = ciomodel.lookup(None)
     self.assertEqual(actual_out, expected_out)
     mock_run_command.assert_called_once_with(command)
     mock_parse_ignore_output.assert_called_once_with("dummy_out")
     self.assertTrue(mock_wok_log.info.called, msg="Expected call to mock_wok_log.info()." " Not Called")
Example #8
0
    def test_model_remove_input_notlist(self, mock_task_model, mock_AsyncTask,
                                        mock_wok_log):
        """
        unit test to validate remove() action with input which is not list
        mock_task_model: mock of wok.model.tasks imported as TaskModel
                        in model.cioignore
        mock_add_task: mock of model.utils.add_task() imported
                       in model.cioignore
        mock_wok_log: mock of wok_log of model.cioignore

        remove() action should raise InvalidParameter Exception
        """
        device = 'deviceé1'
        taskid = 1
        mock_AsyncTask.return_value = taskid
        mock_task_model.lookup.return_value = "test_task"
        cio_model = CIOIgnoreModel(kargs=None)
        self.assertRaises(exception.InvalidParameter, cio_model.remove, '',
                          device)
        self.assertFalse(mock_AsyncTask.called,
                         msg='Unexpected call to mock_AsyncTask()')
        mock_wok_log.error.assert_called_once_with('Input is not of type '
                                                   'list. Input: %s' % device)