def fill_servers_history(step): db = dbmanager.DB(lib.world.config['connections']['mysql']) for record in step.hashes: record['server_id'] = record.get('server_id', "'%s'" % lib.generate_server_id()) server = lib.world.servers.get(record['server_id'], {}) record['cloud_server_id'] = record['cloud_server_id'] record['farm_id'] = record.get('farm_id') or server.get('farm_id') or lib.generate_id() record['farm_roleid'] = record.get('farm_roleid') or server.get('farm_roleid') or lib.generate_id() record['client_id'] = record.get('client_id') or server.get('client_id') or lib.generate_id() record['env_id'] = record.get('env_id') or server.get('env_id') or lib.generate_id() record['platform'] = record.get('platform') or server.get('platform') or random.choice( ["'ec2'", "'gce'", "'idcf'", "'openstack'"]) record['cloud_location'] = record.get('cloud_location') or server.get('cloud_location') or "'us-east-1'" record['instance_type_name'] = record.get('instance_type_name') or server.get('instance_type_name') or 'NULL' record['type'] = record.get('type') or server.get('type') or 'NULL' record['server_index'] = record.get('server_index') or server.get('index') or 1 record['role_id'] = record.get('role_id') or lib.generate_id() record['project_id'] = uuid.UUID(strip(record.get('project_id', '00000000-0000-0000-0000-000000000001'))).hex.upper() record['cc_id'] = uuid.UUID(strip(record.get('cc_id', '00000000-0000-0000-0000-000000000001'))).hex.upper() query = ( "INSERT INTO servers_history " "(server_id, cloud_server_id, farm_id, farm_roleid, role_id, client_id, env_id, " "platform, cloud_location, server_index, instance_type_name, type, project_id, cc_id) " "VALUES ({server_id}, {cloud_server_id}, {farm_id}, {farm_roleid}, {role_id}, " "{client_id}, {env_id}, {platform}, {cloud_location}, {server_index}, " "{instance_type_name}, {type}, UNHEX('{project_id}'), UNHEX('{cc_id}'))" ).format(**record) db.execute(query)
def fill_messages(step): db = dbmanager.DB(lib.world.config['connections']['mysql']) lib.world.messages = {} for record in step.hashes: record['messageid'] = record.get('messageid', "'%s'" % str(uuid.uuid4())) record['status'] = record.get('status', 0) record['handle_attempts'] = record.get('handle_attempts', 0) record['dtlasthandleattempt'] = record.get( 'dthandleattempt', "'%s'" % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) record['message'] = record.get('message', "'Some message'") record['server_id'] = record.get('server_id', "'%s'" % lib.generate_server_id()) record['type'] = record.get('type', "'out'") record['message_version'] = record.get('message_version', 2) record['message_name'] = record.get('message_name', "''") record['message_format'] = record.get('message_format', "'json'") record['event_id'] = record.get('event_id', "'%s'" % lib.generate_id()) query = ( "INSERT messages " "(messageid, status, handle_attempts, dtlasthandleattempt, message, " "server_id, type, message_version, message_name, message_format, event_id) " "VALUES ({messageid}, {status}, {handle_attempts}, {dtlasthandleattempt}, " "{message}, {server_id}, {type}, {message_version}, {message_name}, " "{message_format}, {event_id})" ).format(**record) db.execute(query) message = db.execute( 'SELECT * FROM messages where messageid={0}'.format(record['messageid'].strip()))[0] lib.world.messages[message['messageid']] = message
def fill_messages(step): db = dbmanager.DB(lib.world.config["connections"]["mysql"]) lib.world.messages = {} for record in step.hashes: record["messageid"] = record.get("messageid", "'%s'" % str(uuid.uuid4())) record["status"] = record.get("status", 0) record["handle_attempts"] = record.get("handle_attempts", 0) record["dtlasthandleattempt"] = record.get( "dthandleattempt", "'%s'" % datetime.now().strftime("%Y-%m-%d %H:%M:%S") ) record["message"] = record.get("message", "'Some message'") record["server_id"] = record.get("server_id", "'%s'" % lib.generate_server_id()) record["type"] = record.get("type", "'out'") record["message_version"] = record.get("message_version", 2) record["message_name"] = record.get("message_name", "''") record["message_format"] = record.get("message_format", "'json'") record["event_id"] = record.get("event_id", "'%s'" % lib.generate_id()) query = ( "INSERT messages " "(messageid, status, handle_attempts, dtlasthandleattempt, message, " "server_id, type, message_version, message_name, message_format, event_id) " "VALUES ({messageid}, {status}, {handle_attempts}, {dtlasthandleattempt}, " "{message}, {server_id}, {type}, {message_version}, {message_name}, " "{message_format}, {event_id})" ).format(**record) db.execute(query) message = db.execute("SELECT * FROM messages where messageid={0}".format(record["messageid"].strip()))[0] lib.world.messages[message["messageid"]] = message
def fill_servers(step): db = dbmanager.DB(lib.world.config['connections']['mysql']) lib.world.servers = {} for record in step.hashes: record['server_id'] = record.get('server_id', "'%s'" % lib.generate_server_id()) record['farm_id'] = record.get('farm_id', lib.generate_id()) record['farm_roleid'] = record.get('farm_roleid', lib.generate_id()) record['client_id'] = record.get('client_id', lib.generate_id()) record['env_id'] = record.get('env_id', lib.generate_id()) record['platform'] = record.get( 'platform', random.choice(["'ec2'", "'gce'", "'idcf'", "'openstack'"])) record['cloud_location'] = record.get('cloud_location', "'us-east-1'") record['status'] = record.get('server_status') or record.get('status', "'Running'") record['remote_ip'] = record.get('remote_ip', 'NULL') record['local_ip'] = record.get('local_ip', 'NULL') record['index'] = record.get('index', 1) record['instance_type_name'] = record.get('instance_type_name', 'NULL') record['type'] = record.get('type', 'NULL') record['os_type'] = record.get('os_type', random.choice(["'linux'", "'windows'"])) query = ( "INSERT INTO servers " "(server_id, farm_id, farm_roleid, client_id, env_id, platform, cloud_location, " "status, remote_ip, local_ip, `index`, instance_type_name, type, os_type) " "VALUES ({server_id}, {farm_id}, {farm_roleid}, {client_id}, {env_id}, " "{platform}, {cloud_location}, {status}, {remote_ip}, {local_ip}, {index}, " "{instance_type_name}, {type}, {os_type})" ).format(**record) db.execute(query) server = db.execute("SELECT * FROM servers where server_id='%s'" % strip(record['server_id']))[0] for k, v in server.items(): if isinstance(v, basestring): server[k] = "'%s'" % v lib.world.servers[server['server_id']] = server
def fill_servers(step): db = dbmanager.DB(lib.world.config["connections"]["mysql"]) lib.world.servers = {} for record in step.hashes: record["server_id"] = record.get("server_id", "'%s'" % lib.generate_server_id()) record["farm_id"] = record.get("farm_id", lib.generate_id()) record["farm_roleid"] = record.get("farm_roleid", lib.generate_id()) record["client_id"] = record.get("client_id", lib.generate_id()) record["env_id"] = record.get("env_id", lib.generate_id()) record["platform"] = record.get("platform", random.choice(["'ec2'", "'gce'", "'idcf'", "'openstack'"])) record["cloud_location"] = record.get("cloud_location", "'us-east-1'") record["status"] = record.get("status", "'running'") record["remote_ip"] = record.get("remote_ip", "NULL") record["local_ip"] = record.get("local_ip", "NULL") record["index"] = record.get("index", 1) record["instance_type_name"] = record.get("instance_type_name", "NULL") record["type"] = record.get("type", "NULL") record["os_type"] = record.get("os_type", random.choice(["'linux'", "'windows'"])) query = ( "INSERT INTO servers " "(server_id, farm_id, farm_roleid, client_id, env_id, platform, cloud_location, " "status, remote_ip, local_ip, `index`, instance_type_name, type, os_type) " "VALUES ({server_id}, {farm_id}, {farm_roleid}, {client_id}, {env_id}, " "{platform}, {cloud_location}, {status}, {remote_ip}, {local_ip}, {index}, " "{instance_type_name}, {type}, {os_type})" ).format(**record) db.execute(query) server = db.execute("SELECT * FROM servers where server_id='%s'" % strip(record["server_id"]))[0] for k, v in server.items(): if isinstance(v, basestring): server[k] = "'%s'" % v lib.world.servers[server["server_id"]] = server
def fill_servers_history(step): db = dbmanager.DB(lib.world.config["connections"]["mysql"]) for record in step.hashes: record["server_id"] = record.get("server_id", "'%s'" % lib.generate_server_id()) server = lib.world.servers.get(record["server_id"], {}) record["cloud_server_id"] = record["cloud_server_id"] record["farm_id"] = record.get("farm_id") or server.get("farm_id") or lib.generate_id() record["farm_roleid"] = record.get("farm_roleid") or server.get("farm_roleid") or lib.generate_id() record["client_id"] = record.get("client_id") or server.get("client_id") or lib.generate_id() record["env_id"] = record.get("env_id") or server.get("env_id") or lib.generate_id() record["platform"] = ( record.get("platform") or server.get("platform") or random.choice(["'ec2'", "'gce'", "'idcf'", "'openstack'"]) ) record["cloud_location"] = record.get("cloud_location") or server.get("cloud_location") or "'us-east-1'" record["instance_type_name"] = record.get("instance_type_name") or server.get("instance_type_name") or "NULL" record["type"] = record.get("type") or server.get("type") or "NULL" record["server_index"] = record.get("server_index") or server.get("index") or 1 record["role_id"] = record.get("role_id") or lib.generate_id() record["project_id"] = uuid.UUID( strip(record.get("project_id", "00000000-0000-0000-0000-000000000001")) ).hex.upper() record["cc_id"] = uuid.UUID(strip(record.get("cc_id", "00000000-0000-0000-0000-000000000001"))).hex.upper() query = ( "INSERT INTO servers_history " "(server_id, cloud_server_id, farm_id, farm_roleid, role_id, client_id, env_id, " "platform, cloud_location, server_index, instance_type_name, type, project_id, cc_id) " "VALUES ({server_id}, {cloud_server_id}, {farm_id}, {farm_roleid}, {role_id}, " "{client_id}, {env_id}, {platform}, {cloud_location}, {server_index}, " "{instance_type_name}, {type}, UNHEX('{project_id}'), UNHEX('{cc_id}'))" ).format(**record) db.execute(query)
def fill_messages(step): db = dbmanager.DB(lib.world.config['connections']['mysql']) lib.world.messages = {} for record in step.hashes: record['messageid'] = record.get('messageid', "'%s'" % str(uuid.uuid4())) record['status'] = record.get('status', 0) record['handle_attempts'] = record.get('handle_attempts', 0) record['dtlasthandleattempt'] = record.get( 'dthandleattempt', "'%s'" % datetime.now().strftime('%Y-%m-%d %H:%M:%S')) record['message'] = "'Carrot'" record['server_id'] = record.get('server_id', "'%s'" % lib.generate_server_id()) record['type'] = record.get('type', "'out'") record['message_version'] = record.get('message_version', 2) record['message_name'] = record.get('message_name', "''") record['message_format'] = record.get('message_format', "'json'") record['event_id'] = record.get('event_id', "'%s'" % lib.generate_id()) query = ( "INSERT messages " "(messageid, status, handle_attempts, dtlasthandleattempt, message, " "server_id, type, message_version, message_name, message_format, event_id) " "VALUES ({messageid}, {status}, {handle_attempts}, {dtlasthandleattempt}, " "{message}, {server_id}, {type}, {message_version}, {message_name}, " "{message_format}, {event_id})").format(**record) db.execute(query) message = db.execute( 'SELECT * FROM messages where messageid={0}'.format( record['messageid'].strip()))[0] lib.world.messages[message['messageid']] = message
def fill_servers(step): db = dbmanager.DB(lib.world.config['connections']['mysql']) lib.world.servers = {} for record in step.hashes: record['server_id'] = record.get('server_id', "'%s'" % lib.generate_server_id()) record['farm_id'] = record.get('farm_id', lib.generate_id()) record['farm_roleid'] = record.get('farm_roleid', lib.generate_id()) record['client_id'] = record.get('client_id', lib.generate_id()) record['env_id'] = record.get('env_id', lib.generate_id()) record['role_id'] = record.get('env_id', lib.generate_id()) record['platform'] = record.get( 'platform', random.choice(["'ec2'", "'gce'", "'idcf'", "'openstack'"])) record['status'] = record.get('status', "'running'") record['remote_ip'] = record.get('remote_ip', 'NULL') record['local_ip'] = record.get('local_ip', 'NULL') record['index'] = record.get('index', 1) record['os_type'] = record.get('os_type', random.choice(["'linux'", "'windows'"])) query = ( "INSERT INTO servers " "(server_id, farm_id, farm_roleid, client_id, env_id, role_id, platform, " "status, remote_ip, local_ip, `index`, os_type) " "VALUES ({server_id}, {farm_id}, {farm_roleid}, {client_id}, {env_id}, " "{role_id}, {platform}, {status}, {remote_ip}, {local_ip}, {index}, {os_type})" ).format(**record) db.execute(query) server = db.execute("SELECT * FROM servers where server_id='%s'" % strip(record['server_id'])) server = db.execute("SELECT * FROM servers where server_id='%s'" % strip(record['server_id']))[0] lib.world.servers[server['server_id']] = server
def db_has_messages(step, count): records = [] for i in range(int(count)): record = {} # messages record['messageid'] = "'%s'" % str(uuid.uuid4()) record['status'] = 0 record['handle_attempts'] = 0 record['dtlasthandleattempt'] = "'%s'" % datetime.now().strftime('%Y-%m-%d %H:%M:%S') record['message'] = "'Carrot'" record['server_id'] = "'%s'" % lib.generate_server_id() record['type'] = "'out'" record['message_version'] = 2 record['message_name'] = "''" record['message_format'] = "'json'" record['event_id'] = "'%s'" % lib.generate_id() # servers record['farm_id'] = lib.generate_id() record['farm_roleid'] = lib.generate_id() record['client_id'] = lib.generate_id() record['env_id'] = lib.generate_id() record['role_id'] = lib.generate_id() record['platform'] = random.choice(["'ec2'", "'gce'", "'idcf'", "'openstack'"]) record['status'] = "'running'" record['remote_ip'] = "'127.0.0.1'" record['local_ip'] = "'127.0.0.1'" record['index'] = 1 record['os_type'] = "'linux'" records.append(record) step.hashes = records fill_messages(step) fill_servers(step) for record in step.hashes: # server_properties record['name'] = "'scalarizr.ctrl_port'" record['value'] = random.choice(["'8010'", "'8011'", "'8012'", "'8013'", "'8014'", "'8015'", "'8016'", "'8017'", "'8018'", "'8019'"]) fill_server_properties(step) for record in step.hashes: # server_properties record['name'] = "'scalarizr.key'" record['value'] = "'{0}'".format(scalrpytests.scalarizr_key) fill_server_properties(step)
def db_has_messages(step, count): records = [] for i in range(int(count)): record = {} # messages record['messageid'] = "'%s'" % str(uuid.uuid4()) record['status'] = 0 record['handle_attempts'] = 0 record['dtlasthandleattempt'] = "'%s'" % datetime.now().strftime( '%Y-%m-%d %H:%M:%S') record['message'] = "'Carrot'" record['server_id'] = "'%s'" % lib.generate_server_id() record['type'] = "'out'" record['message_version'] = 2 record['message_name'] = "''" record['message_format'] = "'json'" record['event_id'] = "'%s'" % lib.generate_id() # servers record['farm_id'] = lib.generate_id() record['farm_roleid'] = lib.generate_id() record['client_id'] = lib.generate_id() record['env_id'] = lib.generate_id() record['role_id'] = lib.generate_id() record['platform'] = random.choice( ["'ec2'", "'gce'", "'idcf'", "'openstack'"]) record['status'] = "'running'" record['remote_ip'] = "'127.0.0.1'" record['local_ip'] = "'127.0.0.1'" record['index'] = 1 record['os_type'] = "'linux'" records.append(record) step.hashes = records fill_messages(step) fill_servers(step) for record in step.hashes: # server_properties record['name'] = "'scalarizr.ctrl_port'" record['value'] = random.choice([ "'8010'", "'8011'", "'8012'", "'8013'", "'8014'", "'8015'", "'8016'", "'8017'", "'8018'", "'8019'" ]) fill_server_properties(step) for record in step.hashes: # server_properties record['name'] = "'scalarizr.key'" record['value'] = "'{0}'".format(scalrpytests.scalarizr_key) fill_server_properties(step)
def fill_servers_history(step): db = dbmanager.DB(lib.world.config['connections']['mysql']) for record in step.hashes: record['server_id'] = record.get('server_id', "'%s'" % lib.generate_server_id()) server = lib.world.servers.get(record['server_id'], {}) record['cloud_server_id'] = record['cloud_server_id'] record['farm_id'] = record.get('farm_id') or server.get( 'farm_id') or lib.generate_id() record['farm_roleid'] = record.get('farm_roleid') or server.get( 'farm_roleid') or lib.generate_id() record['client_id'] = record.get('client_id') or server.get( 'client_id') or lib.generate_id() record['env_id'] = record.get('env_id') or server.get( 'env_id') or lib.generate_id() record['platform'] = record.get('platform') or server.get( 'platform') or random.choice( ["'ec2'", "'gce'", "'idcf'", "'openstack'"]) record['cloud_location'] = record.get('cloud_location') or server.get( 'cloud_location') or "'us-east-1'" record['instance_type_name'] = record.get( 'instance_type_name') or server.get('instance_type_name') or 'NULL' record['type'] = record.get('type') or server.get('type') or 'NULL' record['server_index'] = record.get('server_index') or server.get( 'index') or 1 record['role_id'] = record.get('role_id') or lib.generate_id() record['project_id'] = uuid.UUID( strip( record.get( 'project_id', '00000000-0000-0000-0000-000000000001'))).hex.upper() record['cc_id'] = uuid.UUID( strip(record.get( 'cc_id', '00000000-0000-0000-0000-000000000001'))).hex.upper() query = ( "INSERT INTO servers_history " "(server_id, cloud_server_id, farm_id, farm_roleid, role_id, client_id, env_id, " "platform, cloud_location, server_index, instance_type_name, type, project_id, cc_id) " "VALUES ({server_id}, {cloud_server_id}, {farm_id}, {farm_roleid}, {role_id}, " "{client_id}, {env_id}, {platform}, {cloud_location}, {server_index}, " "{instance_type_name}, {type}, UNHEX('{project_id}'), UNHEX('{cc_id}'))" ).format(**record) db.execute(query)