add the scenarios option 41/36341/5
authorzhongjun <zhong.jun@zte.com.cn>
Thu, 22 Jun 2017 02:31:14 +0000 (10:31 +0800)
committerzhongjun <zhong.jun@zte.com.cn>
Fri, 23 Jun 2017 05:54:56 +0000 (13:54 +0800)
Add the scenarios option and yaml configuration files,
currently only support three scenarios as below.
os-nosdn-nofeature-noha/os-odl_l3-nofeature-noha/
os-odl_l2-nofeature-noha.
we will support more secnarios such as os-odl_l3-nofeature-ha
in future.

Change-Id: I24d7875208e277f6ee1b794c0033d5fee6b5e371
Signed-off-by: zhongjun <zhong.jun@zte.com.cn>
deploy/deploy.py
deploy/scenario/ha_nofeature_scenario.yaml [new file with mode: 0644]
deploy/scenario/ha_odl-l2_nofeatrue_scenario.yaml [new file with mode: 0644]
deploy/scenario/ha_odl-l3_nofeature_scenario.yaml [new file with mode: 0644]
deploy/scenario/no-ha_nofeature_scenario.yaml [new file with mode: 0644]
deploy/scenario/no-ha_odl-l2_nofeature_scenario.yaml [new file with mode: 0644]
deploy/scenario/no-ha_odl-l3_nofeature_scenario.yaml [new file with mode: 0644]
deploy/scenario/scenario.yaml [new file with mode: 0644]
deploy/utils.py

index 5926a74..88a5cba 100644 (file)
@@ -15,6 +15,7 @@
 # [ ] 4. get ipmi user/password from PDF (Pod Descriptor File)
 # [ ] 5. get pxe bridge from jjb
 # [ ] 6. enlarge the vm size of Controller & Compute in deploy.yml
+# [ ] 7. support scenarios options and configuration
 ##############################################################################
 
 import argparse
@@ -36,7 +37,9 @@ from utils import (
     check_sudo_privilege,
     check_file_exists,
     make_file_executable,
-    confirm_dir_exists
+    confirm_dir_exists,
+    merge_dicts,
+    check_scenario_valid
 )
 from environment import (
     DaisyEnvironment,
@@ -46,13 +49,12 @@ from environment import (
 class DaisyDeployment(object):
     def __init__(self, lab_name, pod_name, deploy_file, net_file, bin_file,
                  daisy_only, cleanup_only, remote_dir, work_dir, storage_dir,
-                 pxe_bridge, deploy_log):
+                 pxe_bridge, deploy_log, scenario):
         self.lab_name = lab_name
         self.pod_name = pod_name
 
         self.deploy_file = deploy_file
-        with open(deploy_file) as yaml_file:
-            self.deploy_struct = yaml.safe_load(yaml_file)
+        self.deploy_struct = self._consturct_final_deploy_conf(deploy_file, scenario)
 
         if not cleanup_only:
             self.net_file = net_file
@@ -114,6 +116,27 @@ class DaisyDeployment(object):
                 'password': password,
                 'disk_size': disk_size}
 
+    def _consturct_final_deploy_conf(self, deploy_file, scenario):
+        with open(deploy_file) as yaml_file:
+            deploy_struct = yaml.safe_load(yaml_file)
+        scenario_file = path_join(WORKSPACE, 'deploy/scenario/scenario.yaml')
+        with open(scenario_file) as yaml_file:
+            scenario_trans_conf = yaml.safe_load(yaml_file)
+        if scenario in scenario_trans_conf:
+            fin_scenario_file = path_join(WORKSPACE, 'deploy/scenario',
+                                          scenario_trans_conf[scenario]['configfile'])
+        else:
+            fin_scenario_file = path_join(WORKSPACE, 'deploy/scenario', scenario)
+        with open(fin_scenario_file) as yaml_file:
+            deploy_scenario_conf = yaml.safe_load(yaml_file)
+        deploy_scenario_override_conf = deploy_scenario_conf['deploy-override-config']
+        # Only virtual deploy scenarios can override deploy.yml
+        if deploy_scenario_conf and (deploy_struct['adapter'] == 'libvirt'):
+            deploy_struct = dict(merge_dicts(deploy_struct, deploy_scenario_override_conf))
+        modules = deploy_scenario_conf['stack-extensions']
+        deploy_struct['modules'] = modules
+        return deploy_struct
+
     def run(self):
         self.daisy_env.delete_old_environment()
         if self.cleanup_only:
@@ -168,6 +191,9 @@ def config_arg_parser():
     parser.add_argument('-log', dest='deploy_log', action='store', nargs='?',
                         default=path_join(WORKSPACE, 'deploy.log'),
                         help='Path and name of the deployment log file')
