Add timeout option for deployment 59/10059/2
authorPeter Barabas <peter.barabas@ericsson.com>
Tue, 16 Feb 2016 12:33:46 +0000 (13:33 +0100)
committerJonas Bjurel <jonas.bjurel@ericsson.com>
Wed, 24 Feb 2016 14:16:30 +0000 (14:16 +0000)
Change-Id: I6f3f35680c9f90f99148865edf8ba905ecbb6c30
Signed-off-by: Peter Barabas <peter.barabas@ericsson.com>
deploy/cloud/deploy.py
deploy/cloud/deployment.py
deploy/deploy.py
deploy/deploy_env.py

index 679b0ad..3d3017e 100644 (file)
@@ -29,9 +29,10 @@ YAML_CONF_DIR = '/var/lib/opnfv'
 
 class Deploy(object):
 
-    def __init__(self, dea_file, no_health_check):
+    def __init__(self, dea_file, no_health_check, deploy_timeout):
         self.dea = DeploymentEnvironmentAdapter(dea_file)
         self.no_health_check = no_health_check
+        self.deploy_timeout = deploy_timeout
         self.macs_per_blade = {}
         self.blades = self.dea.get_node_ids()
         self.blade_node_dict = self.dea.get_blade_node_map()
@@ -59,7 +60,8 @@ class Deploy(object):
 
     def deploy_cloud(self):
         dep = Deployment(self.dea, YAML_CONF_DIR, self.env_id,
-                         self.node_roles_dict, self.no_health_check)
+                         self.node_roles_dict, self.no_health_check,
+                         self.deploy_timeout)
         dep.deploy()
 
     def deploy(self):
@@ -76,13 +78,17 @@ def parse_arguments():
     parser.add_argument('-nh', dest='no_health_check', action='store_true',
                         default=False,
                         help='Don\'t run health check after deployment')
+    parser.add_argument('-dt', dest='deploy_timeout', action='store',
+                        default=240, help='Deployment timeout (in minutes) '
+                        '[default: 240]')
     parser.add_argument('dea_file', action='store',
                         help='Deployment Environment Adapter: dea.yaml')
     args = parser.parse_args()
     check_file_exists(args.dea_file)
 
     kwargs = {'dea_file': args.dea_file,
-              'no_health_check': args.no_health_check}
+              'no_health_check': args.no_health_check,
+              'deploy_timeout': args.deploy_timeout}
     return kwargs
 
 
index 42bab09..306abf0 100644 (file)
@@ -31,12 +31,13 @@ LIST_OF_CHAR_TO_BE_ESCAPED = ['[', ']', '"']
 class Deployment(object):
 
     def __init__(self, dea, yaml_config_dir, env_id, node_id_roles_dict,
-                 no_health_check):
+                 no_health_check, deploy_timeout):
         self.dea = dea
         self.yaml_config_dir = yaml_config_dir
         self.env_id = env_id
         self.node_id_roles_dict = node_id_roles_dict
         self.no_health_check = no_health_check
+        self.deploy_timeout = deploy_timeout
         self.pattern = re.compile(
             '\d\d\d\d-\d\d-\d\d\s\d\d:\d\d:\d\d')
 
@@ -96,7 +97,6 @@ class Deployment(object):
                     print(log_msg + '\n')
 
     def run_deploy(self):
-        WAIT_LOOP = 240
         SLEEP_TIME = 60
         LOG_FILE = 'cloud.log'
 
@@ -105,7 +105,7 @@ class Deployment(object):
                  % (self.env_id, LOG_FILE))
 
         ready = False
-        for i in range(WAIT_LOOP):
+        for i in range(int(self.deploy_timeout)):
             env = parse(exec_cmd('fuel env --env %s' % self.env_id))
             log('Environment status: %s' % env[0][E['status']])
             r, _ = exec_cmd('tail -2 %s | head -1' % LOG_FILE, False)
