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://%s@%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://%s@%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://%s@%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))
 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 managesf
     self.managesf_repo_path = "ssh://%s@%s/home/gerrit/git/" % (
         config.GERRIT_USER, config.GATEWAY_HOST)
     # 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 \"$@\"" % (
         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 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://%s@%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)
 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(
         config.GATEWAY_URL,
         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://%s@%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')))
Beispiel #5
0
    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://%s@%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)
Beispiel #6
0
    def _prepare_review_submit_testing(self, data=None):
        pname = 'p_%s' % create_random_str()
        self.create_project(pname)
        gu = GerritUtils(
            config.GATEWAY_URL,
            auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
        k_index = gu.add_pubkey(config.USERS[config.ADMIN_USER]["pubkey"])
        self.assertTrue(gu.project_exists(pname))
        priv_key_path = set_private_key(
            config.USERS[config.ADMIN_USER]["privkey"])
        gitu = GerritGitUtils(config.ADMIN_USER, priv_key_path,
                              config.USERS[config.ADMIN_USER]['email'])
        url = "ssh://%s@%s:29418/%s" % (config.ADMIN_USER, config.GATEWAY_HOST,
                                        pname)
        clone_dir = gitu.clone(url, pname)
        self.dirs_to_delete.append(os.path.dirname(clone_dir))

        if not data:
            gitu.add_commit_and_publish(clone_dir, "master", "Test commit")
        else:
            file(os.path.join(clone_dir, "file"), 'w').write(data[1])
            gitu.add_commit_and_publish(clone_dir,
                                        "master",
                                        "Test commit",
                                        fnames=[data[0]])

        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, pname
Beispiel #7
0
 def setUp(self):
     super(TestProjectTestsWorkflow, self).setUp()
     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 keep job/zuul config content
     self.config_clone_dir = self.clone_as_admin("config")
     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()
     self.need_restore_config_repo = False
     # Put USER_2 as core for config project
     self.gu.add_group_member(config.USER_2, "config-core")
 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")
Beispiel #9
0
 def setUp(self):
     super(TestLogExportedInElasticSearch, self).setUp()
     self.un = config.ADMIN_USER
     self.priv_key_path = set_private_key(config.USERS[self.un]["privkey"])
     self.gitu_admin = GerritGitUtils(self.un,
                                      self.priv_key_path,
                                      config.USERS[self.un]['email'])
Beispiel #10
0
    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("redmine"):
            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://%s@%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 has_issue_tracker():
            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)
Beispiel #11
0
    def setUp(self):
        super(TestRepoxplorer, self).setUp()
        priv_key_path = set_private_key(
            config.USERS[config.ADMIN_USER]["privkey"])
        self.gitu_admin = GerritGitUtils(
            config.ADMIN_USER, priv_key_path,
            config.USERS[config.ADMIN_USER]['email'])
        self.gu = GerritUtils(
            config.GATEWAY_URL,
            auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
        self.ju = JenkinsUtils()

        self.dirs_to_delete = []
Beispiel #12
0
 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.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.GATEWAY_URL + "/redmine/",
         auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
Beispiel #13
0
 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.msu = ManageSfUtils(config.GATEWAY_URL)
     self.ru = ResourcesUtils()
     self.ggu = GerritGitUtils(config.ADMIN_USER,
                               config.ADMIN_PRIV_KEY_PATH,
                               config.USERS[config.ADMIN_USER]['email'])
     self.stb_client = SFStoryboard(
         config.GATEWAY_URL + "/storyboard_api",
         config.USERS[config.ADMIN_USER]['auth_cookie'])
Beispiel #14
0
 def setUp(self):
     super(TestGerritHooks, self).setUp()
     self.projects = []
     self.dirs_to_delete = []
     self.issues = []
     self.u = config.ADMIN_USER
     self.rm = get_issue_tracker_utils(
         auth_cookie=config.USERS[config.ADMIN_USER]['auth_cookie'])
     self.gu = GerritUtils(config.GATEWAY_URL,
                           auth_cookie=config.USERS[self.u]['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'])
Beispiel #15
0
    def test_check_add_automatic_reviewers(self):
        """ Test if reviewers-by-blame plugin works
        """
        data = "this\nis\na\ncouple\nof\nlines"
        change_id, gu, k1_index, pname = self._prepare_review_submit_testing(
            ('file', data))

        # Merge the change
        gu.submit_change_note(change_id, "current", "Code-Review", "2")
        gu.submit_change_note(change_id, "current", "Verified", "2")
        gu.submit_change_note(change_id, "current", "Workflow", "1")
        self.assertTrue(gu.submit_patch(change_id, "current"))

        gu2 = GerritUtils(
            config.GATEWAY_URL,
            auth_cookie=config.USERS[config.USER_2]['auth_cookie'])
        # Change the file we have commited with Admin user
        k2_index = gu2.add_pubkey(config.USERS[config.USER_2]["pubkey"])
        priv_key_path = set_private_key(config.USERS[config.USER_2]["privkey"])
        gitu2 = GerritGitUtils(config.USER_2, priv_key_path,
                               config.USERS[config.USER_2]['email'])
        url = "ssh://%s@%s:29418/%s" % (config.USER_2, config.GATEWAY_HOST,
                                        pname)
        clone_dir = gitu2.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))
        gitu2.add_commit_and_publish(clone_dir,
                                     "master",
                                     "Test commit",
                                     fnames=["file"])
        # Get the change id
        change_ids = gu2.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
        for retry in xrange(3):
            if len(gu2.get_reviewers(change_id)) > 0:
                break
            time.sleep(1)
        reviewers = gu2.get_reviewers(change_id)
        self.assertEqual(len(reviewers), 1)
        self.assertEqual(reviewers[0], config.ADMIN_USER)

        gu.del_pubkey(k1_index)
        gu2.del_pubkey(k2_index)
 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 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://%s@%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")))
Beispiel #18
0
    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://%s@%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)
 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)
Beispiel #20
0
    def setUp(self):
        super(TestProjectReplication, self).setUp()
        self.ru = ResourcesUtils()
        self.un = config.ADMIN_USER
        self.ju = JenkinsUtils()
        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 \"$@\"" % (
            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)
Beispiel #21
0
 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://%s@%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))
Beispiel #22
0
    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://%s@%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
    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 %s ssh gerrit systemctl restart gerrit" %
             config.GATEWAY_HOST,
             shell=True)
        call("ssh %s ssh gerrit /root/wait4gerrit.sh" % config.GATEWAY_HOST,
             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://%s@%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
        repo_url = self.managesf_repo_path + '%s.git' % self.pname
        self.mirror_clone_and_check_files(repo_url, self.pname, us_files)
Beispiel #24
0
    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://%s@%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://%s@%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)
Beispiel #25
0
    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 = '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://%s@%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.assertEqual(len(change_ids), 1)
        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)