Ejemplo n.º 1
0
    def test_create_with_custom_options(self, *factory_methods):
        self._run('cfy-agent daemons create --name=name '
                  '--queue=queue --manager-ip=127.0.0.1 --user=user '
                  '--process-management=init.d '
                  '--key=value --complex-key=complex-value')

        factory_new = factory_methods[4]
        factory_new.assert_called_once_with(
            name='name',
            queue='queue',
            user='******',
            manager_ip='127.0.0.1',
            process_management='init.d',
            broker_ip=None,
            workdir=None,
            max_workers=None,
            min_workers=None,
            broker_port=None,
            includes=None,
            host=None,
            deployment_id=None,
            log_level=None,
            pid_file=None,
            log_file=None,
            manager_port=None,
            extra_env_path=None,
            logger=get_logger(),
            key='value',
            complex_key='complex-value',
            broker_user='******',
            broker_pass='******',
            broker_ssl_cert=None,
            broker_ssl_enabled=False,
            broker_get_settings_from_manager=False,
        )
Ejemplo n.º 2
0
def create(**params):

    """
    Creates and stores the daemon parameters.

    """
    attributes = dict(**params)
    attributes.update(_parse_security_settings(attributes))
    custom_arg = attributes.pop('custom_options', ())
    attributes.update(_parse_custom_options(custom_arg))

    click.echo('Creating...')

    _create_rest_ssl_cert(attributes)
    # _create_rest_ssl_cert called before get_broker_configuration because it
    # might be required for the rest call to succeed
    if attributes['broker_get_settings_from_manager']:
        broker = api_utils.internal.get_broker_configuration(attributes)
        attributes.update(broker)
    # _create_broker_ssl_cert called after get_broker_configuration because the
    # cert might be retrieved there
    _create_broker_ssl_cert(attributes)

    from cloudify_agent.shell.main import get_logger
    daemon = DaemonFactory().new(
        logger=get_logger(),
        **attributes
    )

    daemon.create()
    _save_daemon(daemon)
    click.echo('Successfully created daemon: {0}'
               .format(daemon.name))
Ejemplo n.º 3
0
def create(**params):

    """
    Creates and stores the daemon parameters.

    """

    attributes = dict(**params)
    custom_arg = attributes.pop('custom_options', ())
    attributes.update(_parse_custom_options(custom_arg))
    click.echo('Creating...')
    from cloudify_agent.shell.main import get_logger

    if attributes['broker_get_settings_from_manager']:
        broker = api_utils.internal.get_broker_configuration(attributes)
        attributes.update(broker)

    daemon = DaemonFactory().new(
        logger=get_logger(),
        **attributes
    )

    daemon.create()
    _save_daemon(daemon)
    click.echo('Successfully created daemon: {0}'
               .format(daemon.name))
Ejemplo n.º 4
0
    def test_create_with_custom_options(self, *factory_methods):
        self._run('cfy-agent daemons create --name=name '
                  '--queue=queue --manager-ip=127.0.0.1 --user=user '
                  '--process-management=init.d '
                  '--key=value --complex-key=complex-value')

        factory_new = factory_methods[4]
        factory_new.assert_called_once_with(
            name='name',
            queue='queue',
            user='******',
            manager_ip='127.0.0.1',
            process_management='init.d',
            broker_ip=None,
            workdir=None,
            broker_url=None,
            max_workers=None,
            min_workers=None,
            broker_port=None,
            includes=None,
            host=None,
            deployment_id=None,
            log_level=None,
            pid_file=None,
            log_file=None,
            manager_port=None,
            extra_env_path=None,
            logger=get_logger(),
            key='value',
            complex_key='complex-value'
        )
Ejemplo n.º 5
0
    def test_restart(self, *factory_methods):
        self._run("cfy-agent daemons restart --name=name")

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with("name", logger=get_logger())

        daemon = factory_load.return_value
        daemon.restart.assert_called_once_with()
Ejemplo n.º 6
0
    def test_restart(self, *factory_methods):
        self._run('cfy-agent daemons restart --name=name')

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with('name', logger=get_logger())

        daemon = factory_load.return_value
        daemon.restart.assert_called_once_with()
