Skip to content

Commit

Permalink
fixes #110 - bug provisioner conditionals only/except conditionals ar…
Browse files Browse the repository at this point in the history
…e missing
  • Loading branch information
mayn committed Jun 5, 2018
1 parent d40e33a commit 96d02a1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,8 @@

### BUG FIX:
# builder/GoogleCompute: source_image_family / source_image exactly one should be required [GH-111]
# provisioner: only/except conditionals are missing[GH-110]


## 0.8.0 (May 30, 2018)

Expand Down
2 changes: 2 additions & 0 deletions src/packerlicious/provisioner.py
Expand Up @@ -31,6 +31,8 @@ class PackerProvisioner(BasePackerObject):
"""
provisioner_props = {
'pause_before': (str, False),
'only': ([str], False),
'except': ([str], False),
}

def __init__(self, title=None, **kwargs):
Expand Down
86 changes: 86 additions & 0 deletions tests/packerlicious/test_provisioner.py
@@ -0,0 +1,86 @@

from packerlicious import Template
import packerlicious.provisioner as provisioner
import json


class TestProvisionerAttributes(object):

def test_support_only(self):
expected_json = """
{
"provisioners": [
{
"type": "shell-local",
"inline": [ "ls" ],
"only": [ "azure-arm" ]
}
]
}
"""

p = provisioner.ShellLocal(
inline=["ls"],
only=["azure-arm"]
)

t = Template()
t.add_provisioner(p)

to_json = t.to_json()
assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2,
separators=(',', ': '))

def test_support_only(self):
expected_json = """
{
"provisioners": [
{
"type": "shell",
"inline": [ "ls" ],
"except": [ "azure-arm" ]
}
]
}
"""

p = provisioner.Shell(
inline=["ls"])

p.__setattr__('except', ["azure-arm"])

t = Template()
t.add_provisioner(p)

to_json = t.to_json()
assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2,
separators=(',', ': '))



def test_support_pause_before(self):
expected_json = """
{
"provisioners": [
{
"type": "shell",
"inline": [ "ls" ],
"pause_before": "10s"
}
]
}
"""

p = provisioner.Shell(
inline=["ls"],
pause_before="10s"
)

t = Template()
t.add_provisioner(p)

to_json = t.to_json()
assert to_json == json.dumps(json.loads(expected_json), sort_keys=True, indent=2,
separators=(',', ': '))


0 comments on commit 96d02a1

Please sign in to comment.