Esempio n. 1
0
def test_install_from_source(test_plugins, file_server):
    with _patch_client([]):
        installer.install(
            plugins.plugin_struct(file_server, source='mock-plugin.tar'))
    _assert_task_runnable('mock_plugin.tasks.run', expected_return='run')
    _assert_task_runnable('mock_plugin.tasks.call_entry_point',
                          expected_return='mock-plugin-entry-point')
Esempio n. 2
0
def _test_logging(daemon_fixture):
    message = 'THIS IS THE TEST MESSAGE LOG CONTENT'

    daemon = daemon_fixture.create_daemon()
    daemon.create()
    daemon.configure()
    installer.install(daemon_fixture.plugin_struct())
    installer.install(daemon_fixture.plugin_struct(),
                      deployment_id=DEPLOYMENT_ID)
    daemon.start()

    def log_and_assert(_message, _deployment_id=None):
        daemon_fixture.send_task(task_name='mock_plugin.tasks.do_logging',
                                 queue=daemon.queue,
                                 kwargs={'message': _message},
                                 deployment_id=_deployment_id)

        name = _deployment_id if _deployment_id else '__system__'
        logdir = os.path.join(daemon.workdir, 'logs')
        logfile = os.path.join(logdir, '{0}.log'.format(name))
        try:
            with open(logfile) as f:
                assert _message in f.read()
        except IOError:
            daemon_fixture.logger.warning('{0} content: {1}'.format(
                logdir, os.listdir(logdir)))
            raise

    # Test __system__ logs
    log_and_assert(message)
    # Test deployment logs
    log_and_assert(message, DEPLOYMENT_ID)
Esempio n. 3
0
def _test_conf_env_variables(daemon_fixture):
    daemon = daemon_fixture.create_daemon()
    daemon.create()
    daemon.configure()
    installer.install(daemon_fixture.plugin_struct())
    daemon.start()

    expected = {
        constants.REST_HOST_KEY:
        ','.join(daemon.rest_host),
        constants.REST_PORT_KEY:
        str(daemon.rest_port),
        constants.MANAGER_FILE_SERVER_URL_KEY:
        ','.join('https://{0}:{1}/resources'.format(host, daemon.rest_port)
                 for host in daemon.rest_host),
        constants.AGENT_WORK_DIR_KEY:
        daemon.workdir,
    }

    def _get_env_var(var):
        return daemon_fixture.send_task(
            task_name='mock_plugin.tasks.get_env_variable',
            queue=daemon.queue,
            kwargs={'env_variable': var})

    def _check_env_var(var, expected_value):
        _value = _get_env_var(var)
        assert _value == expected_value

    for key, value in expected.items():
        _check_env_var(key, value)
Esempio n. 4
0
def _test_restart(daemon_fixture):
    daemon = daemon_fixture.create_daemon()
    daemon.create()
    daemon.configure()
    installer.install(daemon_fixture.plugin_struct())
    daemon.start()
    daemon.restart()
Esempio n. 5
0
def test_install_from_wagon(test_plugins, file_server):
    with _patch_for_install_wagon(
            plugins.PACKAGE_NAME,
            plugins.PACKAGE_VERSION,
            download_path=test_plugins[plugins.PACKAGE_NAME],
    ):
        installer.install(plugins.plugin_struct(file_server))
    _assert_wagon_plugin_installed()
Esempio n. 6
0
def test_uninstall_from_source(test_plugins, file_server):
    with _patch_client([]):
        installer.install(
            plugins.plugin_struct(file_server, source='mock-plugin.tar'))
    _assert_task_runnable('mock_plugin.tasks.run', expected_return='run')
    with _patch_client([]):
        installer.uninstall(plugin=plugins.plugin_struct(file_server))
        _assert_task_not_runnable('mock_plugin.tasks.run')
