Exemple #1
0
    def test_cvs_command_exclusive_access(self, mock_popen, mock_redis):
        options = {
            'cvs_repo_name': 'root',
            'cvs_root': ':gserver:[email protected]:/cvs/reporoot',
            'cvs_checkout_path': '/tmp/a/b/cc',
            'exclusive_access': True,
        }
        handle = 'program/product/release/release.tjp'

        cmd = 'update program/rhel'
        mock_communicate = mock.Mock()
        mock_communicate.communicate.return_value = ('stdo', 'stde')
        mock_popen.return_value = mock_communicate
        type(mock_communicate).returncode = mock.PropertyMock(return_value=0)

        mock_redis_inst = mock.Mock()
        mock_redis.return_value = mock_redis_inst

        mock_lock = mock.Mock()
        mock_redis_inst.lock.return_value = mock_lock

        reference = cvs_mod.StorageHandler_cvs(handle, options=options)
        assert reference._cvs_command(cmd, exclusive=True) == ('stdo', 'stde')
        mock_popen.assert_called()
        mock_lock.acquire.assert_called()
        mock_lock.release.assert_called()
Exemple #2
0
    def test_checkout_dir_by_opt_arg(self, mock_is_valid_cvs_dir,
                                     mock_wipe_out_dir, mock_shutil_move):
        options = {
            'cvs_repo_name': 'repo',
            'cvs_root': ':gserver:[email protected]:/cvs/reporoot',
            'cvs_checkout_path': '/tmp/a/b/cc'
        }
        handle = 'program/product/release/release.tjp'
        reference = cvs_mod.StorageHandler_cvs(handle, options=options)

        assert reference._cvs_checkout() == '/tmp/a/b/cc'
Exemple #3
0
 def test_cvs_command_exclusive_access_default_redis_config(
         self, mock_redis):
     options = {
         'cvs_repo_name': 'program',
         'cvs_root': ':gserver:[email protected]:/cvs/reporoot',
         'cvs_checkout_path': '/tmp/a/b/cc',
         'exclusive_access': True,
     }
     handle = 'program/product/release/release.tjp'
     reference = cvs_mod.StorageHandler_cvs(handle, options=options)
     mock_redis.assert_called_with()
Exemple #4
0
 def test_cvs_command_exclusive_access_incorrect_custom_redis_config(
         self, mock_redis):
     options = {
         'cvs_repo_name': 'repo',
         'cvs_root': ':gserver:[email protected]:/cvs/reporoot',
         'cvs_checkout_path': '/tmp/a/b/cc',
         'exclusive_access': True,
         'cvs_lock_redis_uri': 'http://redishost:1234/5'
     }
     handle = 'program/product/release/release.tjp'
     reference = cvs_mod.StorageHandler_cvs(handle, options=options)
     mock_redis.assert_called_with()
Exemple #5
0
    def test_checkout_dir_by_opt_arg_force(self, mock_is_valid_cvs_dir,
                                           mock_cvs_command, mock_mkdtemp,
                                           mock_wipe_out_dir,
                                           mock_shutil_move):
        options = {
            'cvs_repo_name': 'repo',
            'cvs_root': ':gserver:[email protected]:/cvs/reporoot',
            'cvs_checkout_path': '/tmp/somepath',
        }
        handle = 'program/product/release/release.tjp'
        reference = cvs_mod.StorageHandler_cvs(handle, options=options)

        mock_is_valid_cvs_dir.return_value = True
        mock_cvs_command.return_value = ('stdout', 'stderr')

        assert reference._cvs_checkout(force=True) == '/tmp/somepath'
        mock_mkdtemp.assert_called()
        mock_wipe_out_dir.assert_called()
        mock_shutil_move.assert_called()
        mock_cvs_command.assert_called()
Exemple #6
0
    def test_is_valid_cvs_dir_root_negative(self, mock_os):
        options = {
            'cvs_repo_name': 'program',
            'cvs_root': ':gserver:[email protected]:/cvs/reporoot'
        }
        path = 'program/product/release-1-2-3'

        reference = cvs_mod.StorageHandler_cvs(options=options)

        mock_fileopen = mock.mock_open(read_data=path)
        mock_cvs_repo = mock_fileopen
        cvs_root = ':gserver:[email protected]:/cvs/reporoot/abc/def/h'
        mock_cvs_root = mock.mock_open(read_data=cvs_root)
        mock_fileopen.side_effect = [
            mock_cvs_repo.return_value, mock_cvs_root.return_value
        ]

        mock_os.path.isdir.return_value = True
        with mock.patch('__builtin__.open', mock_fileopen):
            assert not reference._is_valid_cvs_dir(path)
Exemple #7
0
    def test_cvs_command_exclusive_access_unable_acquire(self, mock_redis):
        options = {
            'cvs_repo_name': 'repo',
            'cvs_root': ':gserver:[email protected]:/cvs/reporoot',
            'cvs_checkout_path': '/tmp/a/b/cc',
            'exclusive_access': True,
        }
        handle = 'program/product/release/release.tjp'

        cmd = 'update program/rhel'

        mock_redis_inst = mock.Mock()
        mock_redis.return_value = mock_redis_inst

        mock_acquire = mock.Mock(return_value=False)
        mock_lock = mock.Mock()
        mock_lock.acquire = mock_acquire
        mock_redis_inst.lock.return_value = mock_lock

        reference = cvs_mod.StorageHandler_cvs(handle, options=options)

        with pytest.raises(storage_handlers.AcquireLockException):
            reference._cvs_command(cmd, exclusive=True)