You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by my...@apache.org on 2020/02/18 13:43:37 UTC

[incubator-dlab] 01/02: [DLAB-1527]: function for apt-get/yum fixed

This is an automated email from the ASF dual-hosted git repository.

mykolabodnar pushed a commit to branch DLAB-1527
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit 5fe0f7c604111ee6b9ffaf93d6894fd1064fbc1a
Author: Mykola_Bodnar1 <bo...@gmail.com>
AuthorDate: Tue Feb 18 15:41:44 2020 +0200

    [DLAB-1527]: function for apt-get/yum fixed
---
 .../src/general/conf/dlab.ini                      |  2 +-
 .../src/general/lib/os/debian/common_lib.py        | 34 +++++++++++++---------
 .../src/general/lib/os/redhat/common_lib.py        | 34 +++++++++++++---------
 3 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/infrastructure-provisioning/src/general/conf/dlab.ini b/infrastructure-provisioning/src/general/conf/dlab.ini
index 9067abe..c37e0e3 100644
--- a/infrastructure-provisioning/src/general/conf/dlab.ini
+++ b/infrastructure-provisioning/src/general/conf/dlab.ini
@@ -356,4 +356,4 @@ expl_instance_memory = 8000
 #--- [reverse_proxy] reverse proxy settings ---#
 [reverse_proxy]
 ### Nginx version
-nginx_version = 1.15.1
+nginx_version = 1.15.1
\ No newline at end of file
diff --git a/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py b/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py
index 0d94ecf..fe9d136 100644
--- a/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py
+++ b/infrastructure-provisioning/src/general/lib/os/debian/common_lib.py
@@ -30,21 +30,29 @@ import time
 def manage_pkg(command, environment, requisites):
     try:
         allow = False
+        counter = 0
         while not allow:
-            if environment == 'remote':
-                if sudo('pgrep apt-get -a </dev/null &'):
-                    print('Package manager still working, pleae wait')
-                else:
-                    allow = True
-                    sudo('apt-get {0} {1}'.format(command, requisites))
-            elif environment == 'local':
-                if local('sudo pgrep apt-get -a </dev/null &'):
-                    print('Package manager still working, pleae wait')
-                else:
-                    allow = True
-                    local('sudo apt-get {0} {1}'.format(command, requisites))
+            if counter > 60:
+                print("Notebook is broken please recreate it.")
+                sys.exit(1)
             else:
-                print('Wrong environment')
+                print('Package manager is:')
+                if environment == 'remote':
+                    if sudo('pgrep apt-get -a && echo "busy" || echo "ready"') == 'busy':
+                        counter += 1
+                        time.sleep(10)
+                    else:
+                        allow = True
+                        sudo('apt-get {0} {1}'.format(command, requisites))
+                elif environment == 'local':
+                    if local('sudo pgrep apt-get -a && echo "busy" || echo "ready"', capture=True) == 'busy':
+                        counter += 1
+                        time.sleep(10)
+                    else:
+                        allow = True
+                        local('sudo apt-get {0} {1}'.format(command, requisites), capture=True)
+                else:
+                    print('Wrong environment')
     except:
         sys.exit(1)
 
diff --git a/infrastructure-provisioning/src/general/lib/os/redhat/common_lib.py b/infrastructure-provisioning/src/general/lib/os/redhat/common_lib.py
index d4209b8..ea5d4f2 100644
--- a/infrastructure-provisioning/src/general/lib/os/redhat/common_lib.py
+++ b/infrastructure-provisioning/src/general/lib/os/redhat/common_lib.py
@@ -29,21 +29,29 @@ import os
 def manage_pkg(command, environment, requisites):
     try:
         allow = False
+        counter = 0
         while not allow:
-            if environment == 'remote':
-                if sudo('pgrep yum -a </dev/null &'):
-                    print('Package manager still working, pleae wait')
-                else:
-                    allow = True
-                    sudo('yum {0} {1}'.format(command, requisites))
-            elif environment == 'local':
-                if local('sudo pgrep yum -a </dev/null &'):
-                    print('Package manager still working, pleae wait')
-                else:
-                    allow = True
-                    local('sudo yum {0} {1}'.format(command, requisites))
+            if counter > 60:
+                print("Notebook is broken please recreate it.")
+                sys.exit(1)
             else:
-                print('Wrong environment')
+                print('Package manager is:')
+                if environment == 'remote':
+                    if sudo('pgrep yum -a && echo "busy" || echo "ready"') == 'busy':
+                        counter += 1
+                        time.sleep(10)
+                    else:
+                        allow = True
+                        sudo('yum {0} {1}'.format(command, requisites))
+                elif environment == 'local':
+                    if local('sudo pgrep yum -a && echo "busy" || echo "ready"', capture=True) == 'busy':
+                        counter += 1
+                        time.sleep(10)
+                    else:
+                        allow = True
+                        local('sudo yum {0} {1}'.format(command, requisites), capture=True)
+                else:
+                    print('Wrong environment')
     except:
         sys.exit(1)
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org