Browse Source

Remove locals() from virt directory

fixes bug 1171936

Change-Id: Id91f2fd516f57970d3af59c1bae6e8da46c5482c
Eugene Nikanorov 5 years ago
parent
commit
03df827e78

+ 1
- 1
nova/virt/baremetal/ipmi.py View File

@@ -133,7 +133,7 @@ class IPMI(base.PowerManager):
133 133
             args.extend(command.split(" "))
134 134
             out, err = utils.execute(*args, attempts=3)
135 135
             LOG.debug(_("ipmitool stdout: '%(out)s', stderr: '%(err)s'"),
136
-                      locals())
136
+                      {'out': out, 'err': err})
137 137
             return out, err
138 138
         finally:
139 139
             bm_utils.unlink_without_raise(pwfile)

+ 7
- 4
nova/virt/baremetal/utils.py View File

@@ -39,7 +39,7 @@ def inject_into_image(image, key, net, metadata, admin_password,
39 39
                 files, partition, use_cow)
40 40
     except Exception as e:
41 41
         LOG.warn(_("Failed to inject data into image %(image)s. "
42
-                   "Error: %(e)s") % locals())
42
+                   "Error: %(e)s"), {'image': image, 'e': e})
43 43
 
44 44
 
45 45
 def unlink_without_raise(path):
@@ -49,7 +49,8 @@ def unlink_without_raise(path):
49 49
         if e.errno == errno.ENOENT:
50 50
             return
51 51
         else:
52
-            LOG.warn(_("Failed to unlink %(path)s, error: %(e)s") % locals())
52
+            LOG.warn(_("Failed to unlink %(path)s, error: %(e)s"),
53
+                     {'path': path, 'e': e})
53 54
 
54 55
 
55 56
 def rmtree_without_raise(path):
@@ -57,7 +58,8 @@ def rmtree_without_raise(path):
57 58
         if os.path.isdir(path):
58 59
             shutil.rmtree(path)
59 60
     except OSError as e:
60
-        LOG.warn(_("Failed to remove dir %(path)s, error: %(e)s") % locals())
61
+        LOG.warn(_("Failed to remove dir %(path)s, error: %(e)s"),
62
+                 {'path': path, 'e': e})
61 63
 
62 64
 
63 65
 def write_to_file(path, contents):
@@ -73,7 +75,8 @@ def create_link_without_raise(source, link):
73 75
             return
74 76
         else:
75 77
             LOG.warn(_("Failed to create symlink from %(source)s to %(link)s"
76
-                       ", error: %(e)s") % locals())
78
+                       ", error: %(e)s"),
79
+                     {'source': source, 'link': link, 'e': e})
77 80
 
78 81
 
79 82
 def random_alnum(count):

+ 1
- 1
nova/virt/disk/api.py View File

@@ -93,7 +93,7 @@ for s in CONF.virt_mkfs:
93 93
 
94 94
 def mkfs(os_type, fs_label, target):
95 95
     mkfs_command = (_MKFS_COMMAND.get(os_type, _DEFAULT_MKFS_COMMAND) or
96
-                    '') % locals()
96
+                    '') % {'fs_label': fs_label, 'target': target}
97 97
     if mkfs_command:
98 98
         utils.execute(*mkfs_command.split(), run_as_root=True)
99 99
 

+ 6
- 2
nova/virt/disk/mount/api.py View File

@@ -40,7 +40,9 @@ class Mount(object):
40 40
     def instance_for_format(imgfile, mountdir, partition, imgfmt):
41 41
         LOG.debug(_("Instance for format imgfile=%(imgfile)s "
42 42
                     "mountdir=%(mountdir)s partition=%(partition)s "
43
-                    "imgfmt=%(imgfmt)s") % locals())
43
+                    "imgfmt=%(imgfmt)s"),
44
+                  {'imgfile': imgfile, 'mountdir': mountdir,
45
+                   'partition': partition, 'imgfmt': imgfmt})
44 46
         if imgfmt == "raw":
45 47
             LOG.debug(_("Using LoopMount"))
46 48
             return importutils.import_object(
@@ -56,7 +58,9 @@ class Mount(object):
56 58
     def instance_for_device(imgfile, mountdir, partition, device):
57 59
         LOG.debug(_("Instance for device imgfile=%(imgfile)s "
58 60
                     "mountdir=%(mountdir)s partition=%(partition)s "
59
-                    "device=%(device)s") % locals())
61
+                    "device=%(device)s"),
62
+                  {'imgfile': imgfile, 'mountdir': mountdir,
63
+                   'partition': partition, 'device': device})
60 64
         if "loop" in device:
