Exemplo n.º 1
0
def _create_mock_wagon(package_name, package_version):
    module_src = tempfile.mkdtemp(prefix='plugin-{0}-'.format(package_name))
    try:
        # Check whether setup.py exists in plugins path
        get_resource(path.join('plugins', package_name, 'setup.py'))
    except RuntimeError:
        try:
            with open(path.join(module_src, 'setup.py'), 'w') as f:
                f.write('from setuptools import setup\n')
                f.write('setup(name="{0}", version={1})'.format(
                    package_name, package_version))
            result = wagon.create(
                module_src,
                archive_destination_dir=tempfile.gettempdir(),
                force=True,
            )
        finally:
            shutil.rmtree(module_src)
        return result

    return wagon.create(
        get_resource(path.join('plugins', package_name)),
        archive_destination_dir=tempfile.gettempdir(),
        force=True,
    )
Exemplo n.º 2
0
def _create_mock_wagon(package_name, package_version):
    module_src = tempfile.mkdtemp(prefix='plugin-{0}-'.format(package_name))
    try:
        # Check whether setup.py exists in plugins path
        get_resource(path.join('plugins', package_name, 'setup.py'))
    except RuntimeError:
        try:
            with open(path.join(module_src, 'setup.py'), 'w') as f:
                f.write('from setuptools import setup\n')
                f.write('setup(name="{0}", version={1})'.format(
                    package_name, package_version))
            result = wagon.create(
                module_src,
                archive_destination_dir=tempfile.gettempdir(),
                force=True,
            )
        finally:
            shutil.rmtree(module_src)
        return result

    return wagon.create(
        get_resource(path.join('plugins', package_name)),
        archive_destination_dir=tempfile.gettempdir(),
        force=True,
    )
Exemplo n.º 3
0
    def test_source_directory_not_a_package(self):
        source_input = tempfile.mkdtemp()

        try:
            with pytest.raises(wagon.WagonError) as ex:
                wagon.create(source_input)
            assert 'Source directory must contain a setup.py file' in str(ex)
        finally:
            shutil.rmtree(source_input, ignore_errors=True)
Exemplo n.º 4
0
def create_plugin_wagon(plugin_dir_name,
                        target_directory,
                        requirements=False,
                        basedir=None):
    """
    Create a wagon from a plugin.

    :param plugin_dir_name: the plugin directory name, relative to the
    resources package.
    :type plugin_dir_name: str
    :param target_directory: the directory to create the wagon in
    :type target_directory: str
    :param requirements: optional requirements for wagon
    :type requirements: str

    :return: path to created wagon`
    :rtype: str
    """
    if basedir:
        plugin_source_path = os.path.join(basedir, plugin_dir_name)
    else:
        plugin_source_path = resources.get_resource(
            os.path.join('plugins', plugin_dir_name))
    return wagon.create(plugin_source_path,
                        requirement_files=requirements,
                        archive_destination_dir=target_directory)
Exemplo n.º 5
0
def create_plugin_wagon(plugin_dir_name,
                        target_directory,
                        requirements=False,
                        basedir=None):

    """
    Create a wagon from a plugin.

    :param plugin_dir_name: the plugin directory name, relative to the
    resources package.
    :type plugin_dir_name: str
    :param target_directory: the directory to create the wagon in
    :type target_directory: str
    :param requirements: optional requirements for wagon
    :type requirements: str

    :return: path to created wagon`
    :rtype: str
    """
    if basedir:
        plugin_source_path = os.path.join(basedir, plugin_dir_name)
    else:
        plugin_source_path = resources.get_resource(os.path.join(
            'plugins', plugin_dir_name))
    return wagon.create(
        plugin_source_path,
        requirement_files=requirements,
        archive_destination_dir=target_directory
    )
Exemplo n.º 6
0
 def create_wheel(package_name, package_version):
     module_src = '{0}=={1}'.format(package_name, package_version)
     return wagon.create(
         module_src,
         archive_destination_dir=tempfile.gettempdir(),
         force=True
     )
Exemplo n.º 7
0
 def _get_or_create_wagon(self, plugin_path):
     target_dir = tempfile.mkdtemp(dir=self.workdir)
     return [wagon.create(
         plugin_path,
         archive_destination_dir=target_dir,
         force=True
     )]
Exemplo n.º 8
0
 def create_wheel(package_name, package_version):
     module_src = '{0}=={1}'.format(package_name, package_version)
     return wagon.create(
         module_src,
         archive_destination_dir=tempfile.gettempdir(),
         force=True
     )
Exemplo n.º 9
0
 def _put_n_plugins(self, number_of_plugins):
     for i in range(0, number_of_plugins):
         tmpdir = tempfile.mkdtemp(prefix='test-pagination-')
         with open(os.path.join(tmpdir, 'setup.py'), 'w') as f:
             f.write('from setuptools import setup\n')
             f.write('setup(name="some-package", version={0})'.format(i))
         plugin_path = wagon.create(tmpdir, archive_destination_dir=tmpdir)
         self.post_file('/plugins', plugin_path)
         shutil.rmtree(tmpdir)