Ejemplo n.º 7
0
    def test_stop(self, *factory_methods):
        self._run("cfy-agent daemons stop --name=name " "--interval 5 --timeout 20")

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with("name", logger=get_logger())

        daemon = factory_load.return_value
        daemon.stop.assert_called_once_with(interval=5, timeout=20)
Ejemplo n.º 8
0
    def test_register(self, *factory_methods):
        self._run('cfy-agent daemons register ' '--name=name --plugin=plugin')

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with('name', logger=get_logger())

        daemon = factory_load.return_value
        daemon.register.assert_called_once_with('plugin')
Ejemplo n.º 9
0
    def test_start(self, *factory_methods):
        self._run("cfy-agent daemons start --name=name " "--interval 5 --timeout 20 --no-delete-amqp-queue")

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with("name", logger=get_logger())

        daemon = factory_load.return_value
        daemon.start.assert_called_once_with(interval=5, timeout=20, delete_amqp_queue=False)
Ejemplo n.º 10
0
    def test_unregister(self, *factory_methods):
        self._run("cfy-agent daemons unregister " "--name=name --plugin=plugin")

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with("name", logger=get_logger())

        daemon = factory_load.return_value
        daemon.unregister.assert_called_once_with("plugin")
Ejemplo n.º 11
0
    def test_delete(self, *factory_methods):
        self._run('cfy-agent daemons delete --name=name')

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with('name',
                                             logger=get_logger())

        daemon = factory_load.return_value
        daemon.delete.assert_called_once_with()
Ejemplo n.º 12
0
    def test_register(self, *factory_methods):
        self._run('cfy-agent daemons register '
                  '--name=name --plugin=plugin')

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with('name', logger=get_logger())

        daemon = factory_load.return_value
        daemon.register.assert_called_once_with('plugin')
Ejemplo n.º 13
0
    def test_stop(self, *factory_methods):
        self._run('cfy-agent daemons stop --name=name '
                  '--interval 5 --timeout 20')

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with('name', logger=get_logger())

        daemon = factory_load.return_value
        daemon.stop.assert_called_once_with(interval=5, timeout=20)
Ejemplo n.º 14
0
def test_restart(mock_daemon_factory_new, mock_daemon_factory_save,
                 mock_daemon_factory_load, mock_daemon_factory_delete,
                 mock_daemon_factory_load_all, mock_get_storage_dir):
    run_agent_command('cfy-agent daemons restart --name=name')

    mock_daemon_factory_load.assert_called_once_with('name',
                                                     logger=get_logger())

    daemon = mock_daemon_factory_load.return_value
    daemon.restart.assert_called_once_with()
Ejemplo n.º 15
0
def ls():
    """
    List all existing daemons.

    """

    from cloudify_agent.shell.main import get_logger
    daemons = DaemonFactory().load_all(logger=get_logger())
    for daemon in daemons:
        click.echo(daemon.name)
Ejemplo n.º 16
0
def install(source, args):
    """
    Install a cloudify plugin into the current virtualenv. This will also
    register the plugin to all daemons created from this virtualenv.
    """

    from cloudify_agent.shell.main import get_logger
    click.echo('Installing plugin from {0}'.format(source))
    installer = PluginInstaller(logger=get_logger())
    name = installer.install(source, args)

    daemons = DaemonFactory().load_all(logger=get_logger())
    for daemon in daemons:
        click.echo('Registering plugin {0} to {1}'.format(name, daemon.name))
        if daemon.virtualenv == VIRTUALENV:
            daemon.register(name)
            _save_daemon(daemon)

    click.echo('Successfully installed plugin: {0}'.format(name))
Ejemplo n.º 17
0
def ls():

    """
    List all existing daemons.

    """

    from cloudify_agent.shell.main import get_logger
    daemons = DaemonFactory().load_all(logger=get_logger())
    for daemon in daemons:
        click.echo(daemon.name)
Ejemplo n.º 18
0
    def test_configure(self, *factory_methods):
        self._run('cfy-agent daemons configure --name=name ')

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with('name', logger=get_logger())

        daemon = factory_load.return_value
        daemon.configure.assert_called_once_with()

        factory_save = factory_methods[3]
        factory_save.assert_called_once_with(daemon)
