Skip to content

Commit

Permalink
Merge pull request Seagate#11 from Seagate/rgw_setup
Browse files Browse the repository at this point in the history
rgw_setup skeleton (Mini-provisioner + directory structure)
  • Loading branch information
cdeshmukh authored Jan 31, 2022
2 parents b3024d4 + 5ca4098 commit a7dd13b
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 0 deletions.
66 changes: 66 additions & 0 deletions jenkins/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash
#
# Copyright (c) 2021 Seagate Technology LLC and/or its Affiliates
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

set -e

PROG=$(basename "$0")
SCRIPT_DIR=$(realpath $(dirname "$0"))
BASE_DIR=$SCRIPT_DIR/..
BUILD_NUMBER=
GIT_VER=

usage() {
echo """usage: $PROG[-v version] [-g git_version] [-b build_number]""" 1>&2;
exit 1;
}

# Check for passed in arguments
while getopts ":g:v:b:" o; do
case "${o}" in
v)
VER=${OPTARG}
;;
g)
GIT_VER=${OPTARG}
;;
b)
BUILD_NUMBER=${OPTARG}
;;
*)
usage
;;
esac
done

[ -z $"$GIT_VER" ] && GIT_VER="$(git rev-parse --short HEAD)" \
|| GIT_VER="${GIT_VER}_$(git rev-parse --short HEAD)"
[ -z "$VER" ] && VER="2.0.0"
[ -z "$BUILD_NUMBER" ] && BUILD_NUMBER=1
REL="${BUILD_NUMBER}_${GIT_VER}"

rpm -q rpm-build > /dev/null || {
echo "error: rpm-build is not installed. Install rpm-build and run $PROG"
exit 1;
}

# Create version file
echo $VER > "$BASE_DIR"/VERSION
/bin/chmod +rx "$BASE_DIR"/VERSION
/bin/chmod +x "$BASE_DIR"/src/setup/rgw_setup

cd "$BASE_DIR"

./setup.py bdist_rpm --release="$REL"
18 changes: 18 additions & 0 deletions src/setup/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/python3

# CORTX Python common library.
# Copyright (c) 2021 Seagate Technology LLC and/or its Affiliates
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

"""init class for rgw."""
24 changes: 24 additions & 0 deletions src/setup/error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python3

# Copyright (c) 2021 Seagate Technology LLC and/or its Affiliates
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

from cortx.utils.errors import BaseError

class SetupError(BaseError):
"""Generic Exception with error code and output."""

def __init__(self, rc, message_id, *message_args):
"""Initalize error message paramters."""
super().__init__(rc, message_id=message_id, *message_args)
90 changes: 90 additions & 0 deletions src/setup/rgw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/env python3

# Copyright (c) 2021 Seagate Technology LLC and/or its Affiliates
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# For any questions about this software or licensing,
# please email [email protected] or [email protected].


class Rgw:
"""Represents RGW and Performs setup related actions."""

@staticmethod
def validate(phase: str):
"""Perform validtions."""

# Perform RPM validations
return 0

@staticmethod
def post_install(config_path: str):
"""
Performs post install operations.
"""

return 0

@staticmethod
def prepare(config_path: str):
"""
Performs prepare phase operations.
"""

return 0

@staticmethod
def config(config_path: str):
"""
Performs configurations.
"""

return 0

@staticmethod
def init(config_path: str):
"""
Perform initialization.
"""

return 0

@staticmethod
def test(config_path: str, plan: str):
"""
Perform configuration testing.
"""

return 0

@staticmethod
def reset(config_path: str):
"""
Remove/Delete all the data/logs that was created by user/testing.
"""

return 0

@staticmethod
def cleanup(pre_factory: bool, config_path: str):
"""
Remove/Delete all the data that was created after post install.
"""

return 0

@staticmethod
def upgrade(config_path: str):
"""
Perform upgrade steps.
"""

return 0
181 changes: 181 additions & 0 deletions src/setup/rgw_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#!/usr/bin/python3