Esempio n. 7
0
def test_install_from_source_with_requirements(test_plugins, file_server):
    with _patch_client([]):
        installer.install(
            plugins.plugin_struct(file_server,
                                  source='mock-plugin-with-requirements.tar',
                                  args='-r requirements.txt'))
    _assert_task_runnable(
        'mock_with_install_args_for_test.module.do_stuff',
        expected_return='on the brilliant marble-sanded beaches of '
        'Santraginus V')
Esempio n. 8
0
def test_install_from_source_with_deployment_id(test_plugins, file_server):
    deployment_id = 'deployment'
    with _patch_client([]):
        installer.install(plugins.plugin_struct(file_server,
                                                source='mock-plugin.tar'),
                          deployment_id=deployment_id)
        _assert_task_not_runnable('mock_plugin.tasks.run')
    _assert_task_runnable('mock_plugin.tasks.run',
                          expected_return='run',
                          deployment_id=deployment_id)
Esempio n. 9
0
def test_install_from_wagon_overriding_same_version(test_plugins, file_server):
    test_install_from_wagon(test_plugins, file_server)
    with _patch_for_install_wagon(
            plugins.PACKAGE_NAME,
            plugins.PACKAGE_VERSION,
            download_path=test_plugins['mock-plugin-modified'],
            plugin_id='2'):
        with pytest.raises(exceptions.PluginInstallationError,
                           match='.*does not match the ID.*'):
            installer.install(plugins.plugin_struct(file_server))
Esempio n. 10
0
def install_plugins(plugins, **_):
    for plugin in plugins:
        name = plugin.get('package_name') or plugin['name']
        ctx.logger.info('Installing plugin: %s', name)
        try:
            plugin_installer.install(plugin=plugin,
                                     deployment_id=ctx.deployment.id,
                                     blueprint_id=ctx.blueprint.id)
        except exceptions.PluginInstallationError as e:
            # preserve traceback
            tpe, value, tb = sys.exc_info()
            reraise(NonRecoverableError, NonRecoverableError(str(e)), tb)
Esempio n. 11
0
def _test_extra_env(daemon_fixture):
    daemon = daemon_fixture.create_daemon()
    daemon.extra_env_path = utils.env_to_file(
        {'TEST_ENV_KEY': 'TEST_ENV_VALUE'}, posix=os.name == 'posix')
    daemon.create()
    daemon.configure()
    installer.install(daemon_fixture.plugin_struct())
    daemon.start()

    # check the env file was properly sourced by querying the env
    # variable from the daemon process. this is done by a task
    value = daemon_fixture.send_task(
        task_name='mock_plugin.tasks.get_env_variable',
        queue=daemon.queue,
        kwargs={'env_variable': 'TEST_ENV_KEY'})
    assert value == 'TEST_ENV_VALUE'
Esempio n. 12
0
def _test_execution_env(daemon_fixture):
    daemon = daemon_fixture.create_daemon()
    daemon.create()
    daemon.configure()
    installer.install(daemon_fixture.plugin_struct())
    daemon.start()

    # check that cloudify.dispatch.dispatch 'execution_env' processing
    # works.
    # not the most ideal place for this test. but on the other hand
    # all the boilerplate is already here, so this is too tempting.
    value = daemon_fixture.send_task(
        task_name='mock_plugin.tasks.get_env_variable',
        queue=daemon.queue,
        kwargs={'env_variable': 'TEST_ENV_KEY2'},
        execution_env={'TEST_ENV_KEY2': 'TEST_ENV_VALUE2'})
    assert value == 'TEST_ENV_VALUE2'
Esempio n. 13
0
def test_install_no_source_or_managed_plugin(file_server):
    with _patch_client([]):
        with pytest.raises(cloudify_exceptions.NonRecoverableError,
                           match='.*source or managed.*'):
            installer.install(plugins.plugin_struct(file_server))
Esempio n. 14
0
 def installer_func(dep_id='__system__'):
     with current_ctx.push(ctx_obj):
         installer.install(plugins.plugin_struct(file_server), dep_id)