コード例 #1
0
 def _create_agent(self):
     old_agent = {
         'local': False,
         'remote_execution': False,
         'ip': '10.0.4.47',
         'manager_ip': '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': '3.3',
         'broker_config': {
             'broker_ip': '10.0.4.46',
             'broker_pass': '******',
             'broker_user': '******',
             'broker_port': '5672',
             'broker_ssl_enable': False,
             'broker_ssl_cert': ''
         }
     }
     configuration.prepare_connection(old_agent)
     configuration.prepare_agent(old_agent, None)
     return old_agent
コード例 #2
0
 def _create_agent(self):
     old_agent = {
         'local': False,
         'remote_execution': False,
         'ip': '10.0.4.47',
         'manager_ip': '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': '3.4',
         'broker_config': {
             'broker_ip': '10.0.4.46',
             'broker_pass': '******',
             'broker_user': '******',
             'broker_port': '5672',
             'broker_ssl_enable': False,
             'broker_ssl_cert': ''
         }
     }
     configuration.prepare_connection(old_agent)
     configuration.prepare_agent(old_agent, None)
     return old_agent
コード例 #3
0
    def _create_agent(self):
        old_agent = {
            'local': False,
            'remote_execution': False,
            'ip': '10.0.4.47',
            'rest_host': '10.0.4.46',
            'file_server_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': '3.4',
            'broker_config': {
                'broker_ip': '10.0.4.46',
                'broker_pass': '******',
                'broker_user': '******',
                'broker_port': '5672',
                'broker_ssl_enable': False,
                'broker_ssl_cert': ''
            }
        }

        operation_ctx = mocks.MockCloudifyContext(runtime_properties={
            'rest_token': 'token1234'
        })
        old_context = ctx
        configuration.prepare_connection(old_agent)
        current_ctx.set(operation_ctx)
        configuration.prepare_agent(old_agent, None)
        current_ctx.set(old_context)
        return old_agent
コード例 #4
0
    def _create_agent(self):
        old_agent = {
            'local': False,
            'remote_execution': False,
            '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': '3.4',
            'broker_config': {
                'broker_ip': '10.0.4.46',
                'broker_pass': '******',
                'broker_user': '******',
                'broker_port': '5672',
                'broker_ssl_enable': False,
                'broker_ssl_cert': ''
            }
        }

        operation_ctx = mocks.MockCloudifyContext(
            runtime_properties={'rest_token': 'token1234'})
        old_context = ctx
        configuration.prepare_connection(old_agent)
        current_ctx.set(operation_ctx)
        configuration.prepare_agent(old_agent, None)
        current_ctx.set(old_context)
        return old_agent
コード例 #5
0
    def test_prepare(self):

        cloudify_agent = {'local': True}
        configuration.prepare_connection(cloudify_agent)
        configuration.prepare_agent(cloudify_agent, 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')
        expected = {
            'agent_dir': agent_dir,
            'process_management': {
                'name': 'init.d' if os.name == 'posix' else 'nssm'
            },
            'basedir': basedir,
            'name': 'test_deployment',
            'manager_ip': 'localhost',
            'manager_port': 8101,
            'queue': 'test_deployment',
            'envdir': envdir,
            'user': user,
            'local': True,
            'disable_requiretty': True,
            'env': {},
            'fabric_env': {},
            'max_workers': 5,
            'min_workers': 0,
            'workdir': workdir,
            'windows': os.name == 'nt',
            'system_python': 'python',
            'remote_execution': True,
            'broker_get_settings_from_manager': True,
        }
        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)
コード例 #6
0
    def test_prepare(self):

        cloudify_agent = {'local': True}
        configuration.prepare_connection(cloudify_agent)
        configuration.prepare_agent(cloudify_agent, 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')
        expected = {
            'agent_dir': agent_dir,
            'process_management':
                {'name': 'init.d' if os.name == 'posix' else 'nssm'},
            'basedir': basedir,
            'name': 'test_deployment',
            'manager_ip': 'localhost',
            'manager_port': 8101,
            'queue': 'test_deployment',
            'envdir': envdir,
            'user': user,
            'local': True,
            'disable_requiretty': True,
            'env': {},
            'fabric_env': {},
            'max_workers': 5,
            'min_workers': 0,
            'workdir': workdir,
            'windows': os.name == 'nt',
            'system_python': 'python',
            'remote_execution': True,
            'broker_get_settings_from_manager': True,
        }
        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)
