Skip to content

Commit

Permalink
reorder query region hosts & fix ok call & fix ci (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
lihsai0 authored Jul 28, 2023
1 parent 904c28c commit 4505df7
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 43 deletions.
38 changes: 22 additions & 16 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
39 changes: 25 additions & 14 deletions qiniu/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 # 断点续传分块大小,该参数为接口规格,暂不支持修改

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion qiniu/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions qiniu/region.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
55 changes: 45 additions & 10 deletions test_qiniu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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'
]
Expand All @@ -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):
Expand Down

0 comments on commit 4505df7

Please sign in to comment.