Updated installation documents and fixed problems found during investigation. 67/35367/1
authorspisarski <s.pisarski@cablelabs.com>
Thu, 25 May 2017 14:46:40 +0000 (08:46 -0600)
committerspisarski <s.pisarski@cablelabs.com>
Thu, 25 May 2017 14:46:40 +0000 (08:46 -0600)
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>
docs/how-to-use/InstallSnaps.rst
snaps/file_utils.py
snaps/openstack/create_keypairs.py
snaps/openstack/utils/glance_utils.py
snaps/openstack/utils/tests/nova_utils_tests.py
snaps/provisioning/ansible_utils.py

index df46743..dc53ef0 100644 (file)
@@ -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.
index 7b93a6d..819c707 100644 (file)
@@ -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):
index 250acec..9b7b350 100644 (file)
@@ -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
index 722cf4c..f4b4466 100644 (file)
@@ -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)
 
index 0a2b24b..98aa889 100644 (file)
@@ -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):
index 3fbc88f..31750ee 100644 (file)
@@ -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'