Example #1
0
    def test_swap_output_returns_404_when_device_not_found(
            self, mock_run_command):
        mock_run_command.return_value = ["", "", 1]

        with self.assertRaises(NotFoundError):
            utils._get_swap_output('fake_device_name')
            cmd = ['grep', '-w', 'fake_device_name', '/proc/swaps']
            mock_run_command.assert_called_once_with(cmd)
Example #2
0
    def test_swap_output_returns_404_when_device_not_found(self,
                                                           mock_run_command):
        mock_run_command.return_value = ["", "", 1]

        with self.assertRaises(NotFoundError):
            utils._get_swap_output('fake_device_name')
            cmd = ['grep', '-w', 'fake_device_name', '/proc/swaps']
            mock_run_command.assert_called_once_with(cmd)
Example #3
0
    def test_swap_output_returns_500_when_unknown_error_occurs(
            self, mock_run_command):

        mock_run_command.return_value = ["", "", 9]

        expected_error_msg = "GINSP00015E"
        with self.assertRaisesRegexp(OperationFailed, expected_error_msg):
            utils._get_swap_output('fake_device_name')
            cmd = ['grep', '-w', 'fake_device_name', '/proc/swaps']
            mock_run_command.assert_called_once_with(cmd)
Example #4
0
    def test_swap_output_returns_500_when_system_dir_not_found(
            self, mock_run_command):

        mock_run_command.return_value = ["", "", 2]

        expected_error_msg = "GINSP00019E"
        with self.assertRaisesRegexp(OperationFailed, expected_error_msg):
            utils._get_swap_output('valid_device_name')
            cmd = ['grep', '-w', 'valid_device_name', '/proc/swaps']
            mock_run_command.assert_called_once_with(cmd)
Example #5
0
    def test_swap_output_returns_500_when_unknown_error_occurs(
            self, mock_run_command):

        mock_run_command.return_value = ["", "", 9]

        expected_error_msg = "GINSP00015E"
        with self.assertRaisesRegexp(OperationFailed, expected_error_msg):
            utils._get_swap_output('fake_device_name')
            cmd = ['grep', '-w', 'fake_device_name', '/proc/swaps']
            mock_run_command.assert_called_once_with(cmd)
Example #6
0
    def test_swap_output_returns_500_when_system_dir_not_found(
            self, mock_run_command):

        mock_run_command.return_value = ["", "", 2]

        expected_error_msg = "GINSP00019E"
        with self.assertRaisesRegexp(OperationFailed, expected_error_msg):
            utils._get_swap_output('valid_device_name')
            cmd = ['grep', '-w', 'valid_device_name', '/proc/swaps']
            mock_run_command.assert_called_once_with(cmd)
Example #7
0
    def lookup(self, name):
        try:
            return utils._get_swap_output(device_name=name)

        except ValueError:
            raise NotFoundError("GINSP00008E", {'name': name})