def init_environment(): # Create the agent first globals()['puppet_agent'] = PuppetAgent(workspace = WORKSPACE, stub_branch = identity) puppet_agent.reset_branch(AGENT_BRANCH) puppet_agent[AGENT_BRANCH]( rewrite_file("VERSION", AGENT_BRANCH.replace("x", "30")), commit("Rewrite the version file for the agent repo!") ) # Now create each of the components for component, (constructor, branch) in COMPONENT_BRANCHES.items(): edited_name = component.replace("-", "_") globals()[edited_name] = constructor(workspace = WORKSPACE, puppet_agent = puppet_agent, stub_branch = identity, update_ref = False) globals()[edited_name].reset_branch(branch) globals()[edited_name].update_url(branch) prev_version = branch.replace("x", "30") next_version = branch.replace("x", "31") globals()[edited_name].in_repo(sequence( lambda : git('push --delete origin %s' % prev_version), lambda : git('tag --delete origin %s' % prev_version), )) globals()[edited_name][branch]( bump_version(prev_version), bump_version(next_version) ) tag_sha = globals()[edited_name].in_branch(branch, exec_stdout('git', 'rev-parse', 'HEAD^')).decode("utf-8") globals()[edited_name].in_repo(sequence( lambda : git('tag -a %s %s -m "Tagging to %s!"' % (prev_version, tag_sha, prev_version)), lambda : git('push origin --tags') )) puppet_agent[AGENT_BRANCH]( bump_component(component, "refs/tags/%s" % prev_version), commit("Pinning '%s' back to previous tag!" % component) )
def reset_component(component_repo): revert_new_maint_branch(component_repo) component_repo.update_url("master") component_repo["master"]( code_change("Creating a 'code-change' merge-base!")) latest = latest_maint_branch(component_repo) fix_version = to_fix_version(latest) component_repo[latest](git_action("reset --hard refs/heads/master"), bump_version(fix_version)) component_repo.update_url(latest) component_repo.in_branch( latest, sequence( delete_tag(fix_version), git_action("tag -a %s -m 'Setting up a z-release tag!'" % fix_version), push('--tags --force'))) # Push all changes made to the component to origin component_repo[latest](noop_action, push=True) component_repo["master"](noop_action, push=True) agent_repo = component_repo.puppet_agent latest = latest_maint_branch(agent_repo) agent_repo[latest]( bump_component(component_repo.component_name, "refs/tags/%s" % fix_version), commit("Pinning %s to the tag %s!" % (component_repo.component_name, fix_version)), )
def reset_component(component): branch = COMPONENT_BRANCHES[component.name][1] component.reset_branch(branch) version_to_bump = branch.replace("x", "10") component[branch]( bump_version(version_to_bump), commit("(packaging) Bump to %s" % version_to_bump) )
def setup_happy_cases(): init_environment() # facter, pxp-agent, and puppet will be the ones that need to be bumped for (component, branch) in [(facter, "3.6.x"), (puppet, "4.10.x"), (pxp_agent, "1.5.x")]: component[branch]( new_file("some_feature", "This is my feature"), commit("Created new feature to simulate a change!"), update_ref = True )
def setup_mcollective(): mcollective = MarionetteCollective(workspace=WORKSPACE, puppet_agent=puppet_agent, stub_prefix=BRANCH_PREFIX) mcollective.reset_branch("master") mcollective["master"]( new_file("some_random_file", "some random contents"), commit( "Creating some random commit to test the localization noop job!"))
def link_to_local_beaker(repo, branch): repo.reset_branch(branch) repo[branch]( map_lines( "acceptance/Gemfile", r"gem ['\"]beaker['\"]", const("gem 'beaker', *location_for('file:///%s')\n" % beaker.root), 1), commit( "Link beaker to local repo so that timing results can be printed"))
def setup_leatherman(): leatherman = Leatherman(workspace=WORKSPACE, puppet_agent=puppet_agent, stub_prefix=BRANCH_PREFIX) leatherman.reset_branch("master") leatherman["master"]( after_line( "curl/src/client.cc", r"throw http_exception\(_\(\"failed to create cURL handle.\"\)\)", const("%s_(\"BLAH MESSAGE FOR TRANSLATION\")" % (" " * 12))), commit("Setting up a test environment for POT file generation!"))
def setup_facter(): facter = Facter(workspace=WORKSPACE, puppet_agent=puppet_agent, stub_prefix=BRANCH_PREFIX) facter.reset_branch("master") facter["master"]( after_line( "lib/src/logging/logging.cc", r"log\(level::warning", const("%slog(level::warning, \"BLAH MESSAGE FOR TRANSLATION\")" % (" " * 16))), commit("Setting up a test environment for POT file generation!"))
def setup_puppet(): puppet = Puppet(workspace=WORKSPACE, puppet_agent=puppet_agent, stub_prefix=BRANCH_PREFIX) puppet.reset_branch("master") puppet["master"]( after_line( "lib/puppet/resource.rb", r"_\('", const("%smsg2 = _('Some dummy message for POT generation!')" % (" " * 4))), commit("Setting up a test environment for POT file generation!"))
def setup_libwhereami(): libwhereami = Libwhereami(workspace=WORKSPACE, puppet_agent=puppet_agent, stub_prefix=BRANCH_PREFIX) libwhereami.reset_branch("master") libwhereami["master"]( after_line( "lib/src/sources/lparstat_source.cc", r"lparstat executable not found", const("%sLOG_WARNING(\"BLAH MESSAGE FOR TRANSLATION\")" % (" " * 12))), commit("Setting up a test environment for POT file generation!"))
def setup_cpp_pcp_client(): cpp_pcp_client = CppPcpClient(workspace=WORKSPACE, puppet_agent=puppet_agent, stub_prefix=BRANCH_PREFIX) cpp_pcp_client.reset_branch("master") cpp_pcp_client["master"]( after_line( "lib/src/connector/connection.cc", r"WebSocket in 'connecting' state", const("%sLOG_WARNING(\"BLAH MESSAGE FOR TRANSLATION\")" % (" " * 12))), commit("Setting up a test environment for POT file generation!"))
def setup_pxp_agent(): pxp_agent = PxpAgent(workspace=WORKSPACE, puppet_agent=puppet_agent, stub_prefix=BRANCH_PREFIX) pxp_agent.reset_branch("master") pxp_agent["master"]( after_line( "lib/src/modules/task.cc", r"Downloading the task file from the master-uri", const("%sLOG_WARNING(\"BLAH MESSAGE FOR TRANSLATION\")" % (" " * 14))), commit("Setting up a test environment for POT file generation!"))
def update_url(self, branch, **kwargs): push_agent = kwargs.get('push_agent', False) kwargs['push'] = push_agent print("\n\nABOUT TO UPDATE COMPONENT %s's URL IN ITS COMPONENT.JSON FILE ..." % self.component_name) print("THIS WILL HAPPEN IN THE %s BRANCHES OF THE PUPPET AGENT" % ', '.join(self.pa_branches[branch])) component_url = super(Component, self.__class__)._git_url(self.github_user, self.name) for pa_branch in self.pa_branches[branch]: self.puppet_agent[pa_branch]( update_component_json(self.component_name, 'url', component_url), commit("Updated the '%s' component's url!" % self.component_name), **kwargs )
def __update_ref(self, branch, **kwargs): push_agent = kwargs.get('push_agent', False) kwargs['push'] = push_agent print("\n\nABOUT TO BUMP COMPONENT %s's REF IN ITS COMPONENT.JSON FILE ..." % self.component_name) print("THIS WILL HAPPEN IN THE %s BRANCHES OF THE PUPPET AGENT" % ', '.join(self.pa_branches[branch])) print("GETTING THE HEAD SHA FIRST ...") sha = self.in_branch(branch, git_head) print("\nNOW DOING THE BUMPS ...") for pa_branch in self.pa_branches[branch]: self.puppet_agent[pa_branch]( bump_component(self.component_name, sha), commit("Bumping '%s' to '%s'!" % (self.component_name, sha)), **kwargs )
def setup_test_environment(repo): def add_test_keys(line): indent = extract_indentation(line) if "nssm" in line: return "" return "%s%s\n%s%s" % (indent, "value_stream: 'experimental'", indent, "p_scm_user: '******'") def modify_branch_param(param_name): return modify_lines( "jenkii/jenkins-master-prod-1/projects/puppet-agent.yaml", r"%s: '[Mm]aster'" % param_name, "%s: 'localization-tests-master'" % param_name) repo["PA-1175"](after_lines( "jenkii/jenkins-master-prod-1/projects/puppet-agent.yaml", "p_dn_component_name", add_test_keys), modify_branch_param("p_component_branch"), modify_branch_param("p_dn_component_branch"), modify_branch_param("p_vanagon_branch"), commit("Set-up test deployment environment!"))
from workflow.utils import (commit, const) from test_scripts.test_utils import WORKSPACE facter = GitRepository("facter", ["3.6.x", "3.9.x", "master"], workspace=WORKSPACE) facter.reset_branches() facter.to_branch( "3.6.x", new_file("my_test_file", "1234\nIS\nNOT GOOD\nFOO"), modify_line("my_test_file", r"(\d*)", r"NUMBER: \g<1>"), remove_file("CMakeLists.txt"), rewrite_file("MAINTAINERS", "NO MAN"), new_file("test_after", "Line One\nLine Two\nLine Three"), after_lines("test_after", "Line", const("Some junk right below!")), new_file("test_before", "Line One\nLine Two\nLine Three"), before_lines("test_before", "Line", const("Some junk right before!")), rename_file("Rakefile", "MY_RAKEFILE"), delete_line("LICENSE", r"facter - Tool for collecting system facts."), delete_line("LICENSE", r"Licensed under the Apache License"), commit("Testing out some CRUD stuff!")) contents = facter.in_branch("3.6.x", read_file("CONTRIBUTING.md")) print("CONTRIBUTING CONTENTS:") print(contents) facter.in_branch( "3.6.x", new_file("Prompted_Push", "Prompting the 'git push'!"), )
def add_feature(feature_name, commit_msg): return sequence(new_file(feature_name, "contents"), commit(commit_msg))
def create_commit(msg): return sequence(new_file(uuid.uuid4().hex, "new temporary file"), commit(msg))
def no_version_case(): init_environment() facter["3.6.x"]( modify_line("CMakeLists.txt", r"FACTER VERSION \d.\d.\d", "FACTER VERSION bad_version"), commit("Put bogus version to trigger job failure") )
def setup_bad_ref_case(): init_environment() puppet_agent[AGENT_BRANCH]( bump_component("facter", "origin/3.6.x"), commit("Setting up bad ref case!") )
def bump_version_action(repo_name, branch): version_bumper = GitRepository.repo_metadata[repo_name][ 'version_bumper'] version_bumper(version)(repo_name, branch) commit("Bumping %s to %s!" % (repo_name, version))(repo_name, branch)
from workflow.actions.file_actions import * from workflow.repos.git_repository import * from workflow.constants import * from workflow.utils import (commit, const) from test_scripts.test_utils import WORKSPACE facter = GitRepository("facter", ["3.6.x", "3.9.x", "master"], workspace = WORKSPACE) facter.reset_branch("3.6.x") facter.to_branch( "3.6.x", new_file("Prompted_Push", "Prompting the git push!"), commit("Testing out the prompted push!"), prompt_push = True )
git, git_head, sequence, exec_stdout) from workflow.actions.repo_actions import (bump_version, bump_component) from workflow.actions.file_actions import (new_file, modify_line, rewrite_file) import os # The agent branch itself AGENT_BRANCH = "5.3.x" RELEASE_BRANCH = AGENT_BRANCH.replace("x", "50") + "-release" GITHUB_DIR = "%s/%s" % (os.environ['HOME'], "GitHub") WORKSPACE = "%s/%s" % (GITHUB_DIR, "puppet-agent-workflow/workspaces/PA-1762") # Create the agent first globals()['puppet_agent'] = PuppetAgent(workspace=WORKSPACE, stub_branch=identity, use_private_fork=True) puppet_agent.reset_branch(AGENT_BRANCH) puppet_agent.in_repo( sequence( lambda: git('branch -D %s' % RELEASE_BRANCH), lambda: git('checkout -b %s' % RELEASE_BRANCH), lambda: git('push --set-upstream origin %s --force' % RELEASE_BRANCH))) puppet_agent.in_repo( sequence( lambda: new_file("feature_one", "first feature")("", ""), lambda: new_file("feature_two", "second feature")("", ""), lambda: commit("Added some features to set-up stuff to merge-up") ("", ""), lambda: git("push")))