예제 #1
0
def test_proper_complex_stop():
    data = DataLoader().load('fixtures/bh-example.yml')
    order = {}
    Ordering().calculateDependenciesStop(data, order)
    assert order == {
        'dashboard': 0, 'elasticsearch': 2, 'fullhouse': 1, 'hadoop-namenode': 3,
        'hbase-master': 2, 'kibana': 0, 'mysql': 2, 'zookeeper': 4}
예제 #2
0
def test_proper_ordering_stop():
    data = DataLoader().load('fixtures/gf-test.yml')
    order = {}
    Ordering().calculateDependenciesStop(data, order)
    assert order == {'mysql': 0, 'network': 1}
예제 #3
0
def test_cycled_ordering_stop():
    data = DataLoader().load('fixtures/gf-test-wrong.yml')
    order = {}
    with pytest.raises(RingDependencyError):
        Ordering().calculateDependenciesStop(data, order)
예제 #4
0
from depsfinder.dataloader import DataLoader
from depsfinder.logging import getLogger
from depsfinder.ordering import Ordering
from depsfinder.parser import parser

logger = getLogger(__name__)

if __name__ == "__main__":
    args = parser.parse_args()

    # Calculate our dependencies. It is far from optimal algorithm - costs around O(n^2) but
    # we're talking about services ordering and usually there are not too many of them - 100-200
    # items, so this will work okay. And man - it's a test case and I'm not a
    # Lennart Poettering (__cross to oneself__). Further work still applicable though. For example,
    # moving from calculation for one host to calculation for N hosts where N is 100+, I would
    # optimize it from recursion to plain calculation. It's not too hard and for many nodes will
    # save a lot of CPU cycles.
    calculator = Ordering()
    methods = {
        "start": calculator.calculateDependenciesStart,
        "stop": calculator.calculateDependenciesStop
    }

    order = dict()
    data = DataLoader().load(args.file)
    methods[args.action](data, order)
    print(f"\n{args.action} order is: ")
    for k, v in sorted(order.items(), key=lambda x: [x[1]]):
        print(f"{k}:{v}")