コード例 #7
0
 def get_agent(self):
     result = {
         'local': True,
         'package_url': self.config['agent_url'],
         'user': self.config['agent_user'],
         'basedir': self.base_dir,
         'manager_ip': '127.0.0.1',
         'name': 'agent_{0}'.format(uuid.uuid4())
     }
     agent_config.prepare_connection(result)
     # We specify base_dir and user directly, so runner is not needed.
     agent_config.prepare_agent(result, None)
     _, agent_file_path = tempfile.mkstemp(dir=self.base_dir)
     with open(agent_file_path, 'a') as agent_file:
         agent_file.write(json.dumps(result))
     result['agent_file'] = agent_file_path
     return result
コード例 #8
0
    def wrapper(*args, **kwargs):

        cloudify_agent = kwargs.get('cloudify_agent', {})

        # first prepare all connection details
        configuration.prepare_connection(cloudify_agent)

        # create the correct runner according to os
        # and local/remote execution. we need this runner now because it
        # will be used to determine the agent basedir in case it wasn't
        # explicitly set
        if cloudify_agent['local']:
            runner = LocalCommandRunner(logger=ctx.logger)
        else:
            try:
                if cloudify_agent['windows']:
                    runner = WinRMRunner(
                        host=cloudify_agent['ip'],
                        user=cloudify_agent['user'],
                        password=cloudify_agent['password'],
                        port=cloudify_agent.get('port'),
                        protocol=cloudify_agent.get('protocol'),
                        uri=cloudify_agent.get('uri'),
                        logger=ctx.logger)
                else:
                    runner = FabricRunner(
                        logger=ctx.logger,
                        host=cloudify_agent['ip'],
                        user=cloudify_agent['user'],
                        port=cloudify_agent.get('port'),
                        key=cloudify_agent.get('key'),
                        password=cloudify_agent.get('password'),
                        fabric_env=cloudify_agent.get('fabric_env'))
            except CommandExecutionError as e:
                return ctx.operation.retry(message=e.error,
                                           retry_after=5)

        # now we can create all other agent attributes
        configuration.prepare_agent(cloudify_agent, runner)

        # create the correct installer according to os
        # and local/remote execution
        if cloudify_agent['local']:
            if os.name == 'nt':
                installer = LocalWindowsAgentInstaller(
                    cloudify_agent, ctx.logger)
            else:
                installer = LocalLinuxAgentInstaller(
                    cloudify_agent, ctx.logger)
        elif cloudify_agent['windows']:
            installer = RemoteWindowsAgentInstaller(
                cloudify_agent, ctx.logger)
        else:
            installer = RemoteLinuxAgentInstaller(
                cloudify_agent, ctx.logger)

        kwargs['cloudify_agent'] = cloudify_agent
        kwargs['runner'] = runner
        kwargs['installer'] = installer

        try:
            return func(*args, **kwargs)
        finally:
            # we need to close fabric connection
            if isinstance(installer, RemoteLinuxAgentInstaller):
                installer.runner.close()
