Beispiel #1
0
    def _manager_env(self):
        port = 8756
        fs = FileServer(root_path=self.temp_folder, port=port)
        fs.start()
        if os.name == 'nt':
            package_name = 'cloudify-windows-agent.exe'
        else:
            dist = platform.dist()
            package_name = '{0}-{1}-agent.tar.gz'.format(
                dist[0].lower(), dist[2].lower())
        resources_dir = os.path.join(self.temp_folder, 'resources')
        agent_dir = os.path.join(resources_dir, 'packages', 'agents')
        agent_script_dir = os.path.join(resources_dir, 'cloudify_agent')
        os.makedirs(agent_dir)
        os.makedirs(agent_script_dir)
        os.makedirs(os.path.join(self.temp_folder, 'cloudify'))

        agent_path = os.path.join(agent_dir, package_name)
        shutil.copyfile(agent_package.get_package_path(), agent_path)

        new_env = {
            constants.REST_HOST_KEY:
            'localhost',
            constants.MANAGER_FILE_SERVER_URL_KEY:
            'http://localhost:{0}'.format(port),
            constants.MANAGER_FILE_SERVER_ROOT_KEY:
            resources_dir,
            constants.REST_PORT_KEY:
            str(port),
        }
        with patch.dict(os.environ, new_env):
            try:
                yield
            finally:
                fs.stop()
Beispiel #2
0
 def _manager_env(self):
     port = 8756
     fs = FileServer(root_path=self.temp_folder, port=port)
     fs.start()
     if os.name == 'nt':
         package_name = 'cloudify-windows-agent.exe'
     else:
         dist = platform.dist()
         package_name = '{0}-{1}-agent.tar.gz'.format(
             dist[0].lower(), dist[2].lower())
     agent_dir = os.path.join(self.temp_folder, 'packages', 'agents')
     os.makedirs(agent_dir)
     agent_path = os.path.join(agent_dir, package_name)
     shutil.copyfile(agent_package.get_package_path(), agent_path)
     resources_dir = os.path.join(self.temp_folder, 'cloudify')
     os.makedirs(resources_dir)
     if os.getenv('AGENT_INSTALL_SCRIPT'):
         install_script_url = os.getenv('AGENT_INSTALL_SCRIPT')
     else:
         install_script_url = _INSTALL_SCRIPT_URL
     urllib.urlretrieve(install_script_url,
                        os.path.join(resources_dir, 'install_agent.py'))
     new_env = {
         constants.MANAGER_IP_KEY:
         'localhost',
         constants.MANAGER_FILE_SERVER_URL_KEY:
         'http://localhost:{0}'.format(port)
     }
     with patch.dict(os.environ, new_env):
         try:
             yield
         finally:
             fs.stop()
Beispiel #3
0
def _make_file_server(tmp_path, agent_ssl_cert, ssl=False):
    base_path = os.path.join(str(tmp_path), 'fileserver')
    if not os.path.exists(base_path):
        os.makedirs(base_path)
    # So that curl -o creates files, make sure we have content
    with open(os.path.join(base_path, 'keep_curl_happy'), 'w') as fh:
        fh.write('')
    return FileServer(agent_ssl_cert, base_path, ssl=ssl)
Beispiel #4
0
    def setUp(self):
        super(AgentInstallerLocalTest, self).setUp()

        self.resource_base = tempfile.mkdtemp(
            prefix='file-server-resource-base')
        self.fs = FileServer(root_path=self.resource_base)
        self.fs.start()

        self.addCleanup(self.fs.stop)
        self.addCleanup(shutil.rmtree, self.resource_base)
    def setUpClass(cls):
        cls.logger = setup_logger(cls.__name__)
        cls.resource_base = tempfile.mkdtemp(
            prefix='file-server-resource-base')
        cls.fs = FileServer(
            root_path=cls.resource_base)
        cls.fs.start()

        cls.source_url = get_source_uri()
        cls.requirements_file = get_requirements_uri()
Beispiel #6
0
    def _manager_env(self):
        port = 8756
        fs = FileServer(root_path=self.temp_folder, port=port)
        fs.start()
        self.addCleanup(fs.stop)
        if os.name == 'nt':
            package_name = 'cloudify-windows-agent.exe'
        else:
            dist = platform.dist()
            package_name = '{0}-{1}-agent.tar.gz'.format(
                dist[0].lower(), dist[2].lower())
        resources_dir = os.path.join(self.temp_folder, 'resources')
        agent_dir = os.path.join(resources_dir, 'packages', 'agents')
        agent_script_dir = os.path.join(resources_dir, 'cloudify_agent')
        os.makedirs(agent_dir)
        os.makedirs(agent_script_dir)
        os.makedirs(os.path.join(self.temp_folder, 'cloudify'))

        agent_path = os.path.join(agent_dir, package_name)
        shutil.copyfile(agent_package.get_package_path(), agent_path)
        self.addCleanup(agent_package.cleanup)

        new_env = {
            constants.MANAGER_FILE_SERVER_ROOT_KEY: resources_dir,
            constants.REST_PORT_KEY: str(port),
            constants.MANAGER_NAME: 'cloudify'
        }

        original_create_op_context = operations._get_cloudify_context

        def mock_create_op_context(agent, task_name):
            context = original_create_op_context(agent, task_name)
            context['__cloudify_context']['local'] = True
            return context

        # Need to patch, to avoid broker_ssl_enabled being True
        @contextmanager
        def get_amqp_client(agent):
            yield get_client()

        managers = [
            ManagerItem({
                'networks': {
                    'default': '127.0.0.1'
                },
                'ca_cert_content': agent_ssl_cert.DUMMY_CERT,
                'hostname': 'cloudify'
            })
        ]
        patches = [
            patch.dict(os.environ, new_env),
            patch('cloudify_agent.operations._get_amqp_client',
                  get_amqp_client),
            patch('cloudify.endpoint.LocalEndpoint.get_managers',
                  return_value=managers),
            patch('cloudify_agent.operations._get_cloudify_context',
                  mock_create_op_context),
            get_tenant_mock()
        ]
        for p in patches:
            p.start()
        try:
            yield
        finally:
            for p in patches:
                p.stop()
            fs.stop()