def may_give_Connection_init_kwarg_dicts(self, remote): remote.expect_sessions( Session("host1", user="******", cmd="nope"), Session("host2", cmd="nope"), ) with cd(support): program.run("fab hosts-are-init-kwargs")
def dash_i_supplies_default_connect_kwarg_key_filename(self): # NOTE: the expect-identity task in tests/_support/fabfile.py # performs asserts about its context's .connect_kwargs value, # relying on other tests to prove connect_kwargs makes its way into # that context. with cd(support): program.run("fab -i identity.key expect-identity")
def single_string_is_single_host_and_single_exec(self, remote): remote.expect(host="myhost", cmd="nope") # In addition to just testing a base case, this checks for a really # dumb bug where one appends to, instead of replacing, the task # list during parameterization/expansion XD with cd(support): program.run("fab -H myhost basic-run")
def key_filename_can_be_set_via_non_override_config_levels(self): # Proves/protects against #1762, where eg key_filenames gets # 'reset' to an empty list. Arbitrarily uses the 'yml' level of # test fixtures, which has a fabric.yml w/ a # connect_kwargs.key_filename value of [private.key, other.key]. with cd(os.path.join(support, "yml_conf")): program.run("fab expect-conf-key-filename")
def may_give_mixed_value_types(self, remote): remote.expect_sessions( Session("host1", user="******", cmd="nope"), Session("host2", cmd="nope"), ) with cd(support): program.run("fab hosts-are-mixed-values")
def main(): sys.argv = [ 'fab', '-r', str(Path(__file__).parent), '-F', 'nested', '--echo' ] + sys.argv[1:] if len(sys.argv) == 6: sys.argv += ['--list'] program.run()
def _expect_prompt(self, getpass, flag, key, value, prompt): getpass.return_value = value with cd(support): # Expect that the given key was found in the context. cmd = "fab -c prompting {} expect-connect-kwarg --key {} --val {}" # noqa program.run(cmd.format(flag, key, value)) # Then we also expect that getpass was called w/ expected prompt getpass.assert_called_once_with(prompt)
def complete_flag_does_not_trigger_remainder_only_behavior(self): # When bug present, 'fab --complete -- fab' fails to load any # collections because it thinks it's in remainder-only, # work-without-a-collection mode. with cd(support): program.run("fab --complete -- fab", exit=False) # Cherry-picked sanity checks looking for tasks from fixture # fabfile output = sys.stdout.getvalue() for name in ("build", "deploy", "expect-from-env"): assert name in output
def _run( self, flag="-S", file_="ssh_config/runtime.conf", tasks="runtime-ssh-config", ): with cd(support): # Relies on asserts within the task, which will bubble up as # it's executed in-process cmd = "fab -c runtime_fabfile {} {} -H runtime {}" program.run(cmd.format(flag, file_, tasks))
def pre_post_tasks_are_not_parameterized_across_hosts(self): with cd(support): program.run("fab -H hostA,hostB,hostC second --show-host") output = sys.stdout.getvalue() # Expect pre once, 3x main, post once, as opposed to e.g. both # pre and main task expected = """ First! Second: hostA Second: hostB Second: hostC Third! """.lstrip() assert output == expected
def double_dash_identity_also_works(self): with cd(support): program.run("fab --identity identity.key expect-identity")
def loads_fabric_config_files_not_invoke_ones(self): for type_ in ("yaml", "yml", "json", "py"): with cd(os.path.join(support, "{}_conf".format(type_))): # This task, in each subdir, expects data present in a # fabric.<ext> nearby to show up in the config. program.run("fab expect-conf-value")
def invokelike_multitask_invocation_preserves_config_mutation(self): # Mostly a guard against Executor subclass tweaks breaking Invoke # behavior added in pyinvoke/invoke#309 with cd(support): program.run("fab mutate expect-mutation")
def multiple_hosts_works_with_remainder_too(self, remote): remote.expect_sessions( Session("host1", cmd="whoami"), Session("host2", cmd="whoami") ) program.run("fab -H host1,host2 -- whoami")
def uses_FABRIC_env_prefix(self, environ): environ["FABRIC_RUN_ECHO"] = "1" with cd(support): program.run("fab expect-from-env")
def main(): """Entry point.""" os.chdir(os.path.dirname(__file__)) logging.config.fileConfig("logging.ini") program.run()
def host_string_shorthand_works_ok(self, remote): remote.expect(host="host1", port=1234, user="******") with cd(support): program.run("fab hosts-are-host-stringlike")
def multiple_strings_is_multiple_host_args(self, remote): remote.expect_sessions( Session("host1", cmd="nope"), Session("host2", cmd="nope") ) with cd(support): program.run("fab two-hosts")
def single_string_is_single_exec(self, remote): remote.expect(host="myhost", cmd="nope") with cd(support): program.run("fab hosts-are-myhost")
def config_mutation_not_preserved(self): with cd(support): program.run("fab -H host1,host2 expect-mutation-to-fail")
def host_string_shorthand_is_passed_through(self, remote): remote.expect(host="host1", port=1234, user="******") program.run("fab -H someuser@host1:1234 -- whoami")
def may_be_given_multiple_times(self): with cd(support): program.run( "fab -i identity.key -i identity2.key expect-identities" )
def _run_fab(argstr, **kwargs): cmd = "fab -f {} {}".format(config_file, argstr) return fab_program.run(cmd, **kwargs)
def calls_task_once_with_invoke_context(self): with cd(support): program.run("fab expect-vanilla-Context")
def cli_identity_still_overrides_when_non_empty(self): with cd(os.path.join(support, "yml_conf")): program.run("fab -i cli.key expect-cli-key-filename")
def vanilla_Invoke_task_works_too(self): with cd(support): program.run("fab vanilla-Task-works-ok")
def executes_remainder_as_anonymous_task(self, remote): remote.expect(host="myhost", cmd="whoami") program.run("fab -H myhost -- whoami", exit=False)
def generates_exception_if_combined_with_remainder(self): program.run("fab -- nope")
def comma_separated_string_is_multiple_hosts(self, remote): remote.expect_sessions( Session("host1", cmd="nope"), Session("host2", cmd="nope") ) with cd(support): program.run("fab -H host1,host2 basic-run")