예제 #1
0
def save_certs(pathname, certs):
    try:
        if not os.path.exists(pathname):
            os.makedirs(pathname)
    except Exception as e:
        logger.error(e)
    for index, cert in enumerate(certs):
        filename = "/".join([pathname.rstrip("/"), "cert%d.pem" % index])
        save_to_file(filename, cert.replace("\\n", '\n'))
예제 #2
0
 def _update_haproxy(self, cfg):
     if self.running_mode in ["acs"]:
         if Haproxy.cls_cfg != cfg:
             logger.info("HAProxy configuration:\n%s" % cfg)
             Haproxy.cls_cfg = cfg
             if save_to_file(config.HAPROXY_CONFIG_FILE, cfg):
                 Haproxy.cls_process = UpdateHelper.run_reload(
                     Haproxy.cls_process)
         elif self.ssl_updated:
             logger.info("SSL certificates have been changed")
             Haproxy.cls_process = UpdateHelper.run_reload(
                 Haproxy.cls_process)
         else:
             logger.info("HAProxy configuration remains unchanged")
         logger.info("===========END===========")
     elif self.running_mode in ["legacy"]:
         logger.info("HAProxy configuration:\n%s" % cfg)
         if save_to_file(config.HAPROXY_CONFIG_FILE, cfg):
             UpdateHelper.run_once()
예제 #3
0
 def test_save_to_file_with_error(self):
     self.assertFalse(save_to_file("/", "something"))
예제 #4
0
 def test_save_to_file(self):
     content = str(uuid.uuid4())
     self.assertTrue(save_to_file(self.f.name, content))
     txt = open(self.f.name).read()
     self.assertEqual(content, txt)
예제 #5
0
def create_pid_file():
    pid = str(os.getpid())
    save_to_file(config.PID_FILE, pid)
    return pid