Exemplo n.º 1
0
def test_v2():
    script = scripts.load_script("v2")
    assert script is not None
    eq_("v2", script["name"])
    assert len(script["shortdesc"]) > 0

    actions = scripts.verify(
        script,
        {
            "id": "www",
            "apache": {"id": "apache"},
            "virtual-ip": {"id": "www-vip", "ip": "192.168.1.100"},
            "install": False,
        },
        external_check=False,
    )
    pprint(actions)
    eq_(len(actions), 1)
    assert str(actions[0]["text"]).find("group www") >= 0

    actions = scripts.verify(
        script,
        {
            "id": "www",
            "apache": {"id": "apache"},
            "virtual-ip": {"id": "www-vip", "ip": "192.168.1.100"},
            "install": True,
        },
        external_check=False,
    )
    pprint(actions)
    eq_(len(actions), 3)
Exemplo n.º 2
0
def test_enums_basic():
    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: enum
      values:
        - one
        - two
        - three
  actions:
    - cib: "{{foo}}"
'''

    script_a = scripts.load_script_string('test-a', a)
    assert script_a is not None

    actions = scripts.verify(script_a,
                             {"foo": "one"}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "one"

    actions = scripts.verify(script_a,
                             {"foo": "three"}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "three"
Exemplo n.º 3
0
def test_enums_basic():
    a = """---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: enum
      values:
        - one
        - two
        - three
  actions:
    - cib: "{{foo}}"
"""

    script_a = scripts.load_script_string("test-a", a)
    assert script_a is not None

    actions = scripts.verify(script_a, {"foo": "one"}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]["text"] == "one"

    actions = scripts.verify(script_a, {"foo": "three"}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]["text"] == "three"
Exemplo n.º 4
0
def test_enums_basic():
    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: enum
      values:
        - one
        - two
        - three
  actions:
    - cib: "{{foo}}"
'''

    script_a = scripts.load_script_string('test-a', a)
    assert script_a is not None

    actions = scripts.verify(script_a,
                             {"foo": "one"})
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "one"

    actions = scripts.verify(script_a,
                             {"foo": "three"})
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "three"
Exemplo n.º 5
0
def test_optional_step_ref():
    """
    It seems I have a bug in referencing ids from substeps.
    """
    a = '''---
- version: 2.2
  category: Script
  include:
    - agent: test:apache
      name: apache
      parameters:
        - name: id
          required: true
'''
    b = '''---
- version: 2.2
  category: Script
  include:
    - script: apache
      required: false
  parameters:
    - name: wiz
      required: true
  actions:
    - cib: "primitive {{wiz}} {{apache:id}}"
'''

    script_a = scripts.load_script_string('apache', a)
    script_b = scripts.load_script_string('test-b', b)
    assert script_a is not None
    assert script_b is not None

    actions = scripts.verify(script_a, {"id": "apacho"}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "primitive apacho test:apache"

    #import ipdb
    #ipdb.set_trace()
    actions = scripts.verify(script_b, {
        'wiz': "SARUMAN",
        "apache": {
            "id": "apacho"
        }
    },
                             external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "primitive SARUMAN apacho"
Exemplo n.º 6
0
def test_value_replace_handles():
    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      value: bar
'''
    b = '''---
- version: 2.2
  category: Script
  include:
    - script: test-a
      parameters:
        - name: foo
          value: "{{wiz}}+{{wiz}}"
  parameters:
    - name: wiz
      required: true
  actions:
    - cib: "{{test-a:foo}}"
'''

    script_a = scripts.load_script_string('test-a', a)
    script_b = scripts.load_script_string('test-b', b)
    assert script_a is not None
    assert script_b is not None
    actions = scripts.verify(script_b,
                             {'wiz': "SARUMAN"}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "SARUMAN+SARUMAN"
Exemplo n.º 7
0
def test_value_replace_handles():
    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      value: bar
'''
    b = '''---
- version: 2.2
  category: Script
  include:
    - script: test-a
      parameters:
        - name: foo
          value: "{{wiz}}+{{wiz}}"
  parameters:
    - name: wiz
      required: true
  actions:
    - cib: "{{test-a:foo}}"
'''

    script_a = scripts.load_script_string('test-a', a)
    script_b = scripts.load_script_string('test-b', b)
    assert script_a is not None
    assert script_b is not None
    actions = scripts.verify(script_b,
                             {'wiz': "SARUMAN"})
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "SARUMAN+SARUMAN"
Exemplo n.º 8
0
def test_value_replace_handles():
    a = """---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      value: bar
"""
    b = """---
- version: 2.2
  category: Script
  include:
    - script: test-a
      parameters:
        - name: foo
          value: "{{wiz}}+{{wiz}}"
  parameters:
    - name: wiz
      required: true
  actions:
    - cib: "{{test-a:foo}}"
"""

    script_a = scripts.load_script_string("test-a", a)
    script_b = scripts.load_script_string("test-b", b)
    assert script_a is not None
    assert script_b is not None
    actions = scripts.verify(script_b, {"wiz": "SARUMAN"}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]["text"] == "SARUMAN+SARUMAN"
Exemplo n.º 9
0
def test_inline_script():
    """
    Test inline script feature for call actions
    """

    a = """---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: string
  actions:
    - call: |
        #!/bin/sh
        echo "{{foo}}"
      nodes: local
"""

    script_a = scripts.load_script_string("foofoo", a)
    assert script_a is not None

    actions = scripts.verify(script_a, {"foo": "hello world"}, external_check=False)
    pprint(actions)
    assert len(actions) == 1
    assert actions[0]["name"] == "call"
    assert actions[0]["value"] == '#!/bin/sh\necho "hello world"'
    tp = TestPrinter()
    scripts.run(script_a, {"foo": "hello world"}, tp)

    for action, args in tp.actions:
        print action, args
        if action == "finish":
            assert args[0]["value"] == '#!/bin/sh\necho "hello world"'
Exemplo n.º 10
0
def test_inline_script():
    """
    Test inline script feature for call actions
    """

    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: string
  actions:
    - call: |
        #!/bin/sh
        echo "{{foo}}"
      nodes: local
'''

    script_a = scripts.load_script_string('foofoo', a)
    assert script_a is not None

    actions = scripts.verify(script_a, {"foo": "hello world"},
                             external_check=False)
    pprint(actions)
    assert len(actions) == 1
    assert actions[0]['name'] == 'call'
    assert actions[0]['value'] == '#!/bin/sh\necho "hello world"'
    tp = TestPrinter()
    scripts.run(script_a, {"foo": "hello world"}, tp)

    for action, args in tp.actions:
        print(action, args)
        if action == 'finish':
            assert args[0]['value'] == '#!/bin/sh\necho "hello world"'
Exemplo n.º 11
0
def test_vipinc():
    script = scripts.load_script("vipinc")
    assert script is not None
    actions = scripts.verify(script, {"vip": {"id": "vop", "ip": "10.0.0.4"}}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]["text"].find('primitive vop test:virtual-ip\n\tip="10.0.0.4"') >= 0
    assert actions[0]["text"].find("clone c-vop vop") >= 0
Exemplo n.º 12
0
def test_agent_include():
    inc2 = scripts.load_script("inc2")
    actions = scripts.verify(
        inc2, {"wiz": "abc", "foo": "cde", "included-script": {"foo": True, "bar": "bah bah"}}, external_check=False
    )
    pprint(actions)
    eq_(len(actions), 6)
    eq_("33\n\nabc", actions[-1]["text"].strip())
Exemplo n.º 13
0
def test_optional_step_ref():
    """
    It seems I have a bug in referencing ids from substeps.
    """
    a = '''---
- version: 2.2
  category: Script
  include:
    - agent: test:apache
      name: apache
      parameters:
        - name: id
          required: true
'''
    b = '''---
- version: 2.2
  category: Script
  include:
    - script: apache
      required: false
  parameters:
    - name: wiz
      required: true
  actions:
    - cib: "primitive {{wiz}} {{apache:id}}"
'''

    script_a = scripts.load_script_string('apache', a)
    script_b = scripts.load_script_string('test-b', b)
    assert script_a is not None
    assert script_b is not None

    actions = scripts.verify(script_a,
                             {"id": "apacho"})
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "primitive apacho test:apache"

    #import ipdb
    #ipdb.set_trace()
    actions = scripts.verify(script_b,
                             {'wiz': "SARUMAN", "apache": {"id": "apacho"}})
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'] == "primitive SARUMAN apacho"
Exemplo n.º 14
0
def test_unified():
    unified = scripts.load_script('unified')
    actions = scripts.verify(
        unified,
        {'id': 'foo',
         'vip': {'id': 'bar', 'ip': '192.168.0.15'}}, external_check=False)
    pprint(actions)
    eq_(len(actions), 1)
    eq_('primitive bar IPaddr2 ip=192.168.0.15\ngroup g-foo foo bar', actions[-1]['text'].strip())
Exemplo n.º 15
0
def test_unified():
    unified = scripts.load_script('unified')
    actions = scripts.verify(
        unified,
        {'id': 'foo',
         'vip': {'id': 'bar', 'ip': '192.168.0.15'}}, external_check=False)
    pprint(actions)
    eq_(len(actions), 1)
    eq_('primitive bar IPaddr2 ip=192.168.0.15\ngroup g-foo foo bar', actions[-1]['text'].strip())
Exemplo n.º 16
0
def test_agent_include():
    inc2 = scripts.load_script('inc2')
    actions = scripts.verify(
        inc2,
        {'wiz': 'abc',
         'foo': 'cde',
         'included-script': {'foo': True, 'bar': 'bah bah'}})
    pprint(actions)
    eq_(len(actions), 6)
    eq_('33\n\nabc', actions[-1]['text'].strip())
Exemplo n.º 17
0
def test_vipinc():
    script = scripts.load_script('vipinc')
    assert script is not None
    actions = scripts.verify(
        script,
        {'vip': {'id': 'vop', 'ip': '10.0.0.4'}})
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'].find('primitive vop test:virtual-ip\n\tip="10.0.0.4"') >= 0
    assert actions[0]['text'].find("clone c-vop vop") >= 0
Exemplo n.º 18
0
def test_agent_include():
    inc2 = scripts.load_script('inc2')
    actions = scripts.verify(
        inc2,
        {'wiz': 'abc',
         'foo': 'cde',
         'included-script': {'foo': True, 'bar': 'bah bah'}}, external_check=False)
    pprint(actions)
    eq_(len(actions), 6)
    eq_('33\n\nabc', actions[-1]['text'].strip())
Exemplo n.º 19
0
def test_vipinc():
    script = scripts.load_script('vipinc')
    assert script is not None
    actions = scripts.verify(
        script,
        {'vip': {'id': 'vop', 'ip': '10.0.0.4'}}, external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]['text'].find('primitive vop test:virtual-ip\n\tip="10.0.0.4"') >= 0
    assert actions[0]['text'].find("clone c-vop vop") >= 0
Exemplo n.º 20
0
def test_two_substeps():
    """
    There is a scoping bug
    """
    a = '''---
- version: 2.2
  category: Script
  include:
    - agent: test:apache
      name: apache
      parameters:
        - name: id
          required: true
'''
    b = '''---
- version: 2.2
  category: Script
  include:
    - script: apache
      name: apache-a
      required: true
    - script: apache
      name: apache-b
      required: true
  parameters:
    - name: wiz
      required: true
  actions:
    - include: apache-a
    - include: apache-b
    - cib: "primitive {{wiz}} {{apache-a:id}} {{apache-b:id}}"
'''

    script_a = scripts.load_script_string('apache', a)
    script_b = scripts.load_script_string('test-b', b)
    assert script_a is not None
    assert script_b is not None

    actions = scripts.verify(script_b, {
        'wiz': "head",
        "apache-a": {
            "id": "one"
        },
        "apache-b": {
            "id": "two"
        }
    },
                             external_check=False)
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0][
        'text'] == "primitive one test:apache\n\nprimitive two test:apache\n\nprimitive head one two"
Exemplo n.º 21
0
def test_load_legacy():
    script = scripts.load_script('legacy')
    assert script is not None
    eq_('legacy', script['name'])
    assert len(script['shortdesc']) > 0
    pprint(script)
    actions = scripts.verify(script, {}, external_check=False)
    pprint(actions)
    eq_([{
        'longdesc': '',
        'name': 'apply_local',
        'shortdesc': 'Configure SSH',
        'text': '',
        'value': 'configure.py ssh'
    }, {
        'longdesc': '',
        'name': 'collect',
        'shortdesc': 'Check state of nodes',
        'text': '',
        'value': 'collect.py'
    }, {
        'longdesc': '',
        'name': 'validate',
        'shortdesc': 'Verify parameters',
        'text': '',
        'value': 'verify.py'
    }, {
        'longdesc': '',
        'name': 'apply',
        'shortdesc': 'Install packages',
        'text': '',
        'value': 'configure.py install'
    }, {
        'longdesc': '',
        'name': 'apply_local',
        'shortdesc': 'Generate corosync authkey',
        'text': '',
        'value': 'authkey.py'
    }, {
        'longdesc': '',
        'name': 'apply',
        'shortdesc': 'Configure cluster nodes',
        'text': '',
        'value': 'configure.py corosync'
    }, {
        'longdesc': '',
        'name': 'apply_local',
        'shortdesc': 'Initialize cluster',
        'text': '',
        'value': 'init.py'
    }], actions)
Exemplo n.º 22
0
def test_v2():
    script = scripts.load_script('v2')
    assert script is not None
    eq_('v2', script['name'])
    assert len(script['shortdesc']) > 0

    actions = scripts.verify(
        script,
        {'id': 'www',
         'apache': {'id': 'apache'},
         'virtual-ip': {'id': 'www-vip', 'ip': '192.168.1.100'},
         'install': False})
    pprint(actions)
    eq_(len(actions), 1)
    assert str(actions[0]['text']).find('group www') >= 0

    actions = scripts.verify(
        script,
        {'id': 'www',
         'apache': {'id': 'apache'},
         'virtual-ip': {'id': 'www-vip', 'ip': '192.168.1.100'},
         'install': True})
    pprint(actions)
    eq_(len(actions), 3)
Exemplo n.º 23
0
def test_v2():
    script = scripts.load_script('v2')
    assert script is not None
    eq_('v2', script['name'])
    assert len(script['shortdesc']) > 0

    actions = scripts.verify(
        script,
        {'id': 'www',
         'apache': {'id': 'apache'},
         'virtual-ip': {'id': 'www-vip', 'ip': '192.168.1.100'},
         'install': False}, external_check=False)
    pprint(actions)
    eq_(len(actions), 1)
    assert str(actions[0]['text']).find('group www') >= 0

    actions = scripts.verify(
        script,
        {'id': 'www',
         'apache': {'id': 'apache'},
         'virtual-ip': {'id': 'www-vip', 'ip': '192.168.1.100'},
         'install': True}, external_check=False)
    pprint(actions)
    eq_(len(actions), 3)
Exemplo n.º 24
0
def test_two_substeps():
    """
    There is a scoping bug
    """
    a = """---
- version: 2.2
  category: Script
  include:
    - agent: test:apache
      name: apache
      parameters:
        - name: id
          required: true
"""
    b = """---
- version: 2.2
  category: Script
  include:
    - script: apache
      name: apache-a
      required: true
    - script: apache
      name: apache-b
      required: true
  parameters:
    - name: wiz
      required: true
  actions:
    - include: apache-a
    - include: apache-b
    - cib: "primitive {{wiz}} {{apache-a:id}} {{apache-b:id}}"
"""

    script_a = scripts.load_script_string("apache", a)
    script_b = scripts.load_script_string("test-b", b)
    assert script_a is not None
    assert script_b is not None

    actions = scripts.verify(
        script_b, {"wiz": "head", "apache-a": {"id": "one"}, "apache-b": {"id": "two"}}, external_check=False
    )
    eq_(len(actions), 1)
    pprint(actions)
    assert actions[0]["text"] == "primitive one test:apache\n\nprimitive two test:apache\n\nprimitive head one two"
Exemplo n.º 25
0
def test_load_legacy():
    script = scripts.load_script("legacy")
    assert script is not None
    eq_("legacy", script["name"])
    assert len(script["shortdesc"]) > 0
    pprint(script)
    actions = scripts.verify(script, {}, external_check=False)
    pprint(actions)
    eq_(
        [
            {
                "longdesc": "",
                "name": "apply_local",
                "shortdesc": "Configure SSH",
                "text": "",
                "value": "configure.py ssh",
            },
            {"longdesc": "", "name": "collect", "shortdesc": "Check state of nodes", "text": "", "value": "collect.py"},
            {"longdesc": "", "name": "validate", "shortdesc": "Verify parameters", "text": "", "value": "verify.py"},
            {
                "longdesc": "",
                "name": "apply",
                "shortdesc": "Install packages",
                "text": "",
                "value": "configure.py install",
            },
            {
                "longdesc": "",
                "name": "apply_local",
                "shortdesc": "Generate corosync authkey",
                "text": "",
                "value": "authkey.py",
            },
            {
                "longdesc": "",
                "name": "apply",
                "shortdesc": "Configure cluster nodes",
                "text": "",
                "value": "configure.py corosync",
            },
            {"longdesc": "", "name": "apply_local", "shortdesc": "Initialize cluster", "text": "", "value": "init.py"},
        ],
        actions,
    )
Exemplo n.º 26
0
def test_load_legacy():
    script = scripts.load_script('legacy')
    assert script is not None
    eq_('legacy', script['name'])
    assert len(script['shortdesc']) > 0
    pprint(script)
    actions = scripts.verify(script, {})
    pprint(actions)
    eq_([{'longdesc': '',
          'name': 'apply_local',
          'shortdesc': 'Configure SSH',
          'text': '',
          'value': 'configure.py ssh'},
         {'longdesc': '',
          'name': 'collect',
          'shortdesc': 'Check state of nodes',
          'text': '',
          'value': 'collect.py'},
         {'longdesc': '',
          'name': 'validate',
          'shortdesc': 'Verify parameters',
          'text': '',
          'value': 'verify.py'},
         {'longdesc': '',
          'name': 'apply',
          'shortdesc': 'Install packages',
          'text': '',
          'value': 'configure.py install'},
         {'longdesc': '',
          'name': 'apply_local',
          'shortdesc': 'Generate corosync authkey',
          'text': '',
          'value': 'authkey.py'},
         {'longdesc': '',
          'name': 'apply',
          'shortdesc': 'Configure cluster nodes',
          'text': '',
          'value': 'configure.py corosync'},
         {'longdesc': '',
          'name': 'apply_local',
          'shortdesc': 'Initialize cluster',
          'text': '',
          'value': 'init.py'}], actions)
Exemplo n.º 27
0
    def runtest(when, val):
        the_script = '''version: 2.2
shortdesc: Test when expressions
longdesc: See if more complicated expressions work
parameters:
  - name: stringtest
    type: string
    shortdesc: A test string
actions:
  - call: "echo '{{stringtest}}'"
    when: %s
'''
        scrpt = scripts.load_script_string('{}_{}'.format(when, val),
                                           the_script % when)
        assert scrpt is not None

        a1 = scripts.verify(scrpt, {"stringtest": val}, external_check=False)
        pprint(a1)
        return a1
Exemplo n.º 28
0
    def runtest(when, val):
        the_script = '''version: 2.2
shortdesc: Test when expressions
longdesc: See if more complicated expressions work
parameters:
  - name: stringtest
    type: string
    shortdesc: A test string
actions:
  - call: "echo '{{stringtest}}'"
    when: %s
'''
        scrpt = scripts.load_script_string('{}_{}'.format(when, val), the_script % when)
        assert scrpt is not None

        a1 = scripts.verify(scrpt,
                            {"stringtest": val},
                            external_check=False)
        pprint(a1)
        return a1
Exemplo n.º 29
0
 def ver():
     return scripts.verify(script_a, {"foo": "one"}, external_check=False)
Exemplo n.º 30
0
 def ver():
     return scripts.verify(script_a, {"foo": "one"}, external_check=False)
Exemplo n.º 31
0
 def ver():
     actions = scripts.verify(script_b, {"foofoo": {"foo": "one"}}, external_check=False)
     pprint(actions)
Exemplo n.º 32
0
 def ver():
     return scripts.verify(script_a, {"foo": "wrong"})
Exemplo n.º 33
0
def test_unified():
    unified = scripts.load_script("unified")
    actions = scripts.verify(unified, {"id": "foo", "vip": {"id": "bar", "ip": "192.168.0.15"}}, external_check=False)
    pprint(actions)
    eq_(len(actions), 1)
    eq_("primitive bar IPaddr2 ip=192.168.0.15\ngroup g-foo foo bar", actions[-1]["text"].strip())
Exemplo n.º 34
0
 def ver():
     return scripts.verify(script_a, {"foo": "one"})
Exemplo n.º 35
0
 def ver():
     actions = scripts.verify(script_b,
                              {"foofoo": {"foo": "one"}}, external_check=False)
     pprint(actions)