]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: validate that the constructed YumDnf baseurl is usable
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 20 Jan 2022 19:48:28 +0000 (14:48 -0500)
committerAdam King <adking@redhat.com>
Thu, 3 Feb 2022 14:58:03 +0000 (09:58 -0500)
If the inputs to the `cephadm add-repo` command would result in an
invalid URL for repo metadata fail the command early with a (somewhat)
helpful error.

Fixes: https://tracker.ceph.com/issues/46773
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm

index 5a83d3900418cb7d42f9087bb9b90fbe05aeb0cb..8694fcd4110160c89644850a405af75fc93cabfa 100755 (executable)
@@ -6486,6 +6486,18 @@ class YumDnf(Packager):
             if self.version and self.version.split('.')[0] >= '16':
                 raise Error('Ceph does not support 16.y.z or later for this version of this linux distro and therefore cannot add a repo for it')
 
+        if self.stable or self.version:
+            # we know that yum & dnf require there to be a
+            # $base_url/$arch/repodata/repomd.xml so we can test if this URL
+            # is gettable in order to validate the inputs
+            test_url = self.repo_baseurl() + '/noarch/repodata/repomd.xml'
+            try:
+                urlopen(test_url)
+            except HTTPError as err:
+                logger.error('unable to fetch repo metadata: %r', err)
+                raise Error('failed to fetch repository metadata. please check'
+                            ' the provided parameters are correct and try again')
+
     def add_repo(self) -> None:
         if self.stable or self.version:
             content = ''