def test_manipulator_remove_plugin(self): inner = copy.deepcopy(TEST_INNER_DOCK_JSON) m = DockJsonManipulator(TEST_BUILD_JSON, inner) m.remove_plugin("postbuild_plugins", "all_rpm_packages") assert len([ x for x in inner["postbuild_plugins"] if x.get("all_rpm_packages", None) ]) == 0
def test_manipulator_merge(): inner = copy.deepcopy(INNER_DOCK_JSON) plugin = [x for x in inner['prebuild_plugins'] if x["name"] == "a_plugin"][0] m = DockJsonManipulator(None, inner) m.dock_json_merge_arg("prebuild_plugins", "a_plugin", "key1", {"a": '3', "z": '9'}) assert plugin['args']['key1']['a'] == '3' assert plugin['args']['key1']['b'] == '2' assert plugin['args']['key1']['z'] == '9'
def test_manipulator_get_dock_json(self): build_json = copy.deepcopy(TEST_BUILD_JSON) env_json = build_json['spec']['strategy']['customStrategy']['env'] p = [env for env in env_json if env["name"] == "DOCK_PLUGINS"] inner = {"a": "b"} p[0]['value'] = json.dumps(inner) m = DockJsonManipulator(build_json, None) response = m.get_dock_json() assert response["a"] == inner["a"]
def test_manipulator_get_dock_json(): build_json = copy.deepcopy(BUILD_JSON) env_json = build_json['parameters']['strategy']['customStrategy']['env'] p = [env for env in env_json if env["name"] == "DOCK_PLUGINS"] inner = { "a": "b" } p[0]['value'] = json.dumps(inner) m = DockJsonManipulator(build_json, None) response = m.get_dock_json() assert response["a"] == inner["a"]
def render(self, validate=True): if validate: self.spec.validate() super(ProductionWithoutKojiBuild, self).render() dj = DockJsonManipulator(self.template, self.inner_template) self.template['parameters']['output']['imageTag'] = self.spec.image_tag.value dj.write_dock_json() self.build_json = self.template logger.debug(self.build_json) return self.build_json
def render(self, validate=True): if validate: self.spec.validate() super(SimpleBuild, self).render() dj = DockJsonManipulator(self.template, self.inner_template) self.template['parameters']['output']['imageTag'] = self.spec.image_tag.value dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "url", self.spec.openshift_uri.value) dj.write_dock_json() self.build_json = self.template logger.debug(self.build_json) return self.build_json
def test_manipulator_merge(self): inner = copy.deepcopy(TEST_INNER_DOCK_JSON) plugin = [ x for x in inner['prebuild_plugins'] if x["name"] == "a_plugin" ][0] m = DockJsonManipulator(None, inner) m.dock_json_merge_arg("prebuild_plugins", "a_plugin", "key1", { "a": '3', "z": '9' }) assert plugin['args']['key1']['a'] == '3' assert plugin['args']['key1']['b'] == '2' assert plugin['args']['key1']['z'] == '9'
def render(self, validate=True): if validate: self.spec.validate() super(ProductionBuild, self).render() dj = DockJsonManipulator(self.template, self.inner_template) self.template['parameters']['output']['imageTag'] = self.spec.image_tag.value dj.dock_json_set_arg('prebuild_plugins', "koji", "target", self.spec.koji_target.value) dj.dock_json_set_arg('prebuild_plugins', "koji", "root", self.spec.kojiroot.value) dj.dock_json_set_arg('prebuild_plugins', "koji", "hub", self.spec.kojihub.value) dj.write_dock_json() self.build_json = self.template logger.debug(self.build_json) return self.build_json
def render(self, validate=True): if validate: self.spec.validate() super(ProductionWithSecretBuild, self).render() dj = DockJsonManipulator(self.template, self.inner_template) self.template['parameters']['source']['sourceSecretName'] = self.spec.source_secret.value # don't push to docker registry, we're using pulp here self.template['parameters']['output']['registry'] = "" dj.dock_json_set_arg('postbuild_plugins', "pulp_push", "pulp_registry_name", self.spec.pulp_registry.value) dj.dock_json_set_arg('postbuild_plugins', "cp_built_image_to_nfs", "nfs_server_path", self.spec.nfs_server_path.value) if self.spec.nfs_dest_dir.value: dj.dock_json_set_arg('postbuild_plugins', "cp_built_image_to_nfs", "dest_dir", self.spec.nfs_dest_dir.value) dj.write_dock_json() self.build_json = self.template logger.debug(self.build_json) return self.build_json
def test_manipulator_get_dock_json_missing_input(): build_json = copy.deepcopy(BUILD_JSON) build_json['parameters']['strategy']['customStrategy']['env'] = None m = DockJsonManipulator(build_json, None) with pytest.raises(RuntimeError): m.get_dock_json()
def render(self, validate=True): if validate: self.spec.validate() super(ProductionBuild, self).render() dj = DockJsonManipulator(self.template, self.inner_template) self.template['parameters']['output']['imageTag'] = self.spec.image_tag.value # if there is yum repo specified, don't pick stuff from koji if self.spec.yum_repourls.value: logger.info("removing koji from request, because there is yum repo specified") dj.remove_plugin("prebuild_plugins", "koji") else: dj.dock_json_set_arg('prebuild_plugins', "koji", "target", self.spec.koji_target.value) dj.dock_json_set_arg('prebuild_plugins', "koji", "root", self.spec.kojiroot.value) dj.dock_json_set_arg('prebuild_plugins', "koji", "hub", self.spec.kojihub.value) dj.write_dock_json() self.build_json = self.template logger.debug(self.build_json) return self.build_json
def render(self, validate=True): if validate: self.spec.validate() super(CommonProductionBuild, self).render() dj = DockJsonManipulator(self.template, self.inner_template) dj.dock_json_set_arg('prebuild_plugins', "distgit_fetch_artefacts", "command", self.spec.sources_command.value) dj.dock_json_set_arg('prebuild_plugins', "change_source_registry", "registry_uri", self.spec.registry_uri.value) dj.dock_json_set_arg('postbuild_plugins', "tag_by_labels", "registry_uri", self.spec.registry_uri.value) implicit_labels = { 'Architecture': self.spec.architecture.value, 'Vendor': self.spec.vendor.value, 'Build_Host': self.spec.build_host.value, 'Authoritative_Registry': self.spec.authoritative_registry.value, } dj.dock_json_merge_arg('prebuild_plugins', "add_labels_in_dockerfile", "labels", implicit_labels) dj.dock_json_set_arg('postbuild_plugins', "store_metadata_in_osv3", "url", self.spec.openshift_uri.value)
def test_manipulator_remove_nonexisting_plugin(self): inner = copy.deepcopy(TEST_INNER_DOCK_JSON) m = DockJsonManipulator(TEST_BUILD_JSON, inner) m.remove_plugin("postbuild_plugins", "this-doesnt-exist")
def test_manipulator_get_dock_json_missing_input(self): build_json = copy.deepcopy(TEST_BUILD_JSON) build_json['spec']['strategy']['customStrategy']['env'] = None m = DockJsonManipulator(build_json, None) with pytest.raises(RuntimeError): m.get_dock_json()
def test_manipulator(self): m = DockJsonManipulator(TEST_BUILD_JSON, TEST_INNER_DOCK_JSON) assert m is not None
def dj(self): if self._dj is None: self._dj = DockJsonManipulator(self.template, self.inner_template) return self._dj
def test_manipulator_remove_plugin(self): inner = copy.deepcopy(TEST_INNER_DOCK_JSON) m = DockJsonManipulator(TEST_BUILD_JSON, inner) m.remove_plugin("postbuild_plugins", "all_rpm_packages") assert len([x for x in inner["postbuild_plugins"] if x.get("all_rpm_packages", None)]) == 0