# Copyright (c) 2021 Seagate Technology LLC and/or its Affiliates
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

import sys
import errno
import traceback

from cortx.utils.log import Log
from cortx.utils.cmd_framework import Cmd
from setup import Rgw
from error import SetupError

class SetupCmdBase(Cmd):
"""Setup cmd base class."""

def __init__(self, *args):
"""Initialize super class members."""
super().__init__(*args)

def add_args(parser):
parser.add_argument('--services', default='services', help='services')
parser.add_argument('--config', default='config_url', help='config')

class PostInstallCmd(SetupCmdBase):
"""PostInstall Setup Cmd."""

name = 'post_install'

def __init__(self, args: dict):
"""Initialize super class members."""
super().__init__(args)

def process(self):
Rgw.validate('post_install')
rc = Rgw.post_install(self._url)
return rc


class PrepareCmd(SetupCmdBase):
"""Prepare Setup Cmd."""
name = 'prepare'

def __init__(self, args: dict):
"""Initialize super class members."""
super().__init__(args)

def process(self):
Rgw.validate('prepare')
rc = Rgw.prepare(self._url)
return rc


class ConfigCmd(SetupCmdBase):
"""Setup Config Cmd."""
name = 'config'

def __init__(self, args):
"""Initialize super class members."""
super().__init__(args)

def process(self):
Rgw.validate('config')
rc = Rgw.config(self._url)
return rc


class InitCmd(SetupCmdBase):
"""Init Setup Cmd."""
name = 'init'

def __init__(self, args):
"""Initialize super class members."""
super().__init__(args)
self.config_path = args.config

def process(self):
Rgw.validate('init')
rc = Rgw.init(self.config_path)
return rc


class TestCmd(SetupCmdBase):
"""Test Setup Cmd."""
name = 'test'

def __init__(self, args):
"""Initialize super class members."""
super().__init__(args)
self.config_path = args.config
# Default test_plan is 'sanity'
self.test_plan = args.plan

def process(self):
Rgw.validate('test')
rc = Rgw.test(self.config_path, self.test_plan)
return rc


class ResetCmd(SetupCmdBase):
"""Reset Setup Cmd."""
name = 'reset'

def __init__(self, args):
""" Initialize super class members."""
super().__init__(args)
self.config_path = args.config

def process(self):
Rgw.validate('reset')
rc = Rgw.reset(self.config_path)
return rc


class CleanupCmd(SetupCmdBase):
"""Cleanup Setup Cmd."""
name = 'cleanup'

def __init__(self, args: dict):
"""Initialize super class members."""
super().__init__(args)
self.config_path = args.config

def process(self):
Rgw.validate('cleanup')
rc = Rgw.cleanup(self.config_path)
return rc


class UpgradeCmd(SetupCmdBase):
"""Upgrade Setup Cmd."""
name = 'upgrade'

def __init__(self, args: dict):
"""Initialize super class members."""
super().__init__(args)
self.config_path = args.config

def process(self):
Rgw.validate('upgrade')
rc = Rgw.upgrade(self.config_path)
return rc


def main():
argv = sys.argv

Log.init() # TODO

try:
desc = "CORTX Rgw Setup command"
command = Cmd.get_command(desc, argv[1:])
rc = command.process()

except SetupError as e:
sys.stderr.write("error: %s\n\n" % str(e))
sys.stderr.write("%s\n" % traceback.format_exc())
Cmd.usage(argv[0])
rc = e.rc

except Exception as e:
sys.stderr.write("error: %s\n\n" % str(e))
sys.stderr.write("%s\n" % traceback.format_exc())
rc = errno.EINVAL

Log.info(f"Command {command} {argv[1]} completed with rc:{rc}")

if __name__ == '__main__':
sys.exit(main())
3 changes: 3 additions & 0 deletions src/setup/templates/rgw.config.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cortx:
common:
rgw_param_1 = test

0 comments on commit a7dd13b

Please sign in to comment.