Skip to content

Commit

Permalink
scripts: upgrade to python 3 - part 2
Browse files Browse the repository at this point in the history
This is the second batch of the python 3 upgrade changes.
This one focuces on httpserver API unit tests and most changes
revolve around changes to urllib.* modules.

The scripts have been tested by runnin following tests in
the root of the modules/httpserver-api directory:

- make check-http
- make check-ssl

Ref #1056

Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
  • Loading branch information
wkozaczuk committed Feb 21, 2020
1 parent e037d86 commit 93773a8
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion modules/httpserver-api/json2code.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import json
import sys
import re
Expand Down
2 changes: 1 addition & 1 deletion modules/httpserver-api/tests/api/testenv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import basetest

class testenv(basetest.Basetest):
Expand Down
8 changes: 4 additions & 4 deletions modules/httpserver-api/tests/api/testfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os
import urllib
import urllib.request, urllib.parse, urllib.error
import basetest
import subprocess

Expand Down Expand Up @@ -45,10 +45,10 @@ def test_file_status_cmd(self):

def test_put_file_cmd(self):
path = "/file"
self.curl(path + "/etc/hosts?op=COPY&destination="+urllib.quote("/etc/hosts1"), method='PUT')
self.curl(path + "/etc/hosts?op=COPY&destination="+urllib.parse.quote("/etc/hosts1"), method='PUT')
hosts = self.curl(path + "/etc/hosts1?op=GETFILESTATUS")
self.assertEqual(hosts["type"], "FILE")
self.curl(path + "/etc/hosts1?op=RENAME&destination="+urllib.quote("/etc/hosts2"), method='PUT')
self.curl(path + "/etc/hosts1?op=RENAME&destination="+urllib.parse.quote("/etc/hosts2"), method='PUT')
hosts = self.curl(path + "/etc/hosts2?op=GETFILESTATUS")
self.assertEqual(hosts["type"], "FILE")
self.assertHttpError(path + "/etc/hosts1?op=GETFILESTATUS")
Expand Down
2 changes: 1 addition & 1 deletion modules/httpserver-api/tests/api/testfs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import basetest

class testfs(basetest.Basetest):
Expand Down
2 changes: 1 addition & 1 deletion modules/httpserver-api/tests/api/testjolokia.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import basetest
import json

Expand Down
8 changes: 4 additions & 4 deletions modules/httpserver-api/tests/api/testjvm.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import time
import basetest
import urllib
import urllib.request, urllib.parse, urllib.error

class testjvm(basetest.Basetest):
def test_jvm_version(self):
Expand Down Expand Up @@ -31,14 +31,14 @@ def test_get_mbeans(self):

def test_get_mbean(self):
mbean = self.curl(self.path_by_nick(self.jvm_api, "getMbeanList") +
urllib.quote("java.lang:name=PS Old Gen,type=MemoryPool"))
urllib.parse.quote("java.lang:name=PS Old Gen,type=MemoryPool"))
self.assertGreaterEqual(len(mbean), 15)
self.assert_key_in("type", mbean[0])
self.assert_key_in("name", mbean[0])
self.assert_key_in("value", mbean[0])

def test_set_mbean(self):
path = self.path_by_nick(self.jvm_api, "getMbeanList") + urllib.quote("java.lang:name=PS Old Gen,type=MemoryPool")
path = self.path_by_nick(self.jvm_api, "getMbeanList") + urllib.parse.quote("java.lang:name=PS Old Gen,type=MemoryPool")
mbean = self.curl(path)
usage = next((item for item in mbean if item["name"] == "UsageThreshold"), None)
self.assertTrue(usage != None)
Expand Down
2 changes: 1 addition & 1 deletion modules/httpserver-api/tests/api/testnetwork.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import time
import basetest

Expand Down
8 changes: 4 additions & 4 deletions modules/httpserver-api/tests/api/testos.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import time
import basetest

class testos(basetest.Basetest):
def test_os_version(self):
path = self.path_by_nick(self.os_api, "os_version")
self.assertRegexpMatches(self.curl(path), r"v0\.\d+(-rc\d+)?(-\d+-[0-9a-z]+)?" , path)
self.assertRegex(self.curl(path), r"v0\.\d+(-rc\d+)?(-\d+-[0-9a-z]+)?" , path)

def test_vendor(self):
self.validate_path(self.os_api, "os_vendor", "Cloudius Systems")
Expand All @@ -18,8 +18,8 @@ def test_os_uptime(self):

def test_os_date(self):
path = self.path_by_nick(self.os_api, "os_date")
val = self.curl(path).encode('ascii', 'ignore')
self.assertRegexpMatches(val, "...\\s+...\\s+\\d+\\s+\\d\\d:\\d\\d:\\d\\d\\s+UTC\\s+20..", path)
val = self.curl(path)
self.assertRegex(val, "...\\s+...\\s+\\d+\\s+\\d\\d:\\d\\d:\\d\\d\\s+UTC\\s+20..", path)

def test_os_total_memory(self):
path = self.path_by_nick(self.os_api, "os_memory_total")
Expand Down
4 changes: 1 addition & 3 deletions modules/httpserver-api/tests/api/testtrace.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import basetest

class testtrace(basetest.Basetest):
Expand All @@ -17,14 +17,12 @@ def check_status_list(self, list):

def test_get_status(self):
status = self.curl(self.path + "/status")
self.assertGreaterEqual(status, 0)
self.check_status_list(status)

def test_set_status(self):
for bt in [True, False]:
for en in [True, False]:
status = self.curl(self.path + '/status?enabled=' + str(en) + '&backtrace=' + str(bt), method='POST')
self.assertGreaterEqual(status, 0)
self.check_status_list(status)
status = self.curl(self.path + "/status")
for s in status:
Expand Down
6 changes: 3 additions & 3 deletions modules/httpserver-api/tests/basetest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import json
import os
import subprocess
Expand Down Expand Up @@ -33,7 +33,7 @@ def get_json_api(cls, name):

@classmethod
def get_json_api_from_directory(cls, directory, name):
json_data = open(os.path.join(directory, name))
json_data = open(os.path.join(directory, name))
data = json.load(json_data)
json_data.close()
return data
Expand Down Expand Up @@ -83,7 +83,7 @@ def validate_path(self, api_definition, nickname, value):

def validate_path_regex(self, api_definition, nickname, expr):
path = self.path_by_nick(api_definition, nickname)
self.assertRegexpMatches(self.curl(path), expr)
self.assertRegex(self.curl(path), expr)

def assertHttpError(self, url, code=404):
try:
Expand Down
2 changes: 1 addition & 1 deletion modules/httpserver-api/tests/testhttpserver-api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
import argparse
import os
Expand Down

0 comments on commit 93773a8

Please sign in to comment.