Copilot commented on code in PR #13207:
URL: https://github.com/apache/cloudstack/pull/13207#discussion_r3571099127


##########
scripts/vm/systemvm/injectkeys.py:
##########
@@ -116,7 +116,7 @@ def copy_priv_key(newKey):
                return 0
        print ("Copying new private key file as it is not matching with old 
file")
        shutil.copyfile(newKey, currDir + pathSep + "id_rsa.cloud")
-       os.chmod(currDir + pathSep + "id_rsa.cloud", 0644)
+       os.chmod(currDir + pathSep + "id_rsa.cloud", 0o644)

Review Comment:
   `id_rsa.cloud` is a private key, but it's being installed with mode 0644 
(world-readable). This exposes the private key to any local user and is 
inconsistent with the XenServer patch permissions (0600).



##########
scripts/vm/hypervisor/xenserver/xenserver60/NFSSR.py:
##########
@@ -22,7 +22,7 @@
 import errno
 import os, re, sys
 import xml.dom.minidom
-import xmlrpclib
+import xmlrpc.client

Review Comment:
   This NFSSR plugin is transferred to XenServer hosts (xenserver60/patch) and 
is executed with `/usr/bin/python` (Python 2 on older XenServer). `import 
xmlrpc.client` is Python 3-only and will fail on Python 2; use a 2/3 compatible 
import while keeping existing `xmlrpc.client.*` call sites working.



##########
scripts/vm/hypervisor/xenserver/xenserver56/NFSSR.py:
##########
@@ -214,7 +214,7 @@ def _checkmount(self):
     def scan_exports(self, target):
         util.SMlog("scanning2 (target=%s)" % target)
         dom = nfs.scan_exports(target)
-        print >>sys.stderr,dom.toprettyxml()
+        print(dom.toprettyxml(), file=sys.stderr)

Review Comment:
   `print(..., file=sys.stderr)` is not valid syntax in Python 2 unless `from 
__future__ import print_function` is enabled. This NFSSR plugin is executed 
under `/usr/bin/python` on XenServer; write to `sys.stderr` for Python 2/3 
compatibility.



##########
scripts/vm/hypervisor/xenserver/xenserver60/NFSSR.py:
##########
@@ -216,11 +216,11 @@ def _checkmount(self):
     def scan_exports(self, target):
         util.SMlog("scanning2 (target=%s)" % target)
         dom = nfs.scan_exports(target)
-        print >>sys.stderr,dom.toprettyxml()
+        print(dom.toprettyxml(), file=sys.stderr)

Review Comment:
   `print(..., file=sys.stderr)` is not valid syntax in Python 2 unless `from 
__future__ import print_function` is enabled. Since this plugin is executed 
under `/usr/bin/python` on XenServer, write directly to `sys.stderr` for Python 
2/3 compatibility.



##########
scripts/vm/hypervisor/xenserver/xenserver56fp1/NFSSR.py:
##########
@@ -210,7 +210,7 @@ def _checkmount(self):
     def scan_exports(self, target):
         util.SMlog("scanning2 (target=%s)" % target)
         dom = nfs.scan_exports(target)
-        print >>sys.stderr,dom.toprettyxml()
+        print(dom.toprettyxml(), file=sys.stderr)

Review Comment:
   `print(..., file=sys.stderr)` is not valid syntax in Python 2 unless `from 
__future__ import print_function` is enabled. This NFSSR plugin is executed 
under `/usr/bin/python` on XenServer; write to `sys.stderr` for Python 2/3 
compatibility.



##########
scripts/vm/hypervisor/xenserver/xenserver56/InterfaceReconfigure.py:
##########
@@ -514,9 +514,7 @@ def save(self, cache_file):
         f.close()
 
     def get_pif_by_uuid(self, uuid):
-        pifs = map(lambda (ref,rec): ref,
-                  filter(lambda (ref,rec): uuid == rec['uuid'],
-                         self.__pifs.items()))
+        pifs = [ref_rec3[0] for ref_rec3 in [ref_rec for ref_rec in 
list(self.__pifs.items()) if uuid == ref_rec[1]['uuid']]]

Review Comment:
   The list comprehension used to replace the old `map/filter` is unnecessarily 
complex and makes this method hard to maintain. It can be simplified while 
keeping the same behavior.



##########
scripts/vm/hypervisor/xenserver/xenserver56/InterfaceReconfigure.py:
##########
@@ -47,7 +47,7 @@ def log(s):
     if get_log_destination() == 'syslog':
         syslog.syslog(s)
     else:
-        print >>sys.stderr, s
+        print(s, file=sys.stderr)

Review Comment:
   `print(..., file=sys.stderr)` is not valid syntax in Python 2 unless `from 
__future__ import print_function` is enabled. `InterfaceReconfigure.py` is 
shipped to XenServer hosts (see xenserver56/patch) where plugins run under 
Python 2; use `sys.stderr.write` for Python 2/3 compatibility.



##########
scripts/vm/hypervisor/xenserver/xenserver56/InterfaceReconfigure.py:
##########
@@ -525,14 +523,10 @@ def get_pif_by_uuid(self, uuid):
         return pifs[0]
 
     def get_pifs_by_device(self, device):
-        return map(lambda (ref,rec): ref,
-                   filter(lambda (ref,rec): rec['device'] == device,
-                          self.__pifs.items()))
+        return [ref_rec4[0] for ref_rec4 in [ref_rec1 for ref_rec1 in 
list(self.__pifs.items()) if ref_rec1[1]['device'] == device]]
 
     def get_pif_by_bridge(self, bridge):
-        networks = map(lambda (ref,rec): ref,
-                       filter(lambda (ref,rec): rec['bridge'] == bridge,
-                              self.__networks.items()))
+        networks = [ref_rec5[0] for ref_rec5 in [ref_rec2 for ref_rec2 in 
list(self.__networks.items()) if ref_rec2[1]['bridge'] == bridge]]

Review Comment:
   These comprehensions are much more complex than necessary, which hurts 
readability and increases maintenance risk. A direct tuple-unpacking 
comprehension is equivalent and clearer.



##########
scripts/vm/hypervisor/xenserver/xcpserver/NFSSR.py:
##########
@@ -209,7 +209,7 @@ def _checkmount(self):
     def scan_exports(self, target):
         util.SMlog("scanning2 (target=%s)" % target)
         dom = nfs.scan_exports(target)
-        print >>sys.stderr,dom.toprettyxml()
+        print(dom.toprettyxml(), file=sys.stderr)

Review Comment:
   `print(..., file=sys.stderr)` is not valid syntax in Python 2 unless `from 
__future__ import print_function` is enabled. This NFSSR plugin is executed 
under `/usr/bin/python` on XenServer; write to `sys.stderr` for Python 2/3 
compatibility.



##########
scripts/vm/hypervisor/xenserver/xcposs/NFSSR.py:
##########
@@ -210,7 +210,7 @@ def _checkmount(self):
     def scan_exports(self, target):
         util.SMlog("scanning2 (target=%s)" % target)
         dom = nfs.scan_exports(target)
-        print >>sys.stderr,dom.toprettyxml()
+        print(dom.toprettyxml(), file=sys.stderr)

Review Comment:
   `print(..., file=sys.stderr)` is not valid syntax in Python 2 unless `from 
__future__ import print_function` is enabled. This NFSSR plugin is executed 
under `/usr/bin/python` on XenServer; write to `sys.stderr` for Python 2/3 
compatibility.



##########
scripts/vm/hypervisor/xenserver/xcpserver83/NFSSR.py:
##########
@@ -224,7 +224,7 @@ def _checkmount(self):
     def scan_exports(self, target):
         util.SMlog("scanning2 (target=%s)" % target)
         dom = nfs.scan_exports(target)
-        print >>sys.stderr,dom.toprettyxml()
+        print(dom.toprettyxml(), file=sys.stderr)

Review Comment:
   `print(..., file=sys.stderr)` is not valid syntax in Python 2 unless `from 
__future__ import print_function` is enabled. This NFSSR plugin is executed 
under `/usr/bin/python` on XenServer; write to `sys.stderr` for Python 2/3 
compatibility.



##########
scripts/vm/hypervisor/ovm3/cloudstack.py:
##########
@@ -31,7 +31,7 @@
 import logging.handlers
 
 from xen.util.xmlrpcclient import ServerProxy
-from xmlrpclib import Error
+from xmlrpc.client import Error

Review Comment:
   This script has a `/usr/bin/python` shebang (Python 2 on OVM3 environments). 
Importing `Error` from `xmlrpc.client` is Python 3-only and will raise 
`ImportError` on Python 2. Use a small compatibility import so the script 
remains usable on both runtimes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to