Ejemplo n.º 19
0
def uninstall(plugin):
    """
    Install a cloudify plugin into the current virtualenv. This will also
    register the plugin to all daemons created from this virtualenv.
    """

    from cloudify_agent.shell.main import get_logger
    click.echo('Uninstalling plugin {0}'.format(plugin))
    installer = PluginInstaller(logger=get_logger())
    installer.uninstall(plugin)

    daemons = DaemonFactory().load_all(logger=get_logger())
    for daemon in daemons:
        click.echo('Un-registering plugin {0} from {1}'.format(
            plugin, daemon.name))
        if daemon.virtualenv == VIRTUALENV:
            daemon.unregister(plugin)
            _save_daemon(daemon)

    click.echo('Successfully installed plugin: {0}'.format(plugin))
Ejemplo n.º 20
0
def test_stop(mock_daemon_factory_new, mock_daemon_factory_save,
              mock_daemon_factory_load, mock_daemon_factory_delete,
              mock_daemon_factory_load_all, mock_get_storage_dir):
    run_agent_command('cfy-agent daemons stop --name=name '
                      '--interval 5 --timeout 20')

    mock_daemon_factory_load.assert_called_once_with('name',
                                                     logger=get_logger())

    daemon = mock_daemon_factory_load.return_value
    daemon.stop.assert_called_once_with(interval=5, timeout=20)
Ejemplo n.º 21
0
    def test_configure(self, *factory_methods):
        self._run("cfy-agent daemons configure --name=name ")

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with("name", logger=get_logger())

        daemon = factory_load.return_value
        daemon.configure.assert_called_once_with()

        factory_save = factory_methods[3]
        factory_save.assert_called_once_with(daemon)
Ejemplo n.º 22
0
    def test_inspect(self, daemon_to_dict, *factory_methods):

        daemon_to_dict.return_value = {}

        name = utils.internal.generate_agent_name()
        self._run('cfy-agent daemons inspect --name={0}'.format(name))

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with(name, logger=get_logger())
        daemon = factory_load.return_value

        daemon_to_dict.assert_called_once_with(daemon)
Ejemplo n.º 23
0
def install(source, args):

    """
    Install a cloudify plugin into the current virtualenv. This will also
    register the plugin to all daemons created from this virtualenv.
    """

    from cloudify_agent.shell.main import get_logger
    click.echo('Installing plugin from {0}'.format(source))
    installer = PluginInstaller(logger=get_logger())
    name = installer.install(source, args)

    daemons = DaemonFactory().load_all(logger=get_logger())
    for daemon in daemons:
        click.echo('Registering plugin {0} to {1}'
                   .format(name, daemon.name))
        if daemon.virtualenv == VIRTUALENV:
            daemon.register(name)
            _save_daemon(daemon)

    click.echo('Successfully installed plugin: {0}'.format(name))
Ejemplo n.º 24
0
def uninstall(plugin):

    """
    Install a cloudify plugin into the current virtualenv. This will also
    register the plugin to all daemons created from this virtualenv.
    """

    from cloudify_agent.shell.main import get_logger
    click.echo('Uninstalling plugin {0}'.format(plugin))
    installer = PluginInstaller(logger=get_logger())
    installer.uninstall(plugin)

    daemons = DaemonFactory().load_all(logger=get_logger())
    for daemon in daemons:
        click.echo('Un-registering plugin {0} from {1}'
                   .format(plugin, daemon.name))
        if daemon.virtualenv == VIRTUALENV:
            daemon.unregister(plugin)
            _save_daemon(daemon)

    click.echo('Successfully installed plugin: {0}'.format(plugin))
Ejemplo n.º 25
0
    def test_inspect(self, daemon_to_dict, *factory_methods):

        daemon_to_dict.return_value = {}

        name = utils.internal.generate_agent_name()
        self._run('cfy-agent daemons inspect --name={0}'.format(name))

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with(name, logger=get_logger())
        daemon = factory_load.return_value

        daemon_to_dict.assert_called_once_with(daemon)
Ejemplo n.º 26
0
    def test_uninstall(self, save, load_all, mock_uninstall, _):
        daemon1 = self._create_magic_daemon()
        daemon2 = self._create_magic_daemon()
        load_all.return_value = [daemon1, daemon2]
        self._run('cfy-agent plugins uninstall --plugin=plugin')
        mock_uninstall.assert_called_once_with('plugin')
        load_all.assert_called_once_with(logger=get_logger())
        daemons = load_all.return_value
        for daemon in daemons:
            unregister = daemon.unregister
            unregister.assert_called_once_with('plugin')

        self.assertEqual(save.call_count, 2)
