]> review.fuel-infra Code Review - tools/sustaining.git/commitdiff
Small features and fixes 24/29924/3
authorAnton Chevychalov <achevychalov@mirantis.com>
Wed, 18 Jan 2017 15:52:10 +0000 (18:52 +0300)
committerAnton Chevychalov <achevychalov@mirantis.com>
Wed, 18 Jan 2017 16:01:45 +0000 (19:01 +0300)
* We can add pub keys now
* There is information about ssh access in summary
* Cleanup some garbage from spool

Change-Id: I0b41afe727f318288d3065b7ef4364a5c309e9fc

jenkins/build_cluster/build_cluster.py
jenkins/build_cluster/build_cluster_test.py
jenkins/build_cluster/config.xml
jenkins/build_cluster/update_helper.sh

index 030bdbcc9d70c3c774ba58279b5693b118d01f6d..d0f03a24bda1748d6d300140cec1cbdc815f641a 100755 (executable)
@@ -2,6 +2,7 @@
 
 from __future__ import print_function
 
+import io
 import os
 import re
 import signal
@@ -20,6 +21,7 @@ REPO_HELPER = "repo_helper.sh"
 SSH_PARAMS = ["-o", "UserKnownHostsFile=/dev/null",
               "-o", "StrictHostKeyChecking=no",
               "-o", "LogLevel=quiet"] # That supress most of warnings and info messages
+SSH_PUBKEYS_FILE = "keys.pub"
 DNS_SERVER = "172.18.16.10" #Moscow DNS
 
 cfg = dict()
@@ -67,6 +69,7 @@ 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")
+cfg["SSH_PUB_KEYS"] = os.getenv("SSH_PUB_KEYS")
 
 try:
     vconn = libvirt.open("qemu:///system")
@@ -89,6 +92,8 @@ class SSHHost:
 
         self.pswd=pswd
 
+        self._valid_key = re.compile('^ssh-rsa.*$')
+
     def _calculate_conn_line(self, usr, subnet):
         admip = str(subnet.ip + 2)
         return "{usr}@{admip}".format(usr=usr, admip=admip)
@@ -105,6 +110,17 @@ class SSHHost:
             ssh_cmd = ["scp"]+SSH_PARAMS+['./'+filename,self.conn_line+":"+dest],
         )
 
+    def put_ssh_pub_keys(self, keys):
+        with io.open(SSH_PUBKEYS_FILE, "wb") as ofile:
+            for key in keys.split('\n'):
+                if self._valid_key.match(key):
+                    ofile.write(key)
+                    ofile.write('\n')
+            ofile.close()
+
+        self.put_file(SSH_PUBKEYS_FILE)
+        return self.execute(["cat", "/tmp/" + SSH_PUBKEYS_FILE, ">>", "~/.ssh/authorized_keys"])
+
 
 def pprint_dict(subj):
     if not isinstance(subj, dict):
@@ -695,6 +711,8 @@ PUBLIC:
     print(summary)
     print ("\nFUEL ACCESS:\n\thttp://{0}:8000".format(
         str(cfg["PUBLIC_SUBNET"].ip + 2)))
+    print ("\nSSH ACCESS:\n\tssh root@{0}".format(
+        str(cfg["PUBLIC_SUBNET"].ip + 2)))
     print ("\nVNC CONSOLES:\n")
     for dom in vconn.listAllDomains():
         if dom.name().startswith(cfg["ENV_NAME"]):
@@ -758,6 +776,9 @@ def main():
     if cfg["ADD_CENT_REPO"]!="" and cfg["ADD_CENT_REPO"] is not None:
         add_cent_repo(admin_node,cfg["ADD_CENT_REPO"])
 
+    if cfg["SSH_PUB_KEYS"]!="" and cfg["SSH_PUB_KEYS"] is not None:
+        admin_node.put_ssh_pub_keys(cfg["SSH_PUB_KEYS"])
+
     if cfg["UPDATE_FUEL"]=="true":
         if do_update(admin_node):
             print("fuel update complete")
index 3c035e65e11fc0cdc0f3b3eed7d1b6d05350436c..ffb32153ee759c3e23c98a4b948b24b7e7d9fe1d 100755 (executable)
@@ -4,7 +4,7 @@ import build_cluster
 import netaddr
 
 
-CONNECT_LINE = "root@780_admin"
+CONNECT_LINE = "root@test_admin"
 PSWD = "r00tme"
 
 
@@ -38,7 +38,7 @@ def main():
     test_bool("scp put file check file",
               not node.execute(["test", "-f","/tmp/update_helper.sh"]))
 
-    # NOTE: can take too many time...
+   # 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/
@@ -63,5 +63,20 @@ def main():
     test_bool("add repo rm repo file 2",
               node.execute(["rm", "-f","/etc/yum.repos.d/add2.repo"]))
 
