def test_inactive_if_deactivate_on_is_fullfilled(self): extension_manager = ExtensionManager() messagebus = Mock() my_message_ids = object() my_endpoint_ids = object() my_config_opt = ConfigOptionId('name', 'description') config = MagicMock() config.filter_config.return_value.get.return_value = True config.filter_config.return_value.__contains__.return_value = True @FrameworkExtension( 'extension', config_options=[ConfigOption(my_config_opt, required=True)], deactivate_on=[my_config_opt]) class Extension(AbstractExtension): @callback_dispatcher(message_ids=my_message_ids, endpoint_ids=my_endpoint_ids) def my_callback_dispatcher(self): pass try: extension_manager.initialize_framework_extension(Extension, config) extension_manager.register_dispatchers(messagebus) self.assertEqual(messagebus.register_dispatcher.call_count, 0) finally: extension_manager.destroy()
def test_count_zero_will_not_override_default_value(self): count_option = ConfigOption( ConfigOptionId('count', '', option_type=Count(0, 1)), required=False) self.config.set(count_option.option_id, 1) with patch('sys.argv', ['zaf', 'command']): extension_config = self.plugin.get_config(self.config, [count_option], {COMMAND: []}) self.assertNotIn('count', extension_config.config)
def test_count_1_not_included_in_config_if_same_as_default(self): count_option = ConfigOption( ConfigOptionId('count', '', option_type=Count(0, 1)), required=False) self.config.set(count_option.option_id, 1) with patch('sys.argv', ['zaf', '--count', 'command']): extension_config = self.plugin.get_config(self.config, [count_option], {COMMAND: []}) self.assertNotIn('count', extension_config.config)
def test_count_clamped_to_max_value(self): count_option = ConfigOption( ConfigOptionId('count', '', option_type=Count(0, 1)), required=False) self.config.set(count_option.option_id, 0) with patch('sys.argv', ['zaf', '--count', '--count', 'command']): extension_config = self.plugin.get_config(self.config, [count_option], {COMMAND: []}) self.assertIn('count', extension_config.config) self.assertEqual(extension_config.config['count'], 1)
def test_count_can_be_given_multiple_times(self): count_option = ConfigOption( ConfigOptionId('count', '', option_type=Count(0, 2)), required=False) self.config.set(count_option.option_id, 0) with patch('sys.argv', ['zaf', '--count', '--count', 'command']): extension_config = self.plugin.get_config(self.config, [count_option], {COMMAND: []}) self.assertIn('count', extension_config.config) self.assertEqual(extension_config.config['count'], 2)
def option(name, namespace=None, short_name=None): global unique_id_counter unique_id_counter += 1 return ConfigOption( ConfigOptionId( name, str(unique_id_counter), namespace=namespace, short_alias=bool(namespace), short_name=short_name), required=True)
time_spent = current_time - self._last_time[interface] self._last_measurement[interface] = new_measurement self._last_time[interface] = current_time result[interface] = { 'rx_kbps': difference['rx_bytes'] / (1024 * time_spent), 'tx_kbps': difference['tx_bytes'] / (1024 * time_spent), } return result SYSTEM_NETWORK_USAGE_MONITOR_ENABLED = ConfigOptionId( 'monitors.sysnet.enabled', 'Should the system network usage monitor be enabled', at=SUT, option_type=bool, default=True) @CommandExtension( name='linuxmonitor', extends=[RUN_COMMAND], config_options=[ ConfigOption(SUT, required=True, instantiate_on=True), ConfigOption(SYSTEM_NETWORK_USAGE_MONITOR_ENABLED, required=False), ], groups=['monitor'], activate_on=[SYSTEM_NETWORK_USAGE_MONITOR_ENABLED], ) class SystemNetworkUsageMonitor(AbstractExtension):
from zaf.config.options import ConfigOptionId from zaf.config.types import ConfigChoice from zaf.messages.message import EndpointId, MessageId from k2.sut import SUT K2_POWER_METER_COMPONENT = 'PowerMeter' POWER_METER_TIMEOUT = 15 AVAILABLE_POWER_METERS = ConfigOptionId( 'powermeter.available', 'A collection of all availabe power meter options', multiple=True) POWER_METER = ConfigOptionId('powermeter', 'The type of the power meter', at=SUT, option_type=ConfigChoice(AVAILABLE_POWER_METERS)) POWER_METER_CONNECTION_CHECK_ENDPOINT = EndpointId( 'powermetercc', 'Endpoint for power meter connection check') POWER_METER_CONNECTION_CHECK_ENABLED = ConfigOptionId( 'powermetercc.enabled', 'Should powermeter connection check be enabled', at=SUT, option_type=bool, default=True) POWER_METER_CONNECTION_CHECK_REQUIRED = ConfigOptionId( 'powermetercc.required',
def test_config_id_is_not_mistaken_for_subgroup(self): my_id = ConfigOptionId('id', 'description') self.assertFalse(is_subgroup(my_id))
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')
from zaf.config.options import ConfigOptionId from zaf.messages.message import EndpointId, MessageId TEST_SOURCES = ConfigOptionId( 'test.sources', 'One or more test sources. Can be files, modules, classes etc', multiple=True, argument=True) FINDER_ENDPOINT = EndpointId('testfinder', """\ The test finder """) FIND_TEST_CASES = MessageId( 'FIND_TEST_CASES', """\ Request to find test cases. returns: List of TestCase """)
self.assertRaises(SystemExit),\ redirect_stdout(help_output): self.plugin.get_config(self.config, self.options, self.commands_with_options) if not_in: self.assertNotIn(string, help_output.getvalue(), msg=help_output.getvalue()) else: self.assertIn(string, help_output.getvalue(), msg=help_output.getvalue()) COMMAND_INTERNAL = CommandId( 'internalcommand', '', callable=None, config_options=[], application_contexts=ApplicationContext.INTERNAL) COMMAND_EXTENDABLE = CommandId( 'extendablecommand', '', callable=None, config_options=[], application_contexts=ApplicationContext.EXTENDABLE) COMMAND_NONE = CommandId('nonecommand', '', callable=None, config_options=[]) OPTION_INTERNAL = ConfigOption( ConfigOptionId('internaloption', '', application_contexts=ApplicationContext.INTERNAL), required=False) OPTION_EXTENDABLE = ConfigOption( ConfigOptionId('extendableoption', '', application_contexts=ApplicationContext.EXTENDABLE), required=False) OPTION_NONE = ConfigOption(ConfigOptionId('noneoption', ''), required=False)
from zaf.config.options import ConfigOptionId from k2.sut import SUT from . import SERIAL_BAUDRATE, SERIAL_CONNECTION_CHECK_ENABLED, SERIAL_CONNECTION_CHECK_REQUIRED, \ SERIAL_DEVICE, SERIAL_ENABLED, SERIAL_FILTERS, SERIAL_LOG_ENABLED, SERIAL_PORT_IDS, \ SERIAL_PROMPT, SERIAL_TIMEOUT, SUT_SERIAL_PORTS SUT_SERIAL_ENABLED = ConfigOptionId('serial.enabled', 'Should serial port be enabled', at=SUT, option_type=bool, default=False) SUT_SERIAL_LOG_ENABLED = ConfigOptionId('serial.log', """\ Should serial trigger LOG_LINE_RECEIVED events. LOG_LINE_RECEIVED events are used by other extensions (e.g. SutEvents) to provide additional functionality and components.""", at=SUT, option_type=bool, default=True) SUT_SERIAL_CONNECTION_CHECK_ENABLED = ConfigOptionId( 'serialcc.enabled', 'Should serial connection check be enabled', at=SUT, option_type=bool, default=True)
from zaf.config.options import ConfigOptionId from zaf.config.types import Choice, ConfigChoice, Flag, Path from zaf.messages.message import EndpointId 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',
elif subcommand == 'state': 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(
f.write(output) def copy_custom_logging_docs(doc_dir, custom_logging_docs): for f in custom_logging_docs: shutil.copy(os.path.abspath(f), doc_dir) return [os.path.basename(f) for f in custom_logging_docs] def file_path(dir, name): return os.path.join(dir, name.replace(' ', '_')) DOC_DIR = ConfigOptionId('doc.dir', 'Directory to store generated documentation in', default='${output.dir}/docs', namespace='docgen', short_alias=True) LIMIT_EXTENSION_NAMESPACES = ConfigOptionId( 'limit.extension.namespaces', 'If given extensions will only be included if they match the namespaces.', multiple=True, namespace='docgen', short_alias=True) ADDITIONAL_EXTENSIONS = ConfigOptionId( 'additional.extensions', "Include additional extensions that don't match the given namespaces.", multiple=True, namespace='docgen',
from zaf.config.options import ConfigOptionId from zaf.messages.message import EndpointId, MessageId SCHEDULER_ENDPOINT = EndpointId( 'scheduler', """\ Handles the scheduling of test cases. The run queue can be modified during the run using a set of messages. """) TESTS_INCLUDE = ConfigOptionId( 'tests.include', 'Include test cases where the start of the qualified name matches this value. ' 'Syntax is "package[.module[[.class].testcase]]."', multiple=True, ) TESTS_INCLUDE_REGEX = ConfigOptionId( 'tests.include.regex', 'Include test cases where the qualified name matches this regex.', multiple=True, ) TESTS_EXCLUDE = ConfigOptionId( 'tests.exclude', 'Exclude test cases where the start of the qualified name matches this value. ' 'Syntax is "package[.module[[.class].testcase]]."', multiple=True, ) TESTS_EXCLUDE_REGEX = ConfigOptionId( 'tests.exclude.regex',
from zaf.config.options import ConfigOptionId from zaf.messages.message import EndpointId, MessageId INSTANCES = ConfigOptionId('ids', 'description instance', multiple=True, namespace='instances', entity=True) MY_EXTENSION_ENDPOINT = EndpointId( 'MY_EXTENSION_ENDPOINT', """\ This is my extensions endpoint """) MY_EXTENSION_MESSAGE = MessageId( 'MY_EXTENSION_MESSAGE', """ This is my extensions message data: None """)
css_stylesheet = zpider.config.get(HTML_CSS_STYLESHEET) futures = zpider.messagebus.send_request( GENERATE_DOC, data=HtmlAsciidoctorCommand(output_html, css_stylesheet)) futures.wait() try: futures[0].result() print('Created output file: {file}'.format(file=output_html)) return 0 except Exception as e: print("Failed to create file '{file}': {msg}".format(file=output_html, msg=str(e))) return 1 OUTPUT_HTML = ConfigOptionId('output.html', 'The output HTML file. Default <input name>.html.') HTML_CSS_STYLESHEET = ConfigOptionId( 'css.stylesheet', 'The CSS stylesheet', default=data_file('styles/zenterio-html-theme.css'), option_type=Path(exists=True)) HTML_COMMAND = CommandId( 'html', 'Generate HTML', html, [ ConfigOption(OUTPUT_HTML, required=False), ConfigOption(HTML_CSS_STYLESHEET, required=True), ]) @FrameworkExtension(
from zaf.config.options import ConfigOptionId from zaf.messages.message import EndpointId from k2.sut import SUT ZNAIL_IP = ConfigOptionId('znail.ip', 'IP number to the Znail device', at=SUT) ZNAIL_PORT = ConfigOptionId('znail.port', 'Port number to connect to', option_type=int, default=80, at=SUT) ZNAIL_TIMEOUT = ConfigOptionId( 'znail.timeout', 'Timeout when communicating with the Znail device, in seconds', option_type=int, default=10, at=SUT) ZNAIL_CONNECTION_CHECK_ENDPOINT = EndpointId( 'znailcc', 'Endpoint for the Znail connection check') ZNAIL_CONNECTION_CHECK_ENABLED = ConfigOptionId( 'znailcc.enabled', 'Should Znail connection check be enabled', at=SUT, option_type=bool, default=True) ZNAIL_CONNECTION_CHECK_REQUIRED = ConfigOptionId(
status_code = None try: status_code = int(args[2]) except Exception: pass if status_code is not None: server.accept_upload(path, file, status_code=status_code) else: server.accept_upload(path, file) server.server_thread.join() FILE_SERVER_IP = ConfigOptionId('ip', 'The ip to use for the file server', default='localhost', namespace='httpfileserver') FILE_SERVER_PORT = ConfigOptionId('port', 'The port to use for the file server', option_type=int, default=0, namespace='httpfileserver') FILE_SERVER_SERVE_DATA = ConfigOptionId( 'serve.data', 'Serve data on a specific path. path:string[:status code][:queries]', multiple=True, namespace='httpfileserver') FILE_SERVER_SERVE_FILE = ConfigOptionId(
from zaf.config.options import ConfigOptionId LOGDEFAULTS_ENABLED = ConfigOptionId('logdefaults.enabled', 'Should logdefaults be enabled', option_type=bool, default=True)
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 ConfigOption, ConfigOptionId from zaf.extensions.extension import FrameworkExtension, get_logger_name from k2.utils.writers import JsonWriter from ..messages import collect_metrics from .reporter import AbstractMetricsReportExtension logger = logging.getLogger(get_logger_name('k2', 'metrics.json')) logger.addHandler(logging.NullHandler()) JSON_REPORTER_ID = ConfigOptionId( name='ids', description='Names a JSON metrics reporter instance', multiple=True, entity=True, namespace='metrics.json', ) JSON_DIRECTORY = ConfigOptionId( name='dir', description='Directory to write the JSON reports to', default='${output.dir}/metrics/json', at=JSON_REPORTER_ID, ) JSON_FILENAME = ConfigOptionId( name='filename', description='Name of the JSON file to write', at=JSON_REPORTER_ID,
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())
if report_file: command.extend(['--xunit-file', report_file]) if verbose: command.extend(['-v', '--with-timer']) if tests: command.extend(tests) else: command.extend(packages) return command EXTENSION_NAMES = ConfigOptionId('extension.names', 'The extension to run unittests for', argument=True, multiple=True) REPORT_ENABLED = ConfigOptionId('report.enabled', 'Generate a test report', option_type=Flag(), default=False, namespace='unittest', short_alias=True) REPORT_FILE = ConfigOptionId('report.file', 'File name of the test report', default='nosetests.xml', namespace='unittest', short_alias=True)
zebra exec "do something; do something else" zebra exec "do something || do something if that failed" """ command_with_arguments = application.config.get( EXEC_COMMAND_WITH_ARGUMENTS) return docker_run.run_in_docker(command_with_arguments, forward_signals=False) EXEC_COMMAND_WITH_ARGUMENTS = ConfigOptionId( 'command.with.arguments', 'The command to run.', multiple=True, namespace='exec', argument=True, ) EXEC_COMMAND = CommandId( 'exec', exec.__doc__, exec, config_options=[ ConfigOption(EXEC_COMMAND_WITH_ARGUMENTS, required=True), ], allow_unknown_options=True, )
from zaf.config.options import ConfigOptionId ZELENIUM_ENABLED = ConfigOptionId( 'zelenium.enabled', 'Should the Zelenium addon be enabled', option_type=bool, default=False) ZELENIUM_HEADLESS = ConfigOptionId( 'zelenium.headless', 'Should the browser run in headless mode', option_type=bool, default=True) ZELENIUM_FIREFOX = ConfigOptionId( 'zelenium.firefox', 'Should support for the Firefox browser be enabled', option_type=bool, default=True)
from zaf.config.options import ConfigOptionId from zaf.config.types import Flag from zaf.messages.message import EndpointId ABORT_ON_FAIL_ENABLED = ConfigOptionId('abort.on.fail', 'Enable abort on fail addon', option_type=Flag(), default=False) ABORT_ON_FAIL_ENDPOINT = EndpointId('abortonfailaddon', """ Abort on fail """) ABORT_ON_UNEXPECTED_SUT_RESET_ENDPOINT = EndpointId( 'abortonunexpectedsutreset', """ Abort on unexpected sut reset """) ABORT_ON_UNEXPECTED_SUT_RESET = ConfigOptionId( 'abort.on.unexpected.sut.reset', 'Abort a test run when an unexpected sut reset occurs.', option_type=Flag(), default=False)
from zaf.config.options import ConfigOptionId REQ_OPTION_1 = ConfigOptionId('req.option1', 'description req.option1') REQ_OPTION_2 = ConfigOptionId('req.option2', 'description req.option2')