本文整理汇总了Python中utils.GerritGitUtils.clone方法的典型用法代码示例。如果您正苦于以下问题:Python GerritGitUtils.clone方法的具体用法?Python GerritGitUtils.clone怎么用?Python GerritGitUtils.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.GerritGitUtils
的用法示例。
在下文中一共展示了GerritGitUtils.clone方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_upstream
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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))
示例2: test_create_public_project_as_user_clone_as_user
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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: _prepare_review_submit_testing
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [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
示例4: test_create_private_project_as_admin_clone_as_admin
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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)
示例5: test_review_labels
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [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)
示例6: test_basic_ops_project_namespace
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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)
示例7: test_01_validate_gerrit_project_acls
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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: test_check_download_commands
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [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)
示例10: test_check_config_repo_exists
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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")))
示例11: test_create_public_project_as_admin_clone_as_admin
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
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)
示例12: test_replication
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [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)
示例13: test_check_add_automatic_reviewers
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [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)
示例14: __init__
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
class SFchecker:
""" This checker is only intended for testin
SF backup/restore and update. It checks that the user
data defined in resourses.yaml are present on the SF.
Those data must have been provisioned by SFProvisioner.
"""
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'])
def check_project(self, name):
print " Check project %s exists ..." % name,
if not self.gu.project_exists(name) or \
(is_present('SFRedmine') and not self.rm.project_exists(name)):
print "FAIL"
exit(1)
print "OK"
def check_files_in_project(self, name, files):
print " Check files(%s) exists in project ..." % ",".join(files),
# TODO(fbo); use gateway host instead of gerrit host
url = "ssh://%[email protected]%s:29418/%s" % (config.ADMIN_USER,
config.GATEWAY_HOST, name)
clone_dir = self.ggu.clone(url, name, config_review=False)
for f in files:
if not os.path.isfile(os.path.join(clone_dir, f)):
print "FAIL"
exit(1)
def check_issues_on_project(self, name, issues):
print " Check that at least %s issues exists for that project ...," %\
len(issues)
current_issues = self.rm.get_issues_by_project(name)
if len(current_issues) < len(issues):
print "FAIL: expected %s, project has %s" % (
len(issues), len(current_issues))
exit(1)
print "OK"
def check_jenkins_jobs(self, name, jobnames):
print " Check that jenkins jobs(%s) exists ..." % ",".join(jobnames),
for jobname in jobnames:
if not '%s_%s' % (name, jobname) in self.ju.list_jobs():
print "FAIL"
exit(1)
print "OK"
def check_reviews_on_project(self, name, issues):
reviews = [i for i in issues if i['review']]
print " Check that at least %s reviews exists for that project ..." %\
len(reviews),
pending_reviews = self.ggu.list_open_reviews(name, config.GATEWAY_HOST)
if not len(pending_reviews) >= len(reviews):
print "FAIL"
exit(1)
print "OK"
def check_pads(self, amount):
pass
def check_pasties(self, amount):
pass
def command(self, cmd):
return ssh_run_cmd(os.path.expanduser("~/.ssh/id_rsa"),
"root",
config.GATEWAY_HOST, shlex.split(cmd))
def compute_checksum(self, f):
out = self.command("md5sum %s" % f)[0]
if out:
return out.split()[0]
def read_file(self, f):
return self.command("cat %s" % f)[0]
def simple_login(self, user, password):
"""log as user"""
return get_cookie(user, password)
def check_users_list(self):
print "Check that users are listable ...",
users = [u['name'] for u in self.resources['users']]
c = {'auth_pubtkt': config.USERS[config.ADMIN_USER]['auth_cookie']}
url = 'http://%s/manage/project/membership/' % config.GATEWAY_HOST
registered = requests.get(url,
cookies=c).json()
#.........这里部分代码省略.........
示例15: TestProjectTestsWorkflow
# 需要导入模块: from utils import GerritGitUtils [as 别名]
# 或者: from utils.GerritGitUtils import clone [as 别名]
class TestProjectTestsWorkflow(Base):
""" Functional tests to verify the configuration of a project test
"""
@classmethod
def setUpClass(cls):
cls.msu = ManageSfUtils(config.GATEWAY_URL)
cls.sample_project_dir = \
os.path.join(config.SF_TESTS_DIR, "sample_project/")
@classmethod
def tearDownClass(cls):
pass
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")
def tearDown(self):
self.restore_config_repo(self.original_layout,
self.original_project,
self.original_zuul_projects)
for name in self.projects:
self.msu.deleteProject(name,
config.ADMIN_USER)
for dirs in self.dirs_to_delete:
shutil.rmtree(dirs)
def assert_reviewer_approvals(self, change_id, value):
approvals = {}
for _ in range(90):
approvals = self.gu.get_reviewer_approvals(change_id,
'jenkins')
if approvals and approvals.get('Verified') == value:
break
time.sleep(1)
self.assertEqual(value, approvals.get('Verified'))
def clone_as_admin(self, pname):
url = "ssh://%[email protected]%s:29418/%s" % (self.un, config.GATEWAY_HOST,
pname)
clone_dir = self.gitu_admin.clone(url, pname)
if os.path.dirname(clone_dir) not in self.dirs_to_delete:
self.dirs_to_delete.append(os.path.dirname(clone_dir))
return clone_dir
def restore_config_repo(self, layout, project, zuul):
file(os.path.join(
self.config_clone_dir, "zuul/layout.yaml"), 'w').write(
layout)
file(os.path.join(
self.config_clone_dir, "zuul/projects.yaml"), 'w').write(
zuul)
file(os.path.join(
self.config_clone_dir, "jobs/projects.yaml"), 'w').write(
project)
self.commit_direct_push_as_admin(
self.config_clone_dir,
"Restore layout.yaml and projects.yaml")
def commit_direct_push_as_admin(self, clone_dir, msg):
# Stage, commit and direct push the additions on master
self.gitu_admin.add_commit_for_all_new_additions(clone_dir, msg)
self.gitu_admin.direct_push_branch(clone_dir, 'master')
def push_review_as_admin(self, clone_dir, msg):
# Stage, commit and direct push the additions on master
self.gitu_admin.add_commit_for_all_new_additions(clone_dir, msg)
self.gitu_admin.review_push_branch(clone_dir, 'master')
def create_project(self, name, user,
options=None):
self.msu.createProject(name, user,
options)
self.projects.append(name)
def test_check_project_test_workflow(self):
#.........这里部分代码省略.........