Skip to content

parallels: error when no VM file found in source#107

Merged
nywilken merged 2 commits intomainfrom
parallels_error_no_copies
Jan 16, 2024
Merged

parallels: error when no VM file found in source#107
nywilken merged 2 commits intomainfrom
parallels_error_no_copies

Conversation

@lbajolet-hashicorp
Copy link
Contributor

The post-processor, when consuming a parallels artifact, checks for the presence of a pvm or macvm file from the files of the artifact received, and copies it in the output box for vagrant to use later. However, if the artifact does not contain a compatible file, the post-processor does not error, and instead returns a success, leading to an unusable box being produced.

To avoid this, we count the files copied, and if none were, the box will be unusable, so the post-processor errors now.

@lbajolet-hashicorp lbajolet-hashicorp requested a review from a team as a code owner January 9, 2024 17:02
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to me I left a single nit.

Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the mocked test needs to be updated to contain a valid file

--- FAIL: TestPostProcessorPostProcess_vagrantfileUserVariable (0.01s)
post-processor_test.go:265: err: No VM file found in source artifact

@lbajolet-hashicorp lbajolet-hashicorp force-pushed the parallels_error_no_copies branch from 3b41b4d to 2fac2c3 Compare January 9, 2024 19:29
@lbajolet-hashicorp
Copy link
Contributor Author

@nywilken regarding the failing test, I opted to add some mocked file hierarchy for the parallels test, and added another one to ensure we do fail when no files are present in the artifact. To be sure if you can do a quick second peek at the code that'd be great, and we can merge if that looks good to you

lbajolet-hashicorp and others added 2 commits January 16, 2024 16:38
The post-processor, when consuming a parallels artifact, checks for the
presence of a pvm or macvm file from the files of the artifact
received, and copies it in the output box for vagrant to use later.
However, if the artifact does not contain a compatible file, the
post-processor does not error, and instead returns a success, leading to
an unusable box being produced.

To avoid this, we count the files copied, and if none were, the box will
be unusable, so the post-processor errors now.
@nywilken nywilken force-pushed the parallels_error_no_copies branch from 2fac2c3 to 40abc55 Compare January 16, 2024 21:54
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rebased and rerolled this change a little to add the test cases to the parallels_test.go file since they are Parallels specific.

?   	github.com/hashicorp/packer-plugin-vagrant	[no test files]
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/packer-plugin-vagrant/builder/vagrant	(cached) [no tests to run]
?   	github.com/hashicorp/packer-plugin-vagrant/version	[no test files]
=== RUN   TestPostProcessorPostProcessParallels
2024/01/16 16:53:33 ui: Creating a dummy Vagrant box to ensure the host system can create one correctly
2024/01/16 16:53:33 Turning dir into box: /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer3976304713 => /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/box-1323631034.box
2024/01/16 16:53:33 Compressing with gzip compression level: -1
2024/01/16 16:53:33 Skipping directory '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer3976304713' for box '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/box-1323631034.box'
2024/01/16 16:53:33 Box add: '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer3976304713/metadata.json' to '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/box-1323631034.box'
2024/01/16 16:53:33 ui: Creating Vagrant box for 'parallels' provider
2024/01/16 16:53:33 ui: Copying: /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T//1055054597.pvm/3873643601
2024/01/16 16:53:33 ui: Copying: /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T//1055054597.pvm/255380389
2024/01/16 16:53:33 ui: Using custom Vagrantfile: /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer122144398
2024/01/16 16:53:33 Turning dir into box: /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer830734517 => packer__parallels_arm64.box
2024/01/16 16:53:33 Compressing with gzip compression level: -1
2024/01/16 16:53:33 Skipping directory '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer830734517' for box 'packer__parallels_arm64.box'
2024/01/16 16:53:33 Skipping directory '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer830734517/1055054597.pvm' for box 'packer__parallels_arm64.box'
2024/01/16 16:53:33 Box add: '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer830734517/1055054597.pvm/255380389' to 'packer__parallels_arm64.box'
2024/01/16 16:53:33 ui: Compressing: 1055054597.pvm/255380389
2024/01/16 16:53:33 Box add: '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer830734517/1055054597.pvm/3873643601' to 'packer__parallels_arm64.box'
2024/01/16 16:53:33 ui: Compressing: 1055054597.pvm/3873643601
2024/01/16 16:53:33 Box add: '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer830734517/Vagrantfile' to 'packer__parallels_arm64.box'
2024/01/16 16:53:33 ui: Compressing: Vagrantfile
2024/01/16 16:53:33 Box add: '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer830734517/metadata.json' to 'packer__parallels_arm64.box'
2024/01/16 16:53:33 ui: Compressing: metadata.json
--- PASS: TestPostProcessorPostProcessParallels (0.01s)
=== RUN   TestPostProcessorPostProcessParallels_NoFileErrorOnCopy
2024/01/16 16:53:33 ui: Creating a dummy Vagrant box to ensure the host system can create one correctly
2024/01/16 16:53:33 Turning dir into box: /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer4246976573 => /var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/box-2869865802.box
2024/01/16 16:53:33 Compressing with gzip compression level: -1
2024/01/16 16:53:33 Skipping directory '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer4246976573' for box '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/box-2869865802.box'
2024/01/16 16:53:33 Box add: '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/packer4246976573/metadata.json' to '/var/folders/jd/zhl6kpsn1156cmqdyttt22xm0000gp/T/box-2869865802.box'
2024/01/16 16:53:33 ui: Creating Vagrant box for 'parallels' provider
    parallels_test.go:117: failed as expected: No VM file found in source artifact
--- PASS: TestPostProcessorPostProcessParallels_NoFileErrorOnCopy (0.00s)
PASS
ok  	github.com/hashicorp/packer-plugin-vagrant/post-processor/vagrant	0.305s
testing: warning: no tests to run
PASS
ok  	github.com/hashicorp/packer-plugin-vagrant/post-processor/vagrant-cloud	(cached) [no tests to run]

@nywilken nywilken added the bug label Jan 16, 2024
@nywilken nywilken merged commit d22623a into main Jan 16, 2024
@nywilken nywilken deleted the parallels_error_no_copies branch January 16, 2024 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants