Ejemplo n.º 1
0
 def check_ssh_checker(self, checkers):
     self.server.start()
     ssh_config = RemoteAccountSSHConfig.from_string("""
     Host dummy_host.com
         Hostname dummy_host.name.com
         Port 22
         User dummy
         ConnectTimeout 1
     """)
     self.account = RemoteAccount(ssh_config, ssh_exception_checks=checkers)
     with pytest.raises(DummyException):
         self.account.ssh('echo test')
Ejemplo n.º 2
0
    def check_remote_account_equality(self):
        """Different instances of remote account initialized with the same parameters should be equal."""

        ssh_config = RemoteAccountSSHConfig(host="thehost", hostname="localhost", port=22)

        kwargs = {
            "ssh_config": ssh_config,
            "externally_routable_ip": "345",
            "logger": logging.getLogger(__name__)
        }
        r1 = RemoteAccount(**kwargs)
        r2 = RemoteAccount(**kwargs)

        assert r1 == r2
Ejemplo n.º 3
0
class CheckRemoteAccount(object):
    def setup(self):
        self.server = SimpleServer()
        self.account = MockAccount()

    def check_wait_for_http(self):
        """Check waiting without timeout"""
        self.server.start(delay_sec=0.0)
        self.account.wait_for_http_service(port=self.server.port,
                                           headers={},
                                           timeout=10,
                                           path="/")

    def check_wait_for_http_timeout(self):
        """Check waiting with timeout"""

        timeout = 1
        start = time.time()
        self.server.start(delay_sec=5)

        try:
            self.account.wait_for_http_service(port=self.server.port,
                                               headers={},
                                               timeout=timeout,
                                               path='/')
            raise Exception(
                "Should have timed out waiting for server to start")
        except TimeoutError:
            # expected behavior. Now check that we're reasonably close to the expected timeout
            # This is a fairly loose check since there are various internal timeouts that can affect the overall
            # timing
            actual_timeout = time.time() - start
            assert abs(actual_timeout - timeout) / timeout < 1

    @pytest.mark.parametrize(
        "checkers",
        [[raise_error_checker], [raise_no_error_checker, raise_error_checker],
         [raise_error_checker, raise_no_error_checker]])
    def check_ssh_checker(self, checkers):
        self.server.start()
        ssh_config = RemoteAccountSSHConfig.from_string("""
        Host dummy_host.com
            Hostname dummy_host.name.com
            Port 22
            User dummy
            ConnectTimeout 1
        """)
        self.account = RemoteAccount(ssh_config, ssh_exception_checks=checkers)
        with pytest.raises(DummyException):
            self.account.ssh('echo test')

    def teardown(self):
        self.server.stop()
Ejemplo n.º 4
0
 def setup(self):
     self.server = SimpleServer()
     self.account = MockAccount()