Skip to content

Commit

Permalink
builder/hyperv-vmcx fix required properties, add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mayn committed Mar 15, 2018
1 parent 7c797e6 commit ce2de47
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
1 change: 1 addition & 0 deletions README.rst
Expand Up @@ -103,6 +103,7 @@ Builders:
- file
- googlecompute
- hyperv-iso
- hyperv-vmcx
- lxc
- lxd
- null
Expand Down
17 changes: 14 additions & 3 deletions src/packerlicious/builder.py
Expand Up @@ -120,7 +120,6 @@ class Alicloud(PackerBuilder):
}



class AmazonSourceAmiFilter(PackerProperty):
"""
https://www.packer.io/docs/builders/amazon-ebs.html#source_ami_filter
Expand Down Expand Up @@ -800,6 +799,7 @@ class HyperV(PackerBuilder):
'temp_path': (str, False),
}


class HyperVvmcx(PackerBuilder):
"""
Hyper-V Builder (from a vmcx)
Expand All @@ -808,8 +808,8 @@ class HyperVvmcx(PackerBuilder):
resource_type = "hyperv-vmcx"

props = {
'clone_from_vmxc_path': (str, True),
'clone_from_vm_name': (str, True),
'clone_from_vmxc_path': (str, False),
'clone_from_vm_name': (str, False),
'clone_from_snapshot_name': (str, False),
'clone_all_snapshots': (validator.boolean, False),
'boot_command': ([str], False),
Expand All @@ -826,6 +826,8 @@ class HyperVvmcx(PackerBuilder):
'http_directory': (str, False),
'http_port_min': (int, False),
'http_port_max': (int, False),
'iso_checksum': (str, False),
'iso_checksum_type': (str, False),
'iso_url': (str, False),
'iso_urls': ([str], False),
'iso_target_extension': (str, False),
Expand All @@ -849,6 +851,13 @@ def validate(self):
]
validator.exactly_one(self.__class__.__name__, self.properties, conds)

iso_url_conds = [
'iso_url',
'iso_urls'
]
validator.mutually_exclusive(self.__class__.__name__, self.properties, iso_url_conds)


class LXD(PackerBuilder):
"""
LXD Builder
Expand All @@ -863,6 +872,7 @@ class LXD(PackerBuilder):
'command_wrapper': (str, False),
}


class LXC(PackerBuilder):
"""
LXC Builder
Expand All @@ -882,6 +892,7 @@ class LXC(PackerBuilder):
'template_parameters': ([str], False),
}


class Null(PackerBuilder):
"""
Null Builder
Expand Down
28 changes: 28 additions & 0 deletions tests/packerlicious/test_builder_hyperv.py
Expand Up @@ -11,3 +11,31 @@ def test_required_fields_missing(self):
with pytest.raises(ValueError) as excinfo:
b.to_dict()
assert 'required' in str(excinfo.value)


class TestHyperVvmcxBuilder(object):

def test_required_fields_missing(self):
b = builder.HyperVvmcx()

with pytest.raises(ValueError) as excinfo:
b.to_dict()
assert 'HyperVvmcx: one of the following must be specified: clone_from_vmxc_path, clone_from_vm_name' == str(excinfo.value)

def test_exactly_one_clone_from_required(self):
b = builder.HyperVvmcx(
clone_from_vmxc_path="c:\\virtual machines\\ubuntu-12.04.5-server-amd64",
clone_from_vm_name="ubuntu-12.04.5-server-amd64"
)

with pytest.raises(ValueError) as excinfo:
b.to_dict()
assert 'HyperVvmcx: only one of the following can be specified: clone_from_vmxc_path, clone_from_vm_name' == str(
excinfo.value)

def test_exactly_one_clone_from_specified(self):
b = builder.HyperVvmcx(
clone_from_vmxc_path="c:\\virtual machines\\ubuntu-12.04.5-server-amd64",
)

b.to_dict()
24 changes: 0 additions & 24 deletions tests/packerlicious/test_builder_hyperv_vmcx.py

This file was deleted.

0 comments on commit ce2de47

Please sign in to comment.