本文整理汇总了Python中utils.GerritGitUtils类的典型用法代码示例。如果您正苦于以下问题:Python GerritGitUtils类的具体用法?Python GerritGitUtils怎么用?Python GerritGitUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GerritGitUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_private_project_as_admin_clone_as_admin
def test_create_private_project_as_admin_clone_as_admin(self):
""" Clone private project as admin and check content
"""
pname = 'p_%s' % create_random_str()
options = {"private": ""}
self.create_project(pname, config.ADMIN_USER, options=options)
ggu = GerritGitUtils(config.ADMIN_USER,
config.ADMIN_PRIV_KEY_PATH,
config.USERS[config.ADMIN_USER]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER,
config.GATEWAY_HOST, pname)
clone_dir = ggu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
# Test that the clone is a success
self.assertTrue(os.path.isdir(clone_dir))
# Verify master own the .gitreview file
self.assertTrue(os.path.isfile(os.path.join(clone_dir,
'.gitreview')))
# Verify meta/config branch own both group and ACLs config file
ggu.fetch_meta_config(clone_dir)
self.assertTrue(os.path.isfile(os.path.join(clone_dir,
'project.config')))
self.assertTrue(os.path.isfile(os.path.join(clone_dir,
'groups')))
# There is a group dev for a private project
content = file(os.path.join(clone_dir, 'project.config')).read()
self.assertTrue('%s-dev' % pname in content)
content = file(os.path.join(clone_dir, 'groups')).read()
self.assertTrue('%s-dev' % pname in content)
示例2: test_create_public_project_as_user_clone_as_user
def test_create_public_project_as_user_clone_as_user(self):
""" Create public project as user then clone as user
"""
pname = 'p_%s' % create_random_str()
# create the project as admin
self.create_project(pname, config.USER_2)
# add user2 ssh pubkey to user2
gu = GerritUtils(
'https://%s/' % config.GATEWAY_HOST,
auth_cookie=config.USERS[config.USER_2]['auth_cookie'])
gu.add_pubkey(config.USER_2_PUB_KEY)
# prepare to clone
priv_key_path = set_private_key(config.USER_2_PRIV_KEY)
self.dirs_to_delete.append(os.path.dirname(priv_key_path))
ggu = GerritGitUtils(config.USER_2,
priv_key_path,
config.USERS[config.USER_2]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (config.USER_2,
config.GATEWAY_HOST, pname)
# clone
clone_dir = ggu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
# Test that the clone is a success
self.assertTrue(os.path.isdir(clone_dir))
# Verify master own the .gitreview file
self.assertTrue(os.path.isfile(os.path.join(clone_dir,
'.gitreview')))
示例3: test_basic_ops_project_namespace
def test_basic_ops_project_namespace(self):
""" Check if a project named with a / (namespace) is handled
correctly on basic ops by managesf
"""
pname = 'skydive/%s' % create_random_str()
self.create_project(pname, config.USER_2)
self.assertTrue(self.gu.project_exists(pname))
self.assertTrue(self.gu.group_exists('%s-ptl' % pname))
if is_present("SFRedmine"):
rname = '_'.join(pname.split('/'))
self.assertTrue(self.rm.project_exists(rname))
# Try to clone
ggu = GerritGitUtils(config.ADMIN_USER,
config.ADMIN_PRIV_KEY_PATH,
config.USERS[config.ADMIN_USER]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER,
config.GATEWAY_HOST, pname)
clone_dir = ggu.clone(url, pname.split('/')[-1])
self.dirs_to_delete.append(os.path.dirname(clone_dir))
# Test that the clone is a success
self.assertTrue(os.path.isdir(clone_dir))
# Verify master own the .gitreview file
self.assertTrue(os.path.isfile(os.path.join(clone_dir,
'.gitreview')))
# Delete the project from SF
self.msu.deleteProject(pname, config.ADMIN_USER)
self.assertFalse(self.gu.project_exists(pname))
self.assertFalse(self.gu.group_exists('%s-ptl' % pname))
if is_present("SFRedmine"):
rname = '_'.join(pname.split('/'))
self.assertFalse(self.rm.project_exists(rname))
self.assertFalse(self.gu.group_exists('%s-core' % pname))
# Clean local clone directory
self.projects.remove(pname)
示例4: test_review_labels
def test_review_labels(self):
""" Test if list of review labels are as expected
"""
pname = 'p_%s' % create_random_str()
self.create_project(pname)
un = config.ADMIN_USER
gu = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[un]['auth_cookie'])
k_index = gu.add_pubkey(config.USERS[un]["pubkey"])
self.assertTrue(gu.project_exists(pname))
priv_key_path = set_private_key(config.USERS[un]["privkey"])
gitu = GerritGitUtils(un,
priv_key_path,
config.USERS[un]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (un, config.GATEWAY_HOST,
pname)
clone_dir = gitu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
gitu.add_commit_and_publish(clone_dir, "master", "Test commit")
change_ids = gu.get_my_changes_for_project(pname)
self.assertEqual(len(change_ids), 1)
change_id = change_ids[0]
labels = gu.get_labels_list_for_change(change_id)
self.assertIn('Workflow', labels)
self.assertIn('Code-Review', labels)
self.assertIn('Verified', labels)
self.assertEqual(len(labels.keys()), 3)
gu.del_pubkey(k_index)
示例5: test_init_user_tests
def test_init_user_tests(self):
""" Check if a test init feature behave as expected
"""
project = "p_%s" % create_random_str()
self.create_project(project, config.USER_4)
self.msu.create_init_tests(project, config.USER_4)
ggu = GerritGitUtils(config.ADMIN_USER, config.ADMIN_PRIV_KEY_PATH, config.USERS[config.ADMIN_USER]["email"])
open_reviews = ggu.list_open_reviews("config", config.GATEWAY_HOST)
match = [
True
for review in open_reviews
if review["commitMessage"].startswith(
"%s proposes initial test " "definition for project %s" % (config.USER_4, project)
)
]
self.assertEqual(len(match), 1)
open_reviews = ggu.list_open_reviews(project, config.GATEWAY_HOST)
match = [
True
for review in open_reviews
if review["commitMessage"].startswith(
"%s proposes initial test " "scripts for project %s" % (config.USER_4, project)
)
]
self.assertEqual(len(match), 1)
示例6: _prepare_review_submit_testing
def _prepare_review_submit_testing(self, project_options=None):
if project_options is None:
u2mail = config.USERS[config.USER_2]['email']
project_options = {'core-group': u2mail}
pname = 'p_%s' % create_random_str()
self.create_project(pname, project_options)
un = config.ADMIN_USER
gu = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[un]['auth_cookie'])
k_index = gu.add_pubkey(config.USERS[un]["pubkey"])
self.assertTrue(gu.project_exists(pname))
priv_key_path = set_private_key(config.USERS[un]["privkey"])
gitu = GerritGitUtils(un,
priv_key_path,
config.USERS[un]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (un, config.GATEWAY_HOST,
pname)
clone_dir = gitu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
gitu.add_commit_and_publish(clone_dir, "master", "Test commit")
change_ids = gu.get_my_changes_for_project(pname)
self.assertEqual(len(change_ids), 1)
change_id = change_ids[0]
return change_id, gu, k_index
示例7: test_01_validate_gerrit_project_acls
def test_01_validate_gerrit_project_acls(self):
""" Verify the correct behavior of ACLs set on
gerrit project
"""
pname = "TestProjectACL"
self.createProject(pname)
un = config.ADMIN_USER
priv_key_path = set_private_key(config.USERS[un]["privkey"])
gitu = GerritGitUtils(un,
priv_key_path,
config.USERS[un]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (un, config.GATEWAY_HOST,
pname)
clone_dir = gitu.clone(url, pname)
gitu.fetch_meta_config(clone_dir)
with open(os.path.join(clone_dir,
'project.config')) as project_config:
p_config = parse_project_config(project_config)
ptl = pname + "-ptl"
core = pname + "-core"
self.assertTrue('access "refs/*"' in p_config.keys(),
repr(p_config))
self.assertTrue('access "refs/heads/*"' in p_config.keys(),
repr(p_config))
self.assertTrue('access "refs/meta/config"' in p_config.keys(),
repr(p_config))
self.assertTrue(any(ptl in l
for l in p_config['access "refs/*"']['owner']),
repr(p_config))
self.assertTrue(any(core in l
for l in p_config['access "refs/*"']['read']),
repr(p_config))
heads = p_config['access "refs/heads/*"']
self.assertTrue(any(core in l
for l in heads['label-Code-Review']),
repr(p_config))
self.assertTrue(any(core in l
for l in heads['label-Workflow']),
repr(p_config))
self.assertTrue(any(ptl in l
for l in heads['label-Verified']),
repr(p_config))
self.assertTrue(any(ptl in l
for l in heads['submit']),
repr(p_config))
self.assertTrue(any(core in l
for l in heads['read']),
repr(p_config))
# no need to test ref/meta/config, we could not test is if we
# could not access it to begin with
self.dirs_to_delete.append(os.path.dirname(clone_dir))
示例8: test_check_config_repo_exists
def test_check_config_repo_exists(self):
""" Validate config repo has been bootstraped
"""
pname = "config"
gu = GerritUtils(config.GATEWAY_URL, auth_cookie=config.USERS[config.ADMIN_USER]["auth_cookie"])
self.assertTrue(gu.project_exists(pname))
ggu = GerritGitUtils(config.ADMIN_USER, config.ADMIN_PRIV_KEY_PATH, config.USERS[config.ADMIN_USER]["email"])
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER, config.GATEWAY_HOST, pname)
clone_dir = ggu.clone(url, pname)
# Test that the clone is a success
self.assertTrue(os.path.isdir(clone_dir))
# Check if the clone dir has projects file
self.assertTrue(os.path.isfile(os.path.join(clone_dir, "jobs/projects.yaml")))
示例9: setUp
def setUp(self):
self.projects = []
self.dirs_to_delete = []
self.un = config.ADMIN_USER
self.gu = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[self.un]['auth_cookie'])
self.gu2 = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[config.USER_2]['auth_cookie'])
self.ju = JenkinsUtils()
self.gu.add_pubkey(config.USERS[self.un]["pubkey"])
priv_key_path = set_private_key(config.USERS[self.un]["privkey"])
self.gitu_admin = GerritGitUtils(self.un,
priv_key_path,
config.USERS[self.un]['email'])
# Clone the config repo and make change to it
# in order to test the new sample_project
self.config_clone_dir = self.clone_as_admin("config")
self.original_layout = file(os.path.join(
self.config_clone_dir, "zuul/layout.yaml")).read()
self.original_zuul_projects = file(os.path.join(
self.config_clone_dir, "zuul/projects.yaml")).read()
self.original_project = file(os.path.join(
self.config_clone_dir, "jobs/projects.yaml")).read()
# Put USER_2 as core for config project
self.gu.add_group_member(config.USER_2, "config-core")
示例10: test_check_download_commands
def test_check_download_commands(self):
""" Test if download commands plugin works
"""
pname = 'p_%s' % create_random_str()
self.create_project(pname)
un = config.ADMIN_USER
gu = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[un]['auth_cookie'])
self.assertTrue(gu.project_exists(pname))
k_index = gu.add_pubkey(config.USERS[un]["pubkey"])
priv_key_path = set_private_key(config.USERS[un]["privkey"])
gitu = GerritGitUtils(un,
priv_key_path,
config.USERS[un]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (un, config.GATEWAY_HOST,
pname)
clone_dir = gitu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
gitu.add_commit_and_publish(clone_dir, "master", "Test commit")
change_ids = gu.get_my_changes_for_project(pname)
self.assertEqual(len(change_ids), 1)
change_id = change_ids[0]
resp = gu.get_change_last_patchset(change_id)
self.assertIn("current_revision", resp)
self.assertIn("revisions", resp)
current_rev = resp["current_revision"]
fetch = resp["revisions"][current_rev]["fetch"]
self.assertGreater(fetch.keys(), 0)
# disable and check if the fetch has anything
gu.e_d_plugin("download-commands", 'disable')
resp = gu.get_change_last_patchset(change_id)
fetch = resp["revisions"][current_rev]["fetch"]
self.assertEqual(len(fetch.keys()), 0)
# enable the plugin and check if the fetch information is valid
gu.e_d_plugin("download-commands", 'enable')
resp = gu.get_change_last_patchset(change_id)
fetch = resp["revisions"][current_rev]["fetch"]
self.assertGreater(len(fetch.keys()), 0)
gu.del_pubkey(k_index)
示例11: test_check_config_repo_exists
def test_check_config_repo_exists(self):
pname = 'config'
gu = GerritUtils(
'https://%s/' % config.GATEWAY_HOST,
auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
self.assertTrue(gu.project_exists(pname))
ggu = GerritGitUtils(config.ADMIN_USER,
config.ADMIN_PRIV_KEY_PATH,
config.USERS[config.ADMIN_USER]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER,
config.GATEWAY_HOST, pname)
clone_dir = ggu.clone(url, pname)
# Test that the clone is a success
self.assertTrue(os.path.isdir(clone_dir))
# Check if the clone dir has projects file
self.assertTrue(os.path.isfile(os.path.join(clone_dir,
"jobs/projects.yaml")))
示例12: test_create_public_project_as_admin_clone_as_admin
def test_create_public_project_as_admin_clone_as_admin(self):
""" Clone public project as admin and check content
"""
pname = "p_%s" % create_random_str()
self.create_project(pname, config.ADMIN_USER)
ggu = GerritGitUtils(config.ADMIN_USER, config.ADMIN_PRIV_KEY_PATH, config.USERS[config.ADMIN_USER]["email"])
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER, config.GATEWAY_HOST, pname)
clone_dir = ggu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
# Test that the clone is a success
self.assertTrue(os.path.isdir(clone_dir))
# Verify master own the .gitreview file
self.assertTrue(os.path.isfile(os.path.join(clone_dir, ".gitreview")))
# Verify meta/config branch own both group and ACLs config file
ggu.fetch_meta_config(clone_dir)
self.assertTrue(os.path.isfile(os.path.join(clone_dir, "project.config")))
self.assertTrue(os.path.isfile(os.path.join(clone_dir, "groups")))
# There is no group dev for a public project
content = file(os.path.join(clone_dir, "project.config")).read()
self.assertFalse("%s-dev" % pname in content)
content = file(os.path.join(clone_dir, "groups")).read()
self.assertFalse("%s-dev" % pname in content)
示例13: test_upstream
def test_upstream(self):
""" Validate upstream feature of managesf
"""
# Create a test upstream project
pname_us = 'p_upstream'
self.create_project(pname_us, config.ADMIN_USER)
ggu_us = GerritGitUtils(config.ADMIN_USER,
config.ADMIN_PRIV_KEY_PATH,
config.USERS[config.ADMIN_USER]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER,
config.GATEWAY_HOST, pname_us)
# clone
us_clone_dir = ggu_us.clone(url, pname_us)
self.dirs_to_delete.append(os.path.dirname(us_clone_dir))
# Test that the clone is a success
self.assertTrue(os.path.isdir(us_clone_dir))
# push some test files to the upstream project
us_files = [str(x) for x in range(1, 10)]
for f in us_files:
file(os.path.join(us_clone_dir, f), 'w').write(f)
os.chmod(os.path.join(us_clone_dir, f), 0755)
ggu_us.add_commit_in_branch(us_clone_dir, "master",
commit="Adding files 1-10",
files=us_files)
ggu_us.direct_push_branch(us_clone_dir, "master")
# No create a test project with upstream pointing to the above
upstream_url = "ssh://%[email protected]%s:29418/%s" % (
config.ADMIN_USER, config.GATEWAY_HOST, pname_us)
pname = 'p_%s' % create_random_str()
# create the project as admin
options = {"upstream": upstream_url,
"upstream-ssh-key": config.ADMIN_PRIV_KEY_PATH}
self.create_project(pname, config.ADMIN_USER, options=options)
ggu = GerritGitUtils(config.ADMIN_USER,
config.ADMIN_PRIV_KEY_PATH,
config.USERS[config.ADMIN_USER]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER,
config.GATEWAY_HOST, pname)
# clone
clone_dir = ggu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
# Check if the files pushed in upstream project is present
files = [f for f in os.listdir(clone_dir) if not f.startswith('.')]
self.assertEqual(set(files), set(us_files))
示例14: __init__
def __init__(self):
with open('resources.yaml', 'r') as rsc:
self.resources = yaml.load(rsc)
config.USERS[config.ADMIN_USER]['auth_cookie'] = get_cookie(
config.ADMIN_USER, config.USERS[config.ADMIN_USER]['password'])
self.msu = ManageSfUtils(config.GATEWAY_URL)
self.ggu = GerritGitUtils(config.ADMIN_USER,
config.ADMIN_PRIV_KEY_PATH,
config.USERS[config.ADMIN_USER]['email'])
self.ju = JenkinsUtils()
self.rm = RedmineUtils(
config.REDMINE_URL,
auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
示例15: __init__
def __init__(self):
with open("%s/resources.yaml" % pwd, 'r') as rsc:
self.resources = yaml.load(rsc)
config.USERS[config.ADMIN_USER]['auth_cookie'] = get_cookie(
config.ADMIN_USER, config.USERS[config.ADMIN_USER]['password'])
self.gu = GerritUtils(
'http://%s/' % config.GATEWAY_HOST,
auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
self.ggu = GerritGitUtils(config.ADMIN_USER,
config.ADMIN_PRIV_KEY_PATH,
config.USERS[config.ADMIN_USER]['email'])
self.ju = JenkinsUtils()
self.rm = RedmineUtils(
config.GATEWAY_URL + "/redmine/",
auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])