Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a check for linux version consistency #5747

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/command_modules/azure-cli-extension/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
Release History
===============

0.0.10
+++++++
* Added check to warn user if used distro is different then the one stored in package source file, as this may lead into errors.

0.0.9
++++++
* Added support for --pip-proxy parameter to az extension add/update commands.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# --------------------------------------------------------------------------------------------
import sys
import os
import platform
import tempfile
import shutil
import zipfile
Expand Down Expand Up @@ -33,6 +34,9 @@
OUT_KEY_TYPE = 'extensionType'
OUT_KEY_METADATA = 'metadata'

IS_WINDOWS = sys.platform.lower() in ['windows', 'win32']
LIST_FILE_PATH = os.path.join(os.sep, 'etc', 'apt', 'sources.list.d', 'azure-cli.list')


def _run_pip(pip_exec_args):
cmd = [sys.executable, '-m', 'pip'] + pip_exec_args + ['-vv', '--disable-pip-version-check', '--no-cache-dir']
Expand Down Expand Up @@ -136,6 +140,8 @@ def _add_whl_ext(source, ext_sha256=None, pip_extra_index_urls=None, pip_proxy=N
except CLIError as e:
raise e
logger.debug('Validation successful on %s', ext_file)
# Check for distro consistency
check_distro_consistency()
# Install with pip
extension_path = get_extension_path(extension_name)
pip_args = ['install', '--target', extension_path, ext_file]
Expand Down Expand Up @@ -259,3 +265,27 @@ def update_extension(extension_name, index_url=None, pip_extra_index_urls=None,

def list_available_extensions(index_url=None):
return get_index_extensions(index_url=index_url)


def check_distro_consistency():
if not IS_WINDOWS:
try:
logger.debug('Linux distro check: Reading from: %s', LIST_FILE_PATH)

with open(LIST_FILE_PATH, 'r') as list_file:
package_source = list_file.read()
stored_linux_dist_name = package_source.split(" ")[3]
logger.debug('Linux distro check: Found in list file: %s', stored_linux_dist_name)
current_linux_dist_name = platform.linux_distribution()[2]
logger.debug('Linux distro check: Reported by API: %s', current_linux_dist_name)

except Exception as err:
current_linux_dist_name = None
stored_linux_dist_name = None
logger.debug('Linux distro check: An error occurred while checking linux distribution version source list consistency.')
logger.debug(err)

if (current_linux_dist_name != stored_linux_dist_name):
logger.warning("Linux distro check: Mismatch distribution name in %s file", LIST_FILE_PATH)
logger.warning("Linux distro check: If command fails, install the appropriate package for your distribution or change the above file accordingly.")
logger.warning("Linux distro check: %s has '%s', current distro is '%s'", LIST_FILE_PATH, stored_linux_dist_name, current_linux_dist_name)
2 changes: 1 addition & 1 deletion src/command_modules/azure-cli-extension/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
logger.warn("Wheel is not available, disabling bdist_wheel hook")
cmdclass = {}

VERSION = "0.0.9"
VERSION = "0.0.10"

CLASSIFIERS = [
'Development Status :: 5 - Production/Stable',
Expand Down