summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2014-12-19 10:58:46 +0100
committerJan Pokorný <jpokorny@redhat.com>2015-01-09 10:19:52 +0100
commita12fb1f94171e61b0c93f2dbfaa5b171087f2a52 (patch)
tree06fc26ce75e00570768af0fdbe6aa12f0290117f
parent71b0af36775ae0e15935c6a5774011ed1a47ca5d (diff)
downloadclufter-a12fb1f94171e61b0c93f2dbfaa5b171087f2a52.tar.gz
clufter-a12fb1f94171e61b0c93f2dbfaa5b171087f2a52.tar.xz
clufter-a12fb1f94171e61b0c93f2dbfaa5b171087f2a52.zip
facts: add ability to translate logical cmd to distro cmd
The target distro cmd is expected to keep the assumed template form (say, a command to install packages should contain "{commands}" field that is then substituted, via "format" method, with the desired packages, completing the command to be used further in the process). Unlike with logical packages, nothing is considered a (suitable) distro-wide default. Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rw-r--r--facts.py11
-rw-r--r--tests/facts.py18
2 files changed, 28 insertions, 1 deletions
diff --git a/facts.py b/facts.py
index 0a0748a..9ce2a06 100644
--- a/facts.py
+++ b/facts.py
@@ -54,6 +54,8 @@ cluster_map = {
'pacemaker[cman]': (1, 1, 4),
#---
'pkg::mysql': 'mysql-server',
+ #---
+ 'cmd::pkg-install': 'yum install -y {packages}',
}),
((14, ), {
'corosync': (1, 4),
@@ -84,6 +86,8 @@ cluster_map = {
'pkg::mysql': 'mysql-server',
'pkg::postgresql': 'postgresql-server',
'pkg::virsh': 'libvirt-client',
+ #---
+ 'cmd::pkg-install': 'yum install -y {packages}',
}),
((6, 2), {
'corosync': (1, 4),
@@ -374,6 +378,13 @@ def package(which, *sys_id):
return _find_meta('pkg', which, *sys_id, default=which)
+def cmd_pkg_install(pkgs, *sys_id):
+ cmd = _find_meta('cmd', 'pkg-install', *sys_id)
+ if cmd:
+ cmd = cmd.format(packages=' '.join(pkgs))
+ return cmd
+
+
cluster_systems = (cluster_pcs_flatiron, cluster_pcs_needle)
diff --git a/tests/facts.py b/tests/facts.py
index d3a20d1..6926106 100644
--- a/tests/facts.py
+++ b/tests/facts.py
@@ -10,7 +10,8 @@ from os.path import join, dirname as d; execfile(join(d(d((__file__))), '_go'))
from unittest import TestCase
-from .facts import cluster_pcs_flatiron, cluster_pcs_1_2, package
+from .facts import cluster_pcs_flatiron, cluster_pcs_1_2, cmd_pkg_install, \
+ package
class TestClusterSystem(TestCase):
@@ -62,4 +63,19 @@ class TestPackage(TestCase):
self.assertEqual(package('virsh', *sys_id), 'libvirt-client')
+class TestCommand(TestCase):
+ def test_pkg_install_rhel60(self):
+ sys_id = 'linux', ('redhat', ' 6.0')
+ self.assertEqual(cmd_pkg_install(('mc', 'vim'), *sys_id),
+ 'yum install -y mc vim')
+ def test_pkg_install_rhel70(self):
+ sys_id = 'linux', ('redhat', ' 7.0')
+ self.assertEqual(cmd_pkg_install(('mc', 'vim'), *sys_id),
+ 'yum install -y mc vim')
+ def test_pkg_install_fedora19(self):
+ sys_id = 'linux', ('fedora', ' 19')
+ self.assertEqual(cmd_pkg_install(('mc', 'vim'), *sys_id),
+ 'yum install -y mc vim')
+
+
from os.path import join, dirname as d; execfile(join(d(d(__file__)), '_gone'))