summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspisarski <s.pisarski@cablelabs.com>2017-05-25 08:46:40 -0600
committerspisarski <s.pisarski@cablelabs.com>2017-05-25 08:46:40 -0600
commit5718894fcfb3e44dd08435cf71d2f1094425bed5 (patch)
tree49a3d582cb01bff697a648ee901372312d56bdb4
parent74386c6efb02cc352b0b090b7150813960ca1c95 (diff)
Updated installation documents and fixed problems found during investigation.
The code changes are primarily required when the runtime environment is Windows. JIRA: SNAPS-75 Change-Id: Ia2134861dd96e1d2c4b597f42fb348929e787a51 Signed-off-by: spisarski <s.pisarski@cablelabs.com>
-rw-r--r--docs/how-to-use/InstallSnaps.rst32
-rw-r--r--snaps/file_utils.py15
-rw-r--r--snaps/openstack/create_keypairs.py7
-rw-r--r--snaps/openstack/utils/glance_utils.py13
-rw-r--r--snaps/openstack/utils/tests/nova_utils_tests.py6
-rw-r--r--snaps/provisioning/ansible_utils.py11
6 files changed, 68 insertions, 16 deletions
diff --git a/docs/how-to-use/InstallSnaps.rst b/docs/how-to-use/InstallSnaps.rst
index df46743..dc53ef0 100644
--- a/docs/how-to-use/InstallSnaps.rst
+++ b/docs/how-to-use/InstallSnaps.rst
@@ -21,13 +21,35 @@ CentOS 7
::
- sudo yum install -7 git gcc python-pip python-devel openssl-devel
+ sudo yum -y update
+ sudo yum install -y epel-release
+ sudo yum install -y git gcc python-pip python-devel openssl-devel
+ sudo pip install --upgrade pip
-Ubuntu
-------
+Ubuntu 14.04
+------------
::
- sudo apt-get install git python2.7-dev libssl-dev
+ sudo apt-get install git python2.7-dev libssl-dev python-pip
+ sudo apt-get install corkscrew (optional for SSH over an HTTP proxy)
+
+Ubuntu 16.04
+------------
+::
+
+ sudo apt install python git python2.7-dev libssl-dev python-pip
+ sudo apt install corkscrew (optional for SSH over an HTTP proxy)
+
+Windows Server 2012
+-------------------
+::
+
+ Install Python 2.7.x
+ Install Git
+ Install Microsoft Visual C++ Compiler for Python 2.7
+
+ Cannot SSH from behind a proxy in the 'cmd' shell as corkscrew is only available for Cygwin
+ Ansible functionality is not working on windows as an exception is being thrown while importing the packages
Optional: Setup a Python virtual environment
--------------------------------------------
@@ -43,6 +65,8 @@ The "pip" command below needs to be executed as root, if you are not using a vir
::
+ git clone https://gerrit.opnfv.org/gerrit/snaps
sudo pip install -e <path to repo>/snaps/
+ (note: on CentOS 7 and Ubuntu 14.04 you may have to try the previous command several times)
The install should now be complete and you can start using the SNAPS-OO libraries.
diff --git a/snaps/file_utils.py b/snaps/file_utils.py
index 7b93a6d..819c707 100644
--- a/snaps/file_utils.py
+++ b/snaps/file_utils.py
@@ -55,11 +55,16 @@ def download(url, dest_path, name=None):
dest = dest_path + '/' + name
logger.debug('Downloading file from - ' + url)
# Override proxy settings to use localhost to download file
- with open(dest, 'wb') as f:
- logger.debug('Saving file to - ' + dest)
- response = __get_url_response(url)
- f.write(response.read())
- return f
+ f = None
+ try:
+ with open(dest, 'wb') as f:
+ logger.debug('Saving file to - ' + dest)
+ response = __get_url_response(url)
+ f.write(response.read())
+ return f
+ finally:
+ if f:
+ f.close()
def get_content_length(url):
diff --git a/snaps/openstack/create_keypairs.py b/snaps/openstack/create_keypairs.py
index 250acec..9b7b350 100644
--- a/snaps/openstack/create_keypairs.py
+++ b/snaps/openstack/create_keypairs.py
@@ -81,6 +81,13 @@ class OpenStackKeypair:
pass
self.__keypair = None
+ if self.keypair_settings.public_filepath:
+ os.chmod(self.keypair_settings.public_filepath, 0o777)
+ os.remove(self.keypair_settings.public_filepath)
+ if self.keypair_settings.private_filepath:
+ os.chmod(self.keypair_settings.private_filepath, 0o777)
+ os.remove(self.keypair_settings.private_filepath)
+
def get_keypair(self):
"""
Returns the OpenStack keypair object
diff --git a/snaps/openstack/utils/glance_utils.py b/snaps/openstack/utils/glance_utils.py
index 722cf4c..f4b4466 100644
--- a/snaps/openstack/utils/glance_utils.py
+++ b/snaps/openstack/utils/glance_utils.py
@@ -140,11 +140,18 @@ def __create_image_v2(glance, image_settings):
:raise Exception if using a file and it cannot be found
"""
cleanup_temp_file = False
+ image_file = None
if image_settings.image_file:
image_filename = image_settings.image_file
elif image_settings.url:
- image_file = file_utils.download(image_settings.url, '/tmp', str(uuid.uuid4()))
- image_filename = image_file.name
+ file_name = str(uuid.uuid4())
+ try:
+ image_file = file_utils.download(image_settings.url, './tmp', file_name)
+ image_filename = image_file.name
+ except:
+ os.remove('./tmp/' + file_name)
+ raise
+
cleanup_temp_file = True
else:
raise Exception('Filename or URL of image not configured')
@@ -171,6 +178,8 @@ def __create_image_v2(glance, image_settings):
delete_image(glance, created_image)
raise
finally:
+ if image_file:
+ image_file.close()
if cleanup_temp_file:
os.remove(image_filename)
diff --git a/snaps/openstack/utils/tests/nova_utils_tests.py b/snaps/openstack/utils/tests/nova_utils_tests.py
index 0a2b24b..98aa889 100644
--- a/snaps/openstack/utils/tests/nova_utils_tests.py
+++ b/snaps/openstack/utils/tests/nova_utils_tests.py
@@ -86,11 +86,13 @@ class NovaUtilsKeypairTests(OSComponentTestCase):
pass
try:
+ os.chmod(self.priv_key_file_path, 0o777)
os.remove(self.priv_key_file_path)
except:
pass
try:
+ os.chmod(self.pub_key_file_path, 0o777)
os.remove(self.pub_key_file_path)
except:
pass
@@ -126,7 +128,9 @@ class NovaUtilsKeypairTests(OSComponentTestCase):
"""
nova_utils.save_keys_to_files(self.keys, self.pub_key_file_path, self.priv_key_file_path)
self.keypair = nova_utils.upload_keypair_file(self.nova, self.keypair_name, self.pub_key_file_path)
- pub_key = open(os.path.expanduser(self.pub_key_file_path)).read()
+ pub_key_file = open(os.path.expanduser(self.pub_key_file_path))
+ pub_key = pub_key_file.read()
+ pub_key_file.close()
self.assertEqual(self.keypair.public_key, pub_key)
def test_floating_ips(self):
diff --git a/snaps/provisioning/ansible_utils.py b/snaps/provisioning/ansible_utils.py
index 3fbc88f..31750ee 100644
--- a/snaps/provisioning/ansible_utils.py
+++ b/snaps/provisioning/ansible_utils.py
@@ -19,10 +19,13 @@ from collections import namedtuple
import os
import paramiko
-from ansible.parsing.dataloader import DataLoader
-from ansible.vars import VariableManager
-from ansible.inventory import Inventory
-from ansible.executor.playbook_executor import PlaybookExecutor
+try:
+ from ansible.parsing.dataloader import DataLoader
+ from ansible.vars import VariableManager
+ from ansible.inventory import Inventory
+ from ansible.executor.playbook_executor import PlaybookExecutor
+except:
+ pass
__author__ = 'spisarski'