Example #1
0
 def test_non_integer_suffix(self):
     """
     ``make_rpm_version`` raises ``UnparseableVersion`` when supplied with a
     version with a non-integer pre or dev suffix number.
     """
     with self.assertRaises(UnparseableVersion):
         make_rpm_version('0.1.2rcX')
Example #2
0
 def test_non_integer_suffix(self):
     """
     ``make_rpm_version`` raises ``UnparseableVersion`` when supplied with a
     version with a non-integer pre or dev suffix number.
     """
     with self.assertRaises(UnparseableVersion):
         make_rpm_version('0.1.2rcX')
Example #3
0
    def test_good(self):
        """
        ``make_rpm_version`` gives the expected ``RPMVersion`` instances when
        supplied with valid ``flocker_version_number``s.
        """
        expected = {
            '0.1.0': RPMVersion(version='0.1.0', release='1'),
            '0.1.0+99.g3d644b1': RPMVersion(
                version='0.1.0', release='1.99.g3d644b1'),
            '0.1.1rc1': RPMVersion(version='0.1.1', release='0.rc.1'),
            '0.1.1': RPMVersion(version='0.1.1', release='1'),
            '0.2.0.dev1': RPMVersion(version='0.2.0', release='0.dev.1'),
            '0.2.0.dev2+99.g3d644b1':
                RPMVersion(version='0.2.0', release='0.dev.2.99.g3d644b1'),
            '0.2.0.dev3+100.g3d644b2.dirty': RPMVersion(
                version='0.2.0', release='0.dev.3.100.g3d644b2.dirty'),
        }
        unexpected_results = []
        for supplied_version, expected_rpm_version in expected.items():
            actual_rpm_version = make_rpm_version(supplied_version)
            if actual_rpm_version != expected_rpm_version:
                unexpected_results.append((
                    supplied_version,
                    actual_rpm_version,
                    expected_rpm_version,
                ))

        if unexpected_results:
            self.fail(unexpected_results)
Example #4
0
    def test_good(self):
        """
        ``make_rpm_version`` gives the expected ``RPMVersion`` instances when
        supplied with valid ``flocker_version_number``s.
        """
        expected = {
            '0.1.0':
            RPMVersion(version='0.1.0', release='1'),
            '0.1.0+99.g3d644b1':
            RPMVersion(version='0.1.0', release='1.99.g3d644b1'),
            '0.1.1rc1':
            RPMVersion(version='0.1.1', release='0.rc.1'),
            '0.1.1':
            RPMVersion(version='0.1.1', release='1'),
            '0.2.0.dev1':
            RPMVersion(version='0.2.0', release='0.dev.1'),
            '0.2.0.dev2+99.g3d644b1':
            RPMVersion(version='0.2.0', release='0.dev.2.99.g3d644b1'),
            '0.2.0.dev3+100.g3d644b2.dirty':
            RPMVersion(version='0.2.0', release='0.dev.3.100.g3d644b2.dirty'),
        }
        unexpected_results = []
        for supplied_version, expected_rpm_version in expected.items():
            actual_rpm_version = make_rpm_version(supplied_version)
            if actual_rpm_version != expected_rpm_version:
                unexpected_results.append((
                    supplied_version,
                    actual_rpm_version,
                    expected_rpm_version,
                ))

        if unexpected_results:
            self.fail(unexpected_results)
Example #5
0
def perform_download_packages_from_repository(dispatcher, intent):
    """
    See :class:`DownloadPackagesFromRepository`.
    """
    rpm_version = make_rpm_version(intent.flocker_version)

    package_type = intent.distribution.package_type()
    s = requests.Session()
    # Tests use a local package repository
    s.mount('file://', FileAdapter())

    downloaded_packages = set()
    for package in intent.packages:
        package_name = package_filename(
            package_type=package_type,
            package=package,
            architecture=PACKAGE_ARCHITECTURE[package],
            rpm_version=rpm_version,
        )
        url = intent.source_repo + '/' + package_name
        local_path = intent.target_path.child(package_name).path
        download = s.get(url)
        download.raise_for_status()
        content = download.content
        with open(local_path, "wb") as local_file:
            local_file.write(content)
        downloaded_packages.add(package_name)

    return downloaded_packages
