Merge changes Ic3741f89,I21472a39
authorMike Marchetti <mmarchetti@sandvine.com>
Fri, 17 Nov 2017 14:38:18 +0000 (15:38 +0100)
committerGerrit Code Review <root@osm.etsi.org>
Fri, 17 Nov 2017 14:38:18 +0000 (15:38 +0100)
* changes:
  add utilities for artifact cleanup
  systest makefile fixes

tools/cleanupBuilds.py [new file with mode: 0755]
tools/cleanupRepo.py [new file with mode: 0755]
tools/newtag.sh

diff --git a/tools/cleanupBuilds.py b/tools/cleanupBuilds.py
new file mode 100755 (executable)
index 0000000..2c44ae2
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/env python
+#
+#   Copyright 2017 Sandvine
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+#
+import requests
+import json
+import pprint
+import argparse
+
+from dateutil import parser
+from dateutil.tz import tzutc
+from datetime import datetime
+import time
+
+arg_parser=argparse.ArgumentParser(description="Tool to retrieve the latest build from the artifactory server")
+arg_parser.add_argument('branch')
+arg_parser.add_argument('--project',default='osm-stage_3')
+arg_parser.add_argument('--url',default='http://osm1.etsi.org:8081/')
+arg_parser.add_argument('--keep',default=5)
+arg_parser.add_argument('--password',default='')
+args = arg_parser.parse_args()
+
+url = args.url + 'artifactory/api/build/' + args.project + " :: " + args.branch
+
+resp = requests.get(url)
+jsonData = json.loads(resp.content)
+if 'buildsNumbers' not in jsonData:
+    print("Cannot find any valid builds")
+    exit(1)
+
+# first entry is the latest build
+buildlist = sorted(jsonData['buildsNumbers'], key=lambda x: int(x['uri'][1:]),reverse=True)
+print("total builds is {}".format(len(buildlist)))
+pprint.pprint(buildlist)
+
+if len(buildlist) < args.keep:
+    print("nothing to cleanup")
+    exit(0)
+
+def convert_to_ms(datetime):
+    #get the millisecond from the date/time
+    ms=datetime.split('.')[1].split('+')[0]
+    parser_out=parser.parse(datetime)
+    timeval=parser_out
+    tuple=int(time.mktime(timeval.timetuple()))
+    return (tuple*1000+int(ms)-(time.timezone*1000))
+
+def buildPost(dateInMS,buildNumber):
+    build = {}
+    data = {}
+    build['buildName'] = args.project + " :: " + args.branch
+    build['buildNumber'] = buildNumber
+    build['date'] = str(dateInMS)
+
+    data['buildsCoordinates'] = list()
+    data['buildsCoordinates'].append(build)
+    return data
+    
+delete_url = args.url + 'artifactory/ui/builds/buildsDelete'
+headers = {'Content-Type': 'application/json'}
+
+for entry in buildlist[int(args.keep):]:
+   ms = convert_to_ms(entry['started'])
+   buildNumber = entry['uri'].split('/')[1]
+   print("deleting build {} ms {}".format(args.project + " :: " + args.branch + '/' + buildNumber,ms))
+   postData = buildPost(ms,entry['uri'].split('/')[1])
+
+   requests.post(delete_url,data=json.dumps(postData),headers=headers,auth=('admin',args.password))
diff --git a/tools/cleanupRepo.py b/tools/cleanupRepo.py
new file mode 100755 (executable)
index 0000000..d25b5c5
--- /dev/null
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+#
+#   Copyright 2017 Sandvine
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+#
+import requests
+import json
+import pprint
+import argparse
+
+from dateutil import parser
+from dateutil.tz import tzutc
+from datetime import datetime
+import time
+
+arg_parser=argparse.ArgumentParser(description="Tool to retrieve the latest build from the artifactory server")
+arg_parser.add_argument('--branch',default=None)
+arg_parser.add_argument('repo')
+arg_parser.add_argument('--url',default='http://osm1.etsi.org:8081/')
+arg_parser.add_argument('--keep',default=5)
+arg_parser.add_argument('--password',default='')
+arg_parser.add_argument('--debug',default=None)
+
+args = arg_parser.parse_args()
+
+
+if args.branch:
+    url = args.url + 'artifactory/api/storage/' + args.repo + '/' + args.branch
+    delete_url = args.url + 'artifactory/' + args.repo + '/' + args.branch
+else:
+    url = args.url + 'artifactory/api/storage/' + args.repo
+    delete_url = args.url + 'artifactory/' + args.repo
+
+resp = requests.get(url)
+jsonData = json.loads(resp.content)
+
+# first entry is the latest build
+filtered_list = filter(lambda x: x['uri'].split('/')[1].isdigit(), jsonData['children'])
+folders_sorted = sorted(filtered_list, key=lambda x: int(x['uri'].split('/')[1]),reverse=True)
+
+if len(folders_sorted) < int(args.keep):
+    print("nothing to cleanup")
+    exit(0)
+
+
+for entry in folders_sorted[int(args.keep):]:
+    if args.debug:
+        print("going to delete {}".format(delete_url+entry['uri']))
+    else:
+        requests.delete(delete_url + entry['uri'], auth=('admin',args.password))
+
+
+# empty the trash can
+empty_trash_url=args.url + 'artifactory/ui/artifactactions/emptytrash'
+headers = {'Content-Type': 'application/json'}
+requests.post(empty_trash_url,headers=headers,auth=('admin',args.password))
+
+
index 2f114fe..124c261 100755 (executable)
@@ -25,7 +25,6 @@ if [ -z "$list" ]; then
 fi
 
 for i in $list; do
-    echo
     echo $i
     if [ ! -d $i ]; then
         git clone ssh://$USER@osm.etsi.org:29418/osm/$i