コード例 #1
0
 def test_check_value_none_found(self) -> None:
     f = PropertiesFile()
     with self.assertRaises(PropertiesFile.UnexpectedKeyValueError) as err:
         f.check_value("invalid", "value")
     self.assertEqual(
         str(err.exception),
         "Expected to have invalid='value', but none was found.")
 def check(self, path: str) -> None:
     ext = os.path.splitext(path)[1]
     if ext not in [
             ".asc",
             ".jar",
             ".md5",
             ".module",
             ".pom",
             ".sha1",
             ".sha256",
             ".sha512",
             ".war",
             ".xml",
             ".zip",
     ]:
         raise BuildArtifactCheck.BuildArtifactInvalidError(
             path, f"{ext} is not a valid extension for a maven file")
     if os.path.splitext(path)[1] == ".jar":
         with ZipFile(path, "r") as zip:
             data = zip.read("META-INF/MANIFEST.MF").decode("UTF-8")
             properties = PropertiesFile(data)
             try:
                 versions: List[Any] = [None]
                 versions.extend(self.target.compatible_component_versions)
                 versions.extend(self.target.compatible_min_versions)
                 properties.check_value_in("Implementation-Version",
                                           versions)
             except PropertiesFile.CheckError as e:
                 raise BuildArtifactCheck.BuildArtifactInvalidError(
                     path, str(e))
             logging.info(
                 f'Checked {path} ({properties.get_value("Implementation-Version", "N/A")})'
             )
コード例 #3
0
 def test_check_value_in_none_found(self) -> None:
     f = PropertiesFile()
     with self.assertRaises(PropertiesFile.UnexpectedKeyValuesError) as err:
         f.check_value_in("invalid", ["one", "two"])
     self.assertEqual(
         str(err.exception),
         "Expected to have invalid=any of ['one', 'two'], but none was found.",
     )
コード例 #4
0
 def test_check_value_in_invalid(self) -> None:
     f = PropertiesFile({"key": "value"})
     with self.assertRaises(PropertiesFile.UnexpectedKeyValuesError) as err:
         f.check_value_in("key", ["one", "two"])
     self.assertEqual(
         str(err.exception),
         "Expected to have key=any of ['one', 'two'], but was 'value'.",
     )
コード例 #5
0
    def __get_dependencies(self):
        cmd = " ".join([
            f"./gradlew {self.gradle_project or ''}:dependencies",
            f"-Dopensearch.version={self.target.opensearch_version}",
            f"-Dbuild.snapshot={str(self.target.snapshot).lower()}",
            "--configuration compileOnly",
            '| grep -e "---"',
        ])

        lines = self.git_repo.output(cmd)
        stack = ["root"]
        props = PropertiesFile("")
        for line in lines.split("\n"):
            # e.g. "|    +--- org.opensearch:opensearch-core:1.1.0-SNAPSHOT"
            # see job_scheduler_dependencies.txt in tests for an example
            match = re.search(r"---\s(.*):([0-9,\w,.-]*)[\s]*", line)
            if match:
                levels = line.count("   ") + line.count("---")

                while levels < len(stack):
                    del stack[-1]

                if levels == len(stack):
                    stack[-1] = match.group(1).strip()
                elif levels > len(stack):
                    stack.append(match.group(1).strip())

                key = "/".join(stack)
                value = match.group(2).strip()
                logging.debug(f"{key}={value}")
                props[key] = value

        return props
コード例 #6
0
    def __get_properties(self):
        cmd = " ".join([
            "./gradlew properties",
            f"-Dopensearch.version={self.target.opensearch_version}",
            f"-Dbuild.snapshot={str(self.target.snapshot).lower()}",
        ])

        return PropertiesFile(self.git_repo.output(cmd))
コード例 #7
0
 def __mock_check(self, props: Any = None, component: Component = None, snapshot: bool = True) -> CiCheckGradlePropertiesVersion:
     with patch.object(CiCheckGradlePropertiesVersion, "_CiCheckGradleProperties__get_properties") as mock_properties:
         mock_properties.return_value = PropertiesFile(props)
         return CiCheckGradlePropertiesVersion(
             component=component or MagicMock(),
             git_repo=MagicMock(),
             target=CiTarget(version="2.0.0", name="opensearch", qualifier="alpha1", snapshot=snapshot),
         )
コード例 #8
0
 def properties(self):
     cmd = ComponentOpenSearch.gradle_cmd(
         "properties",
         {
             "opensearch.version": self.opensearch_version,
             "build.snapshot": str(self.snapshot).lower(),
         },
     )
     return PropertiesFile(self.git_repo.output(cmd))
