Ejemplo n.º 1
0
    def _get_config(options={}):
        defaults = {
            IMAGE_OPTION: 'abs.u14',
            IMAGE_OVERRIDE_OPTION: None,
            TAG_OPTION: 'TAG',
            REGISTRY_OPTION: 'REGISTRY',
            USE_REGISTRY_OPTION: True,
            PULL_OPTION: False,
            ENV_VARIABLES_OPTION: [],
            MOUNTS_OPTION: [],
            HOSTNAME_OPTION: 'HOSTNAME',
            ROOT_OPTION: False,
            ROOT_DIR_OPTION: None,
            CONTAINER_ROOT_DIR_OPTION: '/zebra/workspace',
            PROJECT_DIR_OPTION: None,
            PROJECT_DIR_NAME_OPTION: None,
            NETWORK_OPTION: None,
        }
        for key, value in options.items():
            defaults[key] = value

        config = ConfigManager()
        for key, value in defaults.items():
            config.set(key, value)

        return DockerConfig(config)
Ejemplo n.º 2
0
def create_harness(endpoints_and_messages, config):
    config_manager = ConfigManager()
    for id, value in config.items():
        config_manager.set(id, value)

    return ExtensionTestHarness(
        RemoteServer, endpoints_and_messages=endpoints_and_messages, config=config_manager)
Ejemplo n.º 3
0
def _create_harness(config=None):
    config_manager = ConfigManager()
    for id, value in config.items() if config else []:
        config_manager.set(id, value)
    return ExtensionTestHarness(Metrics,
                                config=config_manager,
                                endpoints_and_messages={})
Ejemplo n.º 4
0
def create_harness(verbosity=0):
    config = ConfigManager()
    if verbosity > 0:
        config.set(VERBOSE, verbosity)

    return ExtensionTestHarness(
        ZebraLoggingExtension,
        config=config,
    )
 def setUp(self):
     self.plugin = ClickParseCli({}, {})
     self.config = ConfigManager()
     self.options = [OPTION_INTERNAL, OPTION_EXTENDABLE, OPTION_NONE]
     self.commands_with_options = {
         COMMAND_INTERNAL: [OPTION_INTERNAL, OPTION_EXTENDABLE, OPTION_NONE],
         COMMAND_EXTENDABLE: [OPTION_INTERNAL, OPTION_EXTENDABLE, OPTION_NONE],
         COMMAND_NONE: [OPTION_INTERNAL, OPTION_EXTENDABLE, OPTION_NONE],
     }
Ejemplo n.º 6
0
def create_harness(docker_run=Mock()):
    config = ConfigManager()
    config.set(EXEC_COMMAND_WITH_ARGUMENTS, ('exec', 'with', 'args'))

    return ExtensionTestHarness(
        CacheExtension,
        config=config,
        components=[ComponentMock('DockerRun', docker_run)],
    )
Ejemplo n.º 7
0
    def test_enabling_remote_client_registers_component(self):
        component_manager = ComponentManager()
        component_manager.clear_component_registry()

        config = ConfigManager()
        config.set(REMOTE_CLIENT_ENABLED, True)

        with ExtensionTestHarness(RemoteClientExtension, config=config):
            self.assertIn('RemoteClient', component_manager.COMPONENT_REGISTRY)
Ejemplo n.º 8
0
def _create_harness():
    config = ConfigManager()
    with patch('os.path.exists', return_value=True):
        config.set(PLUGIN_DIRS, ['/path/to/plugins'])

    return ExtensionTestHarness(
        AsciidoctorPlugins,
        config=config,
    )
Ejemplo n.º 9
0
    def _create_harness(sut=['entity'], power_meter='dummy', value=4.2):
        config = ConfigManager()
        entity = sut[0]
        config.set(SUT, sut)
        config.set(AVAILABLE_POWER_METERS, ['dummy', 'notgude'])
        config.set(POWER_METER, power_meter, entity=entity)
        config.set(DUMMY_POWER_METER_VALUE, value, entity=entity)

        return ExtensionTestHarness(DummyPowerMeter, config=config)
Ejemplo n.º 10
0
def _create_harness(env=Mock()):
    config = ConfigManager()
    with patch('os.path.exists', return_value=True):
        config.set(ADOC_FILE, 'file.adoc')
    return ExtensionTestHarness(
        AsciidoctorExtension,
        endpoints_and_messages={OPTIONS_ENDPOINT: [GET_ASCIIDOCTOR_OPTIONS]},
        config=config,
        components=[ComponentMock('Env', env)])
Ejemplo n.º 11
0
    def create_harness():
        config = ConfigManager()
        config.set(MULTI_RUNNER_ENABLED, True)

        return ExtensionTestHarness(MultiRunner,
                                    config=config,
                                    endpoints_and_messages={
                                        RUN_COMMAND_ENDPOINT: [TEST_RUN],
                                    })