Example #6
0
def perform_download_packages_from_repository(dispatcher, intent):
    """
    See :class:`DownloadPackagesFromRepository`.
    """
    rpm_version = make_rpm_version(intent.flocker_version)
    distribution = Distribution(
        name=intent.distro_name,
        version=intent.distro_version,
    )
    package_type = distribution.package_type()
    s = requests.Session()
    # Tests use a local package repository
    s.mount('file://', FileAdapter())

    downloaded_packages = set()
    for package in intent.packages:
        package_name = package_filename(
            package_type=package_type,
            package=package,
            architecture=PACKAGE_ARCHITECTURE[package],
            rpm_version=rpm_version,
        )
        url = intent.source_repo + '/' + package_name
        local_path = intent.target_path.child(package_name).path
        download = s.get(url)
        download.raise_for_status()
        content = download.content
        with open(local_path, "wb") as local_file:
            local_file.write(content)
        downloaded_packages.add(package_name)

    return downloaded_packages
Example #7
0
 def rpm_version(self):
     """
     :return: An ``rpm_version`` and cache it.
     """
     if self._rpm_version is None:
         self._rpm_version = make_rpm_version(self.package_version_step.version)
     return self._rpm_version
Example #8
0
    def postOptions(self):
        if self['distribution'] is None:
            raise UsageError("Distribution required.")

        if self['config-file'] is not None:
            config_file = FilePath(self['config-file'])
            self['config'] = yaml.safe_load(config_file.getContent())
        else:
            self['config'] = {}

        if self['flocker-version']:
            rpm_version = make_rpm_version(self['flocker-version'])
            os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
            if os_version.endswith('.dirty'):
                os_version = os_version[:-len('.dirty')]
        else:
            os_version = None

        self['package_source'] = PackageSource(
            version=self['flocker-version'],
            os_version=os_version,
            branch=self['branch'],
            build_server=self['build-server'],
        )

        if self['pip']:
            supported = PIP_DISTRIBUTIONS
        else:
            supported = PACKAGED_CLIENT_DISTRIBUTIONS
        if self['distribution'] not in supported:
            raise UsageError(
                "Distribution %r not supported. Available distributions: %s"
                % (self['distribution'], ', '.join(supported)))
Example #9
0
    def postOptions(self):
        if self['distribution'] is None:
            raise UsageError("Distribution required.")

        if self['config-file'] is not None:
            config_file = FilePath(self['config-file'])
            self['config'] = yaml.safe_load(config_file.getContent())
        else:
            self['config'] = {}

        if self['flocker-version']:
            rpm_version = make_rpm_version(self['flocker-version'])
            os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
            if os_version.endswith('.dirty'):
                os_version = os_version[:-len('.dirty')]
        else:
            os_version = None

        self['package_source'] = PackageSource(
            version=self['flocker-version'],
            os_version=os_version,
            branch=self['branch'],
            build_server=self['build-server'],
        )

        if self['pip']:
            supported = PIP_DISTRIBUTIONS
        else:
            supported = PACKAGED_CLIENT_DISTRIBUTIONS
        if self['distribution'] not in supported:
            raise UsageError(
                "Distribution %r not supported. Available distributions: %s" %
                (self['distribution'], ', '.join(supported)))
Example #10
0
 def rpm_version(self):
     """
     :return: An ``rpm_version`` and cache it.
     """
     if self._rpm_version is None:
         self._rpm_version = make_rpm_version(
             self.package_version_step.version)
     return self._rpm_version
Example #11
0
def build_box(path, name, version, branch, build_server):
    """
    Build a vagrant box.

    :param FilePath path: Directory containing ``Vagrantfile``.
    :param bytes name: Base name of vagrant box. Used to build filename.
    :param bytes version: Version of vagrant box. Used to build filename.
    :param bytes branch: Branch to get flocker RPMs from.
    :param build_server: Base URL of build server to download RPMs from.
    """
    box_path = path.child('%s%s%s.box' %
                          (name, '-' if version else '', version))
    json_path = path.child('%s.json' % (name, ))

    # Destroy the box to begin, so that we are guaranteed
    # a clean build.
    run(['vagrant', 'destroy', '-f'], cwd=path.path)

    # Update the base box to the latest version on Atlas.
    run(['vagrant', 'box', 'update'], cwd=path.path)

    # Generate the enviroment variables used to pass options down to the
    # provisioning scripts via the Vagrantfile
    env = os.environ.copy()
    rpm_version = make_rpm_version(version).version
    rpm_release = make_rpm_version(version).release
    env.update({
        'FLOCKER_RPM_VERSION': '%s-%s' % (rpm_version, rpm_release),
        'FLOCKER_BUILD_SERVER': build_server,
        # branch is None if it isn't passed, but that isn't a legal
        # environment value.
        'FLOCKER_BRANCH': branch or ''
    })
    # Boot the VM and run the provisioning scripts.
    run(['vagrant', 'up'], cwd=path.path, env=env)

    # Package up running VM.
    run(['vagrant', 'package', '--output', box_path.path], cwd=path.path)

    # And destroy at the end to save space.  If one of the above commands fail,
    # this will be skipped, so the image can still be debugged.
    run(['vagrant', 'destroy', '-f'], cwd=path.path)

    # Generate metadata needed to add box locally.
    metadata = box_metadata(name, version, box_path)
    json_path.setContent(json.dumps(metadata))
