Exemplo n.º 1
0
def create_new_agent_config(old_agent):
    new_agent = CloudifyAgentConfig()
    _set_default_new_agent_config_values(old_agent, new_agent)
    _copy_values_from_old_agent_config(old_agent, new_agent)
    new_agent.set_default_values()
    new_agent.set_installation_params(runner=None)
    return new_agent
Exemplo n.º 2
0
    def _create_agent():
        old_agent = CloudifyAgentConfig({
            'install_method': 'remote',
            'ip': '10.0.4.47',
            'rest_host': '10.0.4.46',
            'distro': 'ubuntu',
            'distro_codename': 'trusty',
            'basedir': '/home/vagrant',
            'user': '******',
            'key': '~/.ssh/id_rsa',
            'windows': False,
            'package_url': 'http://10.0.4.46:53229/packages/agents/'
                           'ubuntu-trusty-agent.tar.gz',
            'version': '4.4',
            'broker_config': {
                'broker_ip': '10.0.4.46',
                'broker_pass': '******',
                'broker_user': '******',
                'broker_ssl_cert': ''
            }
        })

        old_agent.set_execution_params()
        old_agent.set_default_values()
        old_agent.set_installation_params(runner=None)
        return old_agent
    def _create_agent():
        old_agent = CloudifyAgentConfig({
            'install_method': 'remote',
            'ip': '10.0.4.47',
            'rest_host': '10.0.4.46',
            'distro': 'ubuntu',
            'distro_codename': 'trusty',
            'basedir': '/home/vagrant',
            'user': '******',
            'key': '~/.ssh/id_rsa',
            'windows': False,
            'package_url': 'http://10.0.4.46:53229/packages/agents/'
                           'ubuntu-trusty-agent.tar.gz',
            'version': '4.4',
            'broker_config': {
                'broker_ip': '10.0.4.46',
                'broker_pass': '******',
                'broker_user': '******',
                'broker_ssl_cert': ''
            }
        })

        old_agent.set_execution_params()
        old_agent.set_default_values()
        old_agent.set_installation_params(runner=None)
        return old_agent
Exemplo n.º 4
0
def create_new_agent_config(old_agent):
    new_agent = CloudifyAgentConfig()
    _set_default_new_agent_config_values(old_agent, new_agent)
    _copy_values_from_old_agent_config(old_agent, new_agent)
    new_agent.set_default_values()
    new_agent.set_installation_params(runner=None)
    return new_agent
