Fix previously broken distro auto-detection

Previous patch made the wrong assumption that
platform.linux_distribution() returns distribution and version but
that is not true.

New logic is using the os-release file which is the official way
to idenfity distribution ID (fedora, centos,..) and its major
version (VERSION_ID). Same logic is used by Ansible.

The final distro result should look like: centos7 or fedora28

If task fails it will silenty default to 'centos7' and raise a clear
warning:

WARNING: Unsupported platform '' detected by tripleo-repos, centos7
will be used unless you use CLI param to change it.

Change-Id: I28690d3576291bca02ea5c4b75689881a8e20a6b
Task: https://tree.taiga.io/project/tripleo-ci-board/task/733
Follow-Up: https://review.openstack.org/#/c/635475/
This commit is contained in:
Sorin Sbarnea 2019-02-14 12:30:36 +00:00
parent e6b0badef2
commit db84b7b14b
1 changed files with 13 additions and 7 deletions

View File

@ -14,12 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import argparse
import os
import platform
import re
import subprocess
import warnings
import sys
import requests
@ -64,12 +64,18 @@ class NoRepoTitle(Exception):
def _parse_args():
distro = "".join(platform.linux_distribution()[0:2]).lower()
distro = subprocess.Popen(
'source /etc/os-release && echo "$ID$VERSION_ID"',
shell=True,
stdout=subprocess.PIPE,
stderr=open(os.devnull, 'w')).communicate()[0].rstrip()
if distro not in SUPPORTED_DISTROS:
warnings.warn(
"Unsupported platform '%s' detected by tripleo-repos, centos7 "
"will be used unless you use CLI param to change it." %
distro)
print(
"WARNING: Unsupported platform '%s' detected by tripleo-repos, "
"centos7 will be used unless you use CLI param to change it." %
distro, file=sys.stderr)
distro = 'centos7'
parser = argparse.ArgumentParser(
description='Download and install repos necessary for TripleO. Note '