本文整理汇总了Python中utils.GerritGitUtils.add_commit_and_publish方法的典型用法代码示例。如果您正苦于以下问题:Python GerritGitUtils.add_commit_and_publish方法的具体用法?Python GerritGitUtils.add_commit_and_publish怎么用?Python GerritGitUtils.add_commit_and_publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.GerritGitUtils
的用法示例。
在下文中一共展示了GerritGitUtils.add_commit_and_publish方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_review_labels
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [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: _prepare_review_submit_testing
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [as 别名]
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
示例3: test_check_download_commands
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [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)
示例4: TestGerritHooks
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [as 别名]
class TestGerritHooks(Base):
""" Functional tests that validate Gerrit hooks.
"""
@classmethod
def setUpClass(cls):
cls.msu = ManageSfUtils(config.GATEWAY_URL)
@classmethod
def tearDownClass(cls):
pass
def setUp(self):
self.projects = []
self.dirs_to_delete = []
self.issues = []
self.u = config.ADMIN_USER
self.u2 = config.USER_2
self.rm = RedmineUtils(
config.GATEWAY_URL + "/redmine/",
auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
self.gu = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[self.u]['auth_cookie'])
self.gu2 = GerritUtils(
config.GATEWAY_URL,
auth_cookie=config.USERS[self.u2]['auth_cookie'])
self.gu.add_pubkey(config.USERS[self.u]["pubkey"])
priv_key_path = set_private_key(config.USERS[self.u]["privkey"])
self.gitu = GerritGitUtils(self.u,
priv_key_path,
config.USERS[self.u]['email'])
def tearDown(self):
for issue in self.issues:
self.rm.delete_issue(issue)
for name in self.projects:
self.msu.deleteProject(name, self.u)
for dirs in self.dirs_to_delete:
shutil.rmtree(dirs)
def create_project(self, name, user,
options=None):
self.msu.createProject(name, user,
options)
self.projects.append(name)
def _test_update_issue_hooks(self, comment_template, status):
""" A referenced issue in commit msg triggers the hook
"""
pname = 'p_%s' % create_random_str()
# Be sure the project does not exist
self.msu.deleteProject(pname, self.u)
# Create the project
self.create_project(pname, self.u)
# Put USER_2 as core for the project
self.gu.add_group_member(self.u2, "%s-core" % pname)
# Create an issue on the project
issue_id = self.rm.create_issue(pname, "There is a problem")
# Clone and commit something
url = "ssh://%[email protected]%s:29418/%s" % (self.u, config.GATEWAY_HOST,
pname)
clone_dir = self.gitu.clone(url, pname)
cmt_msg = comment_template % issue_id
self.gitu.add_commit_and_publish(clone_dir, 'master', cmt_msg)
# Check issue status (Gerrit hook updates the issue to in progress)
attempt = 0
while True:
if self.rm.test_issue_status(issue_id, 'In Progress'):
break
if attempt > 10:
break
time.sleep(1)
attempt += 1
self.assertTrue(self.rm.test_issue_status(issue_id, 'In Progress'))
self._test_merging(pname, issue_id, status)
def _test_merging(self, pname, issue_id, status):
# Get the change id and merge the patch
change_ids = self.gu.get_my_changes_for_project(pname)
self.assertGreater(len(change_ids), 0)
change_id = change_ids[0]
self.gu.submit_change_note(change_id, "current", "Code-Review", "2")
self.gu.submit_change_note(change_id, "current", "Workflow", "1")
self.gu.submit_change_note(change_id, "current", "Verified", "2")
self.gu2.submit_change_note(change_id, "current", "Code-Review", "2")
self.assertTrue(self.gu.submit_patch(change_id, "current"))
# Check issue status (Gerrit hook updates the issue to in progress)
attempt = 0
while True:
if self.rm.test_issue_status(issue_id, status):
break
if attempt > 10:
break
time.sleep(1)
#.........这里部分代码省略.........
示例5: test_check_add_automatic_reviewers
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [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)
示例6: TestProjectTestsWorkflow
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [as 别名]
#.........这里部分代码省略.........
last_build_num_ch, last_success_build_num_ch = 0, 1
attempt = 0
while last_build_num_ch != last_success_build_num_ch:
if attempt >= 90:
break
time.sleep(1)
last_build_num_ch = \
self.ju.get_last_build_number("config-check",
"lastBuild")
last_success_build_num_ch = \
self.ju.get_last_build_number("config-check",
"lastSuccessfulBuild")
attempt += 1
self.assertEqual(last_build_num_ch, last_success_build_num_ch)
# Check whether zuul sets verified to +2 after running the tests
# let some time to Zuul to update the test result to Gerrit.
self.assert_reviewer_approvals(change_id, '+2')
# verify whether zuul merged the patch
change = self.gu.get_change('config', 'master', change_id)
change_status = change['status']
attempt = 0
while change_status != 'MERGED':
if attempt >= 90:
break
time.sleep(1)
change = self.gu.get_change('config', 'master', change_id)
change_status = change['status']
attempt += 1
self.assertEqual(change_status, 'MERGED')
# Test post pipe line
# as the patch is merged, post pieline should run config-update job
# Wait for config-update to finish and verify the success
self.ju.wait_till_job_completes("config-update",
last_success_build_num_cu,
"lastSuccessfulBuild")
last_build_num_cu = \
self.ju.get_last_build_number("config-update",
"lastBuild")
last_success_build_num_cu = \
self.ju.get_last_build_number("config-update",
"lastSuccessfulBuild")
self.assertEqual(last_build_num_cu, last_success_build_num_cu)
# Retrieve the prev build number for pname-unit-tests
# Retrieve the prev build number for pname-functional-tests
last_success_build_num_sp_ut = \
self.ju.get_last_build_number("%s-unit-tests" % pname,
"lastSuccessfulBuild")
last_success_build_num_sp_ft = \
self.ju.get_last_build_number("%s-functional-tests" % pname,
"lastSuccessfulBuild")
# Test config-update
# config-update should have created jobs for pname
# Trigger tests on pname
# Send a review and check tests has been run
self.gitu_admin.add_commit_and_publish(
clone_dir, 'master', "Add useless file",
self.un)
# Wait for pname-unit-tests to finish and verify the success
self.ju.wait_till_job_completes("%s-unit-tests" % pname,
last_success_build_num_sp_ut,
"lastSuccessfulBuild")
# Wait for pname-functional-tests to end and check the success
self.ju.wait_till_job_completes("%s-functional-tests" % pname,
last_success_build_num_sp_ft,
"lastSuccessfulBuild")
# Check the unit tests succeed
last_build_num_sp_ut = \
self.ju.get_last_build_number("%s-unit-tests" % pname,
"lastBuild")
last_success_build_num_sp_ut = \
self.ju.get_last_build_number("%s-unit-tests" % pname,
"lastSuccessfulBuild")
self.assertEqual(last_build_num_sp_ut, last_success_build_num_sp_ut)
# Check the functional tests succeed
last_build_num_sp_ft = \
self.ju.get_last_build_number("%s-functional-tests" % pname,
"lastBuild")
last_success_build_num_sp_ft = \
self.ju.get_last_build_number("%s-functional-tests" % pname,
"lastSuccessfulBuild")
self.assertEqual(last_build_num_sp_ft, last_success_build_num_sp_ft)
# Get the change id
change_ids = self.gu.get_my_changes_for_project(pname)
self.assertGreater(len(change_ids), 0)
change_id = change_ids[0]
# let some time to Zuul to update the test result to Gerrit.
for i in range(90):
if "jenkins" in self.gu.get_reviewers(change_id):
break
time.sleep(1)
self.assert_reviewer_approvals(change_id, '+1')
示例7: test_check_zuul_operations
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [as 别名]
def test_check_zuul_operations(self):
""" Test if zuul verifies project correctly through zuul-demo project
"""
# zuul-demo - test project used exclusively to test zuul installation
# The necessary project descriptions are already declared in Jenkins
# and zuul
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
#.........这里部分代码省略.........
示例8: test_replication
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import add_commit_and_publish [as 别名]
def test_replication(self):
""" Test gerrit replication for review process
"""
# Be sure the project, mirror repo, project in config don't exist
self.deleteMirrorRepo(self.pname)
self.deleteConfigSection(self.un, self.pname)
self.msu.deleteProject(self.pname, self.un)
# Create the project
self.create_project(self.pname, self.un)
# Create new section for this project in replication.config
self.createConfigSection(self.un, self.pname)
# Force gerrit to read its known_hosts file. The only
# way to do that is by restarting gerrit. The Puppet Gerrit
# manifest will restart gerrit if a new entry in known_hosts_gerrit
# is discovered.
# This may take some time (gerrit in some condition take long
# to be fully up)
call("ssh [email protected] systemctl restart gerrit", shell=True)
call("ssh [email protected] /root/wait4gerrit.sh", shell=True)
# Clone the project and submit it for review
priv_key_path = set_private_key(config.USERS[self.un]["privkey"])
gitu = GerritGitUtils(self.un,
priv_key_path,
config.USERS[self.un]['email'])
url = "ssh://%[email protected]%s:29418/%s" % (self.un, config.GATEWAY_HOST,
self.pname)
clone_dir = gitu.clone(url, self.pname)
gitu.add_commit_and_publish(clone_dir, "master", "Test commit")
# Add 2 files and resubmit for review
data = "echo Working"
us_files = ["run_functional-tests.sh", "run_tests.sh"]
for f in us_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=us_files)
# Review the patch and merge it
change_ids = self.gu.get_my_changes_for_project(self.pname)
self.assertGreater(len(change_ids), 0)
change_id = change_ids[0]
self.gu.submit_change_note(change_id, "current", "Code-Review", "2")
self.gu.submit_change_note(change_id, "current", "Verified", "2")
self.gu.submit_change_note(change_id, "current", "Workflow", "1")
# Put USER_2 as core for config project
grp_name = '%s-core' % self.pname
self.gu.add_group_member(config.USER_2, grp_name)
self.gu2.submit_change_note(change_id, "current", "Code-Review", "2")
self.assertTrue(self.gu.submit_patch(change_id, "current"))
shutil.rmtree(clone_dir)
# Verify if gerrit automatically triggered replication
# Mirror repo(in mysql node) should have these latest changes
# Clone the mirror repo(from mysql) and check for the 2 files
msql_repo_url = self.msql_repo_path + '%s.git' % self.pname
self.mirror_clone_and_check_files(msql_repo_url, self.pname, us_files)