Exemplo n.º 5
0
    def test_prepare_secured(self):

        cloudify_agent = CloudifyAgentConfig({
            'local': True,
            'rest_port': '443'
        })
        cloudify_agent.set_execution_params()
        cloudify_agent.set_default_values()
        cloudify_agent.set_installation_params(None)

        user = getpass.getuser()
        basedir = utils.get_home_dir(user)
        agent_dir = os.path.join(basedir, 'test_deployment')
        envdir = os.path.join(agent_dir, 'env')
        workdir = os.path.join(agent_dir, 'work')

        # This test needs to be adapted to security settings
        expected = {
            'agent_dir': agent_dir,
            'process_management': {
                'name': 'init.d' if os.name == 'posix' else 'nssm'
            },
            'basedir': basedir,
            'name': 'test_deployment',
            'rest_port': '443',
            'rest_host': 'localhost',
            'queue': 'test_deployment',
            'envdir': envdir,
            'user': user,
            'local': True,
            'install_method': 'local',
            'disable_requiretty': True,
            'env': {},
            'fabric_env': {},
            'max_workers': 5,
            'min_workers': 0,
            'workdir': workdir,
            'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH],
            'windows': os.name == 'nt',
            'system_python': 'python',
            'bypass_maintenance': False,
            'rest_token': 'test_token',
            'rest_tenant': {}
        }
        if os.name == 'posix':
            distro = platform.dist()[0].lower()
            distro_codename = platform.dist()[2].lower()
            expected['distro'] = platform.dist()[0].lower()
            expected['distro_codename'] = platform.dist()[2].lower()
            expected['package_url'] = 'localhost/packages/agents/' \
                                      '{0}-{1}-agent.tar.gz' \
                .format(distro, distro_codename)
        else:
            expected['package_url'] = 'localhost/packages/agents/' \
                                      'cloudify-windows-agent.exe'

        self.maxDiff = None
        self.assertDictEqual(expected, cloudify_agent)
    def _test_prepare(self, agent_config, expected_values, context=None):

        user = getpass.getuser()
        basedir = utils.get_home_dir(user)
        agent_dir = os.path.join(basedir, 'test_deployment')
        envdir = os.path.join(agent_dir, 'env')
        workdir = os.path.join(agent_dir, 'work')

        # This test needs to be adapted to security settings
        expected = {
            'agent_dir': agent_dir,
            'process_management': {
                'name': 'init.d' if os.name == 'posix' else 'nssm'
            },
            'basedir': basedir,
            'name': 'test_deployment',
            'rest_host': 'localhost',
            'broker_ip': ['localhost'],
            'broker_ssl_cert': '',
            'heartbeat': None,
            'queue': 'test_deployment',
            'envdir': envdir,
            'user': user,
            'local': True,
            'install_method': 'local',
            'disable_requiretty': True,
            'env': {},
            'fabric_env': {},
            'max_workers': 5,
            'min_workers': 0,
            'workdir': workdir,
            'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH],
            'windows': os.name == 'nt',
            'system_python': 'python',
            'bypass_maintenance': False,
            'network': 'default',
            'version': utils.get_agent_version(),
            'node_instance_id': 'test_node',
            'log_level': 'info',
            'log_max_bytes': 5242880,
            'log_max_history': 7
        }
        expected.update(expected_values)

        self.maxDiff = None
        context = context or {}
        ctx = mock_context(**context)
        with patch('cloudify_agent.installer.config.agent_config.ctx', ctx), \
                patch('cloudify.utils.ctx', mock_context()):
            cloudify_agent = CloudifyAgentConfig()
            cloudify_agent.set_initial_values(True, agent_config=agent_config)
            cloudify_agent.set_execution_params()
            cloudify_agent.set_default_values()
            cloudify_agent.set_installation_params(None)
            self.assertDictEqual(expected, cloudify_agent)
Exemplo n.º 7
0
    def _test_prepare(self, agent_config, expected_values):
        cloudify_agent = CloudifyAgentConfig()
        cloudify_agent.set_initial_values(True, agent_config=agent_config)
        cloudify_agent.set_execution_params()
        cloudify_agent.set_default_values()
        cloudify_agent.set_installation_params(None)

        user = getpass.getuser()
        basedir = utils.get_home_dir(user)
        agent_dir = os.path.join(basedir, 'test_deployment')
        envdir = os.path.join(agent_dir, 'env')
        workdir = os.path.join(agent_dir, 'work')

        # This test needs to be adapted to security settings
        expected = {
            'agent_dir': agent_dir,
            'process_management': {
                'name': 'init.d' if os.name == 'posix' else 'nssm'
            },
            'basedir': basedir,
            'name': 'test_deployment',
            'rest_host': 'localhost',
            'broker_ip': 'localhost',
            'heartbeat': None,
            'queue': 'test_deployment',
            'envdir': envdir,
            'user': user,
            'local': True,
            'install_method': 'local',
            'disable_requiretty': True,
            'env': {},
            'fabric_env': {},
            'max_workers': 20,
            'min_workers': 0,
            'workdir': workdir,
            'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH],
            'windows': os.name == 'nt',
            'system_python': 'python',
            'bypass_maintenance': False,
            'network': 'default',
            'version': utils.get_agent_version()
        }
        expected.update(expected_values)

        self.maxDiff = None
        self.assertDictEqual(expected, cloudify_agent)
    def _test_prepare(self, agent_config, expected_values, context=None):

        user = getpass.getuser()
        basedir = utils.get_home_dir(user)
        agent_dir = os.path.join(basedir, 'test_deployment')
        envdir = os.path.join(agent_dir, 'env')
        workdir = os.path.join(agent_dir, 'work')

        # This test needs to be adapted to security settings
        expected = {
            'agent_dir': agent_dir,
            'process_management': {
                'name': 'init.d' if os.name == 'posix' else 'nssm'
            },
            'basedir': basedir,
            'name': 'test_deployment',
            'rest_host': ['127.0.0.1'],
            'broker_ip': ['127.0.0.1'],
            'broker_ssl_cert': agent_ssl_cert.DUMMY_CERT,
            'heartbeat': None,
            'queue': 'test_deployment',
            'envdir': envdir,
            'user': user,
            'local': True,
            'install_method': 'local',
            'disable_requiretty': True,
            'env': {},
            'fabric_env': {},
            'file_server_url': 'http://127.0.0.1:80/resources',
            'max_workers': 5,
            'min_workers': 0,
            'workdir': workdir,
            'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH],
            'windows': os.name == 'nt',
            'system_python': 'python',
            'bypass_maintenance': False,
            'network': 'default',
            'version': utils.get_agent_version(),
            'node_instance_id': 'test_node',
            'log_level': 'info',
            'log_max_bytes': 5242880,
            'log_max_history': 7,
            'rest_ssl_cert': agent_ssl_cert.DUMMY_CERT,
            'tenant': {
                'name': 'default_tenant',
                'rabbitmq_username': '******',
                'rabbitmq_password': '******',
                'rabbitmq_vhost': '/'
            }
        }
        expected.update(expected_values)

        self.maxDiff = None
        context = context or {}
        ctx = mock_context(**context)
        patches = [
            patch('cloudify_agent.installer.config.agent_config.ctx', ctx),
            patch('cloudify.utils.ctx', mock_context()),
            patch('cloudify.utils.get_manager_name', return_value='cloudify')
        ]
        # it's originally a string because it comes from envvars
        if expected['rest_port'] != '443':
            patches.append(
                patch('cloudify.utils.get_manager_file_server_scheme',
                      return_value='http')
            )
        for p in patches:
            p.start()
            self.addCleanup(p.stop)

        cloudify_agent = CloudifyAgentConfig()
        cloudify_agent.set_initial_values(
            True, agent_config=agent_config)
        cloudify_agent.set_execution_params()
        cloudify_agent.set_default_values()
        cloudify_agent.set_installation_params(None)
        self.assertDictEqual(expected, cloudify_agent)
