summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--snaps/deploy_venv.py114
-rw-r--r--snaps/openstack/create_instance.py19
-rw-r--r--snaps/openstack/tests/create_instance_tests.py125
-rw-r--r--snaps/openstack/utils/nova_utils.py4
-rw-r--r--snaps/provisioning/ansible_utils.py8
5 files changed, 175 insertions, 95 deletions
diff --git a/snaps/deploy_venv.py b/snaps/deploy_venv.py
index 10e444f..5f2e999 100644
--- a/snaps/deploy_venv.py
+++ b/snaps/deploy_venv.py
@@ -250,11 +250,14 @@ def __create_instances(os_conn_config, instances_config, image_dict, keypairs_di
return vm_dict
-def __apply_ansible_playbooks(ansible_configs, vm_dict, env_file):
+def __apply_ansible_playbooks(ansible_configs, os_conn_config, vm_dict, image_dict, flavor_dict, env_file):
"""
Applies ansible playbooks to running VMs with floating IPs
:param ansible_configs: a list of Ansible configurations
- :param vm_dict: the dictionary of newly instantiated VMs where the VM name is the key
+ :param os_conn_config: the OpenStack connection configuration used to create an OSCreds instance
+ :param vm_dict: the dictionary of newly instantiated VMs where the name is the key
+ :param image_dict: the dictionary of newly instantiated images where the name is the key
+ :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key
:param env_file: the path of the environment for setting the CWD so playbook location is relative to the deployment
file
:return: t/f - true if successful
@@ -274,7 +277,8 @@ def __apply_ansible_playbooks(ansible_configs, vm_dict, env_file):
# Apply playbooks
for ansible_config in ansible_configs:
- __apply_ansible_playbook(ansible_config, vm_dict)
+ os_creds = __get_os_credentials(os_conn_config)
+ __apply_ansible_playbook(ansible_config, os_creds, vm_dict, image_dict, flavor_dict)
# Return to original directory
os.chdir(orig_cwd)
@@ -282,20 +286,25 @@ def __apply_ansible_playbooks(ansible_configs, vm_dict, env_file):
return True
-def __apply_ansible_playbook(ansible_config, vm_dict):
+def __apply_ansible_playbook(ansible_config, os_creds, vm_dict, image_dict, flavor_dict):
"""
Applies an Ansible configuration setting
:param ansible_config: the configuration settings
- :param vm_dict: the dictionary of newly instantiated VMs where the VM name is the key
- :return:
+ :param os_creds: the OpenStack credentials object
+ :param vm_dict: the dictionary of newly instantiated VMs where the name is the key
+ :param image_dict: the dictionary of newly instantiated images where the name is the key
+ :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key
"""
if ansible_config:
remote_user, floating_ips, private_key_filepath, proxy_settings = __get_connection_info(ansible_config, vm_dict)
if floating_ips:
- ansible_utils.apply_playbook(ansible_config['playbook_location'], floating_ips, remote_user,
- private_key_filepath,
- variables=__get_variables(ansible_config.get('variables'), vm_dict),
- proxy_setting=proxy_settings)
+ retval = ansible_utils.apply_playbook(
+ ansible_config['playbook_location'], floating_ips, remote_user, private_key_filepath,
+ variables=__get_variables(ansible_config.get('variables'), os_creds, vm_dict, image_dict, flavor_dict),
+ proxy_setting=proxy_settings)
+ if retval != 0:
+ # Not a fatal type of event
+ logger.warn('Unable to apply playbook found at location - ' + ansible_config('playbook_location'))
def __get_connection_info(ansible_config, vm_dict):
@@ -336,17 +345,20 @@ def __get_connection_info(ansible_config, vm_dict):
return None
-def __get_variables(var_config, vm_dict):
+def __get_variables(var_config, os_creds, vm_dict, image_dict, flavor_dict):
"""
Returns a dictionary of substitution variables to be used for Ansible templates
:param var_config: the variable configuration settings
- :param vm_dict: the dictionary of VMs where the VM name is the key
+ :param os_creds: the OpenStack credentials object
+ :param vm_dict: the dictionary of newly instantiated VMs where the name is the key
+ :param image_dict: the dictionary of newly instantiated images where the name is the key
+ :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key
:return: dictionary or None
"""
if var_config and vm_dict and len(vm_dict) > 0:
variables = dict()
for key, value in var_config.iteritems():
- value = __get_variable_value(value, vm_dict)
+ value = __get_variable_value(value, os_creds, vm_dict, image_dict, flavor_dict)
if key and value:
variables[key] = value
logger.info("Set Jinga2 variable with key [" + key + "] the value [" + value + ']')
@@ -356,11 +368,14 @@ def __get_variables(var_config, vm_dict):
return None
-def __get_variable_value(var_config_values, vm_dict):
+def __get_variable_value(var_config_values, os_creds, vm_dict, image_dict, flavor_dict):
"""
Returns the associated variable value for use by Ansible for substitution purposes
:param var_config_values: the configuration dictionary
- :param vm_dict: the dictionary containing all VMs where the key is the VM's name
+ :param os_creds: the OpenStack credentials object
+ :param vm_dict: the dictionary of newly instantiated VMs where the name is the key
+ :param image_dict: the dictionary of newly instantiated images where the name is the key
+ :param flavor_dict: the dictionary of newly instantiated flavors where the name is the key
:return:
"""
if var_config_values['type'] == 'string':
@@ -368,9 +383,13 @@ def __get_variable_value(var_config_values, vm_dict):
if var_config_values['type'] == 'vm-attr':
return __get_vm_attr_variable_value(var_config_values, vm_dict)
if var_config_values['type'] == 'os_creds':
- return __get_os_creds_variable_value(var_config_values, vm_dict)
+ return __get_os_creds_variable_value(var_config_values, os_creds)
if var_config_values['type'] == 'port':
return __get_vm_port_variable_value(var_config_values, vm_dict)
+ if var_config_values['type'] == 'image':
+ return __get_image_variable_value(var_config_values, image_dict)
+ if var_config_values['type'] == 'flavor':
+ return __get_flavor_variable_value(var_config_values, flavor_dict)
return None
@@ -394,31 +413,31 @@ def __get_vm_attr_variable_value(var_config_values, vm_dict):
if vm:
if var_config_values['value'] == 'floating_ip':
return vm.get_floating_ip().ip
+ if var_config_values['value'] == 'image_user':
+ return vm.get_image_user()
-def __get_os_creds_variable_value(var_config_values, vm_dict):
+def __get_os_creds_variable_value(var_config_values, os_creds):
"""
Returns the associated OS credentials value
:param var_config_values: the configuration dictionary
- :param vm_dict: the dictionary containing all VMs where the key is the VM's name
+ :param os_creds: the credentials
:return: the value
"""
logger.info("Retrieving OS Credentials")
- vm = vm_dict.values()[0]
-
- if vm:
+ if os_creds:
if var_config_values['value'] == 'username':
logger.info("Returning OS username")
- return vm.get_os_creds().username
+ return os_creds.username
elif var_config_values['value'] == 'password':
logger.info("Returning OS password")
- return vm.get_os_creds().password
+ return os_creds.password
elif var_config_values['value'] == 'auth_url':
logger.info("Returning OS auth_url")
- return vm.get_os_creds().auth_url
+ return os_creds.auth_url
elif var_config_values['value'] == 'project_name':
logger.info("Returning OS project_name")
- return vm.get_os_creds().project_name
+ return os_creds.project_name
logger.info("Returning none")
return None
@@ -445,6 +464,48 @@ def __get_vm_port_variable_value(var_config_values, vm_dict):
return vm.get_port_ip(port_name)
+def __get_image_variable_value(var_config_values, image_dict):
+ """
+ Returns the associated image value
+ :param var_config_values: the configuration dictionary
+ :param image_dict: the dictionary containing all images where the key is the name
+ :return: the value
+ """
+ logger.info("Retrieving image values")
+
+ if image_dict:
+ if var_config_values.get('image_name'):
+ image_creator = image_dict.get(var_config_values['image_name'])
+ if image_creator:
+ if var_config_values.get('value') and var_config_values['value'] == 'id':
+ return image_creator.get_image().id
+ if var_config_values.get('value') and var_config_values['value'] == 'user':
+ return image_creator.image_settings.image_user
+
+ logger.info("Returning none")
+ return None
+
+
+def __get_flavor_variable_value(var_config_values, flavor_dict):
+ """
+ Returns the associated flavor value
+ :param var_config_values: the configuration dictionary
+ :param flavor_dict: the dictionary containing all flavor creators where the key is the name
+ :return: the value or None
+ """
+ logger.info("Retrieving flavor values")
+
+ if flavor_dict:
+ if var_config_values.get('flavor_name'):
+ flavor_creator = flavor_dict.get(var_config_values['flavor_name'])
+ if flavor_creator:
+ if var_config_values.get('value') and var_config_values['value'] == 'id':
+ return flavor_creator.get_flavor().id
+
+ logger.info("Returning none")
+ return None
+
+
def main(arguments):
"""
Will need to set environment variable ANSIBLE_HOST_KEY_CHECKING=False or ...
@@ -523,7 +584,8 @@ def main(arguments):
# Provision VMs
ansible_config = config.get('ansible')
if ansible_config and vm_dict:
- if not __apply_ansible_playbooks(ansible_config, vm_dict, arguments.environment):
+ if not __apply_ansible_playbooks(ansible_config, os_conn_config, vm_dict, image_dict, flavor_dict,
+ arguments.environment):
logger.error("Problem applying ansible playbooks")
else:
logger.error('Unable to read configuration file - ' + arguments.environment)
diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py
index caddc05..620483b 100644
--- a/snaps/openstack/create_instance.py
+++ b/snaps/openstack/create_instance.py
@@ -131,9 +131,10 @@ class OpenStackVmInstance:
image=image,
nics=nics,
key_name=keypair_name,
- security_groups=list(self.instance_settings.security_group_names),
+ security_groups=self.instance_settings.security_group_names,
userdata=self.instance_settings.userdata,
availability_zone=self.instance_settings.availability_zone)
+
else:
raise Exception('Cannot create instance, image cannot be located with name ' + self.image_settings.name)
@@ -142,6 +143,11 @@ class OpenStackVmInstance:
if block:
self.vm_active(block=True)
+ # TODO - the call above should add security groups. The return object shows they exist but the association
+ # had never been made by OpenStack. This call is here to ensure they have been added
+ for sec_grp_name in self.instance_settings.security_group_names:
+ nova_utils.add_security_group(self.__nova, self.__vm, sec_grp_name)
+
self.__apply_floating_ips()
def __apply_floating_ips(self):
@@ -594,14 +600,14 @@ class OpenStackVmInstance:
self.vm_active(block=True)
if not security_group:
- logger.warn('Security group object is None, cannot add')
+ logger.warn('Security group object is None, cannot remove')
return False
try:
- nova_utils.remove_security_group(self.__nova, self.get_vm_inst(), security_group['security_group']['name'])
+ nova_utils.remove_security_group(self.__nova, self.get_vm_inst(), security_group)
return True
except NotFound as e:
- logger.warn('Security group not added - ' + e.message)
+ logger.warn('Security group not removed - ' + e.message)
return False
@@ -618,7 +624,7 @@ class VmInstanceSettings:
member's the key and overrides any of the other parameters.
:param name: the name of the VM
:param flavor: the VM's flavor
- :param port_settings: the port configuration settings
+ :param port_settings: the port configuration settings (required)
:param security_group_names: a set of names of the security groups to add to the VM
:param floating_ip_settings: the floating IP configuration settings
:param sudo_user: the sudo user of the VM that will override the instance_settings.image_user when trying to
@@ -698,6 +704,9 @@ class VmInstanceSettings:
if not self.name or not self.flavor:
raise Exception('Instance configuration requires the attributes: name, flavor')
+ if len(self.port_settings) == 0:
+ raise Exception('Instance configuration requires port settings (aka. NICS)')
+
class FloatingIpSettings:
"""
diff --git a/snaps/openstack/tests/create_instance_tests.py b/snaps/openstack/tests/create_instance_tests.py
index d733547..1daf701 100644
--- a/snaps/openstack/tests/create_instance_tests.py
+++ b/snaps/openstack/tests/create_instance_tests.py
@@ -14,6 +14,7 @@
# limitations under the License.
import logging
import os
+import re
import time
import unittest
import uuid
@@ -58,10 +59,21 @@ class VmInstanceSettingsUnitTests(unittest.TestCase):
VmInstanceSettings(config={'name': 'foo'})
def test_name_flavor_only(self):
- settings = VmInstanceSettings(name='foo', flavor='bar')
+ with self.assertRaises(Exception):
+ VmInstanceSettings(name='foo', flavor='bar')
+
+ def test_config_with_name_flavor_only(self):
+ with self.assertRaises(Exception):
+ VmInstanceSettings(config={'name': 'foo', 'flavor': 'bar'})
+
+ def test_name_flavor_port_only(self):
+ port_settings = PortSettings(name='foo-port', network_name='bar-net')
+ settings = VmInstanceSettings(name='foo', flavor='bar', port_settings=[port_settings])
self.assertEquals('foo', settings.name)
self.assertEquals('bar', settings.flavor)
- self.assertEquals(0, len(settings.port_settings))
+ self.assertEquals(1, len(settings.port_settings))
+ self.assertEquals('foo-port', settings.port_settings[0].name)
+ self.assertEquals('bar-net', settings.port_settings[0].network_name)
self.assertEquals(0, len(settings.security_group_names))
self.assertEquals(0, len(settings.floating_ip_settings))
self.assertIsNone(settings.sudo_user)
@@ -70,11 +82,14 @@ class VmInstanceSettingsUnitTests(unittest.TestCase):
self.assertEquals(180, settings.ssh_connect_timeout)
self.assertIsNone(settings.availability_zone)
- def test_config_with_name_flavor_only(self):
- settings = VmInstanceSettings(config={'name': 'foo', 'flavor': 'bar'})
+ def test_config_with_name_flavor_port_only(self):
+ port_settings = PortSettings(name='foo-port', network_name='bar-net')
+ settings = VmInstanceSettings(config={'name': 'foo', 'flavor': 'bar', 'ports': [port_settings]})
self.assertEquals('foo', settings.name)
self.assertEquals('bar', settings.flavor)
- self.assertEquals(0, len(settings.port_settings))
+ self.assertEquals(1, len(settings.port_settings))
+ self.assertEquals('foo-port', settings.port_settings[0].name)
+ self.assertEquals('bar-net', settings.port_settings[0].network_name)
self.assertEquals(0, len(settings.security_group_names))
self.assertEquals(0, len(settings.floating_ip_settings))
self.assertIsNone(settings.sudo_user)
@@ -311,15 +326,22 @@ class SimpleHealthCheck(OSIntegrationTestCase):
self.assertTrue(self.inst_creator.vm_active(block=True))
found = False
- timeout = 100
+ timeout = 160
start_time = time.time()
- match_value = 'Lease of ' + ip + ' obtained,'
+ match_value = 'Lease of.*obtained'
+ logger.info("Looking for expression %s in the console log" % match_value)
while timeout > time.time() - start_time:
output = vm.get_console_output()
- if match_value in output:
- found = True
+ if re.search(match_value, output):
+ logger.info('DHCP lease obtained logged in console')
+ if ip in output:
+ logger.info('With correct IP address')
+ found = True
+ else:
+ logger.error('With incorrect IP address')
break
+
self.assertTrue(found)
@@ -339,20 +361,35 @@ class CreateInstanceSimpleTests(OSIntegrationTestCase):
self.nova = nova_utils.nova_client(self.os_creds)
self.os_image_settings = openstack_tests.cirros_url_image(name=guid + '-image')
+ net_config = openstack_tests.get_priv_net_config(
+ net_name=guid + '-pub-net', subnet_name=guid + '-pub-subnet',
+ router_name=guid + '-pub-router', external_net=self.ext_net_name)
+
# Initialize for tearDown()
self.image_creator = None
self.flavor_creator = None
+
+ self.net_creator = None
self.inst_creator = None
try:
# Create Image
self.image_creator = OpenStackImage(self.os_creds, self.os_image_settings)
self.image_creator.create()
+
# Create Flavor
self.flavor_creator = OpenStackFlavor(
self.admin_os_creds,
FlavorSettings(name=guid + '-flavor-name', ram=2048, disk=10, vcpus=2))
self.flavor_creator.create()
+
+ # Create Network
+ self.network_creator = OpenStackNetwork(self.os_creds, net_config.network_settings)
+ self.network_creator.create()
+
+ self.port_settings = PortSettings(name=guid + '-port',
+ network_name=net_config.network_settings.name)
+
except Exception as e:
self.tearDown()
raise e
@@ -373,6 +410,12 @@ class CreateInstanceSimpleTests(OSIntegrationTestCase):
except Exception as e:
logger.error('Unexpected exception cleaning flavor with message - ' + e.message)
+ if self.net_creator:
+ try:
+ self.net_creator.clean()
+ except Exception as e:
+ logger.error('Unexpected exception cleaning network with message - ' + e.message)
+
if self.image_creator:
try:
self.image_creator.clean()
@@ -385,7 +428,8 @@ class CreateInstanceSimpleTests(OSIntegrationTestCase):
"""
Tests the creation of an OpenStack instance with a single port with a static IP without a Floating IP.
"""
- instance_settings = VmInstanceSettings(name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name)
+ instance_settings = VmInstanceSettings(name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name,
+ port_settings=[self.port_settings])
self.inst_creator = OpenStackVmInstance(
self.os_creds, instance_settings, self.image_creator.image_settings)
@@ -1196,21 +1240,17 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
self.nova = nova_utils.nova_client(self.os_creds)
self.os_image_settings = openstack_tests.cirros_url_image(name=self.guid + '-image')
- self.keypair_priv_filepath = 'tmp/' + self.guid
- self.keypair_pub_filepath = self.keypair_priv_filepath + '.pub'
- self.keypair_name = self.guid + '-kp'
self.vm_inst_name = self.guid + '-inst'
self.port_1_name = self.guid + 'port-1'
self.port_2_name = self.guid + 'port-2'
self.floating_ip_name = self.guid + 'fip1'
- self.pub_net_config = openstack_tests.get_pub_net_config(
+ net_config = openstack_tests.get_priv_net_config(
net_name=self.guid + '-pub-net', subnet_name=self.guid + '-pub-subnet',
router_name=self.guid + '-pub-router', external_net=self.ext_net_name)
# Initialize for tearDown()
self.image_creator = None
- self.keypair_creator = None
self.flavor_creator = None
self.network_creator = None
self.router_creator = None
@@ -1223,24 +1263,17 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
self.image_creator.create()
# Create Network
- self.network_creator = OpenStackNetwork(self.os_creds, self.pub_net_config.network_settings)
+ self.network_creator = OpenStackNetwork(self.os_creds, net_config.network_settings)
self.network_creator.create()
- # Create Router
- self.router_creator = OpenStackRouter(self.os_creds, self.pub_net_config.router_settings)
- self.router_creator.create()
-
# Create Flavor
self.flavor_creator = OpenStackFlavor(
self.admin_os_creds,
FlavorSettings(name=self.guid + '-flavor-name', ram=2048, disk=10, vcpus=2))
self.flavor_creator.create()
- self.keypair_creator = OpenStackKeypair(
- self.os_creds, KeypairSettings(
- name=self.keypair_name, public_filepath=self.keypair_pub_filepath,
- private_filepath=self.keypair_priv_filepath))
- self.keypair_creator.create()
+ self.port_settings = PortSettings(name=self.guid + '-port',
+ network_name=net_config.network_settings.name)
except Exception as e:
self.tearDown()
raise e
@@ -1261,30 +1294,12 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
except Exception as e:
logger.error('Unexpected exception cleaning security group with message - ' + e.message)
- if self.keypair_creator:
- try:
- self.keypair_creator.clean()
- except Exception as e:
- logger.error('Unexpected exception cleaning keypair with message - ' + e.message)
-
- if os.path.isfile(self.keypair_pub_filepath):
- os.remove(self.keypair_pub_filepath)
-
- if os.path.isfile(self.keypair_priv_filepath):
- os.remove(self.keypair_priv_filepath)
-
if self.flavor_creator:
try:
self.flavor_creator.clean()
except Exception as e:
logger.error('Unexpected exception cleaning flavor with message - ' + e.message)
- if self.router_creator:
- try:
- self.router_creator.clean()
- except Exception as e:
- logger.error('Unexpected exception cleaning router with message - ' + e.message)
-
if self.network_creator:
try:
self.network_creator.clean()
@@ -1305,9 +1320,9 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
"""
# Create instance
instance_settings = VmInstanceSettings(
- name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name)
+ name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings])
self.inst_creator = OpenStackVmInstance(self.os_creds, instance_settings, self.image_creator.image_settings)
- vm_inst = self.inst_creator.create()
+ vm_inst = self.inst_creator.create(block=True)
self.assertIsNotNone(vm_inst)
# Create security group object to add to instance
@@ -1331,9 +1346,9 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
"""
# Create instance
instance_settings = VmInstanceSettings(
- name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name)
+ name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings])
self.inst_creator = OpenStackVmInstance(self.os_creds, instance_settings, self.image_creator.image_settings)
- vm_inst = self.inst_creator.create()
+ vm_inst = self.inst_creator.create(block=True)
self.assertIsNotNone(vm_inst)
# Create security group object to add to instance
@@ -1365,9 +1380,9 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
# Create instance
instance_settings = VmInstanceSettings(
name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name,
- security_group_names=[sec_grp_settings.name])
+ security_group_names=[sec_grp_settings.name], port_settings=[self.port_settings])
self.inst_creator = OpenStackVmInstance(self.os_creds, instance_settings, self.image_creator.image_settings)
- vm_inst = self.inst_creator.create()
+ vm_inst = self.inst_creator.create(block=True)
self.assertIsNotNone(vm_inst)
# Check that group has been added
@@ -1391,13 +1406,13 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
# Create instance
instance_settings = VmInstanceSettings(
- name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name)
+ name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name, port_settings=[self.port_settings])
self.inst_creator = OpenStackVmInstance(self.os_creds, instance_settings, self.image_creator.image_settings)
- vm_inst = self.inst_creator.create()
+ vm_inst = self.inst_creator.create(block=True)
self.assertIsNotNone(vm_inst)
# Check that group has been added
- self.assertFalse(inst_has_sec_grp(vm_inst, sec_grp_settings.name))
+ self.assertFalse(inst_has_sec_grp(self.inst_creator.get_vm_inst(), sec_grp_settings.name))
# Add security group to instance after activated
self.assertFalse(self.inst_creator.remove_security_group(sec_grp))
@@ -1418,13 +1433,13 @@ class InstanceSecurityGroupTests(OSIntegrationTestCase):
# Create instance
instance_settings = VmInstanceSettings(
name=self.vm_inst_name, flavor=self.flavor_creator.flavor_settings.name,
- security_group_names=[sec_grp_settings.name])
+ security_group_names=[sec_grp_settings.name], port_settings=[self.port_settings])
self.inst_creator = OpenStackVmInstance(self.os_creds, instance_settings, self.image_creator.image_settings)
- vm_inst = self.inst_creator.create()
+ vm_inst = self.inst_creator.create(block=True)
self.assertIsNotNone(vm_inst)
# Check that group has been added
- self.assertTrue(inst_has_sec_grp(vm_inst, sec_grp_settings.name))
+ self.assertTrue(inst_has_sec_grp(self.inst_creator.get_vm_inst(), sec_grp_settings.name))
# Add security group to instance after activated
self.assertTrue(self.inst_creator.add_security_group(sec_grp))
diff --git a/snaps/openstack/utils/nova_utils.py b/snaps/openstack/utils/nova_utils.py
index 9d0f70f..e7428ed 100644
--- a/snaps/openstack/utils/nova_utils.py
+++ b/snaps/openstack/utils/nova_utils.py
@@ -269,7 +269,7 @@ def add_security_group(nova, vm, security_group_name):
:param vm: the OpenStack server object (VM) to alter
:param security_group_name: the name of the security group to add
"""
- nova.servers.add_security_group(vm.id, security_group_name)
+ nova.servers.add_security_group(str(vm.id), security_group_name)
def remove_security_group(nova, vm, security_group):
@@ -279,4 +279,4 @@ def remove_security_group(nova, vm, security_group):
:param vm: the OpenStack server object (VM) to alter
:param security_group: the OpenStack security group object to add
"""
- nova.servers.remove_security_group(vm.id, security_group)
+ nova.servers.remove_security_group(str(vm.id), security_group['security_group']['name'])
diff --git a/snaps/provisioning/ansible_utils.py b/snaps/provisioning/ansible_utils.py
index 36f1efc..39ae1e6 100644
--- a/snaps/provisioning/ansible_utils.py
+++ b/snaps/provisioning/ansible_utils.py
@@ -79,13 +79,7 @@ def apply_playbook(playbook_path, hosts_inv, host_user, ssh_priv_key_file_path,
passwords=None)
logger.debug('Executing Ansible Playbook - ' + playbook_path)
- retval = executor.run()
-
- if retval != 0:
- logger.error('Playbook application failed [' + playbook_path + '] with return value of - ' + str(retval))
- raise Exception('Playbook not applied - ' + playbook_path)
-
- return retval
+ return executor.run()
def ssh_client(ip, user, private_key_filepath, proxy_settings=None):