def full_test(params): admin_db.init_db() print('Starting Test; Container Name: %s' % params['dbname']) if container_util.container_exists(params['dbname']): print(' Duplicate container: KILLING') result = container_util.kill_con(params['dbname'], Config.accounts[dbtype]['admin'], Config.accounts[dbtype]['admin_pass'], params['username']) time.sleep(5) print(result) print(' removing old directories') volumes.cleanup_dirs(params['dbname']) print(' Create container') res = mongodb_util.create_mongodb(params) print(res) bck_path = Config.backup_voll + '/' + params['dbname'] print(' Test user account') if mongodb_util.auth_mongodb(params['dbuser'], params['dbuserpass'], params['port']): print(" - User exits!") else: print(" - User does not exits!") print(" - All Tests Complete! %s is up and running" % params['dbname'])
def delete_test_container(params): dbtype = params['dbtype'] result = container_util.kill_con(params['dbname'], Config.accounts[dbtype]['admin'], Config.accounts[dbtype]['admin_pass'], params['username']) print(result)
def test_create(params): admin_db.init_db() dbtype = params['dbtype'] print('Starting Test; Container Name: %s' % params['dbname']) if container_util.container_exists(params['dbname']): print(' Duplicate container: KILLING') result = container_util.kill_con(params['dbname'], Config.accounts[dbtype]['admin'], Config.accounts[dbtype]['admin_pass'], params['username']) time.sleep(5) print(result) print(' removing old directories') volumes.cleanup_dirs(params['dbname']) print(' Create container') res = neo4j_util.create(params) print(res) params['port'] = params['port_bindings'][7687][1] print(' Bolt Port: %d' % params['port']) print(' Test user account') if neo4j_util.auth_check(params['dbuser'], params['dbuserpass'], params['port']): print(" - User exits!") else: print(" - User does not exits!") status = neo4j_util.create_account('keith', 'neoTester', params['port']) if status: print(" Created test account for Keith") else: print(" Badness: unable to create account for Keith") print(" - Create Neo4j Complete!")
def delete_test_container(dbtype, con_name): print("\n=========") print(" - Removing Container") print("=========") result = container_util.kill_con(con_name, Config.accounts[dbtype]['admin'], Config.accounts[dbtype]['admin_pass']) print(result)
def full_test(params): admin_db.init_db() con_name = params['dbname'] dbtype = params['dbtype'] print('Starting %s Test; Container Name: %s' % (dbtype, con_name)) if container_util.container_exists(con_name): print(' Duplicate container: KILLING') result = container_util.kill_con(con_name, Config.accounts[dbtype]['admin'], Config.accounts[dbtype]['admin_pass'], params['username']) time.sleep(5) print(result) print(' removing old directories') volumes.cleanup_dirs(con_name) print(' Create container') result = postgres_util.create(params) print(' Create result: %s' % result) port = params['port'] # # Admin DB checking # print(' Check Admin DB log for "create"') admin_db.display_container_log(limit=1) print(' Check Admin DB for State entry') info = admin_db.get_container_state(con_name) print(' Name: %s ' % info.name), print('State: %s ' % info.state), print('TS: %s ' % info.ts), print('CID: %d' % info.c_id) print(' Check Admin DB for Container Info') info = admin_db.display_container_info(con_name) print('Info: %s' % info) print(' Postgres Show All') postgres_util.showall(params) print("\n=========") print(" - Test Accounts\n") print("=========") admin_user = Config.accounts[dbtype]['admin'] admin_pass = Config.accounts[dbtype]['admin_pass'] test_user = Config.accounts['test_user']['admin'] test_pass = Config.accounts['test_user']['admin_pass'] for dbuser, dbuserpass in [[test_user, test_pass], ['svc_' + test_user, params['longpass']], [admin_user, admin_pass]]: auth = postgres_util.auth_check(dbuser, dbuserpass, port) if auth: print('User %s verified!' % dbuser) else: print('user account not valid: %s' % dbuser) print(" - Test Complete")
def delete(): if not session['logged_in']: return redirect(url_for('login')) dbname = request.form['container_name'] dbuser = request.form['dbuser'].replace(';', '').replace('&', '').strip() dbuserpass = request.form['dbuserpass'].replace(';', '').\ replace('&', '').strip() username = session['username'] result = container_util.kill_con(dbname, dbuser, dbuserpass, username) return render_template('results.html', title='Delete Container', container_name=dbname, result=result)
def create_mongodb(params): dbtype = params['dbtype'] con_name = params['dbname'] config_dat = Config.info[dbtype] volumes = config_dat['volumes'] for vol in volumes: if vol[0] == 'DBVOL': vol[0] = params['db_vol'] if vol[0] == 'BAKVOL': vol[0] = Config.backup_vol if container_util.container_exists(con_name): return "Container name %s already in use" % (con_name) port = container_util.get_max_port() params['port'] = port Ports = {config_dat['pub_ports'][0]: (Config.container_ip, port)} params['port_bindings'] = Ports env = {'DB_USER': params['dbuser']} # create container without Auth enabled container_util.make_dirs(con_name, volumes) (c_id, con) = container_util.create_con(params, env, config_dat['command']) print("DEBUG: noauth MongoDB created. Sleeping while it starts.\n") time.sleep(4) mongodb_create_account(params) print("DEBUG: stop and remove container") root = Config.accounts[params['dbtype']]['admin'] password = Config.accounts[params['dbtype']]['admin_pass'] result = container_util.kill_con(params['dbname'], root, password, params['username']) print("DEBUG: mongodb_util kill: %s" % result) admin_db.delete_container(c_id) # we don't duplicate container data print('Sleeping a bit before recreating mongo') time.sleep(4) print("DEBUG: Start with Auth") (c_id, con) = container_util.create_con(params, env, '--auth') print("DEBUG: MongoDB with --auth created: %s." % con['Id']) res = "Your MongoDB container has been created; %s\n\n" % con_name res += 'Mongo URI: "mongodb://%s:%s@%s:%s"' % ( params['dbuser'], params['dbuserpass'], Config.container_host, port) message = 'MongoDB created\n' message += res send_mail("DB4SCI: created MongoDB", message) return res
def delete_con(params): result = container_util.kill_con( params['dbname'], Config.accounts['test_user']['admin'], Config.accounts['test_user']['admin_pass'], params['username']) print(result)
def test_delete(dbtype, dbname): result = container_util.kill_con(dbname, Config.accounts[dbtype]['admin'], Config.accounts[dbtype]['admin_pass']) print(result)