Error “Cannot unregister the machine” on Jenkins, ‘kitchen test’ command

2017/04/06

Ok, it’s a hack… so don’t use it unless you need it, and on your own risk.
For some reason, although the Windows vagrant box is updated using Matt Wrock’s packer templates from here https://github.com/mwrock/packer-templates, and everything goes well, and also on the first manual kitchen test on the Jenkins server everything goes ok, when run from Jenkin’s pipeline mechanism, the box is not destroyed.
Three VirtualBox processes remain hanged in the system.
It’s not a clean solution, but having this error over and over again:

STDERR: There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below.
Command: [“unregistervm”, “some GUID here”, “–delete”]
Stderr: VBoxManage.exe: error: Cannot unregister the machine ‘kitchen-your_cookbook-default-windows2012r2_default_some_numbers’ while it is locked
VBoxManage.exe: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee IUnknown

it’s really annoying, so until the final solution will reveal itself, this might also be a way:

$cookbook = ‘your_cookbook_name’
gwmi -Query “select * from win32_process where name = ‘virtualbox.exe'” | `
? { $_.CommandLine.Contains(“kitchen-$cookbook”)} | `
Select CommandLine, Handle | `
% { Get-Process -Id $_.Handle } | `
Stop-Process -Force -ErrorAction Continue

You’ll need to execute it from Groovy with the bat command, something like

bat “powershell -File \”../killVBoxes.ps1\” ${cookbookName}”

For the path of the PowerShell script you’ll need to provide the correct path.

Note: Be aware that when copy-pasting, the quotes and possibly other characters get messed up by WordPress, you’ll have to replace them.

Advertisements

Add Chef cookbook dependency in Berksfile group for testing

2016/11/24
source `https://supermarket.chef.io`

metadata

group :integration do
cookbook ‘some_cookbook’, path: ‘./test/fixtures/cookbooks/some_cookbook’

# not a strict dependency, but necessary for testing
cookbook ‘java’
end

Note 1: Credits go to StackOverflow, IT blogs and alike, sites that helped me with the code when searching for solutions.
Note 2: Be aware that when copy-pasting, the quotes and possibly other characters get messed up by WordPress, you’ll have to replace them.


Chef error NoMethodError – nil:NilClass

2015/09/22

Had several times the error from below

NoMethodError
————-
undefined method `[]’ for nil:NilClass

and each time I forgot which was the root cause.

What’s happening is that Chef can’t find some attributes, or some array of attributes that it needs to successfully converge the cookbook.

Run the converge in debug mode: kitchen converge -l=DEBUG and on the first line containing the error, see at what .rb files it points, including the line number, and you’ll discover what attributes you’re missing from the cookbook

Update: Another form of this error that I’ve encountered was

NoMethodError
————-
private method `select’ called for nil:NilClass

and this was happening when using artifact_deploy resource from artifact cookbook.
What was really causing the problem was the fact that I was specifying a deploy_to location that was not existing (set to drive D:, when the virtual machine had only a C: drive)


Issue when zipping folder with Chef resource windows_zipfile

2015/09/18

If you receive the warning

Single directory must be specified for compression, and [folder] does not meet that criteria.

when trying to zip a file with Chef resource provider windows_zipfile from windows cookbook, well… it just means what it says: the specified folder is not a folder or doesn’t exists.

The reason I’ve spend more than an hour investigating this is because I was using artifact_deploy resource to first download a build, from which I wanted afterwards to zip only a subfolder; and also, there were several cookbook dependencies, which also had to be compiled… so there goes wasted time.

But the problem is that artifact_deploy uses versioning, so I had to add a current subfolder to point to the right location.
Just to be sure you have the right folder specified, do a

Chef::Log.warn(“Source: #{backup_path}/current/#{app_name}/subfolder

in your cookbook, and paste the output into the file manager from the virtual machine used for testing the cookbook.

Note: Chef::Log.info doesn’t work for me on simple kitchen converge (Chef 12.4), that’s why I used the warn method. Of course, on DEBUG, it’s displayed either way.

Hope this helps someone.

Note: Be aware that when copy-pasting, the quotes and possibly other characters get messed up by WordPress, you’ll have to replace them.


Error when deploying ZIP archive with Chef artifact cookbook

2015/09/16

If you receive the following error when trying to deploy a ZIP archive with artifact_deploy resource:

=====================================================================
Error executing action `deploy` on resource ‘artifact_deploy[sampleArchive]’
=====================================================================
Chef::Exceptions::WindowsNotAdmin
———————————
[…]
Chef::Exceptions::WindowsNotAdmin: can not get the security information for ‘C:/Users/ADMINI~1/AppData/Local/Temp/kitchen/cache/artifact_deploys/sampleArchive/0.0.1/YourArchiveHere.zip’ due to missing Administrator privileges.

you might want to try to add the following configuration to your kitchen.yml file:

  client_rb:
    file_atomic_update: false

just under

provisioner:
  name: chef_zero

The reason that I’ve used it globally in the client.rb file and not in the resource is because so far artifact_deploy doesn’t support this feature.

If you’d like that feature, modify yourself the cookbook, or contact the Riot Games team

More about atomic update under Chef: Atomic File Updates
Chef version: 12.4.0
Operating system: Windows 7 Professional

Note 1: Credits go to StackOverflow, IT blogs and alike, sites that helped me with the code when searching for solutions.
Note 2: Be aware that when copy-pasting, the quotes and possibly other characters get messed up by WordPress, you’ll have to replace them.


%d bloggers like this: