Exemple #1
0
    def test_action_create_fail(self, popen_mock, getgrnam_mock):
        subproc_mock = MagicMock()
        subproc_mock.returncode = 1
        subproc_mock.stdout = subproc_stdout
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = _get_group()

        try:
            with Environment('/') as env:
                Group('mapred', action='create', gid=2, password='******')

            self.fail("Action 'create' should fail when checked_call fails")
        except Fail:
            pass
        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with([
            '/bin/bash', '--login', '--noprofile', '-c',
            "ambari-sudo.sh  PATH=/bin -H -E groupmod -p secure -g 2 mapred"
        ],
                                      shell=False,
                                      preexec_fn=None,
                                      stderr=-2,
                                      stdout=-1,
                                      env={'PATH': '/bin'},
                                      cwd=None,
                                      close_fds=True)
        getgrnam_mock.assert_called_with('mapred')
Exemple #2
0
    def test_action_remove_fail(self, popen_mock, getgrnam_mock):

        subproc_mock = MagicMock()
        subproc_mock.returncode = 1
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = "mapred"

        try:
            with Environment('/') as env:
                Group('mapred', action='remove')
            env.run()
            self.fail("Action 'delete' should fail when checked_call fails")
        except Fail:
            pass

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with(
            ['/bin/bash', '--login', '-c', 'groupdel mapred'],
            shell=False,
            preexec_fn=None,
            stderr=-2,
            stdout=-1,
            env=None,
            cwd=None)
        getgrnam_mock.assert_called_with('mapred')
Exemple #3
0
    def test_action_remove_fail(self, popen_mock, getgrnam_mock):

        subproc_mock = MagicMock()
        subproc_mock.returncode = 1
        subproc_mock.stdout.readline = MagicMock(side_effect=['OK'])
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = _get_group()

        try:
            with Environment('/') as env:
                Group('mapred', action='remove')

            self.fail("Action 'delete' should fail when checked_call fails")
        except Fail:
            pass

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with([
            '/bin/bash', '--login', '--noprofile', '-c',
            'ambari-sudo.sh  PATH=/bin -H -E groupdel mapred'
        ],
                                      shell=False,
                                      preexec_fn=None,
                                      stderr=-2,
                                      stdout=5,
                                      bufsize=1,
                                      env={'PATH': '/bin'},
                                      cwd=None,
                                      close_fds=True)
        getgrnam_mock.assert_called_with('mapred')
Exemple #4
0
    def test_action_create_existent(self, popen_mock, getgrnam_mock):
        subproc_mock = MagicMock()
        subproc_mock.returncode = 0
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = "mapred"

        with Environment('/') as env:
            Group('mapred', action='create', gid=2, password='******')

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with(
            ['/bin/bash', '--login', '-c', 'groupmod -p secure -g 2 mapred'],
            shell=False,
            preexec_fn=None,
            stderr=-2,
            stdout=-1,
            env=None,
            cwd=None)
        getgrnam_mock.assert_called_with('mapred')
Exemple #5
0
    def test_action_create_nonexistent(self, popen_mock, getgrnam_mock):
        subproc_mock = MagicMock()
        subproc_mock.returncode = 0
        popen_mock.return_value = subproc_mock
        getgrnam_mock.side_effect = KeyError()

        with Environment('/') as env:
            Group('hadoop', action='create', password='******')

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with(
            ['/bin/bash', '--login', '-c', 'groupadd -p secure hadoop'],
            shell=False,
            preexec_fn=None,
            stderr=-2,
            stdout=-1,
            env=None,
            cwd=None)
        getgrnam_mock.assert_called_with('hadoop')
Exemple #6
0
    def test_action_remove(self, popen_mock, getgrnam_mock):

        subproc_mock = MagicMock()
        subproc_mock.returncode = 0
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = "mapred"

        with Environment('/') as env:
            Group('mapred', action='remove')

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with(
            ['/bin/bash', '--login', '-c', 'groupdel mapred'],
            shell=False,
            preexec_fn=None,
            stderr=-2,
            stdout=-1,
            env=None,
            cwd=None)
        getgrnam_mock.assert_called_with('mapred')
    def test_action_create_nonexistent(self, popen_mock, getgrnam_mock):
        subproc_mock = MagicMock()
        subproc_mock.returncode = 0
        subproc_mock.stdout = subproc_stdout
        popen_mock.return_value = subproc_mock
        getgrnam_mock.side_effect = KeyError()

        with Environment('/') as env:
            Group('hadoop', action='create', password='******')

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with([
            '/bin/bash', '--login', '--noprofile', '-c',
            "ambari-sudo.sh  PATH=/bin -H -E groupadd -p secure hadoop"
        ],
                                      shell=False,
                                      preexec_fn=preexec_fn,
                                      stderr=-2,
                                      stdout=-1,
                                      env={'PATH': '/bin'},
                                      cwd=None,
                                      close_fds=True)
        getgrnam_mock.assert_called_with('hadoop')
Exemple #8
0
    def test_action_remove(self, popen_mock, getgrnam_mock):

        subproc_mock = MagicMock()
        subproc_mock.returncode = 0
        subproc_mock.stdout.readline = MagicMock(side_effect=['OK'])
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = "mapred"

        with Environment('/') as env:
            Group('mapred', action='remove')

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with(
            ['/bin/bash', '--login', '--noprofile', '-c', 'groupdel mapred'],
            shell=False,
            preexec_fn=None,
            stderr=-2,
            stdout=5,
            bufsize=1,
            env={'PATH': '/bin'},
            cwd=None,
            close_fds=True)
        getgrnam_mock.assert_called_with('mapred')
Exemple #9
0
    def test_action_remove(self, popen_mock, getgrnam_mock):

        subproc_mock = MagicMock()
        subproc_mock.returncode = 0
        subproc_mock.stdout = subproc_stdout
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = _get_group()

        with Environment('/') as env:
            Group('mapred', action='remove')

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with([
            '/bin/bash', '--login', '--noprofile', '-c',
            'ambari-sudo.sh  PATH=/bin -H -E groupdel mapred'
        ],
                                      shell=False,
                                      preexec_fn=None,
                                      stderr=-2,
                                      stdout=-1,
                                      env={'PATH': '/bin'},
                                      cwd=None,
                                      close_fds=True)
        getgrnam_mock.assert_called_with('mapred')
Exemple #10
0
    def test_action_create_existent(self, popen_mock, getgrnam_mock):
        subproc_mock = MagicMock()
        subproc_mock.returncode = 0
        subproc_mock.stdout.readline = MagicMock(side_effect=['OK'])
        popen_mock.return_value = subproc_mock
        getgrnam_mock.return_value = _get_group()

        with Environment('/') as env:
            Group('mapred', action='create', gid=2, password='******')

        self.assertEqual(popen_mock.call_count, 1)
        popen_mock.assert_called_with([
            '/bin/bash', '--login', '--noprofile', '-c',
            "ambari-sudo.sh  PATH=/bin -H -E groupmod -p secure -g 2 mapred"
        ],
                                      shell=False,
                                      preexec_fn=None,
                                      stderr=-2,
                                      stdout=5,
                                      bufsize=1,
                                      env={'PATH': '/bin'},
                                      cwd=None,
                                      close_fds=True)
        getgrnam_mock.assert_called_with('mapred')