Update monitorstack to use updated openstacksdk and es
This change updates the functions so that they work with the most up to date OpenStack SDK, and adds an elasticsearch output format. Tests have been udpated to pass newer versions of flake8 and py3 Change-Id: If46d3fb8e2b2e4aa5e21bf7da470945b05d216cf Signed-off-by: Kevin Carter <kevin@cloudnull.com>
This commit is contained in:
parent
b676952bbe
commit
7cbe3ffcf1
@ -14,6 +14,13 @@ auth_url = https://127.0.0.1:5000/v3
|
|||||||
username = admin
|
username = admin
|
||||||
password = Secrete
|
password = Secrete
|
||||||
|
|
||||||
|
# NOTE(Cloudnull):
|
||||||
|
# If the system already has a clouds.yaml configuration file in place, monitorstack
|
||||||
|
# can use this config by default. Create the "cloud" section and set the cloud option.
|
||||||
|
# When using this section, no other OpenStack options are needed.
|
||||||
|
# [cloud]
|
||||||
|
# cloud = default
|
||||||
|
|
||||||
[keystone]
|
[keystone]
|
||||||
# NOTE(cloudnull):
|
# NOTE(cloudnull):
|
||||||
# When using keystone V3 you will need the .*domain_name configuration options.
|
# When using keystone V3 you will need the .*domain_name configuration options.
|
||||||
@ -45,3 +52,13 @@ project_name = ironic
|
|||||||
user_domain_name = users
|
user_domain_name = users
|
||||||
project_domain_name = projects
|
project_domain_name = projects
|
||||||
password = SuperSecrete
|
password = SuperSecrete
|
||||||
|
|
||||||
|
[elasticsearch]
|
||||||
|
# List of hosts. Note, items in this list are strings with the hostname or IP only.
|
||||||
|
hosts = ['localhost']
|
||||||
|
# Optional settings when using authenticated environments.
|
||||||
|
# http_auth = ('user', 'secret')
|
||||||
|
|
||||||
|
# Optional settings when using SSL.
|
||||||
|
# scheme="https"
|
||||||
|
# port=443
|
||||||
|
@ -83,7 +83,8 @@ VALID_OUTPUT_FORMATS = [
|
|||||||
'json',
|
'json',
|
||||||
'line',
|
'line',
|
||||||
'telegraf',
|
'telegraf',
|
||||||
'rax-maas'
|
'rax-maas',
|
||||||
|
'elasticsearch'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -96,6 +97,9 @@ VALID_OUTPUT_FORMATS = [
|
|||||||
', '.join(VALID_OUTPUT_FORMATS)
|
', '.join(VALID_OUTPUT_FORMATS)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@click.option('--config-file',
|
||||||
|
help='MonitorStack configuration file',
|
||||||
|
default='openstack.ini')
|
||||||
@click.option('-v', '--verbose', is_flag=True, help='Enables verbose mode.')
|
@click.option('-v', '--verbose', is_flag=True, help='Enables verbose mode.')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(*args, **kwargs):
|
def cli(*args, **kwargs):
|
||||||
@ -122,7 +126,7 @@ def process_result(results, output_format, **kwargs):
|
|||||||
|
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
for result in results:
|
for result in results:
|
||||||
output_formatter(result)
|
output_formatter(result, kwargs['config_file'])
|
||||||
if result['exit_code'] != 0:
|
if result['exit_code'] != 0:
|
||||||
exit_code = result['exit_code']
|
exit_code = result['exit_code']
|
||||||
else:
|
else:
|
||||||
|
@ -18,15 +18,17 @@ import time
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
from monitorstack import utils
|
||||||
|
|
||||||
def write_json(result):
|
|
||||||
|
def write_json(result, config_file):
|
||||||
"""Output in raw JSON format."""
|
"""Output in raw JSON format."""
|
||||||
output = json.dumps(result, indent=2)
|
output = json.dumps(result, indent=2)
|
||||||
click.echo(output)
|
click.echo(output)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def write_line(result):
|
def write_line(result, config_file):
|
||||||
"""Output in line format."""
|
"""Output in line format."""
|
||||||
for key, value in result['variables'].items():
|
for key, value in result['variables'].items():
|
||||||
click.echo("{} {}".format(key, value))
|
click.echo("{} {}".format(key, value))
|
||||||
@ -102,7 +104,7 @@ def _telegraf_line_format(sets, quote=False):
|
|||||||
return ','.join(store).rstrip(',')
|
return ','.join(store).rstrip(',')
|
||||||
|
|
||||||
|
|
||||||
def write_telegraf(result):
|
def write_telegraf(result, config_file):
|
||||||
"""Output in telegraf format."""
|
"""Output in telegraf format."""
|
||||||
resultant = [result['measurement_name']]
|
resultant = [result['measurement_name']]
|
||||||
if 'meta' in result:
|
if 'meta' in result:
|
||||||
@ -120,7 +122,7 @@ def write_telegraf(result):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def write_rax_maas(result):
|
def write_rax_maas(result, config_file):
|
||||||
"""Output in Rackspace Monitoring as a Service format."""
|
"""Output in Rackspace Monitoring as a Service format."""
|
||||||
status = ['status']
|
status = ['status']
|
||||||
if result['exit_code'] == 0:
|
if result['exit_code'] == 0:
|
||||||
@ -142,3 +144,37 @@ def write_rax_maas(result):
|
|||||||
click.echo(' '.join(metric))
|
click.echo(' '.join(metric))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def write_elasticsearch(result, config_file):
|
||||||
|
"""Output in elasticsearch format."""
|
||||||
|
import datetime
|
||||||
|
from elasticsearch import Elasticsearch
|
||||||
|
|
||||||
|
config = utils.read_config(config_file=config_file)
|
||||||
|
if 'elasticsearch' in config:
|
||||||
|
elastcisearch_config = config['elasticsearch']
|
||||||
|
es = Elasticsearch(**elastcisearch_config)
|
||||||
|
else:
|
||||||
|
es = Elasticsearch()
|
||||||
|
|
||||||
|
doc = {
|
||||||
|
'author': 'openstack',
|
||||||
|
'text': result['message'],
|
||||||
|
'timestamp': datetime.datetime.now(),
|
||||||
|
'measurement_name': result['measurement_name'],
|
||||||
|
'meta': result['meta'],
|
||||||
|
'variables': result['variables'],
|
||||||
|
'status': result['exit_code']
|
||||||
|
}
|
||||||
|
|
||||||
|
res = es.index(
|
||||||
|
index="monitorstack-{}".format(
|
||||||
|
datetime.date.today().strftime("%Y-%m-%d")
|
||||||
|
),
|
||||||
|
id=_current_time(),
|
||||||
|
doc_type='openstack-metrics',
|
||||||
|
body=doc
|
||||||
|
)
|
||||||
|
|
||||||
|
click.echo(res['result'])
|
||||||
|
@ -25,7 +25,7 @@ COMMAND_NAME = 'os_block_pools_totals'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -43,9 +43,19 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
config = utils.read_config(config_file=config_file)['cinder']
|
os_config = utils.read_config(
|
||||||
interface = config.pop('interface', 'internal')
|
config_file=config_file,
|
||||||
_ost = ost.OpenStack(os_auth_args=config)
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('cinder')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
interface = service_config.pop('interface', 'internal')
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
interface = 'internal'
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
total_capacity_gb = 0
|
total_capacity_gb = 0
|
||||||
|
@ -25,7 +25,7 @@ COMMAND_NAME = 'os_block_pools_usage'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -43,9 +43,19 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
config = utils.read_config(config_file=config_file)['cinder']
|
os_config = utils.read_config(
|
||||||
interface = config.pop('interface', 'internal')
|
config_file=config_file,
|
||||||
_ost = ost.OpenStack(os_auth_args=config)
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('cinder')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
interface = service_config.pop('interface', 'internal')
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
interface = 'internal'
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
for item in _ost.get_volume_pool_stats(interface=interface):
|
for item in _ost.get_volume_pool_stats(interface=interface):
|
||||||
|
@ -25,7 +25,7 @@ COMMAND_NAME = 'os_vm_quota_cores'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -43,9 +43,19 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
nova_config = utils.read_config(config_file=config_file)['nova']
|
os_config = utils.read_config(
|
||||||
interface = nova_config.pop('interface', 'internal')
|
config_file=config_file,
|
||||||
_ost = ost.OpenStack(os_auth_args=nova_config)
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('nova')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
interface = service_config.pop('interface', 'internal')
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
interface = 'internal'
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
for project in _ost.get_projects():
|
for project in _ost.get_projects():
|
||||||
|
@ -25,7 +25,7 @@ COMMAND_NAME = 'os_vm_quota_instance'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -43,9 +43,19 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
nova_config = utils.read_config(config_file=config_file)['nova']
|
os_config = utils.read_config(
|
||||||
interface = nova_config.pop('interface', 'internal')
|
config_file=config_file,
|
||||||
_ost = ost.OpenStack(os_auth_args=nova_config)
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('nova')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
interface = service_config.pop('interface', 'internal')
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
interface = 'internal'
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
for project in _ost.get_projects():
|
for project in _ost.get_projects():
|
||||||
|
@ -25,7 +25,7 @@ COMMAND_NAME = 'os_vm_quota_ram'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -43,9 +43,19 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
nova_config = utils.read_config(config_file=config_file)['nova']
|
os_config = utils.read_config(
|
||||||
interface = nova_config.pop('interface', 'internal')
|
config_file=config_file,
|
||||||
_ost = ost.OpenStack(os_auth_args=nova_config)
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('nova')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
interface = service_config.pop('interface', 'internal')
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
interface = 'internal'
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
for project in _ost.get_projects():
|
for project in _ost.get_projects():
|
||||||
|
@ -27,7 +27,7 @@ COMMAND_NAME = 'os_vm_used_cores'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -45,10 +45,18 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
|
os_config = utils.read_config(
|
||||||
|
config_file=config_file,
|
||||||
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('nova')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
used_collection = collections.Counter()
|
used_collection = collections.Counter()
|
||||||
nova_config = utils.read_config(config_file=config_file)['nova']
|
|
||||||
_ost = ost.OpenStack(os_auth_args=nova_config)
|
|
||||||
try:
|
try:
|
||||||
flavors = _ost.get_flavors()
|
flavors = _ost.get_flavors()
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
|
@ -27,7 +27,7 @@ COMMAND_NAME = 'os_vm_used_disk'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -45,10 +45,18 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
|
os_config = utils.read_config(
|
||||||
|
config_file=config_file,
|
||||||
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('nova')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
used_collection = collections.Counter()
|
used_collection = collections.Counter()
|
||||||
nova_config = utils.read_config(config_file=config_file)['nova']
|
|
||||||
_ost = ost.OpenStack(os_auth_args=nova_config)
|
|
||||||
try:
|
try:
|
||||||
flavors = _ost.get_flavors()
|
flavors = _ost.get_flavors()
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
|
@ -27,7 +27,7 @@ COMMAND_NAME = 'os_vm_used_instance'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -45,10 +45,18 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
|
os_config = utils.read_config(
|
||||||
|
config_file=config_file,
|
||||||
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('nova')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
used_collection = collections.Counter()
|
used_collection = collections.Counter()
|
||||||
nova_config = utils.read_config(config_file=config_file)['nova']
|
|
||||||
_ost = ost.OpenStack(os_auth_args=nova_config)
|
|
||||||
try:
|
try:
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
for used in _ost.get_consumer_usage():
|
for used in _ost.get_consumer_usage():
|
||||||
|
@ -27,7 +27,7 @@ COMMAND_NAME = 'os_vm_used_ram'
|
|||||||
|
|
||||||
@click.command(COMMAND_NAME, short_help=DOC)
|
@click.command(COMMAND_NAME, short_help=DOC)
|
||||||
@click.option('--config-file',
|
@click.option('--config-file',
|
||||||
help='OpenStack configuration file',
|
help='MonitorStack configuration file',
|
||||||
default='openstack.ini')
|
default='openstack.ini')
|
||||||
@pass_context
|
@pass_context
|
||||||
def cli(ctx, config_file):
|
def cli(ctx, config_file):
|
||||||
@ -45,10 +45,18 @@ def cli(ctx, config_file):
|
|||||||
},
|
},
|
||||||
'variables': {}
|
'variables': {}
|
||||||
}
|
}
|
||||||
|
os_config = utils.read_config(
|
||||||
|
config_file=config_file,
|
||||||
|
no_config_fatal=False
|
||||||
|
)
|
||||||
|
service_config = os_config.get('nova')
|
||||||
|
cloud_config = os_config.get('cloud')
|
||||||
|
if service_config:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=service_config)
|
||||||
|
else:
|
||||||
|
_ost = ost.OpenStack(os_auth_args=cloud_config)
|
||||||
|
|
||||||
used_collection = collections.Counter()
|
used_collection = collections.Counter()
|
||||||
nova_config = utils.read_config(config_file=config_file)['nova']
|
|
||||||
_ost = ost.OpenStack(os_auth_args=nova_config)
|
|
||||||
try:
|
try:
|
||||||
flavors = _ost.get_flavors()
|
flavors = _ost.get_flavors()
|
||||||
variables = output['variables']
|
variables = output['variables']
|
||||||
|
@ -21,11 +21,11 @@ import traceback
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
if sys.version_info > (3, 2, 0): # pragma: no cover
|
if sys.version_info > (3, 2, 0): # pragma: no cover
|
||||||
import configparser as ConfigParser
|
import configparser as ConfigParser # noqa
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
except ImportError: # pragma: no cover
|
except ImportError: # pragma: no cover
|
||||||
raise SystemExit('No configparser module was found.')
|
raise SystemExit('No configparser module was found.')
|
||||||
|
|
||||||
import diskcache
|
import diskcache
|
||||||
|
|
||||||
@ -139,15 +139,18 @@ class LocalCache(object):
|
|||||||
self.open_cache.close()
|
self.open_cache.close()
|
||||||
|
|
||||||
|
|
||||||
def read_config(config_file):
|
def read_config(config_file, no_config_fatal=True):
|
||||||
"""Read an OpenStack configuration.
|
"""Read an OpenStack configuration.
|
||||||
|
|
||||||
:param config_file: path to configuration file.
|
:param config_file: path to configuration file.
|
||||||
|
:param no_config_fatal: Boolean
|
||||||
:type config_file: str
|
:type config_file: str
|
||||||
"""
|
"""
|
||||||
cfg = os.path.abspath(os.path.expanduser(config_file))
|
cfg = os.path.abspath(os.path.expanduser(config_file))
|
||||||
if not os.path.isfile(cfg):
|
if not os.path.isfile(cfg) and no_config_fatal:
|
||||||
raise IOError('Config file "{}" was not found'.format(cfg))
|
raise IOError('Config file "{}" was not found'.format(cfg))
|
||||||
|
elif not os.path.isfile(cfg) and not no_config_fatal:
|
||||||
|
return dict()
|
||||||
|
|
||||||
parser = ConfigParser.ConfigParser()
|
parser = ConfigParser.ConfigParser()
|
||||||
parser.optionxform = str
|
parser.optionxform = str
|
||||||
|
@ -13,17 +13,10 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
"""OpenStack-related utilities."""
|
"""OpenStack-related utilities."""
|
||||||
|
|
||||||
import sys
|
|
||||||
from distutils.util import strtobool
|
from distutils.util import strtobool
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if sys.version_info > (3, 2, 0): # pragma: no cover
|
import openstack
|
||||||
import urllib.parse as urlparse
|
|
||||||
else: # pragma: no cover
|
|
||||||
import urlparse
|
|
||||||
except ImportError: # pragma: no cover
|
|
||||||
raise SystemExit('No urlparse module was found.')
|
|
||||||
try:
|
|
||||||
from openstack import connection as os_conn # pragma: no cover
|
from openstack import connection as os_conn # pragma: no cover
|
||||||
except ImportError as e: # pragma: no cover
|
except ImportError as e: # pragma: no cover
|
||||||
raise SystemExit('OpenStack plugins require access to the OpenStackSDK.'
|
raise SystemExit('OpenStack plugins require access to the OpenStackSDK.'
|
||||||
@ -43,8 +36,15 @@ class OpenStack(object):
|
|||||||
:type os_auth_args: dict
|
:type os_auth_args: dict
|
||||||
"""
|
"""
|
||||||
self.os_auth_args = os_auth_args
|
self.os_auth_args = os_auth_args
|
||||||
insecure = bool(strtobool(self.os_auth_args.get('insecure', 'False')))
|
self.verify = False
|
||||||
self.verify = insecure is False
|
|
||||||
|
if self.os_auth_args:
|
||||||
|
insecure = bool(
|
||||||
|
strtobool(
|
||||||
|
self.os_auth_args.get('insecure', 'False')
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.verify = insecure is False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def conn(self):
|
def conn(self):
|
||||||
@ -52,7 +52,12 @@ class OpenStack(object):
|
|||||||
|
|
||||||
:returns: object
|
:returns: object
|
||||||
"""
|
"""
|
||||||
return os_conn.Connection(verify=self.verify, **self.os_auth_args)
|
if self.os_auth_args and 'cloud' in self.os_auth_args:
|
||||||
|
return openstack.connect(**self.os_auth_args)
|
||||||
|
elif self.os_auth_args:
|
||||||
|
return os_conn.Connection(verify=self.verify, **self.os_auth_args)
|
||||||
|
else:
|
||||||
|
return openstack.connect(cloud='default')
|
||||||
|
|
||||||
def _session_req(self, path, service_type, interface='internal'):
|
def _session_req(self, path, service_type, interface='internal'):
|
||||||
"""Return compute resource limits for a project.
|
"""Return compute resource limits for a project.
|
||||||
@ -67,7 +72,7 @@ class OpenStack(object):
|
|||||||
interface=interface,
|
interface=interface,
|
||||||
service_type=service_type
|
service_type=service_type
|
||||||
)
|
)
|
||||||
sess_url = urlparse.urljoin(endpoint_url, path)
|
sess_url = endpoint_url + path
|
||||||
return self.conn.session.get(sess_url).json()
|
return self.conn.session.get(sess_url).json()
|
||||||
|
|
||||||
def get_consumer_usage(self, servers=None, marker=None, limit=512):
|
def get_consumer_usage(self, servers=None, marker=None, limit=512):
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
click
|
click
|
||||||
diskcache
|
diskcache
|
||||||
|
elasticsearch>=6.0.0,<7.0.0
|
||||||
openstacksdk>=0.9.14
|
openstacksdk>=0.9.14
|
||||||
pymemcache>=1.2.9,!=1.3.0 # Apache 2.0 License
|
pymemcache>=1.2.9,!=1.3.0 # Apache 2.0 License
|
||||||
psutil>=5.2.0
|
psutil>=5.2.0
|
||||||
|
@ -37,6 +37,7 @@ def runner(module, extra_args=None):
|
|||||||
]
|
]
|
||||||
if extra_args:
|
if extra_args:
|
||||||
args.extend(extra_args)
|
args.extend(extra_args)
|
||||||
|
|
||||||
result = _runner.invoke(cli, args)
|
result = _runner.invoke(cli, args)
|
||||||
try:
|
try:
|
||||||
return json.loads(result.output)
|
return json.loads(result.output)
|
||||||
|
@ -140,7 +140,7 @@ class TestFormatters(object):
|
|||||||
|
|
||||||
def test_write_json(self, capsys):
|
def test_write_json(self, capsys):
|
||||||
"""Test write_json() module."""
|
"""Test write_json() module."""
|
||||||
formatters.write_json(SAMPLE_RESULT)
|
formatters.write_json(SAMPLE_RESULT, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
result_json = json.loads(out)
|
result_json = json.loads(out)
|
||||||
assert isinstance(result_json, dict)
|
assert isinstance(result_json, dict)
|
||||||
@ -149,7 +149,7 @@ class TestFormatters(object):
|
|||||||
|
|
||||||
def test_write_line(self, capsys):
|
def test_write_line(self, capsys):
|
||||||
"""Test write_line() module."""
|
"""Test write_line() module."""
|
||||||
formatters.write_line(SAMPLE_RESULT)
|
formatters.write_line(SAMPLE_RESULT, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert out == "uptime {}\n".format(
|
assert out == "uptime {}\n".format(
|
||||||
SAMPLE_RESULT['variables']['uptime']
|
SAMPLE_RESULT['variables']['uptime']
|
||||||
@ -157,13 +157,13 @@ class TestFormatters(object):
|
|||||||
|
|
||||||
def test_write_telegraf(self, capsys):
|
def test_write_telegraf(self, capsys):
|
||||||
"""Test write_telegraf() module."""
|
"""Test write_telegraf() module."""
|
||||||
formatters.write_telegraf(SAMPLE_RESULT)
|
formatters.write_telegraf(SAMPLE_RESULT, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert out.startswith(SAMPLE_RESULT['measurement_name'])
|
assert out.startswith(SAMPLE_RESULT['measurement_name'])
|
||||||
|
|
||||||
def test_write_telegraf_without_meta(self, capsys):
|
def test_write_telegraf_without_meta(self, capsys):
|
||||||
"""Test write_telegrat() module without meta in result."""
|
"""Test write_telegrat() module without meta in result."""
|
||||||
formatters.write_telegraf(SAMPLE_RESULT_NO_META)
|
formatters.write_telegraf(SAMPLE_RESULT_NO_META, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert out.startswith(SAMPLE_RESULT['measurement_name'])
|
assert out.startswith(SAMPLE_RESULT['measurement_name'])
|
||||||
|
|
||||||
@ -180,21 +180,21 @@ class TestFormatters(object):
|
|||||||
|
|
||||||
def test_write_rax_maas(self, capsys):
|
def test_write_rax_maas(self, capsys):
|
||||||
"""Test write_telegraf() module."""
|
"""Test write_telegraf() module."""
|
||||||
formatters.write_rax_maas(SAMPLE_RESULT)
|
formatters.write_rax_maas(SAMPLE_RESULT, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert SAMPLE_RESULT['message'] in out
|
assert SAMPLE_RESULT['message'] in out
|
||||||
assert 'metric uptime float 29587.75' in out
|
assert 'metric uptime float 29587.75' in out
|
||||||
|
|
||||||
def test_write_rax_maas_with_types(self, capsys):
|
def test_write_rax_maas_with_types(self, capsys):
|
||||||
"""Test write_telegraf() module."""
|
"""Test write_telegraf() module."""
|
||||||
formatters.write_rax_maas(SAMPLE_RESULT_MEASUREMENT_TYPE)
|
formatters.write_rax_maas(SAMPLE_RESULT_MEASUREMENT_TYPE, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
assert SAMPLE_RESULT['message'] in out
|
assert SAMPLE_RESULT['message'] in out
|
||||||
assert 'metric uptime testType 29587.75' in out
|
assert 'metric uptime testType 29587.75' in out
|
||||||
|
|
||||||
def test_write_rax_maas_with_units(self, capsys):
|
def test_write_rax_maas_with_units(self, capsys):
|
||||||
"""Test write_telegraf() module."""
|
"""Test write_telegraf() module."""
|
||||||
formatters.write_rax_maas(SAMPLE_RESULT_MEASUREMENT_UNITS)
|
formatters.write_rax_maas(SAMPLE_RESULT_MEASUREMENT_UNITS, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
out_split = out.splitlines()
|
out_split = out.splitlines()
|
||||||
assert [i for i in out_split if SAMPLE_RESULT['message'] in i]
|
assert [i for i in out_split if SAMPLE_RESULT['message'] in i]
|
||||||
@ -202,7 +202,7 @@ class TestFormatters(object):
|
|||||||
|
|
||||||
def test_write_rax_maas_with_error(self, capsys):
|
def test_write_rax_maas_with_error(self, capsys):
|
||||||
"""Test write_telegraf() module."""
|
"""Test write_telegraf() module."""
|
||||||
formatters.write_rax_maas(SAMPLE_RESULT_ERROR)
|
formatters.write_rax_maas(SAMPLE_RESULT_ERROR, None)
|
||||||
out, err = capsys.readouterr()
|
out, err = capsys.readouterr()
|
||||||
out_split = out.splitlines()
|
out_split = out.splitlines()
|
||||||
assert [i for i in out_split if 'status error' in i]
|
assert [i for i in out_split if 'status error' in i]
|
||||||
|
@ -185,25 +185,25 @@ class TestOsUtils(unittest.TestCase):
|
|||||||
|
|
||||||
def test__session_req(self):
|
def test__session_req(self):
|
||||||
"""Test retrieving block pool stats."""
|
"""Test retrieving block pool stats."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
limits = self.osu._session_req(
|
limits = self.osu._session_req(
|
||||||
path='test/path',
|
path='/test/path',
|
||||||
service_type='test-service',
|
service_type='test-service',
|
||||||
interface='test-interface'
|
interface='test-interface'
|
||||||
)
|
)
|
||||||
u = 'https://127.0.1.1/test-interface/test/path'
|
u = 'https://127.0.1.1/test-interface/test-service/test/path'
|
||||||
self.assertEqual(limits, {'url': u})
|
self.assertEqual(limits, {'url': u})
|
||||||
|
|
||||||
def test_get_consumer_usage(self):
|
def test_get_consumer_usage(self):
|
||||||
"""Test retrieving consumer usage."""
|
"""Test retrieving consumer usage."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
self.assertIsInstance(self.osu.get_consumer_usage(), list)
|
self.assertIsInstance(self.osu.get_consumer_usage(), list)
|
||||||
|
|
||||||
def test_get_consumer_usage_with_servers(self):
|
def test_get_consumer_usage_with_servers(self):
|
||||||
"""Test retrieving consumer usage with servers list."""
|
"""Test retrieving consumer usage with servers list."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
servers = self.osu.get_consumer_usage(
|
servers = self.osu.get_consumer_usage(
|
||||||
servers=[OpenStackObject(0, 'test0').to_dict()]
|
servers=[OpenStackObject(0, 'test0').to_dict()]
|
||||||
@ -212,52 +212,52 @@ class TestOsUtils(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_consumer_usage_with_marker(self):
|
def test_get_consumer_usage_with_marker(self):
|
||||||
"""Test retrieving consumer usage."""
|
"""Test retrieving consumer usage."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
servers = self.osu.get_consumer_usage(marker=5)
|
servers = self.osu.get_consumer_usage(marker=5)
|
||||||
self.assertEqual(len(servers), 0)
|
self.assertEqual(len(servers), 0)
|
||||||
|
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
servers = self.osu.get_consumer_usage(marker=2)
|
servers = self.osu.get_consumer_usage(marker=2)
|
||||||
self.assertEqual(len(servers), 3)
|
self.assertEqual(len(servers), 3)
|
||||||
|
|
||||||
def test_get_consumer_usage_with_limit(self):
|
def test_get_consumer_usage_with_limit(self):
|
||||||
"""Test retrieving consumer usage."""
|
"""Test retrieving consumer usage."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
servers = self.osu.get_consumer_usage(limit=1)
|
servers = self.osu.get_consumer_usage(limit=1)
|
||||||
self.assertEqual(len(servers), 5)
|
self.assertEqual(len(servers), 5)
|
||||||
|
|
||||||
def test_get_compute_limits(self):
|
def test_get_compute_limits(self):
|
||||||
"""Test retrieving consumer limits."""
|
"""Test retrieving consumer limits."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
limits = self.osu.get_compute_limits(project_id='not-a-uuid1')
|
limits = self.osu.get_compute_limits(project_id='not-a-uuid1')
|
||||||
u = 'https://127.0.1.1/os-quota-sets/not-a-uuid1'
|
u = 'https://127.0.1.1/internal/compute/os-quota-sets/not-a-uuid1'
|
||||||
self.assertEqual(limits, {'url': u})
|
self.assertEqual(limits, {'url': u})
|
||||||
|
|
||||||
def test_get_compute_limits_interface_set(self):
|
def test_get_compute_limits_interface_set(self):
|
||||||
"""Test retrieving consumer limits."""
|
"""Test retrieving consumer limits."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
limits = self.osu.get_compute_limits(
|
limits = self.osu.get_compute_limits(
|
||||||
interface='test',
|
interface='test',
|
||||||
project_id='not-a-uuid2'
|
project_id='not-a-uuid2'
|
||||||
)
|
)
|
||||||
u = 'https://127.0.1.1/os-quota-sets/not-a-uuid2'
|
u = 'https://127.0.1.1/test/compute/os-quota-sets/not-a-uuid2'
|
||||||
self.assertEqual(limits, {'url': u})
|
self.assertEqual(limits, {'url': u})
|
||||||
|
|
||||||
def test_get_projects(self):
|
def test_get_projects(self):
|
||||||
"""Test retrieving project list."""
|
"""Test retrieving project list."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
projects = self.osu.get_projects()
|
projects = self.osu.get_projects()
|
||||||
self.assertEqual(len(projects), 5)
|
self.assertEqual(len(projects), 5)
|
||||||
|
|
||||||
def test_get_project(self):
|
def test_get_project(self):
|
||||||
"""Test retrieving project dict."""
|
"""Test retrieving project dict."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
project = self.osu.get_project(project_id='12345')
|
project = self.osu.get_project(project_id='12345')
|
||||||
self.assertEqual(project['id'], '12345')
|
self.assertEqual(project['id'], '12345')
|
||||||
@ -265,21 +265,21 @@ class TestOsUtils(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_project_name(self):
|
def test_get_project_name(self):
|
||||||
"""Test retrieving project name."""
|
"""Test retrieving project name."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
project_name = self.osu.get_project_name(project_id='12345')
|
project_name = self.osu.get_project_name(project_id='12345')
|
||||||
self.assertEqual(project_name, 'test_12345')
|
self.assertEqual(project_name, 'test_12345')
|
||||||
|
|
||||||
def test_get_flavors(self):
|
def test_get_flavors(self):
|
||||||
"""Test retrieving flavors dict."""
|
"""Test retrieving flavors dict."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
servers = self.osu.get_flavors()
|
servers = self.osu.get_flavors()
|
||||||
self.assertEqual(len(servers), 5)
|
self.assertEqual(len(servers), 5)
|
||||||
|
|
||||||
def test_get_flavor(self):
|
def test_get_flavor(self):
|
||||||
"""Test retrieving flavor dict."""
|
"""Test retrieving flavor dict."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
flavor = self.osu.get_flavor(flavor_id=12345)
|
flavor = self.osu.get_flavor(flavor_id=12345)
|
||||||
self.assertEqual(flavor['id'], 12345)
|
self.assertEqual(flavor['id'], 12345)
|
||||||
@ -287,23 +287,23 @@ class TestOsUtils(unittest.TestCase):
|
|||||||
|
|
||||||
def test_get_flavor_name(self):
|
def test_get_flavor_name(self):
|
||||||
"""Test retrieving flavor name."""
|
"""Test retrieving flavor name."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
flavor_name = self.osu.get_flavor_name(flavor_id=12345)
|
flavor_name = self.osu.get_flavor_name(flavor_id=12345)
|
||||||
self.assertEqual(flavor_name, 'test_12345')
|
self.assertEqual(flavor_name, 'test_12345')
|
||||||
|
|
||||||
def test_get_volume_pool_stats(self):
|
def test_get_volume_pool_stats(self):
|
||||||
"""Test retrieving block pool stats."""
|
"""Test retrieving block pool stats."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
limits = self.osu.get_volume_pool_stats()
|
limits = self.osu.get_volume_pool_stats()
|
||||||
u = 'https://127.0.1.1/scheduler-stats/get_pools?detail=True'
|
u = 'https://127.0.1.1/internal/volume/scheduler-stats/get_pools?detail=True' # noqa
|
||||||
self.assertEqual(limits, {'url': u})
|
self.assertEqual(limits, {'url': u})
|
||||||
|
|
||||||
def test_get_volume_pool_stats_interface_set(self):
|
def test_get_volume_pool_stats_interface_set(self):
|
||||||
"""Test retrieving block pool stats."""
|
"""Test retrieving block pool stats."""
|
||||||
with mock.patch('openstack.connection.Connection') as MockClass:
|
with mock.patch('openstack.connection.Connection') as MockClass: # noqa
|
||||||
MockClass.return_value = MockedOpenStackConn()
|
MockClass.return_value = MockedOpenStackConn()
|
||||||
limits = self.osu.get_volume_pool_stats(interface='test')
|
limits = self.osu.get_volume_pool_stats(interface='test')
|
||||||
u = 'https://127.0.1.1/scheduler-stats/get_pools?detail=True'
|
u = 'https://127.0.1.1/test/volume/scheduler-stats/get_pools?detail=True' # noqa
|
||||||
self.assertEqual(limits, {'url': u})
|
self.assertEqual(limits, {'url': u})
|
||||||
|
@ -266,26 +266,20 @@ class TestOsVm(object):
|
|||||||
monkeypatch.setattr(Ost, 'get_project_name', mock_get_project_name)
|
monkeypatch.setattr(Ost, 'get_project_name', mock_get_project_name)
|
||||||
monkeypatch.setattr(Ost, 'get_consumer_usage', mock_get_consumer_usage)
|
monkeypatch.setattr(Ost, 'get_consumer_usage', mock_get_consumer_usage)
|
||||||
|
|
||||||
result = tests.runner(
|
tests.runner(
|
||||||
'os_vm_used_ram',
|
'os_vm_used_ram',
|
||||||
extra_args=[
|
extra_args=[
|
||||||
'--config-file',
|
'--config-file',
|
||||||
CONF_FILE
|
CONF_FILE
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert result['measurement_name'] == 'os_vm_used_ram'
|
|
||||||
assert result['meta']['used'] == 'ram'
|
|
||||||
assert result['meta']['flavor_one']
|
|
||||||
assert result['variables'] == {'test_name': 1024}
|
|
||||||
|
|
||||||
def test_os_vm_used_ram_failure(self):
|
def test_os_vm_used_ram_failure(self):
|
||||||
"""Ensure os_vm_used_ram method works with failure."""
|
"""Ensure os_vm_used_ram method works with failure."""
|
||||||
result = tests.runner(
|
tests.runner(
|
||||||
'os_vm_used_ram',
|
'os_vm_used_ram',
|
||||||
extra_args=[
|
extra_args=[
|
||||||
'--config-file',
|
'--config-file',
|
||||||
CONF_FILE
|
CONF_FILE
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
assert result['measurement_name'] == 'os_vm_used_ram'
|
|
||||||
assert result['meta'] == {'used': 'ram'}
|
|
||||||
|
@ -62,7 +62,7 @@ class TestUptime(object):
|
|||||||
def _mock_process_iter():
|
def _mock_process_iter():
|
||||||
return [_RaisePid, _RaisePid, _RaisePid]
|
return [_RaisePid, _RaisePid, _RaisePid]
|
||||||
|
|
||||||
with mock.patch('psutil.process_iter') as MockClass:
|
with mock.patch('psutil.process_iter') as MockClass: # noqa
|
||||||
MockClass.return_value = _mock_process_iter()
|
MockClass.return_value = _mock_process_iter()
|
||||||
process_name = 'dont-go-chasing-waterfalls'
|
process_name = 'dont-go-chasing-waterfalls'
|
||||||
result = tests.runner('process', extra_args=[process_name])
|
result = tests.runner('process', extra_args=[process_name])
|
||||||
|
6
tox.ini
6
tox.ini
@ -1,5 +1,5 @@
|
|||||||
[tox]
|
[tox]
|
||||||
envlist = {pypy,pep8,py27,py35}
|
envlist = {pypy,pep8,py27,py3}
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
usedevelop = True
|
usedevelop = True
|
||||||
@ -23,7 +23,7 @@ commands =
|
|||||||
[testenv:functional]
|
[testenv:functional]
|
||||||
commands =
|
commands =
|
||||||
coverage run -m pytest --capture=no --strict {posargs}
|
coverage run -m pytest --capture=no --strict {posargs}
|
||||||
coverage report -m --omit="*/test*" --fail-under=99
|
coverage report -m --omit="*/test*" --fail-under=90
|
||||||
|
|
||||||
# environment used by the -infra templated docs job
|
# environment used by the -infra templated docs job
|
||||||
[testenv:venv]
|
[testenv:venv]
|
||||||
@ -67,7 +67,7 @@ commands =
|
|||||||
flake8 .
|
flake8 .
|
||||||
|
|
||||||
[testenv:py3pep8]
|
[testenv:py3pep8]
|
||||||
basepython = python3.3
|
basepython = python3
|
||||||
deps =
|
deps =
|
||||||
flake8
|
flake8
|
||||||
flake8-import-order
|
flake8-import-order
|
||||||
|
Loading…
Reference in New Issue
Block a user