Skip to content

Commit

Permalink
PackageManager: add info function. (#138)
Browse files Browse the repository at this point in the history
* PackageManager: add info function.

Add info() to get package info.

* Fix tox deprecated travis section (#139)

* Fix tox deprecated travis section

* test-requirements remove attrs version limit

* PackageManager: add info function.

Add info() to get package info.
  • Loading branch information
myakove authored Feb 1, 2021
1 parent 4039042 commit 0827dd7
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
40 changes: 36 additions & 4 deletions rrmngmnt/package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ def is_available(cls, h):
)
return not rc

def _run_command_on_host(self, cmd):
def _execute_cmd(self, cmd):
"""
Run given command on host
Args:
cmd (list): Command to run
Returns:
bool: True, if command success, otherwise false
tuple or None: True, if command success, otherwise false
"""
self.logger.info(
"Execute command '%s' on host %s", " ".join(cmd), self.host
Expand All @@ -45,8 +45,40 @@ def _run_command_on_host(self, cmd):
"Failed to execute command '%s' on host %s; out: %s; err: %s",
" ".join(cmd), self.host, out, err
)
return False
return True
return

return rc, out, err

def _run_command_on_host(self, cmd):
"""
Run given command on host
Args:
cmd (list): Command to run
Returns:
bool: True, if command success, otherwise false
"""
res = self._execute_cmd(cmd=cmd)
return bool(res)

def info(self, package):
"""
Get package info
Args:
package (str): Name of package.
Returns:
str or None: package info or None.
"""
if not self.exist_command_d:
raise NotImplementedError("There is no 'exist' command defined.")

cmd = list(self.exist_command_d)
cmd.append(package)
res = self._execute_cmd(cmd=cmd)
return res[1] if res else res

def exist(self, package):
"""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_package_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def get_host(self, ip='1.1.1.1'):
def get_pm(self):
return self.get_host().package_manager

def test_info(self):
assert not self.get_pm().info(self.packages['installed_1'])

def test_info_negative(self):
assert not self.get_pm().info(self.packages['not_installed'])

def test_exist(self):
assert self.get_pm().exist(self.packages['installed_1'])

Expand Down

0 comments on commit 0827dd7

Please sign in to comment.