]> review.fuel-infra Code Review - tools/sustaining.git/commitdiff
[Jenkins] Allow script to add centos repos. 52/29052/1
authorAnton Chevychalov <achevychalov@mirantis.com>
Wed, 30 Nov 2016 13:55:40 +0000 (16:55 +0300)
committerAnton Chevychalov <achevychalov@mirantis.com>
Wed, 30 Nov 2016 14:02:26 +0000 (17:02 +0300)
New parameter for deployment job ADD_CENT_REPO

Change-Id: Ic20b6516c9e987efa511edb6987a74ce9a1d6775

jenkins/build_cluster/build_cluster.py
jenkins/build_cluster/build_cluster_test.py
jenkins/build_cluster/config.xml
jenkins/build_cluster/repo_helper.sh [new file with mode: 0755]

index a279b9456a8110e98b04dcadfe988209f3bc8d18..54820cc4160bde6551314e16707ffd5ac1e45f82 100755 (executable)
@@ -16,6 +16,7 @@ import scancodes
 
 # CONST
 UPDATE_HELPER = "update_helper.sh"
+REPO_HELPER = "repo_helper.sh"
 SSH_PARAMS = ["-o", "UserKnownHostsFile=/dev/null",
               "-o", "StrictHostKeyChecking=no"]
 
@@ -60,6 +61,7 @@ if cfg["ISO_URL"]:
 
 cfg["PREPARE_CLUSTER"] = os.getenv("PREPARE_CLUSTER")
 cfg["UPDATE_FUEL"] = os.getenv("UPDATE_FUEL")
+cfg["ADD_CENT_REPO"] = os.getenv("ADD_CENT_REPO")
 cfg["RELEASE"] = os.getenv("RELEASE")
 cfg["HA"] = os.getenv("HA")
 cfg["NETWORK_TYPE"] = os.getenv("NETWORK_TYPE")
@@ -493,6 +495,20 @@ def sshpass(psw,ssh_cmd):
         return False
 
 
+def add_cent_repo(node, repolist):
+    if node.put_file(REPO_HELPER):
+        i = 1
+        for repo in repolist.split('\n'):
+            if not node.execute(["/tmp/"+REPO_HELPER,"add"+str(i), repo]):
+                print ("ERROR: Unable to add repo " + repo)
+                return False
+            i = i + 1
+        return True
+    else:
+        print ("ERROR: Unable to copy repo script to admin node")
+        return False
+
+
 def do_update(node):
     if node.put_file(UPDATE_HELPER):
         return node.execute(["/tmp/"+UPDATE_HELPER])
@@ -717,7 +733,10 @@ def main():
 
     admin_node=SSHHost(usr = cfg["FUEL_SSH_USERNAME"],
         subnet=cfg["ADMIN_SUBNET"],
-        psw = cfg["FUEL_SSH_PASSWORD"],)
+        pswd = cfg["FUEL_SSH_PASSWORD"],)
+
+    if cfg["ADD_CENT_REPO"]!="":
+        add_cent_repo(cfg["ADD_CENT_REPO"])
 
     if cfg["UPDATE_FUEL"]=="true":
         if do_update(admin_node):
index 53e6571456317abbc6230e339705814bbf36bbdf..3c035e65e11fc0cdc0f3b3eed7d1b6d05350436c 100755 (executable)
@@ -12,7 +12,7 @@ def test_bool(name, func):
     if func:
         print "\033[32mOK\033[00m   - "+name
     else:
-        print "\033[31mOK\033[00m   - "+name
+        print "\033[31mFAIL\033[00m   - "+name
 
 
 def main():
@@ -41,7 +41,27 @@ def main():
     # NOTE: can take too many time...
     test_bool("do update",
               build_cluster.do_update (node))
+    repolist='''http://mirror.fuel-infra.org/mos-repos/centos/mos9.0-centos7/updates/x86_64/
+    http://mirror.fuel-infra.org/mos-repos/centos/mos9.0-centos7/security/x86_64/
+    '''
 
+    test_bool("add repo",
+              build_cluster.add_cent_repo(node,repolist))
+
+    test_bool("add repo helper file",
+              node.execute(["test", "-f","/tmp/repo_helper.sh"]))
+
+    test_bool("add repo check repo file 1",
+              node.execute(["test", "-f","/etc/yum.repos.d/add1.repo"]))
+
+    test_bool("add repo rm repo file 1",
+              node.execute(["rm", "-f","/etc/yum.repos.d/add1.repo"]))
+
+    test_bool("add repo check repo file 2",
+              node.execute(["test", "-f","/etc/yum.repos.d/add2.repo"]))
+
+    test_bool("add repo rm repo file 2",
+              node.execute(["rm", "-f","/etc/yum.repos.d/add2.repo"]))
 
 if __name__ == "__main__":
     main()
index 49fd4f7a52542321eda7f2645e642b07671860c6..8262105dce996f15b33186b57d5594b4640454e3 100644 (file)
           <description>Tag is used in name of build.</description>
           <defaultValue></defaultValue>
         </hudson.model.StringParameterDefinition>
