From 248681f1811c6484b525da0b893899f1eba74cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Danyi?= Date: Thu, 8 Feb 2018 11:44:04 +0100 Subject: [PATCH] * initial commit --- .bundle/config | 3 ++ .gitignore | 5 +++ Gemfile | 6 ++++ Gemfile.lock | 71 +++++++++++++++++++++++++++++++++++++++++ config.yaml.dist | 25 +++++++++++++++ cron.rb | 72 ++++++++++++++++++++++++++++++++++++++++++ gerrit_client.rb | 26 +++++++++++++++ jenkins_client.rb | 35 ++++++++++++++++++++ jira_client.rb | 41 ++++++++++++++++++++++++ wiki_client.rb | 26 +++++++++++++++ wiki_template.mustache | 66 ++++++++++++++++++++++++++++++++++++++ 11 files changed, 376 insertions(+) create mode 100644 .bundle/config create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 config.yaml.dist create mode 100644 cron.rb create mode 100644 gerrit_client.rb create mode 100644 jenkins_client.rb create mode 100644 jira_client.rb create mode 100644 wiki_client.rb create mode 100644 wiki_template.mustache diff --git a/.bundle/config b/.bundle/config new file mode 100644 index 0000000..57d4641 --- /dev/null +++ b/.bundle/config @@ -0,0 +1,3 @@ +--- +BUNDLE_PATH: vendor/bundle +BUNDLE_DISABLE_SHARED_GEMS: '1' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a3d94c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.idea +vendor + +config.yaml +*.pstore diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..5a1caa5 --- /dev/null +++ b/Gemfile @@ -0,0 +1,6 @@ +source 'https://rubygems.org' +gem 'mustache' +gem 'httpclient' +gem 'jenkins_api_client' +gem 'jira-ruby' +gem 'mediawiki_api' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..d4dd718 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,71 @@ +GEM + remote: https://rubygems.org/ + specs: + activesupport (5.1.4) + concurrent-ruby (~> 1.0, >= 1.0.2) + i18n (~> 0.7) + minitest (~> 5.1) + tzinfo (~> 1.1) + concurrent-ruby (1.0.5) + domain_name (0.5.20170404) + unf (>= 0.0.5, < 1.0.0) + faraday (0.14.0) + multipart-post (>= 1.2, < 3) + faraday-cookie_jar (0.0.6) + faraday (>= 0.7.4) + http-cookie (~> 1.0.0) + faraday_middleware (0.12.2) + faraday (>= 0.7.4, < 1.0) + http-cookie (1.0.3) + domain_name (~> 0.5) + httpclient (2.8.3) + i18n (0.9.3) + concurrent-ruby (~> 1.0) + jenkins_api_client (1.5.3) + json (>= 1.0) + mixlib-shellout (>= 1.1.0) + nokogiri (~> 1.6) + socksify (>= 1.7.0) + terminal-table (>= 1.4.0) + thor (>= 0.16.0) + jira-ruby (1.5.0) + activesupport + multipart-post + oauth (~> 0.5, >= 0.5.0) + json (2.1.0) + mediawiki_api (0.7.1) + faraday (~> 0.9, >= 0.9.0) + faraday-cookie_jar (~> 0.0, >= 0.0.6) + faraday_middleware (~> 0.10, >= 0.10.0) + mini_portile2 (2.3.0) + minitest (5.11.3) + mixlib-shellout (2.3.2) + multipart-post (2.0.0) + mustache (1.0.5) + nokogiri (1.8.2) + mini_portile2 (~> 2.3.0) + oauth (0.5.4) + socksify (1.7.1) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) + thor (0.20.0) + thread_safe (0.3.6) + tzinfo (1.2.5) + thread_safe (~> 0.1) + unf (0.1.4) + unf_ext + unf_ext (0.0.7.5) + unicode-display_width (1.3.0) + +PLATFORMS + ruby + +DEPENDENCIES + httpclient + jenkins_api_client + jira-ruby + mediawiki_api + mustache + +BUNDLED WITH + 1.11.2 diff --git a/config.yaml.dist b/config.yaml.dist new file mode 100644 index 0000000..0599bcd --- /dev/null +++ b/config.yaml.dist @@ -0,0 +1,25 @@ +--- +jira: + url: "https://cc-jira.rnd.ki.sw.ericsson.se/" + user: "CSCFCOMP" + pass: + labelName: "Automated" + jql: 'filter=22843 AND issuetype = "Epic" AND status != "Done" AND (labels NOT IN("%s") OR labels IS EMPTY)' + maxResults: 100 + +wiki: + url: "https://wiki.lmera.ericsson.se/api.php" + user: "CSCFCOMP" + pass: + +gerrit: + url: "https://gerrit.ericsson.se/a/projects/cscf%2fcscf/branches/" + user: "cscfcomp" + pass: + +jenkins: + url: "https://fem029-eiffel021.rnd.ki.sw.ericsson.se:8443/jenkins/" + user: "CSCFCOMP" + pass: + email: "PDLCSCFCOM@pdl.internal.ericsson.com" + jobName: "CreateFeedbackLoop" diff --git a/cron.rb b/cron.rb new file mode 100644 index 0000000..d84bc8e --- /dev/null +++ b/cron.rb @@ -0,0 +1,72 @@ +# load bundler, so we can use locally installed gems +require 'rubygems' +require 'bundler/setup' + +require 'yaml' +require 'pstore' +BASEPATH = File.dirname(__FILE__).freeze +$config = YAML.load_file(BASEPATH + '/config.yaml').freeze +$store = PStore.new("jira_status.pstore") +$code = 0 + +require_relative 'jira_client' +require_relative 'gerrit_client' +require_relative 'jenkins_client' +require_relative 'wiki_client' + + +jira_client = JiraClient.new($config['jira']) +wiki_client = WikiClient.new($config['wiki']) +gerrit_client = GerritClient.new($config['gerrit']) +jenkins_client = JenkinsClient.new($config['jenkins']) + +jira_client.query_new_epics.map do |wp, key| + $store.transaction do + $store[key] = { + :gerrit_created => false, + :jenkins_created => false, + :wiki_created => false + } if $store[key] == nil + end + branch_name = "cscf_int_" + wp + "_compint" + + begin + puts key + " # Error creating gerrit branch: " + branch_name + $code = 1 + next + end unless $store.transaction do + begin + $store[key][:gerrit_created] = gerrit_client.create_new_git_branch branch_name + end unless $store[key][:gerrit_created] + $store[key][:gerrit_created] + end + + begin + puts key + " # Error creating jenkins job" + $code = 1 + next + end unless $store.transaction do + begin + $store[key][:jenkins_created] = jenkins_client.create_new_jenkins_jobs branch_name, wp + end unless $store[key][:jenkins_created] + $store[key][:jenkins_created] + end + + begin + puts key + " # Error creating WIKI page: " + "CSCF_" + wp.upcase + $code = 1 + next + end unless $store.transaction do + begin + $store[key][:wiki_created] = wiki_client.create_new_wiki_page "CSCF " + wp.upcase, wp, branch_name + end unless $store[key][:wiki_created] + $store[key][:wiki_created] + end + + begin + puts key + " # could not add label to the issue" + $code = 1 + end unless jira_client.set_epic_completed(key) +end + +exit $code diff --git a/gerrit_client.rb b/gerrit_client.rb new file mode 100644 index 0000000..f508a74 --- /dev/null +++ b/gerrit_client.rb @@ -0,0 +1,26 @@ +require 'httpclient' +require 'json' + + +class GerritClient + + def initialize(config) + @url = config['url'] + @user = config['user'] + @pass = config['pass'] + end + + def create_new_git_branch(branch_name) + gerrit = HTTPClient.new + gerrit.set_auth(@url, @user, @pass) + gerrit.force_basic_auth = true + + begin + gerrit_resp = gerrit.put(@url + branch_name, {:revision => 'cscf_int'}) + gerrit_parsed = JSON.parse(gerrit_resp.body) + gerrit_parsed['ref'] == 'refs/head/' + branch_name + rescue + return false + end + end +end diff --git a/jenkins_client.rb b/jenkins_client.rb new file mode 100644 index 0000000..4fb92b9 --- /dev/null +++ b/jenkins_client.rb @@ -0,0 +1,35 @@ +require 'jenkins_api_client' + + +class JenkinsClient + + def initialize(config) + @url = config['url'] + @user = config['user'] + @pass = config['pass'] + @email = config['email'] + @job_name = config['jobName'] + end + + def create_new_jenkins_jobs(branch_name, wp_name) + jenkins = JenkinsApi::Client.new( + :server_url => @url, + :username => @user, + :password => @pass + ) + + job_params = { + :GIT_BRANCH => branch_name, + :WPRELEASE => wp_name.upcase + "compint", + :FEEDBACK_LOOPS => "short,nightly,weekly", + :EMAIL_DISTRIBUTION_LIST => @email, + :TSP_LOOPS => nil, + :INCLUDE_WPTESTS_JOB_TSP => true, + :CBA_LOOPS => "cba-git", + :INCLUDE_WPTESTS_JOB_CBA => true, + :ENABLE_ESM => false, + :AM_LOCAL_REPO => "" + } + jenkins.job.build(@job_name, job_params) < 400 + end +end diff --git a/jira_client.rb b/jira_client.rb new file mode 100644 index 0000000..d51e596 --- /dev/null +++ b/jira_client.rb @@ -0,0 +1,41 @@ +require 'jira-ruby' + + +class JiraClient + + def initialize(config) + @label_name = config['labelName'] + @jira_filter = sprintf(config['jql'], @label_name) + @options = { + :username => config['user'], + :password => config['pass'], + :site => config['url'], + :context_path => '', + :auth_type => :basic, + :use_ssl => true + } + @max_results = config['maxResults'] + end + + def query_new_epics + jira = JIRA::Client.new(@options) + result = [] + jira.Issue.jql(@jira_filter, + fields: %w(summary description), + max_results: @max_results + ).each do |epic| + next unless epic.summary.downcase.start_with?("integrate") + wp_name = epic.summary.match /^integrate\s+(?:wp)?(.*?)\s*$/i + result.push ["wp" + wp_name[1].downcase, epic.key] + end + result + end + + def set_epic_completed(key) + jira = JIRA::Client.new(@options) + issue = jira.Issue.find(key) + labels = issue.labels + labels.push(@label_name) + issue.save({:fields => {:labels => labels}}) + end +end diff --git a/wiki_client.rb b/wiki_client.rb new file mode 100644 index 0000000..c916126 --- /dev/null +++ b/wiki_client.rb @@ -0,0 +1,26 @@ +require 'mustache' +require 'mediawiki_api' + + +class WikiClient < Mustache + + self.template_file = BASEPATH + '/wiki_template.mustache' + + def initialize(config) + @url = config['url'] + @user = config['user'] + @pass = config['pass'] + end + + def create_new_wiki_page(page_name, wp_name, branch_name) + begin + page_data = self.render({:wp_name => wp_name, :branch_name => branch_name}) + mediawiki = MediawikiApi::Client.new @url + mediawiki.log_in @user, @pass + response = mediawiki.create_page page_name, page_data + response['result'] == 'Success' + rescue + false + end + end +end diff --git a/wiki_template.mustache b/wiki_template.mustache new file mode 100644 index 0000000..8e3405e --- /dev/null +++ b/wiki_template.mustache @@ -0,0 +1,66 @@ +== {{wp_name}} CBA COMPONENT INTEGRATION == + +=== Dates === +* Start: 2018- - +* Finished: 2018- - + +=== Stream === +* WP Stream: {{branch_name}} + +=== TR - Trouble Reports reported === +{| class="wikitable sortable" +|- +! TR ID !! Heading !! Status +|- +| - || - || - +|- +|} + +=== Jira Tickets reported === +{| class="wikitable sortable" +|- +! Jira ID !! Heading !! Status +|- +| || || +|- +|} + +=== Component Integration === +==== CBA Components on the branch (GIT branch: {{branch_name}}) ==== +{| class="wikitable sortable" +|- +! Malins/Stigs specification !! Used right now on the branch !! Access to version !! Verified to work !! Status !! TR/Jira-case +|- +| || || || || || - +|- +|} + +=== Known issues === +{| class="wikitable sortable" +|- +! Component !! Issue Description !! Person Analyzing !! Status !! Jira-case / TR +|- +| || || || || +|- +|} +==== SS7CAF patch ==== +SS7CAF needs to be patched to avoid manual steps of package modification during upgrade.
+A workaround had been introduced by David Haraldsson, this way the patch is automatically applied during the package creation.
+The patch is stored under /proj/ims-cscf-misc/WP/WP440/WP440L_PATCH/ and is also available under the repository /repo/ss7caf-reboot
+A new python script “$TOOLS/env/cscf_env_DT/lib/python2.7/cscf/package/patches/ss7caf_upgrade_package_patch.py” is run after the upgrade package is created in “create_tlm_and_upgrade_package_in_ci.py” and in “build_and_package.py”.
+“$TOOLS/env/cscf_env_DT/lib/python2.7/cscf/package/patches/ss7caf_upgrade_package_patch.py” script contains the SS7CAF version in the following line:
+ self.patch_version="'''5.1.5-10'''" +'''If a new SS7CAF version is integrated then this line has to be modified, and the new patch has to be stored as well.
''' +The reason behind this patch is the SS7CAF has to be upgraded before the reboot of the processors otherwise the diameter links will not come up (See: 3.1.6 in SS7CAF Installation Instructions CPI).
+Jira ticket describing the fault: [https://cc-jira.rnd.ki.sw.ericsson.se/browse/CC-13934 CC-13934] + +=== PRIs === + +=== CI - Continuous Integration === +* [https://fem029-eiffel021.rnd.ki.sw.ericsson.se:8443/jenkins/view{{wp_name}}compint/ CI {{wp_name}} COMP] + +=== LSV Plan === +* [http://paipeviewer.lmera.ericsson.se/anatomy/viewer.jsp?file=CSCF/CSCF%2015B.ana LSV Plan] + +=== Veckans Leveranser / Weekly Delivery === +* [https://erilink.ericsson.se/eridoc/erl/objectId/09004cff87219835?docno=1/00671-FCP1306259Uen&action=current&format=excel8book Veckans Leveranser]