Skip to content

Commit 0827dd7

Browse files
authored
PackageManager: add info function. (#138)
* 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.
1 parent 4039042 commit 0827dd7

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

rrmngmnt/package_manager.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ def is_available(cls, h):
2626
)
2727
return not rc
2828

29-
def _run_command_on_host(self, cmd):
29+
def _execute_cmd(self, cmd):
3030
"""
3131
Run given command on host
3232
3333
Args:
3434
cmd (list): Command to run
3535
3636
Returns:
37-
bool: True, if command success, otherwise false
37+
tuple or None: True, if command success, otherwise false
3838
"""
3939
self.logger.info(
4040
"Execute command '%s' on host %s", " ".join(cmd), self.host
@@ -45,8 +45,40 @@ def _run_command_on_host(self, cmd):
4545
"Failed to execute command '%s' on host %s; out: %s; err: %s",
4646
" ".join(cmd), self.host, out, err
4747
)
48-
return False
49-
return True
48+
return
49+
50+
return rc, out, err
51+
52+
def _run_command_on_host(self, cmd):
53+
"""
54+
Run given command on host
55+
56+
Args:
57+
cmd (list): Command to run
58+
59+
Returns:
60+
bool: True, if command success, otherwise false
61+
"""
62+
res = self._execute_cmd(cmd=cmd)
63+
return bool(res)
64+
65+
def info(self, package):
66+
"""
67+
Get package info
68+
69+
Args:
70+
package (str): Name of package.
71+
72+
Returns:
73+
str or None: package info or None.
74+
"""
75+
if not self.exist_command_d:
76+
raise NotImplementedError("There is no 'exist' command defined.")
77+
78+
cmd = list(self.exist_command_d)
79+
cmd.append(package)
80+
res = self._execute_cmd(cmd=cmd)
81+
return res[1] if res else res
5082

5183
def exist(self, package):
5284
"""

tests/test_package_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ def get_host(self, ip='1.1.1.1'):
133133
def get_pm(self):
134134
return self.get_host().package_manager
135135

136+
def test_info(self):
137+
assert not self.get_pm().info(self.packages['installed_1'])
138+
139+
def test_info_negative(self):
140+
assert not self.get_pm().info(self.packages['not_installed'])
141+
136142
def test_exist(self):
137143
assert self.get_pm().exist(self.packages['installed_1'])
138144

0 commit comments

Comments
 (0)