Example #1
0
        def errors_in_execution_capture_and_continue_til_end(self):
            cxns = [Mock(name=x) for x in ("host1", "host2", "host3")]

            class OhNoz(Exception):
                pass

            onoz = OhNoz()
            cxns[1].run.side_effect = onoz
            g = SerialGroup.from_connections(cxns)
            try:
                g.run("whatever", hide=True)
            except GroupException as e:
                result = e.result
            else:
                assert False, "Did not raise GroupException!"
            succeeded = {
                cxns[0]: cxns[0].run.return_value,
                cxns[2]: cxns[2].run.return_value,
            }
            failed = {cxns[1]: onoz}
            expected = succeeded.copy()
            expected.update(failed)
            assert result == expected
            assert result.succeeded == succeeded
            assert result.failed == failed
Example #2
0
        def errors_in_execution_capture_and_continue_til_end(self):
            cxns = [Mock(name=x) for x in ("host1", "host2", "host3")]

            class OhNoz(Exception):
                pass

            onoz = OhNoz()
            cxns[1].run.side_effect = onoz
            g = SerialGroup.from_connections(cxns)
            try:
                g.run("whatever", hide=True)
            except GroupException as e:
                result = e.result
            else:
                assert False, "Did not raise GroupException!"
            succeeded = {
                cxns[0]: cxns[0].run.return_value,
                cxns[2]: cxns[2].run.return_value,
            }
            failed = {cxns[1]: onoz}
            expected = succeeded.copy()
            expected.update(failed)
            assert result == expected
            assert result.succeeded == succeeded
            assert result.failed == failed
Example #3
0
 def returns_results_mapping(self):
     cxns = [Mock(name=x) for x in ("host1", "host2", "host3")]
     g = SerialGroup.from_connections(cxns)
     result = g.run("whatever", hide=True)
     assert isinstance(result, GroupResult)
     expected = {x: x.run.return_value for x in cxns}
     assert result == expected
     assert result.succeeded == expected
     assert result.failed == {}
Example #4
0
 def returns_results_mapping(self):
     cxns = [Mock(name=x) for x in ("host1", "host2", "host3")]
     g = SerialGroup.from_connections(cxns)
     result = g.run("whatever", hide=True)
     assert isinstance(result, GroupResult)
     expected = {x: x.run.return_value for x in cxns}
     assert result == expected
     assert result.succeeded == expected
     assert result.failed == {}
Example #5
0
 def executes_arguments_on_contents_run_serially(self):
     "executes arguments on contents' run() serially"
     cxns = [Connection(x) for x in ("host1", "host2", "host3")]
     args = ("command",)
     kwargs = {"hide": True, "warn": True}
     for index, cxn in enumerate(cxns):
         side_effect = _make_serial_tester(cxns, index, args, kwargs)
         cxn.run = Mock(side_effect=side_effect)
     g = SerialGroup.from_connections(cxns)
     g.run(*args, **kwargs)
     # Sanity check, e.g. in case none of them were actually run
     for cxn in cxns:
         cxn.run.assert_called_with(*args, **kwargs)
Example #6
0
 def executes_arguments_on_contents_run_serially(self):
     "executes arguments on contents' run() serially"
     cxns = [Connection(x) for x in ("host1", "host2", "host3")]
     args = ("command",)
     kwargs = {"hide": True, "warn": True}
     for index, cxn in enumerate(cxns):
         side_effect = _make_serial_tester(cxns, index, args, kwargs)
         cxn.run = Mock(side_effect=side_effect)
     g = SerialGroup.from_connections(cxns)
     g.run(*args, **kwargs)
     # Sanity check, e.g. in case none of them were actually run
     for cxn in cxns:
         cxn.run.assert_called_with(*args, **kwargs)
Example #7
0
 def executes_arguments_on_contents_run_serially(self, method):
     "executes arguments on contents' run() serially"
     cxns = [Connection(x) for x in ("host1", "host2", "host3")]
     args = ARGS_BY_METHOD[method]
     kwargs = KWARGS_BY_METHOD[method]
     for index, cxn in enumerate(cxns):
         side_effect = _make_serial_tester(method, cxns, index, args,
                                           kwargs)
         setattr(cxn, method, Mock(side_effect=side_effect))
     g = SerialGroup.from_connections(cxns)
     getattr(g, method)(*args, **kwargs)
     # Sanity check, e.g. in case none of them were actually run
     for cxn in cxns:
         getattr(cxn, method).assert_called_with(*args, **kwargs)
Example #8
0
# load config
config = configparser.ConfigParser()
config.read('config.ini')

# set coordinator
coordinator_connections = []
coordinator_user = config['COORDINATOR'].pop('user')
coordinator_password = config['COORDINATOR'].pop('password')
coordinator_catalog_path = config['COORDINATOR'].pop('catalog_path')
for host_key in config['COORDINATOR'].keys():
    host = config['COORDINATOR'][host_key]
    conn = Connection(host=host,
                      user=coordinator_user,
                      connect_kwargs={'password': coordinator_password})
    coordinator_connections.append(conn)
coordinator_group = SerialGroup.from_connections(coordinator_connections)

# set worker
worker_connections = []
worker_user = config['WORKER'].pop('user')
worker_password = config['WORKER'].pop('password')
worker_catalog_path = config['WORKER'].pop('catalog_path')
for host_key in config['WORKER'].keys():
    host = config['WORKER'][host_key]
    conn = Connection(host=host,
                      user=worker_user,
                      connect_kwargs={'password': worker_password})
    worker_connections.append(conn)
worker_group = SerialGroup.from_connections(worker_connections)

Example #9
0
from fabric import SerialGroup, Connection
import os

# List of master's HAProxy
_haproxies_hosts = [
    '10.148.0.37',
]

_ssh_user = '******'
_ssh_private_key = 'haproxy'

conns = [Connection(host, user=_ssh_user, connect_kwargs={
    "key_filename": _ssh_private_key,
}) for host in _haproxies_hosts]

group = SerialGroup.from_connections(conns)


for conn in conns:
    conn.put('./haproxy.cfg', '/etc/haproxy/haproxy.cfg')

result = group.run('systemctl reload haproxy')