~smoser/cloud-init/lp-1077700

« back to all changes in this revision

Viewing changes to tests/unittests/test_handler/test_handler_yum_add_repo.py

  • Committer: Scott Moser
  • Date: 2012-11-11 03:32:31 UTC
  • mfrom: (687.2.10 yum-repo-conf-write)
  • Revision ID: smoser@ubuntu.com-20121111033231-7qz1g2jlhm9kt1ub
add yum_add_repo configuration module

Add in a configuration module that can write out the yum.repo format for
those that want to hook into different repos for installing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from cloudinit import helpers
 
2
from cloudinit import util
 
3
 
 
4
from cloudinit.config import cc_yum_add_repo
 
5
 
 
6
from tests.unittests import helpers
 
7
 
 
8
import logging
 
9
 
 
10
from StringIO import StringIO
 
11
 
 
12
import configobj
 
13
 
 
14
LOG = logging.getLogger(__name__)
 
15
 
 
16
 
 
17
class TestConfig(helpers.FilesystemMockingTestCase):
 
18
    def setUp(self):
 
19
        super(TestConfig, self).setUp()
 
20
        self.tmp = self.makeDir(prefix="unittest_")
 
21
 
 
22
    def test_bad_config(self):
 
23
        cfg = {
 
24
            'yum_repos': {
 
25
                'epel-testing': {
 
26
                    'name': 'Extra Packages for Enterprise Linux 5 - Testing',
 
27
                    # Missing this should cause the repo not to be written
 
28
                    #'baseurl': 'http://blah.org/pub/epel/testing/5/$basearch',
 
29
                    'enabled': False,
 
30
                    'gpgcheck': True,
 
31
                    'gpgkey': 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL',
 
32
                    'failovermethod': 'priority',
 
33
                },
 
34
            },
 
35
        }
 
36
        self.patchUtils(self.tmp)
 
37
        cc_yum_add_repo.handle('yum_add_repo', cfg, None, LOG, [])
 
38
        with self.assertRaises(IOError):
 
39
            util.load_file("/etc/yum.repos.d/epel_testing.repo")
 
40
 
 
41
    def test_write_config(self):
 
42
        cfg = {
 
43
            'yum_repos': {
 
44
                'epel-testing': {
 
45
                    'name': 'Extra Packages for Enterprise Linux 5 - Testing',
 
46
                    'baseurl': 'http://blah.org/pub/epel/testing/5/$basearch',
 
47
                    'enabled': False,
 
48
                    'gpgcheck': True,
 
49
                    'gpgkey': 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL',
 
50
                    'failovermethod': 'priority',
 
51
                },
 
52
            },
 
53
        }
 
54
        self.patchUtils(self.tmp)
 
55
        cc_yum_add_repo.handle('yum_add_repo', cfg, None, LOG, [])
 
56
        contents = util.load_file("/etc/yum.repos.d/epel_testing.repo")
 
57
        contents = configobj.ConfigObj(StringIO(contents))
 
58
        expected = {
 
59
            'epel_testing': {
 
60
                'name': 'Extra Packages for Enterprise Linux 5 - Testing',
 
61
                'failovermethod': 'priority',
 
62
                'gpgkey': 'file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL',
 
63
                'enabled': '0',
 
64
                'baseurl': 'http://blah.org/pub/epel/testing/5/$basearch',
 
65
                'gpgcheck': '1',
 
66
            }
 
67
        }
 
68
        self.assertEquals(expected, dict(contents))