summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-05-19 11:12:22 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-05-19 11:14:29 -0600
commit0f6dc6e618b5546a652b9a06ac46ae332ea1c4c3 (patch)
treec7cc7bc8ab028ad9aecd8bbd7d24387134f35054
parent8d8af3c360b360c982b44ba343a97cf5949c8c20 (diff)
Fixed error in ansible_utils_tests.py and added ansible helper
method to the OpenStackVMInstance class. Test error was due to the image configuration having the incorrect user applied. The helper method will make it easier for adhoc ansible playbooks to be applied to running instances. JIRA: SNAPS-83 Change-Id: I6b229e0adb836dd3d5ea7b468d38d93f880589a2 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--snaps/openstack/create_instance.py17
-rw-r--r--snaps/openstack/tests/openstack_tests.py2
-rw-r--r--snaps/provisioning/tests/ansible_utils_tests.py8
3 files changed, 19 insertions, 8 deletions
diff --git a/snaps/openstack/create_instance.py b/snaps/openstack/create_instance.py
index bb101ba..3e4fd93 100644
--- a/snaps/openstack/create_instance.py
+++ b/snaps/openstack/create_instance.py
@@ -412,6 +412,7 @@ class OpenStackVmInstance:
:param nic_name: Name of the interface
:param port: The port information containing the expected IP values.
:param floating_ip: The floating IP on which to apply the playbook.
+ :return: the return value from ansible
"""
ip = port['port']['fixed_ips'][0]['ip_address']
variables = {
@@ -421,13 +422,23 @@ class OpenStackVmInstance:
}
if self.image_settings.nic_config_pb_loc and self.keypair_settings:
- ansible_utils.apply_playbook(self.image_settings.nic_config_pb_loc,
- [floating_ip], self.get_image_user(), self.keypair_settings.private_filepath,
- variables, self.__os_creds.proxy_settings)
+ return self.apply_ansible_playbook(self.image_settings.nic_config_pb_loc, variables)
else:
logger.warning('VM ' + self.instance_settings.name + ' cannot self configure NICs eth1++. ' +
'No playbook or keypairs found.')
+ def apply_ansible_playbook(self, pb_file_loc, variables=None, fip_name=None):
+ """
+ Applies a playbook to a VM
+ :param pb_file_loc: the file location of the playbook to be applied
+ :param variables: a dict() of substitution values required by the playbook
+ :param fip_name: the name of the floating IP to use for applying the playbook (default - will take the first)
+ :return: the return value from ansible
+ """
+ return ansible_utils.apply_playbook(pb_file_loc, [self.get_floating_ip(fip_name=fip_name).ip],
+ self.get_image_user(), self.keypair_settings.private_filepath,
+ variables, self.__os_creds.proxy_settings)
+
def get_image_user(self):
"""
Returns the instance sudo_user if it has been configured in the instance_settings else it returns the
diff --git a/snaps/openstack/tests/openstack_tests.py b/snaps/openstack/tests/openstack_tests.py
index 836c293..22c4677 100644
--- a/snaps/openstack/tests/openstack_tests.py
+++ b/snaps/openstack/tests/openstack_tests.py
@@ -232,7 +232,7 @@ def ubuntu_image_settings(name, url=None, image_metadata=None, kernel_settings=N
metadata = image_metadata
return create_image_settings(
- image_name=name, image_user=CENTOS_USER, image_format=DEFAULT_IMAGE_FORMAT, metadata=metadata, disk_url=url,
+ image_name=name, image_user=UBUNTU_USER, image_format=DEFAULT_IMAGE_FORMAT, metadata=metadata, disk_url=url,
default_url=UBUNTU_DEFAULT_IMAGE_URL,
kernel_settings=kernel_settings, ramdisk_settings=ramdisk_settings, public=public)
diff --git a/snaps/provisioning/tests/ansible_utils_tests.py b/snaps/provisioning/tests/ansible_utils_tests.py
index 52977f0..c39bde4 100644
--- a/snaps/provisioning/tests/ansible_utils_tests.py
+++ b/snaps/provisioning/tests/ansible_utils_tests.py
@@ -171,8 +171,7 @@ class AnsibleProvisioningTests(OSIntegrationTestCase):
user = self.inst_creator.get_image_user()
priv_key = self.inst_creator.keypair_settings.private_filepath
- retval = ansible_utils.apply_playbook('provisioning/tests/playbooks/simple_playbook.yml', [ip], user, priv_key,
- proxy_setting=self.os_creds.proxy_settings)
+ retval = self.inst_creator.apply_ansible_playbook('provisioning/tests/playbooks/simple_playbook.yml')
self.assertEqual(0, retval)
ssh = ansible_utils.ssh_client(ip, user, priv_key, self.os_creds.proxy_settings)
@@ -203,8 +202,9 @@ class AnsibleProvisioningTests(OSIntegrationTestCase):
user = self.inst_creator.get_image_user()
priv_key = self.inst_creator.keypair_settings.private_filepath
- ansible_utils.apply_playbook('provisioning/tests/playbooks/template_playbook.yml', [ip], user, priv_key,
- variables={'name': 'Foo'}, proxy_setting=self.os_creds.proxy_settings)
+ retval = self.inst_creator.apply_ansible_playbook('provisioning/tests/playbooks/template_playbook.yml',
+ variables={'name': 'Foo'})
+ self.assertEqual(0, retval)
ssh = ansible_utils.ssh_client(ip, user, priv_key, self.os_creds.proxy_settings)
self.assertIsNotNone(ssh)