Ejemplo n.º 27
0
    def test_uninstall(self, save, load_all, mock_uninstall, _):
        daemon1 = self._create_magic_daemon()
        daemon2 = self._create_magic_daemon()
        load_all.return_value = [daemon1, daemon2]
        self._run('cfy-agent plugins uninstall --plugin=plugin')
        mock_uninstall.assert_called_once_with('plugin')
        load_all.assert_called_once_with(logger=get_logger())
        daemons = load_all.return_value
        for daemon in daemons:
            unregister = daemon.unregister
            unregister.assert_called_once_with('plugin')

        self.assertEqual(save.call_count, 2)
Ejemplo n.º 28
0
    def test_install(self, save, load_all, _, mock_install):
        daemon1 = self._create_magic_daemon()
        daemon2 = self._create_magic_daemon()
        load_all.return_value = [daemon1, daemon2]
        self._run('cfy-agent plugins install --source=source --args=args')
        mock_install.assert_called_once_with('source', 'args')
        load_all.assert_called_once_with(logger=get_logger())
        daemons = load_all.return_value
        for daemon in daemons:
            register = daemon.register
            register.assert_called_once_with(mock_install.return_value)

        self.assertEqual(save.call_count, 2)
Ejemplo n.º 29
0
    def test_start(self, *factory_methods):
        self._run('cfy-agent daemons start --name=name '
                  '--interval 5 --timeout 20 --no-delete-amqp-queue')

        factory_load = factory_methods[2]
        factory_load.assert_called_once_with('name', logger=get_logger())

        daemon = factory_load.return_value
        daemon.start.assert_called_once_with(
            interval=5,
            timeout=20,
            delete_amqp_queue=False,
        )
Ejemplo n.º 30
0
    def test_install(self, save, load_all, _, mock_install):
        daemon1 = self._create_magic_daemon()
        daemon2 = self._create_magic_daemon()
        load_all.return_value = [daemon1, daemon2]
        self._run('cfy-agent plugins install --source=source --args=args')
        mock_install.assert_called_once_with('source', 'args')
        load_all.assert_called_once_with(logger=get_logger())
        daemons = load_all.return_value
        for daemon in daemons:
            register = daemon.register
            register.assert_called_once_with(mock_install.return_value)

        self.assertEqual(save.call_count, 2)
Ejemplo n.º 31
0
def _fix_virtualenv():

    """
    This method is used for auto-configuration of the virtualenv.
    It is needed in case the environment was created using different paths
    than the one that is used at runtime.

    """

    from cloudify_agent.shell.main import get_logger
    logger = get_logger()

    bin_dir = '{0}/bin'.format(VIRTUALENV)

    logger.debug('Searching for executable files in {0}'.format(bin_dir))
    for executable in os.listdir(bin_dir):
        path = os.path.join(bin_dir, executable)
        logger.debug('Checking {0}...'.format(path))
        if not os.path.isfile(path):
            logger.debug('{0} is not a file. Skipping...'.format(path))
            continue
        if os.path.islink(path):
            logger.debug('{0} is a link. Skipping...'.format(path))
            continue
        basename = os.path.basename(path)
        if basename in ['python', 'python2.7', 'python2.6']:
            logger.debug('{0} is the python executable. Skipping...'
                         .format(path))
            continue
        with open(path) as f:
            lines = f.read().split(os.linesep)
            if lines[0].endswith('/bin/python'):
                new_line = '#!{0}/python'.format(bin_dir)
                logger.debug('Replacing {0} with {1}'
                             .format(lines[0], new_line))
                lines[0] = new_line
        with open(path, 'w') as f:
            f.write(os.linesep.join(lines))

    runner = LocalCommandRunner(logger)

    logger.debug('Searching for links in {0}'.format(VIRTUALENV))
    for link in ['archives', 'bin', 'include', 'lib']:
        link_path = '{0}/local/{1}'.format(VIRTUALENV, link)
        logger.debug('Checking {0}...'.format(link_path))
        try:
            runner.run('unlink {0}'.format(link_path))
            runner.run('ln -s {0}/{1} {2}'
                       .format(VIRTUALENV, link, link_path))
        except CommandExecutionException:
            pass
