Merge "Add support for $HOME/.vmtp.yaml"
This commit is contained in:
commit
f3e026de68
@ -21,7 +21,7 @@ VMTP Usage
|
||||
[--stop-on-error] [--vm_image_url <url_to_image>]
|
||||
[--test_description <test_description>]
|
||||
|
||||
OpenStack VM Throughput V2.0.3
|
||||
OpenStack VM Throughput V2.0.4
|
||||
|
||||
optional arguments:
|
||||
-h, --help show this help message and exit
|
||||
@ -77,13 +77,21 @@ VMTP Usage
|
||||
Configuration File
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
VMTP configuration files follow the yaml syntax and contain variables used by VMTP to run and collect performance data. The default configuration is stored in the cfg.default.yaml file.
|
||||
VMTP configuration files follow the yaml syntax and contain variables used by VMTP to run and collect performance data.
|
||||
The default configuration is stored in the cfg.default.yaml file.
|
||||
|
||||
Default values should be overwritten for any cloud under test by defining new variable values in a new configuration file that follows the same format. Variables that are not defined in the new configuration file will retain their default values.
|
||||
Default values should be overwritten for any cloud under test by defining new variable values in a new configuration file that follows the same format.
|
||||
Variables that are not defined in the new configuration file will retain their default values.
|
||||
|
||||
The precedence order for configuration files is as follows:
|
||||
- the command line argument "-c <file>" has highest precedence
|
||||
- $HOME/.vmtp.yaml if the file exists in the user home directory
|
||||
- cfg.default.yaml has the lowest precedence (always exists in the VMTP package root directory)
|
||||
|
||||
To override a default value set in cfg.default.yaml, simply redefine that value in the configuration file passed in -c or in the $HOME/.vmtp.yaml file.
|
||||
Check the content of cfg.default.yaml file as it contains the list of configuration variables and instructions on how to set them.
|
||||
|
||||
**Note:** the configuration file is not needed if the VMTP only runs the native host throughput option (*--host*)
|
||||
**Note:** the configuration file is not needed if VMTP only runs the native host throughput option (*--host*)
|
||||
|
||||
|
||||
OpenStack openrc File
|
||||
|
35
vmtp.py
35
vmtp.py
@ -40,7 +40,7 @@ from neutronclient.v2_0 import client as neutronclient
|
||||
from novaclient.client import Client
|
||||
from novaclient.exceptions import ClientException
|
||||
|
||||
__version__ = '2.0.3'
|
||||
__version__ = '2.0.4'
|
||||
|
||||
from perf_instance import PerfInstance as PerfInstance
|
||||
|
||||
@ -511,6 +511,30 @@ def extract_user_host_pwd(user_host_pwd):
|
||||
sys.exit(4)
|
||||
return match.groups()
|
||||
|
||||
def _merge_config(file, source_config, required=False):
|
||||
'''
|
||||
returns the merged config or exits if the file does not exist and is required
|
||||
'''
|
||||
dest_config = source_config
|
||||
|
||||
fullname = os.path.expanduser(file)
|
||||
if os.path.isfile(fullname):
|
||||
print('Loading ' + fullname + '...')
|
||||
try:
|
||||
alt_config = configure.Configuration.from_file(fullname).configure()
|
||||
dest_config = source_config.merge(alt_config)
|
||||
|
||||
except configure.ConfigurationError:
|
||||
# this is in most cases when the config file passed is empty
|
||||
# configure.ConfigurationError: unconfigured
|
||||
# in case of syntax error, another exception is thrown:
|
||||
# TypeError: string indices must be integers, not str
|
||||
pass
|
||||
elif required:
|
||||
print('Error: configration file %s does not exist' % (fullname))
|
||||
sys.exit(1)
|
||||
return dest_config
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
fpr = FlowPrinter()
|
||||
@ -655,10 +679,15 @@ if __name__ == '__main__':
|
||||
default_cfg_file = get_absolute_path_for_file("cfg.default.yaml")
|
||||
|
||||
# read the default configuration file and possibly an override config file
|
||||
# the precedence order is as follows:
|
||||
# $HOME/.vmtp.yaml if exists
|
||||
# -c <file> from command line if provided
|
||||
# cfg.default.yaml
|
||||
config = configure.Configuration.from_file(default_cfg_file).configure()
|
||||
config = _merge_config('~/.vmtp.yaml', config)
|
||||
|
||||
if opts.config:
|
||||
alt_config = configure.Configuration.from_file(opts.config).configure()
|
||||
config = config.merge(alt_config)
|
||||
config = _merge_config(opts.config, config, required=True)
|
||||
|
||||
if opts.version:
|
||||
print('Version ' + __version__)
|
||||
|
Loading…
x
Reference in New Issue
Block a user