def invoke_command(command, **args): num_tries = 0 while num_tries < NUM_INVOKE_COMMAND_RETRIES: command_output = runner().invoke(oci_cli.cli, [ '--config-file', os.environ['OCI_CLI_CONFIG_FILE'], '--profile', pytest.config.getoption("--config-profile") ] + command, **args) if command_output.exception: output_to_test = str(command_output.exception) else: output_to_test = command_output.output if should_retry(output_to_test): num_tries += 1 if num_tries >= NUM_INVOKE_COMMAND_RETRIES: return command_output else: time.sleep(2**num_tries) # Backoff time.sleep(random.random() * 2) # Jitter else: return command_output return command_output
def invoke_command_with_overrides(command, profile_override, **args): num_tries = 0 if profile_override != '': command = ['--profile', profile_override] + command while num_tries < NUM_INVOKE_COMMAND_RETRIES: command_output = runner().invoke(oci_cli.cli, command, **args) if command_output.exception: output_to_test = str(command_output.exception) else: output_to_test = command_output.output if should_retry(output_to_test): num_tries += 1 if num_tries >= NUM_INVOKE_COMMAND_RETRIES: return command_output else: time.sleep(2**num_tries) # Backoff time.sleep(random.random() * 2) # Jitter else: return command_output return command_output
def invoke_command_as_admin(command, **args): num_tries = 0 while num_tries < NUM_INVOKE_COMMAND_RETRIES: command_output = runner().invoke(oci_cli.cli, [ '--config-file', os.environ['OCI_CLI_CONFIG_FILE'], '--profile', 'ADMIN' ] + command, **args) if command_output.exception: output_to_test = str(command_output.exception) else: output_to_test = command_output.output if should_retry(output_to_test): num_tries += 1 if num_tries >= NUM_INVOKE_COMMAND_RETRIES: return command_output else: time.sleep(2**num_tries) # Backoff time.sleep(random.random() * 2) # Jitter else: return command_output # Always return some sort of output so that the test can handle it (or try and do something). Retries are # a bit strange here because we don't get exceptions (as such) but they are instead dumped out into the # terminal return command_output
def setUp(self): self.runner = runner() inline_help_dir = 'tests/output/inline-help/' for help_file in os.listdir(inline_help_dir): file_path = os.path.join(inline_help_dir, help_file) try: if os.path.isfile(file_path): os.unlink(file_path) except Exception as e: print(e)
def invoke_command_with_auth(command, ** args): num_tries = 0 while num_tries < NUM_INVOKE_COMMAND_RETRIES: command_output = runner().invoke(oci_cli.cli, ['--auth', os.environ['OCI_CLI_AUTH']] + command, **args) if command_output.exception: output_to_test = str(command_output.exception) else: output_to_test = command_output.output if should_retry(output_to_test): num_tries += 1 if num_tries >= NUM_INVOKE_COMMAND_RETRIES: return command_output else: time.sleep(2 ** num_tries) # Backoff time.sleep(random.random() * 2) # Jitter else: return command_output return command_output
def setUp(self): self.runner = runner()
def setUp(self): util.unset_admin_pass_phrase() self.runner = runner()
Cannot move default item Selected: /conditions => {'foo': {...}, 'custom': {...}, ...} """).strip() cmd_select("default") assert cmd_update("custom", arrange=True) == dedent(""" Problem swapping /conditions/default and 'custom': Cannot move default item Selected: /conditions => {'foo': {...}, 'custom': {...}, ...} """).strip() cmd_select("custom") assert cmd_update("default", arrange=True) == dedent(""" Problem swapping /conditions/custom and 'default': Cannot move default item Selected: /conditions => {'foo': {...}, 'custom': {...}, ...} """).strip() if __name__ == "__main__": from conftest import runner # name, func, fixtures, gen_fixtures tests = [ (test_OnModCommand, (), (signal_stub, )), (test_cmd_debug_args, (), (signal_stub, )), (test_cmd_select, (), (signal_stub, )), (test_cmd_update, (), (signal_stub, )), ] runner(tests, locals())
# Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved. # This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license. from . import util import oci_cli from conftest import runner import pytest @pytest.fixture(scope='function') def commands_list(service): commands_list = util.filter_commands_list(service) return commands_list runner = runner() def invoke_example_operation(command_list): return runner.invoke(oci_cli.cli, command_list) def validate_response(result): assert result.exit_code == 0 # Ensure that compartment-id shortcut is set. if "--compartment-id TEXT" in result.output: assert ("-c, --compartment-id" in result.output) def test_help_on_all_commands(commands_list):