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): make_program().run("fab -i identity.key expect-identity")
def may_give_Connection_init_kwarg_dicts(self, remote): remote.expect_sessions( Session("host1", user="******", cmd="nope"), Session("host2", cmd="nope"), ) with cd(support): make_program().run("fab hosts-are-init-kwargs")
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")): make_program().run("fab expect-conf-key-filename")
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): make_program().run("fab -H myhost basic-run")
def may_give_mixed_value_types(self, remote): remote.expect_sessions( Session("host1", user="******", cmd="nope"), Session("host2", cmd="nope"), ) with cd(support): make_program().run("fab hosts-are-mixed-values")
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 make_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 _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 {}" make_program().run(cmd.format(flag, file_, tasks))
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): make_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 pre_post_tasks_are_not_parameterized_across_hosts(self): with cd(support): make_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 expect(invocation, out, program=None, test="equals"): if program is None: program = make_program() program.run("fab {}".format(invocation), exit=False) output = sys.stdout.getvalue() if test == "equals": assert output == out elif test == "contains": assert out in output elif test == "regex": assert re.match(out, output) else: err = "Don't know how to expect that <stdout> {} <expected>!" assert False, err.format(test)
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. make_program().run("fab expect-conf-value")
def comma_separated_string_is_multiple_hosts(self, remote): remote.expect_sessions(Session("host1", cmd="nope"), Session("host2", cmd="nope")) with cd(support): make_program().run("fab -H host1,host2 basic-run")
def cli_identity_still_overrides_when_non_empty(self): with cd(os.path.join(support, "yml_conf")): make_program().run("fab -i cli.key expect-cli-key-filename")
def may_be_given_multiple_times(self): with cd(support): make_program().run( "fab -i identity.key -i identity2.key expect-identities")
def multiple_hosts_works_with_remainder_too(self, remote): remote.expect_sessions(Session("host1", cmd="whoami"), Session("host2", cmd="whoami")) make_program().run("fab -H host1,host2 -- whoami")
def multiple_strings_is_multiple_host_args(self, remote): remote.expect_sessions(Session("host1", cmd="nope"), Session("host2", cmd="nope")) with cd(support): make_program().run("fab two-hosts")
def double_dash_identity_also_works(self): with cd(support): make_program().run( "fab --identity identity.key expect-identity")
def generates_exception_if_combined_with_remainder(self): make_program().run("fab -- nope")
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): make_program().run("fab mutate expect-mutation")
def double_dash_connect_timeout_also_works(self): with cd(support): make_program().run( "fab --connect-timeout 5 expect-connect-timeout")
def vanilla_Invoke_task_works_too(self): with cd(support): make_program().run("fab vanilla-Task-works-ok")
if __name__ == '__main__': import sys from fabric.main import make_program path = sys.argv[:1] args = ' '.join(sys.argv[-5:]) make_program().run(args)
def config_mutation_not_preserved(self): with cd(support): make_program().run( "fab -H host1,host2 expect-mutation-to-fail")
def host_string_shorthand_works_ok(self, remote): remote.expect(host="host1", port=1234, user="******") with cd(support): make_program().run("fab hosts-are-host-stringlike")
def executes_remainder_as_anonymous_task(self, remote): remote.expect(host="myhost", cmd="whoami") make_program().run("fab -H myhost -- whoami", exit=False)
def host_string_shorthand_is_passed_through(self, remote): remote.expect(host="host1", port=1234, user="******") make_program().run("fab -H someuser@host1:1234 -- whoami")
def uses_FABRIC_env_prefix(self, environ): environ["FABRIC_RUN_ECHO"] = "1" with cd(support): make_program().run("fab expect-from-env")
def single_string_is_single_exec(self, remote): remote.expect(host="myhost", cmd="nope") with cd(support): make_program().run("fab hosts-are-myhost")
def calls_task_once_with_invoke_context(self): with cd(support): make_program().run("fab expect-vanilla-Context")
def dash_t_supplies_default_connect_timeout(self): with cd(support): make_program().run("fab -t 5 expect-connect-timeout")