'Test SIGHUP picks up new config values'

@unittest.skipIf(six.PY3, 'SSL    handshakes    are    broken    in    PY3')
def test_reload(self):

    def check_pids(pre, post=None, workers=2):
        if (post is None):
            if (len(pre) == workers):
                return True
            else:
                return False
        if (len(post) == workers):
            if (post.intersection(pre) == set()):
                return True
        return False
    self.api_server.fork_socket = False
    self.registry_server.fork_socket = False
    self.start_servers(fork_socket=False, **vars(self))
    pre_pids = {}
    post_pids = {}
    msg = 'Start    timeout'
    for _ in self.ticker(msg):
        for server in ('api', 'registry'):
            pre_pids[server] = self._get_children(server)
        if check_pids(pre_pids['api'], workers=1):
            if check_pids(pre_pids['registry'], workers=1):
                break
    for server in ('api', 'registry'):
        set_config_value(self._conffile(server), 'workers', '2')
        cmd = ('kill    -HUP    %s' % self._get_parent(server))
        execute(cmd, raise_error=True)
    msg = 'Worker    change    timeout'
    for _ in self.ticker(msg):
        for server in ('api', 'registry'):
            post_pids[server] = self._get_children(server)
        if check_pids(pre_pids['registry'], post_pids['registry']):
            if check_pids(pre_pids['api'], post_pids['api']):
                break
    path = self._url('http', '/')
    response = requests.get(path)
    self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
    del response
    pre_pids['api'] = self._get_children('api')
    key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
    set_config_value(self._conffile('api'), 'key_file', key_file)
    cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
    set_config_value(self._conffile('api'), 'cert_file', cert_file)
    cmd = ('kill    -HUP    %s' % self._get_parent('api'))
    execute(cmd, raise_error=True)
    msg = 'http    to    https    timeout'
    for _ in self.ticker(msg):
        post_pids['api'] = self._get_children('api')
        if check_pids(pre_pids['api'], post_pids['api']):
            break
    ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
    path = self._url('https', '/')
    response = requests.get(path, verify=ca_file)
    self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
    del response
    pre_pids['api'] = self._get_children('api')
    cmd = ('kill    -HUP    %s' % self._get_parent('api'))
    execute(cmd, raise_error=True)
    msg = 'https    restart    timeout'
    for _ in self.ticker(msg):
        post_pids['api'] = self._get_children('api')
        if check_pids(pre_pids['api'], post_pids['api']):
            break
    ca_file = os.path.join(TEST_VAR_DIR, 'ca.crt')
    path = self._url('https', '/')
    response = requests.get(path, verify=ca_file)
    self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
    del response
    pre_pids['api'] = self._get_children('api')
    set_config_value(self._conffile('api'), 'bind_host', '127.0.0.1')
    cmd = ('kill    -HUP    %s' % self._get_parent('api'))
    execute(cmd, raise_error=True)
    msg = 'https    bind_host    timeout'
    for _ in self.ticker(msg):
        post_pids['api'] = self._get_children('api')
        if check_pids(pre_pids['api'], post_pids['api']):
            break
    path = self._url('https', '/')
    response = requests.get(path, verify=ca_file)
    self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
    del response
    pre_pids['api'] = self._get_children('api')
    set_config_value(self._conffile('api'), 'key_file', '')
    set_config_value(self._conffile('api'), 'cert_file', '')
    cmd = ('kill    -HUP    %s' % self._get_parent('api'))
    execute(cmd, raise_error=True)
    msg = 'https    to    http    timeout'
    for _ in self.ticker(msg):
        post_pids['api'] = self._get_children('api')
        if check_pids(pre_pids['api'], post_pids['api']):
            break
    path = self._url('http', '/')
    response = requests.get(path)
    self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
    del response
    pre_pids['api'] = self._get_children('api')
    set_config_value(self._conffile('api'), 'bind_host', '127.0.0.1')
    cmd = ('kill    -HUP    %s' % self._get_parent('api'))
    execute(cmd, raise_error=True)
    msg = 'http    bind_host    timeout'
    for _ in self.ticker(msg):
        post_pids['api'] = self._get_children('api')
        if check_pids(pre_pids['api'], post_pids['api']):
            break
    path = self._url('http', '/')
    response = requests.get(path)
    self.assertEqual(http.MULTIPLE_CHOICES, response.status_code)
    del response
    conf_dir = os.path.join(self.test_dir, 'etc')
    log_file = (conf_dir + 'new.log')
    self.assertFalse(os.path.exists(log_file))
    set_config_value(self._conffile('api'), 'log_file', log_file)
    cmd = ('kill    -HUP    %s' % self._get_parent('api'))
    execute(cmd, raise_error=True)
    msg = 'No    new    log    file    created'
    for _ in self.ticker(msg):
        if os.path.exists(log_file):
            break