Ejemplo n.º 32
0
    def test_create_with_custom_options(self, *factory_methods):
        self._run('cfy-agent daemons create --name=name '
                  '--queue=queue --rest-host=127.0.0.1 --broker-ip=127.0.0.1 '
                  '--file-server-host=127.0.0.1 --user=user '
                  '--process-management=init.d '
                  '--key=value --complex-key=complex-value')

        factory_new = factory_methods[4]
        factory_new.assert_called_once_with(
            name='name',
            queue='queue',
            user='******',
            rest_host='127.0.0.1',
            file_server_host='127.0.0.1',
            process_management='init.d',
            broker_ip='127.0.0.1',
            workdir=None,
            max_workers=None,
            min_workers=None,
            broker_port=None,
            host=None,
            deployment_id=None,
            log_level=None,
            pid_file=None,
            log_file=None,
            rest_port='80',
            extra_env_path=None,
            logger=get_logger(),
            key='value',
            complex_key='complex-value',
            broker_user='******',
            broker_pass='******',
            broker_ssl_cert=None,
            broker_ssl_cert_path=os.environ[
                env_constants.CLOUDIFY_BROKER_SSL_CERT_PATH],
            broker_ssl_enabled=False,
            broker_get_settings_from_manager=False,
            security_enabled=False,
            file_server_protocol='http',
            file_server_port='53229',
            rest_protocol='http',
            rest_username=None,
            rest_password=None,
            rest_token=None,
            verify_rest_certificate=False,
            local_rest_cert_file=os.environ[
                env_constants.CLOUDIFY_AGENT_REST_CERT_PATH],
            rest_cert_content='',
            bypass_maintenance_mode=None,
        )
Ejemplo n.º 33
0
def test_create_with_custom_options(mock_daemon_factory_new,
                                    mock_daemon_factory_save,
                                    mock_daemon_factory_load,
                                    mock_daemon_factory_delete,
                                    mock_daemon_factory_load_all,
                                    mock_get_storage_dir):
    run_agent_command('cfy-agent daemons create --name=name --queue=queue '
                      '--rest-host=127.0.0.1 --broker-ip=127.0.0.1 '
                      '--process-management=init.d --rest-tenant=tenant '
                      '--user=user --key=value --complex-key=complex-value')

    mock_daemon_factory_new.assert_called_once_with(
        name='name',
        queue='queue',
        user='******',
        rest_host=['127.0.0.1'],
        process_management='init.d',
        broker_ip=['127.0.0.1'],
        workdir=None,
        max_workers=None,
        min_workers=None,
        host=None,
        deployment_id=None,
        log_level=None,
        pid_file=None,
        log_dir=None,
        rest_port='80',
        extra_env_path=None,
        logger=get_logger(),
        key='value',
        complex_key='complex-value',
        broker_user='******',
        broker_pass='******',
        broker_vhost='/',
        broker_ssl_cert=None,
        broker_ssl_enabled=False,
        heartbeat=30,
        broker_ssl_cert_path=os.environ[
            env_constants.CLOUDIFY_BROKER_SSL_CERT_PATH],
        rest_username=None,
        rest_password=None,
        rest_token=None,
        rest_tenant='tenant',
        local_rest_cert_file=os.environ[
            env_constants.CLOUDIFY_LOCAL_REST_CERT_PATH],
        bypass_maintenance_mode=None,
        network=None,
        log_max_bytes=None,
        log_max_history=None,
        executable_temp_path=None)
