Skip to content

Commit

Permalink
EOS-20688: Start and Stop MessageBus rest service in utils_setup (Sea…
Browse files Browse the repository at this point in the history
…gate#313)

* MessageBus: Rest Interface using aiohttp (Seagate#257)

* EOS-20462: Adding rsyslog service restart. (Seagate#286)

* Adding rsyslog service restart

Signed-off-by: Udayan Yaragattikar <[email protected]>

* Codacy issues resolved

Signed-off-by: Udayan Yaragattikar <[email protected]>

* Fix service handler

Signed-off-by: Udayan Yaragattikar <[email protected]>

* reverting the change

Signed-off-by: Udayan Yaragattikar <[email protected]>

* Resolve codacy issue

* Resolving codacy issue

Co-authored-by: Sachin Punadikar <[email protected]>

* MessageBus: Rest Interface using aiohttp

This commit incorporated all the changes of PR 254.
And a few modifications as well.

Signed-off-by: Rahul Tripathi <[email protected]>

* Creating error class

Signed-off-by: Rahul Tripathi <[email protected]>

* Revert "Creating error class"

This reverts commit e7675f6a3add2c4d5935e08bb30812e373846bcd.

* Fixes with some cosmetic changes

Signed-off-by: Rahul Tripathi <[email protected]>

Co-authored-by: Udayan Yaragattikar <[email protected]>
Co-authored-by: Sachin Punadikar <[email protected]>

* EOS-16256: Instantiation of Event message and its attributes (Seagate#278)

* Implementation of Iem set and print method

Signed-off-by: Selvakumar <[email protected]>

* Change copyright year

Signed-off-by: Selvakumar <[email protected]>

* Change in class interfaces

Signed-off-by: Selvakumar <[email protected]>

* Cosmetic changes

Signed-off-by: Selvakumar <[email protected]>

* Implemented send and receive

Signed-off-by: Selvakumar <[email protected]>

* Change hex values to string and method parameters

Signed-off-by: Selvakumar <[email protected]>

* Change hex values to string and method parameters

Signed-off-by: Selvakumar <[email protected]>

* Initialise client in init by a bool parameter

Signed-off-by: Selvakumar <[email protected]>

* Remove unneccesary validation

Signed-off-by: Selvakumar <[email protected]>

* Added test code and Derived Error from UtilsError

Signed-off-by: Selvakumar <[email protected]>

* Update Multiline comments

Signed-off-by: Selvakumar <[email protected]>

* Defined Alert schema and added more testcases

Signed-off-by: Selvakumar <[email protected]>

* Modify BaseError to UtilsError

Signed-off-by: Selvakumar <[email protected]>

* fix codacy issues

Signed-off-by: Selvakumar <[email protected]>

* fix codacy issues

Signed-off-by: Selvakumar <[email protected]>

* change multiline comments

Signed-off-by: Selvakumar <[email protected]>

* Make alert schema consistent

Signed-off-by: Selvakumar <[email protected]>

* Resolve conflicting files

Signed-off-by: Selvakumar <[email protected]>

* start and stop Messagebus rest service

Signed-off-by: Selvakumar <[email protected]>

* Shift rc by 8 bits

Signed-off-by: Selvakumar <[email protected]>

* Using SimpleProcess instead of os.system()

Signed-off-by: Selvakumar <[email protected]>

* run as sudo user

Signed-off-by: Selvakumar <[email protected]>

* Utils always runs as root, removing sudo

Signed-off-by: Selvakumar <[email protected]>

* Hadle exceptions in SimpleProcess

Signed-off-by: Selvakumar <[email protected]>

* validate root user

Signed-off-by: Selvakumar <[email protected]>

* Change single line comment

Signed-off-by: Selvakumar <[email protected]>

* Resolve codacy issue

Signed-off-by: Selvakumar <[email protected]>

* Check status of service

Signed-off-by: Selvakumar <[email protected]>

* Alter variable names

Signed-off-by: Selvakumar <[email protected]>

* Change error message

Signed-off-by: Selvakumar <[email protected]>

* Resolve codacy issue

Signed-off-by: Selvakumar <[email protected]>

Co-authored-by: rahul-tripathi-git <[email protected]>
Co-authored-by: Udayan Yaragattikar <[email protected]>
Co-authored-by: Sachin Punadikar <[email protected]>
  • Loading branch information
4 people authored Jun 2, 2021
1 parent 67f1f7e commit 6c8dea9
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
24 changes: 24 additions & 0 deletions py-utils/src/setup/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,21 @@ def init():
admin.register_message_type(message_types=['IEM'], partitions=1)
except MessageBusError as e:
raise SetupError(e.rc, "Unable to create message_type. %s", e)

# start MessageBus service and check status
start_cmd = SimpleProcess("systemctl start cortx_message_bus")
_, start_err, start_rc = start_cmd.run()

if start_rc != 0:
raise SetupError(start_rc, "Unable to start MessageBus Service \
%s", start_err.decode('utf-8'))

status_cmd = SimpleProcess("systemctl status cortx_message_bus")
_, status_err, status_rc = status_cmd.run()

if status_rc != 0:
raise SetupError(status_rc, "MessageBus Service is either failed \
inactive. %s", status_err.decode('utf-8'))
return 0

@staticmethod
Expand Down Expand Up @@ -216,6 +231,15 @@ def reset():
except Exception as e:
raise SetupError(errors.ERR_OP_FAILED, "Can not reset Message Bus. \
%s", e)

# Stop MessageBus Service
cmd = SimpleProcess("systemctl stop cortx_message_bus")
_, stderr, res_rc = cmd.run()

if res_rc != 0:
raise SetupError(res_rc, "Unable to stop MessageBus Service. \
%s", stderr.decode('utf-8'))

return 0

@staticmethod
Expand Down
9 changes: 6 additions & 3 deletions py-utils/src/setup/utils_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,23 @@
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

import os
import sys
import errno
import argparse
import inspect
import traceback

from cortx.setup import Utils
from cortx.setup import Utils, SetupError


class Cmd:
""" Setup Command """
_index = "setup"
_index = 'setup'

def __init__(self, args: dict):
if os.geteuid() != 0:
raise SetupError(errno.EPERM, "Permission denied! You need to be a \
root user")
self._url = args.config
self._args = args.args

Expand Down
35 changes: 25 additions & 10 deletions py-utils/src/utils/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
# For any questions about this software or licensing,
# please email [email protected] or [email protected].

import errno
import subprocess
from subprocess import TimeoutExpired, CalledProcessError # nosec

class Process:
def __init__(self, cmd):
Expand All @@ -25,20 +27,21 @@ def __init__(self, cmd):
def run(self):
pass


class SimpleProcess(Process):
''' Execute process and provide output '''
""" Execute process and provide output """
def __init__(self, cmd):
super(SimpleProcess, self).__init__(cmd)
self.shell=False
self.stdout=subprocess.PIPE
self.realtime_output=False
self.cwd=None
self.timeout=None
self.env=None
self.universal_newlines=None
self.shell = False
self.stdout = subprocess.PIPE
self.realtime_output = False
self.cwd = None
self.timeout = None
self.env = None
self.universal_newlines = None

def run(self, **args):
''' This will can run simple process '''
""" This will can run simple process """
for key, value in args.items():
setattr(self, key, value)

Expand All @@ -54,10 +57,22 @@ def run(self, **args):
self._output = self._cp.stdout
self._err = self._cp.stderr
self._returncode = self._cp.returncode

except TimeoutExpired as e:
self._err = str(e)
self._output = ''
self._returncode = errno.ETIMEDOUT

except CalledProcessError as e:
self._err = str(e)
self._output = ''
self._returncode = e.returncode

except Exception as err:
self._err = "SubProcess Error: " + str(err)
self._output = ""
self._output = ''
self._returncode = -1

return self._output, self._err, self._returncode


Expand Down

0 comments on commit 6c8dea9

Please sign in to comment.