Exemplo n.º 10
0
 def test_plugins_sort(self):
     for i in range(1, 11):
         tmpdir = tempfile.mkdtemp(prefix='test-sort-')
         with open(os.path.join(tmpdir, 'setup.py'), 'w') as f:
             f.write('from setuptools import setup\n')
             f.write('setup(name="some-package", version={0})'.format(i))
         plugin_path = wagon.create(tmpdir, archive_destination_dir=tmpdir)
         self.client.plugins.upload(plugin_path)
         shutil.rmtree(tmpdir)
     self._test_sort('plugins', 'id')
Exemplo n.º 11
0
 def test_plugins_upload(self):
     self.client.plugins.upload = MagicMock()
     plugin_dest_dir = tempfile.mkdtemp()
     try:
         plugin_path = wagon.create('pip',
                                    archive_destination_dir=plugin_dest_dir)
         yaml_path = os.path.join(PLUGINS_DIR, 'plugin.yaml')
         self.invoke('cfy plugins upload {0} -y {1}'.format(
             plugin_path, yaml_path))
     finally:
         shutil.rmtree(plugin_dest_dir, ignore_errors=True)
 def _put_n_plugins(self, number_of_plugins):
     for i in range(0, number_of_plugins):
         tmpdir = tempfile.mkdtemp(prefix='test-pagination-')
         with open(os.path.join(tmpdir, 'setup.py'), 'w') as f:
             f.write('from setuptools import setup\n')
             f.write('setup(name="cloudify-script-plugin", version={0})'
                     .format(i))
         plugin_path = wagon.create(tmpdir, archive_destination_dir=tmpdir)
         yaml_path = self.get_full_path('mock_blueprint/plugin.yaml')
         zip_path = self.zip_files([plugin_path, yaml_path])
         self.post_file('/plugins', zip_path)
         shutil.rmtree(tmpdir)
 def test_plugins_pagination(self):
     for i in range(1, 11):
         tmpdir = tempfile.mkdtemp(prefix='test-pagination-')
         with open(os.path.join(tmpdir, 'setup.py'), 'w') as f:
             f.write('from setuptools import setup\n')
             f.write('setup(name="some-package", version={0})'.format(i))
         wagon_path = wagon.create(tmpdir, archive_destination_dir=tmpdir)
         yaml_path = resource('plugins/plugin.yaml')
         with utils.zip_files([wagon_path, yaml_path]) as zip_path:
             self.client.plugins.upload(zip_path)
         shutil.rmtree(tmpdir)
     self._test_pagination(self.client.plugins.list)
Exemplo n.º 14
0
    def test_create_with_requirements(self):
        test_package = os.path.join('tests', 'resources', 'test-package')
        requirement_files = [os.path.join(test_package, 'requirements.txt')]

        archive_path = wagon.create(source=test_package,
                                    force=True,
                                    requirement_files=requirement_files)
        self.archive_name = os.path.basename(archive_path)
        self.platform = 'any'
        metadata = wagon.show(self.archive_name)
        wheel_names = [whl.split('-')[0] for whl in metadata['wheels']]
        assert 'wheel' in wheel_names
        assert 'test_package' in wheel_names
 def _put_n_plugins(self, number_of_plugins):
     for i in range(0, number_of_plugins):
         tmpdir = tempfile.mkdtemp(prefix='test-pagination-')
         with open(os.path.join(tmpdir, 'setup.py'), 'w') as f:
             f.write('from setuptools import setup\n')
             f.write(
                 'setup(name="cloudify-script-plugin", version={0})'.format(
                     i))
         plugin_path = wagon.create(tmpdir, archive_destination_dir=tmpdir)
         yaml_path = self.get_full_path('mock_blueprint/plugin.yaml')
         zip_path = self.zip_files([plugin_path, yaml_path])
         self.post_file('/plugins', zip_path)
         shutil.rmtree(tmpdir)
Exemplo n.º 16
0
def _create_mock_wagon(package_name, package_version):
    module_src = tempfile.mkdtemp(prefix='plugin-{0}-'.format(package_name))
    try:
        with open(os.path.join(module_src, 'setup.py'), 'w') as f:
            f.write('from setuptools import setup\n')
            f.write('setup(name="{0}", version={1})'.format(
                package_name, package_version))
        result = wagon.create(module_src,
                              archive_destination_dir=tempfile.gettempdir(),
                              force=True)
    finally:
        shutil.rmtree(module_src)
    return result
Exemplo n.º 17
0
 def test_plugins_upload(self):
     self.client.plugins.upload = MagicMock()
     plugin_dest_dir = tempfile.mkdtemp()
     try:
         plugin_path = wagon.create(
             'pip',
             archive_destination_dir=plugin_dest_dir
         )
         yaml_path = os.path.join(PLUGINS_DIR, 'plugin.yaml')
         self.invoke('cfy plugins upload {0} -y {1}'.format(plugin_path,
                                                            yaml_path))
     finally:
         shutil.rmtree(plugin_dest_dir, ignore_errors=True)
 def test_plugins_sort(self):
     for i in range(1, 11):
         tmpdir = tempfile.mkdtemp(prefix='test-sort-')
         with open(os.path.join(tmpdir, 'setup.py'), 'w') as f:
             f.write('from setuptools import setup\n')
             f.write('setup(name="cloudify-script-plugin", version={0})'
                     .format(i))
         wagon_path = wagon.create(tmpdir, archive_destination_dir=tmpdir)
         yaml_path = resource('plugins/plugin.yaml')
         with utils.zip_files([wagon_path, yaml_path]) as zip_path:
             self.client.plugins.upload(zip_path)
         shutil.rmtree(tmpdir)
     self._test_sort('plugins', 'id')