コード例 #9
0
 def __mock_check(self, props=None, component=None, snapshot=True):
     with patch.object(
             CiCheckGradlePropertiesVersion,
             "_CiCheckGradleProperties__get_properties") as mock_properties:
         mock_properties.return_value = PropertiesFile(props)
         return CiCheckGradlePropertiesVersion(
             component=component or MagicMock(),
             git_repo=MagicMock(),
             target=CiTarget(version="1.1.0",
                             name="opensearch",
                             snapshot=snapshot),
         )
 def __mock_check(self, props=None):
     with patch.object(
             CiCheckGradleDependenciesOpenSearchVersion,
             "_CiCheckGradleDependencies__get_dependencies",
     ) as mock_dependencies:
         mock_dependencies.return_value = PropertiesFile(props)
         return CiCheckGradleDependenciesOpenSearchVersion(
             component=MagicMock(),
             git_repo=MagicMock(),
             target=CiTarget(version="1.1.0",
                             name="opensearch",
                             snapshot=True),
             args=None,
         )
コード例 #11
0
    def __get_properties(self) -> PropertiesFile:
        cmd = " ".join(
            filter(
                None,
                [
                    "./gradlew properties",
                    f"-Dopensearch.version={self.target.opensearch_version}",
                    f"-Dbuild.snapshot={str(self.target.snapshot).lower()}",
                    f"-Dbuild.version_qualifier={str(self.target.qualifier)}" if self.target.qualifier else None,
                ]
            )
        )

        return PropertiesFile(self.git_repo.output(cmd))
コード例 #12
0
 def __mock_check(self,
                  props: Any = None,
                  component: Component = None,
                  snapshot: bool = True) -> CiCheckNpmPackageVersion:
     with patch.object(
             CiCheckNpmPackageVersion,
             "_CiCheckPackage__get_properties") as mock_properties:
         mock_properties.return_value = PropertiesFile(props)
         return CiCheckNpmPackageVersion(
             component=component or MagicMock(),
             git_repo=MagicMock(),
             target=CiTarget(version="1.1.0",
                             name="dashboards-plugin",
                             qualifier=None,
                             snapshot=snapshot),
         )
コード例 #13
0
 def check(self, path: str) -> None:
     if os.path.splitext(path)[1] != ".zip":
         raise BuildArtifactCheck.BuildArtifactInvalidError(path, "Not a zip file.")
     if not self.valid_path(path):
         raise BuildArtifactCheck.BuildArtifactInvalidError(path, f"Expected filename to include one of {self.target.compatible_component_versions}.")
     with ZipFile(path, "r") as zip:
         data = zip.read("plugin-descriptor.properties").decode("UTF-8")
         properties = PropertiesFile(data)
         try:
             properties.check_value_in("version", self.target.compatible_component_versions)
             properties.check_value_in("opensearch.version", self.target.compatible_versions)
         except PropertiesFile.CheckError as e:
             raise BuildArtifactCheck.BuildArtifactInvalidError(path, e.__str__())
         logging.info(f'Checked {path} ({properties.get_value("version", "N/A")})')
コード例 #14
0
 def properties(self) -> PropertiesFile:
     cmd = ComponentOpenSearch.gradle_cmd(
         "properties", {"build.snapshot": str(self.snapshot).lower()})
     return PropertiesFile(self.git_repo.output(cmd))
コード例 #15
0
 def test_check_value_in(self) -> None:
     f = PropertiesFile({"key": "value"})
     f.check_value_in("key", ["value"])
コード例 #16
0
 def __get_properties(self) -> PropertiesFile:
     with open(self.package_json_path, "r") as f:
         return PropertiesFile(CiCheckPackage.__flattenDict(json.load(f)))
コード例 #17
0
 def test_check_value_invalid(self) -> None:
     f = PropertiesFile({"key": "value"})
     with self.assertRaises(PropertiesFile.UnexpectedKeyValueError) as err:
         f.check_value("key", "invalid")
     self.assertEqual(str(err.exception),
                      "Expected to have key='invalid', but was 'value'.")
コード例 #18
0
 def test_check_value(self) -> None:
     f = PropertiesFile({"key": "value"})
     f.check_value("key", "value")
コード例 #19
0
 def test_get_value(self) -> None:
     f = PropertiesFile({"key": "value"})
     self.assertEqual(f.get_value("key"), "value")
     self.assertEqual(f.get_value("invalid"), None)
     self.assertEqual(f.get_value("invalid", "default"), "default")
コード例 #20
0
 def test_blank(self) -> None:
     f = PropertiesFile()
     self.assertEqual(f.properties, {})