Exemplo n.º 9
0
def _test_prepare(agent_ssl_cert, agent_config, expected_values,
                  context=None):
    user = getpass.getuser()
    is_windows = os.name == 'nt'
    basedir = utils.get_agent_basedir(is_windows)
    agent_dir = os.path.join(basedir, 'test_deployment')
    envdir = os.path.join(agent_dir, 'env')
    workdir = os.path.join(agent_dir, 'work')

    # This test needs to be adapted to security settings
    expected = {
        'agent_dir': agent_dir,
        'process_management': {
            'name': 'init.d' if os.name == 'posix' else 'nssm'
        },
        'basedir': basedir,
        'name': 'test_deployment',
        'rest_host': ['127.0.0.1'],
        'broker_ip': ['127.0.0.1'],
        'broker_ssl_cert': agent_ssl_cert.DUMMY_CERT,
        'heartbeat': None,
        'queue': 'test_deployment',
        'envdir': envdir,
        'user': user,
        'local': True,
        'install_method': 'local',
        'disable_requiretty': True,
        'env': {},
        'fabric_env': {},
        'file_server_url': 'https://127.0.0.1:80/resources',
        'max_workers': 5,
        'min_workers': 0,
        'workdir': workdir,
        'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH],
        'windows': is_windows,
        'system_python': 'python',
        'bypass_maintenance': False,
        'network': 'default',
        'version': utils.get_agent_version(),
        'node_instance_id': 'test_node',
        'log_level': 'info',
        'log_max_bytes': 5242880,
        'log_max_history': 7,
        'rest_ssl_cert': agent_ssl_cert.DUMMY_CERT,
        'tenant': {
            'name': 'default_tenant',
            'rabbitmq_username': '******',
            'rabbitmq_password': '******',
            'rabbitmq_vhost': '/'
        }
    }
    expected.update(expected_values)

    # port is originally a string because it comes from envvars
    with agent_config_patches(agent_ssl_cert,
                              expected['rest_port'] == '443', context):
        cloudify_agent = CloudifyAgentConfig()
        cloudify_agent.set_initial_values(
            True, agent_config=agent_config)
        cloudify_agent.set_execution_params()
        cloudify_agent.set_default_values()
        cloudify_agent.set_installation_params(None)
        assert expected == cloudify_agent