~smoser/ubuntu/vivid/cloud-init/snappy

« back to all changes in this revision

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

  • Committer: Scott Moser
  • Date: 2015-02-27 20:55:58 UTC
  • mfrom: (355.2.8 vivid)
  • Revision ID: smoser@ubuntu.com-20150227205558-glrwdgxqkaz6zyxa
* Merge with vivid at 0.7.7~bzr1067-0ubuntu1
* New upstream snapshot.
  * fix broken consumption of gzipped user-data (LP: #1424900)
  * functional user-data on Azure again (LP: #1423972)
  * CloudStack: support fetching password from virtual router (LP: #1422388)
* New upstream snapshot.
  * Fix for ascii decode in DataSourceAzure (LP: #1422993).
* New upstream snapshot.
  * support for gpt partitioning, utilized in Azure [Daniel Watkins]
  * fix bug in exception handling in mount_cb.
* New upstream snapshot.
  * move to python3 (LP: #1247132)
  * systemd: run cloud-init before systemd-user-sessions.service
  * Use the GCE short hostname. (LP: #1383794)
  * Enable user-data encoding support for GCE. (LP: #1404311)
  * Update to use a newer and better OMNIBUS_URL
  * Be more tolerant of 'ssh_authorized_keys' types
  * Fix parse_ssh_config failing in ssh_util.py
  * Increase the robustness/configurability of the chef module.
  * retain trailing newline from template files when using
    jinja2 (LP: #1355343)
  * fix broken output handling (LP: #1387340)
  * digital ocean datasource
  * update url in config drive documentation
  * freebsd: enable correct behavior on Ec2.
  * freebsd: Use the proper virtio FreeBSD network interface name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from mocker import MockerTestCase
2
 
 
3
1
from cloudinit import util
4
2
 
5
3
from cloudinit.config import cc_apt_configure
 
4
from ..helpers import TestCase
6
5
 
7
6
import os
8
7
import re
9
 
 
10
 
 
11
 
class TestAptProxyConfig(MockerTestCase):
 
8
import shutil
 
9
import tempfile
 
10
import unittest
 
11
 
 
12
 
 
13
class TestAptProxyConfig(TestCase):
12
14
    def setUp(self):
13
15
        super(TestAptProxyConfig, self).setUp()
14
 
        self.tmp = self.makeDir()
 
16
        self.tmp = tempfile.mkdtemp()
 
17
        self.addCleanup(shutil.rmtree, self.tmp)
15
18
        self.pfile = os.path.join(self.tmp, "proxy.cfg")
16
19
        self.cfile = os.path.join(self.tmp, "config.cfg")
17
20
 
18
21
    def _search_apt_config(self, contents, ptype, value):
19
 
        print(
20
 
            r"acquire::%s::proxy\s+[\"']%s[\"'];\n" % (ptype, value),
21
 
            contents, "flags=re.IGNORECASE")
22
 
        return(re.search(
23
 
            r"acquire::%s::proxy\s+[\"']%s[\"'];\n" % (ptype, value),
24
 
            contents, flags=re.IGNORECASE))
 
22
        return re.search(
 
23
            r"acquire::%s::proxy\s+[\"']%s[\"'];\n" % (ptype, value),
 
24
            contents, flags=re.IGNORECASE)
25
25
 
26
26
    def test_apt_proxy_written(self):
27
27
        cfg = {'apt_proxy': 'myproxy'}
30
30
        self.assertTrue(os.path.isfile(self.pfile))
31
31
        self.assertFalse(os.path.isfile(self.cfile))
32
32
 
33
 
        contents = str(util.read_file_or_url(self.pfile))
 
33
        contents = util.load_tfile_or_url(self.pfile)
34
34
        self.assertTrue(self._search_apt_config(contents, "http", "myproxy"))
35
35
 
36
36
    def test_apt_http_proxy_written(self):
40
40
        self.assertTrue(os.path.isfile(self.pfile))
41
41
        self.assertFalse(os.path.isfile(self.cfile))
42
42
 
43
 
        contents = str(util.read_file_or_url(self.pfile))
 
43
        contents = util.load_tfile_or_url(self.pfile)
44
44
        self.assertTrue(self._search_apt_config(contents, "http", "myproxy"))
45
45
 
46
46
    def test_apt_all_proxy_written(self):
58
58
        self.assertTrue(os.path.isfile(self.pfile))
59
59
        self.assertFalse(os.path.isfile(self.cfile))
60
60
 
61
 
        contents = str(util.read_file_or_url(self.pfile))
 
61
        contents = util.load_tfile_or_url(self.pfile)
62
62
 
63
 
        for ptype, pval in values.iteritems():
 
63
        for ptype, pval in values.items():
64
64
            self.assertTrue(self._search_apt_config(contents, ptype, pval))
65
65
 
66
66
    def test_proxy_deleted(self):
74
74
        cc_apt_configure.apply_apt_config({'apt_proxy': "foo"},
75
75
                                          self.pfile, self.cfile)
76
76
        self.assertTrue(os.path.isfile(self.pfile))
77
 
        contents = str(util.read_file_or_url(self.pfile))
 
77
        contents = util.load_tfile_or_url(self.pfile)
78
78
        self.assertTrue(self._search_apt_config(contents, "http", "foo"))
79
79
 
80
80
    def test_config_written(self):
86
86
        self.assertTrue(os.path.isfile(self.cfile))
87
87
        self.assertFalse(os.path.isfile(self.pfile))
88
88
 
89
 
        self.assertEqual(str(util.read_file_or_url(self.cfile)), payload)
 
89
        self.assertEqual(util.load_tfile_or_url(self.cfile), payload)
90
90
 
91
91
    def test_config_replaced(self):
92
92
        util.write_file(self.pfile, "content doesnt matter")
93
93
        cc_apt_configure.apply_apt_config({'apt_config': "foo"},
94
94
                                          self.pfile, self.cfile)
95
95
        self.assertTrue(os.path.isfile(self.cfile))
96
 
        self.assertEqual(str(util.read_file_or_url(self.cfile)), "foo")
 
96
        self.assertEqual(util.load_tfile_or_url(self.cfile), "foo")
97
97
 
98
98
    def test_config_deleted(self):
99
99
        # if no 'apt_config' is provided, delete any previously written file