Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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.º 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_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.º 7
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.º 8
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.º 9
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.º 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_required_subscript_params():
    """
    If an optional subscript has multiple required parameters,
    excluding all = ok
    excluding one = fail
    """

    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: string
    - name: bar
      required: true
      type: string
  actions:
    - cib: "{{foo}} {{bar}}"
'''

    b = '''---
- version: 2.2
  category: Script
  include:
    - script: foofoo
      required: false
  actions:
    - include: foofoo
    - cib: "{{foofoo:foo}} {{foofoo:bar}"
'''

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

    def ver():
        actions = scripts.verify(script_b, {"foofoo": {
            "foo": "one"
        }},
                                 external_check=False)
        pprint(actions)

    with pytest.raises(ValueError):
        ver()
Exemplo n.º 12
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.º 13
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.º 14
0
def test_required_subscript_params():
    """
    If an optional subscript has multiple required parameters,
    excluding all = ok
    excluding one = fail
    """

    a = """---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: string
    - name: bar
      required: true
      type: string
  actions:
    - cib: "{{foo}} {{bar}}"
"""

    b = """---
- version: 2.2
  category: Script
  include:
    - script: foofoo
      required: false
  actions:
    - include: foofoo
    - cib: "{{foofoo:foo}} {{foofoo:bar}"
"""

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

    def ver():
        actions = scripts.verify(script_b, {"foofoo": {"foo": "one"}}, external_check=False)
        pprint(actions)

    assert_raises(ValueError, ver)
Exemplo n.º 15
0
def test_enums_fail2():
    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: enum
  actions:
    - cib: "{{foo}}"
'''
    script_a = scripts.load_script_string('test-a', a)
    assert script_a is not None

    def ver():
        return scripts.verify(script_a, {"foo": "one"})
    assert_raises(ValueError, ver)
Exemplo n.º 16
0
def test_enums_fail2():
    a = '''---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: enum
  actions:
    - cib: "{{foo}}"
'''
    script_a = scripts.load_script_string('test-a', a)
    assert script_a is not None

    def ver():
        return scripts.verify(script_a, {"foo": "one"}, external_check=False)
    assert_raises(ValueError, ver)
Exemplo n.º 17
0
def test_enums_fail2():
    a = """---
- version: 2.2
  category: Script
  parameters:
    - name: foo
      required: true
      type: enum
  actions:
    - cib: "{{foo}}"
"""
    script_a = scripts.load_script_string("test-a", a)
    assert script_a is not None

    def ver():
        return scripts.verify(script_a, {"foo": "one"}, external_check=False)

    assert_raises(ValueError, ver)
Exemplo n.º 18
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.º 19
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.º 20
0
def test_enums_fail():
    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

    def ver():
        return scripts.verify(script_a, {"foo": "wrong"}, external_check=False)
    assert_raises(ValueError, ver)
Exemplo n.º 21
0
def test_enums_fail():
    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

    def ver():
        return scripts.verify(script_a, {"foo": "wrong"}, external_check=False)

    with pytest.raises(ValueError):
        ver()