61 65
             LOG.debug(_("Using LoopMount"))
62 66
             return importutils.import_object(

+ 3
- 2
nova/virt/disk/vfs/api.py View File

@@ -25,8 +25,9 @@ class VFS(object):
25 25
     @staticmethod
26 26
     def instance_for_image(imgfile, imgfmt, partition):
27 27
         LOG.debug(_("Instance for image imgfile=%(imgfile)s "
28
-                    "imgfmt=%(imgfmt)s partition=%(partition)s")
29
-                  % locals())
28
+                    "imgfmt=%(imgfmt)s partition=%(partition)s"),
29
+                  {'imgfile': imgfile, 'imgfmt': imgfmt,
30
+                   'partition': partition})
30 31
         hasGuestfs = False
31 32
         try:
32 33
             LOG.debug(_("Trying to import guestfs"))

+ 11
- 8
nova/virt/disk/vfs/guestfs.py View File

@@ -151,27 +151,27 @@ class VFSGuestFS(vfs.VFS):
151 151
         return path
152 152
 
153 153
     def make_path(self, path):
154
-        LOG.debug(_("Make directory path=%(path)s") % locals())
154
+        LOG.debug(_("Make directory path=%s"), path)
155 155
         path = self._canonicalize_path(path)
156 156
         self.handle.mkdir_p(path)
157 157
 
158 158
     def append_file(self, path, content):
159
-        LOG.debug(_("Append file path=%(path)s") % locals())
159
+        LOG.debug(_("Append file path=%s"), path)
160 160
         path = self._canonicalize_path(path)
161 161
         self.handle.write_append(path, content)
162 162
 
163 163
     def replace_file(self, path, content):
164
-        LOG.debug(_("Replace file path=%(path)s") % locals())
164
+        LOG.debug(_("Replace file path=%s"), path)
165 165
         path = self._canonicalize_path(path)
166 166
         self.handle.write(path, content)
167 167
 
168 168
     def read_file(self, path):
169
-        LOG.debug(_("Read file path=%(path)s") % locals())
169
+        LOG.debug(_("Read file path=%s"), path)
170 170
         path = self._canonicalize_path(path)
171 171
         return self.handle.read_file(path)
172 172
 
173 173
     def has_file(self, path):
174
-        LOG.debug(_("Has file path=%(path)s") % locals())
174
+        LOG.debug(_("Has file path=%s"), path)
175 175
         path = self._canonicalize_path(path)
176 176
         try:
177 177
             self.handle.stat(path)
@@ -180,13 +180,15 @@ class VFSGuestFS(vfs.VFS):
180 180
             return False
181 181
 
182 182
     def set_permissions(self, path, mode):
183
-        LOG.debug(_("Set permissions path=%(path)s mode=%(mode)s") % locals())
183
+        LOG.debug(_("Set permissions path=%(path)s mode=%(mode)s"),
184
+                  {'path': path, 'mode': mode})
184 185
         path = self._canonicalize_path(path)
185 186
         self.handle.chmod(mode, path)
186 187
 
187 188
     def set_ownership(self, path, user, group):
188 189
         LOG.debug(_("Set ownership path=%(path)s "
189
-                    "user=%(user)s group=%(group)s") % locals())
190
+                    "user=%(user)s group=%(group)s"),
191
+                  {'path': path, 'user': user, 'group': group})
190 192
         path = self._canonicalize_path(path)
191 193
         uid = -1
192 194
         gid = -1
@@ -198,5 +200,6 @@ class VFSGuestFS(vfs.VFS):
198 200
             gid = int(self.handle.aug_get(
199 201
                     "/files/etc/group/" + group + "/gid"))
200 202
 
201
-        LOG.debug(_("chown uid=%(uid)d gid=%(gid)s") % locals())
203
+        LOG.debug(_("chown uid=%(uid)d gid=%(gid)s"),
204
+                  {'uid': uid, 'gid': gid})
202 205
         self.handle.chown(uid, gid, path)

+ 9
- 7
nova/virt/disk/vfs/localfs.py View File

