CLOUDIFY-2083 add test and fix some bugs