Skip to content

Commit

Permalink
Allow inject-config to handle multiple CD-ROM drives. Fixes #54
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmatthews committed Nov 7, 2016
1 parent b9ba302 commit be8a093
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -9,6 +9,8 @@ This project adheres to `Semantic Versioning`_.
**Fixed**

- TypeError in ``find_item`` method (`#54`_).
- ``cot inject-config`` correctly handles OVAs with multiple empty CD-ROM
drives to choose amongst (`#54`_ also).

**Added**

Expand Down
5 changes: 4 additions & 1 deletion COT/ovf/ovf.py
Expand Up @@ -2606,9 +2606,12 @@ def find_empty_drive(self, drive_type):
"""
if drive_type == 'cdrom':
# Find a drive that has no HostResource property
return self.hardware.find_item(
drives = self.hardware.find_all_items(
resource_type=drive_type,
properties={self.HOST_RESOURCE: None})
if drives:
return drives[0]
return None
elif drive_type == 'harddisk':
# All harddisk items must have a HostResource, so we need a
# different way to indicate an empty drive. By convention,
Expand Down
2 changes: 1 addition & 1 deletion COT/ovf/tests/test_hardware.py
Expand Up @@ -26,7 +26,7 @@ def test_find_item_multiple_matches(self):
"""Check find_item raises LookupError if multiple matches are found."""
with VMContextManager(self.input_ovf) as ovf:
hw = ovf.hardware
self.assertRaisesRegexp(
self.assertRaisesRegex(
LookupError,
r"multiple matching 'ide' Items",
hw.find_item, resource_type='ide')
Expand Down
48 changes: 48 additions & 0 deletions COT/tests/test_inject_config.py
Expand Up @@ -32,6 +32,7 @@
from COT.platforms import CSR1000V, IOSv, IOSXRv, IOSXRvLC
from COT.helpers import helpers
from COT.disks import disk_representation_from_file
from COT.remove_file import COTRemoveFile

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -184,6 +185,53 @@ def test_inject_config_iso_secondary(self):
else:
logger.info("isoinfo not available, not checking disk contents")

def test_inject_config_iso_multiple_drives(self):
"""Inject config file on an ISO when multiple empty drives exist."""
temp_ovf = os.path.join(self.temp_dir, "intermediate.ovf")

# Remove the existing ISO from our input_ovf:
rm = COTRemoveFile(UI())
rm.package = self.input_ovf
rm.output = temp_ovf
rm.file_path = "input.iso"
rm.run()
rm.finished()
rm.destroy()

# Now we have two empty drives.
self.instance.package = temp_ovf
self.instance.config_file = self.config_file
self.instance.run()
self.assertLogged(**self.OVERWRITING_DISK_ITEM)
self.instance.finished()
config_iso = os.path.join(self.temp_dir, 'config.iso')
self.check_diff("""
<ovf:File ovf:href="input.vmdk" ovf:id="file1" ovf:size="{vmdk_size}" />
- <ovf:File ovf:href="input.iso" ovf:id="file2" ovf:size="{iso_size}" />
<ovf:File ovf:href="sample_cfg.txt" ovf:id="textfile" \
ovf:size="{cfg_size}" />
+ <ovf:File ovf:href="config.iso" ovf:id="config.iso" \
ovf:size="{config_size}" />
</ovf:References>
...
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
+ <rasd:Description>Configuration disk</rasd:Description>
<rasd:ElementName>CD-ROM 1</rasd:ElementName>
- <rasd:HostResource>ovf:/file/file2</rasd:HostResource>
+ <rasd:HostResource>ovf:/file/config.iso</rasd:HostResource>
<rasd:InstanceID>7</rasd:InstanceID>"""
.format(vmdk_size=self.FILE_SIZE['input.vmdk'],
iso_size=self.FILE_SIZE['input.iso'],
cfg_size=self.FILE_SIZE['sample_cfg.txt'],
config_size=os.path.getsize(config_iso)))
if helpers['isoinfo']:
# The sample_cfg.text should be renamed to the platform-specific
# file name for bootstrap config - in this case, config.txt
self.assertEqual(disk_representation_from_file(config_iso).files,
["config.txt"])
else:
logger.info("isoinfo not available, not checking disk contents")

def test_inject_config_vmdk(self):
"""Inject config file on a VMDK."""
self.instance.package = self.iosv_ovf
Expand Down

0 comments on commit be8a093

Please sign in to comment.