+    parser.add_argument('-s', dest='scenario', action='store', nargs='?',
+                        default='os-nosdn-nofeature-noha',
+                        help='Deployment scenario')
     return parser
 
 
@@ -178,6 +204,8 @@ def parse_arguments():
     save_log_to_file(args.deploy_log)
     LI(args)
 
+    check_scenario_valid(args.scenario)
+
     conf_base_dir = path_join(WORKSPACE, 'labs', args.lab_name, args.pod_name)
     deploy_file = path_join(conf_base_dir, 'daisy/config/deploy.yml')
     net_file = path_join(conf_base_dir, 'daisy/config/network.yml')
@@ -202,7 +230,8 @@ def parse_arguments():
         'work_dir': args.work_dir,
         'storage_dir': args.storage_dir,
         'pxe_bridge': args.pxe_bridge,
-        'deploy_log': args.deploy_log
+        'deploy_log': args.deploy_log,
+        'scenario': args.scenario
     }
     return kwargs
 
diff --git a/deploy/scenario/ha_nofeature_scenario.yaml b/deploy/scenario/ha_nofeature_scenario.yaml
new file mode 100644 (file)
index 0000000..a379146
--- /dev/null
@@ -0,0 +1,46 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+##############################################################################
+# deployment configuration meta-data
+deployment-scenario-metadata:
+   title: OpenStack-only, HA deploymen
+   version: 0.0.1
+   created: Jun 8 2017
+   comment:
+
+##############################################################################
+# Stack extentions are opnfv added value features
+stack-extensions:
+
+##############################################################################
+# By editing the override-config sections below, you can override arbitrary
+# configuration name-space settings
+deploy-override-config:
+  hosts:
+  - name: 'controller01'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'controller02'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'controller03'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'computer01'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer02'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
\ No newline at end of file
diff --git a/deploy/scenario/ha_odl-l2_nofeatrue_scenario.yaml b/deploy/scenario/ha_odl-l2_nofeatrue_scenario.yaml
new file mode 100644 (file)
index 0000000..db0287c
--- /dev/null
@@ -0,0 +1,50 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+##############################################################################
+# deployment configuration meta-data
+deployment-scenario-metadata:
+   title: ODL-L2 HA deployment
+   version: 0.0.1
+   created: Jun 22 2017
+   comment:
+
+##############################################################################
+# Stack extentions are opnfv added value features
+stack-extensions:
+  - module: opendaylight
+    module-config:
+      - enable_l3_odl:
+          value: false
+
+##############################################################################
+# By editing the override-config sections below, you can override arbitrary
+# configuration name-space settings
+deploy-override-config:
+  hosts:
+  - name: 'controller01'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'controller02'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'controller03'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'computer01'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer02'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
\ No newline at end of file
diff --git a/deploy/scenario/ha_odl-l3_nofeature_scenario.yaml b/deploy/scenario/ha_odl-l3_nofeature_scenario.yaml
new file mode 100644 (file)
index 0000000..59e16c4
--- /dev/null
@@ -0,0 +1,50 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+##############################################################################
+# deployment configuration meta-data
+deployment-scenario-metadata:
+   title: ODL-L3 HA deployment
+   version: 0.0.1
+   created: Jun 8 2017
+   comment:
+
+##############################################################################
+# Stack extentions are opnfv added value features
+stack-extensions:
+  - module: opendaylight
+    module-config:
+      - enable_l3_odl:
+          value: true
+
+##############################################################################
+# By editing the override-config sections below, you can override arbitrary
+# configuration name-space settings
+deploy-override-config:
+  hosts:
+  - name: 'controller01'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'controller02'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'controller03'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'computer01'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer02'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
\ No newline at end of file
diff --git a/deploy/scenario/no-ha_nofeature_scenario.yaml b/deploy/scenario/no-ha_nofeature_scenario.yaml
new file mode 100644 (file)
index 0000000..f959234
--- /dev/null
@@ -0,0 +1,42 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+##############################################################################
+# deployment configuration meta-data
+deployment-scenario-metadata:
+   title: OpenStack-only, NO-HA deploymen
+   version: 0.0.1
+   created: Jun 8 2017
+   comment:
+
+##############################################################################
+# Stack extentions are opnfv added value features
+stack-extensions:
+
+##############################################################################
+# By editing the override-config sections below, you can override arbitrary
+# configuration name-space settings
+deploy-override-config:
+  hosts:
+  - name: 'controller01'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'computer01'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer02'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer03'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
\ No newline at end of file
diff --git a/deploy/scenario/no-ha_odl-l2_nofeature_scenario.yaml b/deploy/scenario/no-ha_odl-l2_nofeature_scenario.yaml
new file mode 100644 (file)
index 0000000..12cfc74
--- /dev/null
@@ -0,0 +1,46 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+##############################################################################
+# deployment configuration meta-data
+deployment-scenario-metadata:
+   title: ODL-L2 NO-HA deployment
+   version: 0.0.1
+   created: Jun 22 2017
+   comment:
+
+##############################################################################
+# Stack extentions are opnfv added value features
+stack-extensions:
+  - module: opendaylight
+    module-config:
+      - enable_l3_odl:
+          value: false
+
+##############################################################################
+# By editing the override-config sections below, you can override arbitrary
+# configuration name-space settings
+deploy-override-config:
+  hosts:
+  - name: 'controller01'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'computer01'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer02'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer03'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
\ No newline at end of file
diff --git a/deploy/scenario/no-ha_odl-l3_nofeature_scenario.yaml b/deploy/scenario/no-ha_odl-l3_nofeature_scenario.yaml
new file mode 100644 (file)
index 0000000..e91acc6
--- /dev/null
@@ -0,0 +1,46 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+##############################################################################
+# deployment configuration meta-data
+deployment-scenario-metadata:
+   title: ODL-L3 NO-HA deployment
+   version: 0.0.1
+   created: Jun 8 2017
+   comment:
+
+##############################################################################
+# Stack extentions are opnfv added value features
+stack-extensions:
+  - module: opendaylight
+    module-config:
+      - enable_l3_odl:
+          value: true
+
+##############################################################################
+# By editing the override-config sections below, you can override arbitrary
+# configuration name-space settings
+deploy-override-config:
+  hosts:
+  - name: 'controller01'
+    roles:
+      - 'CONTROLLER_LB'
+    template: 'templates/virtual_environment/vms/controller.xml'
+  - name: 'computer01'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer02'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
+  - name: 'computer03'
+    roles:
+      - 'COMPUTER'
+    template: 'templates/virtual_environment/vms/computer.xml'
\ No newline at end of file
diff --git a/deploy/scenario/scenario.yaml b/deploy/scenario/scenario.yaml
new file mode 100644 (file)
index 0000000..8186248
--- /dev/null
@@ -0,0 +1,34 @@
+##############################################################################
+# Copyright (c) 2017 ZTE Coreporation and others.
+# hu.zhijiang@zte.com.cn
+# sun.jing22@zte.com.cn
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+##############################################################################
+##############################################################################
+# Short scenario name convention to be followed:
+# os-<controller>-<feature>-<mode>[-<optional-parameter>]
+# controler: nosdn|odl|onos|ocl|...
+# feaure: nofeature | [vlan]_[kvm]_[ovs]_[vlan]_....
+# mode: ha|noha
+##############################################################################
+
+os-nosdn-nofeature-ha:
+  configfile: ha_nofeature_scenario.yaml
+
+os-nosdn-nofeature-noha:
+  configfile: no-ha_nofeature_scenario.yaml
+
+os-odl_l3-nofeature-ha:
+  configfile: ha_odl-l3_nofeature_scenario.yaml
+
+os-odl_l3-nofeature-noha:
+  configfile: no-ha_odl-l3_nofeature_scenario.yaml
+
+os-odl_l2-nofeature-ha:
+  configfile: ha_odl-l2_nofeature_scenario.yaml
+
+os-odl_l2-nofeature-noha:
+  configfile: no-ha_odl-l2_nofeature_scenario.yaml
\ No newline at end of file
index 0c5b137..102ae1f 100644 (file)
@@ -19,6 +19,9 @@ path_join = os.path.join
 CWD = os.getcwd()
 WORKSPACE = os.path.normpath(path_join(os.path.dirname(__file__), '..'))
 BASE = CWD
+valid_scenario_list = ['os-nosdn-nofeature-noha',
+                       'os-odl_l3-nofeature-noha',
+                       'os-odl_l2-nofeature-noha']
 
 
 def get_logger():
@@ -136,3 +139,23 @@ def run_shell(cmd, check=False):
             LI('Successful command: ' + str(cmd))
 
     return return_code
+
+
+def merge_dicts(dict1, dict2):
+    for k in set(dict1).union(dict2):
+        if k in dict1 and k in dict2:
+            if isinstance(dict1[k], dict) and isinstance(dict2[k], dict):
+                yield (k, dict(merge_dicts(dict1[k], dict2[k])))
+                continue
+            # If one of the values is not a dict nor a list,
+            # you can't continue merging it.
+            # Value from second dict overrides one in first if exists.
+        if k in dict2:
+            yield (k, dict2[k])
+        else:
+            yield (k, dict1[k])
+
+
+def check_scenario_valid(scenario):
+    if not (scenario in valid_scenario_list):
+        err_exit('Invald scenario:%s' % scenario)