Ejemplo n.º 34
0
def _fix_virtualenv():
    """
    This method is used for auto-configuration of the virtualenv.
    It is needed in case the environment was created using different paths
    than the one that is used at runtime.

    """

    from cloudify_agent.shell.main import get_logger
    logger = get_logger()

    bin_dir = '{0}/bin'.format(VIRTUALENV)

    logger.debug('Searching for executable files in {0}'.format(bin_dir))
    for executable in os.listdir(bin_dir):
        path = os.path.join(bin_dir, executable)
        logger.debug('Checking {0}...'.format(path))
        if not os.path.isfile(path):
            logger.debug('{0} is not a file. Skipping...'.format(path))
            continue
        if os.path.islink(path):
            logger.debug('{0} is a link. Skipping...'.format(path))
            continue
        basename = os.path.basename(path)
        if basename in ['python', 'python2.7', 'python2.6']:
            logger.debug(
                '{0} is the python executable. Skipping...'.format(path))
            continue
        with open(path) as f:
            lines = f.read().split(os.linesep)
            if lines[0].endswith('/bin/python'):
                new_line = '#!{0}/python'.format(bin_dir)
                logger.debug('Replacing {0} with {1}'.format(
                    lines[0], new_line))
                lines[0] = new_line
        with open(path, 'w') as f:
            f.write(os.linesep.join(lines))

    runner = LocalCommandRunner(logger)

    logger.debug('Searching for links in {0}'.format(VIRTUALENV))
    for link in ['archives', 'bin', 'include', 'lib']:
        link_path = '{0}/local/{1}'.format(VIRTUALENV, link)
        logger.debug('Checking {0}...'.format(link_path))
        try:
            runner.run('unlink {0}'.format(link_path))
            runner.run('ln -s {0}/{1} {2}'.format(VIRTUALENV, link, link_path))
        except CommandExecutionException:
            pass
Ejemplo n.º 35
0
def test_inspect(mock_daemon_factory_new, mock_daemon_factory_save,
                 mock_daemon_factory_load, mock_daemon_factory_delete,
                 mock_daemon_factory_load_all,
                 mock_daemon_api_internal_daemon_to_dict,
                 mock_get_storage_dir):

    mock_daemon_api_internal_daemon_to_dict.return_value = {}

    name = utils.internal.generate_agent_name()
    run_agent_command('cfy-agent daemons inspect --name={0}'.format(name))

    mock_daemon_factory_load.assert_called_once_with(name, logger=get_logger())
    daemon = mock_daemon_factory_load.return_value

    mock_daemon_api_internal_daemon_to_dict.assert_called_once_with(daemon)
Ejemplo n.º 36
0
def create(**params):
    """
    Creates and stores the daemon parameters.

    """
    attributes = dict(**params)
    custom_arg = attributes.pop('custom_options', ())
    attributes.update(_parse_custom_options(custom_arg))

    click.echo('Creating...')
    from cloudify_agent.shell.main import get_logger
    daemon = DaemonFactory().new(logger=get_logger(), **attributes)
    daemon.create()
    _save_daemon(daemon)
    click.echo('Successfully created daemon: {0}'.format(daemon.name))
Ejemplo n.º 37
0
def test_start(mock_daemon_factory_new, mock_daemon_factory_save,
               mock_daemon_factory_load, mock_daemon_factory_delete,
               mock_daemon_factory_load_all, mock_get_storage_dir):
    run_agent_command('cfy-agent daemons start --name=name '
                      '--interval 5 --timeout 20 --no-delete-amqp-queue')

    mock_daemon_factory_load.assert_called_once_with('name',
                                                     logger=get_logger())

    daemon = mock_daemon_factory_load.return_value
    daemon.start.assert_called_once_with(
        interval=5,
        timeout=20,
        delete_amqp_queue=True,
    )
Ejemplo n.º 38
0
    def test_create(self, *factory_methods):
        self._run('cfy-agent daemons create --name=name '
                  '--process-management=init.d '
                  '--queue=queue --rest-host=127.0.0.1 '
                  '--file-server-host=127.0.0.1 --user=user ')

        factory_new = factory_methods[4]
        factory_new.assert_called_once_with(
            name='name',
            queue='queue',
            user='******',
            rest_host='127.0.0.1',
            file_server_host='127.0.0.1',
            process_management='init.d',
            broker_ip=None,
            workdir=None,
            log_level=None,
            pid_file=None,
            log_file=None,
            max_workers=None,
            min_workers=None,
            broker_port=None,
            rest_port='80',
            host=None,
            deployment_id=None,
            extra_env_path=None,
            logger=get_logger(),
            broker_user='******',
            broker_pass='******',
            broker_ssl_cert=None,
            broker_ssl_enabled=False,
            broker_get_settings_from_manager=False,
            security_enabled=False,
            file_server_protocol='http',
            file_server_port='53229',
            rest_protocol='http',
            rest_username=None,
            rest_password=None,
            rest_token=None,
            broker_ssl_cert_path=None,
            verify_rest_certificate=False,
            local_rest_cert_file=None,
            rest_cert_content='',
            bypass_maintenance_mode=None,
        )

        daemon = factory_new.return_value
        daemon.create.assert_called_once_with()
