File: tls_server_setup.py

package info (click to toggle)
aws-crt-python 0.28.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,428 kB
  • sloc: ansic: 437,955; python: 27,657; makefile: 5,855; sh: 4,289; ruby: 208; java: 82; perl: 73; cpp: 25; xml: 11
file content (43 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
Setup local TLS server for tests
"""

import Builder

import os
import sys
import subprocess
import atexit
import time


class TlsServerSetup(Builder.Action):
    """
    Set up this machine for running the mock server test

    This action should be run in the 'pre_build_steps' or 'build_steps' stage.
    """

    def run(self, env):
        if not env.project.needs_tests(env):
            print("Skipping TLS server setup because tests disabled for project")
            return

        self.env = env

        base_dir = os.path.dirname(os.path.realpath(__file__))
        dir = os.path.join(base_dir, "..", "..", "tests", "tls_server")

        print("Running openssl TLS server")

        python_path = sys.executable
        p = subprocess.Popen([python_path, "tls_server.py",
                              ], cwd=dir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

        @atexit.register
        def close_tls_server():
            print("Terminating openssl TLS server")
            p.terminate()
            out, err = p.communicate()
            print("TLS server stdout:\n{}".format(out))
            print("TLS server stderr:\n{}".format(err))