Ejemplo n.º 12
0
def create_config(options, entity=None, additional_options={}):
    config = ConfigManager()
    for option_id, value in options.items():
        key = config._option_key(option_id, entity)
        config._config[key].add(value, 1, '')
    for option, value in additional_options.items():
        key = config._option_key(option.option_id)
        config._config[key].add(value, 1, '')
    return config
Ejemplo n.º 13
0
    def test_disabled_does_not_register_to_messages(self):
        config = ConfigManager()
        config.set(REPORTS_TESTNG, False)

        with ExtensionTestHarness(TestNgReporter, config=config) as h:
            assert not h.any_registered_dispatchers(TEST_RESULTS_COLLECTED,
                                                    RESULTS_ENDPOINT)
            assert not h.any_registered_dispatchers(POST_TEST_RUN,
                                                    RUN_COMMAND_ENDPOINT)
Ejemplo n.º 14
0
def _create_harness(enabled=True):
    config = ConfigManager()
    config.set(ABORT_ON_FAIL_ENABLED, enabled)
    harness = ExtensionTestHarness(
        AbortOnFail,
        config=config,
        endpoints_and_messages={RUNNER_ENDPOINT: [TEST_CASE_FINISHED]})

    return harness
Ejemplo n.º 15
0
 def test_get_config_uses_ansible_node_as_suts_when_set(self):
     config = ConfigManager()
     config.set_default_values([ANSIBLE_NODES, ANSIBLE_NODE])
     config.set(ANSIBLE_NODES, ['1', '2', '3'])
     config.set(ANSIBLE_NODE, ['2', '3'])
     config.set(ANSIBLE_ENABLED, True)
     ansible_suts = AnsibleSuts(None, None)
     self.assertCountEqual(
         ansible_suts.get_config(config, [], {}).config['suts.ids'],
         ['2', '3'])
Ejemplo n.º 16
0
def _create_harness(timeout='10'):
    config = ConfigManager()
    config.set(COMMAND_TIMEOUT, timeout)

    return ExtensionTestHarness(CommandTimeout,
                                config=config,
                                endpoints_and_messages={
                                    RUN_COMMAND_ENDPOINT:
                                    [BEFORE_COMMAND, AFTER_COMMAND]
                                })
Ejemplo n.º 17
0
    def create_harness():
        config = ConfigManager()
        config.set(SUT, ['mysut'])

        return ExtensionTestHarness(
            HealthMonitor,
            config=config,
            endpoints_and_messages={
                MOCK_ENDPOINT: [TEST_CASE_FINISHED, SUT_RECOVERY_PERFORM],
            })
Ejemplo n.º 18
0
    def setUp(self):
        output_dir = './output'

        config = ConfigManager()
        config.set(OUTPUT_DIR, output_dir)

        component_context = Mock()
        component_context.callable_qualname = 'package.module.test_case'

        self.workspace = Workspace(component_context, config)
Ejemplo n.º 19
0
def _create_harness(enabled=True):
    config = ConfigManager()
    config.set(ABORT_ON_UNEXPECTED_SUT_RESET, enabled)
    harness = ExtensionTestHarness(
        AbortOnUnexpectedSutReset,
        config=config,
        endpoints_and_messages={
            RUNNER_ENDPOINT: [SUT_RESET_STARTED]
        })

    return harness
Ejemplo n.º 20
0
    def test_clean_containers_does_not_do_anything_when_suts_does_not_can_docker(self):
        manager = Mock()
        manager.get_cans.return_value = []
        config = ConfigManager()
        config.set(SUT, ['sut1', 'sut2'])
        docker = Mock()

        with patch('virt.docker_clean.get_docker_client', return_value=docker), \
                patch('virt.docker_clean.get_container') as m:
            clean_containers(Mock(), manager, config)
            m.assert_not_called()
Ejemplo n.º 21
0
    def test_serial_log_not_enabled(self):
        sut = 'sut'
        port = 'port'
        config = ConfigManager()
        config.set(SUT, [sut])
        config.set(SUT_SERIAL_PORTS, [port], entity=sut)
        config.set(SERIAL_ENABLED, True, entity=port)
        config.set(SERIAL_LOG_ENABLED, False, entity=port)

        with ExtensionTestHarness(SerialFrameworkExtension,
                                  config=config) as harness:
            ext_config = harness.extension.get_config(config, Mock(), Mock())
            self.assertEqual(ext_config.config, {})
Ejemplo n.º 22
0
def _create_harness():
    config = ConfigManager()
    entity = 'myjsonreporter'
    config.set(JSON_REPORTER_ID, [entity])
    config.set(JSON_DIRECTORY, 'my/json/directory', entity=entity)
    config.set(JSON_FILENAME, 'myreport.json', entity=entity)
    config.set(JSON_NAMESPACE, 'my_metrics_namespace', entity=entity)

    return ExtensionTestHarness(
        MetricsJsonReporter,
        config=config,
        endpoints_and_messages={METRICS_ENDPOINT: [GENERATE_METRICS_REPORT]},
    )