Ejemplo n.º 39
0
    def test_create(self, *factory_methods):
        self._run('cfy-agent daemons create --name=name '
                  '--process-management=init.d --user=user '
                  '--queue=queue  --rest-host=127.0.0.1')

        factory_new = factory_methods[4]
        factory_new.assert_called_once_with(
            name='name',
            queue='queue',
            user='******',
            rest_host=['127.0.0.1'],
            process_management='init.d',
            broker_ip=None,
            workdir=None,
            log_level=None,
            pid_file=None,
            log_dir=None,
            max_workers=None,
            min_workers=None,
            rest_port='80',
            host=None,
            deployment_id=None,
            extra_env_path=None,
            logger=get_logger(),
            broker_user='******',
            broker_pass='******',
            broker_vhost='/',
            broker_ssl_cert=None,
            broker_ssl_enabled=False,
            heartbeat=30,
            rest_username=None,
            rest_password=None,
            rest_token=None,
            rest_tenant=None,
            broker_ssl_cert_path=os.environ[
                env_constants.CLOUDIFY_BROKER_SSL_CERT_PATH],
            local_rest_cert_file=os.environ[
                env_constants.CLOUDIFY_LOCAL_REST_CERT_PATH],
            bypass_maintenance_mode=None,
            network=None,
            executable_temp_path=None,
            log_max_bytes=None,
            log_max_history=None
        )

        daemon = factory_new.return_value
        daemon.create.assert_called_once_with()
Ejemplo n.º 40
0
    def test_create_with_custom_options(self, *factory_methods):

        self._run('cfy-agent daemons create --name=name --queue=queue '
                  '--rest-host=127.0.0.1 --broker-ip=127.0.0.1 --user=user '
                  '--process-management=init.d --rest-tenant=tenant '
                  '--key=value --complex-key=complex-value')

        factory_new = factory_methods[4]
        factory_new.assert_called_once_with(
            name='name',
            queue='queue',
            user='******',
            rest_host='127.0.0.1',
            process_management='init.d',
            broker_ip='127.0.0.1',
            workdir=None,
            max_workers=None,
            min_workers=None,
            host=None,
            deployment_id=None,
            log_level=None,
            pid_file=None,
            log_dir=None,
            rest_port='80',
            extra_env_path=None,
            logger=get_logger(),
            key='value',
            complex_key='complex-value',
            broker_user='******',
            broker_pass='******',
            broker_vhost='/',
            broker_ssl_cert=None,
            broker_ssl_enabled=False,
            heartbeat=30,
            broker_ssl_cert_path=os.environ[
                env_constants.CLOUDIFY_BROKER_SSL_CERT_PATH],
            rest_username=None,
            rest_password=None,
            rest_token=None,
            rest_tenant='tenant',
            local_rest_cert_file=os.environ[
                env_constants.CLOUDIFY_LOCAL_REST_CERT_PATH],
            bypass_maintenance_mode=None,
            network=None,
            cluster=None)
Ejemplo n.º 41
0
def _disable_requiretty(no_sudo):
    """
    Disables the requiretty directive in the /etc/sudoers file. This
    will enable operations that require sudo permissions to work properly.

    This is needed because operations are executed
    from within the worker process, which is not a tty process.

    """

    from cloudify_agent.shell.main import get_logger
    runner = LocalCommandRunner(get_logger())

    disable_requiretty_script_path = utils.resource_to_tempfile(
        resource_path='disable-requiretty.sh', executable=True)
    runner.run('chmod +x {0}'.format(disable_requiretty_script_path))
    maybe_sudo = '' if no_sudo else 'sudo'
    runner.run('{0} {1}'.format(disable_requiretty_script_path, maybe_sudo))
Ejemplo n.º 42
0
def _fixup_scripts(bin_dir):
    """Make scripts in bin_dir relative by rewriting their shebangs

    Examine each file in bin_dir - if it looks like a python script, and has a
    shebang - replace it with a new, "relative" shebang. (like
    `virtualenv --relocatable` would)

    The relative shebang is platform-specific, but on linux it will consist
    of a /usr/bin/env shebang, and a python snippet that runs the `activate`
    script.
    """
    from cloudify_agent.shell.main import get_logger
    logger = get_logger()

    new_shebang = _get_relative_shebang()
    for filename in _find_scripts_to_fix(bin_dir):
        logger.debug('Making script {0} relative'.format(filename))
        _rewrite_shebang(filename, new_shebang)