Exemplo n.º 19
0
 def test_plugins_sort(self):
     for i in range(1, 11):
         tmpdir = tempfile.mkdtemp(prefix='test-sort-')
         with open(os.path.join(tmpdir, 'setup.py'), 'w') as f:
             f.write('from setuptools import setup\n')
             f.write('setup(name="cloudify-script-plugin", version={0})'
                     .format(i))
         wagon_path = wagon.create(
             tmpdir, archive_destination_dir=tmpdir,
             # mark the wagon as windows-only, so that the manager doesn't
             # attempt to install it - which would be irrelevant for this
             # test, but add additional flakyness and runtime
             wheel_args=['--build-option', '--plat-name=win'])
         yaml_path = resource('plugins/plugin.yaml')
         with utils.zip_files([wagon_path, yaml_path]) as zip_path:
             self.client.plugins.upload(zip_path)
         shutil.rmtree(tmpdir)
     self._test_sort('plugins', 'id')
Exemplo n.º 20
0
 def test_fail_validation_exclude_and_missing_wheel(self):
     test_package = os.path.join('tests', 'resources', 'test-package')
     requirement_files = [os.path.join(test_package, 'requirements.txt')]
     archive_path = wagon.create(source=test_package,
                                 requirement_files=requirement_files,
                                 force=True)
     archive_name = os.path.basename(archive_path)
     tempdir = tempfile.mkdtemp()
     try:
         wagon._unzip(archive_name, tempdir)
         wheels_dir = os.path.join(tempdir, 'test-package',
                                   wagon.DEFAULT_WHEELS_PATH)
         for wheel in os.listdir(wheels_dir):
             if wheel.startswith('wheel'):
                 break
         wheel_to_delete = os.path.join(wheels_dir, wheel)
         os.remove(wheel_to_delete)
         wagon._tar(os.path.join(tempdir, 'test-package'), archive_name)
         result = wagon.validate(archive_name)
         assert len(result) == 1
     finally:
         shutil.rmtree(tempdir, ignore_errors=True)
         if os.path.isfile(archive_name):
             os.remove(archive_name)
Exemplo n.º 21
0
 def setup_method(self, test_method):
     shutil.rmtree('test_env', ignore_errors=True)
     wagon._make_virtualenv('test_env')
     self.archive_path = wagon.create(source=TEST_PACKAGE, force=True)
Exemplo n.º 22
0
 def test_create_with_validation_no_virtualenv_installed(self):
     with pytest.raises(wagon.WagonError) as ex:
         wagon.create(TEST_PACKAGE, validate_archive=True)
     assert 'virtualenv is not installed' in str(ex.value)
Exemplo n.º 23
0
 def _create_test_wagon(self, plugin_name):
     source_dir = resource('plugins/{0}'.format(plugin_name))
     target_dir = tempfile.mkdtemp(dir=self.workdir)
     return wagon.create(source_dir,
                         archive_destination_dir=target_dir,
                         force=True)
Exemplo n.º 24
0
 def setup_method(self, test_method):
     wagon._run('virtualenv test_env')
     self.archive_path = wagon.create(source=TEST_PACKAGE, force=True)
Exemplo n.º 25
0
 def test_unsupported_url_schema(self):
     with pytest.raises(wagon.WagonError) as ex:
         wagon.create(source='ftp://x')
     assert 'Source URL type' in str(ex)
Exemplo n.º 26
0
 def test_create_archive_already_exists(self):
     wagon.create(TEST_PACKAGE)
     assert os.path.isfile(self.archive_name)
     with pytest.raises(wagon.WagonError) as ex:
         wagon.create(TEST_PACKAGE)
     assert 'Destination archive already exists:' in str(ex)
Exemplo n.º 27
0
def create(source, destination_dir):
    return wagon.create(source=source, archive_destination_dir=destination_dir)
Exemplo n.º 28
0
 def test_create_archive_already_exists_force(self):
     wagon.create(TEST_PACKAGE)
     assert os.path.isfile(self.archive_name)
     wagon.create(TEST_PACKAGE, force=True)
     assert os.path.isfile(self.archive_name)
Exemplo n.º 29
0
 def setup_method(self, test_method):
     self.archive_path = wagon.create(source=TEST_PACKAGE, force=True)
     # wagon._unzip(self.archive_path, '.')
     self.extracted_source = wagon.get_source(self.archive_path)
     self.expected_metadata = wagon._get_metadata(self.extracted_source)
Exemplo n.º 30
0
 def setup_method(self, test_method):
     self.archive_path = wagon.create(source=TEST_PACKAGE)