コード例 #1
0
ファイル: image.py プロジェクト: yangguangxiadeyun/cekit
    def _prepare(self):
        self._descriptor['labels'] = [
            Label(x) for x in self._descriptor.get('labels', [])
        ]
        self._descriptor['envs'] = [
            Env(x) for x in self._descriptor.get('envs', [])
        ]
        self._descriptor['ports'] = [
            Port(x) for x in self._descriptor.get('ports', [])
        ]
        if 'run' in self._descriptor:
            self._descriptor['run'] = Run(self._descriptor['run'])
        self._descriptor['artifacts'] = [
            create_resource(a, directory=self._artifact_dir)
            for a in self._descriptor.get('artifacts', [])
        ]
        self._descriptor['modules'] = Modules(
            self._descriptor.get('modules', {}), self.path)
        self._descriptor['packages'] = Packages(
            self._descriptor.get('packages', {}), self.path)
        self._descriptor['osbs'] = Osbs(self._descriptor.get('osbs', {}),
                                        self.path)
        self._descriptor['volumes'] = [
            Volume(x) for x in self._descriptor.get('volumes', [])
        ]

        # make sure image declarations override any module definitions
        self._image_overrides = {
            'artifacts': Image._to_dict(self.artifacts),
            'modules': Image._to_dict(self.modules.install)
        }
        self._all_artifacts = Image._to_dict(self.artifacts)
コード例 #2
0
def test_packages_invalid_old_repository_definition():
    with pytest.raises(CekitError, match=r"Cannot validate schema: Repository"):
        Packages(yaml.safe_load("""
        repositories:
            - repo-foo
            - repo-bar
        install:
            - pkg-foo"""), "a/path/image.yaml")
コード例 #3
0
def test_packages_content_sets():
    pkg = Packages(
        {
            'content_sets': {
                'x86_64': ['rhel-server-rhscl-7-rpms', 'rhel-7-server-rpms']
            },
            'install': ['package_a', 'package_b']
        }, "a/path")

    assert 'package_a' in pkg['install']
    assert 'content_sets_file' not in pkg
コード例 #4
0
def test_packages_content_sets_and_content_sets_file():
    with pytest.raises(CekitError, match=r"You cannot specify 'content_sets' and 'content_sets_file' together in the packages section!"):
        Packages(
            {
                'content_sets': {
                    'x86_64': ['rhel-server-rhscl-7-rpms', 'rhel-7-server-rpms']
                },
                'content_sets_file': "a_path.yaml"
            },
            "a/path"
        )
コード例 #5
0
def test_packages(mocker):
    mocker.patch.object(Repository, '_get_repo_url', return_value='foo')
    pkg = Packages(yaml.safe_load("""
      repositories:
          - repo-foo
          - repo-bar
      install:
          - pkg-foo"""))

    assert Repository('repo-foo') in pkg['repositories']
    assert Repository('repo-bar') in pkg['repositories']
    assert 'pkg-foo' in pkg['install']
コード例 #6
0
def test_packages_content_sets_file(mocker):
    with mocker.mock_module.patch(
            'cekit.descriptor.packages.os.path.exists') as exists_mock:
        exists_mock.return_value = True
        with mocker.mock_module.patch('cekit.descriptor.packages.open',
                                      mocker.mock_open(read_data='{"a": 12}')):
            pkg = Packages(
                {
                    'content_sets_file': "a_path.yaml",
                    'install': ['package_a', 'package_b']
                }, "a/path")

    assert 'package_a' in pkg['install']
    assert 'content_sets_file' not in pkg
    assert pkg['content_sets'] == {'a': 12}
コード例 #7
0
ファイル: image.py プロジェクト: svkcemk/cekit
 def packages(self):
     return self.get('packages', Packages({}, self.path))
コード例 #8
0
def test_packages():
    pkg = Packages(yaml.safe_load("""
      install:
          - pkg-foo"""), "a/path/image.yaml")

    assert 'pkg-foo' in pkg['install']
コード例 #9
0
ファイル: image.py プロジェクト: vorburger/cekit
    def _prepare(self):
        """Updates self._descriptor with objects and prepare sane label"""

        self._descriptor['labels'] = self._descriptor.get('labels', [])
        # we will persist cekit version in a label here, so we know which version of cekit
        # was used to build the image
        self['labels'].extend([{
            'name': 'org.concrt.version',
            'value': cekit_version
        }, {
            'name': 'io.cekit.version',
            'value': cekit_version
        }])

        # The description key available in image descriptor's
        # root is added as labels to the image
        key = 'description'

        # If we define the label in the image descriptor
        # we should *not* override it with value from
        # the root's key
        if key in self._descriptor and not self.label(key):
            value = self._descriptor[key]
            self._descriptor['labels'].append({'name': key, 'value': value})

        # Last - if there is no 'summary' label added to image descriptor
        # we should use the value of the 'description' key and create
        # a 'summary' label with it's content. If there is even that
        # key missing - we should not add anything.
        description = self.label('description')

        if not self.label('summary') and description:
            self._descriptor['labels'].append({
                'name': 'summary',
                'value': description['value']
            })

        self._descriptor['labels'] = [
            Label(x) for x in self._descriptor.get('labels', [])
        ]
        self._descriptor['envs'] = [
            Env(x) for x in self._descriptor.get('envs', [])
        ]
        self._descriptor['ports'] = [
            Port(x) for x in self._descriptor.get('ports', [])
        ]
        if 'run' in self._descriptor:
            self._descriptor['run'] = Run(self._descriptor['run'])
        self._descriptor['artifacts'] = [
            Resource(a, directory=self._artifact_dir)
            for a in self._descriptor.get('artifacts', [])
        ]
        if 'modules' in self._descriptor:
            self._descriptor['modules'] = Modules(self._descriptor['modules'],
                                                  self.path)
        if 'packages' in self._descriptor:
            self._descriptor['packages'] = Packages(
                self._descriptor['packages'])
        if 'osbs' in self._descriptor:
            self._descriptor['osbs'] = Osbs(self._descriptor['osbs'])
        self._descriptor['volumes'] = [
            Volume(x) for x in self._descriptor.get('volumes', [])
        ]