Example #1
0
def test_step_context_overload(mocker):
    class NoopStep(Step):
        def run(self, another=None):
            pass

    # Waiting step context
    noop_step = NoopStep(another="context1")
    spy = mocker.spy(noop_step, 'run')
    noop_step.run_with_context(Host("local", add="context"))
    spy.assert_called_once_with(another='context1')

    # Waiting no context
    noop_step = NoopStep()
    spy = mocker.spy(noop_step, 'run')
    noop_step.run_with_context(Host("local", add="context"))
    spy.assert_called_once_with()

    # Waiting host context
    noop_step = NoopStep()
    spy = mocker.spy(noop_step, 'run')
    noop_step.run_with_context(Host("local", another="host_context"))
    spy.assert_called_once_with(another="host_context")

    # Waiting step and host context, step context overloading step context
    noop_step = NoopStep(another="context1")
    spy = mocker.spy(noop_step, 'run')
    noop_step.run_with_context(Host("local", another="host_context"))
    spy.assert_called_once_with(another="context1")
Example #2
0
 def run(self):
     self.step(noop_step, Host("local"))
     self.step([
         noop_step,
     ], [
         Host("local"),
     ])
Example #3
0
 class DryTask(SimpleTask):
     hosts = [
         Host("local"),
     ]
     steps = [
         noop_step,
     ]
Example #4
0
def test_global_context():
    h = Host("local")
    assert global_context.host is None
    assert global_context.conn is None

    with global_context.SetContext(h):
        assert global_context.host == h
        assert global_context.conn is not None
        assert isinstance(global_context.conn, Context)

    assert global_context.host is None
    assert global_context.conn is None
Example #5
0
 def run(self):
     self.step(noop_step, Host("local"))
Example #6
0
def centos_ssh_host():
    return Host("127.0.0.1",
                ssh_user="******",
                ssh_password="******",
                ssh_port=22223)
Example #7
0
def ubuntu_ssh_host():
    return Host("127.0.0.1",
                ssh_user="******",
                ssh_password="******",
                ssh_port=22222)
Example #8
0
def local_host():
    return Host("local")
Example #9
0
def test_step_abc(mocker):
    spy = mocker.spy(Step, 'run')
    with pytest.raises(NotImplementedError):
        Step(another="context1").run_with_context(Host("local", add="context"))

    spy.assert_called_once()
Example #10
0
def test_log(capsys):
    with global_context.SetContext(Host("local")):
        utils.log("Hellotest")

        captured = capsys.readouterr()
        assert captured.out == "💃💃💃 local> Hellotest\n"
Example #11
0
def test_host_create():
    assert Host("[email protected]:22").host == "1.2.3.4"
    assert Host("1.2.3.4:22").host == "1.2.3.4"
    assert Host("1.2.3.4").host == "1.2.3.4"
    assert Host("abc.example:22").host == "abc.example"
    assert Host("[email protected]:22").host == "abc.example"

    assert Host("local").is_connection_local() is True
    assert Host("localhost").is_connection_local() is True
    assert Host("user@localhost").is_connection_local() is True

    assert Host("1.2.3.4").is_connection_local() is False
    assert Host("[email protected]").is_connection_local() is False
    assert Host("*****@*****.**").is_connection_local() is False
Example #12
0
def test_host_hash():
    h1 = Host("1.2.3.4")
    h2 = Host("1.2.3.4")

    assert h1.__hash__() == h2.__hash__()