コード例 #9
0
    def test_prepare(self):

        cloudify_agent = {'local': True}
        configuration.prepare_connection(cloudify_agent)
        configuration.prepare_agent(cloudify_agent, 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',
            'rest_port': 80,
            'rest_protocol': 'http',
            'file_server_host': 'localhost',
            'file_server_port': 53229,
            'file_server_protocol': 'http',
            'queue': 'test_deployment',
            'envdir': envdir,
            'user': user,
            'local': True,
            'disable_requiretty': True,
            'env': {},
            'fabric_env': {},
            'max_workers': 5,
            'min_workers': 0,
            'workdir': workdir,
            'agent_rest_cert_path': os.environ[constants.AGENT_REST_CERT_PATH],
            'broker_ssl_cert_path': os.environ[constants.BROKER_SSL_CERT_PATH],
            'windows': os.name == 'nt',
            'system_python': 'python',
            'remote_execution': True,
            'broker_get_settings_from_manager': True,
            'security_enabled': False,
            'rest_cert_content': '',
            'rest_username': None,
            'rest_password': None,
            'verify_rest_certificate': False,
            'bypass_maintenance_mode': False,
            'rest_token': None
        }
        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)
コード例 #10
0
        def wrapper(*args, **kwargs):
            cloudify_agent = kwargs.get('cloudify_agent') or {}
            agent_config = kwargs.get('agent_config') or {}
            cloudify_agent.update(agent_config)

            # first prepare all connection details
            configuration.prepare_connection(cloudify_agent)

            # create the correct runner according to os
            # and local/remote execution. we need this runner now because it
            # will be used to determine the agent basedir in case it wasn't
            # explicitly set
            if cloudify_agent['local']:
                runner = LocalCommandRunner(logger=ctx.logger)
            elif cloudify_agent['remote_execution'] is False:
                runner = StubRunner()
            else:
                host = cloudify_agent['ip']
                try:
                    if cloudify_agent['windows']:
                        runner = WinRMRunner(
                            host=host,
                            port=cloudify_agent.get('port'),
                            user=cloudify_agent['user'],
                            password=cloudify_agent['password'],
                            protocol=cloudify_agent.get('protocol'),
                            uri=cloudify_agent.get('uri'),
                            logger=ctx.logger,
                            validate_connection=validate_connection)
                    else:
                        runner = FabricRunner(
                            host=host,
                            port=cloudify_agent.get('port'),
                            user=cloudify_agent['user'],
                            key=cloudify_agent.get('key'),
                            password=cloudify_agent.get('password'),
                            fabric_env=cloudify_agent.get('fabric_env'),
                            logger=ctx.logger,
                            validate_connection=validate_connection)
                except CommandExecutionError as e:
                    message = e.error
                    if not message:
                        message = 'Failed connecting to host on {0}'.format(
                            host)
                    return ctx.operation.retry(message=message)

            # now we can create all other agent attributes
            configuration.prepare_agent(cloudify_agent, runner)

            # create the correct installer according to os
            # and local/remote execution
            if cloudify_agent['local']:
                installer = prepare_local_installer(cloudify_agent, ctx.logger)
            elif cloudify_agent['windows']:
                installer = RemoteWindowsAgentInstaller(
                    cloudify_agent, runner, ctx.logger)
            else:
                installer = RemoteLinuxAgentInstaller(cloudify_agent, runner,
                                                      ctx.logger)

            kwargs['cloudify_agent'] = cloudify_agent
            kwargs['installer'] = installer

            try:
                return func(*args, **kwargs)
            finally:
                if hasattr(installer.runner, 'close'):
                    installer.runner.close()