index bf0b39d..bc1dfdb 100755 (executable)
@@ -61,7 +61,7 @@ class AutoDeploy(object):
     def __init__(self, no_fuel, fuel_only, no_health_check, cleanup_only,
                  cleanup, storage_dir, pxe_bridge, iso_file, dea_file,
                  dha_file, fuel_plugins_dir, fuel_plugins_conf_dir,
-                 no_plugins):
+                 no_plugins, deploy_timeout):
         self.no_fuel = no_fuel
         self.fuel_only = fuel_only
         self.no_health_check = no_health_check
@@ -75,6 +75,7 @@ class AutoDeploy(object):
         self.fuel_plugins_dir = fuel_plugins_dir
         self.fuel_plugins_conf_dir = fuel_plugins_conf_dir
         self.no_plugins = no_plugins
+        self.deploy_timeout = deploy_timeout
         self.dea = (DeploymentEnvironmentAdapter(dea_file)
                     if not cleanup_only else None)
         self.dha = DeploymentHardwareAdapter(dha_file)
@@ -197,7 +198,7 @@ class AutoDeploy(object):
         dep = CloudDeploy(self.dea, self.dha, self.fuel_conf['ip'],
                           self.fuel_username, self.fuel_password,
                           self.dea_file, self.fuel_plugins_conf_dir,
-                          WORK_DIR, self.no_health_check)
+                          WORK_DIR, self.no_health_check, self.deploy_timeout)
         return dep.deploy()
 
     def setup_execution_environment(self):
@@ -313,6 +314,9 @@ def parse_arguments():
                         help='Fuel Plugins Configuration directory')
     parser.add_argument('-np', dest='no_plugins', action='store_true',
                         default=False, help='Do not install Fuel Plugins')
+    parser.add_argument('-dt', dest='deploy_timeout', action='store',
+                        default=240, help='Deployment timeout (in minutes) '
+                        '[default: 240]')
 
     args = parser.parse_args()
     log(args)
@@ -338,7 +342,8 @@ def parse_arguments():
               'dha_file': args.dha_file,
               'fuel_plugins_dir': args.fuel_plugins_dir,
               'fuel_plugins_conf_dir': args.fuel_plugins_conf_dir,
-              'no_plugins': args.no_plugins}
+              'no_plugins': args.no_plugins,
+              'deploy_timeout': args.deploy_timeout}
     return kwargs
 
 
index 735ea66..3d1cdf4 100644 (file)
@@ -34,7 +34,8 @@ BLADE_RESTART_TIMES = 3
 class CloudDeploy(object):
 
     def __init__(self, dea, dha, fuel_ip, fuel_username, fuel_password,
-                 dea_file, fuel_plugins_conf_dir, work_dir, no_health_check):
+                 dea_file, fuel_plugins_conf_dir, work_dir, no_health_check,
+                 deploy_timeout):
         self.dea = dea
         self.dha = dha
         self.fuel_ip = fuel_ip
@@ -48,6 +49,7 @@ class CloudDeploy(object):
         self.fuel_plugins_conf_dir = fuel_plugins_conf_dir
         self.work_dir = work_dir
         self.no_health_check = no_health_check
+        self.deploy_timeout = deploy_timeout
         self.file_dir = os.path.dirname(os.path.realpath(__file__))
         self.ssh = SSHClient(self.fuel_ip, self.fuel_username,
                              self.fuel_password)
@@ -103,8 +105,11 @@ class CloudDeploy(object):
         deploy_app = '%s/%s' % (self.work_dir, deploy_app)
         dea_file = '%s/%s' % (self.work_dir, os.path.basename(self.dea_file))
         with self.ssh as s:
-            status = s.run('python %s %s %s' % (
-                deploy_app, ('-nh' if self.no_health_check else ''), dea_file))
+            status = s.run('python %s %s %s %s' % (
+                deploy_app,
+                ('-nh' if self.no_health_check else ''),
+                ('-dt %s' % self.deploy_timeout if self.deploy_timeout else ''),
+                dea_file))
         return status
 
     def check_supported_release(self):