Example #12
0
def build_box(path, name, version, branch, build_server):
    """
    Build a vagrant box.

    :param FilePath path: Directory containing ``Vagrantfile``.
    :param bytes name: Base name of vagrant box. Used to build filename.
    :param bytes version: Version of vagrant box. Used to build filename.
    :param bytes branch: Branch to get flocker RPMs from.
    :param build_server: Base URL of build server to download RPMs from.
    """
    box_path = path.child('%s%s%s.box'
                          % (name, '-' if version else '', version))
    json_path = path.child('%s.json' % (name,))

    # Destroy the box to begin, so that we are guaranteed
    # a clean build.
    run(['vagrant', 'destroy', '-f'], cwd=path.path)

    # Update the base box to the latest version on Atlas.
    run(['vagrant', 'box', 'update'], cwd=path.path)

    # Generate the enviroment variables used to pass options down to the
    # provisioning scripts via the Vagrantfile
    env = os.environ.copy()
    rpm_version = make_rpm_version(version).version
    rpm_release = make_rpm_version(version).release
    env.update({
        'FLOCKER_RPM_VERSION': '%s-%s' % (rpm_version, rpm_release),
        'FLOCKER_BUILD_SERVER': build_server,
        # branch is None if it isn't passed, but that isn't a legal
        # environment value.
        'FLOCKER_BRANCH': branch or ''
        })
    # Boot the VM and run the provisioning scripts.
    run(['vagrant', 'up'], cwd=path.path, env=env)

    # Package up running VM.
    run(['vagrant', 'package', '--output', box_path.path], cwd=path.path)

    # And destroy at the end to save space.  If one of the above commands fail,
    # this will be skipped, so the image can still be debugged.
    run(['vagrant', 'destroy', '-f'], cwd=path.path)

    # Generate metadata needed to add box locally.
    metadata = box_metadata(name, version, box_path)
    json_path.setContent(json.dumps(metadata))
Example #13
0
    def postOptions(self):
        if self['distribution'] is None:
            raise UsageError("Distribution required.")

        if self['config-file'] is not None:
            config_file = FilePath(self['config-file'])
            self['config'] = yaml.safe_load(config_file.getContent())
        else:
            self['config'] = {}

        if self['flocker-version']:
            rpm_version = make_rpm_version(self['flocker-version'])
            os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
            if os_version.endswith('.dirty'):
                os_version = os_version[:-len('.dirty')]
        else:
            os_version = None

        package_source = PackageSource(
            version=self['flocker-version'],
            os_version=os_version,
            branch=self['branch'],
            build_server=self['build-server'],
        )

        if self['provider'] not in PROVIDERS:
            raise UsageError(
                "Provider %r not supported. Available providers: %s"
                % (self['provider'], ', '.join(PROVIDERS)))

        if self['provider'] in CLOUD_PROVIDERS:
            # Configuration must include credentials etc for cloud providers.
            try:
                provider_config = self['config'][self['provider']]
            except KeyError:
                raise UsageError(
                    "Configuration file must include a "
                    "{!r} config stanza.".format(self['provider'])
                )

            provisioner = CLOUD_PROVIDERS[self['provider']](**provider_config)

            self.runner = LibcloudRunner(
                config=self['config'],
                top_level=self.top_level,
                distribution=self['distribution'],
                package_source=package_source,
                provisioner=provisioner,
                variants=self['variants'],
            )
        else:
            self.runner = VagrantRunner(
                config=self['config'],
                top_level=self.top_level,
                distribution=self['distribution'],
                package_source=package_source,
                variants=self['variants'],
            )
Example #14
0
 def test_os_version(self):
     """
     os_version() returns an OS version for a FLocker version.
     """
     version = '1.2.3'
     rpm_version = make_rpm_version(version)
     expected = "%s-%s" % (rpm_version.version, rpm_version.release)
     package_source = PackageSource(version=version)
     self.assertEqual(expected, package_source.os_version())
Example #15
0
 def test_os_version(self):
     """
     os_version() returns an OS version for a FLocker version.
     """
     version = '1.2.3'
     rpm_version = make_rpm_version(version)
     expected = "%s-%s" % (rpm_version.version, rpm_version.release)
     package_source = PackageSource(version=version)
     self.assertEqual(expected, package_source.os_version())