コード例 #11
0
ファイル: operations.py プロジェクト: dfilppi/cloudify-agent
        def wrapper(*args, **kwargs):
            cloudify_agent = kwargs.get('cloudify_agent') or {}
            agent_config = kwargs.get('agent_config') or {}
            cloudify_agent.update(agent_config)

            # first prepare all connection details
            configuration.prepare_connection(cloudify_agent)

            # create the correct runner according to os
            # and local/remote execution. we need this runner now because it
            # will be used to determine the agent basedir in case it wasn't
            # explicitly set
            if cloudify_agent['local']:
                runner = LocalCommandRunner(logger=ctx.logger)
            elif cloudify_agent['remote_execution'] is False:
                runner = StubRunner()
            else:
                host = cloudify_agent['ip']
                try:
                    if cloudify_agent['windows']:
                        runner = WinRMRunner(
                            host=host,
                            port=cloudify_agent.get('port'),
                            user=cloudify_agent['user'],
                            password=cloudify_agent['password'],
                            protocol=cloudify_agent.get('protocol'),
                            uri=cloudify_agent.get('uri'),
                            logger=ctx.logger,
                            validate_connection=validate_connection)
                    else:
                        runner = FabricRunner(
                            host=host,
                            port=cloudify_agent.get('port'),
                            user=cloudify_agent['user'],
                            key=cloudify_agent.get('key'),
                            password=cloudify_agent.get('password'),
                            fabric_env=cloudify_agent.get('fabric_env'),
                            logger=ctx.logger,
                            validate_connection=validate_connection)
                except CommandExecutionError as e:
                    message = e.error
                    if not message:
                        message = 'Failed connecting to host on {0}'.format(
                            host)
                    return ctx.operation.retry(message=message)

            # now we can create all other agent attributes
            configuration.prepare_agent(cloudify_agent, runner)

            # create the correct installer according to os
            # and local/remote execution
            if cloudify_agent['local']:
                installer = prepare_local_installer(cloudify_agent, ctx.logger)
            elif cloudify_agent['windows']:
                installer = RemoteWindowsAgentInstaller(
                    cloudify_agent, runner, ctx.logger)
            else:
                installer = RemoteLinuxAgentInstaller(
                    cloudify_agent, runner, ctx.logger)

            kwargs['cloudify_agent'] = cloudify_agent
            kwargs['installer'] = installer

            try:
                return func(*args, **kwargs)
            finally:
                if hasattr(installer.runner, 'close'):
                    installer.runner.close()
コード例 #12
0
ファイル: operations.py プロジェクト: geokala/cloudify-agent
        def wrapper(*args, **kwargs):

            cloudify_agent = kwargs.get("cloudify_agent", {})

            # first prepare all connection details
            configuration.prepare_connection(cloudify_agent)

            # create the correct runner according to os
            # and local/remote execution. we need this runner now because it
            # will be used to determine the agent basedir in case it wasn't
            # explicitly set
            if cloudify_agent["local"]:
                runner = LocalCommandRunner(logger=ctx.logger)
            else:
                try:
                    if cloudify_agent["windows"]:
                        runner = WinRMRunner(
                            host=cloudify_agent["ip"],
                            user=cloudify_agent["user"],
                            password=cloudify_agent["password"],
                            port=cloudify_agent.get("port"),
                            protocol=cloudify_agent.get("protocol"),
                            uri=cloudify_agent.get("uri"),
                            logger=ctx.logger,
                            validate_connection=validate_connection,
                        )
                    else:
                        runner = FabricRunner(
                            logger=ctx.logger,
                            host=cloudify_agent["ip"],
                            user=cloudify_agent["user"],
                            port=cloudify_agent.get("port"),
                            key=cloudify_agent.get("key"),
                            password=cloudify_agent.get("password"),
                            fabric_env=cloudify_agent.get("fabric_env"),
                            validate_connection=validate_connection,
                        )
                except CommandExecutionError as e:
                    return ctx.operation.retry(message=e.error, retry_after=5)

            # now we can create all other agent attributes
            configuration.prepare_agent(cloudify_agent, runner)

            # create the correct installer according to os
            # and local/remote execution
            if cloudify_agent["local"]:
                if os.name == "nt":
                    installer = LocalWindowsAgentInstaller(cloudify_agent, ctx.logger)
                else:
                    installer = LocalLinuxAgentInstaller(cloudify_agent, ctx.logger)
            elif cloudify_agent["windows"]:
                installer = RemoteWindowsAgentInstaller(cloudify_agent, ctx.logger)
            else:
                installer = RemoteLinuxAgentInstaller(cloudify_agent, ctx.logger)

            kwargs["cloudify_agent"] = cloudify_agent
            kwargs["runner"] = runner
            kwargs["installer"] = installer

            try:
                return func(*args, **kwargs)
            finally:
                # we need to close fabric connection
                if isinstance(installer, RemoteLinuxAgentInstaller):
                    installer.runner.close()