Merge lp:~gnuoy/charms/trusty/nova-compute/unit_test_update into lp:~openstack-charmers-archive/charms/trusty/nova-compute/next

Proposed by Liam Young
Status: Merged
Merged at revision: 88
Proposed branch: lp:~gnuoy/charms/trusty/nova-compute/unit_test_update
Merge into: lp:~openstack-charmers-archive/charms/trusty/nova-compute/next
Diff against target: 130 lines (+41/-72)
1 file modified
unit_tests/test_nova_compute_utils.py (+41/-72)
To merge this branch: bzr merge lp:~gnuoy/charms/trusty/nova-compute/unit_test_update
Reviewer Review Type Date Requested Status
James Page Approve
Review via email: mp+243133@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Page (james-page) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'unit_tests/test_nova_compute_utils.py'
2--- unit_tests/test_nova_compute_utils.py 2014-06-24 13:44:41 +0000
3+++ unit_tests/test_nova_compute_utils.py 2014-11-28 10:22:59 +0000
4@@ -192,7 +192,9 @@
5 self.assertFalse(_open.called)
6
7 @patch('pwd.getpwnam')
8- def _test_import_authorized_keys_base(self, getpwnam, prefix=None):
9+ def _test_import_authorized_keys_base(self, getpwnam, prefix=None,
10+ auth_key_path='/home/foo/.ssh/'
11+ 'authorized_keys'):
12 getpwnam.return_value = self.fake_user('foo')
13 self.relation_get.side_effect = [
14 3, # relation_get('known_hosts_max_index')
15@@ -207,77 +209,44 @@
16
17 ex_open = [
18 call('/home/foo/.ssh/known_hosts', 'wb'),
19- call('/home/foo/.ssh/authorized_keys', 'wb')
20- ]
21- ex_write = [
22- call('k_h_0\n'),
23- call('k_h_1\n'),
24- call('k_h_2\n'),
25- call('auth_0\n'),
26- call('auth_1\n'),
27- call('auth_2\n')
28- ]
29-
30- with patch_open() as (_open, _file):
31- utils.import_authorized_keys(user='foo')
32- self.assertEquals(ex_open, _open.call_args_list)
33- self.assertEquals(ex_write, _file.write.call_args_list)
34- expected_relations = [
35- call('known_hosts_max_index'),
36- call('known_hosts_0'),
37- call('known_hosts_1'),
38- call('known_hosts_2'),
39- call('authorized_keys_max_index'),
40- call('authorized_keys_0'),
41- call('authorized_keys_1'),
42- call('authorized_keys_2')
43- ]
44- self.assertEquals(sorted(self.relation_get.call_args_list),
45- sorted(expected_relations))
46-
47- @patch('pwd.getpwnam')
48- def test_import_authorized_keys_prefix(self, getpwnam):
49- getpwnam.return_value = self.fake_user('foo')
50- self.relation_get.side_effect = [
51- 3, # relation_get('bar_known_hosts_max_index')
52- 'k_h_0', # relation_get_('bar_known_hosts_0')
53- 'k_h_1', # relation_get_('bar_known_hosts_1')
54- 'k_h_2', # relation_get_('bar_known_hosts_2')
55- 3, # relation_get('bar_authorized_keys_max_index')
56- 'auth_0', # relation_get('bar_authorized_keys_0')
57- 'auth_1', # relation_get('bar_authorized_keys_1')
58- 'auth_2', # relation_get('bar_authorized_keys_2')
59- ]
60-
61- ex_open = [
62- call('/home/foo/.ssh/known_hosts', 'wb'),
63- call('/home/foo/.ssh/authorized_keys', 'wb')
64- ]
65- ex_write = [
66- call('k_h_0\n'),
67- call('k_h_1\n'),
68- call('k_h_2\n'),
69- call('auth_0\n'),
70- call('auth_1\n'),
71- call('auth_2\n')
72- ]
73-
74- with patch_open() as (_open, _file):
75- utils.import_authorized_keys(user='foo', prefix='bar')
76- self.assertEquals(ex_open, _open.call_args_list)
77- self.assertEquals(ex_write, _file.write.call_args_list)
78- expected_relations = [
79- call('bar_known_hosts_max_index'),
80- call('bar_known_hosts_0'),
81- call('bar_known_hosts_1'),
82- call('bar_known_hosts_2'),
83- call('bar_authorized_keys_max_index'),
84- call('bar_authorized_keys_0'),
85- call('bar_authorized_keys_1'),
86- call('bar_authorized_keys_2')
87- ]
88- self.assertEquals(sorted(self.relation_get.call_args_list),
89- sorted(expected_relations))
90+ call(auth_key_path, 'wb')
91+ ]
92+ ex_write = [
93+ call('k_h_0\n'),
94+ call('k_h_1\n'),
95+ call('k_h_2\n'),
96+ call('auth_0\n'),
97+ call('auth_1\n'),
98+ call('auth_2\n')
99+ ]
100+
101+ with patch_open() as (_open, _file):
102+ utils.import_authorized_keys(user='foo', prefix=prefix)
103+ self.assertEquals(ex_open, _open.call_args_list)
104+ self.assertEquals(ex_write, _file.write.call_args_list)
105+ authkey_root = 'authorized_keys_'
106+ known_hosts_root = 'known_hosts_'
107+ if prefix:
108+ authkey_root = prefix + '_authorized_keys_'
109+ known_hosts_root = prefix + '_known_hosts_'
110+ expected_relations = [
111+ call(known_hosts_root + 'max_index'),
112+ call(known_hosts_root + '0'),
113+ call(known_hosts_root + '1'),
114+ call(known_hosts_root + '2'),
115+ call(authkey_root + 'max_index'),
116+ call(authkey_root + '0'),
117+ call(authkey_root + '1'),
118+ call(authkey_root + '2')
119+ ]
120+ self.assertEquals(sorted(self.relation_get.call_args_list),
121+ sorted(expected_relations))
122+
123+ def test_import_authorized_keys_noprefix(self):
124+ self._test_import_authorized_keys_base()
125+
126+ def test_import_authorized_keys_prefix(self):
127+ self._test_import_authorized_keys_base(prefix='bar')
128
129 @patch('subprocess.check_call')
130 def test_import_keystone_cert_missing_data(self, check_call):

Subscribers

People subscribed via source and target branches