summaryrefslogtreecommitdiff
path: root/cloudinit/config/cc_mcollective.py
diff options
context:
space:
mode:
authorJoshua Harlow <jxharlow@godaddy.com>2016-07-25 12:45:25 -0700
committerJoshua Harlow <jxharlow@godaddy.com>2016-08-11 16:49:21 -0700
commit80db6eb9d697c21bfab85ab9a0dd5aceee571883 (patch)
treecf47f7c4bf5cdf9383f9701e76f16b21d304f693 /cloudinit/config/cc_mcollective.py
parent8028c9234ec4260eda9431bffc6728ac3703e243 (diff)
downloadvyos-cloud-init-80db6eb9d697c21bfab85ab9a0dd5aceee571883.tar.gz
vyos-cloud-init-80db6eb9d697c21bfab85ab9a0dd5aceee571883.zip
Upgrade to a configobj package new enough to work
The older versions have various issues with unicode and those versions seem to be pulled into epel so we should denote that those versions are bad and shouldn't be used by updating to a newer version that does work.
Diffstat (limited to 'cloudinit/config/cc_mcollective.py')
-rw-r--r--cloudinit/config/cc_mcollective.py38
1 files changed, 24 insertions, 14 deletions
diff --git a/cloudinit/config/cc_mcollective.py b/cloudinit/config/cc_mcollective.py
index ada535f8..b3089f30 100644
--- a/cloudinit/config/cc_mcollective.py
+++ b/cloudinit/config/cc_mcollective.py
@@ -19,6 +19,8 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import errno
+
import six
from six import BytesIO
@@ -38,16 +40,18 @@ LOG = logging.getLogger(__name__)
def configure(config, server_cfg=SERVER_CFG,
pubcert_file=PUBCERT_FILE, pricert_file=PRICERT_FILE):
- # Read server.cfg values from the
- # original file in order to be able to mix the rest up
+ # Read server.cfg (if it exists) values from the
+ # original file in order to be able to mix the rest up.
try:
- mcollective_config = ConfigObj(server_cfg, file_error=True)
- existed = True
- except IOError:
- LOG.debug("Did not find file %s", server_cfg)
- mcollective_config = ConfigObj()
- existed = False
-
+ old_contents = util.load_file(server_cfg, quiet=False, decode=False)
+ mcollective_config = ConfigObj(BytesIO(old_contents))
+ except IOError as e:
+ if e.errno != errno.ENOENT:
+ raise
+ else:
+ LOG.debug("Did not find file %s (starting with an empty"
+ " config)", server_cfg)
+ mcollective_config = ConfigObj()
for (cfg_name, cfg) in config.items():
if cfg_name == 'public-cert':
util.write_file(pubcert_file, cfg, mode=0o644)
@@ -74,12 +78,18 @@ def configure(config, server_cfg=SERVER_CFG,
# Otherwise just try to convert it to a string
mcollective_config[cfg_name] = str(cfg)
- if existed:
- # We got all our config as wanted we'll rename
- # the previous server.cfg and create our new one
- util.rename(server_cfg, "%s.old" % (server_cfg))
+ try:
+ # We got all our config as wanted we'll copy
+ # the previous server.cfg and overwrite the old with our new one
+ util.copy(server_cfg, "%s.old" % (server_cfg))
+ except IOError as e:
+ if e.errno == errno.ENOENT:
+ # Doesn't exist to copy...
+ pass
+ else:
+ raise
- # Now we got the whole file, write to disk...
+ # Now we got the whole (new) file, write to disk...
contents = BytesIO()
mcollective_config.write(contents)
util.write_file(server_cfg, contents.getvalue(), mode=0o644)