#!/usr/bin/python ############################################################################### # Copyright (c) 2015 Ericsson AB and others. # jonas.bjurel@ericsson.com # 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 ############################################################################### ############################################################################### # Description # This script constructs the final deployment dea.yaml and dha.yaml files # The dea.yaml get's constructed from (in reverse priority): # 1) dea-base # 2) dea-pod-override # 3) deployment-scenario dea-override-config section # # The dha.yaml get's constructed from (in reverse priority): # 1) pod dha # 2) deployment-scenario dha-override-config section ############################################################################### import os import yaml import sys import urllib2 import calendar import time import collections import hashlib from functools import reduce from operator import or_ from common import ( log, exec_cmd, err, warn, check_file_exists, create_dir_if_not_exists, delete, check_if_root, ArgParser, ) def parse_arguments(): parser = ArgParser(prog='python %s' % __file__) parser.add_argument('-dha', dest='dha_uri', action='store', default=False, help='dha configuration file FQDN URI', required=True) parser.add_argument('-deab', dest='dea_base_uri', action='store', default=False, help='dea base configuration FQDN URI', required=True) parser.add_argument('-deao', dest='dea_pod_override_uri', action='store', default=False, help='dea POD override configuration FQDN URI', required=True) parser.add_argument('-scenario-base-uri', dest='scenario_base_uri', action='store', default=False, help='Deployment scenario base directory URI', required=True) parser.add_argument('-scenario', dest='scenario', action='store', default=False, help=('Deployment scenario short-name (priority),' 'or base file name (in the absense of a' 'shortname defenition)'), required=True) parser.add_argument('-plugins', dest='plugins_uri', action='store', default=False, help='Plugin configurations directory URI', required=True) parser.add_argument('-output', dest='output_path', action='store', default=False, help='Local path for resulting output configuration files', required=True) args = parser.parse_args() log(args) kwargs = {'dha_uri': args.dha_uri, 'dea_base_uri': args.dea_base_uri, 'dea_pod_override_uri': args.dea_pod_override_uri, 'scenario_base_uri': args.scenario_base_uri, 'scenario': args.scenario, 'plugins_uri': args.plugins_uri, 'output_path': args.output_path} return kwargs def warning(msg): red = '\033[0;31m' NC = '\033[0m' print('%(red)s WARNING: %(msg)s %(NC)s' % {'red': red, 'msg': msg, 'NC': NC}) def setup_yaml(): represent_dict_order = lambda self, data: self.represent_mapping('tag:yaml.org,2002:map', data.items()) yaml.add_representer(collections.OrderedDict, represent_dict_order) def sha_uri(uri): response = urllib2.urlopen(uri) data = response.read() sha1 = hashlib.sha1() sha1.update(data) return sha1.hexdigest() def merge_fuel_plugin_version_list(list1, list2): final_list = [] # When the plugin version in not there in list1 it will # not be copied for e_l1 in list1: plugin_version = e_l1.get('metadata', {}).get('plugin_version') plugin_version_found = False for e_l2 in list2: if plugin_version == e_l2.get('metadata', {}).get('plugin_version'): final_l
##############################################################################
# Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
#
# 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
##############################################################################
---
# Sample StorPerf benchmark task config file
# StorPerf is a tool to measure block and object storage performance in an NFVI

schema: "yardstick:task:0.1"

scenarios:
-
  type: StorPerf
  options:
    agent_count: 1
    agent_image: "Ubuntu-16.04"
    agent_flavor: "storperf"
    public_network: "ext-net"
    volume_size: 2
    # target:
    # deadline:
    # nossd:
    # nowarm:
    block_sizes: "4096"
    queue_depths: "4"
    workload: "ws"
    StorPerf_ip: "192.168.23.2"
    query_interval: 10
    timeout: 600

  runner:
    type: Iteration
    iterations: 1

context:
  type: Dummy
" version: " + str(dea_pod_version), " created: " + str(dea_pod_creation), " sha1: " + str(dea_pod_sha), " comment: " + str(dea_pod_comment) + "\n"])) f.write("\n".join([" deployment-scenario:", " uri: " + str(scenario_uri), " title: " + str(deploy_scenario_title), " version: " + str(deploy_scenario_version), " created: " + str(deploy_scenario_creation), " sha1: " + str(deploy_scenario_sha), " comment: " + str(deploy_scenario_comment) + "\n"])) f.write(" plugin-modules:\n") for k, _ in enumerate(modules): f.write("\n".join([" - module: " + modules[k], " uri: " + module_uris[k], " title: " + module_titles[k], " version: " + module_versions[k], " created: " + module_creations[k], " sha-1: " + module_shas[k], " comment: " + module_comments[k] + "\n"])) yaml.dump(final_dea_conf, f, default_flow_style=False) # Load POD dha and override it with "deployment-scenario/dha-override-config" section print('Generating final dha.yaml configuration....') print('Parsing dha-pod yaml configuration....') response = urllib2.urlopen(kwargs["dha_uri"]) dha_pod_conf = yaml.load(response.read()) dha_pod_title = dha_pod_conf['dha-pod-config-metadata']['title'] dha_pod_version = dha_pod_conf['dha-pod-config-metadata']['version'] dha_pod_creation = dha_pod_conf['dha-pod-config-metadata']['created'] dha_pod_sha = sha_uri(kwargs["dha_uri"]) dha_pod_comment = dha_pod_conf['dha-pod-config-metadata']['comment'] dha_pod_conf.pop('dha-pod-config-metadata') final_dha_conf = dha_pod_conf dha_scenario_override_conf = deploy_scenario_conf["dha-override-config"] # Only virtual deploy scenarios can override dha.yaml since there # is no way to programatically override a physical environment: # wireing, IPMI set-up, etc. # For Physical environments, dha.yaml overrides will be silently ignored if dha_scenario_override_conf and (final_dha_conf['adapter'] == 'libvirt' or final_dha_conf['adapter'] == 'esxi' or final_dha_conf['adapter'] == 'vbox'): print('Merging dha-pod and deployment-scenario override information to final dha.yaml configuration....') final_dha_conf = dict(merge_dicts(final_dha_conf, dha_scenario_override_conf)) # Dump final dha.yaml to argument provided directory print('Dumping final dha.yaml to ' + kwargs["output_path"] + '/dha.yaml....') with open(kwargs["output_path"] + '/dha.yaml', "w") as f: f.write("\n".join([("title: DHA.yaml file automatically generated from" "the configuration files stated in the" '"configuration-files" fragment below'), "version: " + str(calendar.timegm(time.gmtime())), "created: " + str(time.strftime("%d/%m/%Y")) + " " + str(time.strftime("%H:%M:%S")), "comment: none\n"])) f.write("configuration-files:\n") f.write("\n".join([" dha-pod-configuration:", " uri: " + kwargs["dha_uri"], " title: " + str(dha_pod_title), " version: " + str(dha_pod_version), " created: " + str(dha_pod_creation), " sha-1: " + str(dha_pod_sha), " comment: " + str(dha_pod_comment) + "\n"])) f.write("\n".join([" deployment-scenario:", " uri: " + str(scenario_uri), " title: " + str(deploy_scenario_title), " version: " + str(deploy_scenario_version), " created: " + str(deploy_scenario_creation), " sha-1: " + str(deploy_scenario_sha), " comment: " + str(deploy_scenario_comment) + "\n"])) yaml.dump(final_dha_conf, f, default_flow_style=False)