@@ -99,12 +99,12 @@ class VFSLocalFS(vfs.VFS):
99 99
         self.mount = None
100 100
 
101 101
     def make_path(self, path):
102
-        LOG.debug(_("Make directory path=%(path)s") % locals())
102
+        LOG.debug(_("Make directory path=%s"), path)
103 103
         canonpath = self._canonical_path(path)
104 104
         utils.execute('mkdir', '-p', canonpath, run_as_root=True)
105 105
 
106 106
     def append_file(self, path, content):
107
-        LOG.debug(_("Append file path=%(path)s") % locals())
107
+        LOG.debug(_("Append file path=%s"), path)
108 108
         canonpath = self._canonical_path(path)
109 109
 
110 110
         args = ["-a", canonpath]
@@ -113,7 +113,7 @@ class VFSLocalFS(vfs.VFS):
113 113
         utils.execute('tee', *args, **kwargs)
114 114
 
115 115
     def replace_file(self, path, content):
116
-        LOG.debug(_("Replace file path=%(path)s") % locals())
116
+        LOG.debug(_("Replace file path=%s"), path)
117 117
         canonpath = self._canonical_path(path)
118 118
 
119 119
         args = [canonpath]
@@ -122,13 +122,13 @@ class VFSLocalFS(vfs.VFS):
122 122
         utils.execute('tee', *args, **kwargs)
123 123
 
124 124
     def read_file(self, path):
125
-        LOG.debug(_("Read file path=%(path)s") % locals())
125
+        LOG.debug(_("Read file path=%s"), path)
126 126
         canonpath = self._canonical_path(path)
127 127
 
128 128
         return utils.read_file_as_root(canonpath)
129 129
 
130 130
     def has_file(self, path):
131
-        LOG.debug(_("Has file path=%(path)s") % locals())
131
+        LOG.debug(_("Has file path=%s"), path)
132 132
         canonpath = self._canonical_path(path)
133 133
         exists, _err = utils.trycmd('readlink', '-e',
134 134
                                     canonpath,
@@ -136,13 +136,15 @@ class VFSLocalFS(vfs.VFS):
136 136
         return exists
137 137
 
138 138
     def set_permissions(self, path, mode):
139
-        LOG.debug(_("Set permissions path=%(path)s mode=%(mode)o") % locals())
139
+        LOG.debug(_("Set permissions path=%(path)s mode=%(mode)o"),
140
+                  {'path': path, 'mode': mode})
140 141
         canonpath = self._canonical_path(path)
141 142
         utils.execute('chmod', "%o" % mode, canonpath, run_as_root=True)
142 143
 
143 144
     def set_ownership(self, path, user, group):
144 145
         LOG.debug(_("Set permissions path=%(path)s "
145
-                    "user=%(user)s group=%(group)s") % locals())
146
+                    "user=%(user)s group=%(group)s"),
147
+                  {'path': path, 'user': user, 'group': group})
146 148
         canonpath = self._canonical_path(path)
147 149
         owner = None
148 150
         cmd = "chown"

+ 2
- 2
nova/virt/driver.py View File

@@ -963,8 +963,8 @@ class ComputeDriver(object):
963 963
             LOG.debug("Emitting event %s" % str(event))
964 964
             self._compute_event_callback(event)
965 965
         except Exception as ex:
966
-            LOG.error(_("Exception dispatching event %(event)s: %(ex)s")
967
-                        % locals())
966
+            LOG.error(_("Exception dispatching event %(event)s: %(ex)s"),
967
+                      {'event': event, 'ex': ex})
968 968
 
969 969
 
970 970
 def load_compute_driver(virtapi, compute_driver=None):

+ 2
- 1
nova/virt/images.py View File

@@ -206,7 +206,8 @@ def fetch_to_raw(context, image_href, path, user_id, project_id):
206 206
         backing_file = data.backing_file
207 207
         if backing_file is not None:
208 208
             raise exception.ImageUnacceptable(image_id=image_href,
209
-                reason=_("fmt=%(fmt)s backed by: %(backing_file)s") % locals())
209
+                reason=(_("fmt=%(fmt)s backed by: %(backing_file)s") %
210
+                        {'fmt': fmt, 'backing_file': backing_file}))
210 211
 
211 212
         if fmt != "raw" and CONF.force_raw_images:
212 213
             staged = "%s.converted" % path

Loading…
Cancel
Save