Example #16
0
 def os_version(self):
     """The version of the OS package of Flocker to install."""
     if self.version:
         rpm_version = make_rpm_version(self.version)
         os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
         if os_version.endswith('.dirty'):
             os_version = os_version[:-len('.dirty')]
     else:
         os_version = None
     return os_version
Example #17
0
 def os_version(self):
     """The version of the OS package of Flocker to install."""
     if self.version:
         rpm_version = make_rpm_version(self.version)
         os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
         if os_version.endswith('.dirty'):
             os_version = os_version[:-len('.dirty')]
     else:
         os_version = None
     return os_version
Example #18
0
    def postOptions(self):
        if self['distribution'] is None:
            raise UsageError("Distribution required.")

        if self['config-file'] is not None:
            config_file = FilePath(self['config-file'])
            self['config'] = yaml.safe_load(config_file.getContent())
        else:
            self['config'] = {}

        if self['flocker-version']:
            rpm_version = make_rpm_version(self['flocker-version'])
            os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
            if os_version.endswith('.dirty'):
                os_version = os_version[:-len('.dirty')]
        else:
            os_version = None

        package_source = PackageSource(
            version=self['flocker-version'],
            os_version=os_version,
            branch=self['branch'],
            build_server=self['build-server'],
        )

        if self['distribution'] not in DISTRIBUTIONS:
            raise UsageError(
                "Distribution %r not supported. Available distributions: %s" %
                (self['distribution'], ', '.join(DISTRIBUTIONS)))

        if self['provider'] not in PROVIDERS:
            raise UsageError(
                "Provider %r not supported. Available providers: %s" %
                (self['provider'], ', '.join(PROVIDERS)))

        if self['provider'] in CLOUD_PROVIDERS:
            # Configuration must include credentials etc for cloud providers.
            try:
                provider_config = self['config'][self['provider']]
            except KeyError:
                raise UsageError("Configuration file must include a "
                                 "{!r} config stanza.".format(
                                     self['provider']))

            provisioner = CLOUD_PROVIDERS[self['provider']](**provider_config)

            self.runner = LibcloudRunner(
                config=self['config'],
                top_level=self.top_level,
                distribution=self['distribution'],
                package_source=package_source,
                provisioner=provisioner,
            )
Example #19
0
    def postOptions(self):
        if self['distribution'] is None:
            raise UsageError("Distribution required.")

        if self['config-file'] is not None:
            config_file = FilePath(self['config-file'])
            self['config'] = yaml.safe_load(config_file.getContent())
        else:
            self['config'] = {}

        provider = self['provider'].lower()
        provider_config = self['config'].get(provider, {})

        if self['flocker-version']:
            rpm_version = make_rpm_version(self['flocker-version'])
            os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
            if os_version.endswith('.dirty'):
                os_version = os_version[:-len('.dirty')]
        else:
            os_version = None

        package_source = PackageSource(
            version=self['flocker-version'],
            os_version=os_version,
            branch=self['branch'],
            build_server=self['build-server'],
        )
        try:
            get_runner = getattr(self, "_runner_" + provider.upper())
        except AttributeError:
            raise UsageError(
                "Provider {!r} not supported. Available providers: {}".format(
                    provider, ', '.join(
                        name.lower() for name in self._get_provider_names()
                    )
                )
            )
        else:
            self.runner = get_runner(
                package_source=package_source,
                dataset_backend=self.dataset_backend(),
                provider_config=provider_config,
            )
Example #20
0
    def postOptions(self):
        if self['distribution'] is None:
            raise UsageError("Distribution required.")

        if self['config-file'] is not None:
            config_file = FilePath(self['config-file'])
            self['config'] = yaml.safe_load(config_file.getContent())
        else:
            self['config'] = {}

        provider = self['provider'].lower()
        provider_config = self['config'].get(provider, {})

        if self['flocker-version']:
            rpm_version = make_rpm_version(self['flocker-version'])
            os_version = "%s-%s" % (rpm_version.version, rpm_version.release)
            if os_version.endswith('.dirty'):
                os_version = os_version[:-len('.dirty')]
        else:
            os_version = None

        package_source = PackageSource(
            version=self['flocker-version'],
            os_version=os_version,
            branch=self['branch'],
            build_server=self['build-server'],
        )
        try:
            get_runner = getattr(self, "_runner_" + provider.upper())
        except AttributeError:
            raise UsageError(
                "Provider {!r} not supported. Available providers: {}".format(
                    provider,
                    ', '.join(name.lower()
                              for name in self._get_provider_names())))
        else:
            self.runner = get_runner(
                package_source=package_source,
                dataset_backend=self.dataset_backend(),
                provider_config=provider_config,
            )