Merge "Add condition for docker pull operation"
diff --git a/src/com/mirantis/mk/Artifactory.groovy b/src/com/mirantis/mk/Artifactory.groovy
index 73ed80f..a840956 100644
--- a/src/com/mirantis/mk/Artifactory.groovy
+++ b/src/com/mirantis/mk/Artifactory.groovy
@@ -9,14 +9,15 @@
/**
* Make generic call using Artifactory REST API and return parsed JSON
*
- * @param art Artifactory connection object
- * @param uri URI which will be appended to artifactory server base URL
+ * @param art Artifactory connection object
+ * @param uri URI which will be appended to artifactory server base URL
* @param method HTTP method to use (default GET)
* @param data JSON data to POST or PUT
* @param headers Map of additional request headers
+ * @param prefix Default prefix "/api"
*/
-def restCall(art, uri, method = 'GET', data = null, headers = [:]) {
- def connection = new URL("${art.url}/api${uri}").openConnection()
+def restCall(art, uri, method = 'GET', data = null, headers = [:], prefix = '/api') {
+ def connection = new URL("${art.url}${prefix}${uri}").openConnection()
if (method != 'GET') {
connection.setRequestMethod(method)
}
@@ -84,6 +85,18 @@
}
/**
+ * Make PUT request using Artifactory REST API for helm charts
+ *
+ * @param art Artifactory connection object
+ * @param uri URI which will be appended to artifactory server base URL
+ * @param data JSON Data to PUT
+ * @param prefix Default prefix "/api" (empty values should be for this way)
+ */
+def restPut2(art, uri, prefix, data = null) {
+ return restCall(art, uri, 'PUT', data, ['Accept': '*/*'], prefix)
+}
+
+/**
* Make DELETE request using Artifactory REST API
*
* @param art Artifactory connection object
@@ -107,9 +120,9 @@
/**
* Query artifacts by properties
*
- * @param art Artifactory connection object
+ * @param art Artifactory connection object
* @param properties String or list of properties in key=value format
- * @param repo Optional repository to search in
+ * @param repo Optional repository to search in
*/
def findArtifactByProperties(art, properties, repo) {
query = parseProperties(properties)
@@ -444,7 +457,7 @@
* @param chartName Chart name
*/
def publishArtifactoryHelmChart(art, repoName, chartName){
- return restPut(art, "/repositories/${repoName}", "${chartName}")
+ return restPut2(art, "/${repoName}", "${chartName}")
}
/**
diff --git a/src/com/mirantis/mk/Galera.groovy b/src/com/mirantis/mk/Galera.groovy
index 382a72f..e6a34c1 100644
--- a/src/com/mirantis/mk/Galera.groovy
+++ b/src/com/mirantis/mk/Galera.groovy
@@ -396,4 +396,37 @@
def restoreGaleraDb(env) {
common.warningMsg("This method was renamed to 'restoreGaleraCluster'. Please change your pipeline to use this call instead! If you think that you really wanted to call 'restoreGaleraDb' you may be missing 'targetNode' parameter in you call.")
return restoreGaleraCluster(env)
+}
+
+/**
+ * Start first node in mysql cluster. Cluster members stay removed in mysql config, additional service restart will be needed once all nodes are up.
+ * https://docs.mirantis.com/mcp/q4-18/mcp-operations-guide/tshooting/
+ * tshoot-mcp-openstack/tshoot-galera/restore-galera-cluster/
+ * restore-galera-manually.html#restore-galera-manually
+ *
+ * @param env Salt Connection object or pepperEnv
+ * @param target last stopped Galera node
+ * @return output of salt commands
+ */
+def startFirstNode(env, target) {
+ def salt = new com.mirantis.mk.Salt()
+ def common = new com.mirantis.mk.Common()
+
+ // make sure that gcom parameter is empty
+ salt.cmdRun(env, target, "sed -i '/wsrep_cluster_address/ s/^#*/#/' /etc/mysql/my.cnf")
+ salt.cmdRun(env, target, "sed -i '/wsrep_cluster_address/a wsrep_cluster_address=\"gcomm://\"' /etc/mysql/my.cnf")
+
+ // start mysql service on the last node
+ salt.runSaltProcessStep(env, target, 'service.start', ['mysql'])
+
+ // wait until mysql service on the last node is up
+
+ common.retry(30, 10) {
+ value = getWsrepParameters(env, target, 'wsrep_evs_state')
+ if (value['wsrep_evs_state'] == 'OPERATIONAL') {
+ common.infoMsg('WSREP state: OPERATIONAL')
+ } else {
+ throw new Exception("Mysql service is not running please fix it.")
+ }
+ }
}
\ No newline at end of file
diff --git a/src/com/mirantis/mk/Git.groovy b/src/com/mirantis/mk/Git.groovy
index 9d2bdb7..5743a61 100644
--- a/src/com/mirantis/mk/Git.groovy
+++ b/src/com/mirantis/mk/Git.groovy
@@ -158,8 +158,7 @@
*
* @param sourceUrl Source git repository
* @param targetUrl Target git repository
- * @param credentialsId Credentials id to use for accessing source/target
- * repositories
+ * @param credentialsId Credentials id to use for accessing target repositories
* @param branches List or comma-separated string of branches to sync
* @param followTags Mirror tags
* @param pushSource Push back into source branch, resulting in 2-way sync
@@ -167,25 +166,54 @@
* @param gitEmail Email for creation of merge commits
* @param gitName Name for creation of merge commits
*/
-def mirrorGit(sourceUrl, targetUrl, credentialsId, branches, followTags = false, pushSource = false, pushSourceTags = false, gitEmail = 'jenkins@localhost', gitName = 'Jenkins') {
+def mirrorGit(sourceUrl, targetUrl, credentialsId, branches, followTags = false, pushSource = false, pushSourceTags = false, gitEmail = 'jenkins@localhost', gitName = 'Jenkins', sourceRemote = 'origin') {
def common = new com.mirantis.mk.Common()
def ssh = new com.mirantis.mk.Ssh()
if (branches instanceof String) {
branches = branches.tokenize(',')
}
+ // If both source and target repos are secured and accessible via http/https,
+ // we need to switch GIT_ASKPASS value when running git commands
+ def sourceAskPass
+ def targetAskPass
- ssh.prepareSshAgentKey(credentialsId)
- ssh.ensureKnownHosts(targetUrl)
+ def sshCreds = common.getCredentialsById(credentialsId, 'sshKey') // True if found
+ if (sshCreds) {
+ ssh.prepareSshAgentKey(credentialsId)
+ ssh.ensureKnownHosts(targetUrl)
+ sh "git config user.name '${gitName}'"
+ } else {
+ withCredentials([[$class : 'UsernamePasswordMultiBinding',
+ credentialsId : credentialsId,
+ passwordVariable: 'GIT_PASSWORD',
+ usernameVariable: 'GIT_USERNAME']]) {
+ sh """
+ set +x
+ git config --global credential.${targetUrl}.username \${GIT_USERNAME}
+ echo "echo \${GIT_PASSWORD}" > ${WORKSPACE}/${credentialsId}_askpass.sh
+ chmod +x ${WORKSPACE}/${credentialsId}_askpass.sh
+ git config user.name \${GIT_USERNAME}
+ """
+ sourceAskPass = env.GIT_ASKPASS ?: ''
+ targetAskPass = "${WORKSPACE}/${credentialsId}_askpass.sh"
+ }
+ }
sh "git config user.email '${gitEmail}'"
- sh "git config user.name '${gitName}'"
def remoteExistence = sh(script: "git remote -v | grep ${TARGET_URL} | grep target", returnStatus: true)
- if(remoteExistence != 0){
- // silently try to remove target
- sh(script:"git remote remove target", returnStatus: true)
- sh("git remote add target ${TARGET_URL}")
+ if(remoteExistence == 0) {
+ // silently try to remove target
+ sh(script: "git remote remove target", returnStatus: true)
}
- ssh.agentSh "git remote update --prune"
+ sh("git remote add target ${TARGET_URL}")
+ if (sshCreds) {
+ ssh.agentSh "git remote update --prune"
+ } else {
+ env.GIT_ASKPASS = sourceAskPass
+ sh "git remote update ${sourceRemote} --prune"
+ env.GIT_ASKPASS = targetAskPass
+ sh "git remote update target --prune"
+ }
for (i=0; i < branches.size; i++) {
branch = branches[i]
@@ -201,21 +229,41 @@
sh "git ls-tree target/${branch} && git merge --no-edit --ff target/${branch} || echo 'Target repository is empty, skipping merge'"
followTagsArg = followTags ? "--follow-tags" : ""
- ssh.agentSh "git push ${followTagsArg} target HEAD:${branch}"
+ if (sshCreds) {
+ ssh.agentSh "git push ${followTagsArg} target HEAD:${branch}"
+ } else {
+ sh "git push ${followTagsArg} target HEAD:${branch}"
+ }
if (pushSource == true) {
followTagsArg = followTags && pushSourceTags ? "--follow-tags" : ""
- ssh.agentSh "git push ${followTagsArg} origin HEAD:${branch}"
+ if (sshCreds) {
+ ssh.agentSh "git push ${followTagsArg} origin HEAD:${branch}"
+ } else {
+ sh "git push ${followTagsArg} origin HEAD:${branch}"
+ }
}
}
if (followTags == true) {
- ssh.agentSh "git push -f target --tags"
+ if (sshCreds) {
+ ssh.agentSh "git push -f target --tags"
+ } else {
+ sh "git push -f target --tags"
+ }
if (pushSourceTags == true) {
- ssh.agentSh "git push -f origin --tags"
+ if (sshCreds) {
+ ssh.agentSh "git push -f origin --tags"
+ } else {
+ sh "git push -f origin --tags"
+ }
}
}
sh "git remote rm target"
+ if (!sshCreds) {
+ sh "set +x; rm -f ${targetAskPass}"
+ sh "git config --global --unset credential.${targetUrl}.username"
+ }
}