Adding SRIOV scenario
[apex.git] / apex / overcloud / deploy.py
index 5c95796..33641ed 100644 (file)
@@ -11,6 +11,7 @@ import base64
 import fileinput
 import logging
 import os
+import platform
 import shutil
 import uuid
 import struct
@@ -37,6 +38,8 @@ SDN_FILE_MAP = {
             'dvr': 'neutron-opendaylight-fdio-dvr.yaml',
             'default': 'neutron-opendaylight-honeycomb.yaml'
         },
+        'l2gw': 'neutron-l2gw-opendaylight.yaml',
+        'sriov': 'neutron-opendaylight-sriov.yaml',
         'default': 'neutron-opendaylight.yaml',
     },
     'onos': {
@@ -135,6 +138,9 @@ def create_deploy_cmd(ds, ns, inv, tmp_dir,
         prep_storage_env(ds, tmp_dir)
         deploy_options.append(os.path.join(con.THT_ENV_DIR,
                                            'storage-environment.yaml'))
+    if ds_opts['sriov']:
+        prep_sriov_env(ds, tmp_dir)
+
     if ds['global_params']['ha_enabled']:
         deploy_options.append(os.path.join(con.THT_ENV_DIR,
                                            'puppet-pacemaker.yaml'))
@@ -151,6 +157,14 @@ def create_deploy_cmd(ds, ns, inv, tmp_dir,
         raise ApexDeployException("Invalid number of control or computes")
     elif num_control > 1 and not ds['global_params']['ha_enabled']:
         num_control = 1
+    if platform.machine() == 'aarch64':
+        # aarch64 deploys were not completing in the default 90 mins.
+        # Not sure if this is related to the hardware the OOO support
+        # was developed on or the virtualization support in CentOS
+        # Either way it will probably get better over time  as the aarch
+        # support matures in CentOS and deploy time should be tested in
+        # the future so this multiplier can be removed.
+        con.DEPLOY_TIMEOUT *= 2
     cmd = "openstack overcloud deploy --templates --timeout {} " \
           .format(con.DEPLOY_TIMEOUT)
     # build cmd env args
@@ -176,10 +190,11 @@ def create_deploy_cmd(ds, ns, inv, tmp_dir,
     return cmd
 
 
-def prep_image(ds, img, tmp_dir, root_pw=None):
+def prep_image(ds, ns, img, tmp_dir, root_pw=None):
     """
     Locates sdn image and preps for deployment.
     :param ds: deploy settings
+    :param ns: network settings
     :param img: sdn image
     :param tmp_dir: dir to store modified sdn image
     :param root_pw: password to configure for overcloud image
@@ -209,6 +224,18 @@ def prep_image(ds, img, tmp_dir, root_pw=None):
                 ".service"
         }])
 
+    if ns.get('http_proxy', ''):
+        virt_cmds.append({
+            con.VIRT_RUN_CMD:
+                "echo 'http_proxy={}' >> /etc/environment".format(
+                    ns['http_proxy'])})
+
+    if ns.get('https_proxy', ''):
+        virt_cmds.append({
+            con.VIRT_RUN_CMD:
+                "echo 'https_proxy={}' >> /etc/environment".format(
+                    ns['https_proxy'])})
+
     if ds_opts['vpn']:
         virt_cmds.append({con.VIRT_RUN_CMD: "chmod +x /etc/rc.d/rc.local"})
         virt_cmds.append({
@@ -436,6 +463,13 @@ def prep_env(ds, ns, inv, opnfv_env, net_env, tmp_dir):
             elif 'ComputeServices' in line:
                 output_line = ("  ComputeServices:\n"
                                "    - OS::TripleO::Services::NeutronDhcpAgent")
+        # SRIOV networks are VLAN based provider networks. In order to simplify
+        # the deployment, nfv_sriov will be the default physnet. VLANs are not
+        # needed in advance, and the user will have to create the network
+        # specifying the segmentation-id.
+        if ds_opts['sriov']:
+            if 'NeutronNetworkVLANRanges' in line:
+                output_line = ("{},nfv_sriov'".format(line[:-1]))
 
         if perf:
             for role in 'NovaCompute', 'Controller':
@@ -533,6 +567,9 @@ def prep_storage_env(ds, tmp_dir):
         elif 'CephAdminKey' in line:
             print("  CephAdminKey: {}".format(generate_ceph_key().decode(
                 'utf-8')))
+        elif 'CephClientKey' in line:
+            print("  CephClientKey: {}".format(generate_ceph_key().decode(
+                'utf-8')))
         else:
             print(line)
     if 'ceph_device' in ds_opts and ds_opts['ceph_device']:
@@ -543,6 +580,46 @@ def prep_storage_env(ds, tmp_dir):
             ))
 
 
+def prep_sriov_env(ds, tmp_dir):
+    """
+    Creates SRIOV environment file for deployment. Source file is copied by
+    undercloud playbook to host.
+    :param ds:
+    :param tmp_dir:
+    :return:
+    """
+    ds_opts = ds['deploy_options']
+    sriov_iface = ds_opts['sriov']
+    sriov_file = os.path.join(tmp_dir, 'neutron-opendaylight-sriov.yaml')
+    if not os.path.isfile(sriov_file):
+        logging.error("sriov-environment file is not in tmp directory: {}. "
+                      "Check if file was copied from "
+                      "undercloud".format(tmp_dir))
+        raise ApexDeployException("sriov-environment file not copied from "
+                                  "undercloud")
+    # TODO(rnoriega): Instead of line editing, refactor this code to load
+    # yaml file into a dict, edit it and write the file back.
+    for line in fileinput.input(sriov_file, inplace=True):
+        line = line.strip('\n')
+        if 'NovaSchedulerDefaultFilters' in line:
+            print("  {}".format(line[3:]))
+        elif 'NovaSchedulerAvailableFilters' in line:
+            print("  {}".format(line[3:]))
+        elif 'NeutronPhysicalDevMappings' in line:
+            print("  NeutronPhysicalDevMappings: \"nfv_sriov:{}\""
+                  .format(sriov_iface))
+        elif 'NeutronSriovNumVFs' in line:
+            print("  NeutronSriovNumVFs: \"{}:8\"".format(sriov_iface))
+        elif 'NovaPCIPassthrough' in line:
+            print("  NovaPCIPassthrough:")
+        elif 'devname' in line:
+            print("    - devname: \"{}\"".format(sriov_iface))
+        elif 'physical_network' in line:
+            print("      physical_network: \"nfv_sriov\"")
+        else:
+            print(line)
+
+
 def external_network_cmds(ns):
     """
     Generates external network openstack commands