Ejemplo n.º 43
0
def _fixup_scripts(bin_dir):
    """Make scripts in bin_dir relative by rewriting their shebangs

    Examine each file in bin_dir - if it looks like a python script, and has a
    shebang - replace it with a new, "relative" shebang. (like
    `virtualenv --relocatable` would)

    The relative shebang is platform-specific, but on linux it will consist
    of a /usr/bin/env shebang, and a python snippet that runs the `activate`
    script.
    """
    from cloudify_agent.shell.main import get_logger
    logger = get_logger()

    new_shebang = _get_relative_shebang()
    for filename in _find_scripts_to_fix(bin_dir):
        logger.debug('Making script {0} relative'.format(filename))
        _rewrite_shebang(filename, new_shebang)
Ejemplo n.º 44
0
def _disable_requiretty():

    """
    Disables the requiretty directive in the /etc/sudoers file. This
    will enable operations that require sudo permissions to work properly.

    This is needed because operations are executed
    from within the worker process, which is not a tty process.

    """

    from cloudify_agent.shell.main import get_logger
    runner = LocalCommandRunner(get_logger())

    disable_requiretty_script_path = utils.resource_to_tempfile(
        resource_path='disable-requiretty.sh'
    )
    runner.run('chmod +x {0}'.format(disable_requiretty_script_path))
    runner.run('{0}'.format(disable_requiretty_script_path))
Ejemplo n.º 45
0
def create(**params):

    """
    Creates and stores the daemon parameters.

    """
    attributes = dict(**params)
    custom_arg = attributes.pop('custom_options', ())
    attributes.update(_parse_custom_options(custom_arg))

    click.echo('Creating...')
    from cloudify_agent.shell.main import get_logger
    daemon = DaemonFactory().new(
        logger=get_logger(),
        **attributes
    )
    daemon.create()
    _save_daemon(daemon)
    click.echo('Successfully created daemon: {0}'
               .format(daemon.name))
Ejemplo n.º 46
0
def create(**params):
    """
    Creates and stores the daemon parameters.

    """
    attributes = dict(**params)
    custom_arg = attributes.pop('custom_options', ())
    attributes.update(_parse_custom_options(custom_arg))

    click.echo('Creating...')

    if attributes['broker_get_settings_from_manager']:
        broker = api_utils.internal.get_broker_configuration(attributes)
        attributes.update(broker)

    from cloudify_agent.shell.main import get_logger
    daemon = DaemonFactory().new(logger=get_logger(), **attributes)

    daemon.create()
    _save_daemon(daemon)
    click.echo('Successfully created daemon: {0}'.format(daemon.name))
Ejemplo n.º 47
0
    def test_create_with_custom_options(self, *factory_methods):
        self._run(
            "cfy-agent daemons create --name=name "
            "--queue=queue --manager-ip=127.0.0.1 --user=user "
            "--process-management=init.d "
            "--key=value --complex-key=complex-value"
        )

        factory_new = factory_methods[4]
        factory_new.assert_called_once_with(
            name="name",
            queue="queue",
            user="******",
            manager_ip="127.0.0.1",
            process_management="init.d",
            broker_ip=None,
            workdir=None,
            max_workers=None,
            min_workers=None,
            broker_port=None,
            includes=None,
            host=None,
            deployment_id=None,
            log_level=None,
            pid_file=None,
            log_file=None,
            manager_port=None,
            extra_env_path=None,
            logger=get_logger(),
            key="value",
            complex_key="complex-value",
            broker_user="******",
            broker_pass="******",
            broker_ssl_cert=None,
            broker_ssl_enabled=False,
            broker_get_settings_from_manager=False,
        )
Ejemplo n.º 48
0
def _load_daemon(name):
    from cloudify_agent.shell.main import get_logger
    return DaemonFactory().load(name, logger=get_logger())
Ejemplo n.º 49
0
def _load_daemon(name, user=None):
    from cloudify_agent.shell.main import get_logger
    return DaemonFactory(username=user).load(name, logger=get_logger())