Ejemplo n.º 1
0
def test_react_basic():
    delete_react_tmp()

    make_react_tmp()
    try:
        args = {
            'service_dir': test_path,
            'service_name': 'service1',
            'service_ver': '1.0.1',
            'config': {
                'TEST': 'test',
                'SERVICE': 'apache2'
            }
        }

        actions = get_service_actions(**args)
        actions.update({
            'apache2.restart': {
                'commands': ['touch /tmp/service1/test.apache2.restart']
            }
        })
        react(actions, get_reactions(**args),
              ['conf.d/test', 'mods-enabled/mod'], [], '/tmp', {})

        assert os.path.exists('/tmp/service1/test.start') == True
        assert os.path.exists('/tmp/service1/test.apache2.restart') == True
        # Don't run reload after starting
        assert os.path.exists('/tmp/service1/test.reload') == False
        # Don't run restart after starting
        assert os.path.exists('/tmp/service1/test.restart') == False
    finally:
        delete_react_tmp()
Ejemplo n.º 2
0
def test_react_precendence():
    delete_react_tmp()

    make_react_tmp()
    try:
        args = {'service_dir':test_path,
                'service_name':'service1',
                'service_ver':'2.0',
                'config': {}}

        actions = get_service_actions(**args)
        actions.update({'apache2.restart': {
            'commands':['touch /tmp/service1/test.apache2.restart']
        }})

        paths_changed = ['service1/conf.d/new-virtual-host', 'service1/mods-enabled/new-mod']
        react(actions, get_reactions(**args), paths_changed, [], '/tmp', {})

        assert os.path.exists('/tmp/service1/test.start') == False
        assert os.path.exists('/tmp/service1/test.apache2.restart') == False
        assert os.path.exists('/tmp/service1/test.reload') == False
        assert os.path.exists('/tmp/service1/test.restart') == True

        delete_react_tmp()
        make_react_tmp()

        react(actions, get_reactions(**args), paths_changed[:1], [], '/tmp', {})

        assert os.path.exists('/tmp/service1/test.start') == False
        assert os.path.exists('/tmp/service1/test.apache2.restart') == False
        assert os.path.exists('/tmp/service1/test.reload') == True
        assert os.path.exists('/tmp/service1/test.restart') == False
    finally:
        delete_react_tmp()
Ejemplo n.º 3
0
def test_resource_react(tmpdir):
    tmpdir = str(tmpdir)
    check_file = os.path.join(tmpdir, 'ran_successfully')
    script = '''#!/bin/sh
    if [ ! -r {} ]; then
        touch {}
    else
        exit 1
    fi
    '''.format(check_file, check_file)

    actions = get_service_actions(test_path, 'resources', '1.0', {})
    reactions = get_reactions(test_path, 'resources', '1.0', {})

    assert len(actions) == 1
    assert len(reactions) == 1
   
    react(actions, reactions, [], [], os.path.join(test_path, 'services'), {'test.sh':lambda:script})

    assert os.path.exists(check_file)
Ejemplo n.º 4
0
def test_react_precendence():
    delete_react_tmp()

    make_react_tmp()
    try:
        args = {
            'service_dir': test_path,
            'service_name': 'service1',
            'service_ver': '2.0',
            'config': {}
        }

        actions = get_service_actions(**args)
        actions.update({
            'apache2.restart': {
                'commands': ['touch /tmp/service1/test.apache2.restart']
            }
        })

        paths_changed = [
            'service1/conf.d/new-virtual-host', 'service1/mods-enabled/new-mod'
        ]
        react(actions, get_reactions(**args), paths_changed, [], '/tmp', {})

        assert os.path.exists('/tmp/service1/test.start') == False
        assert os.path.exists('/tmp/service1/test.apache2.restart') == False
        assert os.path.exists('/tmp/service1/test.reload') == False
        assert os.path.exists('/tmp/service1/test.restart') == True

        delete_react_tmp()
        make_react_tmp()

        react(actions, get_reactions(**args), paths_changed[:1], [], '/tmp',
              {})

        assert os.path.exists('/tmp/service1/test.start') == False
        assert os.path.exists('/tmp/service1/test.apache2.restart') == False
        assert os.path.exists('/tmp/service1/test.reload') == True
        assert os.path.exists('/tmp/service1/test.restart') == False
    finally:
        delete_react_tmp()
Ejemplo n.º 5
0
def test_resource_react(tmpdir):
    tmpdir = str(tmpdir)
    check_file = os.path.join(tmpdir, 'ran_successfully')
    script = '''#!/bin/sh
    if [ ! -r {} ]; then
        touch {}
    else
        exit 1
    fi
    '''.format(check_file, check_file)

    actions = get_service_actions(test_path, 'resources', '1.0', {})
    reactions = get_reactions(test_path, 'resources', '1.0', {})

    assert len(actions) == 1
    assert len(reactions) == 1

    react(actions, reactions, [], [], os.path.join(test_path, 'services'),
          {'test.sh': lambda: script})

    assert os.path.exists(check_file)
Ejemplo n.º 6
0
def test_get_service_actions():
    actions = get_service_actions(test_path, 'service1', '1.0.1', {'TEST':'test'})
    print "actions {}".format(actions)

    assert len(actions) == 3
    assert 'service1.start' in actions
    assert 'service1.reload' in actions
    assert 'service1.restart' in actions

    assert len(actions['service1.start']['commands']) > 0
    assert len(actions['service1.reload']['commands']) > 0
    assert len(actions['service1.restart']['commands']) > 0

    assert len(actions['service1.reload']['not_after']) == 2
    assert len(actions['service1.restart']['not_after']) == 1

    assert 'chdir' in actions['service1.start']

    assert 'service1.start' in actions['service1.reload']['not_after']
    assert 'service1.restart' in actions['service1.reload']['not_after']

    assert 'service1.start' in actions['service1.restart']['not_after']
Ejemplo n.º 7
0
def test_get_service_actions():
    actions = get_service_actions(test_path, 'service1', '1.0.1',
                                  {'TEST': 'test'})
    print "actions {}".format(actions)

    assert len(actions) == 3
    assert 'service1.start' in actions
    assert 'service1.reload' in actions
    assert 'service1.restart' in actions

    assert len(actions['service1.start']['commands']) > 0
    assert len(actions['service1.reload']['commands']) > 0
    assert len(actions['service1.restart']['commands']) > 0

    assert len(actions['service1.reload']['not_after']) == 2
    assert len(actions['service1.restart']['not_after']) == 1

    assert 'chdir' in actions['service1.start']

    assert 'service1.start' in actions['service1.reload']['not_after']
    assert 'service1.restart' in actions['service1.reload']['not_after']

    assert 'service1.start' in actions['service1.restart']['not_after']
Ejemplo n.º 8
0
def test_react_basic():
    delete_react_tmp()

    make_react_tmp()
    try:
        args = {'service_dir':test_path,
                'service_name':'service1',
                'service_ver':'1.0.1',
                'config': {'TEST':'test','SERVICE':'apache2'}}

        actions = get_service_actions(**args)
        actions.update({'apache2.restart': {
            'commands':['touch /tmp/service1/test.apache2.restart']
        }})
        react(actions, get_reactions(**args), ['conf.d/test', 'mods-enabled/mod'], [], '/tmp', {})

        assert os.path.exists('/tmp/service1/test.start') == True
        assert os.path.exists('/tmp/service1/test.apache2.restart') == True
        # Don't run reload after starting
        assert os.path.exists('/tmp/service1/test.reload') == False
        # Don't run restart after starting
        assert os.path.exists('/tmp/service1/test.restart') == False
    finally:
        delete_react_tmp()