diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index e4fce82b..5d4ba447 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -6,36 +6,42 @@ jobs: fail-fast: false max-parallel: 1 matrix: - python_version: ['2.7', '3.4.10', '3.5', '3.6', '3.7', '3.8', '3.9'] + python_version: ['2.7', '3.4', '3.5', '3.6', '3.7', '3.8', '3.9'] runs-on: ubuntu-20.04 steps: - name: Checkout repo uses: actions/checkout@v2 with: ref: ${{ github.ref }} - - name: Setup python - if: ${{ matrix.python_version != '3.4.10' }} - uses: actions/setup-python@v2 + - name: Setup miniconda + uses: conda-incubator/setup-miniconda@v2 with: + auto-update-conda: true + channels: conda-forge python-version: ${{ matrix.python_version }} - architecture: x64 - - name: Setup python manually - if: ${{ matrix.python_version == '3.4.10' }} + activate-environment: qiniu-sdk + auto-activate-base: false + - name: Setup pip + shell: bash -l {0} env: - PYTHON_SOURCE_URL: https://www.python.org/ftp/python/${{ matrix.python_version }}/Python-${{ matrix.python_version }}.tgz + PYTHON_VERSION: ${{ matrix.python_version }} + PIP_BOOTSTRAP_SCRIPT_PREFIX: https://bootstrap.pypa.io/pip run: | - cd /tmp - curl -s -L "$PYTHON_SOURCE_URL" | tar -zxf - -C ./ - cd Python-${{ matrix.python_version }} - ./configure --enable-optimizations - make - sudo make install - echo 'export PATH="/opt/python/bin:$PATH"' >> $HOME/.bashrc + MAJOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f1) + MINOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f2) + # reinstall pip by some python(<3.7) not compatible + if ! [[ $MAJOR -ge 3 && $MINOR -ge 7 ]]; then + cd /tmp + wget -qLO get-pip.py "$PIP_BOOTSTRAP_SCRIPT_PREFIX/$MAJOR.$MINOR/get-pip.py" + python get-pip.py --user + fi - name: Install dependencies + shell: bash -l {0} run: | python -m pip install --upgrade pip - pip install "coverage<7.2" flake8 pytest pytest-cov freezegun requests scrutinizer-ocular codecov + python -m pip install --ignore-installed "coverage<7.2" flake8 pytest pytest-cov freezegun requests scrutinizer-ocular codecov - name: Run cases + shell: bash -l {0} env: QINIU_ACCESS_KEY: ${{ secrets.QINIU_ACCESS_KEY }} QINIU_SECRET_KEY: ${{ secrets.QINIU_SECRET_KEY }} diff --git a/qiniu/config.py b/qiniu/config.py index 6d72702f..cb2ac57c 100644 --- a/qiniu/config.py +++ b/qiniu/config.py @@ -5,6 +5,7 @@ RSF_HOST = 'http://rsf.qbox.me' # 列举操作Host API_HOST = 'http://api.qiniuapi.com' # 数据处理操作Host UC_HOST = region.UC_HOST # 获取空间信息Host +QUERY_REGION_HOST = 'https://kodo-config.qiniuapi.com' _BLOCK_SIZE = 1024 * 1024 * 4 # 断点续传分块大小,该参数为接口规格,暂不支持修改 @@ -14,11 +15,12 @@ 'default_rsf_host': RSF_HOST, 'default_api_host': API_HOST, 'default_uc_host': UC_HOST, - 'default_uc_backup_hosts': [ - 'kodo-config.qiniuapi.com', + 'default_query_region_host': QUERY_REGION_HOST, + 'default_query_region_backup_hosts': [ + 'uc.qbox.me', 'api.qiniu.com' ], - 'default_uc_backup_retry_times': 2, + 'default_backup_hosts_retry_times': 2, 'connection_timeout': 30, # 链接超时为时间为30s 'connection_retries': 3, # 链接重试次数为3次 'connection_pool': 10, # 链接池个数为10 @@ -31,8 +33,9 @@ 'default_rsf_host': False, 'default_api_host': False, 'default_uc_host': False, - 'default_uc_backup_hosts': False, - 'default_uc_backup_retry_times': False, + 'default_query_region_host': False, + 'default_query_region_backup_hosts': False, + 'default_backup_hosts_retry_times': False, 'connection_timeout': False, 'connection_retries': False, 'connection_pool': False, @@ -52,7 +55,8 @@ def set_default( default_zone=None, connection_retries=None, connection_pool=None, connection_timeout=None, default_rs_host=None, default_uc_host=None, default_rsf_host=None, default_api_host=None, default_upload_threshold=None, - default_uc_backup_hosts=None, default_uc_backup_retry_times=None): + default_query_region_host=None, default_query_region_backup_hosts=None, + default_backup_hosts_retry_times=None): if default_zone: _config['default_zone'] = default_zone _is_customized_default['default_zone'] = True @@ -68,14 +72,21 @@ def set_default( if default_uc_host: _config['default_uc_host'] = default_uc_host _is_customized_default['default_uc_host'] = True - _config['default_uc_backup_hosts'] = [] - _is_customized_default['default_uc_backup_hosts'] = True - if default_uc_backup_hosts: - _config['default_uc_backup_hosts'] = default_uc_backup_hosts - _is_customized_default['default_uc_backup_hosts'] = True - if default_uc_backup_retry_times: - _config['default_uc_backup_retry_times'] = default_uc_backup_retry_times - _is_customized_default['default_uc_backup_retry_times'] = True + _config['default_query_region_host'] = default_uc_host + _is_customized_default['default_query_region_host'] = True + _config['default_query_region_backup_hosts'] = [] + _is_customized_default['default_query_region_backup_hosts'] = True + if default_query_region_host: + _config['default_query_region_host'] = default_query_region_host + _is_customized_default['default_query_region_host'] = True + _config['default_query_region_backup_hosts'] = [] + _is_customized_default['default_query_region_backup_hosts'] = True + if default_query_region_backup_hosts: + _config['default_query_region_backup_hosts'] = default_query_region_backup_hosts + _is_customized_default['default_query_region_backup_hosts'] = True + if default_backup_hosts_retry_times: + _config['default_backup_hosts_retry_times'] = default_backup_hosts_retry_times + _is_customized_default['default_backup_hosts_retry_times'] = True if connection_retries: _config['connection_retries'] = connection_retries _is_customized_default['connection_retries'] = True diff --git a/qiniu/http/client.py b/qiniu/http/client.py index 8dfa2369..97c41980 100644 --- a/qiniu/http/client.py +++ b/qiniu/http/client.py @@ -66,7 +66,7 @@ def send_request(self, request, middlewares=None, **kwargs): return None, ResponseInfo(None, e) # if ok try dump response info to dict from json - if not resp_info.ok: + if not resp_info.ok(): return None, resp_info try: diff --git a/qiniu/region.py b/qiniu/region.py index 1ffc5f46..acab5c4e 100644 --- a/qiniu/region.py +++ b/qiniu/region.py @@ -227,8 +227,8 @@ def bucket_hosts(self, ak, bucket): uc_host = UC_HOST if is_customized_default('default_uc_host'): uc_host = get_default('default_uc_host') - uc_backup_hosts = get_default('default_uc_backup_hosts') - uc_backup_retry_times = get_default('default_uc_backup_retry_times') + uc_backup_hosts = get_default('default_query_region_backup_hosts') + uc_backup_retry_times = get_default('default_backup_hosts_retry_times') url = "{0}/v4/query?ak={1}&bucket={2}".format(uc_host, ak, bucket) ret, _resp = qn_http_client.get( diff --git a/test_qiniu.py b/test_qiniu.py index 20962a94..151b861a 100644 --- a/test_qiniu.py +++ b/test_qiniu.py @@ -1000,6 +1000,24 @@ class RegionTestCase(unittest.TestCase): test_rs_host = 'test.region.compatible.config.rs' test_rsf_host = 'test.region.compatible.config.rsf' + @staticmethod + def restore_hosts(): + set_default( + default_rs_host=qiniu.config.RS_HOST, + default_rsf_host=qiniu.config.RSF_HOST, + default_uc_host=qiniu.config.UC_HOST, + default_query_region_host=qiniu.config.QUERY_REGION_HOST, + default_query_region_backup_hosts=[ + 'uc.qbox.me', + 'api.qiniu.com' + ] + ) + qiniu.config._is_customized_default['default_rs_host'] = False + qiniu.config._is_customized_default['default_rsf_host'] = False + qiniu.config._is_customized_default['default_uc_host'] = False + qiniu.config._is_customized_default['default_query_region_host'] = False + qiniu.config._is_customized_default['default_query_region_backup_hosts'] = False + def test_config_compatible(self): try: set_default(default_rs_host=self.test_rs_host) @@ -1008,16 +1026,24 @@ def test_config_compatible(self): assert zone.get_rs_host("mock_ak", "mock_bucket") == self.test_rs_host assert zone.get_rsf_host("mock_ak", "mock_bucket") == self.test_rsf_host finally: - set_default(default_rs_host=qiniu.config.RS_HOST) - set_default(default_rsf_host=qiniu.config.RSF_HOST) - qiniu.config._is_customized_default['default_rs_host'] = False - qiniu.config._is_customized_default['default_rsf_host'] = False + RegionTestCase.restore_hosts() + + def test_query_region_with_custom_domain(self): + try: + set_default( + default_query_region_host='https://fake-uc.phpsdk.qiniu.com' + ) + zone = Zone() + data = zone.bucket_hosts(access_key, bucket_name) + assert data != 'null' + finally: + RegionTestCase.restore_hosts() def test_query_region_with_backup_domains(self): try: set_default( - default_uc_host='https://fake-uc.phpsdk.qiniu.com', - default_uc_backup_hosts=[ + default_query_region_host='https://fake-uc.phpsdk.qiniu.com', + default_query_region_backup_hosts=[ 'unavailable-uc.phpsdk.qiniu.com', 'uc.qbox.me' ] @@ -1026,13 +1052,22 @@ def test_query_region_with_backup_domains(self): data = zone.bucket_hosts(access_key, bucket_name) assert data != 'null' finally: + RegionTestCase.restore_hosts() + + def test_query_region_with_uc_and_backup_domains(self): + try: set_default( - default_uc_host=qiniu.config.UC_HOST, - default_uc_backup_hosts=[ - 'kodo-config.qiniuapi.com', - 'api.qiniu.com' + default_uc_host='https://fake-uc.phpsdk.qiniu.com', + default_query_region_backup_hosts=[ + 'unavailable-uc.phpsdk.qiniu.com', + 'uc.qbox.me' ] ) + zone = Zone() + data = zone.bucket_hosts(access_key, bucket_name) + assert data != 'null' + finally: + RegionTestCase.restore_hosts() class ReadWithoutSeek(object):