本文整理汇总了Python中pysflib.sfgerrit.GerritUtils.del_pubkey方法的典型用法代码示例。如果您正苦于以下问题:Python GerritUtils.del_pubkey方法的具体用法?Python GerritUtils.del_pubkey怎么用?Python GerritUtils.del_pubkey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysflib.sfgerrit.GerritUtils
的用法示例。
在下文中一共展示了GerritUtils.del_pubkey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_review_labels
# 需要导入模块: from pysflib.sfgerrit import GerritUtils [as 别名]
# 或者: from pysflib.sfgerrit.GerritUtils import del_pubkey [as 别名]
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)
示例2: test_check_download_commands
# 需要导入模块: from pysflib.sfgerrit import GerritUtils [as 别名]
# 或者: from pysflib.sfgerrit.GerritUtils import del_pubkey [as 别名]
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)
示例3: test_check_add_automatic_reviewers
# 需要导入模块: from pysflib.sfgerrit import GerritUtils [as 别名]
# 或者: from pysflib.sfgerrit.GerritUtils import del_pubkey [as 别名]
def test_check_add_automatic_reviewers(self):
""" Test if reviewers-by-blame plugin works
"""
pname = 'p_%s' % create_random_str()
u2mail = config.USERS[config.USER_2]['email']
options = {'core-group': u2mail}
self.create_project(pname, options)
first_u = config.ADMIN_USER
gu_first_u = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[first_u]['auth_cookie'])
self.assertTrue(gu_first_u.project_exists(pname))
# Push data in the create project as Admin user
k1_index = gu_first_u.add_pubkey(config.USERS[first_u]["pubkey"])
priv_key_path = set_private_key(config.USERS[first_u]["privkey"])
gitu = GerritGitUtils(first_u,
priv_key_path,
config.USERS[first_u]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (first_u, config.GATEWAY_HOST,
pname)
clone_dir = gitu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
data = ['this', 'is', 'a', 'couple', 'of', 'lines']
clone_dir = gitu.clone(url, pname)
file(os.path.join(clone_dir, "file"), 'w').write("\n".join(data))
gitu.add_commit_and_publish(clone_dir, "master", "Test commit",
fnames=["file"])
# Get the change id
change_ids = gu_first_u.get_my_changes_for_project(pname)
self.assertEqual(len(change_ids), 1)
change_id = change_ids[0]
# Merge the change
gu_first_u.submit_change_note(change_id, "current", "Code-Review", "2")
gu_first_u.submit_change_note(change_id, "current", "Verified", "2")
gu_first_u.submit_change_note(change_id, "current", "Workflow", "1")
second_u = config.USER_2
gu_second_u = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[second_u]['auth_cookie'])
self.assertTrue(gu_first_u.submit_patch(change_id, "current"))
# Change the file we have commited with Admin user
k2_index = gu_second_u.add_pubkey(config.USERS[second_u]["pubkey"])
priv_key_path = set_private_key(config.USERS[second_u]["privkey"])
gitu = GerritGitUtils(second_u,
priv_key_path,
config.USERS[second_u]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (second_u, config.GATEWAY_HOST,
pname)
clone_dir = gitu.clone(url, pname)
self.dirs_to_delete.append(os.path.dirname(clone_dir))
data = ['this', 'is', 'some', 'lines']
file(os.path.join(clone_dir, "file"), 'w').write("\n".join(data))
gitu.add_commit_and_publish(clone_dir, "master", "Test commit",
fnames=["file"])
# Get the change id
change_ids = gu_second_u.get_my_changes_for_project(pname)
self.assertEqual(len(change_ids), 1)
change_id = change_ids[0]
# Verify first_u has been automatically added to reviewers
attempts = 0
while True:
if len(gu_second_u.get_reviewers(change_id)) > 0 or attempts >= 3:
break
attempts += 1
time.sleep(1)
reviewers = gu_second_u.get_reviewers(change_id)
self.assertGreaterEqual(len(reviewers), 1)
self.assertTrue(first_u in reviewers)
gu_first_u.del_pubkey(k1_index)
gu_second_u.del_pubkey(k2_index)
示例4: test_check_zuul_operations
# 需要导入模块: from pysflib.sfgerrit import GerritUtils [as 别名]
# 或者: from pysflib.sfgerrit.GerritUtils import del_pubkey [as 别名]
#.........这里部分代码省略.........
pname = 'demo/zuul-demo'
self.create_project(pname, config.ADMIN_USER)
un = config.ADMIN_USER
gu = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[un]['auth_cookie'])
ju = JenkinsUtils()
k_index = gu.add_pubkey(config.USERS[un]["pubkey"])
# Gerrit part
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))
last_fail_build_num_ft = \
ju.get_last_build_number("zuul-demo-functional-tests",
"lastFailedBuild")
last_fail_build_num_ut = \
ju.get_last_build_number("zuul-demo-unit-tests",
"lastFailedBuild")
last_succeed_build_num_ft = \
ju.get_last_build_number("zuul-demo-functional-tests",
"lastSuccessfulBuild")
last_succeed_build_num_ut = \
ju.get_last_build_number("zuul-demo-unit-tests",
"lastSuccessfulBuild")
gitu.add_commit_and_publish(clone_dir, "master", "Test commit")
change_ids = gu.get_my_changes_for_project(pname)
self.assertGreater(len(change_ids), 0)
change_id = change_ids[0]
# Give some time for jenkins to work
ju.wait_till_job_completes("zuul-demo-functional-tests",
last_fail_build_num_ft, "lastFailedBuild")
ju.wait_till_job_completes("zuul-demo-unit-tests",
last_fail_build_num_ut, "lastFailedBuild")
attempt = 0
while "jenkins" not in gu.get_reviewers(change_id):
if attempt >= 90:
break
time.sleep(1)
attempt += 1
attempt = 0
while gu.get_reviewer_approvals(change_id, 'jenkins')['Verified'] \
!= '-1':
if attempt >= 90:
break
time.sleep(1)
attempt += 1
self.assertEqual(
gu.get_reviewer_approvals(change_id, 'jenkins')['Verified'], '-1')
# Add the test case files and resubmit for review
data = "echo Working"
files = ["run_functional-tests.sh", "run_tests.sh"]
for f in files:
file(os.path.join(clone_dir, f), 'w').write(data)
os.chmod(os.path.join(clone_dir, f), 0755)
gitu.add_commit_and_publish(clone_dir, "master", None, fnames=files)
# Give some time for jenkins to work
ju.wait_till_job_completes("zuul-demo-functional-tests",
last_succeed_build_num_ft,
"lastSuccessfulBuild")
ju.wait_till_job_completes("zuul-demo-unit-tests",
last_succeed_build_num_ut,
"lastSuccessfulBuild")
attempt = 0
while "jenkins" not in gu.get_reviewers(change_id):
if attempt >= 90:
break
time.sleep(1)
attempt += 1
attempt = 0
while gu.get_reviewer_approvals(change_id, 'jenkins')['Verified'] \
!= '+1':
if attempt >= 90:
break
time.sleep(1)
attempt += 1
self.assertEqual(
gu.get_reviewer_approvals(change_id, 'jenkins')['Verified'], '+1')
gu.del_pubkey(k_index)
示例5: TestProjectReplication
# 需要导入模块: from pysflib.sfgerrit import GerritUtils [as 别名]
# 或者: from pysflib.sfgerrit.GerritUtils import del_pubkey [as 别名]
class TestProjectReplication(Base):
""" Functional tests to verify the gerrit replication feature
"""
def setUp(self):
self.msu = ManageSfUtils(config.GATEWAY_URL)
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.k_idx = self.gu2.add_pubkey(config.USERS[config.USER_2]["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'])
# Configuration to access mirror repo present in mysql
self.msql_repo_path = "ssh://%[email protected]%s/%s" \
% (config.GERRIT_USER, config.GATEWAY_HOST,
'home/gerrit/site_path/git/')
# prepare environment for git clone on mirror repo
self.mt = Tool()
self.mt_tempdir = tempfile.mkdtemp()
priv_key = file(config.GERRIT_SERVICE_PRIV_KEY_PATH, 'r').read()
priv_key_path = os.path.join(self.mt_tempdir, 'user.priv')
file(priv_key_path, 'w').write(priv_key)
os.chmod(priv_key_path, stat.S_IREAD | stat.S_IWRITE)
ssh_wrapper = "ssh -o StrictHostKeyChecking=no -i " \
"%s \"[email protected]\"" % priv_key_path
wrapper_path = os.path.join(self.mt_tempdir, 'ssh_wrapper.sh')
file(wrapper_path, 'w').write(ssh_wrapper)
os.chmod(wrapper_path, stat.S_IRWXU)
self.mt.env['GIT_SSH'] = wrapper_path
self.pname = 'test-replication'
def tearDown(self):
self.deleteConfigSection(self.un, self.pname)
self.deleteMirrorRepo(self.pname)
self.msu.deleteProject(self.pname, self.un)
self.gu2.del_pubkey(self.k_idx)
# Can't use GerritGitUtils.clone as not sure when source uri repo in mysql
# be ready.(i.e gerrit is taking time to create the mirror repo in mysql
# node) So this clone may succeed or fail, we don't need 'git review -s'
# and other review commands in clone method
def clone(self, uri, target):
self.assertTrue(uri.startswith('ssh://'))
cmd = "git clone %s %s" % (uri, target)
self.mt.exe(cmd, self.mt_tempdir)
clone = os.path.join(self.mt_tempdir, target)
return clone
def create_project(self, name, user, options=None):
self.msu.createProject(name, user, options)
def ssh_run_cmd(self, sshkey_priv_path, user, host, subcmd):
host = '%[email protected]%s' % (user, host)
sshcmd = ['ssh', '-o', 'LogLevel=ERROR',
'-o', 'StrictHostKeyChecking=no',
'-o', 'UserKnownHostsFile=/dev/null', '-i',
sshkey_priv_path, host]
cmd = sshcmd + subcmd
p = Popen(cmd, stdout=PIPE)
return p.communicate()
def deleteMirrorRepo(self, name):
sshkey_priv_path = config.GERRIT_SERVICE_PRIV_KEY_PATH
user = 'gerrit'
host = config.GATEWAY_HOST
mirror_path = '/home/gerrit/site_path/git/%s.git' % name
cmd = ['rm', '-rf', mirror_path]
self.ssh_run_cmd(sshkey_priv_path, user, host, cmd)
def createConfigSection(self, user, project):
# Section name will be node name and the project
section = 'mysql_%s' % project
host = '%[email protected]%s' % (config.GERRIT_USER, config.GATEWAY_HOST)
mirror_repo_path = '/home/gerrit/site_path/git/\${name}.git'
url = '%s:%s' % (host, mirror_repo_path)
self.msu.replicationModifyConfig(user, 'add', section,
'projects', project)
self.msu.replicationModifyConfig(user, 'add',
section, 'url', url)
push = '+refs/heads/*:refs/heads/*'
self.msu.replicationModifyConfig(user, 'add',
section, 'push', push)
push = '+refs/tags/*:refs/tags/*'
self.msu.replicationModifyConfig(user, 'add',
section, 'push', push)
def deleteConfigSection(self, user, project):
# section name will be node name and the project
section = 'managesf_%s' % project
self.msu.replicationModifyConfig(user, 'remove-section', section)
def mirror_clone_and_check_files(self, url, pname, us_files):
retries = 0
files = []
#.........这里部分代码省略.........
示例6: TestProjectReplication
# 需要导入模块: from pysflib.sfgerrit import GerritUtils [as 别名]
# 或者: from pysflib.sfgerrit.GerritUtils import del_pubkey [as 别名]
class TestProjectReplication(Base):
""" Functional tests to verify the gerrit replication feature
"""
def setUp(self):
self.msu = ManageSfUtils(config.GATEWAY_URL)
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.k_idx = self.gu2.add_pubkey(config.USERS[config.USER_2]["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'])
# Prepare environment for git clone on mirror repo
self.mt = Tool()
self.mt_tempdir = tempfile.mkdtemp()
# Copy the service private key in a flat file
priv_key = file(config.SERVICE_PRIV_KEY_PATH, 'r').read()
priv_key_path = os.path.join(self.mt_tempdir, 'user.priv')
file(priv_key_path, 'w').write(priv_key)
os.chmod(priv_key_path, stat.S_IREAD | stat.S_IWRITE)
# Prepare the ssh wrapper script
ssh_wrapper = "ssh -o StrictHostKeyChecking=no -i %s \"[email protected]\"" % (
priv_key_path)
wrapper_path = os.path.join(self.mt_tempdir, 'ssh_wrapper.sh')
file(wrapper_path, 'w').write(ssh_wrapper)
os.chmod(wrapper_path, stat.S_IRWXU)
# Set the wrapper as GIT_SSH env variable
self.mt.env['GIT_SSH'] = wrapper_path
self.config_clone_dir = None
# Project we are going to configure the replication for
self.pname = 'test/replication'
# Remove artifacts of previous run if any
self.delete_config_section(self.un, self.pname)
self.delete_mirror_repo(self.pname)
def tearDown(self):
self.delete_config_section(self.un, self.pname)
self.delete_mirror_repo(self.pname)
self.msu.deleteProject(self.pname, self.un)
self.gu2.del_pubkey(self.k_idx)
def clone(self, uri, target):
self.assertTrue(uri.startswith('ssh://'))
cmd = "git clone %s %s" % (uri, target)
clone = os.path.join(self.mt_tempdir, target)
if os.path.isdir(clone):
shutil.rmtree(clone)
self.mt.exe(cmd, self.mt_tempdir)
return clone
def create_project(self, name, user, options=None):
self.msu.createProject(name, user, options)
def ssh_run_cmd(self, sshkey_priv_path, user, host, subcmd):
host = '%[email protected]%s' % (user, host)
sshcmd = ['ssh', '-o', 'LogLevel=ERROR',
'-o', 'StrictHostKeyChecking=no',
'-o', 'UserKnownHostsFile=/dev/null', '-i',
sshkey_priv_path, host]
cmd = sshcmd + subcmd
p = Popen(cmd, stdout=PIPE)
return p.communicate(), p.returncode
def delete_mirror_repo(self, name):
mirror_path = '/home/gerrit/git/%s.git' % name
cmd = ['ssh', 'gerrit.%s' % config.GATEWAY_HOST,
'rm', '-rf', mirror_path]
self.ssh_run_cmd(config.SERVICE_PRIV_KEY_PATH,
'root',
config.GATEWAY_HOST, cmd)
def create_config_section(self, project):
host = '%[email protected]%s' % (config.GERRIT_USER, config.GATEWAY_HOST)
mirror_repo_path = '/home/gerrit/git/\${name}.git'
url = '%s:%s' % (host, mirror_repo_path)
path = os.path.join(self.config_clone_dir,
'gerrit/replication.config')
call("git config -f %s --remove-section remote.test_project" %
path, shell=True)
call("git config -f %s --add remote.test_project.projects %s" %
(path, project), shell=True)
call("git config -f %s --add remote.test_project.url %s" %
(path, url), shell=True)
self.gitu_admin.add_commit_for_all_new_additions(
self.config_clone_dir, "Add replication test section")
# The direct push will trigger the config-update job
# as we commit through 29418
self.gitu_admin.direct_push_branch(self.config_clone_dir, 'master')
attempts = 0
cmd = ['ssh', 'gerrit.%s' % config.GATEWAY_HOST, 'grep',
#.........这里部分代码省略.........