From ce915927beddc8eb766fca89dcf35f50d0ebcd21 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Thu, 4 Feb 2016 09:13:20 -0700 Subject: [PATCH] Fix issue with depulicate ssh keys after save The CloudConfig.Save() did not load the metadata resulting in the diff function always thinking the SSH keys were new. This would cause them to be saved over and over again just getting bigger and bigger. --- config/config.go | 3 ++ .../rostest/test_08_ssh_key_merge.py | 43 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/integration/rostest/test_08_ssh_key_merge.py diff --git a/config/config.go b/config/config.go index 4415e5fb..3175cdee 100644 --- a/config/config.go +++ b/config/config.go @@ -163,6 +163,9 @@ func (c *CloudConfig) Save() error { if err != nil { return err } + + exCfg = mergeMetadata(exCfg, readMetadata()) + exData := map[interface{}]interface{}{} if err := util.Convert(exCfg, &exData); err != nil { return err diff --git a/tests/integration/rostest/test_08_ssh_key_merge.py b/tests/integration/rostest/test_08_ssh_key_merge.py new file mode 100644 index 00000000..e3d6f9c9 --- /dev/null +++ b/tests/integration/rostest/test_08_ssh_key_merge.py @@ -0,0 +1,43 @@ +import pytest +import rostest.util as u +from rostest.util import SSH + + +@pytest.fixture(scope="module") +def qemu(request): + q = u.run_qemu(request) + u.flush_out(q.stdout) + return q + + +def test_ssh_key_merging(qemu): + SSH(qemu).check_call('bash', '-c', '''cat > test-merge << "SCRIPT" +set -x -e +rm /var/lib/rancher/conf/cloud-config.yml + +EXISTING=$(ros config get ssh_authorized_keys | head -1) +cat > /var/lib/rancher/conf/metadata << EOF +SSHPublicKeys: + "0": zero + "1": one + "2": two +EOF +ros config set hostname one +ros config set hostname two +ros config set hostname three + +cat > expected << EOF +$EXISTING +- zero +- one +- two + +EOF + +ros config get ssh_authorized_keys > got + +diff got expected + +SCRIPT +sudo bash test-merge + '''.strip())