from zaf.config.options import ConfigOptionId from zaf.config.types import Choice SERIES_AGGREGATOR_IDS = ConfigOptionId( name='ids', description='Names a series value aggregator instance', multiple=True, entity=True, namespace='metrics.aggregators.series', ) SOURCE_SERIES = ConfigOptionId( name='source.namespace', description='The metrics series to aggregate the values of', multiple=True, at=SERIES_AGGREGATOR_IDS, ) TARGET_VALUE = ConfigOptionId( name='target.namespace', description='The metrics namespace to write the results to', at=SERIES_AGGREGATOR_IDS, ) SERIES_AGGREGATOR_TYPE = ConfigOptionId( name='type', description='Type of aggregator', option_type=Choice(['min', 'max', 'average']), at=SERIES_AGGREGATOR_IDS, )
from zaf.config.options import ConfigOptionId from zaf.config.types import Choice, Flag class RunException(Exception): pass ENV = ConfigOptionId('env', 'Select the environment to run shell commands in', option_type=Choice(['docker', 'host']), default='docker') ROOT = ConfigOptionId('root', 'Run as the root user inside the Docker environment.', option_type=Flag())
from k2.sut import SUT ANSIBLE_ENDPOINT = EndpointId('ansible', 'Ansible Manager') ANSIBLE_ENABLED = ConfigOptionId( 'ansible.enabled', 'Should Ansible support be enabled', option_type=Flag(), default=False, ) ANSIBLE_BACKEND = ConfigOptionId( 'ansible.backend', 'Backend to test against', option_type=Choice(['docker']), default='docker', ) ANSIBLE_CONFIGS = ConfigOptionId( 'ansible.configs', 'KEY=value pairs of ansible config. The key should be the Ansible environment variable name of the config option.', option_type=str, multiple=True, ) ANSIBLE_CONFIG_FILE = ConfigOptionId( 'ansible.configfile', 'Path to ansible.cfg', option_type=str, )
from zaf.config.options import ConfigOptionId from zaf.config.types import Choice REPORTS_TEXT = ConfigOptionId( 'reports.text', 'Print test results in human readable text format', option_type=bool, default=True) REPORTS_TEXT_OUTPUT = ConfigOptionId('reports.text.output', 'Output location(s), default stdout', option_type=str, multiple=True, default=['-']) REPORTS_TEXT_SHOW_OWNER = ConfigOptionId('reports.text.show.owner', 'Show the owner of test cases. ', option_type=bool, default=False) REPORTS_TEXT_TEMPLATE = ConfigOptionId('reports.text.format', 'Choose how much to print. ', option_type=Choice( ['full', 'brief', 'summary']), default='full')
APPLICATION_ROOT = ConfigOptionId( 'application.root', 'The root package of the application', application_contexts=ApplicationContext.INTERNAL) ENTRYPOINT_NAME = ConfigOptionId( 'application.entrypoint', 'Name of the entrypoint', application_contexts=ApplicationContext.INTERNAL) APPLICATION_VERSION = ConfigOptionId( 'application.version', 'Version of the application', application_contexts=ApplicationContext.INTERNAL) APPLICATION_CONTEXT = ConfigOptionId( 'application.context', 'The application context for the application', option_type=Choice([item.name for item in list(ApplicationContext)]), default='EXTENDABLE', transform=ApplicationContext.__getitem__, application_contexts=ApplicationContext.INTERNAL) APPLICATION_CHANGELOG_TYPE = ConfigOptionId( 'application.changelog.type', 'Changelog type for this application', option_type=Choice([item.name for item in list(ChangeLogType)]), default='NONE', transform=ChangeLogType.__getitem__, application_contexts=ApplicationContext.INTERNAL) CWD = ConfigOptionId('cwd', 'Current working directory', default=os.getcwd(), application_contexts=ApplicationContext.INTERNAL)
text += 'The power state of sut {sut} is {state}\n'.format( sut=sut, state=sut_result['state']) else: if sut_result['changed']: text += 'The power state of sut {sut} changed to {state}\n'.format( sut=sut, state=sut_result['state']) else: text += 'The power state of sut {sut} was already {state}\n'.format( sut=sut, state=sut_result['state']) return text POWER_SUBCOMMAND = ConfigOptionId( 'powerswitch.subcommand', 'The subcommand to powerswitch', option_type=Choice(['state', 'on', 'off']), argument=True) POWER_COMMAND = CommandId( 'powerswitch', power.__doc__, power, config_options=[ ConfigOption(POWER_SUBCOMMAND, required=True), ConfigOption(JSON_OUTPUT, required=False), ConfigOption(SUT, required=True) ]) @FrameworkExtension( 'powerswitch',
self.config, [ConfigOption(TRANSFORM_TO_OTHER_TYPE, required=False)], {COMMAND: []}) self.assertNotIn('transform', extension_config.config) def test_transform_not_performed_on_default_value_by_using_invalid_choice( self): with patch('sys.argv', ['zaf', 'command']): extension_config = self.plugin.get_config( self.config, [ConfigOption(TRANSFORM_FROM_CHOICE, required=False)], {COMMAND: []}) self.assertNotIn('transform', extension_config.config) COMMAND = CommandId('command', '', callable=None, config_options=[]) TRANSFORM = ConfigOptionId('transform', '', default='original', transform=lambda s: 'transformed') TRANSFORM_TO_OTHER_TYPE = ConfigOptionId('transform.to.other.type', '', default=2.3, option_type=float, transform=lambda s: 'transformed') TRANSFORM_FROM_CHOICE = ConfigOptionId('transform.to.other.type', '', default='1', option_type=Choice(['1', '2', '3']), transform=lambda s: '4')
'', option_type=float), required=False) BOOL_OPTION = ConfigOption(ConfigOptionId('bool.option', '', option_type=bool), required=False) FLAG_OPTION = ConfigOption(ConfigOptionId('flag.option', '', option_type=Flag()), required=False) PATH_OPTION = ConfigOption(ConfigOptionId('path.option', '', option_type=Path(exists=True)), required=False) CHOICE_OPTION = ConfigOption(ConfigOptionId('choice.option', '', option_type=Choice(['1', '2'])), required=False) CONFIG_CHOICE_OPTION = ConfigOption(ConfigOptionId( 'config.choice.option', '', option_type=ConfigChoice(MULTIPLE_STR_OPTION.option_id)), required=False) TRANSFORM_OPTION = ConfigOption(ConfigOptionId('transform.option', '', transform=lambda s: int(s)), required=False) TRANSFORM_CHOICE_OPTION = ConfigOption(ConfigOptionId('transform.option', '', option_type=Choice( ['1', '2']), transform=lambda s: 3),
from zaf.config.options import ConfigOptionId from zaf.config.types import Choice, Path STR_OPTION = ConfigOptionId('str.option', 'description str.option', str) INT_OPTION = ConfigOptionId('int.option', 'description int.option', int) FLOAT_OPTION = ConfigOptionId('float.option', 'description float.option', float) CHOICE_OPTION = ConfigOptionId('choice.option', 'description choice.option', Choice(['a', 'b', 'c'])) PATH_OPTION = ConfigOptionId('path.option', 'description path.option', Path(exists=True)) BOOL_OPTION = ConfigOptionId('bool.option', 'description bool.option', bool)
from zaf.config.options import ConfigOptionId from zaf.config.types import Choice, Flag from zebra.docker import docker IMAGE_OPTION = ConfigOptionId( 'image', 'The name of the image to use.', option_type=Choice(sorted(docker.IMAGES.keys())), default=list(docker.IMAGES.keys())[0], short_name='i', ) IMAGE_OVERRIDE_OPTION = ConfigOptionId( 'image.override', 'Override the image option to allow the loading of any image in the repository.', ) TAG_OPTION = ConfigOptionId( 'tag', 'The tag of the image to use.', default='latest', short_name='t', ) REGISTRY_OPTION = ConfigOptionId( 'registry', 'The registry to fetch the image from.', default='docker.zenterio.lan', short_name='r', ) USE_REGISTRY_OPTION = ConfigOptionId( 'use.registry', 'Specify if registry should be used when determining URL to pull from.',
def _make_directories(path): logger.info('Creating directories: {path}'.format(path=path)) os.makedirs(path) def _make_file(path, contents): logger.info('Writing file: {path}'.format(path=path)) with open(path, 'w') as f: f.write(contents) ADDON_SUBCOMMAND = ConfigOptionId('addon.subcommand', 'The subcommand to addon', option_type=Choice(['create']), argument=True) ADDON_COMMAND = CommandId('addon', addon.__doc__, addon, config_options=[ ConfigOption(ADDON_SUBCOMMAND, required=True), ]) @FrameworkExtension( 'addon', commands=[ADDON_COMMAND], groups=['addon'], )