-        <hudson.model.StringParameterDefinition>
+        <jp.ikedam.jenkins.plugins.extensible__choice__parameter.ExtensibleChoiceParameterDefinition plugin="extensible-choice-parameter@1.3.2">
           <name>ISO_URL</name>
-          <description>Required! Can be direct URL or URL to torrent-file. Public ISOs are available here - &lt;b&gt;http://vault.infra.mirantis.net/&lt;/b&gt;</description>
-          <defaultValue></defaultValue>
-        </hudson.model.StringParameterDefinition>
+          <description>&lt;b&gt;&lt;a href=&quot;http://vault.infra.mirantis.net/&quot;&gt;http://vault.infra.mirantis.net/&lt;/a&gt;&lt;/b&gt; - public ISOs are available here.
+Required! Can be direct URL or URL to torrent-file. </description>
+          <editable>true</editable>
+          <choiceListProvider class="jp.ikedam.jenkins.plugins.extensible_choice_parameter.TextareaChoiceListProvider">
+            <choiceList class="java.util.RandomAccessSubList">
+              <l class="java.util.Arrays$ArrayList">
+                <a class="string-array">
+                  <string>http://vault.infra.mirantis.net/MirantisOpenStack-9.0.iso.torrent</string>
+                  <string>http://vault.infra.mirantis.net/MirantisOpenStack-8.0.iso.torrent</string>
+                  <string>http://vault.infra.mirantis.net/MirantisOpenStack-7.0.iso.torrent</string>
+                  <string>http://vault.infra.mirantis.net/MirantisOpenStack-6.1.iso.torrent</string>
+                  <string>http://vault.infra.mirantis.net/MirantisOpenStack-5.1.1.iso.torrent</string>
+                  <string></string>
+                </a>
+              </l>
+              <offset>0</offset>
+              <size>5</size>
+            </choiceList>
+          </choiceListProvider>
+        </jp.ikedam.jenkins.plugins.extensible__choice__parameter.ExtensibleChoiceParameterDefinition>
         <hudson.model.StringParameterDefinition>
           <name>NODES_COUNT</name>
           <description>Quantity of cluster nodes without fuel-master node.</description>
         </hudson.model.BooleanParameterDefinition>
         <hudson.model.BooleanParameterDefinition>
           <name>UPDATE_FUEL</name>
-          <description>Update fuel version to latest MU (7.0 and 8.0 only)</description>
+          <description>Update fuel version to latest MU (7.0 and 8.0 only) or upgrade release 9.x (9.0 to 9.1)</description>
           <defaultValue>false</defaultValue>
         </hudson.model.BooleanParameterDefinition>
+        <hudson.model.TextParameterDefinition>
+          <name>ADD_CENT_REPO</name>
+          <description>Add repo url. One per line. It will be added as add&lt;i&gt;.repo</description>
+          <defaultValue></defaultValue>
+        </hudson.model.TextParameterDefinition>
         <hudson.model.ChoiceParameterDefinition>
           <name>NETWORK_TYPE</name>
           <description>Choose a network type or leave it empty</description>
 export ENV_NAME=${BUILD_USER_ID}-${BUILD_NUMBER}
 export PYTHONUNBUFFERED=1
 curl -o ./build_cluster.py &quot;https://raw.githubusercontent.com/Mirantis/tools-sustaining/master/jenkins/build_cluster/build_cluster.py&quot;
-curl -o ./update_helper.sh &quot;https://raw.githubusercontent.com/Mirantis/tools-sustaining/master/jenkins/build_cluster/update_helper.sh&quot;
 curl -o ./scancodes.py &quot;https://raw.githubusercontent.com/Mirantis/tools-sustaining/master/jenkins/build_cluster/scancodes.py&quot;
+curl -o ./update_helper.sh &quot;https://raw.githubusercontent.com/Mirantis/tools-sustaining/master/jenkins/build_cluster/update_helper.sh&quot;
+curl -o ./update_helper.sh &quot;https://raw.githubusercontent.com/Mirantis/tools-sustaining/master/jenkins/build_cluster/repo_helper.sh&quot;
+
+chmod +x update_helper.sh
+chmod +x repo_helper.sh
 
 python build_cluster.py
 
@@ -163,4 +189,4 @@ python build_cluster.py --destroy
     </org.jenkinsci.plugins.buildnamesetter.BuildNameSetter>
     <org.jenkinsci.plugins.builduser.BuildUser plugin="build-user-vars-plugin@1.4"/>
   </buildWrappers>
-</project>
+</project>
\ No newline at end of file
diff --git a/jenkins/build_cluster/repo_helper.sh b/jenkins/build_cluster/repo_helper.sh
new file mode 100755 (executable)
index 0000000..06200dc
--- /dev/null
@@ -0,0 +1,11 @@
+#!/bin/bash
+
+[ -z "$2" ] && exit 
+
+cat > /etc/yum.repos.d/$1.repo <<-EOF
+[$1]
+name=$1
+baseurl=$2
+enabled=1
+gpgcheck=0
+EOF