Revision a4eae71f lib/config.py

b/lib/config.py
1145 1145
    if modified:
1146 1146
      self._WriteConfig()
1147 1147

  
1148
  def _DistributeConfig(self):
1148
  def _DistributeConfig(self, feedback_fn):
1149 1149
    """Distribute the configuration to the other nodes.
1150 1150

  
1151 1151
    Currently, this only copies the configuration file. In the future,
......
1154 1154
    """
1155 1155
    if self._offline:
1156 1156
      return True
1157

  
1157 1158
    bad = False
1158 1159

  
1159 1160
    node_list = []
......
1180 1181
        msg = ("Copy of file %s to node %s failed: %s" %
1181 1182
               (self._cfg_file, to_node, msg))
1182 1183
        logging.error(msg)
1184

  
1185
        if feedback_fn:
1186
          feedback_fn(msg)
1187

  
1183 1188
        bad = True
1189

  
1184 1190
    return not bad
1185 1191

  
1186
  def _WriteConfig(self, destination=None):
1192
  def _WriteConfig(self, destination=None, feedback_fn=None):
1187 1193
    """Write the configuration data to persistent storage.
1188 1194

  
1189 1195
    """
1196
    assert feedback_fn is None or callable(feedback_fn)
1197

  
1190 1198
    # first, cleanup the _temporary_ids set, if an ID is now in the
1191 1199
    # other objects it should be discarded to prevent unbounded growth
1192 1200
    # of that structure
......
1206 1214
    self.write_count += 1
1207 1215

  
1208 1216
    # and redistribute the config file to master candidates
1209
    self._DistributeConfig()
1217
    self._DistributeConfig(feedback_fn)
1210 1218

  
1211 1219
    # Write ssconf files on all nodes (including locally)
1212 1220
    if self._last_cluster_serial < self._config_data.cluster.serial_no:
......
1214 1222
        result = rpc.RpcRunner.call_write_ssconf_files(
1215 1223
          self._UnlockedGetNodeList(),
1216 1224
          self._UnlockedGetSsconfValues())
1225

  
1217 1226
        for nname, nresu in result.items():
1218 1227
          msg = nresu.fail_msg
1219 1228
          if msg:
1220
            logging.warning("Error while uploading ssconf files to"
1221
                            " node %s: %s", nname, msg)
1229
            errmsg = ("Error while uploading ssconf files to"
1230
                      " node %s: %s" % (nname, msg))
1231
            logging.warning(errmsg)
1232

  
1233
            if feedback_fn:
1234
              feedback_fn(errmsg)
1235

  
1222 1236
      self._last_cluster_serial = self._config_data.cluster.serial_no
1223 1237

  
1224 1238
  def _UnlockedGetSsconfValues(self):
......
1302 1316
    return self._config_data.cluster
1303 1317

  
1304 1318
  @locking.ssynchronized(_config_lock)
1305
  def Update(self, target):
1319
  def Update(self, target, feedback_fn):
1306 1320
    """Notify function to be called after updates.
1307 1321

  
1308 1322
    This function must be called when an object (as returned by
......
1314 1328
    @param target: an instance of either L{objects.Cluster},
1315 1329
        L{objects.Node} or L{objects.Instance} which is existing in
1316 1330
        the cluster
1331
    @param feedback_fn: Callable feedback function
1317 1332

  
1318 1333
    """
1319 1334
    if self._config_data is None:
......
1346 1361
      for nic in target.nics:
1347 1362
        self._temporary_macs.discard(nic.mac)
1348 1363

  
1349
    self._WriteConfig()
1364
    self._WriteConfig(feedback_fn=feedback_fn)

Also available in: Unified diff