ansible: Correct variable filename for SLES12 in common role
[lttng-ci.git] / automation / update_standalone.py
index 6f7094c88fabd3d2d864a500024dd5b765481d03..d29afd9a3e200ad6dd86bd1611c9d77259bfebf0 100644 (file)
 """ This script is used to upgrade the base snapshot of standalone ci slaves """
 
 USERNAME = ''
-PASSWORD = ''
+APIKEY = ''
 JENKINS_URL = 'https://ci.lttng.org'
 
 DISTRO_LIST = ['el', 'sles', 'ubuntu']
 DEFAULT_DISTRO = 'ubuntu'
 DISTRO_COMMAND = {
-    'el': 'yum update -y && yum clean all',
+    'el': 'yum update -y && package-cleanup -y --oldkernels --count=2 && yum clean all',
     'sles': 'zypper --non-interactive refresh && zypper --non-interactive patch --auto-agree-with-licenses --with-interactive',
     'ubuntu': 'apt-get update && apt-get dist-upgrade -V -y && apt-get clean && apt-get --purge autoremove -y',
 }
@@ -43,7 +43,7 @@ SNAPSHOTXML = """
 import argparse
 import sys
 import libvirt
-#from jenkinsapi.jenkins import Jenkins
+from jenkinsapi.jenkins import Jenkins
 from time import sleep
 import paramiko
 import select
@@ -69,13 +69,25 @@ def main():
 
 
     # Get jenkibs connexion
-    #jenkins = Jenkins(JENKINS_URL, username=USERNAME, password=PASSWORD)
+    jenkins = Jenkins(JENKINS_URL, username=USERNAME, password=APIKEY)
 
     # Get jenkins node
-    #node = jenkins.get_node(instance_name)
+    print("Getting node %s from Jenkins..." % instance_name)
+    node = jenkins.get_node(instance_name)
+
+    if not node:
+        print("Could not get node %s on %s" % (instance_name, JENKINS_URL))
+        sys.exit(1)
+
+    # Check if node is idle
+    if not node.is_idle:
+        print("Node %s is not idle" % instance_name)
+        sys.exit(1)
+
 
     # Set node temporarily offline
-    #node.toggle_temporarily_offline('Down for upgrade to base snapshot')
+    if not node.is_temporarily_offline():
+        node.toggle_temporarily_offline('Down for upgrade to base snapshot')
 
     # Get libvirt connexion
     print("Opening libvirt connexion to %s..." % vmhost_name)
@@ -182,6 +194,10 @@ def main():
         print("Failed to create new snapshot.")
         sys.exit(1)
 
+    # Set node online in jenkins
+    if node.is_temporarily_offline():
+        node.toggle_temporarily_offline()
+
     # And we're done!
     print("All done!")
 
This page took 0.025804 seconds and 4 git commands to generate.