Esempio n. 1
0
def verify_license(_):
    import sys
    import os
    from automation.utilities.path import get_repo_root

    license_header = """# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
"""

    env_path = os.path.join(get_repo_root(), 'env')

    files_without_header = []
    for current_dir, _, files in os.walk(get_repo_root()):
        if current_dir.startswith(env_path):
            continue

        file_itr = (os.path.join(current_dir, p) for p in files if p.endswith('.py') and p != 'azure_bdist_wheel.py')
        for python_file in file_itr:
            with open(python_file, 'r') as f:
                file_text = f.read()

                if file_text and license_header not in file_text:
                    files_without_header.append(os.path.join(current_dir, python_file))

    if files_without_header:
        sys.stderr.write("Error: The following files don't have the required license headers: \n{}".format(
            '\n'.join(files_without_header)))

        sys.exit(1)
def verify_license(args):
    import sys
    import os
    from automation.utilities.path import get_repo_root

    license_header = \
"""# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
"""

    env_path = os.path.join(get_repo_root(), 'env')

    files_without_header = []
    for current_dir, _, files in os.walk(get_repo_root()):
        if current_dir.startswith(env_path):
            continue

        file_itr = (os.path.join(current_dir, p) for p in files
                    if p.endswith('.py') and p != 'azure_bdist_wheel.py')
        for python_file in file_itr:
            with open(python_file, 'r') as f:
                file_text = f.read()

                if file_text and license_header not in file_text:
                    files_without_header.append(
                        os.path.join(current_dir, python_file))

    if files_without_header:
        sys.stderr.write(
            "Error: The following files don't have the required license headers: \n{}"
            .format('\n'.join(files_without_header)))

        sys.exit(1)
Esempio n. 3
0
def run_pep8():
    print('\n\nRun flake8 for PEP8 compliance')
    modules_list = ' '.join([os.path.join(automation_path.get_repo_root(), m) for m in MODULES])
    print(modules_list)
    command = 'flake8 --statistics --append-config={} {}'.format(
        os.path.join(automation_path.get_repo_root(), '.flake8'), modules_list)

    return_code = call(command.split())
    if return_code:
        print('Flake8 failed')
    else:
        print('Flake8 passed')

    return return_code
Esempio n. 4
0
def run_tests(parallel, run_live):
    print('\n\nRun automation')

    # create test results folder
    test_results_folder = get_test_results_dir(with_timestamp=True,
                                               prefix='tests')

    # get test runner
    run_nose = get_nose_runner(test_results_folder,
                               xunit_report=True,
                               exclude_integration=True,
                               parallel=parallel)

    # set environment variable
    if run_live:
        os.environ['AZURE_CLI_TEST_RUN_LIVE'] = 'True'

    # run tests
    passed = True
    module_results = []
    name = 'batch-extensions'
    test_path = os.path.join(automation_path.get_repo_root(), 'tests')
    result, start, end, _ = run_nose(name, test_path)
    passed &= result
    record = (name, start.strftime('%H:%M:%D'),
              str((end - start).total_seconds()), 'Pass' if result else 'Fail')

    module_results.append(record)

    print_records(module_results, title='test results')

    return passed
Esempio n. 5
0
def run_pylint():
    print('\n\nRun pylint')

    modules_list = os.path.join(automation_path.get_repo_root(), 'azure')
    arguments = '{} --rcfile={} -j {} -r n -d I0013'.format(
        modules_list,
        os.path.join(automation_path.get_repo_root(), 'pylintrc'),
        multiprocessing.cpu_count())

    return_code = call(('python -m pylint ' + arguments).split())

    if return_code:
        print('Pylint failed')
    else:
        print('Pylint passed')

    return return_code
Esempio n. 6
0
def run_pylint():
    print('\n\nRun pylint')

    modules = [os.path.join(automation_path.get_repo_root(), 'azext')]
    modules.append(os.path.join(automation_path.get_repo_root(), 'batch-cli-extensions', 'azext_batch'))
    modules_list = ' '.join(modules)
    print(modules_list)
    arguments = '{} --rcfile={} -j {} -r n -d I0013'.format(
        modules_list,
        os.path.join(automation_path.get_repo_root(), 'pylintrc'),
        multiprocessing.cpu_count())

    return_code = call(('python -m pylint ' + arguments).split())

    if return_code:
        print('Pylint failed')
    else:
        print('Pylint passed')

    return return_code