+    test_bool("add pub keys",
+              node.put_ssh_pub_keys("""ssh-rsa AAAAB6NzaC1yc2EAAAADAQABAAABAQC8PWq76FFIKmxPGMdWErBMEFwtb2NZYeTxu1lMVacC1QemMMaoybNisvD+L4JyaiC+zFQzlHlCDgicCgw7TXkgFtoyttLMxbshcu+wx0uG8bMlQTZ5DZ7ywwBU7+OysSgBEvju1dlMF7wOKDcYLfJxbYoUYvq+tgVbBWBFm8q+PrMvZZGfPX5M6m/sdpiFc3/f1K6Hh+DeV+9hFx/2vES62Qwv76zzr7oGS3tAi2RyBFt6BWrJx9vqa25AAoqzRsHoj0+0iAi1reZQ3jvz3FIsfgVN+ymVv431X4Gr3H8+BMj56VpT5z8McXj9+o+qoK70YLrtg2z2IpSONOE7o3JX ac@achevychalov_
+
+XXXXXJJJJJJJJJ ac@achevycahlov
+ssh-rsa AAAAB7NzaC1yc2EAAAADAQABAAABAQC8PWq76FFIKmxPGMdWErBMEFwtb2NZYeTxu1lMVacC1QemMMaoybNisvD+L4JyaiC+zFQzlHlCDgicCgw7TXkgFtoyttLMxbshcu+wx0uG8bMlQTZ5DZ7ywwBU7+OysSgBEvju1dlMF7wOKDcYLfJxbYoUYvq+tgVbBWBFm8q+PrMvZZGfPX5M6m/sdpiFc3/f1K6Hh+DeV+9hFx/2vES62Qwv76zzr7oGS3tAi2RyBFt6BWrJx9vqa25AAoqzRsHoj0+0iAi1reZQ3jvz3FIsfgVN+ymVv431X4Gr3H8+BMj56VpT5z8McXj9+o+qoK70YLrtg2z2IpSONOE7o3JX ac@achevychalov_"""))
+
+    test_bool("add pub keys CHECK1",
+              node.execute(["egrep","-q","AAAAB6N", ".ssh/authorized_keys"]))
+
+    test_bool("add pub keys CHECK2",
+              node.execute(["egrep","-q","AAAAB7N", ".ssh/authorized_keys"]))
+
+    test_bool("add pub keys CHECK3",
+              not node.execute(["egrep","-q","XXXXXJ", ".ssh/authorized_keys"]))
+
 if __name__ == "__main__":
     main()
index 4165639c30e7f5b5a83c413ef8977e99e1ab8e5c..0e77719b14ca8e6f5e4ce47fd36741c9283c98c2 100644 (file)
@@ -113,6 +113,11 @@ Required! Can be direct URL or URL to torrent-file. </description>
             </a>
           </choices>
         </hudson.model.ChoiceParameterDefinition>
+        <hudson.model.TextParameterDefinition>
+          <name>SSH_PUB_KEYS</name>
+          <description>Add you keys to default value of job</description>
+          <defaultValue></defaultValue>
+        </hudson.model.TextParameterDefinition>
         <org.jvnet.jenkins.plugins.nodelabelparameter.LabelParameterDefinition plugin="nodelabelparameter@1.5.1">
           <name>Label of Slave</name>
           <description>You can choose where to deploy your cluster by typing exact slave label here.</description>
@@ -158,7 +163,7 @@ fi
 
 for file in build_cluster.py scancodes.py update_helper.sh repo_helper.sh; do
     #curl -o ./${file} &quot;https://raw.githubusercontent.com/Mirantis/tools-sustaining/master/jenkins/build_cluster/${file}&quot;
-    curl -o ./${file} &quot;https://review.fuel-infra.org/gitweb?p=tools/sustaining.git;a=blob_plain;f=jenkins/build_cluster/${file}${commit_url}&quot;
+    curl -s -o ./${file} &quot;https://review.fuel-infra.org/gitweb?p=tools/sustaining.git;a=blob_plain;f=jenkins/build_cluster/${file}${commit_url}&quot;
     chmod +x ${file}
 done;
 
index 8619f8570c9e732c94eac3bff07ebba3f8a88e7b..d1a6cd60f1280f9e8366fefcf60886399b21dffc 100755 (executable)
@@ -70,10 +70,11 @@ wait_for () {
     while true; do
                eval $1 && return 0
                ((cnt++))
-               echo -en "$cnt... "
+               echo -en "."
                [[ $cnt -eq $2 ]] && return 1
                sleep $3
        done;
+       echo ""
 }
 
 first_phase () {