예제 #1
0
    def run_entire_flow(self, milmove_env: MilMoveEnv) -> None:
        try:
            set_up_certs(env=milmove_env)

            flow_session_manager = FlowSessionManager(milmove_env, None)

            while self.run(flow_session_manager):
                pass
        finally:
            remove_certs(env=milmove_env)
예제 #2
0
    def test_no_error_if_cert_already_gone(self, tmp_path: Path):
        cert_key_pem = tmp_path / DP3_CERT_KEY_PEM_FILENAME

        assert len(list(tmp_path.iterdir())) == 0

        with mock.patch("utils.auth.DP3_CERT_KEY_PEM", cert_key_pem):
            remove_certs(env=MilMoveEnv.DP3)

            assert len(list(tmp_path.iterdir())) == 0

            assert not cert_key_pem.exists()
예제 #3
0
    def test_cert_removed_for_deployed_envs(self, tmp_path: Path):
        cert_key_pem = tmp_path / DP3_CERT_KEY_PEM_FILENAME

        cert_key_pem.touch()

        with mock.patch("utils.auth.DP3_CERT_KEY_PEM", cert_key_pem):
            remove_certs(env=MilMoveEnv.DP3)

            assert len(list(tmp_path.iterdir())) == 0

            assert not cert_key_pem.exists()
예제 #4
0
    def test_no_file_is_removed_if_running_locally(self,
                                                   tmp_path: Path) -> None:
        cert_key_pem = tmp_path / DP3_CERT_KEY_PEM_FILENAME

        cert_key_pem.touch(
        )  # creating it just so that we can test that it won't get removed

        with mock.patch("utils.auth.DP3_CERT_KEY_PEM", cert_key_pem):
            remove_certs(env=MilMoveEnv.LOCAL)

            assert len(list(tmp_path.iterdir())) == 1
            assert cert_key_pem.exists()
예제 #5
0
def on_quitting(environment: Environment, **_kwargs):
    """
    Event hook that gets run when locust is shutting down.

    We're using it to clean up certs that were created during setup.
    :param environment: locust environment.
    :param _kwargs: Other kwargs we aren't using that are passed to hook functions.
    :return: None
    """
    try:
        milmove_env = MilMoveEnv(value=environment.host)
    except ValueError as err:
        # This should in theory never happen since a similar check is done on init, but just in
        # case...
        environment.runner.quit()

        raise err

    remove_certs(env=milmove_env)