Ejemplo n.º 23
0
    def create_harness(headless=True, firefox_enabled=False):
        config = ConfigManager()
        config.set(ZELENIUM_ENABLED, True)
        config.set(ZELENIUM_HEADLESS, headless)
        config.set(ZELENIUM_FIREFOX, firefox_enabled)

        return ExtensionTestHarness(Zelenium, config=config)
Ejemplo n.º 24
0
    def test_sets_root_logger_level_and_attaches_stdout_handler(self):
        logger = MagicMock()
        handler = Mock()

        config = ConfigManager()
        config.set(LOG_LEVEL, 'warning')

        with patch('logging.getLogger', return_value=logger), \
                patch('logging.StreamHandler', return_value=handler), \
                patch('zaf.builtin.logging.logging.Filter', return_value=filter) as get_filter:
            with ExtensionTestHarness(RootLogger, config=config):
                logger.setLevel.assert_called_with(logging.DEBUG)
                logger.addHandler.assert_called_with(handler)
                self.assertEqual(handler.addFilter.call_count, 1)
                get_filter.assert_called_with({'': 30})
Ejemplo n.º 25
0
 def test_get_config_does_not_create_config_when_not_enabled(self):
     config = ConfigManager()
     config.set_default_values([ANSIBLE_NODES, ANSIBLE_NODE])
     config.set(ANSIBLE_NODES, ['1', '2', '3'])
     config.set(ANSIBLE_ENABLED, False)
     ansible_suts = AnsibleSuts(None, None)
     self.assertNotIn('suts.ids',
                      ansible_suts.get_config(config, [], {}).config)
Ejemplo n.º 26
0
    def test_sut_serial_log_enabled_adds_log_source(self):
        sut = 'sut'
        config = ConfigManager()
        config.set(SUT, [sut])
        config.set(SUT_SERIAL_ENABLED, True, entity=sut)
        config.set(SUT_SERIAL_DEVICE, '/dev/null', entity=sut)
        config.set(SUT_SERIAL_LOG_ENABLED, True, entity=sut)

        with ExtensionTestHarness(SerialFrameworkExtension,
                                  config=config) as harness:
            ext_config = harness.extension.get_config(config, Mock(), Mock())
            self.assertGreater(len(ext_config.config), 0)
            self.assertEqual(ext_config.config[SERIAL_PORT_IDS.key], [sut])
            self.assertEqual(
                ext_config.config[config_key(SUT_LOG_SOURCES, sut)],
                ['serial-sut'])
Ejemplo n.º 27
0
    def create_harness(
            znail_cc_enabled=True, znail_cc_required=True, sut=['entity'], component_mock=None):
        config = ConfigManager()
        entity = sut[0]
        config.set(SUT, sut)
        config.set(ZNAIL_IP, '1.2.3.4', entity=entity)
        config.set(ZNAIL_CONNECTION_CHECK_ENABLED, znail_cc_enabled, entity=entity)
        config.set(ZNAIL_CONNECTION_CHECK_REQUIRED, znail_cc_required, entity=entity)

        if component_mock is None:
            component_mock = Mock()

        return ExtensionTestHarness(
            ZnailConnectionCheck,
            config=config,
            components=[ComponentMock(name='Znail', mock=component_mock)])
Ejemplo n.º 28
0
 def test_throws_on_unexpected_exit_code(self):
     with _create_harness(ConfigManager()) as harness:
         scope = Scope(name='myscope')
         exec = harness.component_factory.call(DockerContainerExec, scope)
         harness.node._container.exec.return_value = ('stdout', 'stderr', 1)
         with self.assertRaises(DockerError):
             exec.send_line('command', expected_exit_code=0)
Ejemplo n.º 29
0
    def test_test_finder_extension_calls_finder_when_receiving_request(self):
        config = ConfigManager()
        config.set(TEST_SOURCES, ['name1', 'name2'])

        with ExtensionTestHarness(TestFinder, config=config) as harness:

            expected_result = Mock()
            # Don't want to run the real finder because it's very hard to get nose to work as intended
            # inside a unittest
            with patch('k2.finder.testfinder.Finder.find_tests',
                       return_value=expected_result) as find_tests_mock:
                actual_tests = harness.send_request(
                    FIND_TEST_CASES,
                    FINDER_ENDPOINT).wait(timeout=1)[0].result(timeout=1)
                self.assertEqual(expected_result, actual_tests)
                find_tests_mock.assert_called_with('name1', 'name2')
Ejemplo n.º 30
0
    def test_enabling_using_config(self):
        config = ConfigManager()
        config.set(BLOCKER_ENABLED, True)

        with ExtensionTestHarness(
                Blocker,
                endpoints_and_messages={APPLICATION_ENDPOINT: [AFTER_COMMAND]},
                config=config) as harness:
            self.assertTrue(harness.extension._enabled)

        with ExtensionTestHarness(Blocker,
                                  endpoints_and_messages={
                                      TEST_BLOCKER_ENDPOINT:
                                      [TEST_BLOCKER_BLOCK],
                                      APPLICATION_ENDPOINT: [AFTER_COMMAND]
                                  }) as harness:
            self.assertFalse(harness.extension._enabled)