added mock support for external input

ignore patch files in git

Change-Id: I7e9b293989db4997f7d5c731be6a45478693eba6
This commit is contained in:
Elisha Rosensweig 2015-12-30 16:24:34 +02:00
parent c7e0b55d35
commit 71654564fb
4 changed files with 38 additions and 15 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.patch
*.iml
#swap file
*.swp

View File

@ -64,7 +64,8 @@ def generate_random_events_list(generator_spec_list):
def simple_instance_generators(host_num, vm_num,
snapshot_events=0, update_events=0):
snapshot_events=0, update_events=0,
snap_vals=None, update_vals=None):
"""A function for returning vm event generators.
Returns generators for a given number of hosts and
@ -74,6 +75,8 @@ def simple_instance_generators(host_num, vm_num,
:param vm_num: number of vms
:param snapshot_events: number of snapshot events per instance
:param update_events: number of update events per instance
:param snap_vals: preset vals for ALL snapshot events
:param update_vals: preset vals for ALL update events
:return: generators for vm_num vms as specified
"""
@ -86,6 +89,7 @@ def simple_instance_generators(host_num, vm_num,
test_entity_spec_list.append(
{tg.DYNAMIC_INFO_FKEY: tg.SYNC_INST_SNAPSHOT_D,
tg.STATIC_INFO_FKEY: tg.SYNC_INST_SNAPSHOT_S,
tg.EXTERNAL_INFO_KEY: snap_vals,
tg.MAPPING_KEY: mapping,
tg.NAME_KEY: 'Instance (vm) snapshot generator',
tg.NUM_EVENTS: snapshot_events
@ -95,6 +99,7 @@ def simple_instance_generators(host_num, vm_num,
test_entity_spec_list.append(
{tg.DYNAMIC_INFO_FKEY: tg.SYNC_INST_UPDATE_D,
tg.STATIC_INFO_FKEY: None,
tg.EXTERNAL_INFO_KEY: update_vals,
tg.MAPPING_KEY: mapping,
tg.NAME_KEY: 'Instance (vm) update generator',
tg.NUM_EVENTS: update_events

View File

@ -45,7 +45,8 @@ def generate_random_events_list(generator_spec_list):
return data
def simple_instance_generators(host_num, vm_num, snapshot_events=0):
def simple_instance_generators(host_num, vm_num, snapshot_events=0,
snap_vals=None):
"""A simple function for returning vm generators.
Returns generators for a given number of hosts and
@ -66,6 +67,7 @@ def simple_instance_generators(host_num, vm_num, snapshot_events=0):
{tg.DYNAMIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_D,
tg.STATIC_INFO_FKEY: tg.TRANS_INST_SNAPSHOT_S,
tg.MAPPING_KEY: mapping,
tg.EXTERNAL_INFO_KEY: snap_vals,
tg.NAME_KEY: 'Instance (vm) snapshot generator',
tg.NUM_EVENTS: snapshot_events
}
@ -74,7 +76,8 @@ def simple_instance_generators(host_num, vm_num, snapshot_events=0):
return tg.get_trace_generators(test_entity_spec_list)
def simple_host_generators(zone_num, host_num, snapshot_events=0):
def simple_host_generators(zone_num, host_num, snapshot_events=0,
snap_vals=None):
"""A simple function for returning vm generators.
Returns generators for a given number of hosts and
@ -95,6 +98,7 @@ def simple_host_generators(zone_num, host_num, snapshot_events=0):
{tg.DYNAMIC_INFO_FKEY: tg.HOST_SNAPSHOT_D,
tg.STATIC_INFO_FKEY: tg.HOST_SNAPSHOT_S,
tg.MAPPING_KEY: mapping,
tg.EXTERNAL_INFO_KEY: snap_vals,
tg.NAME_KEY: 'Host snapshot generator',
tg.NUM_EVENTS: snapshot_events
}
@ -103,7 +107,7 @@ def simple_host_generators(zone_num, host_num, snapshot_events=0):
return tg.get_trace_generators(test_entity_spec_list)
def simple_zone_generators(zone_num, snapshot_events=0):
def simple_zone_generators(zone_num, snapshot_events=0, snap_vals=None):
"""A simple function for returning vm generators.
Returns generators for a given number of hosts and
@ -122,6 +126,7 @@ def simple_zone_generators(zone_num, snapshot_events=0):
{tg.DYNAMIC_INFO_FKEY: tg.ZONE_SNAPSHOT_D,
tg.STATIC_INFO_FKEY: tg.ZONE_SNAPSHOT_S,
tg.MAPPING_KEY: mapping,
tg.EXTERNAL_INFO_KEY: snap_vals,
tg.NAME_KEY: 'Zone snapshot generator',
tg.NUM_EVENTS: snapshot_events
}

View File

@ -34,6 +34,7 @@ DYNAMIC_INFO_FKEY = 'filename'
STATIC_INFO_FKEY = 'static_filename'
NAME_KEY = 'name'
MAPPING_KEY = 'mapping'
EXTERNAL_INFO_KEY = 'external'
NUM_EVENTS = '#events'
GENERATOR = 'generator'
@ -152,9 +153,9 @@ def _get_sync_vm_snapshot_values(spec):
"OS-EXT-SRV-ATTR:host": host_name,
"OS-EXT-SRV-ATTR:hypervisor_hostname": host_name,
'name': vm_name}
vm_static_info = utils.generate_vals(static_info_re)
static_values.append(utils.merge_vals(vm_static_info, mapping))
static_values.append(combine_data(
static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
))
return static_values
@ -176,8 +177,9 @@ def _get_trans_vm_snapshot_values(spec):
mapping = {'hostname': host_name,
'id': vm_name,
'name': vm_name}
vm_static_info = utils.generate_vals(static_info_re)
static_values.append(utils.merge_vals(vm_static_info, mapping))
static_values.append(combine_data(
static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
))
return static_values
@ -199,8 +201,9 @@ def _get_sync_vm_update_values(spec):
for vm_name, host_name in vm_host_mapping:
mapping = {'payload': {'host': host_name,
'display_name': vm_name}}
vm_static_info = utils.generate_vals(static_info_re)
static_values.append(utils.merge_vals(vm_static_info, mapping))
static_values.append(combine_data(
static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
))
return static_values
@ -223,8 +226,9 @@ def _get_host_snapshot_values(spec):
mapping = {'zone_id': zone_name,
'name': host_name,
'id': host_name}
host_static_info = utils.generate_vals(static_info_re)
static_values.append(utils.merge_vals(host_static_info, mapping))
static_values.append(combine_data(
static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
))
return static_values
@ -246,12 +250,20 @@ def _get_zone_snapshot_values(spec):
for zone_name, node_name in zone_node_mapping:
mapping = {'name': zone_name,
'id': zone_name}
host_static_info = utils.generate_vals(static_info_re)
static_values.append(utils.merge_vals(host_static_info, mapping))
static_values.append(combine_data(
static_info_re, mapping, spec.get(EXTERNAL_INFO_KEY, None)
))
return static_values
def combine_data(static_info_re, mapping_info, external_info):
if external_info:
mapping_info = utils.merge_vals(mapping_info, external_info)
static_info = utils.generate_vals(static_info_re)
return utils.merge_vals(static_info, mapping_info)
def get_trace_generators(entity_spec_list, default_events=100):
"""Returns a collection of event generators.