diff options
author | Steven Pisarski <s.pisarski@cablelabs.com> | 2017-05-22 13:24:48 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-05-22 13:24:48 +0000 |
commit | c2d7aa60a04e3e7239603942e7d94be9a39828ae (patch) | |
tree | 5cc0273e2616ee1e423dc19b3f8bf360d58c68eb | |
parent | fbfb1489ae0069bf0623bb40efd9594e354b86bf (diff) | |
parent | 0f6dc6e618b5546a652b9a06ac46ae332ea1c4c3 (diff) |
Merge "Fixed error in ansible_utils_tests.py and added ansible helper method to the OpenStackVMInstance class."
-rw-r--r-- | snaps/openstack/create_instance.py | 17 | ||||
-rw-r--r-- | snaps/openstack/tests/openstack_tests.py | 2 | ||||
-rw-r--r-- | snaps/provisioning/tests/ansible_utils_tests.py | 8 |
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) |