Esempio n. 7
0
    def test_azure_cli_module_manifest_and_azure_bdist(self):
        path = self.test_data['module_path']
        self.assertTrue(os.path.isdir(path), msg='Path {} does not exist'.format(path))

        manifest_file = os.path.join(path, 'MANIFEST.in')
        self.assertTrue(os.path.isfile(manifest_file), msg='Manifest file {} missing'.format(manifest_file))

        # Check azure_bdist_wheel.py file for module.
        # Assumption is that core has the correct file always so compare against that.
        core_azure_bdist_wheel = os.path.join(automation_path.get_repo_root(), 'src', 'azure-cli-core', 'azure_bdist_wheel.py')
        mod_azure_bdist_wheel = os.path.join(path, 'azure_bdist_wheel.py')
        if os.path.isfile(mod_azure_bdist_wheel):
            self.assertTrue(filecmp.cmp(core_azure_bdist_wheel, mod_azure_bdist_wheel), "Make sure {} is correct. It should look like {}".format(mod_azure_bdist_wheel, core_azure_bdist_wheel))
Esempio n. 8
0
def run_pep8(modules):
    print('\n\nRun flake8 for PEP8 compliance')
    print('Modules: {}'.format(', '.join(name for name, _ in modules)))

    command = 'flake8 --statistics --append-config={} {}'.format(
        os.path.join(automation_path.get_repo_root(), '.flake8'),
        ' '.join(path for _, path in modules))

    return_code = call(command.split())
    if return_code:
        print('Flake8 failed')
    else:
        print('Flake8 passed')

    return return_code
Esempio n. 9
0
def run_pep8(modules):
    print('\n\nRun flake8 for PEP8 compliance')
    print('Modules: {}'.format(', '.join(name for name, _, _ in modules)))

    command = 'flake8 --statistics --append-config={} {}'.format(
        os.path.join(automation_path.get_repo_root(), '.flake8'),
        ' '.join(path for _, path, _ in modules))

    return_code = call(command.split())
    if return_code:
        print('Flake8 failed')
    else:
        print('Flake8 passed')

    return return_code
Esempio n. 10
0
def run_pylint(modules):
    print('\n\nRun pylint')
    print('Modules: {}'.format(', '.join(name for name, _, _ in modules)))

    modules_list = ' '.join(os.path.join(path, 'azure') for _, path, _ in modules)
    arguments = '{} --rcfile={} -j {} -r n -d I0013'.format(
        modules_list,
        os.path.join(automation_path.get_repo_root(), 'pylintrc'),
        multiprocessing.cpu_count())

    return_code = call(('python -m pylint ' + arguments).split())

    if return_code:
        print('Pylint failed')
    else:
        print('Pylint passed')

    return return_code
Esempio n. 11
0
def run_pylint(modules):
    print('\n\nRun pylint')
    print(
    'Modules: {}'.format(', '.join([name for name, _ in modules if not name.endswith('-nspkg')])))

    modules_list = ' '.join(
        [os.path.join(path, 'azure') for name, path in modules if not name.endswith('-nspkg')])
    arguments = '{} --rcfile={} -j {}'.format(
        modules_list,
        os.path.join(automation_path.get_repo_root(), 'pylintrc'),
        multiprocessing.cpu_count())

    return_code = call(('python -m pylint ' + arguments).split())

    if return_code:
        print('Pylint failed')
    else:
        print('Pylint passed')

    return return_code
Esempio n. 12
0
    def test_azure_cli_module_manifest_and_azure_bdist(self):
        path = self.test_data['module_path']
        self.assertTrue(os.path.isdir(path),
                        msg='Path {} does not exist'.format(path))

        manifest_file = os.path.join(path, 'MANIFEST.in')
        self.assertTrue(os.path.isfile(manifest_file),
                        msg='Manifest file {} missing'.format(manifest_file))

        # Check azure_bdist_wheel.py file for module.
        # Assumption is that core has the correct file always so compare against that.
        core_azure_bdist_wheel = os.path.join(automation_path.get_repo_root(),
                                              'src', 'azure-cli-core',
                                              'azure_bdist_wheel.py')
        mod_azure_bdist_wheel = os.path.join(path, 'azure_bdist_wheel.py')
        if os.path.isfile(mod_azure_bdist_wheel):
            self.assertTrue(
                filecmp.cmp(core_azure_bdist_wheel, mod_azure_bdist_wheel),
                "Make sure {} is correct. It should look like {}".format(
                    mod_azure_bdist_wheel, core_azure_bdist_wheel))
Esempio n. 13
0
    def _runner(module_paths):
        from subprocess import check_call, CalledProcessError
        if len(module_paths) > 1:
            print('When --test is given, no more than 1 module can be selected.')
            return False

        module_path = module_paths[0][len(os.path.join(get_repo_root(), 'src' + os.sep)):]
        if module_path.startswith('command_modules'):
            module_path = module_path.split(os.sep, 2)[-1].replace(os.sep, '.')
        else:
            module_path = module_path.split(os.sep, 1)[-1].replace(os.sep, '.')

        try:
            import unittest
            suite = unittest.TestLoader().loadTestsFromNames(['{}.{}'.format(module_path, t) for t in test_cases])
            runner = unittest.TextTestRunner()
            result = runner.run(suite)

            return not result.failures
        except CalledProcessError:
            return False
Esempio n. 14
0
    def _runner(module_paths):
        from subprocess import check_call, CalledProcessError
        if len(module_paths) > 1:
            print('When --test is given, no more than 1 module can be selected.')
            return False

        module_path = module_paths[0][len(os.path.join(get_repo_root(), 'src' + os.sep)):]
        if module_path.startswith('command_modules'):
            module_path = module_path.split(os.sep, 2)[-1].replace(os.sep, '.')
        else:
            module_path = module_path.split(os.sep, 1)[-1].replace(os.sep, '.')

        try:
            import unittest
            suite = unittest.TestLoader().loadTestsFromNames(['{}.{}'.format(module_path, t) for t in test_cases])
            runner = unittest.TextTestRunner()
            result = runner.run(suite)

            return not result.failures
        except CalledProcessError:
            return False
Esempio n. 15
0
"""Verify the list of modules that should be included as part of the CLI install. """

from __future__ import print_function

import os
import sys
import json
import tempfile
import zipfile
import glob

from automation.utilities.path import (get_repo_root,
                                       get_command_modules_paths)
from automation.utilities.display import print_heading

AZURE_CLI_PATH = os.path.join(get_repo_root(), 'src', 'azure-cli')
AZURE_CLI_SETUP_PY = os.path.join(AZURE_CLI_PATH, 'setup.py')


def get_cli_dependencies(build_folder):
    azure_cli_wheel = glob.glob(build_folder.rstrip('/') +
                                '/azure_cli-*.whl')[0]
    print('Explore wheel file {}.'.format(azure_cli_wheel))

    tmp_dir = tempfile.mkdtemp()

    zip_ref = zipfile.ZipFile(azure_cli_wheel, 'r')
    zip_ref.extractall(tmp_dir)
    zip_ref.close()

    dist_info_dir = [
Esempio n. 16
0
"""Verify the list of modules that should be included as part of the CLI install. """

from __future__ import print_function

import os
import sys
import json
import tempfile
import zipfile
import glob

from automation.utilities.path import (get_repo_root, get_command_modules_paths)
from automation.utilities.display import print_heading

AZURE_CLI_PATH = os.path.join(get_repo_root(), 'src', 'azure-cli')
AZURE_CLI_SETUP_PY = os.path.join(AZURE_CLI_PATH, 'setup.py')

# This is a list of modules that we do not want to be installed by default.
# Add your modules to this list if you don't want it to be installed when the CLI is installed.
MODULES_TO_EXCLUDE = ['azure-cli-taskhelp']


def get_cli_dependencies(build_folder):
    azure_cli_wheel = glob.glob(build_folder.rstrip('/') + '/azure_cli-*.whl')[0]
    print('Explore wheel file {}.'.format(azure_cli_wheel))

    tmp_dir = tempfile.mkdtemp()

    zip_ref = zipfile.ZipFile(azure_cli_wheel, 'r')
    zip_ref.extractall(tmp_dir)