Пример #1
0
    def test_remove_user(self, mock_execute_cmd):

        result = mock.Mock(returncode=0)
        mock_execute_cmd.return_value = result

        shell.remove_user('user', False, 'root', 'pass', 'remote_host')

        mock_execute_cmd.assert_called_once_with('userdel user', 'root',
                                                 'pass', 'remote_host')
Пример #2
0
    def test_remove_user_error(self, mock_execute_cmd):

        result = mock.Mock(returncode=1)
        mock_execute_cmd.return_value = result

        with self.assertRaises(shell.ShellError) as err:
            shell.remove_user('user', False, 'root', 'pass')

        mock_execute_cmd.assert_called_once_with('userdel user', 'root',
                                                 'pass', None)
        self.assertTrue('error removing user user' in str(err.exception))
Пример #3
0
    def uninstall(self, software_path, virtual_host, conf_file, root_user, password, **kwargs):
        """
        Uninstall SAP Netweaver instance

        Args:
            software_path (str): Path where SAP Netweaver 'sapinst' tool is located
            virtual_host (str): Virtual host name of the machine
            conf_file (str): Path to the configuration file
            root_user (str): Root user name
            password (str): Root user password
            remote_host (str, opt): Remote host where the command will be executed
        """
        remote_host = kwargs.get('remote_host', None)
        user = self.NETWEAVER_USER.format(sid=self.sid)
        self.install(
            software_path, virtual_host, self.UNINSTALL_PRODUCT, conf_file, root_user, password,
            remote_host=remote_host)
        shell.remove_user(user, True, root_user, password, remote_host)
Пример #4
0
    def test_remove_user_force_error(self, mock_execute_cmd):

        result1 = mock.Mock(
            returncode=1,
            err='userdel: user user is currently used by process 1')
        result2 = mock.Mock(returncode=1, err='other error')
        result3 = mock.Mock(returncode=0)
        mock_execute_cmd.side_effect = [result1, None, result2, None, result3]

        with self.assertRaises(shell.ShellError) as err:
            shell.remove_user('user', True, 'root', 'pass')

        mock_execute_cmd.assert_has_calls([
            mock.call('userdel user', 'root', 'pass', None),
            mock.call('kill -9 1', 'root', 'pass', None),
            mock.call('userdel user', 'root', 'pass', None)
        ])
        self.assertTrue('error removing user user' in str(err.exception))
Пример #5
0
    def test_remove_user_force(self, mock_execute_cmd):

        result1 = mock.Mock(
            returncode=1,
            err='userdel: user user is currently used by process 1')
        result2 = mock.Mock(
            returncode=1,
            err='userdel: user user is currently used by process 2')
        result3 = mock.Mock(returncode=0)
        mock_execute_cmd.side_effect = [result1, None, result2, None, result3]

        shell.remove_user('user', True, 'root', 'pass')

        mock_execute_cmd.assert_has_calls([
            mock.call('userdel user', 'root', 'pass', None),
            mock.call('kill -9 1', 'root', 'pass', None),
            mock.call('userdel user', 'root', 'pass', None),
            mock.call('kill -9 2', 'root', 'pass', None),
            mock.call('userdel user', 'root', 'pass', None),
        ])