Parametrize populate-fixture-data.py
Add -p for setting the port, and -u for the user count. Change-Id: I872607b3ce5707b8fc9e8b090292bc984bdfc535
This commit is contained in:
40
contrib/populate-fixture-data.py
Normal file → Executable file
40
contrib/populate-fixture-data.py
Normal file → Executable file
@@ -17,34 +17,24 @@
|
|||||||
This script will populate an empty standard Gerrit instance with some
|
This script will populate an empty standard Gerrit instance with some
|
||||||
data for local testing.
|
data for local testing.
|
||||||
|
|
||||||
This script requires 'requests'. If you do not have this module, run
|
|
||||||
'pip3 install requests' to install it.
|
|
||||||
|
|
||||||
TODO(hiesel): Make real git commits instead of empty changes
|
TODO(hiesel): Make real git commits instead of empty changes
|
||||||
TODO(hiesel): Add comments
|
TODO(hiesel): Add comments
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import atexit
|
import atexit
|
||||||
import json
|
import json
|
||||||
|
import optparse
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import requests.auth
|
import requests.auth
|
||||||
|
|
||||||
DEFAULT_TMP_PATH = "/tmp"
|
DEFAULT_TMP_PATH = "/tmp"
|
||||||
TMP_PATH = ""
|
TMP_PATH = ""
|
||||||
BASE_URL = "http://localhost:8080/a/"
|
BASE_URL = "http://localhost:%d/a/"
|
||||||
ACCESS_URL = BASE_URL + "access/"
|
|
||||||
ACCOUNTS_URL = BASE_URL + "accounts/"
|
|
||||||
CHANGES_URL = BASE_URL + "changes/"
|
|
||||||
CONFIG_URL = BASE_URL + "config/"
|
|
||||||
GROUPS_URL = BASE_URL + "groups/"
|
|
||||||
PLUGINS_URL = BASE_URL + "plugins/"
|
|
||||||
PROJECTS_URL = BASE_URL + "projects/"
|
|
||||||
|
|
||||||
ADMIN_BASIC_AUTH = requests.auth.HTTPBasicAuth("admin", "secret")
|
ADMIN_BASIC_AUTH = requests.auth.HTTPBasicAuth("admin", "secret")
|
||||||
|
|
||||||
@@ -158,7 +148,7 @@ def basic_auth(user):
|
|||||||
def fetch_admin_group():
|
def fetch_admin_group():
|
||||||
global GROUP_ADMIN
|
global GROUP_ADMIN
|
||||||
# Get admin group
|
# Get admin group
|
||||||
r = json.loads(clean(requests.get(GROUPS_URL + "?suggest=ad&p=All-Projects",
|
r = json.loads(clean(requests.get(BASE_URL + "groups/" + "?suggest=ad&p=All-Projects",
|
||||||
headers=HEADERS,
|
headers=HEADERS,
|
||||||
auth=ADMIN_BASIC_AUTH).text))
|
auth=ADMIN_BASIC_AUTH).text))
|
||||||
admin_group_name = r.keys()[0]
|
admin_group_name = r.keys()[0]
|
||||||
@@ -222,7 +212,7 @@ def create_gerrit_groups():
|
|||||||
"visible_to_all": False, "owner": GROUP_ADMIN["name"],
|
"visible_to_all": False, "owner": GROUP_ADMIN["name"],
|
||||||
"owner_id": GROUP_ADMIN["id"]}]
|
"owner_id": GROUP_ADMIN["id"]}]
|
||||||
for g in groups:
|
for g in groups:
|
||||||
requests.put(GROUPS_URL + g["name"],
|
requests.put(BASE_URL + "groups/" + g["name"],
|
||||||
json.dumps(g),
|
json.dumps(g),
|
||||||
headers=HEADERS,
|
headers=HEADERS,
|
||||||
auth=ADMIN_BASIC_AUTH)
|
auth=ADMIN_BASIC_AUTH)
|
||||||
@@ -244,7 +234,7 @@ def create_gerrit_projects(owner_groups):
|
|||||||
"branches": ["master"], "description": "some small scripts.",
|
"branches": ["master"], "description": "some small scripts.",
|
||||||
"owners": [owner_groups[3]], "create_empty_commit": True}]
|
"owners": [owner_groups[3]], "create_empty_commit": True}]
|
||||||
for p in projects:
|
for p in projects:
|
||||||
requests.put(PROJECTS_URL + p["name"],
|
requests.put(BASE_URL + "projects/" + p["name"],
|
||||||
json.dumps(p),
|
json.dumps(p),
|
||||||
headers=HEADERS,
|
headers=HEADERS,
|
||||||
auth=ADMIN_BASIC_AUTH)
|
auth=ADMIN_BASIC_AUTH)
|
||||||
@@ -253,7 +243,7 @@ def create_gerrit_projects(owner_groups):
|
|||||||
|
|
||||||
def create_gerrit_users(gerrit_users):
|
def create_gerrit_users(gerrit_users):
|
||||||
for user in gerrit_users:
|
for user in gerrit_users:
|
||||||
requests.put(ACCOUNTS_URL + user["username"],
|
requests.put(BASE_URL + "accounts/" + user["username"],
|
||||||
json.dumps(user),
|
json.dumps(user),
|
||||||
headers=HEADERS,
|
headers=HEADERS,
|
||||||
auth=ADMIN_BASIC_AUTH)
|
auth=ADMIN_BASIC_AUTH)
|
||||||
@@ -267,7 +257,7 @@ def create_change(user, project_name):
|
|||||||
"branch": "master",
|
"branch": "master",
|
||||||
"status": "NEW",
|
"status": "NEW",
|
||||||
}
|
}
|
||||||
requests.post(CHANGES_URL,
|
requests.post(BASE_URL + "changes/",
|
||||||
json.dumps(change),
|
json.dumps(change),
|
||||||
headers=HEADERS,
|
headers=HEADERS,
|
||||||
auth=basic_auth(user))
|
auth=basic_auth(user))
|
||||||
@@ -278,8 +268,22 @@ def clean_up():
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
p = optparse.OptionParser()
|
||||||
|
p.add_option("-u", "--user_count", action="store",
|
||||||
|
default=100,
|
||||||
|
type='int',
|
||||||
|
help="number of users to generate")
|
||||||
|
p.add_option("-p", "--port", action="store",
|
||||||
|
default=8080,
|
||||||
|
type='int',
|
||||||
|
help="port of server")
|
||||||
|
(options, _) = p.parse_args()
|
||||||
|
global BASE_URL
|
||||||
|
BASE_URL = BASE_URL % options.port
|
||||||
|
print BASE_URL
|
||||||
|
|
||||||
set_up()
|
set_up()
|
||||||
gerrit_users = get_random_users(100)
|
gerrit_users = get_random_users(options.user_count)
|
||||||
|
|
||||||
group_names = create_gerrit_groups()
|
group_names = create_gerrit_groups()
|
||||||
for idx, u in enumerate(gerrit_users):
|
for idx, u in enumerate(gerrit_users):
|
||||||
|
Reference in New Issue
Block a user