Commit 095661ea authored by Martin Abbrent's avatar Martin Abbrent 💬
Browse files

Resolve "Check if Minio Client (mc) is available"

parent 1bc6183e
......@@ -6,6 +6,24 @@ stages:
- test
- release
integration-test:
tags:
- hifis
stage: test
image: python:latest
services:
- name: minio/minio
alias: minio
command:
- "server"
- "/vol0"
- "--console-address"
- ":9001"
script:
- pip install minio
- curl https://dl.min.io/client/mc/release/linux-amd64/mc > /usr/local/bin/mc
- chmod a+x /usr/local/bin/mc
- python tests.py
build-package:
stage: release
......
MAJOR = 0
MINOR = 0
PATCH = 7
PATCH = 8
__version__ = '{}.{}.{}'.format(MAJOR, MINOR, PATCH)
......@@ -8,12 +8,15 @@ from minio.commonconfig import GOVERNANCE
from minio.objectlockconfig import ObjectLockConfig, YEARS
class MinIoClientError(ChildProcessError):
class MinIoClientError(Exception):
pass
class Mc:
class MinioClientNotFoundError(Exception):
pass
class Mc:
ALIAS = 'my_minio'
CONFIG_TEMPLATE = {
"version": "10",
......@@ -54,6 +57,16 @@ class Mc:
self.logger = logging.getLogger('minio-cli-wrapper')
self._check_setup()
def _check_setup(self):
try:
self._command(['ls', self.alias])
except FileNotFoundError as e:
raise MinioClientNotFoundError(
'Unable to find minio cli client. Install it from '
'<https://docs.min.io/docs/minio-client-quickstart-guide.html#GNU/Linux>. ') from e
def _init_config(self):
self.proto = 'https://' if self.secure else 'http://'
self.config['aliases'][self.alias]['url'] = '{proto}{url}'.format(proto=self.proto,
......@@ -72,12 +85,16 @@ class Mc:
)
if ret.returncode != 0:
raise MinIoClientError(ret.stderr)
err_from_stdout = ret.stdout if json.loads(ret.stdout).get('status') == 'error' else ''
msg = ret.stderr or err_from_stdout or '"Unspecified error: Empty response from minio ' \
'client" '
raise MinIoClientError(json.dumps(json.loads(msg), indent=4))
if not confidential:
self.logger.info(ret.stdout)
return json.loads(ret.stdout)
return json.loads(ret.stdout or 'null')
def user_add(self, access_key: str, secret_key: str):
ret = self._command(
......
from tests import integration_test
if __name__ == '__main__':
integration_test
import argparse
from minio_cli_wrapper.mc import Mc
parser = argparse.ArgumentParser()
parser.add_argument('--url', default='minio:9000')
args = parser.parse_args()
m = Mc(args.url, secure=False, access_key='minioadmin', secret_key='minioadmin')
ret = m._command(['ls', m.ALIAS])
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment