def test_update_extension_extra_index_url(self):
        """
        Tests extension update while specifying --extra-index-url parameter.
        :return:
        """
        extra_index_urls = [
            'https://testpypi.python.org/simple',
            'https://pypi.python.org/simple'
        ]

        add_extension(cmd=self.cmd,
                      source=MY_EXT_SOURCE,
                      pip_extra_index_urls=extra_index_urls)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
        newer_extension = _get_test_data_file(
            'myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
        computed_extension_sha256 = _compute_file_hash(newer_extension)
        with mock.patch(
                'azure.cli.core.extension.operations.resolve_from_index',
                return_value=(newer_extension, computed_extension_sha256)):
            update_extension(self.cmd,
                             MY_EXT_NAME,
                             pip_extra_index_urls=extra_index_urls)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.4+dev')
Пример #2
0
def start_shell(cmd, update=None, style=None):
    from importlib import import_module

    try:
        get_extension(INTERACTIVE_EXTENSION_NAME)

        if update:
            logger.warning(
                "Updating the Interactive extension to the latest available..."
            )
            update_extension(cmd, INTERACTIVE_EXTENSION_NAME)
            reload_extension(INTERACTIVE_EXTENSION_NAME)
    except ExtensionNotInstalledException:
        logger.warning("Installing the Interactive extension...")
        add_extension(cmd, extension_name=INTERACTIVE_EXTENSION_NAME)

    ext = get_extension(INTERACTIVE_EXTENSION_NAME)
    try:
        check_version_compatibility(ext.get_metadata())
    except CLIError:
        raise CLIError('Run `az interactive --update` and try again.')

    add_extension_to_path(INTERACTIVE_EXTENSION_NAME, ext_dir=ext.path)
    interactive_module = get_extension_modname(
        ext_name=INTERACTIVE_EXTENSION_NAME, ext_dir=ext.path)
    azext_interactive = import_module(interactive_module)
    azext_interactive.start_shell(cmd, style=style)
Пример #3
0
 def test_update_extension_no_updates(self):
     add_extension(source=MY_EXT_SOURCE)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
     with mock.patch('azure.cli.core.extension.operations.resolve_from_index', side_effect=NoExtensionCandidatesError()):
         with self.assertRaises(CLIError) as err:
             update_extension(MY_EXT_NAME)
         self.assertTrue("No updates available for '{}'.".format(MY_EXT_NAME) in str(err.exception))
 def test_update_extension_no_updates(self):
     add_extension(cmd=self.cmd, source=MY_EXT_SOURCE)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
     with mock.patch('azure.cli.core.extension.operations.resolve_from_index', side_effect=NoExtensionCandidatesError()):
         with self.assertRaises(CLIError) as err:
             update_extension(self.cmd, MY_EXT_NAME)
         self.assertTrue("No updates available for '{}'.".format(MY_EXT_NAME) in str(err.exception))
Пример #5
0
 def test_update_extension(self):
     add_extension(source=MY_EXT_SOURCE)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
     newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
     computed_extension_sha256 = _compute_file_hash(newer_extension)
     with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(newer_extension, computed_extension_sha256)):
         update_extension(MY_EXT_NAME)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.4+dev')
 def test_update_extension(self):
     add_extension(cmd=self.cmd, source=MY_EXT_SOURCE)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
     newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
     computed_extension_sha256 = _compute_file_hash(newer_extension)
     with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(newer_extension, computed_extension_sha256)):
         update_extension(self.cmd, MY_EXT_NAME)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.4+dev')
Пример #7
0
 def test_update_extension_exception_in_update_and_rolled_back(self):
     add_extension(source=MY_EXT_SOURCE)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
     newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
     bad_sha256 = 'thishashisclearlywrong'
     with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(newer_extension, bad_sha256)):
         with self.assertRaises(CLIError) as err:
             update_extension(MY_EXT_NAME)
         self.assertTrue('Failed to update. Rolled {} back to {}.'.format(ext['name'], ext[OUT_KEY_VERSION]) in str(err.exception))
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
 def test_update_extension_exception_in_update_and_rolled_back(self):
     add_extension(cmd=self.cmd, source=MY_EXT_SOURCE)
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
     newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
     bad_sha256 = 'thishashisclearlywrong'
     with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(newer_extension, bad_sha256)):
         with self.assertRaises(CLIError) as err:
             update_extension(self.cmd, MY_EXT_NAME)
         self.assertTrue('Failed to update. Rolled {} back to {}.'.format(ext['name'], ext[OUT_KEY_VERSION]) in str(err.exception))
     ext = show_extension(MY_EXT_NAME)
     self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
    def test_update_extension_no_updates(self):
        logger_msgs = []

        def mock_log_warning(_, msg):
            logger_msgs.append(msg)

        add_extension(cmd=self.cmd, source=MY_EXT_SOURCE)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
        with mock.patch('azure.cli.core.extension.operations.resolve_from_index', side_effect=NoExtensionCandidatesError()), \
                mock.patch('logging.Logger.warning', mock_log_warning):
            update_extension(self.cmd, MY_EXT_NAME)
        self.assertTrue("No updates available for '{}'.".format(MY_EXT_NAME) in
                        logger_msgs[0])
Пример #10
0
def start_shell(cmd, update=None, style=None):
    from importlib import import_module
    try:
        get_extension(INTERACTIVE_EXTENSION_NAME)
        if update:
            logger.warning("Updating the Interactive extension to the latest available..")
            update_extension(INTERACTIVE_EXTENSION_NAME)
            reload_extension(INTERACTIVE_EXTENSION_NAME)
    except ExtensionNotInstalledException:
        logger.warning("Installing the Interactive extension..")
        add_extension(extension_name=INTERACTIVE_EXTENSION_NAME)

    add_extension_to_path(INTERACTIVE_EXTENSION_NAME)
    interactive_module = get_extension_modname(ext_name=INTERACTIVE_EXTENSION_NAME)
    azext_interactive = import_module(interactive_module)
    azext_interactive.start_shell(cmd, style=style)
    def test_update_extension_extra_index_url(self):
        """
        Tests extension update while specifying --extra-index-url parameter.
        :return:
        """
        extra_index_urls = ['https://testpypi.python.org/simple', 'https://pypi.python.org/simple']

        add_extension(cmd=self.cmd, source=MY_EXT_SOURCE, pip_extra_index_urls=extra_index_urls)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
        newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
        computed_extension_sha256 = _compute_file_hash(newer_extension)
        with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(newer_extension, computed_extension_sha256)):
            update_extension(self.cmd, MY_EXT_NAME, pip_extra_index_urls=extra_index_urls)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.4+dev')
Пример #12
0
def update_extension_cmd(extension_name,
                         index_url=None,
                         pip_extra_index_urls=None,
                         pip_proxy=None):
    return update_extension(extension_name,
                            index_url=index_url,
                            pip_extra_index_urls=pip_extra_index_urls,
                            pip_proxy=pip_proxy)
Пример #13
0
    def test_update_extension_verify_no_pip_proxy(self):
        add_extension(source=MY_EXT_SOURCE)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
        newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
        computed_extension_sha256 = _compute_file_hash(newer_extension)

        with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(MY_EXT_SOURCE, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.shutil'), \
                mock.patch('azure.cli.core.extension.operations.is_valid_sha256sum', return_value=(True, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.extension_exists', return_value=None), \
                mock.patch('azure.cli.core.extension.operations.check_output') as check_output:

            update_extension(MY_EXT_NAME)
            args = check_output.call_args
            pip_cmd = args[0][0]
            if '--proxy' in pip_cmd:
                raise AssertionError("proxy parameter in check_output args although no proxy specified")
    def test_update_extension_verify_no_pip_proxy(self):
        add_extension(cmd=self.cmd, source=MY_EXT_SOURCE)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
        newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
        computed_extension_sha256 = _compute_file_hash(newer_extension)

        with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(MY_EXT_SOURCE, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.shutil'), \
                mock.patch('azure.cli.core.extension.operations.is_valid_sha256sum', return_value=(True, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.extension_exists', return_value=None), \
                mock.patch('azure.cli.core.extension.operations.check_output') as check_output:

            update_extension(self.cmd, MY_EXT_NAME)
            args = check_output.call_args
            pip_cmd = args[0][0]
            if '--proxy' in pip_cmd:
                raise AssertionError("proxy parameter in check_output args although no proxy specified")
Пример #15
0
def start_shell(cmd, update=None, style=None):
    from importlib import import_module
    try:
        get_extension(INTERACTIVE_EXTENSION_NAME)
        if update:
            logger.warning(
                "Updating the Interactive extension to the latest available..")
            update_extension(INTERACTIVE_EXTENSION_NAME)
            reload_extension(INTERACTIVE_EXTENSION_NAME)
    except ExtensionNotInstalledException:
        logger.warning("Installing the Interactive extension..")
        add_extension(extension_name=INTERACTIVE_EXTENSION_NAME)

    add_extension_to_path(INTERACTIVE_EXTENSION_NAME)
    interactive_module = get_extension_modname(
        ext_name=INTERACTIVE_EXTENSION_NAME)
    azext_interactive = import_module(interactive_module)
    azext_interactive.start_shell(cmd, style=style)
Пример #16
0
def update_extension_cmd(cmd,
                         extension_name,
                         index_url=None,
                         pip_extra_index_urls=None,
                         pip_proxy=None):
    return update_extension(cli_ctx=cmd.cli_ctx,
                            extension_name=extension_name,
                            index_url=index_url,
                            pip_extra_index_urls=pip_extra_index_urls,
                            pip_proxy=pip_proxy)
Пример #17
0
    def test_update_extension_with_pip_proxy(self):
        add_extension(source=MY_EXT_SOURCE)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
        newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
        computed_extension_sha256 = _compute_file_hash(newer_extension)

        proxy_param = '--proxy'
        proxy_endpoint = "https://*****:*****@proxy.microsoft.com"
        with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(MY_EXT_SOURCE, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.shutil'), \
                mock.patch('azure.cli.core.extension.operations.is_valid_sha256sum', return_value=(True, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.extension_exists', return_value=None), \
                mock.patch('azure.cli.core.extension.operations.check_output') as check_output:

            update_extension(MY_EXT_NAME, pip_proxy=proxy_endpoint)
            args = check_output.call_args
            pip_cmd = args[0][0]
            proxy_index = pip_cmd.index(proxy_param)
            assert pip_cmd[proxy_index + 1] == proxy_endpoint
    def test_update_extension_with_pip_proxy(self):
        add_extension(cmd=self.cmd, source=MY_EXT_SOURCE)
        ext = show_extension(MY_EXT_NAME)
        self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev')
        newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl')
        computed_extension_sha256 = _compute_file_hash(newer_extension)

        proxy_param = '--proxy'
        proxy_endpoint = "https://*****:*****@proxy.microsoft.com"
        with mock.patch('azure.cli.core.extension.operations.resolve_from_index', return_value=(MY_EXT_SOURCE, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.shutil'), \
                mock.patch('azure.cli.core.extension.operations.is_valid_sha256sum', return_value=(True, computed_extension_sha256)), \
                mock.patch('azure.cli.core.extension.operations.extension_exists', return_value=None), \
                mock.patch('azure.cli.core.extension.operations.check_output') as check_output:

            update_extension(self.cmd, MY_EXT_NAME, pip_proxy=proxy_endpoint)
            args = check_output.call_args
            pip_cmd = args[0][0]
            proxy_index = pip_cmd.index(proxy_param)
            assert pip_cmd[proxy_index + 1] == proxy_endpoint
Пример #19
0
def teamcloud_update(cmd, version=None, prerelease=False):
    from azure.cli.core.extension.operations import update_extension
    from ._deploy_utils import get_github_release

    release = get_github_release('TeamCloud',
                                 version=version,
                                 prerelease=prerelease)

    index = next((a for a in release['assets']
                  if 'index.json' in a['browser_download_url']), None)

    index_url = index['browser_download_url'] if index else None

    if not index_url:
        raise CLIError(
            f"Could not find index.json asset on release {release['tag_name']}. "
            'Specify a specific prerelease version with --version '
            'or use latest prerelease with --pre')

    update_extension(cmd, extension_name='tc', index_url=index_url)
 def test_update_extension_not_found(self):
     with self.assertRaises(CLIError) as err:
         update_extension(self.cmd, MY_EXT_NAME)
     self.assertEqual(str(err.exception), 'The extension {} is not installed.'.format(MY_EXT_NAME))
Пример #21
0
def update_extension_cmd(extension_name, index_url=None, pip_extra_index_urls=None, pip_proxy=None):
    return update_extension(extension_name, index_url=index_url, pip_extra_index_urls=pip_extra_index_urls,
                            pip_proxy=pip_proxy)
 def test_update_extension_not_found(self):
     with self.assertRaises(CLIError) as err:
         update_extension(self.cmd, MY_EXT_NAME)
     self.assertEqual(
         str(err.exception),
         'The extension {} is not installed.'.format(MY_EXT_NAME))