Ejemplo n.º 1
0
 def test_undeploy_none_occur_stop(self):
     # invalid parameter
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     self.assertFalse(
         undeploycron_between("* * * * * echo Good > "
                              "/tmp/buffer", "* * * * * echo day > "
                              "/tmp/buffer", 1, None))
Ejemplo n.º 2
0
 def test_deploy_content(self):
     # specify content
     deploycron(content="* * * * * echo hello > /tmp/buffer")
     subprocess.call(["crontab -l > /tmp/test_crontab"], shell=True)
     with open("/tmp/test_crontab") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_crontab"], shell=True)
     self.assertEqual(file_content, "* * * * * echo hello > /tmp/buffer\n")
Ejemplo n.º 3
0
 def test_deploy_duplicates(self):
     # duplicates are not added
     deploycron(content="* * * * * echo greetings > /tmp/buffer")
     deploycron(content="* * * * * echo greetings > /tmp/buffer")
     subprocess.call(["crontab -l > /tmp/test_crontab"], shell=True)
     with open("/tmp/test_crontab") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_crontab"], shell=True)
     self.assertEqual(file_content, "* * * * * echo greetings > "
                      "/tmp/buffer\n")
Ejemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("filepath",
                        help="Complete file path of the cron to deploy")
    args = parser.parse_args()
    filepath = args.filepath
    if not os.path.isfile(filepath):
        print("ERROR: filepath [%s] is not a file" % filepath, file=sys.stderr)
        sys.exit(1)
    deploycron.deploycron(filename=filepath)
Ejemplo n.º 5
0
 def test_deploy_override(self):
     # override existing crontab
     deploycron(content="* * * * * echo hello > /tmp/buffer")
     deploycron(content="* * * * * echo greetings > /tmp/buffer",
                override=True)
     subprocess.call(["crontab -l > /tmp/test_crontab"], shell=True)
     with open("/tmp/test_crontab") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_crontab"], shell=True)
     self.assertEqual(file_content, "* * * * * echo greetings > "
                      "/tmp/buffer\n")
Ejemplo n.º 6
0
 def test_undeploy_2_occur_stop_error(self):
     # stop_line occurence not found
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     self.assertFalse(
         undeploycron_between("* * * * * echo Good > "
                              "/tmp/buffer", "* * * * * echo mate > "
                              "/tmp/buffer", 1, 2))
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
Ejemplo n.º 7
0
 def test_undeploy_stop_not_found(self):
     # stop_line is not found
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo day > /tmp/buffer",
                          "* * * * * echo not_found > /tmp/buffer")
     result = subprocess.call(["crontab -l > /tmp/test_undeploy"],
                              shell=True)
     self.assertFalse(result)
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
Ejemplo n.º 8
0
 def test_deploy_filename(self):
     # specify a filename with content
     subprocess.call([
         "echo '* * * * * echo file > /tmp/buffer' > "
         "/tmp/youcrontab.tab"
     ],
                     shell=True)
     deploycron(filename="/tmp/youcrontab.tab")
     subprocess.call(["crontab -l > /tmp/test_filename"], shell=True)
     with open("/tmp/test_filename") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/youcrontab.tab"], shell=True)
     subprocess.call(["rm /tmp/test_filename"], shell=True)
     self.assertEqual(file_content, "* * * * * echo file > /tmp/buffer\n")
Ejemplo n.º 9
0
 def test_undeploy_inverted_indices(self):
     # stop_line is before start_line in the parameters
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo mate > /tmp/buffer",
                          "* * * * * echo day > /tmp/buffer")
     subprocess.call(["crontab -l > /tmp/test_undeploy"], shell=True)
     with open("/tmp/test_undeploy") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
     self.assertEqual(file_content, "* * * * * echo Good > /tmp/buffer\n")
Ejemplo n.º 10
0
 def test_undeploy(self):
     # remove cron instructions
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo day > /tmp/buffer",
                          "* * * * * echo mate > /tmp/buffer")
     subprocess.call(["crontab -l > /tmp/test_undeploy"], shell=True)
     with open("/tmp/test_undeploy") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
     self.assertEqual(file_content, "* * * * * echo Good > /tmp/buffer\n")
Ejemplo n.º 11
0
 def test_undeploy_2_occur_stop(self):
     # remove where there are multiple occurences of stop_line
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron_duplicates(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     undeploycron_between("* * * * * echo Good > /tmp/buffer",
                          "* * * * * echo you > /tmp/buffer", 1, 2)
     subprocess.call(["crontab -l > /tmp/test_undeploy"], shell=True)
     with open("/tmp/test_undeploy") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_undeploy"], shell=True)
     self.assertEqual(file_content, "* * * * * echo mate > /tmp/buffer\n")
Ejemplo n.º 12
0
 def test_undeploy_argparse(self):
     deploycron(content="* * * * * echo Good > /tmp/buffer")
     deploycron(content="* * * * * echo day > /tmp/buffer")
     deploycron(content="* * * * * echo to > /tmp/buffer")
     deploycron(content="* * * * * echo you > /tmp/buffer")
     deploycron(content="* * * * * echo mate > /tmp/buffer")
     subprocess.call([
         "python ../deploycron/cli_undeploycron_between.py "
         "'* * * * * echo day > /tmp/buffer' "
         "'* * * * * echo mate > /tmp/buffer'"
     ],
                     shell=True)
     subprocess.call(["crontab -l > /tmp/test_undeploy_argparse"],
                     shell=True)
     with open("/tmp/test_undeploy_argparse") as f:
         file_content = f.read()
     subprocess.call(["rm /tmp/test_undeploy_argparse"], shell=True)
     self.assertEqual(file_content, "* * * * * echo Good > /tmp/buffer\n")
Ejemplo n.º 13
0
 def test_deploy_filename_error(self):
     # file doesn't exist
     with self.assertRaises(Exception):
         deploycron(filename="/tmp/idonotexist.tab")
Ejemplo n.º 14
0
 def test_deploy_none(self):
     # Nothing specified
     with self.assertRaises(ValueError):
         deploycron()
Ejemplo n.º 15
0
    print("ERROR : %s"%(error_))
    logging.error("ERROR : %s"%(error_))
    send_mail(error_)
    sys.exit()
else:
  try:
    del_path = take_backup(db,collection,compression,backup_path,retention=retention,backup_type=backup_type,feildnames=feildnames,client_name=client_name,logfile=logfile)
    delete_path = ''
    del_path = del_path.split('/')
    del_path.pop(0)
    del_path.pop(-1)
    for i in del_path:
      del_path = '/' + i
      delete_path = delete_path + del_path
    delete_path_list = os.listdir(delete_path)
    dep_path = os.path.join(os.getcwd(),'take_backup.py')
    deploycron(content='0 0 * * * python {} -f {}'.format(dep_path,jc_file))
    if len(delete_path_list) > retention:
      rm_path = delete_path+'/'+delete_path_list[0]
      print("removed : " + rm_path)
      shutil.rmtree(rm_path)
    #print(delete_path)
  except:
    error_ = commands.getoutput('grep Failed temp')
    error_ = error_ + "\nBackup failed"
    print("ERROR : %s"%(error_))
    logging.error("ERROR : %s"%(error_))
    send_mail(error_)
    sys.exit()